-
Notifications
You must be signed in to change notification settings - Fork 13
/
types.go
72 lines (63 loc) · 2.23 KB
/
types.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
package common
import (
ethcommon "github.com/ethereum/go-ethereum/common"
ethTypes "github.com/ethereum/go-ethereum/core/types"
)
//Genesis File Structure
type Genesis struct {
Alloc AccountMap
Poa PoaMap
}
//AccountMap holds the alloc section of the genesis file
type AccountMap map[string]struct {
Code string `json:"code"`
Storage map[string]string `json:"storage"`
Balance string `json:"balance"`
Authorising bool `json:"authorising"`
Nonce uint64 `json:"nonce,omitempty"`
}
//PoaMap holds the poa section of the genesis file
type PoaMap struct {
Address string
Balance string
Storage map[string]string
Abi string
Code string
Nonce uint64 `json:"nonce,omitempty"`
}
//JSONReceipt is the JSON structure for the return receipt from the tx end
//point
type JSONReceipt struct {
Root ethcommon.Hash `json:"root"`
TransactionHash ethcommon.Hash `json:"transactionHash"`
From ethcommon.Address `json:"from"`
To *ethcommon.Address `json:"to"`
GasUsed uint64 `json:"gasUsed"`
CumulativeGasUsed uint64 `json:"cumulativeGasUsed"`
ContractAddress ethcommon.Address `json:"contractAddress"`
Logs []*ethTypes.Log `json:"logs"`
LogsBloom ethTypes.Bloom `json:"logsBloom"`
Status uint64 `json:"status"`
}
// ToJSONReceipt uses a transaction, its from address, and a receipt to create
// a JSONReceipt. The "from" addressed is derived from the transaction's
// signature.
func ToJSONReceipt(receipt *ethTypes.Receipt, tx *ethTypes.Transaction, signer ethTypes.Signer) *JSONReceipt {
from, _ := ethTypes.Sender(signer, tx)
jsonReceipt := JSONReceipt{
Root: ethcommon.BytesToHash(receipt.PostState),
TransactionHash: tx.Hash(),
From: from,
To: tx.To(),
GasUsed: receipt.GasUsed,
CumulativeGasUsed: receipt.CumulativeGasUsed,
ContractAddress: receipt.ContractAddress,
Logs: receipt.Logs,
LogsBloom: receipt.Bloom,
Status: receipt.Status,
}
if receipt.Logs == nil {
jsonReceipt.Logs = []*ethTypes.Log{}
}
return &jsonReceipt
}