- 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
Feat/near sample #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| WalkthroughA new function,  Changes
 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
Poem
 ✨ Finishing Touches
 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit: 
 SupportNeed 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)
 Other keywords and placeholders
 CodeRabbit Configuration File ( | 
There was a problem hiding this 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
📒 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.
| txInputData, _ := proto.Marshal(&input) | ||
| msgForSign := core.PreImageHashes(core.CoinTypeNEAR, txInputData) | ||
|  | ||
| var preSigningOutput transactioncompiler.PreSigningOutput | ||
| proto.Unmarshal(msgForSign, &preSigningOutput) | 
There was a problem hiding this comment.
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.
| 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.
| signatureBytes, _ := hex.DecodeString("969a83332186ee9755e4839325525806e189a3d2d2bb4b4760e94443e97e1c4f22deeef0059a8e9713100eda6e19144da7e8a0ef7e539b20708ba1d8d021bd01") | ||
| blockHashBytes, _ := hex.DecodeString("0fa473fd26901df296be6adc4cc4df34d040efa2435224b6986910e630c2fef6") | ||
| pubKeyBytes, _ := hex.DecodeString("917b3d268d4b58f7fec1b150bd68d69be3ee5d4cc39855e341538465bb77860d") | 
There was a problem hiding this comment.
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.
| 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.
Sample code for go-wrapper: NEAR
Summary by CodeRabbit