forked from rubblelabs/ripple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ledgerentry.go
274 lines (246 loc) · 10.3 KB
/
ledgerentry.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
package data
type LedgerEntrySlice []LedgerEntry
type leBase struct {
LedgerEntryType LedgerEntryType
LedgerIndex *Hash256 `json:"index,omitempty"`
PreviousTxnID *Hash256 `json:",omitempty"`
PreviousTxnLgrSeq *uint32 `json:",omitempty"`
Hash Hash256 `json:"-"`
Id Hash256 `json:"-"`
}
type AccountRoot struct {
leBase
Flags *LedgerEntryFlag `json:",omitempty"`
Account *Account `json:",omitempty"`
Sequence *uint32 `json:",omitempty"`
Balance *Value `json:",omitempty"`
OwnerCount *uint32 `json:",omitempty"`
MintedNFTokens *uint32 `json:",omitempty"`
AccountTxnID *Hash256 `json:",omitempty"`
RegularKey *RegularKey `json:",omitempty"`
EmailHash *Hash128 `json:",omitempty"`
WalletLocator *Hash256 `json:",omitempty"`
WalletSize *uint32 `json:",omitempty"`
MessageKey *VariableLength `json:",omitempty"`
TransferRate *uint32 `json:",omitempty"`
Domain *VariableLength `json:",omitempty"`
TickSize *uint8 `json:",omitempty"`
TicketCount *uint32 `json:",omitempty"`
}
type RippleState struct {
leBase
Flags *LedgerEntryFlag `json:",omitempty"`
LowLimit *Amount `json:",omitempty"`
HighLimit *Amount `json:",omitempty"`
Balance *Amount `json:",omitempty"`
LowNode *NodeIndex `json:",omitempty"`
HighNode *NodeIndex `json:",omitempty"`
LowQualityIn *uint32 `json:",omitempty"`
LowQualityOut *uint32 `json:",omitempty"`
HighQualityIn *uint32 `json:",omitempty"`
HighQualityOut *uint32 `json:",omitempty"`
}
type Offer struct {
leBase
Flags *LedgerEntryFlag `json:",omitempty"`
Account *Account `json:",omitempty"`
Sequence *uint32 `json:",omitempty"`
TakerPays *Amount `json:",omitempty"`
TakerGets *Amount `json:",omitempty"`
BookDirectory *Hash256 `json:",omitempty"`
BookNode *NodeIndex `json:",omitempty"`
OwnerNode *NodeIndex `json:",omitempty"`
Expiration *uint32 `json:",omitempty"`
}
type Directory struct {
leBase
Flags *LedgerEntryFlag `json:",omitempty"`
RootIndex *Hash256 `json:",omitempty"`
Indexes *Vector256 `json:",omitempty"`
Owner *Account `json:",omitempty"`
TakerPaysCurrency *Hash160 `json:",omitempty"`
TakerPaysIssuer *Hash160 `json:",omitempty"`
TakerGetsCurrency *Hash160 `json:",omitempty"`
TakerGetsIssuer *Hash160 `json:",omitempty"`
ExchangeRate *ExchangeRate `json:",omitempty"`
IndexNext *NodeIndex `json:",omitempty"`
IndexPrevious *NodeIndex `json:",omitempty"`
NFTokenID *Hash256 `json:",omitempty"`
}
type LedgerHashes struct {
leBase
Flags *LedgerEntryFlag `json:",omitempty"`
FirstLedgerSequence *uint32 `json:",omitempty"`
LastLedgerSequence *uint32 `json:",omitempty"`
Hashes *Vector256 `json:",omitempty"`
}
type Majority struct {
Amendment *Hash256 `json:",omitempty"`
CloseTime *uint32 `json:",omitempty"`
}
type Amendments struct {
leBase
Flags *LedgerEntryFlag `json:",omitempty"`
Amendments *Vector256 `json:",omitempty"`
Majorities []Majority `json:",omitempty"`
}
type FeeSettings struct {
leBase
Flags *LedgerEntryFlag `json:",omitempty"`
BaseFee *Uint64Hex `json:",omitempty"`
ReferenceFeeUnits *uint32 `json:",omitempty"`
ReserveBase *uint32 `json:",omitempty"`
ReserveIncrement *uint32 `json:",omitempty"`
}
type DisabledValidator struct {
FirstLedgerSequence *uint32 `json:",omitempty"`
PublicKey *PublicKey `json:",omitempty"`
}
type NegativeUNL struct {
leBase
Flags *LedgerEntryFlag `json:",omitempty"`
DisabledValidators []DisabledValidator `json:",omitempty"`
ValidatorToDisable *VariableLength `json:",omitempty"`
ValidatorToReEnable *VariableLength `json:",omitempty"`
}
type Escrow struct {
leBase
Flags *LedgerEntryFlag `json:",omitempty"`
Account Account `json:",omitempty"`
Destination Account `json:",omitempty"`
Amount Amount `json:",omitempty"`
Condition *VariableLength `json:",omitempty"`
CancelAfter *uint32 `json:",omitempty"`
FinishAfter *uint32 `json:",omitempty"`
SourceTag *uint32 `json:",omitempty"`
DestinationTag *uint32 `json:",omitempty"`
OwnerNode *NodeIndex `json:",omitempty"`
DestinationNode *NodeIndex `json:",omitempty"`
}
type SignerEntry struct {
Account *Account `json:",omitempty"`
SignerWeight *uint16 `json:",omitempty"`
}
type SignerList struct {
leBase
Flags *LedgerEntryFlag `json:",omitempty"`
OwnerNode *NodeIndex `json:",omitempty"`
SignerQuorum *uint32 `json:",omitempty"`
SignerEntries []SignerEntry `json:",omitempty"`
SignerListID *uint32 `json:",omitempty"`
}
type Ticket struct {
leBase
Flags *LedgerEntryFlag `json:",omitempty"`
Account *Account `json:",omitempty"`
TicketSequence *uint32 `json:",omitempty"`
OwnerNode *NodeIndex `json:",omitempty"`
}
type PayChannel struct {
leBase
Flags *LedgerEntryFlag `json:",omitempty"`
Account *Account `json:",omitempty"`
Destination *Account `json:",omitempty"`
Amount *Amount `json:",omitempty"`
Balance *Amount `json:",omitempty"`
PublicKey *PublicKey `json:",omitempty"`
SettleDelay *uint32 `json:",omitempty"`
OwnerNode *NodeIndex `json:",omitempty"`
DestinationNode *NodeIndex `json:",omitempty"`
Expiration *uint32 `json:",omitempty"`
CancelAfter *uint32 `json:",omitempty"`
DestinationTag *uint32 `json:",omitempty"`
SourceTag *uint32 `json:",omitempty"`
}
type Check struct {
leBase
Flags *LedgerEntryFlag `json:",omitempty"`
Account *Account `json:",omitempty"`
Destination *Account `json:",omitempty"`
OwnerNode *NodeIndex `json:",omitempty"`
SendMax *Amount `json:",omitempty"`
Sequence *uint32 `json:",omitempty"`
DestinationNode *NodeIndex `json:",omitempty"`
DestinationTag *uint32 `json:",omitempty"`
Expiration *uint32 `json:",omitempty"`
SourceTag *uint32 `json:",omitempty"`
InvoiceID *Hash256 `json:",omitempty"`
}
type DepositPreAuth struct {
leBase
Account *Account `json:",omitempty"`
Authorize *Account `json:",omitempty"`
Flags *LedgerEntryFlag `json:",omitempty"`
OwnerNode *NodeIndex `json:",omitempty"`
}
type NFToken struct {
NFTokenID Hash256 `json:",omitempty"`
URI VariableLength `json:",omitempty"`
}
// NFTokens is defined as map. Doesn't work properly unless defined like this.
type NFTokens []map[string]NFToken
type NFTokenPage struct {
leBase
Flags LedgerEntryFlag `json:",omitempty"`
PreviousPageMin *Hash256 `json:",omitempty"`
NextPageMin *Hash256 `json:",omitempty"`
NFTokens NFTokens `json:",omitempty"`
}
type NFTokenOffer struct {
leBase
Owner Account `json:",omitempty"`
NFTokenID Hash256 `json:",omitempty"`
Amount Amount `json:",omitempty"`
Expiration *uint32 `json:",omitempty"`
Destination *Account `json:",omitempty"`
//OwnerNode *VariableLength `json:",omitempty"`
//NFTokenOfferNode *VariableLength `json:",omitempty"`
Flags uint32 `json:",omitempty"`
}
func (a *AccountRoot) Affects(account Account) bool {
return a.Account != nil && a.Account.Equals(account)
}
func (r *RippleState) Affects(account Account) bool {
return r.LowLimit.Issuer.Equals(account) || r.HighLimit.Issuer.Equals(account)
}
func (o *Offer) Affects(account Account) bool { return o.Account.Equals(account) }
func (d *Directory) Affects(account Account) bool { return false }
func (l *LedgerHashes) Affects(account Account) bool { return false }
func (a *Amendments) Affects(account Account) bool { return false }
func (f *FeeSettings) Affects(account Account) bool { return false }
func (n *NegativeUNL) Affects(account Account) bool { return false }
func (s *Escrow) Affects(account Account) bool {
return s.Account.Equals(account) || s.Destination.Equals(account)
}
func (s *SignerList) Affects(account Account) bool {
for _, entry := range s.SignerEntries {
if entry.Account != nil && entry.Account.Equals(account) {
return true
}
}
return false
}
func (t *Ticket) Affects(account Account) bool { return t.Account != nil && t.Account.Equals(account) }
func (p *PayChannel) Affects(account Account) bool {
return (p.Account != nil && p.Account.Equals(account)) || (p.Destination != nil && p.Destination.Equals(account))
}
func (p *Check) Affects(account Account) bool {
return (p.Account != nil && p.Account.Equals(account)) || (p.Destination != nil && p.Destination.Equals(account))
}
func (d *DepositPreAuth) Affects(account Account) bool {
return (d.Account != nil && d.Account.Equals(account)) || (d.Authorize != nil && d.Authorize.Equals(account))
}
func (p *NFTokenPage) Affects(account Account) bool { return false }
func (p *NFTokenOffer) Affects(account Account) bool { return false }
func (le *leBase) GetType() string { return ledgerEntryNames[le.LedgerEntryType] }
func (le *leBase) GetLedgerEntryType() LedgerEntryType { return le.LedgerEntryType }
func (le *leBase) Prefix() HashPrefix { return HP_LEAF_NODE }
func (le *leBase) NodeType() NodeType { return NT_ACCOUNT_NODE }
func (le *leBase) Ledger() uint32 { return 0 }
func (le *leBase) GetHash() *Hash256 { return &le.Hash }
func (le *leBase) NodeId() *Hash256 { return &le.Id }
func (le *leBase) GetLedgerIndex() *Hash256 { return le.LedgerIndex }
func (le *leBase) GetPreviousTxnId() *Hash256 { return le.PreviousTxnID }
func (o *Offer) Ratio() *Value {
return o.TakerPays.Ratio(*o.TakerGets)
}