This repository has been archived by the owner on Aug 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
tx.go
225 lines (186 loc) · 5.25 KB
/
tx.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package cmds
import (
"github.com/Qitmeer/qitmeer/core/json"
)
type CreateRawTransactionCmd struct {
Inputs []json.TransactionInput
Amounts json.Amounts
LockTime int64
}
func NewCreateRawTransactionCmd(inputs []json.TransactionInput, amounts json.Amounts, lockTime int64) *CreateRawTransactionCmd {
return &CreateRawTransactionCmd{
Inputs: inputs,
Amounts: amounts,
LockTime: lockTime,
}
}
type DecodeRawTransactionCmd struct {
HexTx string
}
func NewDecodeRawTransactionCmd(hexTx string) *DecodeRawTransactionCmd {
return &DecodeRawTransactionCmd{
HexTx: hexTx,
}
}
type SendRawTransactionCmd struct {
HexTx string
AllowHighFees bool
}
func NewSendRawTransactionCmd(hexTx string, allowHighFees bool) *SendRawTransactionCmd {
return &SendRawTransactionCmd{
HexTx: hexTx,
AllowHighFees: allowHighFees,
}
}
type GetRawTransactionCmd struct {
TxHash string
Verbose bool
}
func NewGetRawTransactionCmd(txHash string, verbose bool) *GetRawTransactionCmd {
return &GetRawTransactionCmd{
TxHash: txHash,
Verbose: verbose,
}
}
type GetUtxoCmd struct {
TxHash string
Vout uint32
IncludeMempool bool
}
func NewGetUtxoCmd(txHash string, vout uint32, includeMempool bool) *GetUtxoCmd {
return &GetUtxoCmd{
TxHash: txHash,
Vout: vout,
IncludeMempool: includeMempool,
}
}
type GetRawTransactionsCmd struct {
Addre string
Vinext bool
Count uint
Skip uint
Revers bool
Verbose bool
FilterAddrs []string
}
func NewGetRawTransactionsCmd(addre string, vinext bool, count uint, skip uint, revers bool, verbose bool, filterAddrs []string) *GetRawTransactionsCmd {
return &GetRawTransactionsCmd{
Addre: addre,
Vinext: vinext,
Count: count,
Skip: skip,
Revers: revers,
Verbose: verbose,
FilterAddrs: filterAddrs,
}
}
type TxSignCmd struct {
PrivkeyStr string
RawTxStr string
}
func NewTxSignCmd(privkeyStr string, rawTxStr string) *TxSignCmd {
return &TxSignCmd{
PrivkeyStr: privkeyStr,
RawTxStr: rawTxStr,
}
}
type GetMempoolCmd struct {
TxType string
Verbose bool
}
func NewGetMempoolCmd(txType string, verbose bool) *GetMempoolCmd {
return &GetMempoolCmd{
TxType: txType,
Verbose: verbose,
}
}
// ws
type NotifyNewTransactionsCmd struct {
Verbose bool
}
// OutPoint describes a transaction outpoint that will be marshalled to and
// from JSON.
type OutPoint struct {
Hash string `json:"hash"`
Index uint32 `json:"index"`
}
// RescanCmd defines the rescan JSON-RPC command.
//
type RescanCmd struct {
BeginBlock uint64
Addresses []string
OutPoints []OutPoint
EndBlock uint64
}
type TxConfirm struct {
Txid string
Order uint64
Confirmations int32
EndHeight uint64
}
type NotifyTxsConfirmedCmd struct {
Txs []TxConfirm
}
type RemoveTxsConfirmedCmd struct {
Txs []TxConfirm
}
// ws
type NotifyTxsByAddrCmd struct {
Reload bool
Addresses []string
OutPoints []OutPoint
}
// ws
type UnNotifyTxsByAddrCmd struct {
Addresses []string
}
func NewNotifyNewTransactionsCmd(verbose bool) *NotifyNewTransactionsCmd {
return &NotifyNewTransactionsCmd{
Verbose: verbose,
}
}
func NewNotifyTxsConfirmed(txs []TxConfirm) *NotifyTxsConfirmedCmd {
return &NotifyTxsConfirmedCmd{
Txs: txs,
}
}
func NewRemoveTxsConfirmed(txs []TxConfirm) *RemoveTxsConfirmedCmd {
return &RemoveTxsConfirmedCmd{
Txs: txs,
}
}
type StopNotifyNewTransactionsCmd struct{}
func NewStopNotifyNewTransactionsCmd() *StopNotifyNewTransactionsCmd {
return &StopNotifyNewTransactionsCmd{}
}
func NewNotifyTxsByAddrCmd(reload bool, addr []string, outpoint []OutPoint) *NotifyTxsByAddrCmd {
return &NotifyTxsByAddrCmd{
Reload: reload,
Addresses: addr,
OutPoints: outpoint,
}
}
func StopNotifyTxsByAddrCmd(addr []string) *UnNotifyTxsByAddrCmd {
return &UnNotifyTxsByAddrCmd{
Addresses: addr,
}
}
func init() {
flags := UsageFlag(0)
MustRegisterCmd("createRawTransaction", (*CreateRawTransactionCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("decodeRawTransaction", (*DecodeRawTransactionCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("sendRawTransaction", (*SendRawTransactionCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("getRawTransaction", (*GetRawTransactionCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("getUtxo", (*GetUtxoCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("getRawTransactions", (*GetRawTransactionsCmd)(nil), flags, DefaultServiceNameSpace)
MustRegisterCmd("txSign", (*TxSignCmd)(nil), flags, TestNameSpace)
MustRegisterCmd("getMempool", (*GetMempoolCmd)(nil), flags, DefaultServiceNameSpace)
// ws
MustRegisterCmd("notifynewtransactions", (*NotifyNewTransactionsCmd)(nil), UFWebsocketOnly, NotifyNameSpace)
MustRegisterCmd("stopnotifynewtransactions", (*StopNotifyNewTransactionsCmd)(nil), UFWebsocketOnly, NotifyNameSpace)
// ws
MustRegisterCmd("notifyTxsByAddr", (*NotifyTxsByAddrCmd)(nil), UFWebsocketOnly, NotifyNameSpace)
MustRegisterCmd("stopnotifyTxsByAddr", (*UnNotifyTxsByAddrCmd)(nil), UFWebsocketOnly, NotifyNameSpace)
MustRegisterCmd("notifyTxsConfirmed", (*NotifyTxsConfirmedCmd)(nil), flags, NotifyNameSpace)
MustRegisterCmd("removeTxsConfirmed", (*RemoveTxsConfirmedCmd)(nil), flags, NotifyNameSpace)
}