Skip to content

Commit

Permalink
Add missing fields to txn
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt committed Apr 21, 2021
1 parent 89e2fdf commit 2e3b8ca
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
19 changes: 11 additions & 8 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,17 @@ type Block struct {
}

type Transaction struct {
Hash Hash
From Address
To *Address
Input []byte
GasPrice uint64
Gas uint64
Value *big.Int
Nonce uint64
Hash Hash
From Address
To *Address
Input []byte
GasPrice uint64
Gas uint64
Value *big.Int
Nonce uint64
BlockHash Hash
BlockNumber uint64
TxnIndex uint64
}

type CallMsg struct {
Expand Down
5 changes: 4 additions & 1 deletion structs_encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ func TestJSONEncoding(t *testing.T) {
"value": "0x0",
"gasPrice": "0x0",
"gas": "0x0",
"nonce": "0x10"
"nonce": "0x10",
"blockHash": "{{.Hash0}}",
"blockNumber": "0x0",
"transactionIndex": "0x0"
}`,
build: txn,
},
Expand Down
3 changes: 3 additions & 0 deletions structs_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ func (t *Transaction) MarshalJSON() ([]byte, error) {
// we can remove this once we include support for custom nonces
o.Set("nonce", a.NewString(fmt.Sprintf("0x%x", t.Nonce)))
}
o.Set("blockHash", a.NewString(t.BlockHash.String()))
o.Set("blockNumber", a.NewString(fmt.Sprintf("0x%x", t.BlockNumber)))
o.Set("transactionIndex", a.NewString(fmt.Sprintf("0x%x", t.TxnIndex)))

res := o.MarshalTo(nil)
defaultArena.Put(a)
Expand Down
10 changes: 10 additions & 0 deletions structs_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ func (t *Transaction) unmarshalJSON(v *fastjson.Value) error {
if t.Nonce, err = decodeUint(v, "nonce"); err != nil {
return err
}

if err = decodeHash(&t.BlockHash, v, "blockHash"); err != nil {
return err
}
if t.BlockNumber, err = decodeUint(v, "blockNumber"); err != nil {
return err
}
if t.TxnIndex, err = decodeUint(v, "transactionIndex"); err != nil {
return err
}
return nil
}

Expand Down

0 comments on commit 2e3b8ca

Please sign in to comment.