From 2a99ee6086ba28a0a76c53ea7936fd176a093c75 Mon Sep 17 00:00:00 2001 From: Alejo Acosta Date: Wed, 16 Oct 2024 14:57:05 -0300 Subject: [PATCH] handle null blocknumber in getTransactionByHash --- pkg/eth/rpc_types.go | 22 +++++++++++++++++++++ pkg/transformer/eth_getTransactionByHash.go | 7 +++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/pkg/eth/rpc_types.go b/pkg/eth/rpc_types.go index 9b4f72d1..e35aa2f6 100644 --- a/pkg/eth/rpc_types.go +++ b/pkg/eth/rpc_types.go @@ -275,6 +275,28 @@ type ( } ) +func (tx *GetTransactionByHashResponse) MarshalJSON() ([]byte, error) { + type Alias GetTransactionByHashResponse + return json.Marshal(&struct { + BlockHash interface{} `json:"blockHash"` + BlockNumber interface{} `json:"blockNumber"` + TransactionIndex interface{} `json:"transactionIndex"` + *Alias + }{ + BlockHash: nullIfEmpty(tx.BlockHash), + BlockNumber: nullIfEmpty(tx.BlockNumber), + TransactionIndex: nullIfEmpty(tx.TransactionIndex), + Alias: (*Alias)(tx), + }) +} + +func nullIfEmpty(s string) interface{} { + if s == "" { + return nil + } + return s +} + func (r *GetTransactionByHashRequest) UnmarshalJSON(data []byte) error { var params []interface{} if err := json.Unmarshal(data, ¶ms); err != nil { diff --git a/pkg/transformer/eth_getTransactionByHash.go b/pkg/transformer/eth_getTransactionByHash.go index 4155c75b..5407d80a 100644 --- a/pkg/transformer/eth_getTransactionByHash.go +++ b/pkg/transformer/eth_getTransactionByHash.go @@ -100,8 +100,11 @@ func getTransactionByHash(ctx context.Context, p *qtum.Qtum, hash string) (*eth. if ethTx == nil { ethTx = ð.GetTransactionByHashResponse{ - Hash: utils.AddHexPrefix(qtumDecodedRawTx.ID), - Nonce: "0x0", + Hash: utils.AddHexPrefix(qtumDecodedRawTx.ID), + Nonce: "0x0", + TransactionIndex: "", + BlockHash: "", + BlockNumber: "", // Added for go-ethereum client and graph-node support R: "0xf000000000000000000000000000000000000000000000000000000000000000",