-
Notifications
You must be signed in to change notification settings - Fork 979
/
Copy pathStellar-transaction.x
731 lines (601 loc) · 18.8 KB
/
Stellar-transaction.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
// 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-ledger-entries.h"
namespace stellar
{
struct DecoratedSignature
{
SignatureHint hint; // last 4 bytes of the public key, used as a hint
Signature signature; // actual signature
};
enum OperationType
{
CREATE_ACCOUNT = 0,
PAYMENT = 1,
PATH_PAYMENT = 2,
MANAGE_OFFER = 3,
CREATE_PASSIVE_OFFER = 4,
SET_OPTIONS = 5,
CHANGE_TRUST = 6,
ALLOW_TRUST = 7,
ACCOUNT_MERGE = 8,
INFLATION = 9,
MANAGE_DATA = 10
};
/* CreateAccount
Creates and funds a new account with the specified starting balance.
Threshold: med
Result: CreateAccountResult
*/
struct CreateAccountOp
{
AccountID destination; // account to create
int64 startingBalance; // amount they end up with
};
/* Payment
Send an amount in specified asset to a destination account.
Threshold: med
Result: PaymentResult
*/
struct PaymentOp
{
AccountID destination; // recipient of the payment
Asset asset; // what they end up with
int64 amount; // amount they end up with
};
/* PathPayment
send an amount to a destination account through a path.
(up to sendMax, sendAsset)
(X0, Path[0]) .. (Xn, Path[n])
(destAmount, destAsset)
Threshold: med
Result: PathPaymentResult
*/
struct PathPaymentOp
{
Asset sendAsset; // asset we pay with
int64 sendMax; // the maximum amount of sendAsset to
// send (excluding fees).
// The operation will fail if can't be met
AccountID destination; // recipient of the payment
Asset destAsset; // what they end up with
int64 destAmount; // amount they end up with
Asset path<5>; // additional hops it must go through to get there
};
/* Creates, updates or deletes an offer
Threshold: med
Result: ManageOfferResult
*/
struct ManageOfferOp
{
Asset selling;
Asset buying;
int64 amount; // amount being sold. if set to 0, delete the offer
Price price; // price of thing being sold in terms of what you are buying
// 0=create a new offer, otherwise edit an existing offer
uint64 offerID;
};
/* Creates an offer that doesn't take offers of the same price
Threshold: med
Result: CreatePassiveOfferResult
*/
struct CreatePassiveOfferOp
{
Asset selling; // A
Asset buying; // B
int64 amount; // amount taker gets. if set to 0, delete the offer
Price price; // cost of A in terms of B
};
/* Set Account Options
updates "AccountEntry" fields.
note: updating thresholds or signers requires high threshold
Threshold: med or high
Result: SetOptionsResult
*/
struct SetOptionsOp
{
AccountID* inflationDest; // sets the inflation destination
uint32* clearFlags; // which flags to clear
uint32* setFlags; // which flags to set
// account threshold manipulation
uint32* masterWeight; // weight of the master account
uint32* lowThreshold;
uint32* medThreshold;
uint32* highThreshold;
string32* homeDomain; // sets the home domain
// Add, update or remove a signer for the account
// signer is deleted if the weight is 0
Signer* signer;
};
/* Creates, updates or deletes a trust line
Threshold: med
Result: ChangeTrustResult
*/
struct ChangeTrustOp
{
Asset line;
// if limit is set to 0, deletes the trust line
int64 limit;
};
/* Updates the "authorized" flag of an existing trust line
this is called by the issuer of the related asset.
note that authorize can only be set (and not cleared) if
the issuer account does not have the AUTH_REVOCABLE_FLAG set
Threshold: low
Result: AllowTrustResult
*/
struct AllowTrustOp
{
AccountID trustor;
union switch (AssetType type)
{
// ASSET_TYPE_NATIVE is not allowed
case ASSET_TYPE_CREDIT_ALPHANUM4:
opaque assetCode4[4];
case ASSET_TYPE_CREDIT_ALPHANUM12:
opaque assetCode12[12];
// add other asset types here in the future
}
asset;
bool authorize;
};
/* Inflation
Runs inflation
Threshold: low
Result: InflationResult
*/
/* AccountMerge
Transfers native balance to destination account.
Threshold: high
Result : AccountMergeResult
*/
/* ManageData
Adds, Updates, or Deletes a key value pair associated with a particular
account.
Threshold: med
Result: ManageDataResult
*/
struct ManageDataOp
{
string64 dataName;
DataValue* dataValue; // set to null to clear
};
/* An operation is the lowest unit of work that a transaction does */
struct Operation
{
// sourceAccount is the account used to run the operation
// if not set, the runtime defaults to "sourceAccount" specified at
// the transaction level
AccountID* sourceAccount;
union switch (OperationType type)
{
case CREATE_ACCOUNT:
CreateAccountOp createAccountOp;
case PAYMENT:
PaymentOp paymentOp;
case PATH_PAYMENT:
PathPaymentOp pathPaymentOp;
case MANAGE_OFFER:
ManageOfferOp manageOfferOp;
case CREATE_PASSIVE_OFFER:
CreatePassiveOfferOp createPassiveOfferOp;
case SET_OPTIONS:
SetOptionsOp setOptionsOp;
case CHANGE_TRUST:
ChangeTrustOp changeTrustOp;
case ALLOW_TRUST:
AllowTrustOp allowTrustOp;
case ACCOUNT_MERGE:
AccountID destination;
case INFLATION:
void;
case MANAGE_DATA:
ManageDataOp manageDataOp;
}
body;
};
enum MemoType
{
MEMO_NONE = 0,
MEMO_TEXT = 1,
MEMO_ID = 2,
MEMO_HASH = 3,
MEMO_RETURN = 4
};
union Memo switch (MemoType type)
{
case MEMO_NONE:
void;
case MEMO_TEXT:
string text<28>;
case MEMO_ID:
uint64 id;
case MEMO_HASH:
Hash hash; // the hash of what to pull from the content server
case MEMO_RETURN:
Hash retHash; // the hash of the tx you are rejecting
};
struct TimeBounds
{
uint64 minTime;
uint64 maxTime; // 0 here means no maxTime
};
/* a transaction is a container for a set of operations
- is executed by an account
- fees are collected from the account
- operations are executed in order as one ACID transaction
either all operations are applied or none are
if any returns a failing code
*/
struct Transaction
{
// account used to run the transaction
AccountID sourceAccount;
// the fee the sourceAccount will pay
uint32 fee;
// sequence number to consume in the account
SequenceNumber seqNum;
// validity range (inclusive) for the last ledger close time
TimeBounds* timeBounds;
Memo memo;
Operation operations<100>;
// reserved for future use
union switch (int v)
{
case 0:
void;
}
ext;
};
struct TransactionSignaturePayload {
Hash networkId;
union switch (EnvelopeType type)
{
case ENVELOPE_TYPE_TX:
Transaction tx;
/* All other values of type are invalid */
} taggedTransaction;
};
/* A TransactionEnvelope wraps a transaction with signatures. */
struct TransactionEnvelope
{
Transaction tx;
/* Each decorated signature is a signature over the SHA256 hash of
* a TransactionSignaturePayload */
DecoratedSignature
signatures<20>;
};
/* Operation Results section */
/* This result is used when offers are taken during an operation */
struct ClaimOfferAtom
{
// emitted to identify the offer
AccountID sellerID; // Account that owns the offer
uint64 offerID;
// amount and asset taken from the owner
Asset assetSold;
int64 amountSold;
// amount and asset sent to the owner
Asset assetBought;
int64 amountBought;
};
/******* CreateAccount Result ********/
enum CreateAccountResultCode
{
// codes considered as "success" for the operation
CREATE_ACCOUNT_SUCCESS = 0, // account was created
// codes considered as "failure" for the operation
CREATE_ACCOUNT_MALFORMED = -1, // invalid destination
CREATE_ACCOUNT_UNDERFUNDED = -2, // not enough funds in source account
CREATE_ACCOUNT_LOW_RESERVE =
-3, // would create an account below the min reserve
CREATE_ACCOUNT_ALREADY_EXIST = -4 // account already exists
};
union CreateAccountResult switch (CreateAccountResultCode code)
{
case CREATE_ACCOUNT_SUCCESS:
void;
default:
void;
};
/******* Payment Result ********/
enum PaymentResultCode
{
// codes considered as "success" for the operation
PAYMENT_SUCCESS = 0, // payment successfuly completed
// codes considered as "failure" for the operation
PAYMENT_MALFORMED = -1, // bad input
PAYMENT_UNDERFUNDED = -2, // not enough funds in source account
PAYMENT_SRC_NO_TRUST = -3, // no trust line on source account
PAYMENT_SRC_NOT_AUTHORIZED = -4, // source not authorized to transfer
PAYMENT_NO_DESTINATION = -5, // destination account does not exist
PAYMENT_NO_TRUST = -6, // destination missing a trust line for asset
PAYMENT_NOT_AUTHORIZED = -7, // destination not authorized to hold asset
PAYMENT_LINE_FULL = -8, // destination would go above their limit
PAYMENT_NO_ISSUER = -9 // missing issuer on asset
};
union PaymentResult switch (PaymentResultCode code)
{
case PAYMENT_SUCCESS:
void;
default:
void;
};
/******* Payment Result ********/
enum PathPaymentResultCode
{
// codes considered as "success" for the operation
PATH_PAYMENT_SUCCESS = 0, // success
// codes considered as "failure" for the operation
PATH_PAYMENT_MALFORMED = -1, // bad input
PATH_PAYMENT_UNDERFUNDED = -2, // not enough funds in source account
PATH_PAYMENT_SRC_NO_TRUST = -3, // no trust line on source account
PATH_PAYMENT_SRC_NOT_AUTHORIZED = -4, // source not authorized to transfer
PATH_PAYMENT_NO_DESTINATION = -5, // destination account does not exist
PATH_PAYMENT_NO_TRUST = -6, // dest missing a trust line for asset
PATH_PAYMENT_NOT_AUTHORIZED = -7, // dest not authorized to hold asset
PATH_PAYMENT_LINE_FULL = -8, // dest would go above their limit
PATH_PAYMENT_NO_ISSUER = -9, // missing issuer on one asset
PATH_PAYMENT_TOO_FEW_OFFERS = -10, // not enough offers to satisfy path
PATH_PAYMENT_OFFER_CROSS_SELF = -11, // would cross one of its own offers
PATH_PAYMENT_OVER_SENDMAX = -12 // could not satisfy sendmax
};
struct SimplePaymentResult
{
AccountID destination;
Asset asset;
int64 amount;
};
union PathPaymentResult switch (PathPaymentResultCode code)
{
case PATH_PAYMENT_SUCCESS:
struct
{
ClaimOfferAtom offers<>;
SimplePaymentResult last;
} success;
case PATH_PAYMENT_NO_ISSUER:
Asset noIssuer; // the asset that caused the error
default:
void;
};
/******* ManageOffer Result ********/
enum ManageOfferResultCode
{
// codes considered as "success" for the operation
MANAGE_OFFER_SUCCESS = 0,
// codes considered as "failure" for the operation
MANAGE_OFFER_MALFORMED = -1, // generated offer would be invalid
MANAGE_OFFER_SELL_NO_TRUST = -2, // no trust line for what we're selling
MANAGE_OFFER_BUY_NO_TRUST = -3, // no trust line for what we're buying
MANAGE_OFFER_SELL_NOT_AUTHORIZED = -4, // not authorized to sell
MANAGE_OFFER_BUY_NOT_AUTHORIZED = -5, // not authorized to buy
MANAGE_OFFER_LINE_FULL = -6, // can't receive more of what it's buying
MANAGE_OFFER_UNDERFUNDED = -7, // doesn't hold what it's trying to sell
MANAGE_OFFER_CROSS_SELF = -8, // would cross an offer from the same user
MANAGE_OFFER_SELL_NO_ISSUER = -9, // no issuer for what we're selling
MANAGE_OFFER_BUY_NO_ISSUER = -10, // no issuer for what we're buying
// update errors
MANAGE_OFFER_NOT_FOUND = -11, // offerID does not match an existing offer
MANAGE_OFFER_LOW_RESERVE = -12 // not enough funds to create a new Offer
};
enum ManageOfferEffect
{
MANAGE_OFFER_CREATED = 0,
MANAGE_OFFER_UPDATED = 1,
MANAGE_OFFER_DELETED = 2
};
struct ManageOfferSuccessResult
{
// offers that got claimed while creating this offer
ClaimOfferAtom offersClaimed<>;
union switch (ManageOfferEffect effect)
{
case MANAGE_OFFER_CREATED:
case MANAGE_OFFER_UPDATED:
OfferEntry offer;
default:
void;
}
offer;
};
union ManageOfferResult switch (ManageOfferResultCode code)
{
case MANAGE_OFFER_SUCCESS:
ManageOfferSuccessResult success;
default:
void;
};
/******* SetOptions Result ********/
enum SetOptionsResultCode
{
// codes considered as "success" for the operation
SET_OPTIONS_SUCCESS = 0,
// codes considered as "failure" for the operation
SET_OPTIONS_LOW_RESERVE = -1, // not enough funds to add a signer
SET_OPTIONS_TOO_MANY_SIGNERS = -2, // max number of signers already reached
SET_OPTIONS_BAD_FLAGS = -3, // invalid combination of clear/set flags
SET_OPTIONS_INVALID_INFLATION = -4, // inflation account does not exist
SET_OPTIONS_CANT_CHANGE = -5, // can no longer change this option
SET_OPTIONS_UNKNOWN_FLAG = -6, // can't set an unknown flag
SET_OPTIONS_THRESHOLD_OUT_OF_RANGE = -7, // bad value for weight/threshold
SET_OPTIONS_BAD_SIGNER = -8, // signer cannot be masterkey
SET_OPTIONS_INVALID_HOME_DOMAIN = -9 // malformed home domain
};
union SetOptionsResult switch (SetOptionsResultCode code)
{
case SET_OPTIONS_SUCCESS:
void;
default:
void;
};
/******* ChangeTrust Result ********/
enum ChangeTrustResultCode
{
// codes considered as "success" for the operation
CHANGE_TRUST_SUCCESS = 0,
// codes considered as "failure" for the operation
CHANGE_TRUST_MALFORMED = -1, // bad input
CHANGE_TRUST_NO_ISSUER = -2, // could not find issuer
CHANGE_TRUST_INVALID_LIMIT = -3, // cannot drop limit below balance
// cannot create with a limit of 0
CHANGE_TRUST_LOW_RESERVE = -4 // not enough funds to create a new trust line
};
union ChangeTrustResult switch (ChangeTrustResultCode code)
{
case CHANGE_TRUST_SUCCESS:
void;
default:
void;
};
/******* AllowTrust Result ********/
enum AllowTrustResultCode
{
// codes considered as "success" for the operation
ALLOW_TRUST_SUCCESS = 0,
// codes considered as "failure" for the operation
ALLOW_TRUST_MALFORMED = -1, // asset is not ASSET_TYPE_ALPHANUM
ALLOW_TRUST_NO_TRUST_LINE = -2, // trustor does not have a trustline
// source account does not require trust
ALLOW_TRUST_TRUST_NOT_REQUIRED = -3,
ALLOW_TRUST_CANT_REVOKE = -4 // source account can't revoke trust
};
union AllowTrustResult switch (AllowTrustResultCode code)
{
case ALLOW_TRUST_SUCCESS:
void;
default:
void;
};
/******* AccountMerge Result ********/
enum AccountMergeResultCode
{
// codes considered as "success" for the operation
ACCOUNT_MERGE_SUCCESS = 0,
// codes considered as "failure" for the operation
ACCOUNT_MERGE_MALFORMED = -1, // can't merge onto itself
ACCOUNT_MERGE_NO_ACCOUNT = -2, // destination does not exist
ACCOUNT_MERGE_IMMUTABLE_SET = -3, // source account has AUTH_IMMUTABLE set
ACCOUNT_MERGE_HAS_SUB_ENTRIES = -4 // account has trust lines/offers
};
union AccountMergeResult switch (AccountMergeResultCode code)
{
case ACCOUNT_MERGE_SUCCESS:
int64 sourceAccountBalance; // how much got transfered from source account
default:
void;
};
/******* Inflation Result ********/
enum InflationResultCode
{
// codes considered as "success" for the operation
INFLATION_SUCCESS = 0,
// codes considered as "failure" for the operation
INFLATION_NOT_TIME = -1
};
struct InflationPayout // or use PaymentResultAtom to limit types?
{
AccountID destination;
int64 amount;
};
union InflationResult switch (InflationResultCode code)
{
case INFLATION_SUCCESS:
InflationPayout payouts<>;
default:
void;
};
/******* ManageData Result ********/
enum ManageDataResultCode
{
// codes considered as "success" for the operation
MANAGE_DATA_SUCCESS = 0,
// codes considered as "failure" for the operation
MANAGE_DATA_NOT_SUPPORTED_YET = -1, // The network hasn't moved to this protocol change yet
MANAGE_DATA_NAME_NOT_FOUND = -2, // Trying to remove a Data Entry that isn't there
MANAGE_DATA_LOW_RESERVE = -3, // not enough funds to create a new Data Entry
MANAGE_DATA_INVALID_NAME = -4 // Name not a valid string
};
union ManageDataResult switch (ManageDataResultCode code)
{
case MANAGE_DATA_SUCCESS:
void;
default:
void;
};
/* High level Operation Result */
enum OperationResultCode
{
opINNER = 0, // inner object result is valid
opBAD_AUTH = -1, // too few valid signatures / wrong network
opNO_ACCOUNT = -2 // source account was not found
};
union OperationResult switch (OperationResultCode code)
{
case opINNER:
union switch (OperationType type)
{
case CREATE_ACCOUNT:
CreateAccountResult createAccountResult;
case PAYMENT:
PaymentResult paymentResult;
case PATH_PAYMENT:
PathPaymentResult pathPaymentResult;
case MANAGE_OFFER:
ManageOfferResult manageOfferResult;
case CREATE_PASSIVE_OFFER:
ManageOfferResult createPassiveOfferResult;
case SET_OPTIONS:
SetOptionsResult setOptionsResult;
case CHANGE_TRUST:
ChangeTrustResult changeTrustResult;
case ALLOW_TRUST:
AllowTrustResult allowTrustResult;
case ACCOUNT_MERGE:
AccountMergeResult accountMergeResult;
case INFLATION:
InflationResult inflationResult;
case MANAGE_DATA:
ManageDataResult manageDataResult;
}
tr;
default:
void;
};
enum TransactionResultCode
{
txSUCCESS = 0, // all operations succeeded
txFAILED = -1, // one of the operations failed (none were applied)
txTOO_EARLY = -2, // ledger closeTime before minTime
txTOO_LATE = -3, // ledger closeTime after maxTime
txMISSING_OPERATION = -4, // no operation was specified
txBAD_SEQ = -5, // sequence number does not match source account
txBAD_AUTH = -6, // too few valid signatures / wrong network
txINSUFFICIENT_BALANCE = -7, // fee would bring account below reserve
txNO_ACCOUNT = -8, // source account not found
txINSUFFICIENT_FEE = -9, // fee is too small
txBAD_AUTH_EXTRA = -10, // unused signatures attached to transaction
txINTERNAL_ERROR = -11 // an unknown error occured
};
struct TransactionResult
{
int64 feeCharged; // actual fee charged for the transaction
union switch (TransactionResultCode code)
{
case txSUCCESS:
case txFAILED:
OperationResult results<>;
default:
void;
}
result;
// reserved for future use
union switch (int v)
{
case 0:
void;
}
ext;
};
}