This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathflags.go
201 lines (180 loc) · 5.41 KB
/
flags.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
package data
import (
"fmt"
)
type TransactionFlag uint32
type LedgerEntryFlag uint32
// Transaction Flags
const (
//Universal flags
TxCanonicalSignature TransactionFlag = 0x80000000
// Payment flags
TxNoDirectRipple TransactionFlag = 0x00010000
TxPartialPayment TransactionFlag = 0x00020000
TxLimitQuality TransactionFlag = 0x00040000
TxCircle TransactionFlag = 0x00080000 // Not implemented
// AccountSet flags
TxSetRequireDest TransactionFlag = 0x00000001
TxSetRequireAuth TransactionFlag = 0x00000002
TxSetDisallowXRP TransactionFlag = 0x00000003
TxSetDisableMaster TransactionFlag = 0x00000004
TxSetAccountTxnID TransactionFlag = 0x00000005
TxNoFreeze TransactionFlag = 0x00000006
TxGlobalFreeze TransactionFlag = 0x00000007
TxDefaultRipple TransactionFlag = 0x00000008
TxRequireDestTag TransactionFlag = 0x00010000
TxOptionalDestTag TransactionFlag = 0x00020000
TxRequireAuth TransactionFlag = 0x00040000
TxOptionalAuth TransactionFlag = 0x00080000
TxDisallowXRP TransactionFlag = 0x00100000
TxAllowXRP TransactionFlag = 0x00200000
// OfferCreate flags
TxPassive TransactionFlag = 0x00010000
TxImmediateOrCancel TransactionFlag = 0x00020000
TxFillOrKill TransactionFlag = 0x00040000
TxSell TransactionFlag = 0x00080000
// TrustSet flags
TxSetAuth TransactionFlag = 0x00010000
TxSetNoRipple TransactionFlag = 0x00020000
TxClearNoRipple TransactionFlag = 0x00040000
TxSetFreeze TransactionFlag = 0x00100000
TxClearFreeze TransactionFlag = 0x00200000
// EnableAmendments flags
TxGotMajority TransactionFlag = 0x00010000
TxLostMajority TransactionFlag = 0x00020000
// PaymentChannelClaim flags
TxRenew TransactionFlag = 0x00010000
TxClose TransactionFlag = 0x00020000
)
var txFlagNames = map[TransactionType][]struct {
Flag TransactionFlag
Name string
}{
PAYMENT: {
{TxNoDirectRipple, "NoDirectRipple"},
{TxPartialPayment, "PartialPayment"},
{TxLimitQuality, "LimitQuality"},
{TxCircle, "Circle"},
},
ACCOUNT_SET: {
{TxSetRequireDest, "SetRequireDest"},
{TxSetRequireAuth, "SetRequireAuth"},
{TxSetDisallowXRP, "SetDisallowXRP"},
{TxSetDisableMaster, "SetDisableMaster"},
{TxNoFreeze, "NoFreeze"},
{TxGlobalFreeze, "GlobalFreeze"},
{TxRequireDestTag, "RequireDestTag"},
{TxOptionalDestTag, "OptionalDestTag"},
{TxRequireAuth, "RequireAuth"},
{TxDisallowXRP, "DisallowXRP"},
{TxAllowXRP, "AllowXRP"},
},
OFFER_CREATE: {
{TxPassive, "Passive"},
{TxImmediateOrCancel, "ImmediateOrCancel"},
{TxFillOrKill, "FillOrKill"},
{TxSell, "Sell"},
},
TRUST_SET: {
{TxSetAuth, "SetAuth"},
{TxSetNoRipple, "SetNoRipple"},
{TxClearNoRipple, "ClearNoRipple"},
{TxSetFreeze, "SetFreeze"},
{TxClearFreeze, "ClearFreeze"},
},
}
// Ledger entry flags
const (
// AccountRoot flags
LsPasswordSpent LedgerEntryFlag = 0x00010000
LsRequireDestTag LedgerEntryFlag = 0x00020000
LsRequireAuth LedgerEntryFlag = 0x00040000
LsDisallowXRP LedgerEntryFlag = 0x00080000
LsDisableMaster LedgerEntryFlag = 0x00100000
LsNoFreeze LedgerEntryFlag = 0x00200000
LsGlobalFreeze LedgerEntryFlag = 0x00400000
LsDefaultRipple LedgerEntryFlag = 0x00800000
// Offer flags
LsPassive LedgerEntryFlag = 0x00010000
LsSell LedgerEntryFlag = 0x00020000
// RippleState flags
LsLowReserve LedgerEntryFlag = 0x00010000
LsHighReserve LedgerEntryFlag = 0x00020000
LsLowAuth LedgerEntryFlag = 0x00040000
LsHighAuth LedgerEntryFlag = 0x00080000
LsLowNoRipple LedgerEntryFlag = 0x00100000
LsHighNoRipple LedgerEntryFlag = 0x00200000
LsLowFreeze LedgerEntryFlag = 0x00400000
LsHighFreeze LedgerEntryFlag = 0x00800000
// SignerList flags
LsOneOwnerCount LedgerEntryFlag = 0x00010000
// DirNode flags
LsNFTokenBuyOffers LedgerEntryFlag = 0x00000001
LsNFTokenSellOffers LedgerEntryFlag = 0x00000002
// TokenOffer flags
LsSellNFToken LedgerEntryFlag = 0x00000001
)
var leFlagNames = map[LedgerEntryType][]struct {
Flag LedgerEntryFlag
Name string
}{
ACCOUNT_ROOT: {
{LsPasswordSpent, "PasswordSpent"},
{LsRequireDestTag, "RequireDestTag"},
{LsRequireAuth, "RequireAuth"},
{LsDisallowXRP, "DisallowXRP"},
{LsDisableMaster, "DisableMaster"},
{LsNoFreeze, "NoFreeze"},
},
OFFER: {
{LsPassive, "Passive"},
{LsSell, "Sell"},
},
RIPPLE_STATE: {
{LsLowReserve, "LowReserve"},
{LsHighReserve, "HighReserve"},
{LsLowAuth, "LowAuth"},
{LsHighAuth, "HighAuth"},
{LsLowNoRipple, "LowNoRipple"},
{LsHighNoRipple, "HighNoRipple"},
{LsLowFreeze, "LowFreeze"},
{LsHighFreeze, "HighFreeze"},
},
SIGNER_LIST: {
{LsOneOwnerCount, "OneOwnerCount"},
},
DIRECTORY: {
{LsNFTokenBuyOffers, "NFTokenBuyOffers"},
{LsNFTokenSellOffers, "NFTokenSellOffers"},
},
NFTOKEN_OFFER: {
{LsSellNFToken, "SellNFToken"},
},
}
func (f TransactionFlag) String() string {
return fmt.Sprintf("%08X", uint32(f))
}
func (f LedgerEntryFlag) String() string {
return fmt.Sprintf("%08X", uint32(f))
}
func (f TransactionFlag) Explain(tx Transaction) []string {
var flags []string
if f&TxCanonicalSignature > 0 {
flags = append(flags, "CanonicalSignature")
}
for _, n := range txFlagNames[tx.GetTransactionType()] {
if f&n.Flag > 0 {
flags = append(flags, n.Name)
}
}
return flags
}
func (f LedgerEntryFlag) Explain(le LedgerEntry) []string {
var flags []string
for _, n := range leFlagNames[le.GetLedgerEntryType()] {
if f&n.Flag > 0 {
flags = append(flags, n.Name)
}
}
return flags
}