Skip to content

Commit

Permalink
Merge pull request #113 from alejoacosta74/fix-gettxbyhash
Browse files Browse the repository at this point in the history
handle null BlockNumber and BlockHash in getTransactionByHash
  • Loading branch information
qtum-neil authored Oct 16, 2024
2 parents e06ac22 + 2a99ee6 commit fcbd873
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
22 changes: 22 additions & 0 deletions pkg/eth/rpc_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &params); err != nil {
Expand Down
7 changes: 5 additions & 2 deletions pkg/transformer/eth_getTransactionByHash.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ func getTransactionByHash(ctx context.Context, p *qtum.Qtum, hash string) (*eth.

if ethTx == nil {
ethTx = &eth.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",
Expand Down

0 comments on commit fcbd873

Please sign in to comment.