forked from stellar/stellar-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStellar-ledger-entries.x
295 lines (248 loc) · 6.26 KB
/
Stellar-ledger-entries.x
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
// Copyright 2015 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
%#include "xdr/Stellar-types.h"
namespace stellar
{
typedef PublicKey AccountID;
typedef opaque Thresholds[4];
typedef string string32<32>;
typedef string string64<64>;
typedef int64 SequenceNumber;
typedef uint64 TimePoint;
typedef opaque DataValue<64>;
// 1-4 alphanumeric characters right-padded with 0 bytes
typedef opaque AssetCode4[4];
// 5-12 alphanumeric characters right-padded with 0 bytes
typedef opaque AssetCode12[12];
enum AssetType
{
ASSET_TYPE_NATIVE = 0,
ASSET_TYPE_CREDIT_ALPHANUM4 = 1,
ASSET_TYPE_CREDIT_ALPHANUM12 = 2
};
union Asset switch (AssetType type)
{
case ASSET_TYPE_NATIVE: // Not credit
void;
case ASSET_TYPE_CREDIT_ALPHANUM4:
struct
{
AssetCode4 assetCode;
AccountID issuer;
} alphaNum4;
case ASSET_TYPE_CREDIT_ALPHANUM12:
struct
{
AssetCode12 assetCode;
AccountID issuer;
} alphaNum12;
// add other asset types here in the future
};
// price in fractional representation
struct Price
{
int32 n; // numerator
int32 d; // denominator
};
struct Liabilities
{
int64 buying;
int64 selling;
};
// the 'Thresholds' type is packed uint8_t values
// defined by these indexes
enum ThresholdIndexes
{
THRESHOLD_MASTER_WEIGHT = 0,
THRESHOLD_LOW = 1,
THRESHOLD_MED = 2,
THRESHOLD_HIGH = 3
};
enum LedgerEntryType
{
ACCOUNT = 0,
TRUSTLINE = 1,
OFFER = 2,
DATA = 3
};
struct Signer
{
SignerKey key;
uint32 weight; // really only need 1 byte
};
enum AccountFlags
{ // masks for each flag
// Flags set on issuer accounts
// TrustLines are created with authorized set to "false" requiring
// the issuer to set it for each TrustLine
AUTH_REQUIRED_FLAG = 0x1,
// If set, the authorized flag in TrustLines can be cleared
// otherwise, authorization cannot be revoked
AUTH_REVOCABLE_FLAG = 0x2,
// Once set, causes all AUTH_* flags to be read-only
AUTH_IMMUTABLE_FLAG = 0x4
};
// mask for all valid flags
const MASK_ACCOUNT_FLAGS = 0x7;
/* AccountEntry
Main entry representing a user in Stellar. All transactions are
performed using an account.
Other ledger entries created require an account.
*/
struct AccountEntry
{
AccountID accountID; // master public key for this account
int64 balance; // in stroops
SequenceNumber seqNum; // last sequence number used for this account
uint32 numSubEntries; // number of sub-entries this account has
// drives the reserve
AccountID* inflationDest; // Account to vote for during inflation
uint32 flags; // see AccountFlags
string32 homeDomain; // can be used for reverse federation and memo lookup
// fields used for signatures
// thresholds stores unsigned bytes: [weight of master|low|medium|high]
Thresholds thresholds;
Signer signers<20>; // possible signers for this account
// reserved for future use
union switch (int v)
{
case 0:
void;
case 1:
struct
{
Liabilities liabilities;
union switch (int v)
{
case 0:
void;
}
ext;
} v1;
}
ext;
};
/* TrustLineEntry
A trust line represents a specific trust relationship with
a credit/issuer (limit, authorization)
as well as the balance.
*/
enum TrustLineFlags
{
// issuer has authorized account to perform transactions with its credit
AUTHORIZED_FLAG = 1
};
// mask for all trustline flags
const MASK_TRUSTLINE_FLAGS = 1;
struct TrustLineEntry
{
AccountID accountID; // account this trustline belongs to
Asset asset; // type of asset (with issuer)
int64 balance; // how much of this asset the user has.
// Asset defines the unit for this;
int64 limit; // balance cannot be above this
uint32 flags; // see TrustLineFlags
// reserved for future use
union switch (int v)
{
case 0:
void;
case 1:
struct
{
Liabilities liabilities;
union switch (int v)
{
case 0:
void;
}
ext;
} v1;
}
ext;
};
enum OfferEntryFlags
{
// issuer has authorized account to perform transactions with its credit
PASSIVE_FLAG = 1
};
// Mask for OfferEntry flags
const MASK_OFFERENTRY_FLAGS = 1;
/* OfferEntry
An offer is the building block of the offer book, they are automatically
claimed by payments when the price set by the owner is met.
For example an Offer is selling 10A where 1A is priced at 1.5B
*/
struct OfferEntry
{
AccountID sellerID;
int64 offerID;
Asset selling; // A
Asset buying; // B
int64 amount; // amount of A
/* price for this offer:
price of A in terms of B
price=AmountB/AmountA=priceNumerator/priceDenominator
price is after fees
*/
Price price;
uint32 flags; // see OfferEntryFlags
// reserved for future use
union switch (int v)
{
case 0:
void;
}
ext;
};
/* DataEntry
Data can be attached to accounts.
*/
struct DataEntry
{
AccountID accountID; // account this data belongs to
string64 dataName;
DataValue dataValue;
// reserved for future use
union switch (int v)
{
case 0:
void;
}
ext;
};
struct LedgerEntry
{
uint32 lastModifiedLedgerSeq; // ledger the LedgerEntry was last changed
union switch (LedgerEntryType type)
{
case ACCOUNT:
AccountEntry account;
case TRUSTLINE:
TrustLineEntry trustLine;
case OFFER:
OfferEntry offer;
case DATA:
DataEntry data;
}
data;
// reserved for future use
union switch (int v)
{
case 0:
void;
}
ext;
};
// list of all envelope types used in the application
// those are prefixes used when building signatures for
// the respective envelopes
enum EnvelopeType
{
ENVELOPE_TYPE_SCP = 1,
ENVELOPE_TYPE_TX = 2,
ENVELOPE_TYPE_AUTH = 3,
ENVELOPE_TYPE_SCPVALUE = 4
};
}