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",