aboutsummaryrefslogtreecommitdiffstats
path: root/interfaces.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-11-29 22:54:06 +0800
committerFelix Lange <fjl@twurst.com>2016-12-05 17:57:11 +0800
commit3bc0fe1ee3183311efe851aca8fd10d5a5433929 (patch)
treeed6e33c3af93115e02e508f86b993a6bf64f5328 /interfaces.go
parentfa0cc274009670209fd71b1462dcdde3b431d64f (diff)
downloaddexon-3bc0fe1ee3183311efe851aca8fd10d5a5433929.tar
dexon-3bc0fe1ee3183311efe851aca8fd10d5a5433929.tar.gz
dexon-3bc0fe1ee3183311efe851aca8fd10d5a5433929.tar.bz2
dexon-3bc0fe1ee3183311efe851aca8fd10d5a5433929.tar.lz
dexon-3bc0fe1ee3183311efe851aca8fd10d5a5433929.tar.xz
dexon-3bc0fe1ee3183311efe851aca8fd10d5a5433929.tar.zst
dexon-3bc0fe1ee3183311efe851aca8fd10d5a5433929.zip
ethclient, ethereum: add NotFound, split transactions out of ChainReader
ethclient now returns ethereum.NotFound if the server returns null and no error while accessing blockchain data. The light client cannot provide arbitrary transactions. The change to split transaction access into its own interface emphasizes that transactions should not be relied on and recommends use of logs.
Diffstat (limited to 'interfaces.go')
-rw-r--r--interfaces.go36
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'