-
Notifications
You must be signed in to change notification settings - Fork 29
/
types.go
206 lines (172 loc) · 7.69 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// Copyright 2022 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package construction
import (
"context"
"encoding/json"
"math/big"
evmClient "github.com/coinbase/rosetta-geth-sdk/client"
"github.com/coinbase/rosetta-geth-sdk/configuration"
RosettaTypes "github.com/coinbase/rosetta-sdk-go/types"
"github.com/ethereum/go-ethereum/common"
EthTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
)
// Client contains all the methods required to interact with go-ethereum based blockchain
type Client interface {
// Status returns the current status of the network
Status(
context.Context,
) (*RosettaTypes.BlockIdentifier,
int64,
*RosettaTypes.SyncStatus,
[]*RosettaTypes.Peer,
error,
)
// Balance is to fetch the state of an account based on the provided currencies
Balance(
context.Context,
*RosettaTypes.AccountIdentifier,
*RosettaTypes.PartialBlockIdentifier,
[]*RosettaTypes.Currency,
) (*RosettaTypes.AccountBalanceResponse, error)
// Submit is to submit a pre-signed transaction to the blockchain
Submit(context.Context, *EthTypes.Transaction) error
// GetNonce returns the account nonce of the given account
// The given account is the from address in Options input
GetNonce(context.Context, evmClient.Options) (uint64, error)
// GetGasPrice retrieves the currently suggested gas price
GetGasPrice(context.Context, evmClient.Options) (*big.Int, error)
// GetGasTipCap returns gas tip cap for EIP-1559 support
GetGasTipCap(context.Context, evmClient.Options) (*big.Int, error)
// GetGasFeeCap returns gas fee cap for EIP-1559 support
GetGasFeeCap(context.Context, evmClient.Options, *big.Int) (*big.Int, error)
// GetBaseFee returns base fee for EIP-1559 support
GetBaseFee(ctx context.Context) (*big.Int, error)
// GetL1DataFee returns L1 data fee
GetL1DataFee(ctx context.Context, ethTxBytes []byte) (*big.Int, error)
// GetRosettaConfig returns the Rosetta config we defined for the network
GetRosettaConfig() configuration.RosettaConfig
// GetBlockHash returns the block hash given block identifier
GetBlockHash(ctx context.Context, blockIdentifier RosettaTypes.BlockIdentifier) (string, error)
// SkipTxReceiptParsing determines if the tx receipt parsing can be skipped for specific contract address
SkipTxReceiptParsing(contractAddress string) bool
// GetCustomizedBlockBody returns the customized block body
GetCustomizedBlockBody(raw json.RawMessage, body *evmClient.RPCBlock) error
// TraceBlockByHash returns all traces for each transaction in the block
// by calling geth debug_traceBlockByHash JSON RPC.
// The output is map which key is transaction hash, and the value is list of
// FlatCall. Each Flatcall is populated from one single trace.
TraceBlockByHash(
context.Context,
common.Hash,
[]evmClient.RPCTransaction,
) (map[string][]*evmClient.FlatCall, error)
// TraceTransaction returns all traces for one transaction
// by calling geth debug_traceTransaction JSON RPC.
// The output is a list of FlatCall. Each Flatcall is populated from one single trace.
TraceTransaction(ctx context.Context, hash common.Hash) (json.RawMessage, []*evmClient.FlatCall, error)
// BlockRewardTransaction returns the block reward Rosetta transaction for the miner
BlockRewardTransaction(
blockIdentifier *RosettaTypes.BlockIdentifier,
miner string,
uncles []*EthTypes.Header,
) *RosettaTypes.Transaction
// GetLoadedTransaction populates the LoadedTransaction which used by Rosetta data APIs
GetLoadedTransaction(
ctx context.Context,
request *RosettaTypes.BlockTransactionRequest,
) (*evmClient.LoadedTransaction, error)
// BlockAuthor returns the block author
BlockAuthor(ctx context.Context, blockIndex int64) (string, error)
// GetUncles calls eth_getUncleByBlockHashAndIndex eth RPC to load uncle blocks
GetUncles(
ctx context.Context,
head *EthTypes.Header,
body *evmClient.RPCBlock,
) ([]*EthTypes.Header, error)
// TraceReplayBlockTransactions returns all traces for each transaction in the block
// by calling open ethereum trace_replayBlockTransactions JSON RPC.
// The output is map which key is transaction hash, and the value is list of
// FlatCall. Each Flatcall is populated from one single trace.
TraceReplayBlockTransactions(
ctx context.Context,
hsh string,
) (map[string][]*evmClient.FlatCall, error)
// TraceTransaction returns all traces for one transaction
// by calling open ethereum trace_replayTransaction JSON RPC.
// The output is a list of FlatCall. Each Flatcall is populated from one single trace.
TraceReplayTransaction(ctx context.Context, hsh string) (json.RawMessage, []*evmClient.FlatCall, error)
// PopulateCrossChainTransactions populates all the bridge transactions for the block
// This method is used for blockchain that supports bridging function
PopulateCrossChainTransactions(
*EthTypes.Block,
[]*evmClient.LoadedTransaction,
) ([]*RosettaTypes.Transaction, error)
// GetContractCurrency returns the ERC20 currency into for a specific token contract address
GetContractCurrency(addr common.Address, erc20 bool) (*evmClient.ContractCurrency, error)
// CallContext performs a JSON-RPC call with the given arguments.
// The method is used by the JSON RPC Client, which is the interface
// for accessing go-ethereum's JSON RPC endpoint.
CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
// BatchCall sends all given requests as a single batch and waits for the server
// to return a response for all of them. The wait duration is bounded by the
// context's deadline.
// The method is used by the JSON RPC Client, which is the interface
// for accessing go-ethereum's JSON RPC endpoint.
BatchCallContext(ctx context.Context, b []rpc.BatchElem) error
// GetBlockReceipts returns a list of transaction receipts, used by Rosetta block api
GetBlockReceipts(
ctx context.Context,
blockHash common.Hash,
txs []evmClient.RPCTransaction,
baseFee *big.Int,
) ([]*evmClient.RosettaTxReceipt, error)
// GetTransactionReceipt returns the Rosetta transaction receipt, used by Rosetta
// block/transaction api
GetTransactionReceipt(
ctx context.Context,
tx *evmClient.LoadedTransaction,
) (*evmClient.RosettaTxReceipt, error)
// GetNativeTransferGasLimit returns the estimated gas limit for the native currency transfer
// This method is used by Rosetta construction/metadata api
GetNativeTransferGasLimit(
ctx context.Context,
toAddress string,
fromAddress string,
value *big.Int,
) (uint64, error)
// GetErc20TransferGasLimit returns the estimated gas limit for the ERC20 token transfer
// This method is used by Rosetta construction/metadata api
GetErc20TransferGasLimit(
ctx context.Context,
toAddress string,
fromAddress string,
value *big.Int,
currency *RosettaTypes.Currency,
) (uint64, error)
// GetErc20TransferGasLimit returns the estimated gas limit for the ERC20 token transfer
// This method is used by Rosetta construction/metadata api
GetContractCallGasLimit(
ctx context.Context,
toAddress string,
fromAddress string,
value *big.Int,
data []byte,
) (uint64, error)
// ParseOps returns a list of operations
ParseOps(
tx *evmClient.LoadedTransaction,
) ([]*RosettaTypes.Operation, error)
}