Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for CAP-0015 (FeeBumpTransaction). #298

Merged
merged 9 commits into from
Apr 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .xdr/Stellar-ledger-entries.x
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,15 @@ struct AccountEntry
enum TrustLineFlags
{
// issuer has authorized account to perform transactions with its credit
AUTHORIZED_FLAG = 1
AUTHORIZED_FLAG = 1,
// issuer has authorized account to maintain and reduce liabilities for its
// credit
AUTHORIZED_TO_MAINTAIN_LIABILITIES_FLAG = 2
};

// mask for all trustline flags
const MASK_TRUSTLINE_FLAGS = 1;
const MASK_TRUSTLINE_FLAGS_V13 = 3;

struct TrustLineEntry
{
Expand Down Expand Up @@ -287,9 +291,11 @@ struct LedgerEntry
// 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_SCPVALUE = 4,
ENVELOPE_TYPE_TX_FEE_BUMP = 5
};
}
136 changes: 125 additions & 11 deletions .xdr/Stellar-transaction.x
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ struct AllowTrustOp
}
asset;

bool authorize;
// 0, or any bitwise combination of TrustLineFlags
uint32 authorize;
};

/* Inflation
Expand Down Expand Up @@ -353,6 +354,34 @@ struct TimeBounds
// maximum number of operations per transaction
const MAX_OPS_PER_TX = 100;

// TransactionV0 is a transaction with the AccountID discriminant stripped off,
// leaving a raw ed25519 public key to identify the source account. This is used
// for backwards compatibility starting from the protocol 12/13 boundary. If an
// "old-style" TransactionEnvelope containing a Transaction is parsed with this
// XDR definition, it will be parsed as a "new-style" TransactionEnvelope
// containing a TransactionV0.
struct TransactionV0
{
uint256 sourceAccountEd25519;
uint32 fee;
SequenceNumber seqNum;
TimeBounds* timeBounds;
Memo memo;
Operation operations<MAX_OPS_PER_TX>;
union switch (int v) {
case 0:
void;
} ext;
};

struct TransactionV0Envelope
{
TransactionV0 tx;
/* Each decorated signature is a signature over the SHA256 hash of
* a TransactionSignaturePayload */
DecoratedSignature signatures<20>;
};

/* a transaction is a container for a set of operations
- is executed by an account
- fees are collected from the account
Expand Down Expand Up @@ -387,27 +416,61 @@ struct Transaction
ext;
};

struct TransactionSignaturePayload
struct TransactionV1Envelope
{
Hash networkId;
Transaction tx;
/* Each decorated signature is a signature over the SHA256 hash of
* a TransactionSignaturePayload */
DecoratedSignature signatures<20>;
};

struct FeeBumpTransaction
{
AccountID feeSource;
int64 fee;
union switch (EnvelopeType type)
{
case ENVELOPE_TYPE_TX:
Transaction tx;
/* All other values of type are invalid */
}
taggedTransaction;
TransactionV1Envelope v1;
} innerTx;
union switch (int v) {
case 0:
void;
} ext;
};

/* A TransactionEnvelope wraps a transaction with signatures. */
struct TransactionEnvelope
struct FeeBumpTransactionEnvelope
{
Transaction tx;
FeeBumpTransaction tx;
/* Each decorated signature is a signature over the SHA256 hash of
* a TransactionSignaturePayload */
DecoratedSignature signatures<20>;
};

/* A TransactionEnvelope wraps a transaction with signatures. */
union TransactionEnvelope switch (EnvelopeType type) {
case ENVELOPE_TYPE_TX_V0:
TransactionV0Envelope v0;
case ENVELOPE_TYPE_TX:
TransactionV1Envelope v1;
case ENVELOPE_TYPE_TX_FEE_BUMP:
FeeBumpTransactionEnvelope feeBump;
};

struct TransactionSignaturePayload
{
Hash networkId;
union switch (EnvelopeType type)
{
// Backwards Compatibility: Use ENVELOPE_TYPE_TX to sign ENVELOPE_TYPE_TX_V0
case ENVELOPE_TYPE_TX:
Transaction tx;
case ENVELOPE_TYPE_TX_FEE_BUMP:
FeeBumpTransaction feeBump;
}
taggedTransaction;
};

/* Operation Results section */

/* This result is used when offers are taken during an operation */
Expand Down Expand Up @@ -859,6 +922,7 @@ default:

enum TransactionResultCode
{
txFEE_BUMP_INNER_SUCCESS = 1, // fee bump inner transaction succeeded
txSUCCESS = 0, // all operations succeeded

txFAILED = -1, // one of the operations failed (none were applied)
Expand All @@ -873,7 +937,54 @@ enum TransactionResultCode
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
txINTERNAL_ERROR = -11, // an unknown error occured

txNOT_SUPPORTED = -12, // transaction type not supported
txFEE_BUMP_INNER_FAILED = -13 // fee bump inner transaction failed
};

// InnerTransactionResult must be binary compatible with TransactionResult
// because it is be used to represent the result of a Transaction.
struct InnerTransactionResult
{
// Always 0. Here for binary compatibility.
int64 feeCharged;

union switch (TransactionResultCode code)
{
// txFEE_BUMP_INNER_SUCCESS is not included
case txSUCCESS:
case txFAILED:
OperationResult results<>;
case txTOO_EARLY:
case txTOO_LATE:
case txMISSING_OPERATION:
case txBAD_SEQ:
case txBAD_AUTH:
case txINSUFFICIENT_BALANCE:
case txNO_ACCOUNT:
case txINSUFFICIENT_FEE:
case txBAD_AUTH_EXTRA:
case txINTERNAL_ERROR:
case txNOT_SUPPORTED:
// txFEE_BUMP_INNER_FAILED is not included
void;
}
result;

// reserved for future use
union switch (int v)
{
case 0:
void;
}
ext;
};

struct InnerTransactionResultPair
{
Hash transactionHash; // hash of the inner transaction
InnerTransactionResult result; // result for the inner transaction
};

struct TransactionResult
Expand All @@ -882,6 +993,9 @@ struct TransactionResult

union switch (TransactionResultCode code)
{
case txFEE_BUMP_INNER_SUCCESS:
case txFEE_BUMP_INNER_FAILED:
InnerTransactionResultPair innerResultPair;
case txSUCCESS:
case txFAILED:
OperationResult results<>;
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mnemonic = "*"
toml = "*"

[requires]
python_version = "3.7"
python_version = "3.8"

[pipenv]
allow_prereleases = true
Loading