diff --git a/api/types.go b/api/types.go index 5a506944..776f9c43 100644 --- a/api/types.go +++ b/api/types.go @@ -175,6 +175,7 @@ type EthereumSpecific struct { GasLimit *big.Int `json:"gasLimit"` GasUsed *big.Int `json:"gasUsed"` GasPrice *Amount `json:"gasPrice"` + Data string `json:"data,omitempty"` } // Tx holds information about a transaction diff --git a/api/worker.go b/api/worker.go index 74e676bc..95c66b35 100644 --- a/api/worker.go +++ b/api/worker.go @@ -293,6 +293,7 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height int, spe GasUsed: ethTxData.GasUsed, Nonce: ethTxData.Nonce, Status: ethTxData.Status, + Data: ethTxData.Data, } } // for now do not return size, we would have to compute vsize of segwit transactions diff --git a/bchain/coins/eth/ethparser.go b/bchain/coins/eth/ethparser.go index 5cfe88f9..a9911f4f 100644 --- a/bchain/coins/eth/ethparser.go +++ b/bchain/coins/eth/ethparser.go @@ -475,6 +475,7 @@ type EthereumTxData struct { GasLimit *big.Int `json:"gaslimit"` GasUsed *big.Int `json:"gasused"` GasPrice *big.Int `json:"gasprice"` + Data string `json:"data"` } // GetEthereumTxData returns EthereumTxData from bchain.Tx @@ -486,6 +487,7 @@ func GetEthereumTxData(tx *bchain.Tx) *EthereumTxData { etd.Nonce, _ = hexutil.DecodeUint64(csd.Tx.AccountNonce) etd.GasLimit, _ = hexutil.DecodeBig(csd.Tx.GasLimit) etd.GasPrice, _ = hexutil.DecodeBig(csd.Tx.GasPrice) + etd.Data = csd.Tx.Payload } if csd.Receipt != nil { switch csd.Receipt.Status { diff --git a/bchain/coins/eth/ethparser_test.go b/bchain/coins/eth/ethparser_test.go index e05874e6..cad6f349 100644 --- a/bchain/coins/eth/ethparser_test.go +++ b/bchain/coins/eth/ethparser_test.go @@ -266,3 +266,30 @@ func TestEthereumParser_UnpackTx(t *testing.T) { }) } } + +func TestEthereumParser_GetEthereumTxData(t *testing.T) { + tests := []struct { + name string + tx *bchain.Tx + want string + }{ + { + name: "Test empty data", + tx: &testTx1, + want: "0x", + }, + { + name: "Test non empty data", + tx: &testTx2, + want: "0xa9059cbb000000000000000000000000555ee11fbddc0e49a9bab358a8941ad95ffdb48f00000000000000000000000000000000000000000000021e19e0c9bab2400000", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := GetEthereumTxData(tt.tx) + if got.Data != tt.want { + t.Errorf("EthereumParser.GetEthereumTxData() = %v, want %v", got.Data, tt.want) + } + }) + } +}