-
Notifications
You must be signed in to change notification settings - Fork 10
/
interface.go
168 lines (123 loc) · 3.43 KB
/
interface.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package sqlite
import (
"github.com/elastos/Elastos.ELA.SPV/util"
"github.com/elastos/Elastos.ELA.SPV/wallet/sutil"
"github.com/elastos/Elastos.ELA/common"
)
type DataStore interface {
State() State
Addrs() Addrs
Txs() Txs
UTXOs() UTXOs
STXOs() STXOs
Batch() DataBatch
Clear() error
Close() error
}
type DataBatch interface {
batch
Addrs() AddrsBatch
Txs() TxsBatch
UTXOs() UTXOsBatch
STXOs() STXOsBatch
RollbackHeight(height uint32) error
}
type batch interface {
Rollback() error
Commit() error
}
type State interface {
// save state height
PutHeight(height uint32)
// get state height
GetHeight() uint32
}
type Addrs interface {
// put a address to database
Put(hash *common.Uint168, script []byte, addrType int) error
// get a address from database
Get(hash *common.Uint168) (*sutil.Addr, error)
// get all addresss from database
GetAll() ([]*sutil.Addr, error)
// delete a address from database
Del(hash *common.Uint168) error
// Batch return a AddrsBatch
Batch() AddrsBatch
}
type AddrsBatch interface {
batch
// put a address to database
Put(hash *common.Uint168, script []byte, addrType int) error
// delete a address from database
Del(hash *common.Uint168) error
}
type Txs interface {
// Put a new transaction to database
Put(tx *util.Tx) error
// Fetch a raw tx and it's metadata given a hash
Get(txId *common.Uint256) (*util.Tx, error)
// Fetch all transactions from database
GetAll() ([]*util.Tx, error)
// Fetch all transactions from the given height.
GetAllFrom(height uint32) ([]*util.Tx, error)
// Fetch all unconfirmed transactions.
GetAllUnconfirmed() ([]*util.Tx, error)
// Delete a transaction from the db
Del(txId *common.Uint256) error
// PutForkTxs persists the fork chain transactions into database with the
// fork block hash and can be queried by GetForkTxs(hash).
PutForkTxs(txs []*util.Tx, hash *common.Uint256) error
// GetForkTxs returns all transactions within the fork block hash.
GetForkTxs(hash *common.Uint256) ([]*util.Tx, error)
// Batch return a TxsBatch
Batch() TxsBatch
}
type TxsBatch interface {
batch
// Put a new transaction to database
Put(tx *util.Tx) error
// Delete a transaction from the db
Del(txId *common.Uint256) error
}
type UTXOs interface {
// put a utxo to database
Put(utxo *sutil.UTXO) error
// get a utxo from database
Get(op *util.OutPoint) (*sutil.UTXO, error)
// get utxos of the given address hash from database
GetAddrAll(hash *common.Uint168) ([]*sutil.UTXO, error)
// Get all UTXOs in database
GetAll() ([]*sutil.UTXO, error)
// delete a utxo from database
Del(outPoint *util.OutPoint) error
// Batch return a UTXOsBatch.
Batch() UTXOsBatch
}
type UTXOsBatch interface {
batch
// put a utxo to database
Put(utxo *sutil.UTXO) error
// delete a utxo from database
Del(outPoint *util.OutPoint) error
}
type STXOs interface {
// Put save a STXO into database
Put(stxo *sutil.STXO) error
// get a stxo from database
Get(op *util.OutPoint) (*sutil.STXO, error)
// get stxos of the given address hash from database
GetAddrAll(hash *common.Uint168) ([]*sutil.STXO, error)
// Get all STXOs in database
GetAll() ([]*sutil.STXO, error)
// delete a stxo from database
Del(outPoint *util.OutPoint) error
// Batch return a STXOsBatch.
Batch() STXOsBatch
}
type STXOsBatch interface {
batch
// Put save a STXO into database
Put(stxo *sutil.STXO) error
// delete a stxo from database
Del(outPoint *util.OutPoint) error
}