The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/rosetta/services/construction_check.go

304 lines
10 KiB

Rosetta Implementation - pt4 (Stage 3.4 of Node API Overhaul) (#3380) * [rosetta] Add /construct function framework Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add network ID check to all construct endpoints Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add UnsupportedCurveTypeError Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement ConstructionDerive & add ConstructAPI router Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make recover middleware the outermost middleware Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Correct error for block not found Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Expose EstimateGas Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add InvalidTransactionConstructionError * Add GetValidConstructionOperations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make TransactionMetadata optional ptr * Add UnmarshalFromInterface for TransactionMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add InvalidTransactionConstructionError to network response Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ConstructionPreprocess & ConstructionMetadata skeleton * Add Helper methods for said functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add GasPrice to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make suggested gas fee & price its own fn Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add To & From Account ID in tx metadata * remove getAmountFromUndelegateMessage * make contract address a valid account identifier * remove needless metadata in non-staking operations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error report for b32 error in newAccountIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Simplify assertValidNetworkIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Use sdk MapMarshall instead of rpc structured response * remove unused GetValidConstructionOperations * Add CurrencyHash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement assertValidTransferOperationsAndGetTxAccounts * refactor usages of rpc structured response for sdk map marshall * add account identifier checks for transaction metadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Max related operation check more general for tx op check * refactor names for readability Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add & Expose OperationComponents * Remove txAccounts & add OperationComponents to metadata for quicker processing * Remove From & To acc ID from TransactionMetadata as it's in OperationComponents * Update tests for changes Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add tx type to OperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add logs to TransactionMetadata * Enforce Operation type uniqueness invariant for each transaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error for 3+ operations in getOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Expose GetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add staking operation medata type declaration Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix error messages & update comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getCrossShardOperationComponents * rename txAccs to components for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getContractCreationOperationComponents * Fix some edge case optional checks for operation validation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [go.mod] Bump rosetta version to 0.4.4 & dependent libs * Update broken rosetta structs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ChainID to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename PreStakingBlockRewardOperation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Init operation_components.go & move respective code Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor formatTransaction for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Move maxNumOfConstructionOps to operation_components.go * Clarify unsupported type err msg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement framework for ConstructionPayloads * Remove currying OperationComponents in metadata as PublicKeys is now part of the request in the necessary endpoints * Add respective checks for added PublicKeys * Make getAddressFromPublicKey more general & update tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add getAddress and update respective functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Create transaction_construction.go & impl ConstructTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add unmarshal check for ConstructMetadata & ConstructMetadataOptions * Remove constructTransaction * Wrap unsigned transaction with UnsignedTransaction to include intended signer * Add framework for ConstructionParse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add getSigningPayload method to construction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal/commonm] Add MustGeneratePrivateKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseUnsignedTransaction * Add unpackWrappedTransactionFromHexString & refactor rlp encoding of transactions * Make getSigningPayload return a list Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add TestUnpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseSignedTransaction * Move unpackWrappedTransactionFromHexString to ConstructionParse before parsing transactions bases on if it's signed or not Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix WrappedTransaction comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add extra negative tests for unpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Finish initial Construct implementation * Implement ConstructionCombine * Implement ConstructionHash * Implement ConstructionSubmit * Ensure RLPbytes & From is present in WrappedTransaction when unpackWrappedTransactionFromHexString is called Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor construction into separate files * Move tests into appropriate files Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_check_test.go * Update edge case for getSuggestedFeeAndPrice found during testing Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_parse_test.go * Clarify names for construction_create_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix ConstructionParse to not use crypto.PubkeyToAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix UnmarshalFromInterface for CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add operation_components_test.go * Implement TestGetContractCreationOperationComponents * Implement TestGetCrossShardOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Finish operation_components_test.go * Implement TestGetTransferOperationComponents * Implement TestGetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix big number checks for getTransferOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement transaction_construction_test.go * Implement TestConstructPlainTransaction * Implement TestConstructCrossShardTransaction * Implement TestConstructContractCreationTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add shard ID checks for constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add bad curve test for TestGetAddressFromPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add nil error catches for Construction API * Fix nits in messages as seen during pass * Add DefaultGasLimit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add trace message with version to all err msgs * Add NewError unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add TestGetAddressFromKnownPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Fix possible nil ptr crash for GetBlockSigners Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Edge case bug fixes * Create empty TransactionMetdata if no metadata is provided in operations. Also update tests to correctly account for the behavior. * In pre-staking era make current block one less than the absolute latest to guarentee calculation of pres-taking eara block rewards. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix unpackWrappedTransactionFromHexString * Rename function to unpackWrappedTransactionFromString * Update respective tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make parsed transaction statuses empty Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Remove needles list initialization Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add SignatureType & SignedPayloadLength with checks Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix genesis network status crash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Correct error message dumps for transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add OperationType to ConstructMetadataOptions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix rosetta service rebase Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Fix estimate gas fail check Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add formatNegativeValue to ensure there's only 1 zero * Correct regression found in constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add contract creation estimate gas hack Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add DefaultSenderAddress for transaction formatter * Update Construction API parser to reflect change Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Address PR comments * Add GetCallStackInfo to internal utils * Add EstimateGas TODO in RPC package * Remove DefaultGasLimit to use param gas limit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add checks to tx formatter for nil to addr * Remove needless block check for genesisBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove EstimatedGasUsed from WrappedTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
package services
import (
"context"
"encoding/json"
"fmt"
"math/big"
"github.com/coinbase/rosetta-sdk-go/types"
ethCommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
ethRpc "github.com/ethereum/go-ethereum/rpc"
Rosetta Implementation - pt4 (Stage 3.4 of Node API Overhaul) (#3380) * [rosetta] Add /construct function framework Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add network ID check to all construct endpoints Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add UnsupportedCurveTypeError Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement ConstructionDerive & add ConstructAPI router Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make recover middleware the outermost middleware Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Correct error for block not found Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Expose EstimateGas Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add InvalidTransactionConstructionError * Add GetValidConstructionOperations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make TransactionMetadata optional ptr * Add UnmarshalFromInterface for TransactionMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add InvalidTransactionConstructionError to network response Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ConstructionPreprocess & ConstructionMetadata skeleton * Add Helper methods for said functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add GasPrice to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make suggested gas fee & price its own fn Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add To & From Account ID in tx metadata * remove getAmountFromUndelegateMessage * make contract address a valid account identifier * remove needless metadata in non-staking operations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error report for b32 error in newAccountIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Simplify assertValidNetworkIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Use sdk MapMarshall instead of rpc structured response * remove unused GetValidConstructionOperations * Add CurrencyHash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement assertValidTransferOperationsAndGetTxAccounts * refactor usages of rpc structured response for sdk map marshall * add account identifier checks for transaction metadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Max related operation check more general for tx op check * refactor names for readability Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add & Expose OperationComponents * Remove txAccounts & add OperationComponents to metadata for quicker processing * Remove From & To acc ID from TransactionMetadata as it's in OperationComponents * Update tests for changes Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add tx type to OperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add logs to TransactionMetadata * Enforce Operation type uniqueness invariant for each transaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error for 3+ operations in getOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Expose GetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add staking operation medata type declaration Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix error messages & update comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getCrossShardOperationComponents * rename txAccs to components for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getContractCreationOperationComponents * Fix some edge case optional checks for operation validation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [go.mod] Bump rosetta version to 0.4.4 & dependent libs * Update broken rosetta structs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ChainID to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename PreStakingBlockRewardOperation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Init operation_components.go & move respective code Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor formatTransaction for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Move maxNumOfConstructionOps to operation_components.go * Clarify unsupported type err msg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement framework for ConstructionPayloads * Remove currying OperationComponents in metadata as PublicKeys is now part of the request in the necessary endpoints * Add respective checks for added PublicKeys * Make getAddressFromPublicKey more general & update tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add getAddress and update respective functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Create transaction_construction.go & impl ConstructTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add unmarshal check for ConstructMetadata & ConstructMetadataOptions * Remove constructTransaction * Wrap unsigned transaction with UnsignedTransaction to include intended signer * Add framework for ConstructionParse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add getSigningPayload method to construction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal/commonm] Add MustGeneratePrivateKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseUnsignedTransaction * Add unpackWrappedTransactionFromHexString & refactor rlp encoding of transactions * Make getSigningPayload return a list Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add TestUnpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseSignedTransaction * Move unpackWrappedTransactionFromHexString to ConstructionParse before parsing transactions bases on if it's signed or not Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix WrappedTransaction comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add extra negative tests for unpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Finish initial Construct implementation * Implement ConstructionCombine * Implement ConstructionHash * Implement ConstructionSubmit * Ensure RLPbytes & From is present in WrappedTransaction when unpackWrappedTransactionFromHexString is called Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor construction into separate files * Move tests into appropriate files Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_check_test.go * Update edge case for getSuggestedFeeAndPrice found during testing Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_parse_test.go * Clarify names for construction_create_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix ConstructionParse to not use crypto.PubkeyToAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix UnmarshalFromInterface for CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add operation_components_test.go * Implement TestGetContractCreationOperationComponents * Implement TestGetCrossShardOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Finish operation_components_test.go * Implement TestGetTransferOperationComponents * Implement TestGetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix big number checks for getTransferOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement transaction_construction_test.go * Implement TestConstructPlainTransaction * Implement TestConstructCrossShardTransaction * Implement TestConstructContractCreationTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add shard ID checks for constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add bad curve test for TestGetAddressFromPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add nil error catches for Construction API * Fix nits in messages as seen during pass * Add DefaultGasLimit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add trace message with version to all err msgs * Add NewError unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add TestGetAddressFromKnownPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Fix possible nil ptr crash for GetBlockSigners Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Edge case bug fixes * Create empty TransactionMetdata if no metadata is provided in operations. Also update tests to correctly account for the behavior. * In pre-staking era make current block one less than the absolute latest to guarentee calculation of pres-taking eara block rewards. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix unpackWrappedTransactionFromHexString * Rename function to unpackWrappedTransactionFromString * Update respective tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make parsed transaction statuses empty Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Remove needles list initialization Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add SignatureType & SignedPayloadLength with checks Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix genesis network status crash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Correct error message dumps for transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add OperationType to ConstructMetadataOptions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix rosetta service rebase Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Fix estimate gas fail check Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add formatNegativeValue to ensure there's only 1 zero * Correct regression found in constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add contract creation estimate gas hack Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add DefaultSenderAddress for transaction formatter * Update Construction API parser to reflect change Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Address PR comments * Add GetCallStackInfo to internal utils * Add EstimateGas TODO in RPC package * Remove DefaultGasLimit to use param gas limit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add checks to tx formatter for nil to addr * Remove needless block check for genesisBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove EstimatedGasUsed from WrappedTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
"github.com/pkg/errors"
"github.com/harmony-one/harmony/core/vm"
Rosetta Implementation - pt4 (Stage 3.4 of Node API Overhaul) (#3380) * [rosetta] Add /construct function framework Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add network ID check to all construct endpoints Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add UnsupportedCurveTypeError Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement ConstructionDerive & add ConstructAPI router Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make recover middleware the outermost middleware Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Correct error for block not found Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Expose EstimateGas Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add InvalidTransactionConstructionError * Add GetValidConstructionOperations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make TransactionMetadata optional ptr * Add UnmarshalFromInterface for TransactionMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add InvalidTransactionConstructionError to network response Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ConstructionPreprocess & ConstructionMetadata skeleton * Add Helper methods for said functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add GasPrice to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make suggested gas fee & price its own fn Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add To & From Account ID in tx metadata * remove getAmountFromUndelegateMessage * make contract address a valid account identifier * remove needless metadata in non-staking operations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error report for b32 error in newAccountIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Simplify assertValidNetworkIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Use sdk MapMarshall instead of rpc structured response * remove unused GetValidConstructionOperations * Add CurrencyHash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement assertValidTransferOperationsAndGetTxAccounts * refactor usages of rpc structured response for sdk map marshall * add account identifier checks for transaction metadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Max related operation check more general for tx op check * refactor names for readability Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add & Expose OperationComponents * Remove txAccounts & add OperationComponents to metadata for quicker processing * Remove From & To acc ID from TransactionMetadata as it's in OperationComponents * Update tests for changes Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add tx type to OperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add logs to TransactionMetadata * Enforce Operation type uniqueness invariant for each transaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error for 3+ operations in getOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Expose GetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add staking operation medata type declaration Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix error messages & update comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getCrossShardOperationComponents * rename txAccs to components for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getContractCreationOperationComponents * Fix some edge case optional checks for operation validation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [go.mod] Bump rosetta version to 0.4.4 & dependent libs * Update broken rosetta structs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ChainID to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename PreStakingBlockRewardOperation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Init operation_components.go & move respective code Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor formatTransaction for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Move maxNumOfConstructionOps to operation_components.go * Clarify unsupported type err msg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement framework for ConstructionPayloads * Remove currying OperationComponents in metadata as PublicKeys is now part of the request in the necessary endpoints * Add respective checks for added PublicKeys * Make getAddressFromPublicKey more general & update tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add getAddress and update respective functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Create transaction_construction.go & impl ConstructTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add unmarshal check for ConstructMetadata & ConstructMetadataOptions * Remove constructTransaction * Wrap unsigned transaction with UnsignedTransaction to include intended signer * Add framework for ConstructionParse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add getSigningPayload method to construction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal/commonm] Add MustGeneratePrivateKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseUnsignedTransaction * Add unpackWrappedTransactionFromHexString & refactor rlp encoding of transactions * Make getSigningPayload return a list Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add TestUnpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseSignedTransaction * Move unpackWrappedTransactionFromHexString to ConstructionParse before parsing transactions bases on if it's signed or not Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix WrappedTransaction comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add extra negative tests for unpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Finish initial Construct implementation * Implement ConstructionCombine * Implement ConstructionHash * Implement ConstructionSubmit * Ensure RLPbytes & From is present in WrappedTransaction when unpackWrappedTransactionFromHexString is called Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor construction into separate files * Move tests into appropriate files Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_check_test.go * Update edge case for getSuggestedFeeAndPrice found during testing Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_parse_test.go * Clarify names for construction_create_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix ConstructionParse to not use crypto.PubkeyToAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix UnmarshalFromInterface for CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add operation_components_test.go * Implement TestGetContractCreationOperationComponents * Implement TestGetCrossShardOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Finish operation_components_test.go * Implement TestGetTransferOperationComponents * Implement TestGetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix big number checks for getTransferOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement transaction_construction_test.go * Implement TestConstructPlainTransaction * Implement TestConstructCrossShardTransaction * Implement TestConstructContractCreationTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add shard ID checks for constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add bad curve test for TestGetAddressFromPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add nil error catches for Construction API * Fix nits in messages as seen during pass * Add DefaultGasLimit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add trace message with version to all err msgs * Add NewError unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add TestGetAddressFromKnownPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Fix possible nil ptr crash for GetBlockSigners Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Edge case bug fixes * Create empty TransactionMetdata if no metadata is provided in operations. Also update tests to correctly account for the behavior. * In pre-staking era make current block one less than the absolute latest to guarentee calculation of pres-taking eara block rewards. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix unpackWrappedTransactionFromHexString * Rename function to unpackWrappedTransactionFromString * Update respective tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make parsed transaction statuses empty Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Remove needles list initialization Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add SignatureType & SignedPayloadLength with checks Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix genesis network status crash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Correct error message dumps for transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add OperationType to ConstructMetadataOptions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix rosetta service rebase Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Fix estimate gas fail check Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add formatNegativeValue to ensure there's only 1 zero * Correct regression found in constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add contract creation estimate gas hack Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add DefaultSenderAddress for transaction formatter * Update Construction API parser to reflect change Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Address PR comments * Add GetCallStackInfo to internal utils * Add EstimateGas TODO in RPC package * Remove DefaultGasLimit to use param gas limit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add checks to tx formatter for nil to addr * Remove needless block check for genesisBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove EstimatedGasUsed from WrappedTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
"github.com/harmony-one/harmony/internal/params"
"github.com/harmony-one/harmony/rosetta/common"
"github.com/harmony-one/harmony/rpc"
)
// ConstructMetadataOptions is constructed by ConstructionPreprocess for ConstructionMetadata options
type ConstructMetadataOptions struct {
TransactionMetadata *TransactionMetadata `json:"transaction_metadata"`
OperationType string `json:"operation_type,omitempty"`
GasPriceMultiplier *float64 `json:"gas_price_multiplier,omitempty"`
}
// UnmarshalFromInterface ..
func (m *ConstructMetadataOptions) UnmarshalFromInterface(metadata interface{}) error {
var T ConstructMetadataOptions
dat, err := json.Marshal(metadata)
if err != nil {
return err
}
if err := json.Unmarshal(dat, &T); err != nil {
return err
}
if T.TransactionMetadata == nil {
return fmt.Errorf("transaction metadata is required")
}
if T.OperationType == "" {
return fmt.Errorf("operation type is required")
}
*m = T
return nil
}
// ConstructionPreprocess implements the /construction/preprocess endpoint.
// Note that `request.MaxFee` is never considered for this construction implementation.
func (s *ConstructAPI) ConstructionPreprocess(
ctx context.Context, request *types.ConstructionPreprocessRequest,
) (*types.ConstructionPreprocessResponse, *types.Error) {
if err := assertValidNetworkIdentifier(request.NetworkIdentifier, s.hmy.ShardID); err != nil {
return nil, err
}
txMetadata := &TransactionMetadata{}
if request.Metadata != nil {
if err := txMetadata.UnmarshalFromInterface(request.Metadata); err != nil {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": errors.WithMessage(err, "invalid transaction metadata").Error(),
})
}
}
if txMetadata.FromShardID != nil && *txMetadata.FromShardID != s.hmy.ShardID {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": fmt.Sprintf("expect from shard ID to be %v", s.hmy.ShardID),
})
}
components, rosettaError := GetOperationComponents(request.Operations)
if rosettaError != nil {
return nil, rosettaError
}
if components.From == nil {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": "sender address is not found for given operations",
})
}
if txMetadata.ToShardID != nil && txMetadata.FromShardID != nil &&
components.Type != common.NativeCrossShardTransferOperation && *txMetadata.ToShardID != *txMetadata.FromShardID {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": "given from & to shard are different for a native same shard transfer",
})
}
if request.SuggestedFeeMultiplier != nil && *request.SuggestedFeeMultiplier < 1 {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": "given gas price multiplier must be at least 1",
})
}
Rosetta Implementation - pt4 (Stage 3.4 of Node API Overhaul) (#3380) * [rosetta] Add /construct function framework Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add network ID check to all construct endpoints Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add UnsupportedCurveTypeError Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement ConstructionDerive & add ConstructAPI router Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make recover middleware the outermost middleware Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Correct error for block not found Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Expose EstimateGas Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add InvalidTransactionConstructionError * Add GetValidConstructionOperations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make TransactionMetadata optional ptr * Add UnmarshalFromInterface for TransactionMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add InvalidTransactionConstructionError to network response Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ConstructionPreprocess & ConstructionMetadata skeleton * Add Helper methods for said functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add GasPrice to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make suggested gas fee & price its own fn Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add To & From Account ID in tx metadata * remove getAmountFromUndelegateMessage * make contract address a valid account identifier * remove needless metadata in non-staking operations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error report for b32 error in newAccountIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Simplify assertValidNetworkIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Use sdk MapMarshall instead of rpc structured response * remove unused GetValidConstructionOperations * Add CurrencyHash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement assertValidTransferOperationsAndGetTxAccounts * refactor usages of rpc structured response for sdk map marshall * add account identifier checks for transaction metadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Max related operation check more general for tx op check * refactor names for readability Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add & Expose OperationComponents * Remove txAccounts & add OperationComponents to metadata for quicker processing * Remove From & To acc ID from TransactionMetadata as it's in OperationComponents * Update tests for changes Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add tx type to OperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add logs to TransactionMetadata * Enforce Operation type uniqueness invariant for each transaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error for 3+ operations in getOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Expose GetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add staking operation medata type declaration Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix error messages & update comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getCrossShardOperationComponents * rename txAccs to components for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getContractCreationOperationComponents * Fix some edge case optional checks for operation validation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [go.mod] Bump rosetta version to 0.4.4 & dependent libs * Update broken rosetta structs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ChainID to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename PreStakingBlockRewardOperation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Init operation_components.go & move respective code Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor formatTransaction for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Move maxNumOfConstructionOps to operation_components.go * Clarify unsupported type err msg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement framework for ConstructionPayloads * Remove currying OperationComponents in metadata as PublicKeys is now part of the request in the necessary endpoints * Add respective checks for added PublicKeys * Make getAddressFromPublicKey more general & update tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add getAddress and update respective functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Create transaction_construction.go & impl ConstructTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add unmarshal check for ConstructMetadata & ConstructMetadataOptions * Remove constructTransaction * Wrap unsigned transaction with UnsignedTransaction to include intended signer * Add framework for ConstructionParse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add getSigningPayload method to construction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal/commonm] Add MustGeneratePrivateKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseUnsignedTransaction * Add unpackWrappedTransactionFromHexString & refactor rlp encoding of transactions * Make getSigningPayload return a list Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add TestUnpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseSignedTransaction * Move unpackWrappedTransactionFromHexString to ConstructionParse before parsing transactions bases on if it's signed or not Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix WrappedTransaction comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add extra negative tests for unpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Finish initial Construct implementation * Implement ConstructionCombine * Implement ConstructionHash * Implement ConstructionSubmit * Ensure RLPbytes & From is present in WrappedTransaction when unpackWrappedTransactionFromHexString is called Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor construction into separate files * Move tests into appropriate files Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_check_test.go * Update edge case for getSuggestedFeeAndPrice found during testing Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_parse_test.go * Clarify names for construction_create_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix ConstructionParse to not use crypto.PubkeyToAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix UnmarshalFromInterface for CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add operation_components_test.go * Implement TestGetContractCreationOperationComponents * Implement TestGetCrossShardOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Finish operation_components_test.go * Implement TestGetTransferOperationComponents * Implement TestGetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix big number checks for getTransferOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement transaction_construction_test.go * Implement TestConstructPlainTransaction * Implement TestConstructCrossShardTransaction * Implement TestConstructContractCreationTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add shard ID checks for constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add bad curve test for TestGetAddressFromPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add nil error catches for Construction API * Fix nits in messages as seen during pass * Add DefaultGasLimit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add trace message with version to all err msgs * Add NewError unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add TestGetAddressFromKnownPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Fix possible nil ptr crash for GetBlockSigners Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Edge case bug fixes * Create empty TransactionMetdata if no metadata is provided in operations. Also update tests to correctly account for the behavior. * In pre-staking era make current block one less than the absolute latest to guarentee calculation of pres-taking eara block rewards. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix unpackWrappedTransactionFromHexString * Rename function to unpackWrappedTransactionFromString * Update respective tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make parsed transaction statuses empty Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Remove needles list initialization Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add SignatureType & SignedPayloadLength with checks Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix genesis network status crash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Correct error message dumps for transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add OperationType to ConstructMetadataOptions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix rosetta service rebase Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Fix estimate gas fail check Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add formatNegativeValue to ensure there's only 1 zero * Correct regression found in constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add contract creation estimate gas hack Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add DefaultSenderAddress for transaction formatter * Update Construction API parser to reflect change Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Address PR comments * Add GetCallStackInfo to internal utils * Add EstimateGas TODO in RPC package * Remove DefaultGasLimit to use param gas limit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add checks to tx formatter for nil to addr * Remove needless block check for genesisBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove EstimatedGasUsed from WrappedTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
options, err := types.MarshalMap(ConstructMetadataOptions{
TransactionMetadata: txMetadata,
OperationType: components.Type,
GasPriceMultiplier: request.SuggestedFeeMultiplier,
})
if err != nil {
return nil, common.NewError(common.CatchAllError, map[string]interface{}{
"message": err.Error(),
})
}
if _, err := getAddress(components.From); err != nil {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": err.Error(),
})
}
Rosetta Implementation - pt4 (Stage 3.4 of Node API Overhaul) (#3380) * [rosetta] Add /construct function framework Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add network ID check to all construct endpoints Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add UnsupportedCurveTypeError Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement ConstructionDerive & add ConstructAPI router Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make recover middleware the outermost middleware Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Correct error for block not found Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Expose EstimateGas Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add InvalidTransactionConstructionError * Add GetValidConstructionOperations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make TransactionMetadata optional ptr * Add UnmarshalFromInterface for TransactionMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add InvalidTransactionConstructionError to network response Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ConstructionPreprocess & ConstructionMetadata skeleton * Add Helper methods for said functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add GasPrice to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make suggested gas fee & price its own fn Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add To & From Account ID in tx metadata * remove getAmountFromUndelegateMessage * make contract address a valid account identifier * remove needless metadata in non-staking operations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error report for b32 error in newAccountIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Simplify assertValidNetworkIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Use sdk MapMarshall instead of rpc structured response * remove unused GetValidConstructionOperations * Add CurrencyHash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement assertValidTransferOperationsAndGetTxAccounts * refactor usages of rpc structured response for sdk map marshall * add account identifier checks for transaction metadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Max related operation check more general for tx op check * refactor names for readability Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add & Expose OperationComponents * Remove txAccounts & add OperationComponents to metadata for quicker processing * Remove From & To acc ID from TransactionMetadata as it's in OperationComponents * Update tests for changes Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add tx type to OperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add logs to TransactionMetadata * Enforce Operation type uniqueness invariant for each transaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error for 3+ operations in getOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Expose GetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add staking operation medata type declaration Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix error messages & update comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getCrossShardOperationComponents * rename txAccs to components for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getContractCreationOperationComponents * Fix some edge case optional checks for operation validation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [go.mod] Bump rosetta version to 0.4.4 & dependent libs * Update broken rosetta structs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ChainID to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename PreStakingBlockRewardOperation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Init operation_components.go & move respective code Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor formatTransaction for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Move maxNumOfConstructionOps to operation_components.go * Clarify unsupported type err msg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement framework for ConstructionPayloads * Remove currying OperationComponents in metadata as PublicKeys is now part of the request in the necessary endpoints * Add respective checks for added PublicKeys * Make getAddressFromPublicKey more general & update tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add getAddress and update respective functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Create transaction_construction.go & impl ConstructTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add unmarshal check for ConstructMetadata & ConstructMetadataOptions * Remove constructTransaction * Wrap unsigned transaction with UnsignedTransaction to include intended signer * Add framework for ConstructionParse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add getSigningPayload method to construction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal/commonm] Add MustGeneratePrivateKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseUnsignedTransaction * Add unpackWrappedTransactionFromHexString & refactor rlp encoding of transactions * Make getSigningPayload return a list Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add TestUnpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseSignedTransaction * Move unpackWrappedTransactionFromHexString to ConstructionParse before parsing transactions bases on if it's signed or not Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix WrappedTransaction comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add extra negative tests for unpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Finish initial Construct implementation * Implement ConstructionCombine * Implement ConstructionHash * Implement ConstructionSubmit * Ensure RLPbytes & From is present in WrappedTransaction when unpackWrappedTransactionFromHexString is called Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor construction into separate files * Move tests into appropriate files Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_check_test.go * Update edge case for getSuggestedFeeAndPrice found during testing Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_parse_test.go * Clarify names for construction_create_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix ConstructionParse to not use crypto.PubkeyToAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix UnmarshalFromInterface for CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add operation_components_test.go * Implement TestGetContractCreationOperationComponents * Implement TestGetCrossShardOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Finish operation_components_test.go * Implement TestGetTransferOperationComponents * Implement TestGetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix big number checks for getTransferOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement transaction_construction_test.go * Implement TestConstructPlainTransaction * Implement TestConstructCrossShardTransaction * Implement TestConstructContractCreationTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add shard ID checks for constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add bad curve test for TestGetAddressFromPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add nil error catches for Construction API * Fix nits in messages as seen during pass * Add DefaultGasLimit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add trace message with version to all err msgs * Add NewError unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add TestGetAddressFromKnownPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Fix possible nil ptr crash for GetBlockSigners Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Edge case bug fixes * Create empty TransactionMetdata if no metadata is provided in operations. Also update tests to correctly account for the behavior. * In pre-staking era make current block one less than the absolute latest to guarentee calculation of pres-taking eara block rewards. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix unpackWrappedTransactionFromHexString * Rename function to unpackWrappedTransactionFromString * Update respective tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make parsed transaction statuses empty Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Remove needles list initialization Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add SignatureType & SignedPayloadLength with checks Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix genesis network status crash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Correct error message dumps for transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add OperationType to ConstructMetadataOptions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix rosetta service rebase Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Fix estimate gas fail check Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add formatNegativeValue to ensure there's only 1 zero * Correct regression found in constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add contract creation estimate gas hack Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add DefaultSenderAddress for transaction formatter * Update Construction API parser to reflect change Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Address PR comments * Add GetCallStackInfo to internal utils * Add EstimateGas TODO in RPC package * Remove DefaultGasLimit to use param gas limit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add checks to tx formatter for nil to addr * Remove needless block check for genesisBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove EstimatedGasUsed from WrappedTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
return &types.ConstructionPreprocessResponse{
Options: options,
RequiredPublicKeys: []*types.AccountIdentifier{
components.From,
},
}, nil
}
// ConstructMetadata with a set of operations will construct a valid transaction
type ConstructMetadata struct {
Nonce uint64 `json:"nonce"`
GasLimit uint64 `json:"gas_limit"`
GasPrice *big.Int `json:"gas_price"`
ContractCode hexutil.Bytes `json:"contract_code"`
EvmReturn hexutil.Bytes `json:"evm_return"`
EvmErrorMessage string `json:"evm_error_message"`
Transaction *TransactionMetadata `json:"transaction_metadata"`
Rosetta Implementation - pt4 (Stage 3.4 of Node API Overhaul) (#3380) * [rosetta] Add /construct function framework Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add network ID check to all construct endpoints Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add UnsupportedCurveTypeError Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement ConstructionDerive & add ConstructAPI router Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make recover middleware the outermost middleware Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Correct error for block not found Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Expose EstimateGas Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add InvalidTransactionConstructionError * Add GetValidConstructionOperations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make TransactionMetadata optional ptr * Add UnmarshalFromInterface for TransactionMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add InvalidTransactionConstructionError to network response Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ConstructionPreprocess & ConstructionMetadata skeleton * Add Helper methods for said functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add GasPrice to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make suggested gas fee & price its own fn Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add To & From Account ID in tx metadata * remove getAmountFromUndelegateMessage * make contract address a valid account identifier * remove needless metadata in non-staking operations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error report for b32 error in newAccountIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Simplify assertValidNetworkIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Use sdk MapMarshall instead of rpc structured response * remove unused GetValidConstructionOperations * Add CurrencyHash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement assertValidTransferOperationsAndGetTxAccounts * refactor usages of rpc structured response for sdk map marshall * add account identifier checks for transaction metadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Max related operation check more general for tx op check * refactor names for readability Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add & Expose OperationComponents * Remove txAccounts & add OperationComponents to metadata for quicker processing * Remove From & To acc ID from TransactionMetadata as it's in OperationComponents * Update tests for changes Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add tx type to OperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add logs to TransactionMetadata * Enforce Operation type uniqueness invariant for each transaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error for 3+ operations in getOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Expose GetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add staking operation medata type declaration Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix error messages & update comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getCrossShardOperationComponents * rename txAccs to components for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getContractCreationOperationComponents * Fix some edge case optional checks for operation validation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [go.mod] Bump rosetta version to 0.4.4 & dependent libs * Update broken rosetta structs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ChainID to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename PreStakingBlockRewardOperation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Init operation_components.go & move respective code Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor formatTransaction for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Move maxNumOfConstructionOps to operation_components.go * Clarify unsupported type err msg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement framework for ConstructionPayloads * Remove currying OperationComponents in metadata as PublicKeys is now part of the request in the necessary endpoints * Add respective checks for added PublicKeys * Make getAddressFromPublicKey more general & update tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add getAddress and update respective functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Create transaction_construction.go & impl ConstructTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add unmarshal check for ConstructMetadata & ConstructMetadataOptions * Remove constructTransaction * Wrap unsigned transaction with UnsignedTransaction to include intended signer * Add framework for ConstructionParse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add getSigningPayload method to construction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal/commonm] Add MustGeneratePrivateKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseUnsignedTransaction * Add unpackWrappedTransactionFromHexString & refactor rlp encoding of transactions * Make getSigningPayload return a list Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add TestUnpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseSignedTransaction * Move unpackWrappedTransactionFromHexString to ConstructionParse before parsing transactions bases on if it's signed or not Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix WrappedTransaction comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add extra negative tests for unpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Finish initial Construct implementation * Implement ConstructionCombine * Implement ConstructionHash * Implement ConstructionSubmit * Ensure RLPbytes & From is present in WrappedTransaction when unpackWrappedTransactionFromHexString is called Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor construction into separate files * Move tests into appropriate files Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_check_test.go * Update edge case for getSuggestedFeeAndPrice found during testing Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_parse_test.go * Clarify names for construction_create_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix ConstructionParse to not use crypto.PubkeyToAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix UnmarshalFromInterface for CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add operation_components_test.go * Implement TestGetContractCreationOperationComponents * Implement TestGetCrossShardOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Finish operation_components_test.go * Implement TestGetTransferOperationComponents * Implement TestGetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix big number checks for getTransferOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement transaction_construction_test.go * Implement TestConstructPlainTransaction * Implement TestConstructCrossShardTransaction * Implement TestConstructContractCreationTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add shard ID checks for constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add bad curve test for TestGetAddressFromPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add nil error catches for Construction API * Fix nits in messages as seen during pass * Add DefaultGasLimit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add trace message with version to all err msgs * Add NewError unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add TestGetAddressFromKnownPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Fix possible nil ptr crash for GetBlockSigners Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Edge case bug fixes * Create empty TransactionMetdata if no metadata is provided in operations. Also update tests to correctly account for the behavior. * In pre-staking era make current block one less than the absolute latest to guarentee calculation of pres-taking eara block rewards. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix unpackWrappedTransactionFromHexString * Rename function to unpackWrappedTransactionFromString * Update respective tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make parsed transaction statuses empty Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Remove needles list initialization Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add SignatureType & SignedPayloadLength with checks Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix genesis network status crash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Correct error message dumps for transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add OperationType to ConstructMetadataOptions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix rosetta service rebase Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Fix estimate gas fail check Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add formatNegativeValue to ensure there's only 1 zero * Correct regression found in constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add contract creation estimate gas hack Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add DefaultSenderAddress for transaction formatter * Update Construction API parser to reflect change Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Address PR comments * Add GetCallStackInfo to internal utils * Add EstimateGas TODO in RPC package * Remove DefaultGasLimit to use param gas limit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add checks to tx formatter for nil to addr * Remove needless block check for genesisBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove EstimatedGasUsed from WrappedTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
}
// UnmarshalFromInterface ..
func (m *ConstructMetadata) UnmarshalFromInterface(blockArgs interface{}) error {
var T ConstructMetadata
dat, err := json.Marshal(blockArgs)
if err != nil {
return err
}
if err := json.Unmarshal(dat, &T); err != nil {
return err
}
if T.GasPrice == nil {
return fmt.Errorf("gas price is required")
}
if T.Transaction == nil {
return fmt.Errorf("transaction metadata is required")
}
*m = T
return nil
}
// ConstructionMetadata implements the /construction/metadata endpoint.
func (s *ConstructAPI) ConstructionMetadata(
ctx context.Context, request *types.ConstructionMetadataRequest,
) (*types.ConstructionMetadataResponse, *types.Error) {
if err := assertValidNetworkIdentifier(request.NetworkIdentifier, s.hmy.ShardID); err != nil {
return nil, err
}
options := &ConstructMetadataOptions{}
if err := options.UnmarshalFromInterface(request.Options); err != nil {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": errors.WithMessage(err, "invalid metadata option(s)").Error(),
})
}
if len(request.PublicKeys) != 1 {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": "require sender public key only",
})
}
senderAddr, rosettaError := getAddressFromPublicKey(request.PublicKeys[0])
if rosettaError != nil {
return nil, rosettaError
}
nonce, err := s.hmy.GetPoolNonce(ctx, *senderAddr)
if err != nil {
return nil, common.NewError(common.CatchAllError, map[string]interface{}{
"message": err.Error(),
})
}
data := hexutil.Bytes{}
if options.TransactionMetadata.Data != nil {
var err error
if data, err = hexutil.Decode(*options.TransactionMetadata.Data); err != nil {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": errors.WithMessage(err, "invalid tx data format").Error(),
})
}
}
var contractAddress ethCommon.Address
if options.TransactionMetadata.ContractAccountIdentifier != nil {
contractAddress, err = getAddress(options.TransactionMetadata.ContractAccountIdentifier)
if err != nil {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": errors.WithMessage(err, "unable to get provided contract address").Error(),
})
}
}
state, _, err := s.hmy.StateAndHeaderByNumber(ctx, ethRpc.LatestBlockNumber)
if state == nil || err != nil {
return nil, common.NewError(common.BlockNotFoundError, map[string]interface{}{
"message": "block state not found for latest block",
})
}
Rosetta Implementation - pt4 (Stage 3.4 of Node API Overhaul) (#3380) * [rosetta] Add /construct function framework Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add network ID check to all construct endpoints Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add UnsupportedCurveTypeError Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement ConstructionDerive & add ConstructAPI router Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make recover middleware the outermost middleware Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Correct error for block not found Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Expose EstimateGas Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add InvalidTransactionConstructionError * Add GetValidConstructionOperations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make TransactionMetadata optional ptr * Add UnmarshalFromInterface for TransactionMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add InvalidTransactionConstructionError to network response Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ConstructionPreprocess & ConstructionMetadata skeleton * Add Helper methods for said functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add GasPrice to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make suggested gas fee & price its own fn Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add To & From Account ID in tx metadata * remove getAmountFromUndelegateMessage * make contract address a valid account identifier * remove needless metadata in non-staking operations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error report for b32 error in newAccountIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Simplify assertValidNetworkIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Use sdk MapMarshall instead of rpc structured response * remove unused GetValidConstructionOperations * Add CurrencyHash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement assertValidTransferOperationsAndGetTxAccounts * refactor usages of rpc structured response for sdk map marshall * add account identifier checks for transaction metadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Max related operation check more general for tx op check * refactor names for readability Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add & Expose OperationComponents * Remove txAccounts & add OperationComponents to metadata for quicker processing * Remove From & To acc ID from TransactionMetadata as it's in OperationComponents * Update tests for changes Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add tx type to OperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add logs to TransactionMetadata * Enforce Operation type uniqueness invariant for each transaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error for 3+ operations in getOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Expose GetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add staking operation medata type declaration Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix error messages & update comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getCrossShardOperationComponents * rename txAccs to components for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getContractCreationOperationComponents * Fix some edge case optional checks for operation validation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [go.mod] Bump rosetta version to 0.4.4 & dependent libs * Update broken rosetta structs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ChainID to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename PreStakingBlockRewardOperation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Init operation_components.go & move respective code Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor formatTransaction for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Move maxNumOfConstructionOps to operation_components.go * Clarify unsupported type err msg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement framework for ConstructionPayloads * Remove currying OperationComponents in metadata as PublicKeys is now part of the request in the necessary endpoints * Add respective checks for added PublicKeys * Make getAddressFromPublicKey more general & update tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add getAddress and update respective functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Create transaction_construction.go & impl ConstructTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add unmarshal check for ConstructMetadata & ConstructMetadataOptions * Remove constructTransaction * Wrap unsigned transaction with UnsignedTransaction to include intended signer * Add framework for ConstructionParse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add getSigningPayload method to construction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal/commonm] Add MustGeneratePrivateKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseUnsignedTransaction * Add unpackWrappedTransactionFromHexString & refactor rlp encoding of transactions * Make getSigningPayload return a list Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add TestUnpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseSignedTransaction * Move unpackWrappedTransactionFromHexString to ConstructionParse before parsing transactions bases on if it's signed or not Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix WrappedTransaction comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add extra negative tests for unpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Finish initial Construct implementation * Implement ConstructionCombine * Implement ConstructionHash * Implement ConstructionSubmit * Ensure RLPbytes & From is present in WrappedTransaction when unpackWrappedTransactionFromHexString is called Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor construction into separate files * Move tests into appropriate files Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_check_test.go * Update edge case for getSuggestedFeeAndPrice found during testing Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_parse_test.go * Clarify names for construction_create_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix ConstructionParse to not use crypto.PubkeyToAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix UnmarshalFromInterface for CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add operation_components_test.go * Implement TestGetContractCreationOperationComponents * Implement TestGetCrossShardOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Finish operation_components_test.go * Implement TestGetTransferOperationComponents * Implement TestGetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix big number checks for getTransferOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement transaction_construction_test.go * Implement TestConstructPlainTransaction * Implement TestConstructCrossShardTransaction * Implement TestConstructContractCreationTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add shard ID checks for constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add bad curve test for TestGetAddressFromPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add nil error catches for Construction API * Fix nits in messages as seen during pass * Add DefaultGasLimit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add trace message with version to all err msgs * Add NewError unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add TestGetAddressFromKnownPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Fix possible nil ptr crash for GetBlockSigners Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Edge case bug fixes * Create empty TransactionMetdata if no metadata is provided in operations. Also update tests to correctly account for the behavior. * In pre-staking era make current block one less than the absolute latest to guarentee calculation of pres-taking eara block rewards. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix unpackWrappedTransactionFromHexString * Rename function to unpackWrappedTransactionFromString * Update respective tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make parsed transaction statuses empty Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Remove needles list initialization Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add SignatureType & SignedPayloadLength with checks Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix genesis network status crash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Correct error message dumps for transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add OperationType to ConstructMetadataOptions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix rosetta service rebase Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Fix estimate gas fail check Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add formatNegativeValue to ensure there's only 1 zero * Correct regression found in constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add contract creation estimate gas hack Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add DefaultSenderAddress for transaction formatter * Update Construction API parser to reflect change Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Address PR comments * Add GetCallStackInfo to internal utils * Add EstimateGas TODO in RPC package * Remove DefaultGasLimit to use param gas limit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add checks to tx formatter for nil to addr * Remove needless block check for genesisBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove EstimatedGasUsed from WrappedTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
var estGasUsed uint64
if !isStakingOperation(options.OperationType) {
if options.OperationType == common.ContractCreationOperation {
estGasUsed, err = rpc.EstimateGas(ctx, s.hmy, rpc.CallArgs{From: senderAddr, Data: &data}, nil)
Rosetta Implementation - pt4 (Stage 3.4 of Node API Overhaul) (#3380) * [rosetta] Add /construct function framework Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add network ID check to all construct endpoints Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add UnsupportedCurveTypeError Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement ConstructionDerive & add ConstructAPI router Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make recover middleware the outermost middleware Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Correct error for block not found Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Expose EstimateGas Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add InvalidTransactionConstructionError * Add GetValidConstructionOperations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make TransactionMetadata optional ptr * Add UnmarshalFromInterface for TransactionMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add InvalidTransactionConstructionError to network response Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ConstructionPreprocess & ConstructionMetadata skeleton * Add Helper methods for said functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add GasPrice to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make suggested gas fee & price its own fn Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add To & From Account ID in tx metadata * remove getAmountFromUndelegateMessage * make contract address a valid account identifier * remove needless metadata in non-staking operations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error report for b32 error in newAccountIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Simplify assertValidNetworkIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Use sdk MapMarshall instead of rpc structured response * remove unused GetValidConstructionOperations * Add CurrencyHash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement assertValidTransferOperationsAndGetTxAccounts * refactor usages of rpc structured response for sdk map marshall * add account identifier checks for transaction metadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Max related operation check more general for tx op check * refactor names for readability Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add & Expose OperationComponents * Remove txAccounts & add OperationComponents to metadata for quicker processing * Remove From & To acc ID from TransactionMetadata as it's in OperationComponents * Update tests for changes Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add tx type to OperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add logs to TransactionMetadata * Enforce Operation type uniqueness invariant for each transaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error for 3+ operations in getOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Expose GetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add staking operation medata type declaration Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix error messages & update comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getCrossShardOperationComponents * rename txAccs to components for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getContractCreationOperationComponents * Fix some edge case optional checks for operation validation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [go.mod] Bump rosetta version to 0.4.4 & dependent libs * Update broken rosetta structs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ChainID to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename PreStakingBlockRewardOperation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Init operation_components.go & move respective code Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor formatTransaction for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Move maxNumOfConstructionOps to operation_components.go * Clarify unsupported type err msg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement framework for ConstructionPayloads * Remove currying OperationComponents in metadata as PublicKeys is now part of the request in the necessary endpoints * Add respective checks for added PublicKeys * Make getAddressFromPublicKey more general & update tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add getAddress and update respective functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Create transaction_construction.go & impl ConstructTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add unmarshal check for ConstructMetadata & ConstructMetadataOptions * Remove constructTransaction * Wrap unsigned transaction with UnsignedTransaction to include intended signer * Add framework for ConstructionParse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add getSigningPayload method to construction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal/commonm] Add MustGeneratePrivateKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseUnsignedTransaction * Add unpackWrappedTransactionFromHexString & refactor rlp encoding of transactions * Make getSigningPayload return a list Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add TestUnpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseSignedTransaction * Move unpackWrappedTransactionFromHexString to ConstructionParse before parsing transactions bases on if it's signed or not Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix WrappedTransaction comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add extra negative tests for unpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Finish initial Construct implementation * Implement ConstructionCombine * Implement ConstructionHash * Implement ConstructionSubmit * Ensure RLPbytes & From is present in WrappedTransaction when unpackWrappedTransactionFromHexString is called Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor construction into separate files * Move tests into appropriate files Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_check_test.go * Update edge case for getSuggestedFeeAndPrice found during testing Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_parse_test.go * Clarify names for construction_create_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix ConstructionParse to not use crypto.PubkeyToAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix UnmarshalFromInterface for CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add operation_components_test.go * Implement TestGetContractCreationOperationComponents * Implement TestGetCrossShardOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Finish operation_components_test.go * Implement TestGetTransferOperationComponents * Implement TestGetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix big number checks for getTransferOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement transaction_construction_test.go * Implement TestConstructPlainTransaction * Implement TestConstructCrossShardTransaction * Implement TestConstructContractCreationTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add shard ID checks for constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add bad curve test for TestGetAddressFromPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add nil error catches for Construction API * Fix nits in messages as seen during pass * Add DefaultGasLimit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add trace message with version to all err msgs * Add NewError unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add TestGetAddressFromKnownPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Fix possible nil ptr crash for GetBlockSigners Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Edge case bug fixes * Create empty TransactionMetdata if no metadata is provided in operations. Also update tests to correctly account for the behavior. * In pre-staking era make current block one less than the absolute latest to guarentee calculation of pres-taking eara block rewards. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix unpackWrappedTransactionFromHexString * Rename function to unpackWrappedTransactionFromString * Update respective tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make parsed transaction statuses empty Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Remove needles list initialization Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add SignatureType & SignedPayloadLength with checks Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix genesis network status crash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Correct error message dumps for transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add OperationType to ConstructMetadataOptions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix rosetta service rebase Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Fix estimate gas fail check Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add formatNegativeValue to ensure there's only 1 zero * Correct regression found in constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add contract creation estimate gas hack Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add DefaultSenderAddress for transaction formatter * Update Construction API parser to reflect change Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Address PR comments * Add GetCallStackInfo to internal utils * Add EstimateGas TODO in RPC package * Remove DefaultGasLimit to use param gas limit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add checks to tx formatter for nil to addr * Remove needless block check for genesisBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove EstimatedGasUsed from WrappedTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
estGasUsed *= 2 // HACK to account for imperfect contract creation estimation
} else {
estGasUsed, err = rpc.EstimateGas(
ctx, s.hmy, rpc.CallArgs{From: senderAddr, To: &contractAddress, Data: &data}, nil,
)
Rosetta Implementation - pt4 (Stage 3.4 of Node API Overhaul) (#3380) * [rosetta] Add /construct function framework Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add network ID check to all construct endpoints Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add UnsupportedCurveTypeError Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement ConstructionDerive & add ConstructAPI router Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make recover middleware the outermost middleware Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Correct error for block not found Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Expose EstimateGas Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add InvalidTransactionConstructionError * Add GetValidConstructionOperations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make TransactionMetadata optional ptr * Add UnmarshalFromInterface for TransactionMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add InvalidTransactionConstructionError to network response Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ConstructionPreprocess & ConstructionMetadata skeleton * Add Helper methods for said functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add GasPrice to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make suggested gas fee & price its own fn Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add To & From Account ID in tx metadata * remove getAmountFromUndelegateMessage * make contract address a valid account identifier * remove needless metadata in non-staking operations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error report for b32 error in newAccountIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Simplify assertValidNetworkIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Use sdk MapMarshall instead of rpc structured response * remove unused GetValidConstructionOperations * Add CurrencyHash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement assertValidTransferOperationsAndGetTxAccounts * refactor usages of rpc structured response for sdk map marshall * add account identifier checks for transaction metadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Max related operation check more general for tx op check * refactor names for readability Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add & Expose OperationComponents * Remove txAccounts & add OperationComponents to metadata for quicker processing * Remove From & To acc ID from TransactionMetadata as it's in OperationComponents * Update tests for changes Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add tx type to OperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add logs to TransactionMetadata * Enforce Operation type uniqueness invariant for each transaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error for 3+ operations in getOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Expose GetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add staking operation medata type declaration Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix error messages & update comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getCrossShardOperationComponents * rename txAccs to components for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getContractCreationOperationComponents * Fix some edge case optional checks for operation validation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [go.mod] Bump rosetta version to 0.4.4 & dependent libs * Update broken rosetta structs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ChainID to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename PreStakingBlockRewardOperation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Init operation_components.go & move respective code Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor formatTransaction for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Move maxNumOfConstructionOps to operation_components.go * Clarify unsupported type err msg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement framework for ConstructionPayloads * Remove currying OperationComponents in metadata as PublicKeys is now part of the request in the necessary endpoints * Add respective checks for added PublicKeys * Make getAddressFromPublicKey more general & update tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add getAddress and update respective functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Create transaction_construction.go & impl ConstructTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add unmarshal check for ConstructMetadata & ConstructMetadataOptions * Remove constructTransaction * Wrap unsigned transaction with UnsignedTransaction to include intended signer * Add framework for ConstructionParse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add getSigningPayload method to construction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal/commonm] Add MustGeneratePrivateKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseUnsignedTransaction * Add unpackWrappedTransactionFromHexString & refactor rlp encoding of transactions * Make getSigningPayload return a list Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add TestUnpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseSignedTransaction * Move unpackWrappedTransactionFromHexString to ConstructionParse before parsing transactions bases on if it's signed or not Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix WrappedTransaction comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add extra negative tests for unpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Finish initial Construct implementation * Implement ConstructionCombine * Implement ConstructionHash * Implement ConstructionSubmit * Ensure RLPbytes & From is present in WrappedTransaction when unpackWrappedTransactionFromHexString is called Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor construction into separate files * Move tests into appropriate files Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_check_test.go * Update edge case for getSuggestedFeeAndPrice found during testing Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_parse_test.go * Clarify names for construction_create_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix ConstructionParse to not use crypto.PubkeyToAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix UnmarshalFromInterface for CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add operation_components_test.go * Implement TestGetContractCreationOperationComponents * Implement TestGetCrossShardOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Finish operation_components_test.go * Implement TestGetTransferOperationComponents * Implement TestGetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix big number checks for getTransferOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement transaction_construction_test.go * Implement TestConstructPlainTransaction * Implement TestConstructCrossShardTransaction * Implement TestConstructContractCreationTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add shard ID checks for constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add bad curve test for TestGetAddressFromPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add nil error catches for Construction API * Fix nits in messages as seen during pass * Add DefaultGasLimit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add trace message with version to all err msgs * Add NewError unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add TestGetAddressFromKnownPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Fix possible nil ptr crash for GetBlockSigners Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Edge case bug fixes * Create empty TransactionMetdata if no metadata is provided in operations. Also update tests to correctly account for the behavior. * In pre-staking era make current block one less than the absolute latest to guarentee calculation of pres-taking eara block rewards. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix unpackWrappedTransactionFromHexString * Rename function to unpackWrappedTransactionFromString * Update respective tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make parsed transaction statuses empty Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Remove needles list initialization Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add SignatureType & SignedPayloadLength with checks Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix genesis network status crash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Correct error message dumps for transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add OperationType to ConstructMetadataOptions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix rosetta service rebase Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Fix estimate gas fail check Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add formatNegativeValue to ensure there's only 1 zero * Correct regression found in constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add contract creation estimate gas hack Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add DefaultSenderAddress for transaction formatter * Update Construction API parser to reflect change Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Address PR comments * Add GetCallStackInfo to internal utils * Add EstimateGas TODO in RPC package * Remove DefaultGasLimit to use param gas limit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add checks to tx formatter for nil to addr * Remove needless block check for genesisBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove EstimatedGasUsed from WrappedTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
}
} else {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": "staking operations are not supported",
})
}
if err != nil {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": errors.WithMessage(err, "invalid transaction data").Error(),
})
}
gasMul := float64(1)
if options.GasPriceMultiplier != nil && *options.GasPriceMultiplier > 1 {
gasMul = *options.GasPriceMultiplier
}
Rosetta Implementation Cleanup (Stage 3 of Node API Overhaul) (#3390) * [core] Add FindLogsWithTopic & unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Add GetDetailedBlockSignerInfo Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Add IsCommitteeSelectionBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [test] Add test transaction creation helpers Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Refactor account.go & add tests * Move TestNewAccountIdentifier & TestGetAddress to account_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Move Operation & Tx formatting to own files * Move Respective unit tests to own files * Expose GetOperations & GetStakingOperations * Expose FormatTransaction, FormatCrossShardReceiverTransaction, FormatGenesisTransaction, FormatPreStakingRewardTransaction & FormatUndelegationPayoutTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Move TransactionMetadata to transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Update construction to use new helpers & formatters * Make docs consistent for mempool.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Move all special tx & blk handling to own file Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove all moved fns, methods & tests from block.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * Fix lint & imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename all tx related files for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename DefaultSenderAddress to FormatDefaultSenderAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename Currency to NativeCurrency * This is in anticipation of HRC20 token support with rosetta * Rename various native operation functions accordingly * Add documentation to explain what a native token is Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix pre-staking block reward calculation * Move getPreStakingRewardTransactionIdentifiers to block_special.go * Add epoch to block metadata * Update unit tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * Add IsLastBlockInEpoch method to Block & Header * Refactor all uses of length check `ShardState` * [hmy] Refactor IsCommitteeSelectionBlock to use chain.IsCommitteeSelectionBlock * Address PR comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Update var names in preStakingRewardBlockTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
sugNativeFee, sugNativePrice := getSuggestedNativeFeeAndPrice(gasMul, new(big.Int).SetUint64(estGasUsed))
Rosetta Implementation - pt4 (Stage 3.4 of Node API Overhaul) (#3380) * [rosetta] Add /construct function framework Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add network ID check to all construct endpoints Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add UnsupportedCurveTypeError Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement ConstructionDerive & add ConstructAPI router Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make recover middleware the outermost middleware Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Correct error for block not found Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Expose EstimateGas Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add InvalidTransactionConstructionError * Add GetValidConstructionOperations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make TransactionMetadata optional ptr * Add UnmarshalFromInterface for TransactionMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add InvalidTransactionConstructionError to network response Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ConstructionPreprocess & ConstructionMetadata skeleton * Add Helper methods for said functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add GasPrice to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make suggested gas fee & price its own fn Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add To & From Account ID in tx metadata * remove getAmountFromUndelegateMessage * make contract address a valid account identifier * remove needless metadata in non-staking operations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error report for b32 error in newAccountIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Simplify assertValidNetworkIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Use sdk MapMarshall instead of rpc structured response * remove unused GetValidConstructionOperations * Add CurrencyHash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement assertValidTransferOperationsAndGetTxAccounts * refactor usages of rpc structured response for sdk map marshall * add account identifier checks for transaction metadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Max related operation check more general for tx op check * refactor names for readability Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add & Expose OperationComponents * Remove txAccounts & add OperationComponents to metadata for quicker processing * Remove From & To acc ID from TransactionMetadata as it's in OperationComponents * Update tests for changes Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add tx type to OperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add logs to TransactionMetadata * Enforce Operation type uniqueness invariant for each transaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error for 3+ operations in getOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Expose GetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add staking operation medata type declaration Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix error messages & update comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getCrossShardOperationComponents * rename txAccs to components for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getContractCreationOperationComponents * Fix some edge case optional checks for operation validation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [go.mod] Bump rosetta version to 0.4.4 & dependent libs * Update broken rosetta structs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ChainID to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename PreStakingBlockRewardOperation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Init operation_components.go & move respective code Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor formatTransaction for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Move maxNumOfConstructionOps to operation_components.go * Clarify unsupported type err msg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement framework for ConstructionPayloads * Remove currying OperationComponents in metadata as PublicKeys is now part of the request in the necessary endpoints * Add respective checks for added PublicKeys * Make getAddressFromPublicKey more general & update tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add getAddress and update respective functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Create transaction_construction.go & impl ConstructTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add unmarshal check for ConstructMetadata & ConstructMetadataOptions * Remove constructTransaction * Wrap unsigned transaction with UnsignedTransaction to include intended signer * Add framework for ConstructionParse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add getSigningPayload method to construction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal/commonm] Add MustGeneratePrivateKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseUnsignedTransaction * Add unpackWrappedTransactionFromHexString & refactor rlp encoding of transactions * Make getSigningPayload return a list Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add TestUnpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseSignedTransaction * Move unpackWrappedTransactionFromHexString to ConstructionParse before parsing transactions bases on if it's signed or not Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix WrappedTransaction comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add extra negative tests for unpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Finish initial Construct implementation * Implement ConstructionCombine * Implement ConstructionHash * Implement ConstructionSubmit * Ensure RLPbytes & From is present in WrappedTransaction when unpackWrappedTransactionFromHexString is called Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor construction into separate files * Move tests into appropriate files Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_check_test.go * Update edge case for getSuggestedFeeAndPrice found during testing Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_parse_test.go * Clarify names for construction_create_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix ConstructionParse to not use crypto.PubkeyToAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix UnmarshalFromInterface for CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add operation_components_test.go * Implement TestGetContractCreationOperationComponents * Implement TestGetCrossShardOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Finish operation_components_test.go * Implement TestGetTransferOperationComponents * Implement TestGetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix big number checks for getTransferOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement transaction_construction_test.go * Implement TestConstructPlainTransaction * Implement TestConstructCrossShardTransaction * Implement TestConstructContractCreationTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add shard ID checks for constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add bad curve test for TestGetAddressFromPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add nil error catches for Construction API * Fix nits in messages as seen during pass * Add DefaultGasLimit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add trace message with version to all err msgs * Add NewError unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add TestGetAddressFromKnownPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Fix possible nil ptr crash for GetBlockSigners Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Edge case bug fixes * Create empty TransactionMetdata if no metadata is provided in operations. Also update tests to correctly account for the behavior. * In pre-staking era make current block one less than the absolute latest to guarentee calculation of pres-taking eara block rewards. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix unpackWrappedTransactionFromHexString * Rename function to unpackWrappedTransactionFromString * Update respective tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make parsed transaction statuses empty Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Remove needles list initialization Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add SignatureType & SignedPayloadLength with checks Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix genesis network status crash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Correct error message dumps for transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add OperationType to ConstructMetadataOptions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix rosetta service rebase Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Fix estimate gas fail check Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add formatNegativeValue to ensure there's only 1 zero * Correct regression found in constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add contract creation estimate gas hack Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add DefaultSenderAddress for transaction formatter * Update Construction API parser to reflect change Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Address PR comments * Add GetCallStackInfo to internal utils * Add EstimateGas TODO in RPC package * Remove DefaultGasLimit to use param gas limit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add checks to tx formatter for nil to addr * Remove needless block check for genesisBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove EstimatedGasUsed from WrappedTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
evmErrorMsg := ""
evmReturn := hexutil.Bytes{}
if !isStakingOperation(options.OperationType) &&
options.OperationType != common.ContractCreationOperation &&
len(data) > 0 {
gas := hexutil.Uint64(estGasUsed)
callArgs := rpc.CallArgs{
From: senderAddr,
To: &contractAddress,
Data: &data,
Gas: &gas,
}
evmExe, err := rpc.DoEVMCall(
ctx, s.hmy, callArgs, ethRpc.LatestBlockNumber, vm.Config{}, rpc.CallTimeout, s.hmy.RPCGasCap,
)
if err != nil {
return nil, common.NewError(common.CatchAllError, map[string]interface{}{
"message": errors.WithMessage(err, "unable to execute EVM").Error(),
})
}
if evmExe.VMErr != nil {
evmErrorMsg = evmExe.VMErr.Error()
}
evmReturn = evmExe.ReturnData
sugNativeFee, sugNativePrice = getSuggestedNativeFeeAndPrice(gasMul, new(big.Int).SetUint64(evmExe.UsedGas))
}
Rosetta Implementation - pt4 (Stage 3.4 of Node API Overhaul) (#3380) * [rosetta] Add /construct function framework Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add network ID check to all construct endpoints Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add UnsupportedCurveTypeError Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement ConstructionDerive & add ConstructAPI router Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make recover middleware the outermost middleware Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Correct error for block not found Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Expose EstimateGas Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add InvalidTransactionConstructionError * Add GetValidConstructionOperations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make TransactionMetadata optional ptr * Add UnmarshalFromInterface for TransactionMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add InvalidTransactionConstructionError to network response Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ConstructionPreprocess & ConstructionMetadata skeleton * Add Helper methods for said functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add GasPrice to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make suggested gas fee & price its own fn Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add To & From Account ID in tx metadata * remove getAmountFromUndelegateMessage * make contract address a valid account identifier * remove needless metadata in non-staking operations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error report for b32 error in newAccountIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Simplify assertValidNetworkIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Use sdk MapMarshall instead of rpc structured response * remove unused GetValidConstructionOperations * Add CurrencyHash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement assertValidTransferOperationsAndGetTxAccounts * refactor usages of rpc structured response for sdk map marshall * add account identifier checks for transaction metadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Max related operation check more general for tx op check * refactor names for readability Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add & Expose OperationComponents * Remove txAccounts & add OperationComponents to metadata for quicker processing * Remove From & To acc ID from TransactionMetadata as it's in OperationComponents * Update tests for changes Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add tx type to OperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add logs to TransactionMetadata * Enforce Operation type uniqueness invariant for each transaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error for 3+ operations in getOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Expose GetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add staking operation medata type declaration Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix error messages & update comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getCrossShardOperationComponents * rename txAccs to components for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getContractCreationOperationComponents * Fix some edge case optional checks for operation validation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [go.mod] Bump rosetta version to 0.4.4 & dependent libs * Update broken rosetta structs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ChainID to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename PreStakingBlockRewardOperation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Init operation_components.go & move respective code Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor formatTransaction for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Move maxNumOfConstructionOps to operation_components.go * Clarify unsupported type err msg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement framework for ConstructionPayloads * Remove currying OperationComponents in metadata as PublicKeys is now part of the request in the necessary endpoints * Add respective checks for added PublicKeys * Make getAddressFromPublicKey more general & update tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add getAddress and update respective functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Create transaction_construction.go & impl ConstructTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add unmarshal check for ConstructMetadata & ConstructMetadataOptions * Remove constructTransaction * Wrap unsigned transaction with UnsignedTransaction to include intended signer * Add framework for ConstructionParse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add getSigningPayload method to construction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal/commonm] Add MustGeneratePrivateKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseUnsignedTransaction * Add unpackWrappedTransactionFromHexString & refactor rlp encoding of transactions * Make getSigningPayload return a list Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add TestUnpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseSignedTransaction * Move unpackWrappedTransactionFromHexString to ConstructionParse before parsing transactions bases on if it's signed or not Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix WrappedTransaction comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add extra negative tests for unpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Finish initial Construct implementation * Implement ConstructionCombine * Implement ConstructionHash * Implement ConstructionSubmit * Ensure RLPbytes & From is present in WrappedTransaction when unpackWrappedTransactionFromHexString is called Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor construction into separate files * Move tests into appropriate files Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_check_test.go * Update edge case for getSuggestedFeeAndPrice found during testing Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_parse_test.go * Clarify names for construction_create_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix ConstructionParse to not use crypto.PubkeyToAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix UnmarshalFromInterface for CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add operation_components_test.go * Implement TestGetContractCreationOperationComponents * Implement TestGetCrossShardOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Finish operation_components_test.go * Implement TestGetTransferOperationComponents * Implement TestGetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix big number checks for getTransferOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement transaction_construction_test.go * Implement TestConstructPlainTransaction * Implement TestConstructCrossShardTransaction * Implement TestConstructContractCreationTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add shard ID checks for constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add bad curve test for TestGetAddressFromPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add nil error catches for Construction API * Fix nits in messages as seen during pass * Add DefaultGasLimit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add trace message with version to all err msgs * Add NewError unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add TestGetAddressFromKnownPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Fix possible nil ptr crash for GetBlockSigners Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Edge case bug fixes * Create empty TransactionMetdata if no metadata is provided in operations. Also update tests to correctly account for the behavior. * In pre-staking era make current block one less than the absolute latest to guarentee calculation of pres-taking eara block rewards. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix unpackWrappedTransactionFromHexString * Rename function to unpackWrappedTransactionFromString * Update respective tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make parsed transaction statuses empty Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Remove needles list initialization Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add SignatureType & SignedPayloadLength with checks Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix genesis network status crash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Correct error message dumps for transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add OperationType to ConstructMetadataOptions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix rosetta service rebase Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Fix estimate gas fail check Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add formatNegativeValue to ensure there's only 1 zero * Correct regression found in constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add contract creation estimate gas hack Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add DefaultSenderAddress for transaction formatter * Update Construction API parser to reflect change Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Address PR comments * Add GetCallStackInfo to internal utils * Add EstimateGas TODO in RPC package * Remove DefaultGasLimit to use param gas limit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add checks to tx formatter for nil to addr * Remove needless block check for genesisBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove EstimatedGasUsed from WrappedTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
metadata, err := types.MarshalMap(ConstructMetadata{
Nonce: nonce,
GasPrice: sugNativePrice,
GasLimit: estGasUsed,
Transaction: options.TransactionMetadata,
ContractCode: state.GetCode(contractAddress),
EvmErrorMessage: evmErrorMsg,
EvmReturn: evmReturn,
Rosetta Implementation - pt4 (Stage 3.4 of Node API Overhaul) (#3380) * [rosetta] Add /construct function framework Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add network ID check to all construct endpoints Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add UnsupportedCurveTypeError Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement ConstructionDerive & add ConstructAPI router Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make recover middleware the outermost middleware Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Correct error for block not found Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Expose EstimateGas Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add InvalidTransactionConstructionError * Add GetValidConstructionOperations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make TransactionMetadata optional ptr * Add UnmarshalFromInterface for TransactionMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add InvalidTransactionConstructionError to network response Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ConstructionPreprocess & ConstructionMetadata skeleton * Add Helper methods for said functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add GasPrice to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make suggested gas fee & price its own fn Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add To & From Account ID in tx metadata * remove getAmountFromUndelegateMessage * make contract address a valid account identifier * remove needless metadata in non-staking operations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error report for b32 error in newAccountIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Simplify assertValidNetworkIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Use sdk MapMarshall instead of rpc structured response * remove unused GetValidConstructionOperations * Add CurrencyHash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement assertValidTransferOperationsAndGetTxAccounts * refactor usages of rpc structured response for sdk map marshall * add account identifier checks for transaction metadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Max related operation check more general for tx op check * refactor names for readability Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add & Expose OperationComponents * Remove txAccounts & add OperationComponents to metadata for quicker processing * Remove From & To acc ID from TransactionMetadata as it's in OperationComponents * Update tests for changes Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add tx type to OperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add logs to TransactionMetadata * Enforce Operation type uniqueness invariant for each transaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error for 3+ operations in getOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Expose GetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add staking operation medata type declaration Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix error messages & update comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getCrossShardOperationComponents * rename txAccs to components for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getContractCreationOperationComponents * Fix some edge case optional checks for operation validation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [go.mod] Bump rosetta version to 0.4.4 & dependent libs * Update broken rosetta structs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ChainID to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename PreStakingBlockRewardOperation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Init operation_components.go & move respective code Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor formatTransaction for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Move maxNumOfConstructionOps to operation_components.go * Clarify unsupported type err msg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement framework for ConstructionPayloads * Remove currying OperationComponents in metadata as PublicKeys is now part of the request in the necessary endpoints * Add respective checks for added PublicKeys * Make getAddressFromPublicKey more general & update tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add getAddress and update respective functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Create transaction_construction.go & impl ConstructTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add unmarshal check for ConstructMetadata & ConstructMetadataOptions * Remove constructTransaction * Wrap unsigned transaction with UnsignedTransaction to include intended signer * Add framework for ConstructionParse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add getSigningPayload method to construction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal/commonm] Add MustGeneratePrivateKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseUnsignedTransaction * Add unpackWrappedTransactionFromHexString & refactor rlp encoding of transactions * Make getSigningPayload return a list Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add TestUnpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseSignedTransaction * Move unpackWrappedTransactionFromHexString to ConstructionParse before parsing transactions bases on if it's signed or not Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix WrappedTransaction comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add extra negative tests for unpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Finish initial Construct implementation * Implement ConstructionCombine * Implement ConstructionHash * Implement ConstructionSubmit * Ensure RLPbytes & From is present in WrappedTransaction when unpackWrappedTransactionFromHexString is called Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor construction into separate files * Move tests into appropriate files Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_check_test.go * Update edge case for getSuggestedFeeAndPrice found during testing Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_parse_test.go * Clarify names for construction_create_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix ConstructionParse to not use crypto.PubkeyToAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix UnmarshalFromInterface for CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add operation_components_test.go * Implement TestGetContractCreationOperationComponents * Implement TestGetCrossShardOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Finish operation_components_test.go * Implement TestGetTransferOperationComponents * Implement TestGetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix big number checks for getTransferOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement transaction_construction_test.go * Implement TestConstructPlainTransaction * Implement TestConstructCrossShardTransaction * Implement TestConstructContractCreationTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add shard ID checks for constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add bad curve test for TestGetAddressFromPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add nil error catches for Construction API * Fix nits in messages as seen during pass * Add DefaultGasLimit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add trace message with version to all err msgs * Add NewError unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add TestGetAddressFromKnownPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Fix possible nil ptr crash for GetBlockSigners Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Edge case bug fixes * Create empty TransactionMetdata if no metadata is provided in operations. Also update tests to correctly account for the behavior. * In pre-staking era make current block one less than the absolute latest to guarentee calculation of pres-taking eara block rewards. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix unpackWrappedTransactionFromHexString * Rename function to unpackWrappedTransactionFromString * Update respective tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make parsed transaction statuses empty Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Remove needles list initialization Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add SignatureType & SignedPayloadLength with checks Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix genesis network status crash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Correct error message dumps for transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add OperationType to ConstructMetadataOptions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix rosetta service rebase Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Fix estimate gas fail check Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add formatNegativeValue to ensure there's only 1 zero * Correct regression found in constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add contract creation estimate gas hack Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add DefaultSenderAddress for transaction formatter * Update Construction API parser to reflect change Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Address PR comments * Add GetCallStackInfo to internal utils * Add EstimateGas TODO in RPC package * Remove DefaultGasLimit to use param gas limit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add checks to tx formatter for nil to addr * Remove needless block check for genesisBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove EstimatedGasUsed from WrappedTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
})
if err != nil {
return nil, common.NewError(common.CatchAllError, map[string]interface{}{
"message": err.Error(),
})
}
return &types.ConstructionMetadataResponse{
Metadata: metadata,
Rosetta Implementation Cleanup (Stage 3 of Node API Overhaul) (#3390) * [core] Add FindLogsWithTopic & unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Add GetDetailedBlockSignerInfo Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Add IsCommitteeSelectionBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [test] Add test transaction creation helpers Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Refactor account.go & add tests * Move TestNewAccountIdentifier & TestGetAddress to account_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Move Operation & Tx formatting to own files * Move Respective unit tests to own files * Expose GetOperations & GetStakingOperations * Expose FormatTransaction, FormatCrossShardReceiverTransaction, FormatGenesisTransaction, FormatPreStakingRewardTransaction & FormatUndelegationPayoutTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Move TransactionMetadata to transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Update construction to use new helpers & formatters * Make docs consistent for mempool.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Move all special tx & blk handling to own file Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove all moved fns, methods & tests from block.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * Fix lint & imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename all tx related files for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename DefaultSenderAddress to FormatDefaultSenderAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename Currency to NativeCurrency * This is in anticipation of HRC20 token support with rosetta * Rename various native operation functions accordingly * Add documentation to explain what a native token is Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix pre-staking block reward calculation * Move getPreStakingRewardTransactionIdentifiers to block_special.go * Add epoch to block metadata * Update unit tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * Add IsLastBlockInEpoch method to Block & Header * Refactor all uses of length check `ShardState` * [hmy] Refactor IsCommitteeSelectionBlock to use chain.IsCommitteeSelectionBlock * Address PR comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Update var names in preStakingRewardBlockTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
SuggestedFee: sugNativeFee,
Rosetta Implementation - pt4 (Stage 3.4 of Node API Overhaul) (#3380) * [rosetta] Add /construct function framework Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add network ID check to all construct endpoints Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add UnsupportedCurveTypeError Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement ConstructionDerive & add ConstructAPI router Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make recover middleware the outermost middleware Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Correct error for block not found Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Expose EstimateGas Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add InvalidTransactionConstructionError * Add GetValidConstructionOperations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make TransactionMetadata optional ptr * Add UnmarshalFromInterface for TransactionMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add InvalidTransactionConstructionError to network response Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ConstructionPreprocess & ConstructionMetadata skeleton * Add Helper methods for said functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add GasPrice to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make suggested gas fee & price its own fn Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add To & From Account ID in tx metadata * remove getAmountFromUndelegateMessage * make contract address a valid account identifier * remove needless metadata in non-staking operations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error report for b32 error in newAccountIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Simplify assertValidNetworkIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Use sdk MapMarshall instead of rpc structured response * remove unused GetValidConstructionOperations * Add CurrencyHash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement assertValidTransferOperationsAndGetTxAccounts * refactor usages of rpc structured response for sdk map marshall * add account identifier checks for transaction metadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Max related operation check more general for tx op check * refactor names for readability Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add & Expose OperationComponents * Remove txAccounts & add OperationComponents to metadata for quicker processing * Remove From & To acc ID from TransactionMetadata as it's in OperationComponents * Update tests for changes Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add tx type to OperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add logs to TransactionMetadata * Enforce Operation type uniqueness invariant for each transaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error for 3+ operations in getOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Expose GetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add staking operation medata type declaration Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix error messages & update comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getCrossShardOperationComponents * rename txAccs to components for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getContractCreationOperationComponents * Fix some edge case optional checks for operation validation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [go.mod] Bump rosetta version to 0.4.4 & dependent libs * Update broken rosetta structs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ChainID to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename PreStakingBlockRewardOperation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Init operation_components.go & move respective code Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor formatTransaction for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Move maxNumOfConstructionOps to operation_components.go * Clarify unsupported type err msg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement framework for ConstructionPayloads * Remove currying OperationComponents in metadata as PublicKeys is now part of the request in the necessary endpoints * Add respective checks for added PublicKeys * Make getAddressFromPublicKey more general & update tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add getAddress and update respective functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Create transaction_construction.go & impl ConstructTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add unmarshal check for ConstructMetadata & ConstructMetadataOptions * Remove constructTransaction * Wrap unsigned transaction with UnsignedTransaction to include intended signer * Add framework for ConstructionParse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add getSigningPayload method to construction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal/commonm] Add MustGeneratePrivateKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseUnsignedTransaction * Add unpackWrappedTransactionFromHexString & refactor rlp encoding of transactions * Make getSigningPayload return a list Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add TestUnpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseSignedTransaction * Move unpackWrappedTransactionFromHexString to ConstructionParse before parsing transactions bases on if it's signed or not Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix WrappedTransaction comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add extra negative tests for unpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Finish initial Construct implementation * Implement ConstructionCombine * Implement ConstructionHash * Implement ConstructionSubmit * Ensure RLPbytes & From is present in WrappedTransaction when unpackWrappedTransactionFromHexString is called Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor construction into separate files * Move tests into appropriate files Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_check_test.go * Update edge case for getSuggestedFeeAndPrice found during testing Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_parse_test.go * Clarify names for construction_create_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix ConstructionParse to not use crypto.PubkeyToAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix UnmarshalFromInterface for CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add operation_components_test.go * Implement TestGetContractCreationOperationComponents * Implement TestGetCrossShardOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Finish operation_components_test.go * Implement TestGetTransferOperationComponents * Implement TestGetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix big number checks for getTransferOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement transaction_construction_test.go * Implement TestConstructPlainTransaction * Implement TestConstructCrossShardTransaction * Implement TestConstructContractCreationTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add shard ID checks for constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add bad curve test for TestGetAddressFromPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add nil error catches for Construction API * Fix nits in messages as seen during pass * Add DefaultGasLimit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add trace message with version to all err msgs * Add NewError unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add TestGetAddressFromKnownPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Fix possible nil ptr crash for GetBlockSigners Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Edge case bug fixes * Create empty TransactionMetdata if no metadata is provided in operations. Also update tests to correctly account for the behavior. * In pre-staking era make current block one less than the absolute latest to guarentee calculation of pres-taking eara block rewards. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix unpackWrappedTransactionFromHexString * Rename function to unpackWrappedTransactionFromString * Update respective tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make parsed transaction statuses empty Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Remove needles list initialization Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add SignatureType & SignedPayloadLength with checks Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix genesis network status crash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Correct error message dumps for transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add OperationType to ConstructMetadataOptions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix rosetta service rebase Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Fix estimate gas fail check Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add formatNegativeValue to ensure there's only 1 zero * Correct regression found in constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add contract creation estimate gas hack Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add DefaultSenderAddress for transaction formatter * Update Construction API parser to reflect change Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Address PR comments * Add GetCallStackInfo to internal utils * Add EstimateGas TODO in RPC package * Remove DefaultGasLimit to use param gas limit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add checks to tx formatter for nil to addr * Remove needless block check for genesisBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove EstimatedGasUsed from WrappedTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
}, nil
}
Rosetta Implementation Cleanup (Stage 3 of Node API Overhaul) (#3390) * [core] Add FindLogsWithTopic & unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Add GetDetailedBlockSignerInfo Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Add IsCommitteeSelectionBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [test] Add test transaction creation helpers Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Refactor account.go & add tests * Move TestNewAccountIdentifier & TestGetAddress to account_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Move Operation & Tx formatting to own files * Move Respective unit tests to own files * Expose GetOperations & GetStakingOperations * Expose FormatTransaction, FormatCrossShardReceiverTransaction, FormatGenesisTransaction, FormatPreStakingRewardTransaction & FormatUndelegationPayoutTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Move TransactionMetadata to transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Update construction to use new helpers & formatters * Make docs consistent for mempool.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Move all special tx & blk handling to own file Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove all moved fns, methods & tests from block.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * Fix lint & imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename all tx related files for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename DefaultSenderAddress to FormatDefaultSenderAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename Currency to NativeCurrency * This is in anticipation of HRC20 token support with rosetta * Rename various native operation functions accordingly * Add documentation to explain what a native token is Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix pre-staking block reward calculation * Move getPreStakingRewardTransactionIdentifiers to block_special.go * Add epoch to block metadata * Update unit tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * Add IsLastBlockInEpoch method to Block & Header * Refactor all uses of length check `ShardState` * [hmy] Refactor IsCommitteeSelectionBlock to use chain.IsCommitteeSelectionBlock * Address PR comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Update var names in preStakingRewardBlockTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
// getSuggestedNativeFeeAndPrice ..
func getSuggestedNativeFeeAndPrice(
Rosetta Implementation - pt4 (Stage 3.4 of Node API Overhaul) (#3380) * [rosetta] Add /construct function framework Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add network ID check to all construct endpoints Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add UnsupportedCurveTypeError Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement ConstructionDerive & add ConstructAPI router Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make recover middleware the outermost middleware Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Correct error for block not found Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Expose EstimateGas Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add InvalidTransactionConstructionError * Add GetValidConstructionOperations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make TransactionMetadata optional ptr * Add UnmarshalFromInterface for TransactionMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add InvalidTransactionConstructionError to network response Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ConstructionPreprocess & ConstructionMetadata skeleton * Add Helper methods for said functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add GasPrice to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make suggested gas fee & price its own fn Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add To & From Account ID in tx metadata * remove getAmountFromUndelegateMessage * make contract address a valid account identifier * remove needless metadata in non-staking operations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error report for b32 error in newAccountIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Simplify assertValidNetworkIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Use sdk MapMarshall instead of rpc structured response * remove unused GetValidConstructionOperations * Add CurrencyHash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement assertValidTransferOperationsAndGetTxAccounts * refactor usages of rpc structured response for sdk map marshall * add account identifier checks for transaction metadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Max related operation check more general for tx op check * refactor names for readability Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add & Expose OperationComponents * Remove txAccounts & add OperationComponents to metadata for quicker processing * Remove From & To acc ID from TransactionMetadata as it's in OperationComponents * Update tests for changes Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add tx type to OperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add logs to TransactionMetadata * Enforce Operation type uniqueness invariant for each transaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error for 3+ operations in getOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Expose GetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add staking operation medata type declaration Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix error messages & update comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getCrossShardOperationComponents * rename txAccs to components for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getContractCreationOperationComponents * Fix some edge case optional checks for operation validation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [go.mod] Bump rosetta version to 0.4.4 & dependent libs * Update broken rosetta structs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ChainID to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename PreStakingBlockRewardOperation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Init operation_components.go & move respective code Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor formatTransaction for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Move maxNumOfConstructionOps to operation_components.go * Clarify unsupported type err msg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement framework for ConstructionPayloads * Remove currying OperationComponents in metadata as PublicKeys is now part of the request in the necessary endpoints * Add respective checks for added PublicKeys * Make getAddressFromPublicKey more general & update tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add getAddress and update respective functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Create transaction_construction.go & impl ConstructTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add unmarshal check for ConstructMetadata & ConstructMetadataOptions * Remove constructTransaction * Wrap unsigned transaction with UnsignedTransaction to include intended signer * Add framework for ConstructionParse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add getSigningPayload method to construction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal/commonm] Add MustGeneratePrivateKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseUnsignedTransaction * Add unpackWrappedTransactionFromHexString & refactor rlp encoding of transactions * Make getSigningPayload return a list Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add TestUnpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseSignedTransaction * Move unpackWrappedTransactionFromHexString to ConstructionParse before parsing transactions bases on if it's signed or not Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix WrappedTransaction comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add extra negative tests for unpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Finish initial Construct implementation * Implement ConstructionCombine * Implement ConstructionHash * Implement ConstructionSubmit * Ensure RLPbytes & From is present in WrappedTransaction when unpackWrappedTransactionFromHexString is called Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor construction into separate files * Move tests into appropriate files Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_check_test.go * Update edge case for getSuggestedFeeAndPrice found during testing Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_parse_test.go * Clarify names for construction_create_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix ConstructionParse to not use crypto.PubkeyToAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix UnmarshalFromInterface for CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add operation_components_test.go * Implement TestGetContractCreationOperationComponents * Implement TestGetCrossShardOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Finish operation_components_test.go * Implement TestGetTransferOperationComponents * Implement TestGetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix big number checks for getTransferOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement transaction_construction_test.go * Implement TestConstructPlainTransaction * Implement TestConstructCrossShardTransaction * Implement TestConstructContractCreationTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add shard ID checks for constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add bad curve test for TestGetAddressFromPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add nil error catches for Construction API * Fix nits in messages as seen during pass * Add DefaultGasLimit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add trace message with version to all err msgs * Add NewError unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add TestGetAddressFromKnownPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Fix possible nil ptr crash for GetBlockSigners Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Edge case bug fixes * Create empty TransactionMetdata if no metadata is provided in operations. Also update tests to correctly account for the behavior. * In pre-staking era make current block one less than the absolute latest to guarentee calculation of pres-taking eara block rewards. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix unpackWrappedTransactionFromHexString * Rename function to unpackWrappedTransactionFromString * Update respective tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make parsed transaction statuses empty Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Remove needles list initialization Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add SignatureType & SignedPayloadLength with checks Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix genesis network status crash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Correct error message dumps for transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add OperationType to ConstructMetadataOptions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix rosetta service rebase Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Fix estimate gas fail check Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add formatNegativeValue to ensure there's only 1 zero * Correct regression found in constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add contract creation estimate gas hack Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add DefaultSenderAddress for transaction formatter * Update Construction API parser to reflect change Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Address PR comments * Add GetCallStackInfo to internal utils * Add EstimateGas TODO in RPC package * Remove DefaultGasLimit to use param gas limit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add checks to tx formatter for nil to addr * Remove needless block check for genesisBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove EstimatedGasUsed from WrappedTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
gasMul float64, estGasUsed *big.Int,
) ([]*types.Amount, *big.Int) {
if estGasUsed == nil {
estGasUsed = big.NewInt(0).SetUint64(params.TxGas)
}
if gasMul < 1 {
gasMul = 1
}
gasPriceFloat := big.NewFloat(0).Mul(big.NewFloat(DefaultGasPrice), big.NewFloat(gasMul))
gasPriceTruncated, _ := gasPriceFloat.Uint64()
gasPrice := new(big.Int).SetUint64(gasPriceTruncated)
return []*types.Amount{
{
Value: fmt.Sprintf("%v", new(big.Int).Mul(gasPrice, estGasUsed)),
Rosetta Implementation Cleanup (Stage 3 of Node API Overhaul) (#3390) * [core] Add FindLogsWithTopic & unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Add GetDetailedBlockSignerInfo Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Add IsCommitteeSelectionBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [test] Add test transaction creation helpers Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Refactor account.go & add tests * Move TestNewAccountIdentifier & TestGetAddress to account_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Move Operation & Tx formatting to own files * Move Respective unit tests to own files * Expose GetOperations & GetStakingOperations * Expose FormatTransaction, FormatCrossShardReceiverTransaction, FormatGenesisTransaction, FormatPreStakingRewardTransaction & FormatUndelegationPayoutTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Move TransactionMetadata to transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Update construction to use new helpers & formatters * Make docs consistent for mempool.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Move all special tx & blk handling to own file Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove all moved fns, methods & tests from block.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * Fix lint & imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename all tx related files for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename DefaultSenderAddress to FormatDefaultSenderAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename Currency to NativeCurrency * This is in anticipation of HRC20 token support with rosetta * Rename various native operation functions accordingly * Add documentation to explain what a native token is Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix pre-staking block reward calculation * Move getPreStakingRewardTransactionIdentifiers to block_special.go * Add epoch to block metadata * Update unit tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * Add IsLastBlockInEpoch method to Block & Header * Refactor all uses of length check `ShardState` * [hmy] Refactor IsCommitteeSelectionBlock to use chain.IsCommitteeSelectionBlock * Address PR comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Update var names in preStakingRewardBlockTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
Currency: &common.NativeCurrency,
Rosetta Implementation - pt4 (Stage 3.4 of Node API Overhaul) (#3380) * [rosetta] Add /construct function framework Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add network ID check to all construct endpoints Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add UnsupportedCurveTypeError Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement ConstructionDerive & add ConstructAPI router Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make recover middleware the outermost middleware Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Correct error for block not found Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Expose EstimateGas Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add InvalidTransactionConstructionError * Add GetValidConstructionOperations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make TransactionMetadata optional ptr * Add UnmarshalFromInterface for TransactionMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add InvalidTransactionConstructionError to network response Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ConstructionPreprocess & ConstructionMetadata skeleton * Add Helper methods for said functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add GasPrice to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make suggested gas fee & price its own fn Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add To & From Account ID in tx metadata * remove getAmountFromUndelegateMessage * make contract address a valid account identifier * remove needless metadata in non-staking operations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error report for b32 error in newAccountIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Simplify assertValidNetworkIdentifier Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Use sdk MapMarshall instead of rpc structured response * remove unused GetValidConstructionOperations * Add CurrencyHash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement assertValidTransferOperationsAndGetTxAccounts * refactor usages of rpc structured response for sdk map marshall * add account identifier checks for transaction metadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Max related operation check more general for tx op check * refactor names for readability Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add & Expose OperationComponents * Remove txAccounts & add OperationComponents to metadata for quicker processing * Remove From & To acc ID from TransactionMetadata as it's in OperationComponents * Update tests for changes Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add tx type to OperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add logs to TransactionMetadata * Enforce Operation type uniqueness invariant for each transaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add error for 3+ operations in getOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Expose GetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add staking operation medata type declaration Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix error messages & update comment Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getCrossShardOperationComponents * rename txAccs to components for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement getContractCreationOperationComponents * Fix some edge case optional checks for operation validation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [go.mod] Bump rosetta version to 0.4.4 & dependent libs * Update broken rosetta structs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add ChainID to ConstructMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Rename PreStakingBlockRewardOperation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Init operation_components.go & move respective code Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor formatTransaction for clarity Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Move maxNumOfConstructionOps to operation_components.go * Clarify unsupported type err msg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Implement framework for ConstructionPayloads * Remove currying OperationComponents in metadata as PublicKeys is now part of the request in the necessary endpoints * Add respective checks for added PublicKeys * Make getAddressFromPublicKey more general & update tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add getAddress and update respective functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Create transaction_construction.go & impl ConstructTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add unmarshal check for ConstructMetadata & ConstructMetadataOptions * Remove constructTransaction * Wrap unsigned transaction with UnsignedTransaction to include intended signer * Add framework for ConstructionParse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add getSigningPayload method to construction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal/commonm] Add MustGeneratePrivateKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseUnsignedTransaction * Add unpackWrappedTransactionFromHexString & refactor rlp encoding of transactions * Make getSigningPayload return a list Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add TestUnpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement parseSignedTransaction * Move unpackWrappedTransactionFromHexString to ConstructionParse before parsing transactions bases on if it's signed or not Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Nit - fix WrappedTransaction comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add extra negative tests for unpackWrappedTransactionFromHexString Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Finish initial Construct implementation * Implement ConstructionCombine * Implement ConstructionHash * Implement ConstructionSubmit * Ensure RLPbytes & From is present in WrappedTransaction when unpackWrappedTransactionFromHexString is called Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Refactor construction into separate files * Move tests into appropriate files Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_check_test.go * Update edge case for getSuggestedFeeAndPrice found during testing Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement construction_parse_test.go * Clarify names for construction_create_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix ConstructionParse to not use crypto.PubkeyToAddress Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix UnmarshalFromInterface for CrossShardTransactionOperationMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add operation_components_test.go * Implement TestGetContractCreationOperationComponents * Implement TestGetCrossShardOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Finish operation_components_test.go * Implement TestGetTransferOperationComponents * Implement TestGetOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix big number checks for getTransferOperationComponents Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement transaction_construction_test.go * Implement TestConstructPlainTransaction * Implement TestConstructCrossShardTransaction * Implement TestConstructContractCreationTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add shard ID checks for constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add bad curve test for TestGetAddressFromPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add nil error catches for Construction API * Fix nits in messages as seen during pass * Add DefaultGasLimit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add trace message with version to all err msgs * Add NewError unit test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add TestGetAddressFromKnownPublicKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Fix possible nil ptr crash for GetBlockSigners Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Edge case bug fixes * Create empty TransactionMetdata if no metadata is provided in operations. Also update tests to correctly account for the behavior. * In pre-staking era make current block one less than the absolute latest to guarentee calculation of pres-taking eara block rewards. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix unpackWrappedTransactionFromHexString * Rename function to unpackWrappedTransactionFromString * Update respective tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Make parsed transaction statuses empty Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Remove needles list initialization Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add SignatureType & SignedPayloadLength with checks Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix genesis network status crash Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Correct error message dumps for transaction_construction.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add OperationType to ConstructMetadataOptions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Fix rosetta service rebase Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Fix estimate gas fail check Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add formatNegativeValue to ensure there's only 1 zero * Correct regression found in constructCrossShardTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> [rosetta] Add contract creation estimate gas hack Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add DefaultSenderAddress for transaction formatter * Update Construction API parser to reflect change Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Address PR comments * Add GetCallStackInfo to internal utils * Add EstimateGas TODO in RPC package * Remove DefaultGasLimit to use param gas limit Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add checks to tx formatter for nil to addr * Remove needless block check for genesisBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove EstimatedGasUsed from WrappedTransaction Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
},
}, gasPrice
}
// isStakingOperation ..
func isStakingOperation(op string) bool {
for _, stakingOp := range common.StakingOperationTypes {
if stakingOp == op {
return true
}
}
return false
}