feat: TxBuilder implementation for Cosmos and EVM#17
Merged
Conversation
feat: implement UpgradeController and full upgrade management
feat: daemon controller dependencies
feat: add TxController with E2E testing
Add TxBuilder implementation for Cosmos SDK chains with: - SDK version detection via ABCI info endpoint - Feature detection based on SDK version (gov-v1, authz, group, feegrant) - Semantic version parsing with pre-release support - Factory function with config validation - Stub implementations for BuildTx, SignTx, BroadcastTx
Add QueryAccount method to TxBuilder that queries the Cosmos SDK REST API to fetch account number and sequence needed for transaction signing. Supports both BaseAccount and ModuleAccount types.
Add message builders for governance votes, bank sends, and staking delegations with proper Cosmos SDK type handling. - Create msgs.go with payload types and BuildMessage function - Implement parseVoteOption for gov vote options (yes/no/abstain/no_with_veto) - Add ParseGasPrice and ParseAmount utility functions - Update BuildTx to query account info and construct unsigned tx - Add comprehensive tests for all transaction types The BuildTx implementation creates JSON-encoded tx bytes as a placeholder that will be replaced with proper protobuf encoding in Task 6.
- Add validation for zero/negative amounts in ParseAmount - Add validation for empty to_address in BankSendPayload - Add validation for empty validator_address in StakingDelegatePayload - Add test for decimal amount rejection in TestParseAmount - Add test for zero amount rejection in TestParseAmount - Add test for nowithveto variant in TestParseVoteOption
- Add signing.go with LoadPrivateKey and SignBytes helper functions - Implement SignTx method in TxBuilder to sign transactions - Add comprehensive tests for key loading, signing, and error cases The signing implementation uses Cosmos SDK's secp256k1 package for cryptographic operations. LoadPrivateKey validates 32-byte key length, and SignBytes produces signatures that can be verified with the corresponding public key.
- Add nil check for privKey in SignTx after LoadPrivateKey - Add input validation for privKey and signDoc in SignBytes - Add named constant secp256k1PrivKeySize for key length validation - Add tests for nil signDoc and nil privKey in SignBytes
Implement the BroadcastTx method for Cosmos SDK chains using the CometBFT JSON-RPC broadcast_tx_sync endpoint. This completes Task 5 of the TxBuilder implementation. Changes: - Create broadcast.go with BroadcastMode, BroadcastRequest, and BroadcastResponse types - Implement BroadcastTx method that encodes tx as base64, sends JSON-RPC request, and parses the response - Add comprehensive tests for success, RPC errors, non-zero codes, network errors, invalid JSON, nil input, empty bytes, HTTP errors, and context cancellation - Add interface compliance check: var _ network.TxBuilder = (*TxBuilder)(nil)
Add EVM TxBuilder implementation with: - TxBuilder struct with rpcEndpoint, chainID, client, and httpClient fields - NewTxBuilder constructor with validation and ethclient connection - SupportedTxTypes returning TxTypeBankSend - Placeholder methods for BuildTx, SignTx, and BroadcastTx - Close method for cleanup - Interface compliance check for network.TxBuilder
Implement the BuildTx method for EVM TxBuilder to support native token transfers (TxTypeBankSend). This includes: - Create msgs.go with NativeTransferPayload struct and parsing functions - ParseNativeTransferPayload validates hex addresses via common.IsHexAddress - ParseAmount converts wei amount strings to *big.Int - BuildTx switches on TxType and calls buildNativeTransfer helper - buildNativeTransfer creates legacy EVM transactions with: - Nonce from client (or 0 for testing) - Gas price from request or network suggestion - Default 21000 gas limit for native transfers - RLP encoding for TxBytes - SignDoc using types.LatestSignerForChainID().Hash() - Add comprehensive tests for all functionality
- Fix JSON marshal error handling in test functions (lines 20, 47, 106, 132, 158) - Add test case for invalid hex data in TestParseNativeTransferPayload - Add test case for empty to_address field validation - Add nonce verification assertions in TestBuildTx functions - Replace magic number with DefaultGasPriceGwei constant (1 Gwei in wei)
- Add nil signedTx validation in BroadcastTx - Add empty TxBytes validation in BroadcastTx - Add httpClient nil check with default fallback - Add test for nil signed transaction error - Add test for empty transaction bytes error - Add test for RPC error response handling - Fix outdated stub tests in txbuilder_test.go
- Add grpcTxBuilder wrapper for remote TxBuilder access - Implement CreateTxBuilder, BuildTx, SignTx, BroadcastTx via gRPC - Add TxBuilderFactory interface compliance to GRPCClient - Wire TxBuilder operations into plugin gRPC server - Update proto definitions for TxBuilder messages
- Keep network.TxBuilder interface from pkg/network - Remove duplicate plugin.TxBuilder types - Update tests to use network package types
Fixes naming conflict between the local 'plugin' package and the imported 'github.com/hashicorp/go-plugin' by using 'hcplugin' alias.
- Remove unused SignDoc struct initialization in cosmos/txbuilder.go - Fix gofmt formatting in cosmos/config.go - Fix gofmt formatting in evm/sign_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes