Skip to content

Add missing native functions, and make naming consistent - #3

Merged
ChrisBQu merged 5 commits into
sourcenetwork:mainfrom
ChrisBQu:main
Jul 29, 2026
Merged

Add missing native functions, and make naming consistent#3
ChrisBQu merged 5 commits into
sourcenetwork:mainfrom
ChrisBQu:main

Conversation

@ChrisBQu

@ChrisBQu ChrisBQu commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

This PR adds the following missing methods:

Java_source_defra_DefraTransaction_VerifyBlockSignatureNative
Java_source_defra_DefraTransaction_ListLensesNative
Java_source_defra_DefraTransaction_AddLensNative
Java_source_defra_DefraTransaction_SetLensNative
Java_source_defra_DefraTransaction_DeleteEncryptedIndexNative
Java_source_defra_DefraTransaction_ListEncryptedIndexesNative
Java_source_defra_DefraTransaction_NewEncryptedIndexNative
Java_source_defra_DefraTransaction_TruncateCollectionNative
Java_source_defra_DefraTransaction_DescribeCollectionNative

This PR also renames BlockVerifySignature to VerifyBlockSignature to be consistent with our Go codebase.

This PR also makes isEncrypted a boolean, whereas before it was an integer.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

💤 Files selected but had no reviewable changes (1)
  • src/main/c/nativewrapper.c
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 718b0c2e-3c71-43bd-ae4f-3345d990535c

📥 Commits

Reviewing files that changed from the base of the PR and between c9b452d and 375f529.

📒 Files selected for processing (1)
  • src/main/c/nativewrapper.c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The JNI wrapper was updated for the Java SDK build, expanded node and collection option marshalling, boxed signing overrides, boolean document encryption flags, a corrected block-signature symbol, and previously missing transaction-native operations.

Changes

Java JNI bridge

Layer / File(s) Summary
JNI contracts and option marshalling
src/main/c/nativewrapper.c, src/main/java/source/defra/DefraCollectionOptions.java
Result conversion and Java option marshalling now support expanded node fields, collection signing overrides, and resource cleanup.
Document insertion and node or collection wiring
src/main/c/nativewrapper.c, src/main/java/source/defra/DefraCollection.java, src/main/java/source/defra/DefraNode.java, src/main/java/source/defra/DefraTransaction.java
Document insertion passes encryption flags as booleans; native node, transaction, and collection methods use the updated signatures and option conversions, and block verification uses the corrected JNI symbol.
Transaction-native operation coverage
src/main/c/nativewrapper.c
Transaction-handle methods were added for collection description and truncation, encrypted indexes, lenses, and block signature verification.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DefraTransaction
  participant nativewrapper.c
  participant Cbindings
  participant JavaResult
  DefraTransaction->>nativewrapper.c: invoke transaction native operation
  nativewrapper.c->>Cbindings: call transaction-handle operation
  Cbindings-->>nativewrapper.c: return native Result
  nativewrapper.c-->>JavaResult: convert Result to Java result object
Loading
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ChrisBQu ChrisBQu changed the title Rename Block Verify Signature native method Add missing native functions, and make naming consistent Jul 29, 2026
@ChrisBQu
ChrisBQu marked this pull request as ready for review July 29, 2026 17:34

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main/c/nativewrapper.c (1)

1602-1738: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Consider extracting shared logic to reduce DefraNode/DefraTransaction duplication.

The 9 newly-added DefraTransaction natives are byte-for-byte duplicates of their DefraNode counterparts (same body, same underlying C-function calls), as the comment above line 1602 acknowledges. This mirrors dozens of other duplicated pairs already in the file (ACP, P2P, Document, Index methods). Since JNI requires one exported symbol per Java native method, consider factoring each duplicated body into a static helper (e.g. ACPAddDACPolicyImpl(...)) called by both Java_..._DefraNode_XNative and Java_..._DefraTransaction_XNative wrappers, to cut duplication without breaking the JNI export surface.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/c/nativewrapper.c` around lines 1602 - 1738, Extract the shared
implementations for the nine newly added DefraTransaction natives into static C
helpers, then have both the corresponding Java_source_defra_DefraNode_*Native
and Java_source_defra_DefraTransaction_*Native JNI wrappers delegate to them.
Preserve each existing signature, argument conversion and release behavior,
underlying cbindings call, and JNI export symbol while removing the duplicated
method bodies.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/main/c/nativewrapper.c`:
- Around line 1602-1738: Extract the shared implementations for the nine newly
added DefraTransaction natives into static C helpers, then have both the
corresponding Java_source_defra_DefraNode_*Native and
Java_source_defra_DefraTransaction_*Native JNI wrappers delegate to them.
Preserve each existing signature, argument conversion and release behavior,
underlying cbindings call, and JNI export symbol while removing the duplicated
method bodies.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: facdf9bb-e631-4955-80d2-aac11b0c4213

📥 Commits

Reviewing files that changed from the base of the PR and between e37bc6d and c9b452d.

📒 Files selected for processing (5)
  • src/main/c/nativewrapper.c
  • src/main/java/source/defra/DefraCollection.java
  • src/main/java/source/defra/DefraCollectionOptions.java
  • src/main/java/source/defra/DefraNode.java
  • src/main/java/source/defra/DefraTransaction.java
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: Build Android Library and Test
🔇 Additional comments (7)
src/main/c/nativewrapper.c (3)

1-24: LGTM!

Also applies to: 29-95, 96-107, 117-270, 285-364, 365-1155, 1157-1601, 1740-1920


108-116: 🩺 Stability & Availability

No change needed. DefraNodeInitOptions() initializes dbPath, listeningAddresses, replicatorRetryIntervals, and peers to "", so these GetStringUTFChars calls are not reaching a NULL jstring in the JNI entry point.


271-284: 🎯 Functional Correctness

Verify CollectionOptions.enableSigning tri-state contract in DefraDB

This Java mapping uses null0, true1, and false-1; make sure defra_exports.h and the Go/C consumer enforce the same 0/1/-1 semantics for signing overrides.

src/main/java/source/defra/DefraCollectionOptions.java (1)

9-11: LGTM!

src/main/java/source/defra/DefraNode.java (1)

41-41: LGTM!

Also applies to: 456-464

src/main/java/source/defra/DefraCollection.java (1)

10-10: LGTM!

Also applies to: 59-67

src/main/java/source/defra/DefraTransaction.java (1)

36-36: LGTM!

Also applies to: 349-357

@ChrisBQu ChrisBQu self-assigned this Jul 29, 2026
@ChrisBQu
ChrisBQu merged commit 144459c into sourcenetwork:main Jul 29, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant