module Stellar

xdr source ============================================================

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;
    }
    ext;
};

xdr source ============================================================

union switch (int v)
    {
    case 0:
        void;
    }

xdr source ============================================================

enum AccountFlags
{ // masks for each flag

    // if set, 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
};

xdr source ============================================================

union AccountMergeResult switch (AccountMergeResultCode code)
{
case ACCOUNT_MERGE_SUCCESS:
    int64 sourceAccountBalance; // how much got transfered from source account
default:
    void;
};

xdr source ============================================================

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_HAS_CREDIT = -3, // account has active trust lines
    ACCOUNT_MERGE_CREDIT_HELD = -4 // an issuer cannot be merged if used
};

xdr source ============================================================

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;
};

xdr source ============================================================

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
    }

xdr source ============================================================

union AllowTrustResult switch (AllowTrustResultCode code)
{
case ALLOW_TRUST_SUCCESS:
    void;
default:
    void;
};

xdr source ============================================================

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
};

xdr source ============================================================

union Asset switch (AssetType type)
{
case ASSET_TYPE_NATIVE: // Not credit
    void;

case ASSET_TYPE_CREDIT_ALPHANUM4:
    struct
    {
        opaque assetCode[4];
        AccountID issuer;
    } alphaNum4;

case ASSET_TYPE_CREDIT_ALPHANUM12:
    struct
    {
        opaque assetCode[12];
        AccountID issuer;
    } alphaNum12;

    // add other asset types here in the future
};

xdr source ============================================================

struct
    {
        opaque assetCode[12];
        AccountID issuer;
    }

xdr source ============================================================

struct
    {
        opaque assetCode[4];
        AccountID issuer;
    }

xdr source ============================================================

enum AssetType
{
    ASSET_TYPE_NATIVE = 0,
    ASSET_TYPE_CREDIT_ALPHANUM4 = 1,
    ASSET_TYPE_CREDIT_ALPHANUM12 = 2
};

xdr source ============================================================

union BucketEntry switch (BucketEntryType type)
{
case LIVEENTRY:
    LedgerEntry liveEntry;

case DEADENTRY:
    LedgerKey deadEntry;
};

xdr source ============================================================

enum BucketEntryType
{
    LIVEENTRY = 0,
    DEADENTRY = 1
};

xdr source ============================================================

struct ChangeTrustOp
{
    Asset line;

    // if limit is set to 0, deletes the trust line
    int64 limit;
};

xdr source ============================================================

union ChangeTrustResult switch (ChangeTrustResultCode code)
{
case CHANGE_TRUST_SUCCESS:
    void;
default:
    void;
};

xdr source ============================================================

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
    CHANGE_TRUST_LOW_RESERVE = -4 // not enough funds to create a new trust line
};

xdr source ============================================================

struct ClaimOfferAtom
{
    // emited 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;
};

xdr source ============================================================

struct CreateAccountOp
{
    AccountID destination; // account to create
    int64 startingBalance; // amount they end up with
};

xdr source ============================================================

union CreateAccountResult switch (CreateAccountResultCode code)
{
case CREATE_ACCOUNT_SUCCESS:
    void;
default:
    void;
};

xdr source ============================================================

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
};

xdr source ============================================================

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
};

xdr source ============================================================

enum CryptoKeyType
{
    KEY_TYPE_ED25519 = 0
};

xdr source ============================================================

struct DecoratedSignature
{
    SignatureHint hint;  // first 4 bytes of the public key, used as a hint
    Signature signature; // actual signature
};

xdr source ============================================================

struct DontHave
{
    MessageType type;
    uint256 reqHash;
};

xdr source ============================================================

enum EnvelopeType
{
    ENVELOPE_TYPE_SCP = 1,
    ENVELOPE_TYPE_TX = 2
};

xdr source ============================================================

struct Error
{
    int code;
    string msg<100>;
};

xdr source ============================================================

struct Hello
{
    uint32 ledgerVersion;
    uint32 overlayVersion;
    string versionStr<100>;
    int listeningPort;
    NodeID peerID;
};

xdr source ============================================================

struct InflationPayout // or use PaymentResultAtom to limit types?
{
    AccountID destination;
    int64 amount;
};

xdr source ============================================================

union InflationResult switch (InflationResultCode code)
{
case INFLATION_SUCCESS:
    InflationPayout payouts<>;
default:
    void;
};

xdr source ============================================================

enum InflationResultCode
{
    // codes considered as "success" for the operation
    INFLATION_SUCCESS = 0,
    // codes considered as "failure" for the operation
    INFLATION_NOT_TIME = -1
};

xdr source ============================================================

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;
    }
    data;

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

xdr source ============================================================

union switch (LedgerEntryType type)
    {
    case ACCOUNT:
        AccountEntry account;
    case TRUSTLINE:
        TrustLineEntry trustLine;
    case OFFER:
        OfferEntry offer;
    }

xdr source ============================================================

union switch (int v)
    {
    case 0:
        void;
    }

xdr source ============================================================

union LedgerEntryChange switch (LedgerEntryChangeType type)
{
case LEDGER_ENTRY_CREATED:
    LedgerEntry created;
case LEDGER_ENTRY_UPDATED:
    LedgerEntry updated;
case LEDGER_ENTRY_REMOVED:
    LedgerKey removed;
};

xdr source ============================================================

enum LedgerEntryChangeType
{
    LEDGER_ENTRY_CREATED = 0, // entry was added to the ledger
    LEDGER_ENTRY_UPDATED = 1, // entry was modified in the ledger
    LEDGER_ENTRY_REMOVED = 2  // entry was removed from the ledger
};

xdr source ============================================================

enum LedgerEntryType
{
    ACCOUNT = 0,
    TRUSTLINE = 1,
    OFFER = 2
};

xdr source ============================================================

struct LedgerHeader
{
    uint32 ledgerVersion;    // the protocol version of the ledger
    Hash previousLedgerHash; // hash of the previous ledger header
    StellarValue scpValue;   // what consensus agreed to
    Hash txSetResultHash;    // the TransactionResultSet that led to this ledger
    Hash bucketListHash;     // hash of the ledger state

    uint32 ledgerSeq; // sequence number of this ledger

    int64 totalCoins; // total number of stroops in existence

    int64 feePool;       // fees burned since last inflation run
    uint32 inflationSeq; // inflation sequence number

    uint64 idPool; // last used global ID, used for generating objects

    uint32 baseFee;     // base fee per operation in stroops
    uint32 baseReserve; // account base reserve in stroops

    Hash skipList[4]; // hashes of ledgers in the past. allows you to jump back
                      // in time without walking the chain back ledger by ledger
                      // each slot contains the oldest ledger that is mod of
                      // either 50  5000  50000 or 500000 depending on index
                      // skipList[0] mod(50), skipList[1] mod(5000), etc

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

xdr source ============================================================

union switch (int v)
    {
    case 0:
        void;
    }

xdr source ============================================================

struct LedgerHeaderHistoryEntry
{
    Hash hash;
    LedgerHeader header;

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

xdr source ============================================================

union switch (int v)
    {
    case 0:
        void;
    }

xdr source ============================================================

union LedgerKey switch (LedgerEntryType type)
{
case ACCOUNT:
    struct
    {
        AccountID accountID;
    } account;

case TRUSTLINE:
    struct
    {
        AccountID accountID;
        Asset asset;
    } trustLine;

case OFFER:
    struct
    {
        AccountID sellerID;
        uint64 offerID;
    } offer;
};

xdr source ============================================================

struct
    {
        AccountID accountID;
    }

xdr source ============================================================

struct
    {
        AccountID sellerID;
        uint64 offerID;
    }

xdr source ============================================================

struct
    {
        AccountID accountID;
        Asset asset;
    }

xdr source ============================================================

union LedgerUpgrade switch (LedgerUpgradeType type)
{
case LEDGER_UPGRADE_VERSION:
    uint32 newLedgerVersion; // update ledgerVersion
case LEDGER_UPGRADE_BASE_FEE:
    uint32 newBaseFee; // update baseFee
};

xdr source ============================================================

enum LedgerUpgradeType
{
    LEDGER_UPGRADE_VERSION = 1,
    LEDGER_UPGRADE_BASE_FEE = 2
};

xdr source ============================================================

enum ManageOfferEffect
{
    MANAGE_OFFER_CREATED = 0,
    MANAGE_OFFER_UPDATED = 1,
    MANAGE_OFFER_DELETED = 2
};

xdr source ============================================================

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;
};

xdr source ============================================================

union ManageOfferResult switch (ManageOfferResultCode code)
{
case MANAGE_OFFER_SUCCESS:
    ManageOfferSuccessResult success;
default:
    void;
};

xdr source ============================================================

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

    // update errors
    MANAGE_OFFER_NOT_FOUND = -9, // offerID does not match an existing offer
    MANAGE_OFFER_MISMATCH = -10, // currencies don't match offer

    MANAGE_OFFER_LOW_RESERVE = -11 // not enough funds to create a new Offer
};

xdr source ============================================================

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;
};

xdr source ============================================================

union switch (ManageOfferEffect effect)
    {
    case MANAGE_OFFER_CREATED:
    case MANAGE_OFFER_UPDATED:
        OfferEntry offer;
    default:
        void;
    }

xdr source ============================================================

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
};

xdr source ============================================================

enum MemoType
{
    MEMO_NONE = 0,
    MEMO_TEXT = 1,
    MEMO_ID = 2,
    MEMO_HASH = 3,
    MEMO_RETURN = 4
};

xdr source ============================================================

enum MessageType
{
    ERROR_MSG = 0,
    HELLO = 1,
    DONT_HAVE = 2,

    GET_PEERS = 3, // gets a list of peers this guy knows about
    PEERS = 4,

    GET_TX_SET = 5, // gets a particular txset by hash
    TX_SET = 6,

    TRANSACTION = 7, // pass on a tx you have heard about

    // SCP
    GET_SCP_QUORUMSET = 8,
    SCP_QUORUMSET = 9,
    SCP_MESSAGE = 10
};

xdr source ============================================================

struct OfferEntry
{
    AccountID sellerID;
    uint64 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;
};

xdr source ============================================================

union switch (int v)
    {
    case 0:
        void;
    }

xdr source ============================================================

enum OfferEntryFlags
{
    // issuer has authorized account to perform transactions with its credit
    PASSIVE_FLAG = 1
};

xdr source ============================================================

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;
    }
    body;
};

xdr source ============================================================

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;
    }

xdr source ============================================================

struct OperationMeta
{
    LedgerEntryChanges changes;
};

xdr source ============================================================

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;
    }
    tr;
default:
    void;
};

xdr source ============================================================

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;
    }

xdr source ============================================================

enum OperationResultCode
{
    opINNER = 0, // inner object result is valid

    opBAD_AUTH = -1,  // not enough signatures to perform operation
    opNO_ACCOUNT = -2 // source account was not found
};

xdr source ============================================================

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
};

xdr source ============================================================

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
};

xdr source ============================================================

union PathPaymentResult switch (PathPaymentResultCode code)
{
case PATH_PAYMENT_SUCCESS:
    struct
    {
        ClaimOfferAtom offers<>;
        SimplePaymentResult last;
    } success;
default:
    void;
};

xdr source ============================================================

struct
    {
        ClaimOfferAtom offers<>;
        SimplePaymentResult last;
    }

xdr source ============================================================

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_TOO_FEW_OFFERS = -9,     // not enough offers to satisfy path
    PATH_PAYMENT_OFFER_CROSS_SELF = -10,  // would cross one of its own offers
    PATH_PAYMENT_OVER_SENDMAX = -11       // could not satisfy sendmax
};

xdr source ============================================================

struct PaymentOp
{
    AccountID destination; // recipient of the payment
    Asset asset;           // what they end up with
    int64 amount;          // amount they end up with
};

xdr source ============================================================

union PaymentResult switch (PaymentResultCode code)
{
case PAYMENT_SUCCESS:
    void;
default:
    void;
};

xdr source ============================================================

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
};

xdr source ============================================================

struct PeerAddress
{
    opaque ip[4];
    uint32 port;
    uint32 numFailures;
};

xdr source ============================================================

struct Price
{
    int32 n; // numerator
    int32 d; // denominator
};

xdr source ============================================================

union PublicKey switch (CryptoKeyType type)
{
case KEY_TYPE_ED25519:
    uint256 ed25519;
};

xdr source ============================================================

struct SCPBallot
{
    uint32 counter; // n
    Value value;    // x
};

xdr source ============================================================

struct SCPEnvelope
{
    SCPStatement statement;
    Signature signature;
};

xdr source ============================================================

struct SCPNomination
{
    Hash quorumSetHash; // D
    Value votes<>;      // X
    Value accepted<>;   // Y
};

xdr source ============================================================

struct SCPQuorumSet
{
    uint32 threshold;
    PublicKey validators<>;
    SCPQuorumSet innerSets<>;
};

xdr source ============================================================

struct SCPStatement
{
    NodeID nodeID;    // v
    uint64 slotIndex; // i

    union switch (SCPStatementType type)
    {
    case SCP_ST_PREPARE:
        struct
        {
            Hash quorumSetHash;       // D
            SCPBallot ballot;         // b
            SCPBallot* prepared;      // p
            SCPBallot* preparedPrime; // p'
            uint32 nC;                // n_c
            uint32 nP;                // n_P
        } prepare;
    case SCP_ST_CONFIRM:
        struct
        {
            Hash quorumSetHash; // D
            uint32 nPrepared;   // n_p
            SCPBallot commit;   // c
            uint32 nP;          // n_P
        } confirm;
    case SCP_ST_EXTERNALIZE:
        struct
        {
            SCPBallot commit; // c
            uint32 nP;        // n_P
            // not from the paper, but useful to build tooling to
            // traverse the graph based off only the latest statement
            Hash commitQuorumSetHash; // D used before EXTERNALIZE
        } externalize;
    case SCP_ST_NOMINATE:
        SCPNomination nominate;
    }
    pledges;
};

xdr source ============================================================

union switch (SCPStatementType type)
    {
    case SCP_ST_PREPARE:
        struct
        {
            Hash quorumSetHash;       // D
            SCPBallot ballot;         // b
            SCPBallot* prepared;      // p
            SCPBallot* preparedPrime; // p'
            uint32 nC;                // n_c
            uint32 nP;                // n_P
        } prepare;
    case SCP_ST_CONFIRM:
        struct
        {
            Hash quorumSetHash; // D
            uint32 nPrepared;   // n_p
            SCPBallot commit;   // c
            uint32 nP;          // n_P
        } confirm;
    case SCP_ST_EXTERNALIZE:
        struct
        {
            SCPBallot commit; // c
            uint32 nP;        // n_P
            // not from the paper, but useful to build tooling to
            // traverse the graph based off only the latest statement
            Hash commitQuorumSetHash; // D used before EXTERNALIZE
        } externalize;
    case SCP_ST_NOMINATE:
        SCPNomination nominate;
    }

xdr source ============================================================

struct
        {
            Hash quorumSetHash; // D
            uint32 nPrepared;   // n_p
            SCPBallot commit;   // c
            uint32 nP;          // n_P
        }

xdr source ============================================================

struct
        {
            SCPBallot commit; // c
            uint32 nP;        // n_P
            // not from the paper, but useful to build tooling to
            // traverse the graph based off only the latest statement
            Hash commitQuorumSetHash; // D used before EXTERNALIZE
        }

xdr source ============================================================

struct
        {
            Hash quorumSetHash;       // D
            SCPBallot ballot;         // b
            SCPBallot* prepared;      // p
            SCPBallot* preparedPrime; // p'
            uint32 nC;                // n_c
            uint32 nP;                // n_P
        }

xdr source ============================================================

enum SCPStatementType
{
    SCP_ST_PREPARE = 0,
    SCP_ST_CONFIRM = 1,
    SCP_ST_EXTERNALIZE = 2,
    SCP_ST_NOMINATE = 3
};

xdr source ============================================================

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;
};

xdr source ============================================================

union SetOptionsResult switch (SetOptionsResultCode code)
{
case SET_OPTIONS_SUCCESS:
    void;
default:
    void;
};

xdr source ============================================================

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
};

xdr source ============================================================

struct Signer
{
    AccountID pubKey;
    uint32 weight; // really only need 1byte
};

xdr source ============================================================

struct SimplePaymentResult
{
    AccountID destination;
    Asset asset;
    int64 amount;
};

xdr source ============================================================

union StellarMessage switch (MessageType type)
{
case ERROR_MSG:
    Error error;
case HELLO:
    Hello hello;
case DONT_HAVE:
    DontHave dontHave;
case GET_PEERS:
    void;
case PEERS:
    PeerAddress peers<>;

case GET_TX_SET:
    uint256 txSetHash;
case TX_SET:
    TransactionSet txSet;

case TRANSACTION:
    TransactionEnvelope transaction;

// SCP
case GET_SCP_QUORUMSET:
    uint256 qSetHash;
case SCP_QUORUMSET:
    SCPQuorumSet qSet;
case SCP_MESSAGE:
    SCPEnvelope envelope;
};

xdr source ============================================================

struct StellarValue
{
    Hash txSetHash;   // transaction set to apply to previous ledger
    uint64 closeTime; // network close time

    // upgrades to apply to the previous ledger (usually empty)
    // this is a vector of encoded 'LedgerUpgrade' so that nodes can drop
    // unknown steps during consensus if needed.
    // see notes below on 'LedgerUpgrade' for more detail
    UpgradeType upgrades<4>;

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

xdr source ============================================================

union switch (int v)
    {
    case 0:
        void;
    }

xdr source ============================================================

enum ThresholdIndexes
{
    THRESHOLD_MASTER_WEIGHT = 0,
    THRESHOLD_LOW = 1,
    THRESHOLD_MED = 2,
    THRESHOLD_HIGH = 3
};

xdr source ============================================================

struct TimeBounds
{
    uint64 minTime;
    uint64 maxTime;
};

xdr source ============================================================

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;
};

xdr source ============================================================

union switch (int v)
    {
    case 0:
        void;
    }

xdr source ============================================================

struct TransactionEnvelope
{
    Transaction tx;
    DecoratedSignature signatures<20>;
};

xdr source ============================================================

struct TransactionHistoryEntry
{
    uint32 ledgerSeq;
    TransactionSet txSet;

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

xdr source ============================================================

union switch (int v)
    {
    case 0:
        void;
    }

xdr source ============================================================

struct TransactionHistoryResultEntry
{
    uint32 ledgerSeq;
    TransactionResultSet txResultSet;

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

xdr source ============================================================

union switch (int v)
    {
    case 0:
        void;
    }

xdr source ============================================================

union TransactionMeta switch (int v)
{
case 0:
    struct
    {
        LedgerEntryChanges changes;
        OperationMeta operations<>;
    } v0;
};

xdr source ============================================================

struct
    {
        LedgerEntryChanges changes;
        OperationMeta operations<>;
    }

xdr source ============================================================

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;
};

xdr source ============================================================

union switch (int v)
    {
    case 0:
        void;
    }

xdr source ============================================================

union switch (TransactionResultCode code)
    {
    case txSUCCESS:
    case txFAILED:
        OperationResult results<>;
    default:
        void;
    }

xdr source ============================================================

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,             // not enough signatures to perform transaction
    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,      // too many signatures on transaction
    txINTERNAL_ERROR = -11       // an unknown error occured
};

xdr source ============================================================

struct TransactionResultPair
{
    Hash transactionHash;
    TransactionResult result; // result for the transaction
};

xdr source ============================================================

struct TransactionResultSet
{
    TransactionResultPair results<MAX_TX_PER_LEDGER>;
};

xdr source ============================================================

struct TransactionSet
{
    Hash previousLedgerHash;
    TransactionEnvelope txs<MAX_TX_PER_LEDGER>;
};

xdr source ============================================================

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;
    }
    ext;
};

xdr source ============================================================

union switch (int v)
    {
    case 0:
        void;
    }

xdr source ============================================================

enum TrustLineFlags
{
    // issuer has authorized account to perform transactions with its credit
    AUTHORIZED_FLAG = 1
};

Constants

AccountID
Hash
Int32
Int64
LedgerEntryChanges
MAX_TX_PER_LEDGER
NodeID
ONE
SequenceNumber
Signature
SignatureHint
String32
Thresholds
Uint256
Uint32
Uint64
UpgradeType
Value

Public Class Methods

current_network() click to toggle source

Returns the passphrase for the currently-configured network, as set by Stellar.default_network or Stellar.on_network

# File lib/stellar/networks.rb, line 25
def self.current_network
  Thread.current["stellar_network_passphrase"] || 
  @default_network || 
  Stellar::Networks::PUBLIC
end
current_network_id() click to toggle source

Returns the id for the currently configured network, suitable for use in generating a signature base string or making the root account’s keypair.

# File lib/stellar/networks.rb, line 33
def self.current_network_id
  Digest::SHA256.digest(self.current_network) 
end
default_network=(passphrase) click to toggle source

Configures the default stellar network passphrase for the current process. Unless otherwise specified in a method that needs the passphrase, this value will be used.

NOTE: This method is not thread-safe. It’s best to just call this at startup once and use the other

methods of specifying a network if you need two threads in the same process to communicate with
different networks

@see Stellar.default_network @see Stellar.on_network

# File lib/stellar/networks.rb, line 19
def self.default_network=(passphrase)
  @default_network = passphrase
end
on_network(passphrase, &block) click to toggle source

Executes the provided block in the context of the provided network.

# File lib/stellar/networks.rb, line 38
def self.on_network(passphrase, &block)
  old = Thread.current["stellar_network_passphrase"]
  Thread.current["stellar_network_passphrase"] = passphrase
  block.call
ensure
  Thread.current["stellar_network_passphrase"] = old
end