Skip to content

Conversation

@nguyen-zung
Copy link
Collaborator

@nguyen-zung nguyen-zung commented Jun 22, 2025

Sample code for go-wrapper: NEAR

Summary by CodeRabbit

  • New Features
    • Introduced a new sample function to demonstrate creating, signing, verifying, and compiling NEAR blockchain transactions.
  • Other
    • Updated sample calls to include NEAR transaction testing in place of Aptos for the last wallet instance.

@nguyen-zung nguyen-zung self-assigned this Jun 22, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jun 22, 2025

Walkthrough

A new function, TestNEAR, is added to demonstrate creating, signing, verifying, and compiling a NEAR blockchain transaction. The main function is updated to call this test for NEAR instead of Aptos, and the last wallet instance is switched from Aptos to NEAR. Intermediate values are printed for debugging.

Changes

File(s) Change Summary
wrapper/go-wrapper/sample/near.go Added TestNEAR function to demonstrate NEAR transaction creation, signing, verification, and output.
wrapper/go-wrapper/main.go Updated control flow to call TestNEAR instead of TestAptos; last wallet changed from Aptos to NEAR.

Sequence Diagram(s)

sequenceDiagram
    participant Main
    participant Sample
    participant Core

    Main->>Sample: TestAptos()
    Main->>Core: Create Aptos wallet
    Main->>Core: Create NEAR wallet
    Main->>Sample: TestNEAR()
    Sample->>Core: Generate pre-image hash for NEAR tx
    Sample->>Core: Verify signature with public key
    Sample->>Core: Compile signed NEAR transaction
    Sample->>Sample: Print outputs
Loading

Poem

In the warren of code, a NEAR test appears,
With signatures checked and hashes so clear.
From Aptos to NEAR, the wallets now swap,
Debug prints abound as transactions hop.
The blockchain bunnies cheer with delight—
Another transaction signed just right!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
wrapper/go-wrapper/main.go (1)

52-58: Update the outdated comment.

The comment on line 52 still refers to "Aptos wallet" but the code now creates a NEAR wallet. This could be confusing for future maintainers.

Apply this diff to fix the comment:

-	// Aptos wallet
+	// NEAR wallet
 	tw, err := core.CreateWalletWithMnemonic(mn, core.CoinTypeNEAR)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d42b875 and 5287bf7.

📒 Files selected for processing (2)
  • wrapper/go-wrapper/main.go (1 hunks)
  • wrapper/go-wrapper/sample/near.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: build
  • GitHub Check: test
  • GitHub Check: test-wasm
  • GitHub Check: build
  • GitHub Check: build-and-test
  • GitHub Check: build
🔇 Additional comments (3)
wrapper/go-wrapper/sample/near.go (1)

14-63: LGTM! Well-structured NEAR transaction demonstration.

The function provides a comprehensive example of NEAR transaction handling, including all the key steps: input creation, pre-image hash generation, signature verification, and transaction compilation. The debug prints are helpful for understanding the intermediate values.

wrapper/go-wrapper/main.go (2)

50-50: LGTM! Good addition of NEAR testing.

Adding the TestAptos() call earlier in the function allows testing both Aptos and NEAR functionality, which demonstrates the flexibility of the wallet core library.


53-58: LGTM! Correct integration of NEAR wallet and test function.

The wallet creation and test function call are properly aligned - both using NEAR instead of Aptos. The logic is consistent and follows the same pattern as other wallet integrations in the file.

Comment on lines +40 to +44
txInputData, _ := proto.Marshal(&input)
msgForSign := core.PreImageHashes(core.CoinTypeNEAR, txInputData)

var preSigningOutput transactioncompiler.PreSigningOutput
proto.Unmarshal(msgForSign, &preSigningOutput)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add consistent error handling for protobuf operations.

The code has inconsistent error handling - proto.Marshal at line 40 ignores errors while proto.Unmarshal at line 57 handles them. Both operations should have proper error handling for robustness.

Apply this diff to add missing error handling:

-	txInputData, _ := proto.Marshal(&input)
+	txInputData, err := proto.Marshal(&input)
+	if err != nil {
+		panic(fmt.Errorf("failed to marshal signing input: %w", err))
+	}
 	msgForSign := core.PreImageHashes(core.CoinTypeNEAR, txInputData)
 
 	var preSigningOutput transactioncompiler.PreSigningOutput
-	proto.Unmarshal(msgForSign, &preSigningOutput)
+	err = proto.Unmarshal(msgForSign, &preSigningOutput)
+	if err != nil {
+		panic(fmt.Errorf("failed to unmarshal pre-signing output: %w", err))
+	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
txInputData, _ := proto.Marshal(&input)
msgForSign := core.PreImageHashes(core.CoinTypeNEAR, txInputData)
var preSigningOutput transactioncompiler.PreSigningOutput
proto.Unmarshal(msgForSign, &preSigningOutput)
txInputData, err := proto.Marshal(&input)
if err != nil {
panic(fmt.Errorf("failed to marshal signing input: %w", err))
}
msgForSign := core.PreImageHashes(core.CoinTypeNEAR, txInputData)
var preSigningOutput transactioncompiler.PreSigningOutput
err = proto.Unmarshal(msgForSign, &preSigningOutput)
if err != nil {
panic(fmt.Errorf("failed to unmarshal pre-signing output: %w", err))
}
🤖 Prompt for AI Agents
In wrapper/go-wrapper/sample/near.go around lines 40 to 44, the proto.Marshal
call ignores errors while proto.Unmarshal handles them inconsistently. Modify
the code to capture and check errors returned by proto.Marshal and
proto.Unmarshal, returning or handling the error appropriately to ensure robust
error handling for both protobuf operations.

Comment on lines +16 to +18
signatureBytes, _ := hex.DecodeString("969a83332186ee9755e4839325525806e189a3d2d2bb4b4760e94443e97e1c4f22deeef0059a8e9713100eda6e19144da7e8a0ef7e539b20708ba1d8d021bd01")
blockHashBytes, _ := hex.DecodeString("0fa473fd26901df296be6adc4cc4df34d040efa2435224b6986910e630c2fef6")
pubKeyBytes, _ := hex.DecodeString("917b3d268d4b58f7fec1b150bd68d69be3ee5d4cc39855e341538465bb77860d")
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve error handling for hex decoding operations.

The code ignores potential errors from hex.DecodeString() operations using the blank identifier _. This could lead to silent failures if the hardcoded hex strings are malformed.

Consider handling these errors explicitly:

-	signatureBytes, _ := hex.DecodeString("969a83332186ee9755e4839325525806e189a3d2d2bb4b4760e94443e97e1c4f22deeef0059a8e9713100eda6e19144da7e8a0ef7e539b20708ba1d8d021bd01")
-	blockHashBytes, _ := hex.DecodeString("0fa473fd26901df296be6adc4cc4df34d040efa2435224b6986910e630c2fef6")
-	pubKeyBytes, _ := hex.DecodeString("917b3d268d4b58f7fec1b150bd68d69be3ee5d4cc39855e341538465bb77860d")
+	signatureBytes, err := hex.DecodeString("969a83332186ee9755e4839325525806e189a3d2d2bb4b4760e94443e97e1c4f22deeef0059a8e9713100eda6e19144da7e8a0ef7e539b20708ba1d8d021bd01")
+	if err != nil {
+		panic(fmt.Errorf("failed to decode signature: %w", err))
+	}
+	blockHashBytes, err := hex.DecodeString("0fa473fd26901df296be6adc4cc4df34d040efa2435224b6986910e630c2fef6")
+	if err != nil {
+		panic(fmt.Errorf("failed to decode block hash: %w", err))
+	}
+	pubKeyBytes, err := hex.DecodeString("917b3d268d4b58f7fec1b150bd68d69be3ee5d4cc39855e341538465bb77860d")
+	if err != nil {
+		panic(fmt.Errorf("failed to decode public key: %w", err))
+	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
signatureBytes, _ := hex.DecodeString("969a83332186ee9755e4839325525806e189a3d2d2bb4b4760e94443e97e1c4f22deeef0059a8e9713100eda6e19144da7e8a0ef7e539b20708ba1d8d021bd01")
blockHashBytes, _ := hex.DecodeString("0fa473fd26901df296be6adc4cc4df34d040efa2435224b6986910e630c2fef6")
pubKeyBytes, _ := hex.DecodeString("917b3d268d4b58f7fec1b150bd68d69be3ee5d4cc39855e341538465bb77860d")
signatureBytes, err := hex.DecodeString("969a83332186ee9755e4839325525806e189a3d2d2bb4b4760e94443e97e1c4f22deeef0059a8e9713100eda6e19144da7e8a0ef7e539b20708ba1d8d021bd01")
if err != nil {
panic(fmt.Errorf("failed to decode signature: %w", err))
}
blockHashBytes, err := hex.DecodeString("0fa473fd26901df296be6adc4cc4df34d040efa2435224b6986910e630c2fef6")
if err != nil {
panic(fmt.Errorf("failed to decode block hash: %w", err))
}
pubKeyBytes, err := hex.DecodeString("917b3d268d4b58f7fec1b150bd68d69be3ee5d4cc39855e341538465bb77860d")
if err != nil {
panic(fmt.Errorf("failed to decode public key: %w", err))
}
🤖 Prompt for AI Agents
In wrapper/go-wrapper/sample/near.go around lines 16 to 18, the hex.DecodeString
calls ignore errors by assigning them to the blank identifier, which risks
silent failures if the hex strings are malformed. Modify the code to capture and
check the error returned by each hex.DecodeString call, and handle any errors
appropriately, such as returning the error or logging it, to ensure any decoding
issues are detected and managed.

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.

2 participants