/
transaction.go
364 lines (321 loc) · 9.51 KB
/
transaction.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
package data
type TxBase struct {
TransactionType TransactionType
Flags *TransactionFlag `json:",omitempty"`
SourceTag *uint32 `json:",omitempty"`
Account Account
Sequence uint32
Fee Value
AccountTxnID *Hash256 `json:",omitempty"`
SigningPubKey *PublicKey `json:",omitempty"`
TxnSignature *VariableLength `json:",omitempty"`
Signers []Signer `json:",omitempty"`
Memos Memos `json:",omitempty"`
PreviousTxnID *Hash256 `json:",omitempty"`
LastLedgerSequence *uint32 `json:",omitempty"`
Hash Hash256 `json:"hash"`
}
type SignerItem struct {
Account Account
TxnSignature *VariableLength `json:",omitempty"`
SigningPubKey *PublicKey `json:",omitempty"`
}
type Signer struct {
Signer SignerItem
}
type Payment struct {
TxBase
Destination Account
Amount Amount
SendMax *Amount `json:",omitempty"`
DeliverMin *Amount `json:",omitempty"`
Paths *PathSet `json:",omitempty"`
DestinationTag *uint32 `json:",omitempty"`
InvoiceID *Hash256 `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
type AccountSet struct {
TxBase
EmailHash *Hash128 `json:",omitempty"`
WalletLocator *Hash256 `json:",omitempty"`
WalletSize *uint32 `json:",omitempty"`
MessageKey *VariableLength `json:",omitempty"`
Domain *VariableLength `json:",omitempty"`
TransferRate *uint32 `json:",omitempty"`
TickSize *uint8 `json:",omitempty"`
SetFlag *uint32 `json:",omitempty"`
ClearFlag *uint32 `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
type AccountDelete struct {
TxBase
Destination Account
DestinationTag *uint32 `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
type SetRegularKey struct {
TxBase
RegularKey *RegularKey `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
type OfferCreate struct {
TxBase
OfferSequence *uint32 `json:",omitempty"`
TakerPays Amount
TakerGets Amount
Expiration *uint32 `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
type OfferCancel struct {
TxBase
OfferSequence uint32
TicketSequence *uint32 `json:",omitempty"`
}
type AMMCreate struct {
TxBase
Amount Amount
Amount2 Amount
TradingFee uint16
}
type AMMDeposit struct {
TxBase
Asset Asset
Asset2 Asset
Amount *Amount `json:",omitempty"`
Amount2 *Amount `json:",omitempty"`
EPrice *Amount `json:",omitempty"`
LPTokenOut *Amount `json:",omitempty"`
TradingFee *uint16 `json:",omitempty"`
}
type AMMWithdraw struct {
TxBase
Asset Asset
Asset2 Asset
Amount *Amount `json:",omitempty"`
Amount2 *Amount `json:",omitempty"`
EPrice *Amount `json:",omitempty"`
LPTokenIn *Amount `json:",omitempty"`
}
type AMMVote struct {
TxBase
Asset Asset
Asset2 Asset
TradingFee uint16
}
type AMMBid struct {
TxBase
Asset Asset
Asset2 Asset
BidMin *Amount `json:",omitempty"`
BidMax *Amount `json:",omitempty"`
AuthAccounts []AuthAccount `json:",omitempty"`
}
type AMMDelete struct {
TxBase
Asset Asset
Asset2 Asset
}
type TrustSet struct {
TxBase
LimitAmount Amount
QualityIn *uint32 `json:",omitempty"`
QualityOut *uint32 `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
type SetFee struct {
TxBase
BaseFee Uint64Hex
ReferenceFeeUnits uint32
ReserveBase uint32
ReserveIncrement uint32
BaseFeeDrops *Amount `json:",omitempty"`
ReserveBaseDrops *Amount `json:",omitempty"`
ReserveIncrementDrops *Amount `json:",omitempty"`
}
type Amendment struct {
TxBase
Amendment Hash256
}
type EscrowCreate struct {
TxBase
Destination Account
Amount Amount
Digest *Hash256 `json:",omitempty"`
CancelAfter *uint32 `json:",omitempty"`
FinishAfter *uint32 `json:",omitempty"`
DestinationTag *uint32 `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
type EscrowFinish struct {
TxBase
Owner Account
OfferSequence uint32
Method *uint8 `json:",omitempty"`
Digest *Hash256 `json:",omitempty"`
Proof *Hash256 `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
type EscrowCancel struct {
TxBase
Owner Account
OfferSequence uint32
TicketSequence *uint32 `json:",omitempty"`
}
type PaymentChannelCreate struct {
TxBase
Amount Amount
Destination Account
SettleDelay uint32
PublicKey PublicKey
CancelAfter *uint32 `json:",omitempty"`
DestinationTag *uint32 `json:",omitempty"`
SourceTag *uint32 `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
type PaymentChannelFund struct {
TxBase
Channel Hash256
Amount Amount
Expiration *uint32 `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
type PaymentChannelClaim struct {
TxBase
Channel Hash256
Balance *Amount `json:",omitempty"`
Amount *Amount `json:",omitempty"`
Signature *VariableLength `json:",omitempty"`
PublicKey *PublicKey `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
// CheckCreate, CheckCash, CheckCancel enabled by amendment 157D2D480E006395B76F948E3E07A45A05FE10230D88A7993C71F97AE4B1F2D1
// https://ripple.com/build/transactions/#checkcreate
type CheckCreate struct {
TxBase
Destination Account
SendMax Amount
DestinationTag *uint32 `json:",omitempty"`
Expiration *uint32 `json:",omitempty"`
InvoiceID *Hash256 `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
// https://ripple.com/build/transactions/#checkcash
// Must include one of Amount or DeliverMin
type CheckCash struct {
TxBase
CheckID Hash256
Amount *Amount `json:",omitempty"`
DeliverMin *Amount `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
// https://ripple.com/build/transactions/#checkcancel
type CheckCancel struct {
TxBase
CheckID Hash256
TicketSequence *uint32 `json:",omitempty"`
}
type TicketCreate struct {
TxBase
TicketCount *uint32 `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
type SignerListSet struct {
TxBase
SignerQuorum uint32 `json:",omitempty"`
SignerEntries []SignerEntry `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
type UNLModify struct {
TxBase
UNLModifyDisabling uint8 `json:",omitempty"`
UNLModifyValidator *VariableLength `json:",omitempty"`
}
type SetDepositPreAuth struct {
TxBase
Authorize *Account `json:",omitempty"`
Unauthorize *Account `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
type NFTokenMint struct {
TxBase
NFTokenTaxon *uint32 `json:",omitempty"`
TransferFee *uint16 `json:",omitempty"`
Issuer *Account `json:",omitempty"`
URI *VariableLength `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
type NFTokenBurn struct {
TxBase
Owner *Account `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
type NFTokenCreateOffer struct {
TxBase
NFTokenID *Hash256 `json:",omitempty"`
Amount *Amount `json:",omitempty"`
Destination *Account `json:",omitempty"`
Owner *Account `json:",omitempty"`
Expiration *uint32 `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
type NFTCancelOffer struct {
TxBase
NFTokenOffers *Vector256 `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
type NFTAcceptOffer struct {
TxBase
NFTokenBuyOffer *Hash256 `json:",omitempty"`
NFTokenSellOffer *Hash256 `json:",omitempty"`
NFTokenBrokerFee *Amount `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
}
type Clawback struct {
TxBase
Amount Amount
}
func (t *TxBase) GetBase() *TxBase { return t }
func (t *TxBase) GetType() string { return txNames[t.TransactionType] }
func (t *TxBase) GetTransactionType() TransactionType { return t.TransactionType }
func (t *TxBase) Prefix() HashPrefix { return HP_TRANSACTION_ID }
func (t *TxBase) GetPublicKey() *PublicKey { return t.SigningPubKey }
func (t *TxBase) GetSignature() *VariableLength { return t.TxnSignature }
func (t *TxBase) SigningPrefix() HashPrefix { return HP_TRANSACTION_SIGN }
func (t *TxBase) MultiSigningPrefix() HashPrefix { return HP_TRANSACTION_MULTISIGN }
func (t *TxBase) SetSigners(signers []Signer) { t.Signers = signers }
func (t *TxBase) PathSet() PathSet { return PathSet(nil) }
func (t *TxBase) GetHash() *Hash256 { return &t.Hash }
func (t *TxBase) Compare(other *TxBase) int {
switch {
case t.Account.Equals(other.Account):
switch {
case t.Sequence == other.Sequence:
return t.GetHash().Compare(*other.GetHash())
case t.Sequence < other.Sequence:
return -1
default:
return 1
}
case t.Account.Less(other.Account):
return -1
default:
return 1
}
}
func (t *TxBase) InitialiseForSigning() {
if t.SigningPubKey == nil {
t.SigningPubKey = new(PublicKey)
}
if t.TxnSignature == nil {
t.TxnSignature = new(VariableLength)
}
}
func (o *OfferCreate) Ratio() *Value {
return o.TakerPays.Ratio(o.TakerGets)
}
func (p *Payment) PathSet() PathSet {
if p.Paths == nil {
return PathSet(nil)
}
return *p.Paths
}