-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtransaction_receipt.go
61 lines (53 loc) · 1.7 KB
/
transaction_receipt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package getho
import (
"encoding/json"
"math/big"
"strconv"
)
type TransactionReceipt struct {
BlockHash *string `json:"blockHash"`
BlockNumber *big.Int `json:"blockNumber"`
ContractAddress *string `json:"contractAddress"`
CumulativeGasUsed *uint64 `json:"cumulativeGasUsed"`
From string `json:"from"`
GasUsed uint64 `json:"gasUsed"`
Logs interface{} `json:"logs"`
LogsBloom string `json:"logsBloom"`
To *string `json:"to"`
TransactionHash string `json:"transactionHash"`
TransactionIndex *uint64 `json:"transactionIndex"`
Root *string `json:"root"`
Status string `json:"status"`
}
func (r *TransactionReceipt) UnmarshalJSON(data []byte) error {
type Alias TransactionReceipt
a := &struct {
BlockNumber *string `json:"blockNumber"`
CumulativeGasUsed *string `json:"cumulativeGasUsed"`
GasUsed *string `json:"gasUsed"`
TransactionIndex *string `json:"transactionIndex"`
*Alias
}{
Alias: (*Alias)(r),
}
if err := json.Unmarshal(data, &a); err != nil {
return err
}
if a.BlockNumber != nil {
blkNumber, _ := new(big.Int).SetString(remove0x(*a.BlockNumber), 16)
r.BlockNumber = blkNumber
}
if a.CumulativeGasUsed != nil {
cumulativeGasUsed, _ := strconv.ParseUint(remove0x(*a.CumulativeGasUsed), 16, 64)
r.CumulativeGasUsed = &cumulativeGasUsed
}
if a.GasUsed != nil {
gasUsed, _ := strconv.ParseUint(remove0x(*a.GasUsed), 16, 64)
r.GasUsed = gasUsed
}
if a.TransactionIndex != nil {
txIndex, _ := strconv.ParseUint(remove0x(*a.TransactionIndex), 16, 64)
r.TransactionIndex = &txIndex
}
return nil
}