diff options
Diffstat (limited to 'interfaces.go')
-rw-r--r-- | interfaces.go | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/interfaces.go b/interfaces.go index aab0e2029..5e38a9054 100644 --- a/interfaces.go +++ b/interfaces.go @@ -18,6 +18,7 @@ package ethereum import ( + "errors" "math/big" "github.com/ethereum/go-ethereum/common" @@ -26,6 +27,9 @@ import ( "golang.org/x/net/context" ) +// NotFound is returned by API methods if the requested item does not exist. +var NotFound = errors.New("not found") + // TODO: move subscription to package event // Subscription represents an event subscription where events are @@ -46,6 +50,8 @@ type Subscription interface { // blockchain fork that was previously downloaded and processed by the node. The block // number argument can be nil to select the latest canonical block. Reading block headers // should be preferred over full blocks whenever possible. +// +// The returned error is NotFound if the requested item does not exist. type ChainReader interface { BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) @@ -53,7 +59,30 @@ type ChainReader interface { HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error) - TransactionByHash(ctx context.Context, txHash common.Hash) (*types.Transaction, error) + + // This method subscribes to notifications about changes of the head block of + // the canonical chain. + SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (Subscription, error) +} + +// TransactionReader provides access to past transactions and their receipts. +// Implementations may impose arbitrary restrictions on the transactions and receipts that +// can be retrieved. Historic transactions may not be available. +// +// Avoid relying on this interface if possible. Contract logs (through the LogFilterer +// interface) are more reliable and usually safer in the presence of chain +// reorganisations. +// +// The returned error is NotFound if the requested item does not exist. +type TransactionReader interface { + // TransactionByHash checks the pool of pending transactions in addition to the + // blockchain. The isPending return value indicates whether the transaction has been + // mined yet. Note that the transaction may not be part of the canonical chain even if + // it's not pending. + TransactionByHash(ctx context.Context, txHash common.Hash) (tx *types.Transaction, isPending bool, err error) + // TransactionReceipt returns the receipt of a mined transaction. Note that the + // transaction may not be included in the current canonical chain even if a receipt + // exists. TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) } @@ -83,11 +112,6 @@ type ChainSyncReader interface { SyncProgress(ctx context.Context) (*SyncProgress, error) } -// A ChainHeadEventer returns notifications whenever the canonical head block is updated. -type ChainHeadEventer interface { - SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (Subscription, error) -} - // CallMsg contains parameters for contract calls. type CallMsg struct { From common.Address // the sender of the 'transaction' |