forked from stellar/stellar-xdr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Stellar-ledger-entries.x
797 lines (680 loc) · 17.2 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
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
// 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"
%#include "xdr/Stellar-contract.h"
%#include "xdr/Stellar-contract-config-setting.h"
namespace stellar
{
typedef opaque Thresholds[4];
typedef string string32<32>;
typedef string string64<64>;
typedef int64 SequenceNumber;
typedef opaque DataValue<64>;
typedef Hash PoolID; // SHA256(LiquidityPoolParameters)
// 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,
ASSET_TYPE_POOL_SHARE = 3
};
union AssetCode switch (AssetType type)
{
case ASSET_TYPE_CREDIT_ALPHANUM4:
AssetCode4 assetCode4;
case ASSET_TYPE_CREDIT_ALPHANUM12:
AssetCode12 assetCode12;
// add other asset types here in the future
};
struct AlphaNum4
{
AssetCode4 assetCode;
AccountID issuer;
};
struct AlphaNum12
{
AssetCode12 assetCode;
AccountID issuer;
};
union Asset switch (AssetType type)
{
case ASSET_TYPE_NATIVE: // Not credit
void;
case ASSET_TYPE_CREDIT_ALPHANUM4:
AlphaNum4 alphaNum4;
case ASSET_TYPE_CREDIT_ALPHANUM12:
AlphaNum12 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,
CLAIMABLE_BALANCE = 4,
LIQUIDITY_POOL = 5,
CONTRACT_DATA = 6,
CONTRACT_CODE = 7,
CONFIG_SETTING = 8,
TTL = 9
};
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,
// Trustlines are created with clawback enabled set to "true",
// and claimable balances created from those trustlines are created
// with clawback enabled set to "true"
AUTH_CLAWBACK_ENABLED_FLAG = 0x8
};
// mask for all valid flags
const MASK_ACCOUNT_FLAGS = 0x7;
const MASK_ACCOUNT_FLAGS_V17 = 0xF;
// maximum number of signers
const MAX_SIGNERS = 20;
typedef AccountID* SponsorshipDescriptor;
struct AccountEntryExtensionV3
{
// We can use this to add more fields, or because it is first, to
// change AccountEntryExtensionV3 into a union.
ExtensionPoint ext;
// Ledger number at which `seqNum` took on its present value.
uint32 seqLedger;
// Time at which `seqNum` took on its present value.
TimePoint seqTime;
};
struct AccountEntryExtensionV2
{
uint32 numSponsored;
uint32 numSponsoring;
SponsorshipDescriptor signerSponsoringIDs<MAX_SIGNERS>;
union switch (int v)
{
case 0:
void;
case 3:
AccountEntryExtensionV3 v3;
}
ext;
};
struct AccountEntryExtensionV1
{
Liabilities liabilities;
union switch (int v)
{
case 0:
void;
case 2:
AccountEntryExtensionV2 v2;
}
ext;
};
/* 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<MAX_SIGNERS>; // possible signers for this account
// reserved for future use
union switch (int v)
{
case 0:
void;
case 1:
AccountEntryExtensionV1 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,
// issuer has authorized account to maintain and reduce liabilities for its
// credit
AUTHORIZED_TO_MAINTAIN_LIABILITIES_FLAG = 2,
// issuer has specified that it may clawback its credit, and that claimable
// balances created with its credit may also be clawed back
TRUSTLINE_CLAWBACK_ENABLED_FLAG = 4
};
// mask for all trustline flags
const MASK_TRUSTLINE_FLAGS = 1;
const MASK_TRUSTLINE_FLAGS_V13 = 3;
const MASK_TRUSTLINE_FLAGS_V17 = 7;
enum LiquidityPoolType
{
LIQUIDITY_POOL_CONSTANT_PRODUCT = 0
};
union TrustLineAsset switch (AssetType type)
{
case ASSET_TYPE_NATIVE: // Not credit
void;
case ASSET_TYPE_CREDIT_ALPHANUM4:
AlphaNum4 alphaNum4;
case ASSET_TYPE_CREDIT_ALPHANUM12:
AlphaNum12 alphaNum12;
case ASSET_TYPE_POOL_SHARE:
PoolID liquidityPoolID;
// add other asset types here in the future
};
struct TrustLineEntryExtensionV2
{
int32 liquidityPoolUseCount;
union switch (int v)
{
case 0:
void;
}
ext;
};
struct TrustLineEntry
{
AccountID accountID; // account this trustline belongs to
TrustLineAsset 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;
case 2:
TrustLineEntryExtensionV2 v2;
}
ext;
} v1;
}
ext;
};
enum OfferEntryFlags
{
// an offer with this flag will not act on and take a reverse offer of equal
// price
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;
};
enum ClaimPredicateType
{
CLAIM_PREDICATE_UNCONDITIONAL = 0,
CLAIM_PREDICATE_AND = 1,
CLAIM_PREDICATE_OR = 2,
CLAIM_PREDICATE_NOT = 3,
CLAIM_PREDICATE_BEFORE_ABSOLUTE_TIME = 4,
CLAIM_PREDICATE_BEFORE_RELATIVE_TIME = 5
};
union ClaimPredicate switch (ClaimPredicateType type)
{
case CLAIM_PREDICATE_UNCONDITIONAL:
void;
case CLAIM_PREDICATE_AND:
ClaimPredicate andPredicates<2>;
case CLAIM_PREDICATE_OR:
ClaimPredicate orPredicates<2>;
case CLAIM_PREDICATE_NOT:
ClaimPredicate* notPredicate;
case CLAIM_PREDICATE_BEFORE_ABSOLUTE_TIME:
int64 absBefore; // Predicate will be true if closeTime < absBefore
case CLAIM_PREDICATE_BEFORE_RELATIVE_TIME:
int64 relBefore; // Seconds since closeTime of the ledger in which the
// ClaimableBalanceEntry was created
};
enum ClaimantType
{
CLAIMANT_TYPE_V0 = 0
};
union Claimant switch (ClaimantType type)
{
case CLAIMANT_TYPE_V0:
struct
{
AccountID destination; // The account that can use this condition
ClaimPredicate predicate; // Claimable if predicate is true
} v0;
};
enum ClaimableBalanceIDType
{
CLAIMABLE_BALANCE_ID_TYPE_V0 = 0
};
union ClaimableBalanceID switch (ClaimableBalanceIDType type)
{
case CLAIMABLE_BALANCE_ID_TYPE_V0:
Hash v0;
};
enum ClaimableBalanceFlags
{
// If set, the issuer account of the asset held by the claimable balance may
// clawback the claimable balance
CLAIMABLE_BALANCE_CLAWBACK_ENABLED_FLAG = 0x1
};
const MASK_CLAIMABLE_BALANCE_FLAGS = 0x1;
struct ClaimableBalanceEntryExtensionV1
{
union switch (int v)
{
case 0:
void;
}
ext;
uint32 flags; // see ClaimableBalanceFlags
};
struct ClaimableBalanceEntry
{
// Unique identifier for this ClaimableBalanceEntry
ClaimableBalanceID balanceID;
// List of claimants with associated predicate
Claimant claimants<10>;
// Any asset including native
Asset asset;
// Amount of asset
int64 amount;
// reserved for future use
union switch (int v)
{
case 0:
void;
case 1:
ClaimableBalanceEntryExtensionV1 v1;
}
ext;
};
struct LiquidityPoolConstantProductParameters
{
Asset assetA; // assetA < assetB
Asset assetB;
int32 fee; // Fee is in basis points, so the actual rate is (fee/100)%
};
struct LiquidityPoolEntry
{
PoolID liquidityPoolID;
union switch (LiquidityPoolType type)
{
case LIQUIDITY_POOL_CONSTANT_PRODUCT:
struct
{
LiquidityPoolConstantProductParameters params;
int64 reserveA; // amount of A in the pool
int64 reserveB; // amount of B in the pool
int64 totalPoolShares; // total number of pool shares issued
int64 poolSharesTrustLineCount; // number of trust lines for the
// associated pool shares
} constantProduct;
}
body;
};
enum ContractDataDurability {
TEMPORARY = 0,
PERSISTENT = 1
};
struct ContractDataEntry {
ExtensionPoint ext;
SCAddress contract;
SCVal key;
ContractDataDurability durability;
SCVal val;
};
struct ContractCodeCostInputs {
ExtensionPoint ext;
uint32 nInstructions;
uint32 nFunctions;
uint32 nGlobals;
uint32 nTableEntries;
uint32 nTypes;
uint32 nDataSegments;
uint32 nElemSegments;
uint32 nImports;
uint32 nExports;
uint32 nDataSegmentBytes;
};
struct ContractCodeEntry {
union switch (int v)
{
case 0:
void;
case 1:
struct
{
ExtensionPoint ext;
ContractCodeCostInputs costInputs;
} v1;
} ext;
Hash hash;
opaque code<>;
};
struct TTLEntry {
// Hash of the LedgerKey that is associated with this TTLEntry
Hash keyHash;
uint32 liveUntilLedgerSeq;
};
struct LedgerEntryExtensionV1
{
SponsorshipDescriptor sponsoringID;
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;
case CLAIMABLE_BALANCE:
ClaimableBalanceEntry claimableBalance;
case LIQUIDITY_POOL:
LiquidityPoolEntry liquidityPool;
case CONTRACT_DATA:
ContractDataEntry contractData;
case CONTRACT_CODE:
ContractCodeEntry contractCode;
case CONFIG_SETTING:
ConfigSettingEntry configSetting;
case TTL:
TTLEntry ttl;
}
data;
// reserved for future use
union switch (int v)
{
case 0:
void;
case 1:
LedgerEntryExtensionV1 v1;
}
ext;
};
union LedgerKey switch (LedgerEntryType type)
{
case ACCOUNT:
struct
{
AccountID accountID;
} account;
case TRUSTLINE:
struct
{
AccountID accountID;
TrustLineAsset asset;
} trustLine;
case OFFER:
struct
{
AccountID sellerID;
int64 offerID;
} offer;
case DATA:
struct
{
AccountID accountID;
string64 dataName;
} data;
case CLAIMABLE_BALANCE:
struct
{
ClaimableBalanceID balanceID;
} claimableBalance;
case LIQUIDITY_POOL:
struct
{
PoolID liquidityPoolID;
} liquidityPool;
case CONTRACT_DATA:
struct
{
SCAddress contract;
SCVal key;
ContractDataDurability durability;
} contractData;
case CONTRACT_CODE:
struct
{
Hash hash;
} contractCode;
case CONFIG_SETTING:
struct
{
ConfigSettingID configSettingID;
} configSetting;
case TTL:
struct
{
// Hash of the LedgerKey that is associated with this TTLEntry
Hash keyHash;
} ttl;
};
// list of all envelope types used in the application
// those are prefixes used when building signatures for
// the respective envelopes
enum EnvelopeType
{
ENVELOPE_TYPE_TX_V0 = 0,
ENVELOPE_TYPE_SCP = 1,
ENVELOPE_TYPE_TX = 2,
ENVELOPE_TYPE_AUTH = 3,
ENVELOPE_TYPE_SCPVALUE = 4,
ENVELOPE_TYPE_TX_FEE_BUMP = 5,
ENVELOPE_TYPE_OP_ID = 6,
ENVELOPE_TYPE_POOL_REVOKE_OP_ID = 7,
ENVELOPE_TYPE_CONTRACT_ID = 8,
ENVELOPE_TYPE_SOROBAN_AUTHORIZATION = 9
};
enum BucketListType
{
LIVE = 0,
HOT_ARCHIVE = 1,
COLD_ARCHIVE = 2
};
/* Entries used to define the bucket list */
enum BucketEntryType
{
METAENTRY =
-1, // At-and-after protocol 11: bucket metadata, should come first.
LIVEENTRY = 0, // Before protocol 11: created-or-updated;
// At-and-after protocol 11: only updated.
DEADENTRY = 1,
INITENTRY = 2 // At-and-after protocol 11: only created.
};
enum HotArchiveBucketEntryType
{
HOT_ARCHIVE_METAENTRY = -1, // Bucket metadata, should come first.
HOT_ARCHIVE_ARCHIVED = 0, // Entry is Archived
HOT_ARCHIVE_LIVE = 1, // Entry was previously HOT_ARCHIVE_ARCHIVED, or HOT_ARCHIVE_DELETED, but
// has been added back to the live BucketList.
// Does not need to be persisted.
HOT_ARCHIVE_DELETED = 2 // Entry deleted (Note: must be persisted in archive)
};
enum ColdArchiveBucketEntryType
{
COLD_ARCHIVE_METAENTRY = -1, // Bucket metadata, should come first.
COLD_ARCHIVE_ARCHIVED_LEAF = 0, // Full LedgerEntry that was archived during the epoch
COLD_ARCHIVE_DELETED_LEAF = 1, // LedgerKey that was deleted during the epoch
COLD_ARCHIVE_BOUNDARY_LEAF = 2, // Dummy leaf representing low/high bound
COLD_ARCHIVE_HASH = 3 // Intermediary Merkle hash entry
};
struct BucketMetadata
{
// Indicates the protocol version used to create / merge this bucket.
uint32 ledgerVersion;
// reserved for future use
union switch (int v)
{
case 0:
void;
case 1:
BucketListType bucketListType;
}
ext;
};
union BucketEntry switch (BucketEntryType type)
{
case LIVEENTRY:
case INITENTRY:
LedgerEntry liveEntry;
case DEADENTRY:
LedgerKey deadEntry;
case METAENTRY:
BucketMetadata metaEntry;
};
union HotArchiveBucketEntry switch (HotArchiveBucketEntryType type)
{
case HOT_ARCHIVE_ARCHIVED:
LedgerEntry archivedEntry;
case HOT_ARCHIVE_LIVE:
case HOT_ARCHIVE_DELETED:
LedgerKey key;
case HOT_ARCHIVE_METAENTRY:
BucketMetadata metaEntry;
};
struct ColdArchiveArchivedLeaf
{
uint32 index;
LedgerEntry archivedEntry;
};
struct ColdArchiveDeletedLeaf
{
uint32 index;
LedgerKey deletedKey;
};
struct ColdArchiveBoundaryLeaf
{
uint32 index;
bool isLowerBound;
};
struct ColdArchiveHashEntry
{
uint32 index;
uint32 level;
Hash hash;
};
union ColdArchiveBucketEntry switch (ColdArchiveBucketEntryType type)
{
case COLD_ARCHIVE_METAENTRY:
BucketMetadata metaEntry;
case COLD_ARCHIVE_ARCHIVED_LEAF:
ColdArchiveArchivedLeaf archivedLeaf;
case COLD_ARCHIVE_DELETED_LEAF:
ColdArchiveDeletedLeaf deletedLeaf;
case COLD_ARCHIVE_BOUNDARY_LEAF:
ColdArchiveBoundaryLeaf boundaryLeaf;
case COLD_ARCHIVE_HASH:
ColdArchiveHashEntry hashEntry;
};
}