-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinterfaces.go
65 lines (48 loc) · 2.26 KB
/
interfaces.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
package bitcoin_reader
import (
"context"
"github.com/tokenized/pkg/bitcoin"
"github.com/tokenized/pkg/merkle_proof"
"github.com/tokenized/pkg/wire"
"github.com/google/uuid"
)
type TxProcessor interface {
// ProcessTx returns true if the tx is relevant.
ProcessTx(ctx context.Context, tx *wire.MsgTx) (bool, error)
// CancelTx specifies that a tx is no longer valid because a conflicting tx has been confirmed.
CancelTx(ctx context.Context, txid bitcoin.Hash32) error
// AddTxConflict specifies that there is an unconfirmed conflicting tx to a relevant tx.
AddTxConflict(ctx context.Context, txid, conflictTxID bitcoin.Hash32) error
ConfirmTx(ctx context.Context, txid bitcoin.Hash32, blockHeight int,
merkleProof *merkle_proof.MerkleProof) error
UpdateTxChainDepth(ctx context.Context, txid bitcoin.Hash32, chainDepth uint32) error
ProcessCoinbaseTx(ctx context.Context, blockHash bitcoin.Hash32, tx *wire.MsgTx) error
}
type TxSaver interface {
SaveTx(context.Context, *wire.MsgTx) error
}
// HandleBlock handles a block coming from a data source.
type HandleBlock func(ctx context.Context, header *wire.BlockHeader, txCount uint64,
txChannel <-chan *wire.MsgTx) error
type OnStop func(context.Context)
type BlockRequestor interface {
// RequestBlock requests a block from a data source.
// "handler" handles the block data as it is provided.
// "onStop" is a function that is called if the data source stops. It should abort the request
// from the handler side.
RequestBlock(ctx context.Context, hash bitcoin.Hash32,
handler HandleBlock, onStop OnStop) (BlockRequestCanceller, error)
}
type BlockRequestCanceller interface {
// ID returns the unique id of block requestor.
ID() uuid.UUID
// CancelBlockRequest cancels a request for a block. It returns true if the block handler has
// already been called.
CancelBlockRequest(context.Context, bitcoin.Hash32) bool
}
type BlockTxManager interface {
// FetchBlockTxIDs fetches the relevant txids for a block hash. Returns false if data doesn't
// exist for the block hash, which means the block has not been processed yet.
FetchBlockTxIDs(ctx context.Context, blockHash bitcoin.Hash32) ([]bitcoin.Hash32, bool, error)
AppendBlockTxIDs(ctx context.Context, blockHash bitcoin.Hash32, txids []bitcoin.Hash32) error
}