Skip to content

Fix WalletConnect solana_signAllTransactions parsing and response format#1027

Open
0xh3rman wants to merge 1 commit intomainfrom
feature/wc-sign-all-transactions
Open

Fix WalletConnect solana_signAllTransactions parsing and response format#1027
0xh3rman wants to merge 1 commit intomainfrom
feature/wc-sign-all-transactions

Conversation

@0xh3rman
Copy link
Collaborator

Fixes:

  • Parse error: raw base64 was stored as data but decode_send_transaction expects {"transaction":"..."} JSON format
  • Wrong response: was returning {"signature":"..."} instead of {"transactions":["..."]}

Added SignAllTransactions action variant with Vec to support multiple transactions.

Two bugs fixed:
- Parse error: raw base64 was stored as data but decode_send_transaction expects {"transaction":"..."} JSON format
- Wrong response: was returning {"signature":"..."} instead of {"transactions":["..."]}

Added SignAllTransactions action variant with Vec<String> to support multiple transactions.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances WalletConnect's functionality for Solana by addressing critical issues related to batch transaction signing. It ensures that requests for signing multiple transactions are parsed correctly and that the responses adhere to the expected format, thereby improving the reliability and compatibility of Solana integrations within the WalletConnect ecosystem.

Highlights

  • Solana Sign All Transactions Parsing: Fixed a parse error where raw base64 transaction data for solana_signAllTransactions was not correctly wrapped in the expected {"transaction":"..."} JSON format.
  • Solana Sign All Transactions Response Format: Corrected the response format for solana_signAllTransactions to return {"transactions":["..."]} instead of {"signature":"..."}.
  • New Action Variant: Introduced a new SignAllTransactions action variant with Vec<String> to properly support handling multiple transactions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the SignAllTransactions action for Solana WalletConnect, enabling the signing of multiple transactions simultaneously. This includes adding the new action type, implementing parsing logic in SolanaRequestHandler::parse_sign_all_transactions, and encoding logic in WalletConnectResponseHandler::encode_sign_all_transactions, along with corresponding tests. Feedback suggests an efficiency improvement in parse_sign_all_transactions by moving the empty array check earlier, and recommends adding more robust test cases for failure scenarios in the same function.

Comment on lines +53 to +55
if transactions.is_empty() {
return Err("Empty transactions array".to_string());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For efficiency, it's better to check if the transactions array is empty before mapping over it and collecting the results into a new Vec. This check should be performed on the array variable right after it's created on line 44. This avoids unnecessary allocations and processing if the input array is empty.

Comment on lines +84 to +101
#[test]
fn test_sign_all_transactions() {
let params: Value = serde_json::from_str(r#"{"transactions":["AQAAA","BBBBB"]}"#).unwrap();
let result = SolanaRequestHandler::parse_sign_all_transactions(params).unwrap();
assert_eq!(
result,
WalletConnectAction::SignAllTransactions {
chain: Chain::Solana,
transaction_type: WalletConnectTransactionType::Solana {
output_type: TransferDataOutputType::EncodedTransaction,
},
transactions: vec![
r#"{"transaction":"AQAAA"}"#.to_string(),
r#"{"transaction":"BBBBB"}"#.to_string(),
],
}
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This test covers the happy path well. To make the test suite more robust, consider adding test cases for failure scenarios, such as:

  • An empty transactions array.
  • A transactions array containing non-string elements.

This will ensure that the error handling paths in parse_sign_all_transactions are working as expected.


#[test]
fn test_solana_sign_all_transactions_roundtrip() {
let params = r#"{"transactions":["AQAAAB64encoded","BBBBB64encoded"]}"#;
Copy link
Contributor

Choose a reason for hiding this comment

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

can you move this to file? it could be reused in other unit tests that you above below

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