-
Notifications
You must be signed in to change notification settings - Fork 36
/
source.go
114 lines (95 loc) · 4.06 KB
/
source.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
package sources
import (
"context"
"fmt"
"github.com/tonkeeper/tongo"
)
type SubscribeToTransactionsOptions struct {
Accounts []tongo.AccountID
AllAccounts bool
Operations []string
AllOperations bool
}
// SubscribeToMempoolOptions configures subscription to mempool events.
type SubscribeToMempoolOptions struct {
// Emulation if set, opentonapi will send a message payload and additionally a list of accounts
// that are involved in the corresponding trace.
Accounts []tongo.AccountID
}
// DeliveryFn describes a callback that will be triggered once an event happens.
type DeliveryFn func(eventData []byte)
// CancelFn has to be called to unsubscribe.
type CancelFn func()
// TransactionEventData represents a notification about a new transaction.
// This is part of our API contract with subscribers.
type TransactionEventData struct {
AccountID tongo.AccountID `json:"account_id"`
Lt uint64 `json:"lt"`
TxHash string `json:"tx_hash"`
}
// TransactionSource provides a method to subscribe to notifications about new transactions from the blockchain.
type TransactionSource interface {
SubscribeToTransactions(ctx context.Context, deliveryFn DeliveryFn, opts SubscribeToTransactionsOptions) CancelFn
}
// MessageEventData represents a notification about a new pending inbound message.
// This is part of our API contract with subscribers.
type MessageEventData struct {
BOC []byte `json:"boc"`
}
// EmulationMessageEventData represents a notification about a new pending inbound message.
// After opentonapi receives a message, it emulates what happens when the message lands on the blockchain.
// Then it sends the message and the emulation results to subscribers.
// This is part of our API contract with subscribers.
type EmulationMessageEventData struct {
BOC []byte `json:"boc"`
// InvolvedAccounts is a list of accounts that are involved in the corresponding trace of the message.
// The trace is a result of emulation.
InvolvedAccounts []tongo.AccountID `json:"involved_accounts"`
}
// MemPoolSource provides a method to subscribe to notifications about pending inbound messages.
type MemPoolSource interface {
SubscribeToMessages(ctx context.Context, deliveryFn DeliveryFn, opts SubscribeToMempoolOptions) (CancelFn, error)
}
// SubscribeToBlockHeadersOptions configures subscription to block events.
type SubscribeToBlockHeadersOptions struct {
// Workchain, if set, opentonapi will filter out blocks that are not from the specified workchain.
Workchain *int `json:"workchain,omitempty"`
}
// BlockEvent represents a notification about a new block.
// This is part of our API contract with subscribers.
type BlockEvent struct {
Workchain int32 `json:"workchain"`
Shard string `json:"shard"`
Seqno uint32 `json:"seqno"`
RootHash string `json:"root_hash"`
FileHash string `json:"file_hash"`
}
func (e BlockEvent) String() string {
return fmt.Sprintf("(%d,%x,%d)", e.Workchain, e.Shard, e.Seqno)
}
// BlockHeadersSource provides a method to subscribe to notifications about new blocks in the TON network.
type BlockHeadersSource interface {
SubscribeToBlockHeaders(ctx context.Context, deliveryFn DeliveryFn, opts SubscribeToBlockHeadersOptions) CancelFn
}
type SubscribeToBlocksOptions struct {
MasterchainSeqno uint32 `json:"masterchain_seqno,omitempty"`
// RateLimit defines the rate limit (KB/sec) for the block streaming.
RateLimit int
}
type Block struct {
Workchain int32 `json:"workchain"`
Shard string `json:"shard"`
Seqno uint32 `json:"seqno"`
RootHash string `json:"root_hash"`
FileHash string `json:"file_hash"`
Raw []byte `json:"raw"`
}
// BlockchainSliceEvent represents a notification about a new bunch of blocks in the blockchain.
type BlockchainSliceEvent struct {
MasterchainSeqno uint32 `json:"masterchain_seqno"`
// Blocks contains one masterchain block and all blocks from the basechain created since the previous blockchain slice.
Blocks []Block `json:"blocks"`
}
type BlockSource interface {
SubscribeToBlocks(ctx context.Context, deliveryFn DeliveryFn, opts SubscribeToBlocksOptions) (CancelFn, error)
}