forked from hyperledger-labs/yui-ibc-solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eth.go
117 lines (97 loc) · 3.05 KB
/
eth.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package client
import (
"context"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
)
func NewETHClient(endpoint string, clientType string) (*Client, error) {
conn, err := rpc.DialHTTP(endpoint)
if err != nil {
return nil, err
}
return &Client{
endpoint: endpoint,
clientType: clientType,
conn: conn,
ETHClient: ethClient{Client: ethclient.NewClient(conn)},
}, nil
}
type ethReceipt struct {
// Consensus fields: These fields are defined by the Yellow Paper
PostState_ []byte `json:"root"`
Status_ uint64 `json:"status"`
CumulativeGasUsed_ uint64 `json:"cumulativeGasUsed" gencodec:"required"`
Bloom_ types.Bloom `json:"logsBloom" gencodec:"required"`
Logs_ []*types.Log `json:"logs" gencodec:"required"`
// Implementation fields: These fields are added by geth when processing a transaction.
// They are stored in the chain database.
TxHash_ common.Hash `json:"transactionHash" gencodec:"required"`
ContractAddress_ common.Address `json:"contractAddress"`
GasUsed_ uint64 `json:"gasUsed" gencodec:"required"`
// Inclusion information: These fields provide information about the inclusion of the
// transaction corresponding to this receipt.
BlockHash_ common.Hash `json:"blockHash,omitempty"`
BlockNumber_ *big.Int `json:"blockNumber,omitempty"`
TransactionIndex_ uint `json:"transactionIndex"`
}
func (rc ethReceipt) PostState() []byte {
return rc.PostState_
}
func (rc ethReceipt) Status() uint64 {
return rc.Status_
}
func (rc ethReceipt) CumulativeGasUsed() uint64 {
return rc.CumulativeGasUsed_
}
func (rc ethReceipt) Bloom() types.Bloom {
return rc.Bloom_
}
func (rc ethReceipt) Logs() []*types.Log {
return rc.Logs_
}
func (rc ethReceipt) TxHash() common.Hash {
return rc.TxHash_
}
func (rc ethReceipt) ContractAddress() common.Address {
return rc.ContractAddress_
}
func (rc ethReceipt) GasUsed() uint64 {
return rc.GasUsed_
}
func (rc ethReceipt) BlockHash() common.Hash {
return rc.BlockHash_
}
func (rc ethReceipt) BlockNumber() *big.Int {
return rc.BlockNumber_
}
func (rc ethReceipt) TransactionIndex() uint {
return rc.TransactionIndex_
}
func (rc ethReceipt) RevertReason() string {
return ""
}
type ethClient struct {
*ethclient.Client
}
func (cl ethClient) TransactionReceipt(ctx context.Context, txHash common.Hash) (Receipt, error) {
rc, err := cl.Client.TransactionReceipt(ctx, txHash)
if err != nil {
return nil, err
}
return ethReceipt{
PostState_: rc.PostState,
Status_: rc.Status,
CumulativeGasUsed_: rc.CumulativeGasUsed,
Bloom_: rc.Bloom,
Logs_: rc.Logs,
TxHash_: rc.TxHash,
ContractAddress_: rc.ContractAddress,
GasUsed_: rc.GasUsed,
BlockHash_: rc.BlockHash,
BlockNumber_: rc.BlockNumber,
TransactionIndex_: rc.TransactionIndex,
}, nil
}