github.com/neatlab/neatio@v1.7.3-0.20220425043230-d903e92fcc75/interfaces.go (about) 1 package neatio 2 3 import ( 4 "context" 5 "errors" 6 "math/big" 7 8 "github.com/neatlab/neatio/chain/core/types" 9 "github.com/neatlab/neatio/utilities/common" 10 ) 11 12 var NotFound = errors.New("not found") 13 14 type Subscription interface { 15 Unsubscribe() 16 17 Err() <-chan error 18 } 19 20 type ChainReader interface { 21 BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) 22 BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) 23 HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) 24 HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) 25 TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error) 26 TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error) 27 28 SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (Subscription, error) 29 } 30 31 type TransactionReader interface { 32 TransactionByHash(ctx context.Context, txHash common.Hash) (tx *types.Transaction, isPending bool, err error) 33 34 TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) 35 } 36 37 type ChainStateReader interface { 38 BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) 39 StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error) 40 CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) 41 NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) 42 } 43 44 type SyncProgress struct { 45 StartingBlock uint64 46 CurrentBlock uint64 47 HighestBlock uint64 48 PulledStates uint64 49 KnownStates uint64 50 } 51 52 type ChainSyncReader interface { 53 SyncProgress(ctx context.Context) (*SyncProgress, error) 54 } 55 56 type CallMsg struct { 57 From common.Address 58 To *common.Address 59 Gas uint64 60 GasPrice *big.Int 61 Value *big.Int 62 Data []byte 63 } 64 65 type ContractCaller interface { 66 CallContract(ctx context.Context, call CallMsg, blockNumber *big.Int) ([]byte, error) 67 } 68 69 type FilterQuery struct { 70 FromBlock *big.Int 71 ToBlock *big.Int 72 Addresses []common.Address 73 74 Topics [][]common.Hash 75 } 76 77 type LogFilterer interface { 78 FilterLogs(ctx context.Context, q FilterQuery) ([]types.Log, error) 79 SubscribeFilterLogs(ctx context.Context, q FilterQuery, ch chan<- types.Log) (Subscription, error) 80 } 81 82 type TransactionSender interface { 83 SendTransaction(ctx context.Context, tx *types.Transaction) error 84 } 85 86 type GasPricer interface { 87 SuggestGasPrice(ctx context.Context) (*big.Int, error) 88 } 89 90 type PendingStateReader interface { 91 PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error) 92 PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error) 93 PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) 94 PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) 95 PendingTransactionCount(ctx context.Context) (uint, error) 96 } 97 98 type PendingContractCaller interface { 99 PendingCallContract(ctx context.Context, call CallMsg) ([]byte, error) 100 } 101 102 type GasEstimator interface { 103 EstimateGas(ctx context.Context, call CallMsg) (uint64, error) 104 } 105 106 type PendingStateEventer interface { 107 SubscribePendingTransactions(ctx context.Context, ch chan<- *types.Transaction) (Subscription, error) 108 }