-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtransaction.go
83 lines (71 loc) · 1.91 KB
/
transaction.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package infura
import "fmt"
type Transaction struct {
From string `json:"from"`
Gas string `json:"gas"`
GasPrice *string `json:"gasPrice"`
To *string `json:"to"`
Value *string `json:"value"`
Data string `json:"data"`
}
func (tx *Transaction) toMap() map[string]interface{} {
txMap := make(map[string]interface{})
txMap["from"] = tx.From
txMap["gas"] = tx.Gas
if tx.GasPrice != nil {
txMap["gasPrice"] = tx.GasPrice
}
if tx.To != nil {
txMap["to"] = *tx.To
}
if tx.Value != nil {
txMap["value"] = tx.Value
}
if len(tx.Data) == 0 {
txMap["data"] = "0x"
} else {
txMap["data"] = tx.Data
}
return txMap
}
func (tx *Transaction) String() string {
return fmt.Sprintf("from: %v\nto: %v\ngas: %v\ngasPrice: %v\nvalue: %v\ndata: %v\n", tx.From, tx.To, tx.Gas, tx.GasPrice, tx.Value, tx.Data)
}
type RawTransaction struct {
Transaction
BlockHash string `json:"blockHash"`
BlockNumber *string `json:"blockNumber"`
Hash string `json:"hash"`
Input string `json:"input"`
Nonce string `json:"nonce"`
R string `json:"r"`
S string `json:"s"`
TransactionIndex string `json:"transactionIndex"`
V string `json:"v"`
// Parity only
// Condition *string `json:"condition"`
// ChainId *int `json:"chain_id"`
// Creates *string `json:"creates"`
// PublicKey *string `json:"public_key"`
// Raw *string `json:"raw"`
// StandardV *int `json:"standard_v"`
}
func (tx *RawTransaction) String() string {
return fmt.Sprintf("from: %v\nto: %v\ngas: %v\ngasPrice: %v\nvalue: %v\ndata: %v\nblockHash: %v\nblockNumber: %v\nhash: %v\ninput: %v\nnounce: %v\nr: %v\ns: %v\nv: %v\ntransactionIndex: %v\n",
tx.From,
tx.To,
tx.Gas,
tx.GasPrice,
tx.Value,
tx.Data,
tx.BlockHash,
tx.BlockNumber,
tx.Hash,
tx.Input,
tx.Nonce,
tx.R,
tx.S,
tx.V,
tx.TransactionIndex,
)
}