forked from rubblelabs/ripple
/
transaction.go
262 lines (231 loc) · 6.53 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
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 Signers `json:",omitempty"`
Memos Memos `json:",omitempty"`
PreviousTxnID *Hash256 `json:",omitempty"`
LastLedgerSequence *uint32 `json:",omitempty"`
Hash Hash256 `json:"hash"`
}
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"`
}
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"`
}
type SetRegularKey struct {
TxBase
RegularKey *RegularKey `json:",omitempty"`
}
type OfferCreate struct {
TxBase
OfferSequence *uint32 `json:",omitempty"`
TakerPays Amount
TakerGets Amount
Expiration *uint32 `json:",omitempty"`
}
type OfferCancel struct {
TxBase
OfferSequence uint32
}
type TrustSet struct {
TxBase
LimitAmount Amount
QualityIn *uint32 `json:",omitempty"`
QualityOut *uint32 `json:",omitempty"`
}
type SetFee struct {
TxBase
BaseFee Uint64Hex
ReferenceFeeUnits uint32
ReserveBase uint32
ReserveIncrement uint32
}
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"`
}
type EscrowFinish struct {
TxBase
Owner Account
OfferSequence uint32
Method *uint8 `json:",omitempty"`
Digest *Hash256 `json:",omitempty"`
Proof *Hash256 `json:",omitempty"`
}
type EscrowCancel struct {
TxBase
Owner Account
OfferSequence uint32
}
type PaymentChannelCreate struct {
TxBase
Amount Amount
Destination Account
SettleDelay uint32
PublicKey PublicKey
CancelAfter *uint32 `json:",omitempty"`
DestinationTag *uint32 `json:",omitempty"`
SourceTag *uint32 `json:",omitempty"`
}
type PaymentChannelFund struct {
TxBase
Channel Hash256
Amount Amount
Expiration *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"`
}
// 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"`
}
// 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"`
}
// https://ripple.com/build/transactions/#checkcancel
type CheckCancel struct {
TxBase
CheckID Hash256
}
type TicketCreate struct {
Target *Account `json:",omitempty"`
Expiration *uint32 `json:",omitempty"`
}
type TicketCancel struct {
TicketID Hash256
}
type SignerListSet struct {
TxBase
SignerQuorum uint32 `json:",omitempty"`
SignerEntries []SignerEntries `json:",omitempty"`
}
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 t.signingPrefix() }
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) AddSignature(signer *Signer) {
t.Signers = append(t.Signers, *signer)
}
func (t *TxBase) signingPrefix() HashPrefix {
if t.Signers == nil {
return HP_TRANSACTION_SIGN
}
return HP_TRANSACTION_MULTISIGN
}
func (t *TxBase) InitialiseForSigning() {
if t.Signers == nil {
if t.SigningPubKey == nil {
t.SigningPubKey = new(PublicKey)
}
if t.TxnSignature == nil {
t.TxnSignature = new(VariableLength)
}
} else {
t.SigningPubKey = new(PublicKey)
t.TxnSignature = nil
}
}
func (t *TxBase) SortSigners(signerEntries []SignerEntries) {
var signers Signers
copy(t.Signers, signers)
for i := range signerEntries {
signer := signerEntries[i].SignerEntry.Account
for j := range t.Signers {
if t.Signers[j].Signer.Account.Equals(*signer) {
signers = append(signers, t.Signers[j])
}
}
}
if signers != nil {
t.Signers = signers
}
}
func (t *TxBase) InitialiseForMultiSigning() {
if t.Signers == nil {
t.Signers = Signers{}
}
t.SigningPubKey = new(PublicKey)
t.TxnSignature = nil
}
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
}