From 49e37fb3b5c59b2f8e059a53673465a55b5eda89 Mon Sep 17 00:00:00 2001 From: Balazs Zachar Date: Mon, 19 Feb 2018 21:36:22 +0100 Subject: [PATCH 1/3] added federation.x and regenerated JavaScript from xdr --- src/generated/stellar-xdr_generated.js | 47 +++++++++++++++++++++++++- xdr/Stellar-federation.x | 26 ++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 xdr/Stellar-federation.x diff --git a/src/generated/stellar-xdr_generated.js b/src/generated/stellar-xdr_generated.js index a7b2241de..2e83a11fb 100644 --- a/src/generated/stellar-xdr_generated.js +++ b/src/generated/stellar-xdr_generated.js @@ -1,4 +1,4 @@ -// Automatically generated on 2017-02-08T14:45:22+01:00 +// Automatically generated on 2018-02-19T21:33:00+01:00 // DO NOT EDIT or your changes may be overwritten /* jshint maxstatements:2147483647 */ @@ -3393,5 +3393,50 @@ xdr.struct("HmacSha256Mac", [ ["mac", xdr.opaque(32)], ]); +// === xdr source ============================================================ +// +// union switch (int v) +// { +// case 0: +// void; +// } +// +// =========================================================================== +xdr.union("FederationResponseExt", { + switchOn: xdr.int(), + switchName: "v", + switches: [ + [0, xdr.void()], + ], + arms: { + }, +}); + +// === xdr source ============================================================ +// +// struct FederationResponse +// { +// +// string64 stellarAddress; // Stellar uses string32 for domain name, using double for the federation name +// AccountID accountID; +// Memo memo; +// +// // reserved for future use +// union switch (int v) +// { +// case 0: +// void; +// } +// ext; +// }; +// +// =========================================================================== +xdr.struct("FederationResponse", [ + ["stellarAddress", xdr.lookup("String64")], + ["accountId", xdr.lookup("AccountId")], + ["memo", xdr.lookup("Memo")], + ["ext", xdr.lookup("FederationResponseExt")], +]); + }); export default types; diff --git a/xdr/Stellar-federation.x b/xdr/Stellar-federation.x new file mode 100644 index 000000000..c9136fd23 --- /dev/null +++ b/xdr/Stellar-federation.x @@ -0,0 +1,26 @@ +// 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 FederationResponse +{ + + string64 stellarAddress; // Stellar uses string32 for domain name, using double for the federation name + AccountID accountID; + Memo memo; + + // reserved for future use + union switch (int v) + { + case 0: + void; + } + ext; +}; + +} From 5372dac5b354ff55b7c86f1553808f414859b9d7 Mon Sep 17 00:00:00 2001 From: Helmuth Breitenfellner Date: Mon, 19 Feb 2018 21:59:39 +0100 Subject: [PATCH 2/3] Updated xdr files (using rake xdr:update) Regenerated stellar-xdr_generated.js using rake xdr:generate --- Gemfile.lock | 20 +- src/generated/stellar-xdr_generated.js | 4591 ++++++++++++------------ xdr/Stellar-federation.x | 4 +- xdr/Stellar-ledger-entries.x | 10 + xdr/Stellar-ledger.x | 6 +- 5 files changed, 2336 insertions(+), 2295 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9e46804a1..93208fd96 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,9 +1,9 @@ GIT remote: git@github.com:stellar/xdrgen.git - revision: 6c8d27a3b2314be1fc352f53fcb22e418ba296b5 + revision: c683684abb3cb2c8b8c3dc12dc7c6cc9bf1e3b60 specs: xdrgen (0.0.1) - activesupport (~> 4) + activesupport (~> 5) memoist (~> 0.11.0) slop (~> 3.4) treetop (~> 1.5.3) @@ -11,21 +11,21 @@ GIT GEM remote: https://rubygems.org/ specs: - activesupport (4.2.4) + activesupport (5.1.5) + concurrent-ruby (~> 1.0, >= 1.0.2) i18n (~> 0.7) - json (~> 1.7, >= 1.7.7) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) addressable (2.3.8) coderay (1.1.0) + concurrent-ruby (1.0.5) faraday (0.9.1) multipart-post (>= 1.2, < 3) - i18n (0.7.0) - json (1.8.3) + i18n (0.9.5) + concurrent-ruby (~> 1.0) memoist (0.11.0) method_source (0.8.2) - minitest (5.8.0) + minitest (5.11.3) multipart-post (2.0.0) netrc (0.10.3) octokit (4.1.0) @@ -39,10 +39,10 @@ GEM addressable (~> 2.3.5) faraday (~> 0.8, < 0.10) slop (3.6.0) - thread_safe (0.3.5) + thread_safe (0.3.6) treetop (1.5.3) polyglot (~> 0.3) - tzinfo (1.2.2) + tzinfo (1.2.5) thread_safe (~> 0.1) PLATFORMS diff --git a/src/generated/stellar-xdr_generated.js b/src/generated/stellar-xdr_generated.js index 2e83a11fb..4577bcda7 100644 --- a/src/generated/stellar-xdr_generated.js +++ b/src/generated/stellar-xdr_generated.js @@ -1,4 +1,4 @@ -// Automatically generated on 2018-02-19T21:33:00+01:00 +// Automatically generated on 2018-02-19T21:58:07+01:00 // DO NOT EDIT or your changes may be overwritten /* jshint maxstatements:2147483647 */ @@ -11,596 +11,530 @@ var types = XDR.config(xdr => { // === xdr source ============================================================ // -// typedef opaque Value<>; -// -// =========================================================================== -xdr.typedef("Value", xdr.varOpaque()); - -// === xdr source ============================================================ -// -// struct SCPBallot +// enum ErrorCode // { -// uint32 counter; // n -// Value value; // x +// ERR_MISC = 0, // Unspecific error +// ERR_DATA = 1, // Malformed data +// ERR_CONF = 2, // Misconfiguration error +// ERR_AUTH = 3, // Authentication failure +// ERR_LOAD = 4 // System overloaded // }; // // =========================================================================== -xdr.struct("ScpBallot", [ - ["counter", xdr.lookup("Uint32")], - ["value", xdr.lookup("Value")], -]); +xdr.enum("ErrorCode", { + errMisc: 0, + errDatum: 1, + errConf: 2, + errAuth: 3, + errLoad: 4, +}); // === xdr source ============================================================ // -// enum SCPStatementType +// struct Error // { -// SCP_ST_PREPARE = 0, -// SCP_ST_CONFIRM = 1, -// SCP_ST_EXTERNALIZE = 2, -// SCP_ST_NOMINATE = 3 +// ErrorCode code; +// string msg<100>; // }; // // =========================================================================== -xdr.enum("ScpStatementType", { - scpStPrepare: 0, - scpStConfirm: 1, - scpStExternalize: 2, - scpStNominate: 3, -}); +xdr.struct("Error", [ + ["code", xdr.lookup("ErrorCode")], + ["msg", xdr.string(100)], +]); // === xdr source ============================================================ // -// struct SCPNomination +// struct AuthCert // { -// Hash quorumSetHash; // D -// Value votes<>; // X -// Value accepted<>; // Y +// Curve25519Public pubkey; +// uint64 expiration; +// Signature sig; // }; // // =========================================================================== -xdr.struct("ScpNomination", [ - ["quorumSetHash", xdr.lookup("Hash")], - ["votes", xdr.varArray(xdr.lookup("Value"), 2147483647)], - ["accepted", xdr.varArray(xdr.lookup("Value"), 2147483647)], +xdr.struct("AuthCert", [ + ["pubkey", xdr.lookup("Curve25519Public")], + ["expiration", xdr.lookup("Uint64")], + ["sig", xdr.lookup("Signature")], ]); // === xdr source ============================================================ // -// struct -// { -// Hash quorumSetHash; // D -// SCPBallot ballot; // b -// SCPBallot* prepared; // p -// SCPBallot* preparedPrime; // p' -// uint32 nC; // c.n -// uint32 nH; // h.n -// } +// struct Hello +// { +// uint32 ledgerVersion; +// uint32 overlayVersion; +// uint32 overlayMinVersion; +// Hash networkID; +// string versionStr<100>; +// int listeningPort; +// NodeID peerID; +// AuthCert cert; +// uint256 nonce; +// }; // // =========================================================================== -xdr.struct("ScpStatementPrepare", [ - ["quorumSetHash", xdr.lookup("Hash")], - ["ballot", xdr.lookup("ScpBallot")], - ["prepared", xdr.option(xdr.lookup("ScpBallot"))], - ["preparedPrime", xdr.option(xdr.lookup("ScpBallot"))], - ["nC", xdr.lookup("Uint32")], - ["nH", xdr.lookup("Uint32")], +xdr.struct("Hello", [ + ["ledgerVersion", xdr.lookup("Uint32")], + ["overlayVersion", xdr.lookup("Uint32")], + ["overlayMinVersion", xdr.lookup("Uint32")], + ["networkId", xdr.lookup("Hash")], + ["versionStr", xdr.string(100)], + ["listeningPort", xdr.int()], + ["peerId", xdr.lookup("NodeId")], + ["cert", xdr.lookup("AuthCert")], + ["nonce", xdr.lookup("Uint256")], ]); // === xdr source ============================================================ // -// struct -// { -// SCPBallot ballot; // b -// uint32 nPrepared; // p.n -// uint32 nCommit; // c.n -// uint32 nH; // h.n -// Hash quorumSetHash; // D -// } +// struct Auth +// { +// // Empty message, just to confirm +// // establishment of MAC keys. +// int unused; +// }; // // =========================================================================== -xdr.struct("ScpStatementConfirm", [ - ["ballot", xdr.lookup("ScpBallot")], - ["nPrepared", xdr.lookup("Uint32")], - ["nCommit", xdr.lookup("Uint32")], - ["nH", xdr.lookup("Uint32")], - ["quorumSetHash", xdr.lookup("Hash")], +xdr.struct("Auth", [ + ["unused", xdr.int()], ]); // === xdr source ============================================================ // -// struct -// { -// SCPBallot commit; // c -// uint32 nH; // h.n -// Hash commitQuorumSetHash; // D used before EXTERNALIZE -// } +// enum IPAddrType +// { +// IPv4 = 0, +// IPv6 = 1 +// }; // // =========================================================================== -xdr.struct("ScpStatementExternalize", [ - ["commit", xdr.lookup("ScpBallot")], - ["nH", xdr.lookup("Uint32")], - ["commitQuorumSetHash", xdr.lookup("Hash")], -]); +xdr.enum("IpAddrType", { + iPv4: 0, + iPv6: 1, +}); // === xdr source ============================================================ // -// union switch (SCPStatementType type) +// union switch (IPAddrType type) // { -// case SCP_ST_PREPARE: -// struct -// { -// Hash quorumSetHash; // D -// SCPBallot ballot; // b -// SCPBallot* prepared; // p -// SCPBallot* preparedPrime; // p' -// uint32 nC; // c.n -// uint32 nH; // h.n -// } prepare; -// case SCP_ST_CONFIRM: -// struct -// { -// SCPBallot ballot; // b -// uint32 nPrepared; // p.n -// uint32 nCommit; // c.n -// uint32 nH; // h.n -// Hash quorumSetHash; // D -// } confirm; -// case SCP_ST_EXTERNALIZE: -// struct -// { -// SCPBallot commit; // c -// uint32 nH; // h.n -// Hash commitQuorumSetHash; // D used before EXTERNALIZE -// } externalize; -// case SCP_ST_NOMINATE: -// SCPNomination nominate; +// case IPv4: +// opaque ipv4[4]; +// case IPv6: +// opaque ipv6[16]; // } // // =========================================================================== -xdr.union("ScpStatementPledges", { - switchOn: xdr.lookup("ScpStatementType"), +xdr.union("PeerAddressIp", { + switchOn: xdr.lookup("IpAddrType"), switchName: "type", switches: [ - ["scpStPrepare", "prepare"], - ["scpStConfirm", "confirm"], - ["scpStExternalize", "externalize"], - ["scpStNominate", "nominate"], + ["iPv4", "ipv4"], + ["iPv6", "ipv6"], ], arms: { - prepare: xdr.lookup("ScpStatementPrepare"), - confirm: xdr.lookup("ScpStatementConfirm"), - externalize: xdr.lookup("ScpStatementExternalize"), - nominate: xdr.lookup("ScpNomination"), + ipv4: xdr.opaque(4), + ipv6: xdr.opaque(16), }, }); // === xdr source ============================================================ // -// struct SCPStatement +// struct PeerAddress // { -// NodeID nodeID; // v -// uint64 slotIndex; // i -// -// union switch (SCPStatementType type) +// union switch (IPAddrType type) // { -// case SCP_ST_PREPARE: -// struct -// { -// Hash quorumSetHash; // D -// SCPBallot ballot; // b -// SCPBallot* prepared; // p -// SCPBallot* preparedPrime; // p' -// uint32 nC; // c.n -// uint32 nH; // h.n -// } prepare; -// case SCP_ST_CONFIRM: -// struct -// { -// SCPBallot ballot; // b -// uint32 nPrepared; // p.n -// uint32 nCommit; // c.n -// uint32 nH; // h.n -// Hash quorumSetHash; // D -// } confirm; -// case SCP_ST_EXTERNALIZE: -// struct -// { -// SCPBallot commit; // c -// uint32 nH; // h.n -// Hash commitQuorumSetHash; // D used before EXTERNALIZE -// } externalize; -// case SCP_ST_NOMINATE: -// SCPNomination nominate; +// case IPv4: +// opaque ipv4[4]; +// case IPv6: +// opaque ipv6[16]; // } -// pledges; +// ip; +// uint32 port; +// uint32 numFailures; // }; // // =========================================================================== -xdr.struct("ScpStatement", [ - ["nodeId", xdr.lookup("NodeId")], - ["slotIndex", xdr.lookup("Uint64")], - ["pledges", xdr.lookup("ScpStatementPledges")], +xdr.struct("PeerAddress", [ + ["ip", xdr.lookup("PeerAddressIp")], + ["port", xdr.lookup("Uint32")], + ["numFailures", xdr.lookup("Uint32")], ]); // === xdr source ============================================================ // -// struct SCPEnvelope +// enum MessageType // { -// SCPStatement statement; -// Signature signature; -// }; -// -// =========================================================================== -xdr.struct("ScpEnvelope", [ - ["statement", xdr.lookup("ScpStatement")], - ["signature", xdr.lookup("Signature")], -]); - -// === xdr source ============================================================ -// -// struct SCPQuorumSet +// ERROR_MSG = 0, +// AUTH = 2, +// DONT_HAVE = 3, +// +// GET_PEERS = 4, // gets a list of peers this guy knows about +// PEERS = 5, +// +// GET_TX_SET = 6, // gets a particular txset by hash +// TX_SET = 7, +// +// TRANSACTION = 8, // pass on a tx you have heard about +// +// // SCP +// GET_SCP_QUORUMSET = 9, +// SCP_QUORUMSET = 10, +// SCP_MESSAGE = 11, +// GET_SCP_STATE = 12, +// +// // new messages +// HELLO = 13 +// }; +// +// =========================================================================== +xdr.enum("MessageType", { + errorMsg: 0, + auth: 2, + dontHave: 3, + getPeer: 4, + peer: 5, + getTxSet: 6, + txSet: 7, + transaction: 8, + getScpQuorumset: 9, + scpQuorumset: 10, + scpMessage: 11, + getScpState: 12, + hello: 13, +}); + +// === xdr source ============================================================ +// +// struct DontHave // { -// uint32 threshold; -// PublicKey validators<>; -// SCPQuorumSet innerSets<>; +// MessageType type; +// uint256 reqHash; // }; // // =========================================================================== -xdr.struct("ScpQuorumSet", [ - ["threshold", xdr.lookup("Uint32")], - ["validators", xdr.varArray(xdr.lookup("PublicKey"), 2147483647)], - ["innerSets", xdr.varArray(xdr.lookup("ScpQuorumSet"), 2147483647)], +xdr.struct("DontHave", [ + ["type", xdr.lookup("MessageType")], + ["reqHash", xdr.lookup("Uint256")], ]); // === xdr source ============================================================ // -// typedef PublicKey AccountID; +// union StellarMessage switch (MessageType type) +// { +// case ERROR_MSG: +// Error error; +// case HELLO: +// Hello hello; +// case AUTH: +// Auth auth; +// 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; +// case GET_SCP_STATE: +// uint32 getSCPLedgerSeq; // ledger seq requested ; if 0, requests the latest +// }; // // =========================================================================== -xdr.typedef("AccountId", xdr.lookup("PublicKey")); +xdr.union("StellarMessage", { + switchOn: xdr.lookup("MessageType"), + switchName: "type", + switches: [ + ["errorMsg", "error"], + ["hello", "hello"], + ["auth", "auth"], + ["dontHave", "dontHave"], + ["getPeer", xdr.void()], + ["peer", "peers"], + ["getTxSet", "txSetHash"], + ["txSet", "txSet"], + ["transaction", "transaction"], + ["getScpQuorumset", "qSetHash"], + ["scpQuorumset", "qSet"], + ["scpMessage", "envelope"], + ["getScpState", "getScpLedgerSeq"], + ], + arms: { + error: xdr.lookup("Error"), + hello: xdr.lookup("Hello"), + auth: xdr.lookup("Auth"), + dontHave: xdr.lookup("DontHave"), + peers: xdr.varArray(xdr.lookup("PeerAddress"), 2147483647), + txSetHash: xdr.lookup("Uint256"), + txSet: xdr.lookup("TransactionSet"), + transaction: xdr.lookup("TransactionEnvelope"), + qSetHash: xdr.lookup("Uint256"), + qSet: xdr.lookup("ScpQuorumSet"), + envelope: xdr.lookup("ScpEnvelope"), + getScpLedgerSeq: xdr.lookup("Uint32"), + }, +}); // === xdr source ============================================================ // -// typedef opaque Thresholds[4]; +// struct +// { +// uint64 sequence; +// StellarMessage message; +// HmacSha256Mac mac; +// } // // =========================================================================== -xdr.typedef("Thresholds", xdr.opaque(4)); +xdr.struct("AuthenticatedMessageV0", [ + ["sequence", xdr.lookup("Uint64")], + ["message", xdr.lookup("StellarMessage")], + ["mac", xdr.lookup("HmacSha256Mac")], +]); // === xdr source ============================================================ // -// typedef string string32<32>; +// union AuthenticatedMessage switch (uint32 v) +// { +// case 0: +// struct +// { +// uint64 sequence; +// StellarMessage message; +// HmacSha256Mac mac; +// } v0; +// }; // // =========================================================================== -xdr.typedef("String32", xdr.string(32)); +xdr.union("AuthenticatedMessage", { + switchOn: xdr.lookup("Uint32"), + switchName: "v", + switches: [ + [0, "v0"], + ], + arms: { + v0: xdr.lookup("AuthenticatedMessageV0"), + }, +}); // === xdr source ============================================================ // -// typedef string string64<64>; +// typedef opaque Hash[32]; // // =========================================================================== -xdr.typedef("String64", xdr.string(64)); +xdr.typedef("Hash", xdr.opaque(32)); // === xdr source ============================================================ // -// typedef uint64 SequenceNumber; +// typedef opaque uint256[32]; // // =========================================================================== -xdr.typedef("SequenceNumber", xdr.lookup("Uint64")); +xdr.typedef("Uint256", xdr.opaque(32)); // === xdr source ============================================================ // -// typedef opaque DataValue<64>; +// typedef unsigned int uint32; // // =========================================================================== -xdr.typedef("DataValue", xdr.varOpaque(64)); +xdr.typedef("Uint32", xdr.uint()); // === xdr source ============================================================ // -// enum AssetType -// { -// ASSET_TYPE_NATIVE = 0, -// ASSET_TYPE_CREDIT_ALPHANUM4 = 1, -// ASSET_TYPE_CREDIT_ALPHANUM12 = 2 -// }; +// typedef int int32; // // =========================================================================== -xdr.enum("AssetType", { - assetTypeNative: 0, - assetTypeCreditAlphanum4: 1, - assetTypeCreditAlphanum12: 2, -}); +xdr.typedef("Int32", xdr.int()); // === xdr source ============================================================ // -// struct -// { -// opaque assetCode[4]; // 1 to 4 characters -// AccountID issuer; -// } +// typedef unsigned hyper uint64; // // =========================================================================== -xdr.struct("AssetAlphaNum4", [ - ["assetCode", xdr.opaque(4)], - ["issuer", xdr.lookup("AccountId")], -]); +xdr.typedef("Uint64", xdr.uhyper()); // === xdr source ============================================================ // -// struct -// { -// opaque assetCode[12]; // 5 to 12 characters -// AccountID issuer; -// } +// typedef hyper int64; // // =========================================================================== -xdr.struct("AssetAlphaNum12", [ - ["assetCode", xdr.opaque(12)], - ["issuer", xdr.lookup("AccountId")], -]); +xdr.typedef("Int64", xdr.hyper()); // === xdr source ============================================================ // -// union Asset switch (AssetType type) +// enum CryptoKeyType // { -// case ASSET_TYPE_NATIVE: // Not credit -// void; -// -// case ASSET_TYPE_CREDIT_ALPHANUM4: -// struct -// { -// opaque assetCode[4]; // 1 to 4 characters -// AccountID issuer; -// } alphaNum4; -// -// case ASSET_TYPE_CREDIT_ALPHANUM12: -// struct -// { -// opaque assetCode[12]; // 5 to 12 characters -// AccountID issuer; -// } alphaNum12; -// -// // add other asset types here in the future +// KEY_TYPE_ED25519 = 0, +// KEY_TYPE_PRE_AUTH_TX = 1, +// KEY_TYPE_HASH_X = 2 // }; // // =========================================================================== -xdr.union("Asset", { - switchOn: xdr.lookup("AssetType"), - switchName: "type", - switches: [ - ["assetTypeNative", xdr.void()], - ["assetTypeCreditAlphanum4", "alphaNum4"], - ["assetTypeCreditAlphanum12", "alphaNum12"], - ], - arms: { - alphaNum4: xdr.lookup("AssetAlphaNum4"), - alphaNum12: xdr.lookup("AssetAlphaNum12"), - }, +xdr.enum("CryptoKeyType", { + keyTypeEd25519: 0, + keyTypePreAuthTx: 1, + keyTypeHashX: 2, }); // === xdr source ============================================================ // -// struct Price +// enum PublicKeyType // { -// int32 n; // numerator -// int32 d; // denominator +// PUBLIC_KEY_TYPE_ED25519 = KEY_TYPE_ED25519 // }; // // =========================================================================== -xdr.struct("Price", [ - ["n", xdr.lookup("Int32")], - ["d", xdr.lookup("Int32")], -]); +xdr.enum("PublicKeyType", { + publicKeyTypeEd25519: 0, +}); // === xdr source ============================================================ // -// enum ThresholdIndexes +// enum SignerKeyType // { -// THRESHOLD_MASTER_WEIGHT = 0, -// THRESHOLD_LOW = 1, -// THRESHOLD_MED = 2, -// THRESHOLD_HIGH = 3 +// SIGNER_KEY_TYPE_ED25519 = KEY_TYPE_ED25519, +// SIGNER_KEY_TYPE_PRE_AUTH_TX = KEY_TYPE_PRE_AUTH_TX, +// SIGNER_KEY_TYPE_HASH_X = KEY_TYPE_HASH_X // }; // // =========================================================================== -xdr.enum("ThresholdIndices", { - thresholdMasterWeight: 0, - thresholdLow: 1, - thresholdMed: 2, - thresholdHigh: 3, +xdr.enum("SignerKeyType", { + signerKeyTypeEd25519: 0, + signerKeyTypePreAuthTx: 1, + signerKeyTypeHashX: 2, }); // === xdr source ============================================================ // -// enum LedgerEntryType +// union PublicKey switch (PublicKeyType type) // { -// ACCOUNT = 0, -// TRUSTLINE = 1, -// OFFER = 2, -// DATA = 3 +// case PUBLIC_KEY_TYPE_ED25519: +// uint256 ed25519; // }; // // =========================================================================== -xdr.enum("LedgerEntryType", { - account: 0, - trustline: 1, - offer: 2, - datum: 3, +xdr.union("PublicKey", { + switchOn: xdr.lookup("PublicKeyType"), + switchName: "type", + switches: [ + ["publicKeyTypeEd25519", "ed25519"], + ], + arms: { + ed25519: xdr.lookup("Uint256"), + }, }); // === xdr source ============================================================ // -// struct Signer +// union SignerKey switch (SignerKeyType type) // { -// SignerKey key; -// uint32 weight; // really only need 1byte +// case SIGNER_KEY_TYPE_ED25519: +// uint256 ed25519; +// case SIGNER_KEY_TYPE_PRE_AUTH_TX: +// /* Hash of Transaction structure */ +// uint256 preAuthTx; +// case SIGNER_KEY_TYPE_HASH_X: +// /* Hash of random 256 bit preimage X */ +// uint256 hashX; // }; // // =========================================================================== -xdr.struct("Signer", [ - ["key", xdr.lookup("SignerKey")], - ["weight", xdr.lookup("Uint32")], -]); +xdr.union("SignerKey", { + switchOn: xdr.lookup("SignerKeyType"), + switchName: "type", + switches: [ + ["signerKeyTypeEd25519", "ed25519"], + ["signerKeyTypePreAuthTx", "preAuthTx"], + ["signerKeyTypeHashX", "hashX"], + ], + arms: { + ed25519: xdr.lookup("Uint256"), + preAuthTx: xdr.lookup("Uint256"), + hashX: xdr.lookup("Uint256"), + }, +}); // === xdr source ============================================================ // -// 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 -// }; +// typedef opaque Signature<64>; // // =========================================================================== -xdr.enum("AccountFlags", { - authRequiredFlag: 1, - authRevocableFlag: 2, - authImmutableFlag: 4, -}); +xdr.typedef("Signature", xdr.varOpaque(64)); // === xdr source ============================================================ // -// union switch (int v) -// { -// case 0: -// void; -// } +// typedef opaque SignatureHint[4]; // // =========================================================================== -xdr.union("AccountEntryExt", { - switchOn: xdr.int(), - switchName: "v", - switches: [ - [0, xdr.void()], - ], - arms: { - }, -}); +xdr.typedef("SignatureHint", xdr.opaque(4)); // === 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; -// }; +// typedef PublicKey NodeID; // // =========================================================================== -xdr.struct("AccountEntry", [ - ["accountId", xdr.lookup("AccountId")], - ["balance", xdr.lookup("Int64")], - ["seqNum", xdr.lookup("SequenceNumber")], - ["numSubEntries", xdr.lookup("Uint32")], - ["inflationDest", xdr.option(xdr.lookup("AccountId"))], - ["flags", xdr.lookup("Uint32")], - ["homeDomain", xdr.lookup("String32")], - ["thresholds", xdr.lookup("Thresholds")], - ["signers", xdr.varArray(xdr.lookup("Signer"), 20)], - ["ext", xdr.lookup("AccountEntryExt")], -]); +xdr.typedef("NodeId", xdr.lookup("PublicKey")); // === xdr source ============================================================ // -// enum TrustLineFlags +// struct Curve25519Secret // { -// // issuer has authorized account to perform transactions with its credit -// AUTHORIZED_FLAG = 1 +// opaque key[32]; // }; // // =========================================================================== -xdr.enum("TrustLineFlags", { - authorizedFlag: 1, -}); +xdr.struct("Curve25519Secret", [ + ["key", xdr.opaque(32)], +]); // === xdr source ============================================================ // -// union switch (int v) -// { -// case 0: -// void; -// } +// struct Curve25519Public +// { +// opaque key[32]; +// }; // // =========================================================================== -xdr.union("TrustLineEntryExt", { - switchOn: xdr.int(), - switchName: "v", - switches: [ - [0, xdr.void()], - ], - arms: { - }, -}); +xdr.struct("Curve25519Public", [ + ["key", xdr.opaque(32)], +]); // === xdr source ============================================================ // -// struct TrustLineEntry +// struct HmacSha256Key // { -// 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; +// opaque key[32]; // }; // // =========================================================================== -xdr.struct("TrustLineEntry", [ - ["accountId", xdr.lookup("AccountId")], - ["asset", xdr.lookup("Asset")], - ["balance", xdr.lookup("Int64")], - ["limit", xdr.lookup("Int64")], - ["flags", xdr.lookup("Uint32")], - ["ext", xdr.lookup("TrustLineEntryExt")], +xdr.struct("HmacSha256Key", [ + ["key", xdr.opaque(32)], ]); // === xdr source ============================================================ // -// enum OfferEntryFlags +// struct HmacSha256Mac // { -// // issuer has authorized account to perform transactions with its credit -// PASSIVE_FLAG = 1 +// opaque mac[32]; // }; // // =========================================================================== -xdr.enum("OfferEntryFlags", { - passiveFlag: 1, -}); +xdr.struct("HmacSha256Mac", [ + ["mac", xdr.opaque(32)], +]); // === xdr source ============================================================ // @@ -611,7 +545,7 @@ xdr.enum("OfferEntryFlags", { // } // // =========================================================================== -xdr.union("OfferEntryExt", { +xdr.union("FederationResponseExt", { switchOn: xdr.int(), switchName: "v", switches: [ @@ -623,21 +557,12 @@ xdr.union("OfferEntryExt", { // === xdr source ============================================================ // -// struct OfferEntry +// struct FederationResponse // { -// 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 +// string64 stellarAddress; // Stellar uses string32 for domain name, using double for the federation name +// AccountID accountID; +// Memo memo; // // // reserved for future use // union switch (int v) @@ -649,523 +574,445 @@ xdr.union("OfferEntryExt", { // }; // // =========================================================================== -xdr.struct("OfferEntry", [ - ["sellerId", xdr.lookup("AccountId")], - ["offerId", xdr.lookup("Uint64")], - ["selling", xdr.lookup("Asset")], - ["buying", xdr.lookup("Asset")], - ["amount", xdr.lookup("Int64")], - ["price", xdr.lookup("Price")], - ["flags", xdr.lookup("Uint32")], - ["ext", xdr.lookup("OfferEntryExt")], +xdr.struct("FederationResponse", [ + ["stellarAddress", xdr.lookup("String64")], + ["accountId", xdr.lookup("AccountId")], + ["memo", xdr.lookup("Memo")], + ["ext", xdr.lookup("FederationResponseExt")], ]); // === xdr source ============================================================ // -// union switch (int v) -// { -// case 0: -// void; -// } -// -// =========================================================================== -xdr.union("DataEntryExt", { - switchOn: xdr.int(), - switchName: "v", - switches: [ - [0, xdr.void()], - ], - arms: { - }, -}); - -// === xdr source ============================================================ -// -// struct DataEntry +// struct DecoratedSignature // { -// AccountID accountID; // account this data belongs to -// string64 dataName; -// DataValue dataValue; -// -// // reserved for future use -// union switch (int v) -// { -// case 0: -// void; -// } -// ext; +// SignatureHint hint; // last 4 bytes of the public key, used as a hint +// Signature signature; // actual signature // }; // // =========================================================================== -xdr.struct("DataEntry", [ - ["accountId", xdr.lookup("AccountId")], - ["dataName", xdr.lookup("String64")], - ["dataValue", xdr.lookup("DataValue")], - ["ext", xdr.lookup("DataEntryExt")], +xdr.struct("DecoratedSignature", [ + ["hint", xdr.lookup("SignatureHint")], + ["signature", xdr.lookup("Signature")], ]); // === xdr source ============================================================ // -// union switch (LedgerEntryType type) -// { -// case ACCOUNT: -// AccountEntry account; -// case TRUSTLINE: -// TrustLineEntry trustLine; -// case OFFER: -// OfferEntry offer; -// case DATA: -// DataEntry data; -// } +// 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 +// }; // // =========================================================================== -xdr.union("LedgerEntryData", { - switchOn: xdr.lookup("LedgerEntryType"), - switchName: "type", - switches: [ - ["account", "account"], - ["trustline", "trustLine"], - ["offer", "offer"], - ["datum", "data"], - ], - arms: { - account: xdr.lookup("AccountEntry"), - trustLine: xdr.lookup("TrustLineEntry"), - offer: xdr.lookup("OfferEntry"), - data: xdr.lookup("DataEntry"), - }, +xdr.enum("OperationType", { + createAccount: 0, + payment: 1, + pathPayment: 2, + manageOffer: 3, + createPassiveOffer: 4, + setOption: 5, + changeTrust: 6, + allowTrust: 7, + accountMerge: 8, + inflation: 9, + manageDatum: 10, }); // === xdr source ============================================================ // -// union switch (int v) -// { -// case 0: -// void; -// } +// struct CreateAccountOp +// { +// AccountID destination; // account to create +// int64 startingBalance; // amount they end up with +// }; // // =========================================================================== -xdr.union("LedgerEntryExt", { - switchOn: xdr.int(), - switchName: "v", - switches: [ - [0, xdr.void()], - ], - arms: { - }, -}); +xdr.struct("CreateAccountOp", [ + ["destination", xdr.lookup("AccountId")], + ["startingBalance", xdr.lookup("Int64")], +]); // === xdr source ============================================================ // -// struct LedgerEntry +// struct PaymentOp // { -// 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; +// AccountID destination; // recipient of the payment +// Asset asset; // what they end up with +// int64 amount; // amount they end up with // }; // // =========================================================================== -xdr.struct("LedgerEntry", [ - ["lastModifiedLedgerSeq", xdr.lookup("Uint32")], - ["data", xdr.lookup("LedgerEntryData")], - ["ext", xdr.lookup("LedgerEntryExt")], +xdr.struct("PaymentOp", [ + ["destination", xdr.lookup("AccountId")], + ["asset", xdr.lookup("Asset")], + ["amount", xdr.lookup("Int64")], ]); // === xdr source ============================================================ // -// enum EnvelopeType +// struct PathPaymentOp // { -// ENVELOPE_TYPE_SCP = 1, -// ENVELOPE_TYPE_TX = 2, -// ENVELOPE_TYPE_AUTH = 3 +// 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.enum("EnvelopeType", { - envelopeTypeScp: 1, - envelopeTypeTx: 2, - envelopeTypeAuth: 3, -}); +xdr.struct("PathPaymentOp", [ + ["sendAsset", xdr.lookup("Asset")], + ["sendMax", xdr.lookup("Int64")], + ["destination", xdr.lookup("AccountId")], + ["destAsset", xdr.lookup("Asset")], + ["destAmount", xdr.lookup("Int64")], + ["path", xdr.varArray(xdr.lookup("Asset"), 5)], +]); // === xdr source ============================================================ // -// typedef opaque UpgradeType<128>; +// 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.typedef("UpgradeType", xdr.varOpaque(128)); +xdr.struct("ManageOfferOp", [ + ["selling", xdr.lookup("Asset")], + ["buying", xdr.lookup("Asset")], + ["amount", xdr.lookup("Int64")], + ["price", xdr.lookup("Price")], + ["offerId", xdr.lookup("Uint64")], +]); // === xdr source ============================================================ // -// union switch (int v) -// { -// case 0: -// void; -// } +// 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.union("StellarValueExt", { - switchOn: xdr.int(), - switchName: "v", - switches: [ - [0, xdr.void()], - ], - arms: { - }, -}); +xdr.struct("CreatePassiveOfferOp", [ + ["selling", xdr.lookup("Asset")], + ["buying", xdr.lookup("Asset")], + ["amount", xdr.lookup("Int64")], + ["price", xdr.lookup("Price")], +]); // === xdr source ============================================================ // -// struct StellarValue +// struct SetOptionsOp // { -// Hash txSetHash; // transaction set to apply to previous ledger -// uint64 closeTime; // network close time +// AccountID* inflationDest; // sets the inflation destination // -// // 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 -// // max size is dictated by number of upgrade types (+ room for future) -// UpgradeType upgrades<6>; +// uint32* clearFlags; // which flags to clear +// uint32* setFlags; // which flags to set // -// // reserved for future use -// union switch (int v) -// { -// case 0: -// void; -// } -// ext; +// // 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.struct("StellarValue", [ - ["txSetHash", xdr.lookup("Hash")], - ["closeTime", xdr.lookup("Uint64")], - ["upgrades", xdr.varArray(xdr.lookup("UpgradeType"), 6)], - ["ext", xdr.lookup("StellarValueExt")], -]); +xdr.struct("SetOptionsOp", [ + ["inflationDest", xdr.option(xdr.lookup("AccountId"))], + ["clearFlags", xdr.option(xdr.lookup("Uint32"))], + ["setFlags", xdr.option(xdr.lookup("Uint32"))], + ["masterWeight", xdr.option(xdr.lookup("Uint32"))], + ["lowThreshold", xdr.option(xdr.lookup("Uint32"))], + ["medThreshold", xdr.option(xdr.lookup("Uint32"))], + ["highThreshold", xdr.option(xdr.lookup("Uint32"))], + ["homeDomain", xdr.option(xdr.lookup("String32"))], + ["signer", xdr.option(xdr.lookup("Signer"))], +]); // === xdr source ============================================================ // -// union switch (int v) +// struct ChangeTrustOp +// { +// Asset line; +// +// // if limit is set to 0, deletes the trust line +// int64 limit; +// }; +// +// =========================================================================== +xdr.struct("ChangeTrustOp", [ + ["line", xdr.lookup("Asset")], + ["limit", xdr.lookup("Int64")], +]); + +// === xdr source ============================================================ +// +// union switch (AssetType type) // { -// case 0: -// void; +// // 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.union("LedgerHeaderExt", { - switchOn: xdr.int(), - switchName: "v", +xdr.union("AllowTrustOpAsset", { + switchOn: xdr.lookup("AssetType"), + switchName: "type", switches: [ - [0, xdr.void()], + ["assetTypeCreditAlphanum4", "assetCode4"], + ["assetTypeCreditAlphanum12", "assetCode12"], ], arms: { + assetCode4: xdr.opaque(4), + assetCode12: xdr.opaque(12), }, }); // === xdr source ============================================================ // -// struct LedgerHeader +// struct AllowTrustOp // { -// 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. -// // 10,000,000 stroops in 1 XLM -// -// 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 -// -// uint32 maxTxSetSize; // maximum size a transaction set can be +// AccountID trustor; +// union switch (AssetType type) +// { +// // ASSET_TYPE_NATIVE is not allowed +// case ASSET_TYPE_CREDIT_ALPHANUM4: +// opaque assetCode4[4]; // -// 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 +// case ASSET_TYPE_CREDIT_ALPHANUM12: +// opaque assetCode12[12]; // -// // reserved for future use -// union switch (int v) -// { -// case 0: -// void; +// // add other asset types here in the future // } -// ext; +// asset; +// +// bool authorize; // }; // // =========================================================================== -xdr.struct("LedgerHeader", [ - ["ledgerVersion", xdr.lookup("Uint32")], - ["previousLedgerHash", xdr.lookup("Hash")], - ["scpValue", xdr.lookup("StellarValue")], - ["txSetResultHash", xdr.lookup("Hash")], - ["bucketListHash", xdr.lookup("Hash")], - ["ledgerSeq", xdr.lookup("Uint32")], - ["totalCoins", xdr.lookup("Int64")], - ["feePool", xdr.lookup("Int64")], - ["inflationSeq", xdr.lookup("Uint32")], - ["idPool", xdr.lookup("Uint64")], - ["baseFee", xdr.lookup("Uint32")], - ["baseReserve", xdr.lookup("Uint32")], - ["maxTxSetSize", xdr.lookup("Uint32")], - ["skipList", xdr.array(xdr.lookup("Hash"), 4)], - ["ext", xdr.lookup("LedgerHeaderExt")], +xdr.struct("AllowTrustOp", [ + ["trustor", xdr.lookup("AccountId")], + ["asset", xdr.lookup("AllowTrustOpAsset")], + ["authorize", xdr.bool()], ]); // === xdr source ============================================================ // -// enum LedgerUpgradeType +// struct ManageDataOp // { -// LEDGER_UPGRADE_VERSION = 1, -// LEDGER_UPGRADE_BASE_FEE = 2, -// LEDGER_UPGRADE_MAX_TX_SET_SIZE = 3 +// string64 dataName; +// DataValue* dataValue; // set to null to clear // }; // // =========================================================================== -xdr.enum("LedgerUpgradeType", { - ledgerUpgradeVersion: 1, - ledgerUpgradeBaseFee: 2, - ledgerUpgradeMaxTxSetSize: 3, -}); +xdr.struct("ManageDataOp", [ + ["dataName", xdr.lookup("String64")], + ["dataValue", xdr.option(xdr.lookup("DataValue"))], +]); // === xdr source ============================================================ // -// union LedgerUpgrade switch (LedgerUpgradeType type) -// { -// case LEDGER_UPGRADE_VERSION: -// uint32 newLedgerVersion; // update ledgerVersion -// case LEDGER_UPGRADE_BASE_FEE: -// uint32 newBaseFee; // update baseFee -// case LEDGER_UPGRADE_MAX_TX_SET_SIZE: -// uint32 newMaxTxSetSize; // update maxTxSetSize -// }; +// 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; +// } // // =========================================================================== -xdr.union("LedgerUpgrade", { - switchOn: xdr.lookup("LedgerUpgradeType"), +xdr.union("OperationBody", { + switchOn: xdr.lookup("OperationType"), switchName: "type", switches: [ - ["ledgerUpgradeVersion", "newLedgerVersion"], - ["ledgerUpgradeBaseFee", "newBaseFee"], - ["ledgerUpgradeMaxTxSetSize", "newMaxTxSetSize"], + ["createAccount", "createAccountOp"], + ["payment", "paymentOp"], + ["pathPayment", "pathPaymentOp"], + ["manageOffer", "manageOfferOp"], + ["createPassiveOffer", "createPassiveOfferOp"], + ["setOption", "setOptionsOp"], + ["changeTrust", "changeTrustOp"], + ["allowTrust", "allowTrustOp"], + ["accountMerge", "destination"], + ["inflation", xdr.void()], + ["manageDatum", "manageDataOp"], ], arms: { - newLedgerVersion: xdr.lookup("Uint32"), - newBaseFee: xdr.lookup("Uint32"), - newMaxTxSetSize: xdr.lookup("Uint32"), + createAccountOp: xdr.lookup("CreateAccountOp"), + paymentOp: xdr.lookup("PaymentOp"), + pathPaymentOp: xdr.lookup("PathPaymentOp"), + manageOfferOp: xdr.lookup("ManageOfferOp"), + createPassiveOfferOp: xdr.lookup("CreatePassiveOfferOp"), + setOptionsOp: xdr.lookup("SetOptionsOp"), + changeTrustOp: xdr.lookup("ChangeTrustOp"), + allowTrustOp: xdr.lookup("AllowTrustOp"), + destination: xdr.lookup("AccountId"), + manageDataOp: xdr.lookup("ManageDataOp"), }, }); // === xdr source ============================================================ // -// struct +// 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) // { -// AccountID accountID; +// 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; +// }; // // =========================================================================== -xdr.struct("LedgerKeyAccount", [ - ["accountId", xdr.lookup("AccountId")], +xdr.struct("Operation", [ + ["sourceAccount", xdr.option(xdr.lookup("AccountId"))], + ["body", xdr.lookup("OperationBody")], ]); // === xdr source ============================================================ // -// struct -// { -// AccountID accountID; -// Asset asset; -// } +// enum MemoType +// { +// MEMO_NONE = 0, +// MEMO_TEXT = 1, +// MEMO_ID = 2, +// MEMO_HASH = 3, +// MEMO_RETURN = 4 +// }; // // =========================================================================== -xdr.struct("LedgerKeyTrustLine", [ - ["accountId", xdr.lookup("AccountId")], - ["asset", xdr.lookup("Asset")], -]); - -// === xdr source ============================================================ -// -// struct -// { -// AccountID sellerID; -// uint64 offerID; -// } -// -// =========================================================================== -xdr.struct("LedgerKeyOffer", [ - ["sellerId", xdr.lookup("AccountId")], - ["offerId", xdr.lookup("Uint64")], -]); - -// === xdr source ============================================================ -// -// struct -// { -// AccountID accountID; -// string64 dataName; -// } -// -// =========================================================================== -xdr.struct("LedgerKeyData", [ - ["accountId", xdr.lookup("AccountId")], - ["dataName", xdr.lookup("String64")], -]); - -// === 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; -// -// case DATA: -// struct -// { -// AccountID accountID; -// string64 dataName; -// } data; -// }; -// -// =========================================================================== -xdr.union("LedgerKey", { - switchOn: xdr.lookup("LedgerEntryType"), - switchName: "type", - switches: [ - ["account", "account"], - ["trustline", "trustLine"], - ["offer", "offer"], - ["datum", "data"], - ], - arms: { - account: xdr.lookup("LedgerKeyAccount"), - trustLine: xdr.lookup("LedgerKeyTrustLine"), - offer: xdr.lookup("LedgerKeyOffer"), - data: xdr.lookup("LedgerKeyData"), - }, -}); - -// === xdr source ============================================================ -// -// enum BucketEntryType -// { -// LIVEENTRY = 0, -// DEADENTRY = 1 -// }; -// -// =========================================================================== -xdr.enum("BucketEntryType", { - liveentry: 0, - deadentry: 1, +xdr.enum("MemoType", { + memoNone: 0, + memoText: 1, + memoId: 2, + memoHash: 3, + memoReturn: 4, }); // === xdr source ============================================================ // -// union BucketEntry switch (BucketEntryType type) +// union Memo switch (MemoType type) // { -// case LIVEENTRY: -// LedgerEntry liveEntry; -// -// case DEADENTRY: -// LedgerKey deadEntry; +// 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.union("BucketEntry", { - switchOn: xdr.lookup("BucketEntryType"), +xdr.union("Memo", { + switchOn: xdr.lookup("MemoType"), switchName: "type", switches: [ - ["liveentry", "liveEntry"], - ["deadentry", "deadEntry"], + ["memoNone", xdr.void()], + ["memoText", "text"], + ["memoId", "id"], + ["memoHash", "hash"], + ["memoReturn", "retHash"], ], arms: { - liveEntry: xdr.lookup("LedgerEntry"), - deadEntry: xdr.lookup("LedgerKey"), + text: xdr.string(28), + id: xdr.lookup("Uint64"), + hash: xdr.lookup("Hash"), + retHash: xdr.lookup("Hash"), }, }); // === xdr source ============================================================ // -// struct TransactionSet -// { -// Hash previousLedgerHash; -// TransactionEnvelope txs<>; -// }; -// -// =========================================================================== -xdr.struct("TransactionSet", [ - ["previousLedgerHash", xdr.lookup("Hash")], - ["txes", xdr.varArray(xdr.lookup("TransactionEnvelope"), 2147483647)], -]); - -// === xdr source ============================================================ -// -// struct TransactionResultPair -// { -// Hash transactionHash; -// TransactionResult result; // result for the transaction -// }; -// -// =========================================================================== -xdr.struct("TransactionResultPair", [ - ["transactionHash", xdr.lookup("Hash")], - ["result", xdr.lookup("TransactionResult")], -]); - -// === xdr source ============================================================ -// -// struct TransactionResultSet +// struct TimeBounds // { -// TransactionResultPair results<>; +// uint64 minTime; +// uint64 maxTime; // 0 here means no maxTime // }; // // =========================================================================== -xdr.struct("TransactionResultSet", [ - ["results", xdr.varArray(xdr.lookup("TransactionResultPair"), 2147483647)], +xdr.struct("TimeBounds", [ + ["minTime", xdr.lookup("Uint64")], + ["maxTime", xdr.lookup("Uint64")], ]); // === xdr source ============================================================ @@ -1177,7 +1024,7 @@ xdr.struct("TransactionResultSet", [ // } // // =========================================================================== -xdr.union("TransactionHistoryEntryExt", { +xdr.union("TransactionExt", { switchOn: xdr.int(), switchName: "v", switches: [ @@ -1189,10 +1036,23 @@ xdr.union("TransactionHistoryEntryExt", { // === xdr source ============================================================ // -// struct TransactionHistoryEntry +// struct Transaction // { -// uint32 ledgerSeq; -// TransactionSet txSet; +// // 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) @@ -1204,2239 +1064,2406 @@ xdr.union("TransactionHistoryEntryExt", { // }; // // =========================================================================== -xdr.struct("TransactionHistoryEntry", [ - ["ledgerSeq", xdr.lookup("Uint32")], - ["txSet", xdr.lookup("TransactionSet")], - ["ext", xdr.lookup("TransactionHistoryEntryExt")], +xdr.struct("Transaction", [ + ["sourceAccount", xdr.lookup("AccountId")], + ["fee", xdr.lookup("Uint32")], + ["seqNum", xdr.lookup("SequenceNumber")], + ["timeBounds", xdr.option(xdr.lookup("TimeBounds"))], + ["memo", xdr.lookup("Memo")], + ["operations", xdr.varArray(xdr.lookup("Operation"), 100)], + ["ext", xdr.lookup("TransactionExt")], ]); // === xdr source ============================================================ // -// union switch (int v) +// union switch (EnvelopeType type) // { -// case 0: -// void; +// case ENVELOPE_TYPE_TX: +// Transaction tx; +// /* All other values of type are invalid */ // } // // =========================================================================== -xdr.union("TransactionHistoryResultEntryExt", { - switchOn: xdr.int(), - switchName: "v", +xdr.union("TransactionSignaturePayloadTaggedTransaction", { + switchOn: xdr.lookup("EnvelopeType"), + switchName: "type", switches: [ - [0, xdr.void()], + ["envelopeTypeTx", "tx"], ], arms: { + tx: xdr.lookup("Transaction"), }, }); // === xdr source ============================================================ // -// struct TransactionHistoryResultEntry -// { -// uint32 ledgerSeq; -// TransactionResultSet txResultSet; -// -// // reserved for future use -// union switch (int v) +// struct TransactionSignaturePayload { +// Hash networkId; +// union switch (EnvelopeType type) // { -// case 0: -// void; -// } -// ext; +// case ENVELOPE_TYPE_TX: +// Transaction tx; +// /* All other values of type are invalid */ +// } taggedTransaction; // }; // // =========================================================================== -xdr.struct("TransactionHistoryResultEntry", [ - ["ledgerSeq", xdr.lookup("Uint32")], - ["txResultSet", xdr.lookup("TransactionResultSet")], - ["ext", xdr.lookup("TransactionHistoryResultEntryExt")], +xdr.struct("TransactionSignaturePayload", [ + ["networkId", xdr.lookup("Hash")], + ["taggedTransaction", xdr.lookup("TransactionSignaturePayloadTaggedTransaction")], ]); // === xdr source ============================================================ // -// union switch (int v) -// { -// case 0: -// void; -// } +// struct TransactionEnvelope +// { +// Transaction tx; +// /* Each decorated signature is a signature over the SHA256 hash of +// * a TransactionSignaturePayload */ +// DecoratedSignature +// signatures<20>; +// }; // // =========================================================================== -xdr.union("LedgerHeaderHistoryEntryExt", { - switchOn: xdr.int(), - switchName: "v", - switches: [ - [0, xdr.void()], - ], - arms: { - }, -}); - -// === xdr source ============================================================ -// -// struct LedgerHeaderHistoryEntry -// { -// Hash hash; -// LedgerHeader header; -// -// // reserved for future use -// union switch (int v) -// { -// case 0: -// void; -// } -// ext; -// }; -// -// =========================================================================== -xdr.struct("LedgerHeaderHistoryEntry", [ - ["hash", xdr.lookup("Hash")], - ["header", xdr.lookup("LedgerHeader")], - ["ext", xdr.lookup("LedgerHeaderHistoryEntryExt")], +xdr.struct("TransactionEnvelope", [ + ["tx", xdr.lookup("Transaction")], + ["signatures", xdr.varArray(xdr.lookup("DecoratedSignature"), 20)], ]); // === xdr source ============================================================ // -// struct LedgerSCPMessages +// struct ClaimOfferAtom // { -// uint32 ledgerSeq; -// SCPEnvelope messages<>; +// // 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; // }; // // =========================================================================== -xdr.struct("LedgerScpMessages", [ - ["ledgerSeq", xdr.lookup("Uint32")], - ["messages", xdr.varArray(xdr.lookup("ScpEnvelope"), 2147483647)], +xdr.struct("ClaimOfferAtom", [ + ["sellerId", xdr.lookup("AccountId")], + ["offerId", xdr.lookup("Uint64")], + ["assetSold", xdr.lookup("Asset")], + ["amountSold", xdr.lookup("Int64")], + ["assetBought", xdr.lookup("Asset")], + ["amountBought", xdr.lookup("Int64")], ]); // === xdr source ============================================================ // -// struct SCPHistoryEntryV0 +// enum CreateAccountResultCode // { -// SCPQuorumSet quorumSets<>; // additional quorum sets used by ledgerMessages -// LedgerSCPMessages ledgerMessages; +// // 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.struct("ScpHistoryEntryV0", [ - ["quorumSets", xdr.varArray(xdr.lookup("ScpQuorumSet"), 2147483647)], - ["ledgerMessages", xdr.lookup("LedgerScpMessages")], -]); +xdr.enum("CreateAccountResultCode", { + createAccountSuccess: 0, + createAccountMalformed: -1, + createAccountUnderfunded: -2, + createAccountLowReserve: -3, + createAccountAlreadyExist: -4, +}); // === xdr source ============================================================ // -// union SCPHistoryEntry switch (int v) +// union CreateAccountResult switch (CreateAccountResultCode code) // { -// case 0: -// SCPHistoryEntryV0 v0; +// case CREATE_ACCOUNT_SUCCESS: +// void; +// default: +// void; // }; // // =========================================================================== -xdr.union("ScpHistoryEntry", { - switchOn: xdr.int(), - switchName: "v", +xdr.union("CreateAccountResult", { + switchOn: xdr.lookup("CreateAccountResultCode"), + switchName: "code", switches: [ - [0, "v0"], + ["createAccountSuccess", xdr.void()], ], arms: { - v0: xdr.lookup("ScpHistoryEntryV0"), }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// enum LedgerEntryChangeType +// enum PaymentResultCode // { -// 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 -// LEDGER_ENTRY_STATE = 3 // value of the entry +// // 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 // }; // // =========================================================================== -xdr.enum("LedgerEntryChangeType", { - ledgerEntryCreated: 0, - ledgerEntryUpdated: 1, - ledgerEntryRemoved: 2, - ledgerEntryState: 3, +xdr.enum("PaymentResultCode", { + paymentSuccess: 0, + paymentMalformed: -1, + paymentUnderfunded: -2, + paymentSrcNoTrust: -3, + paymentSrcNotAuthorized: -4, + paymentNoDestination: -5, + paymentNoTrust: -6, + paymentNotAuthorized: -7, + paymentLineFull: -8, + paymentNoIssuer: -9, }); // === xdr source ============================================================ // -// union LedgerEntryChange switch (LedgerEntryChangeType type) +// union PaymentResult switch (PaymentResultCode code) // { -// case LEDGER_ENTRY_CREATED: -// LedgerEntry created; -// case LEDGER_ENTRY_UPDATED: -// LedgerEntry updated; -// case LEDGER_ENTRY_REMOVED: -// LedgerKey removed; -// case LEDGER_ENTRY_STATE: -// LedgerEntry state; +// case PAYMENT_SUCCESS: +// void; +// default: +// void; // }; // // =========================================================================== -xdr.union("LedgerEntryChange", { - switchOn: xdr.lookup("LedgerEntryChangeType"), - switchName: "type", +xdr.union("PaymentResult", { + switchOn: xdr.lookup("PaymentResultCode"), + switchName: "code", switches: [ - ["ledgerEntryCreated", "created"], - ["ledgerEntryUpdated", "updated"], - ["ledgerEntryRemoved", "removed"], - ["ledgerEntryState", "state"], + ["paymentSuccess", xdr.void()], ], arms: { - created: xdr.lookup("LedgerEntry"), - updated: xdr.lookup("LedgerEntry"), - removed: xdr.lookup("LedgerKey"), - state: xdr.lookup("LedgerEntry"), }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// typedef LedgerEntryChange LedgerEntryChanges<>; +// 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 +// }; // // =========================================================================== -xdr.typedef("LedgerEntryChanges", xdr.varArray(xdr.lookup("LedgerEntryChange"), 2147483647)); +xdr.enum("PathPaymentResultCode", { + pathPaymentSuccess: 0, + pathPaymentMalformed: -1, + pathPaymentUnderfunded: -2, + pathPaymentSrcNoTrust: -3, + pathPaymentSrcNotAuthorized: -4, + pathPaymentNoDestination: -5, + pathPaymentNoTrust: -6, + pathPaymentNotAuthorized: -7, + pathPaymentLineFull: -8, + pathPaymentNoIssuer: -9, + pathPaymentTooFewOffer: -10, + pathPaymentOfferCrossSelf: -11, + pathPaymentOverSendmax: -12, +}); // === xdr source ============================================================ // -// struct OperationMeta +// struct SimplePaymentResult // { -// LedgerEntryChanges changes; +// AccountID destination; +// Asset asset; +// int64 amount; // }; // // =========================================================================== -xdr.struct("OperationMeta", [ - ["changes", xdr.lookup("LedgerEntryChanges")], +xdr.struct("SimplePaymentResult", [ + ["destination", xdr.lookup("AccountId")], + ["asset", xdr.lookup("Asset")], + ["amount", xdr.lookup("Int64")], ]); // === xdr source ============================================================ // -// union TransactionMeta switch (int v) +// struct +// { +// ClaimOfferAtom offers<>; +// SimplePaymentResult last; +// } +// +// =========================================================================== +xdr.struct("PathPaymentResultSuccess", [ + ["offers", xdr.varArray(xdr.lookup("ClaimOfferAtom"), 2147483647)], + ["last", xdr.lookup("SimplePaymentResult")], +]); + +// === xdr source ============================================================ +// +// union PathPaymentResult switch (PathPaymentResultCode code) // { -// case 0: -// OperationMeta operations<>; +// 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; // }; // // =========================================================================== -xdr.union("TransactionMeta", { - switchOn: xdr.int(), - switchName: "v", +xdr.union("PathPaymentResult", { + switchOn: xdr.lookup("PathPaymentResultCode"), + switchName: "code", switches: [ - [0, "operations"], + ["pathPaymentSuccess", "success"], + ["pathPaymentNoIssuer", "noIssuer"], ], arms: { - operations: xdr.varArray(xdr.lookup("OperationMeta"), 2147483647), + success: xdr.lookup("PathPaymentResultSuccess"), + noIssuer: xdr.lookup("Asset"), }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// enum ErrorCode +// enum ManageOfferResultCode // { -// ERR_MISC = 0, // Unspecific error -// ERR_DATA = 1, // Malformed data -// ERR_CONF = 2, // Misconfiguration error -// ERR_AUTH = 3, // Authentication failure -// ERR_LOAD = 4 // System overloaded +// // 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 // }; // // =========================================================================== -xdr.enum("ErrorCode", { - errMisc: 0, - errDatum: 1, - errConf: 2, - errAuth: 3, - errLoad: 4, +xdr.enum("ManageOfferResultCode", { + manageOfferSuccess: 0, + manageOfferMalformed: -1, + manageOfferSellNoTrust: -2, + manageOfferBuyNoTrust: -3, + manageOfferSellNotAuthorized: -4, + manageOfferBuyNotAuthorized: -5, + manageOfferLineFull: -6, + manageOfferUnderfunded: -7, + manageOfferCrossSelf: -8, + manageOfferSellNoIssuer: -9, + manageOfferBuyNoIssuer: -10, + manageOfferNotFound: -11, + manageOfferLowReserve: -12, }); // === xdr source ============================================================ // -// struct Error +// enum ManageOfferEffect // { -// ErrorCode code; -// string msg<100>; +// MANAGE_OFFER_CREATED = 0, +// MANAGE_OFFER_UPDATED = 1, +// MANAGE_OFFER_DELETED = 2 // }; // // =========================================================================== -xdr.struct("Error", [ - ["code", xdr.lookup("ErrorCode")], - ["msg", xdr.string(100)], -]); +xdr.enum("ManageOfferEffect", { + manageOfferCreated: 0, + manageOfferUpdated: 1, + manageOfferDeleted: 2, +}); // === xdr source ============================================================ // -// struct AuthCert -// { -// Curve25519Public pubkey; -// uint64 expiration; -// Signature sig; -// }; +// union switch (ManageOfferEffect effect) +// { +// case MANAGE_OFFER_CREATED: +// case MANAGE_OFFER_UPDATED: +// OfferEntry offer; +// default: +// void; +// } // // =========================================================================== -xdr.struct("AuthCert", [ - ["pubkey", xdr.lookup("Curve25519Public")], - ["expiration", xdr.lookup("Uint64")], - ["sig", xdr.lookup("Signature")], -]); +xdr.union("ManageOfferSuccessResultOffer", { + switchOn: xdr.lookup("ManageOfferEffect"), + switchName: "effect", + switches: [ + ["manageOfferCreated", "offer"], + ["manageOfferUpdated", "offer"], + ], + arms: { + offer: xdr.lookup("OfferEntry"), + }, + defaultArm: xdr.void(), +}); // === xdr source ============================================================ // -// struct Hello +// struct ManageOfferSuccessResult // { -// uint32 ledgerVersion; -// uint32 overlayVersion; -// uint32 overlayMinVersion; -// Hash networkID; -// string versionStr<100>; -// int listeningPort; -// NodeID peerID; -// AuthCert cert; -// uint256 nonce; +// // 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.struct("Hello", [ - ["ledgerVersion", xdr.lookup("Uint32")], - ["overlayVersion", xdr.lookup("Uint32")], - ["overlayMinVersion", xdr.lookup("Uint32")], - ["networkId", xdr.lookup("Hash")], - ["versionStr", xdr.string(100)], - ["listeningPort", xdr.int()], - ["peerId", xdr.lookup("NodeId")], - ["cert", xdr.lookup("AuthCert")], - ["nonce", xdr.lookup("Uint256")], +xdr.struct("ManageOfferSuccessResult", [ + ["offersClaimed", xdr.varArray(xdr.lookup("ClaimOfferAtom"), 2147483647)], + ["offer", xdr.lookup("ManageOfferSuccessResultOffer")], ]); // === xdr source ============================================================ // -// struct Auth +// union ManageOfferResult switch (ManageOfferResultCode code) // { -// // Empty message, just to confirm -// // establishment of MAC keys. -// int unused; +// case MANAGE_OFFER_SUCCESS: +// ManageOfferSuccessResult success; +// default: +// void; // }; // // =========================================================================== -xdr.struct("Auth", [ - ["unused", xdr.int()], -]); +xdr.union("ManageOfferResult", { + switchOn: xdr.lookup("ManageOfferResultCode"), + switchName: "code", + switches: [ + ["manageOfferSuccess", "success"], + ], + arms: { + success: xdr.lookup("ManageOfferSuccessResult"), + }, + defaultArm: xdr.void(), +}); // === xdr source ============================================================ // -// enum IPAddrType +// enum SetOptionsResultCode // { -// IPv4 = 0, -// IPv6 = 1 +// // 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 // }; // // =========================================================================== -xdr.enum("IpAddrType", { - iPv4: 0, - iPv6: 1, +xdr.enum("SetOptionsResultCode", { + setOptionsSuccess: 0, + setOptionsLowReserve: -1, + setOptionsTooManySigner: -2, + setOptionsBadFlag: -3, + setOptionsInvalidInflation: -4, + setOptionsCantChange: -5, + setOptionsUnknownFlag: -6, + setOptionsThresholdOutOfRange: -7, + setOptionsBadSigner: -8, + setOptionsInvalidHomeDomain: -9, }); // === xdr source ============================================================ // -// union switch (IPAddrType type) -// { -// case IPv4: -// opaque ipv4[4]; -// case IPv6: -// opaque ipv6[16]; -// } +// union SetOptionsResult switch (SetOptionsResultCode code) +// { +// case SET_OPTIONS_SUCCESS: +// void; +// default: +// void; +// }; // // =========================================================================== -xdr.union("PeerAddressIp", { - switchOn: xdr.lookup("IpAddrType"), - switchName: "type", +xdr.union("SetOptionsResult", { + switchOn: xdr.lookup("SetOptionsResultCode"), + switchName: "code", switches: [ - ["iPv4", "ipv4"], - ["iPv6", "ipv6"], + ["setOptionsSuccess", xdr.void()], ], arms: { - ipv4: xdr.opaque(4), - ipv6: xdr.opaque(16), }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// struct PeerAddress +// enum ChangeTrustResultCode // { -// union switch (IPAddrType type) -// { -// case IPv4: -// opaque ipv4[4]; -// case IPv6: -// opaque ipv6[16]; -// } -// ip; -// uint32 port; -// uint32 numFailures; +// // 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, +// CHANGE_TRUST_SELF_NOT_ALLOWED = -5 // trusting self is not allowed // }; // // =========================================================================== -xdr.struct("PeerAddress", [ - ["ip", xdr.lookup("PeerAddressIp")], - ["port", xdr.lookup("Uint32")], - ["numFailures", xdr.lookup("Uint32")], -]); +xdr.enum("ChangeTrustResultCode", { + changeTrustSuccess: 0, + changeTrustMalformed: -1, + changeTrustNoIssuer: -2, + changeTrustInvalidLimit: -3, + changeTrustLowReserve: -4, + changeTrustSelfNotAllowed: -5, +}); // === xdr source ============================================================ // -// enum MessageType +// union ChangeTrustResult switch (ChangeTrustResultCode code) // { -// ERROR_MSG = 0, -// AUTH = 2, -// DONT_HAVE = 3, -// -// GET_PEERS = 4, // gets a list of peers this guy knows about -// PEERS = 5, -// -// GET_TX_SET = 6, // gets a particular txset by hash -// TX_SET = 7, -// -// TRANSACTION = 8, // pass on a tx you have heard about -// -// // SCP -// GET_SCP_QUORUMSET = 9, -// SCP_QUORUMSET = 10, -// SCP_MESSAGE = 11, -// GET_SCP_STATE = 12, -// -// // new messages -// HELLO = 13 +// case CHANGE_TRUST_SUCCESS: +// void; +// default: +// void; // }; // // =========================================================================== -xdr.enum("MessageType", { - errorMsg: 0, - auth: 2, - dontHave: 3, - getPeer: 4, - peer: 5, - getTxSet: 6, - txSet: 7, - transaction: 8, - getScpQuorumset: 9, - scpQuorumset: 10, - scpMessage: 11, - getScpState: 12, - hello: 13, +xdr.union("ChangeTrustResult", { + switchOn: xdr.lookup("ChangeTrustResultCode"), + switchName: "code", + switches: [ + ["changeTrustSuccess", xdr.void()], + ], + arms: { + }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// struct DontHave +// enum AllowTrustResultCode // { -// MessageType type; -// uint256 reqHash; +// // 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, +// ALLOW_TRUST_SELF_NOT_ALLOWED = -5 // trusting self is not allowed // }; // // =========================================================================== -xdr.struct("DontHave", [ - ["type", xdr.lookup("MessageType")], - ["reqHash", xdr.lookup("Uint256")], -]); +xdr.enum("AllowTrustResultCode", { + allowTrustSuccess: 0, + allowTrustMalformed: -1, + allowTrustNoTrustLine: -2, + allowTrustTrustNotRequired: -3, + allowTrustCantRevoke: -4, + allowTrustSelfNotAllowed: -5, +}); // === xdr source ============================================================ // -// union StellarMessage switch (MessageType type) +// union AllowTrustResult switch (AllowTrustResultCode code) // { -// case ERROR_MSG: -// Error error; -// case HELLO: -// Hello hello; -// case AUTH: -// Auth auth; -// case DONT_HAVE: -// DontHave dontHave; -// case GET_PEERS: +// case ALLOW_TRUST_SUCCESS: +// void; +// default: // 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; -// case GET_SCP_STATE: -// uint32 getSCPLedgerSeq; // ledger seq requested ; if 0, requests the latest // }; // // =========================================================================== -xdr.union("StellarMessage", { - switchOn: xdr.lookup("MessageType"), - switchName: "type", +xdr.union("AllowTrustResult", { + switchOn: xdr.lookup("AllowTrustResultCode"), + switchName: "code", switches: [ - ["errorMsg", "error"], - ["hello", "hello"], - ["auth", "auth"], - ["dontHave", "dontHave"], - ["getPeer", xdr.void()], - ["peer", "peers"], - ["getTxSet", "txSetHash"], - ["txSet", "txSet"], - ["transaction", "transaction"], - ["getScpQuorumset", "qSetHash"], - ["scpQuorumset", "qSet"], - ["scpMessage", "envelope"], - ["getScpState", "getScpLedgerSeq"], + ["allowTrustSuccess", xdr.void()], ], arms: { - error: xdr.lookup("Error"), - hello: xdr.lookup("Hello"), - auth: xdr.lookup("Auth"), - dontHave: xdr.lookup("DontHave"), - peers: xdr.varArray(xdr.lookup("PeerAddress"), 2147483647), - txSetHash: xdr.lookup("Uint256"), - txSet: xdr.lookup("TransactionSet"), - transaction: xdr.lookup("TransactionEnvelope"), - qSetHash: xdr.lookup("Uint256"), - qSet: xdr.lookup("ScpQuorumSet"), - envelope: xdr.lookup("ScpEnvelope"), - getScpLedgerSeq: xdr.lookup("Uint32"), }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// struct +// enum AccountMergeResultCode // { -// uint64 sequence; -// StellarMessage message; -// HmacSha256Mac mac; -// } +// // 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 +// }; // // =========================================================================== -xdr.struct("AuthenticatedMessageV0", [ - ["sequence", xdr.lookup("Uint64")], - ["message", xdr.lookup("StellarMessage")], - ["mac", xdr.lookup("HmacSha256Mac")], -]); +xdr.enum("AccountMergeResultCode", { + accountMergeSuccess: 0, + accountMergeMalformed: -1, + accountMergeNoAccount: -2, + accountMergeImmutableSet: -3, + accountMergeHasSubEntry: -4, +}); // === xdr source ============================================================ // -// union AuthenticatedMessage switch (uint32 v) -// { -// case 0: -// struct +// union AccountMergeResult switch (AccountMergeResultCode code) // { -// uint64 sequence; -// StellarMessage message; -// HmacSha256Mac mac; -// } v0; +// case ACCOUNT_MERGE_SUCCESS: +// int64 sourceAccountBalance; // how much got transfered from source account +// default: +// void; // }; // // =========================================================================== -xdr.union("AuthenticatedMessage", { - switchOn: xdr.lookup("Uint32"), - switchName: "v", +xdr.union("AccountMergeResult", { + switchOn: xdr.lookup("AccountMergeResultCode"), + switchName: "code", switches: [ - [0, "v0"], + ["accountMergeSuccess", "sourceAccountBalance"], ], arms: { - v0: xdr.lookup("AuthenticatedMessageV0"), + sourceAccountBalance: xdr.lookup("Int64"), }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// struct DecoratedSignature -// { -// SignatureHint hint; // last 4 bytes of the public key, used as a hint -// Signature signature; // actual signature -// }; -// -// =========================================================================== -xdr.struct("DecoratedSignature", [ - ["hint", xdr.lookup("SignatureHint")], - ["signature", xdr.lookup("Signature")], -]); - -// === xdr source ============================================================ -// -// enum OperationType +// enum InflationResultCode // { -// 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 +// // codes considered as "success" for the operation +// INFLATION_SUCCESS = 0, +// // codes considered as "failure" for the operation +// INFLATION_NOT_TIME = -1 // }; // // =========================================================================== -xdr.enum("OperationType", { - createAccount: 0, - payment: 1, - pathPayment: 2, - manageOffer: 3, - createPassiveOffer: 4, - setOption: 5, - changeTrust: 6, - allowTrust: 7, - accountMerge: 8, - inflation: 9, - manageDatum: 10, +xdr.enum("InflationResultCode", { + inflationSuccess: 0, + inflationNotTime: -1, }); // === xdr source ============================================================ // -// struct CreateAccountOp +// struct InflationPayout // or use PaymentResultAtom to limit types? // { -// AccountID destination; // account to create -// int64 startingBalance; // amount they end up with +// AccountID destination; +// int64 amount; // }; // // =========================================================================== -xdr.struct("CreateAccountOp", [ +xdr.struct("InflationPayout", [ ["destination", xdr.lookup("AccountId")], - ["startingBalance", xdr.lookup("Int64")], + ["amount", xdr.lookup("Int64")], ]); // === xdr source ============================================================ // -// struct PaymentOp +// union InflationResult switch (InflationResultCode code) // { -// AccountID destination; // recipient of the payment -// Asset asset; // what they end up with -// int64 amount; // amount they end up with +// case INFLATION_SUCCESS: +// InflationPayout payouts<>; +// default: +// void; // }; // // =========================================================================== -xdr.struct("PaymentOp", [ - ["destination", xdr.lookup("AccountId")], - ["asset", xdr.lookup("Asset")], - ["amount", xdr.lookup("Int64")], -]); +xdr.union("InflationResult", { + switchOn: xdr.lookup("InflationResultCode"), + switchName: "code", + switches: [ + ["inflationSuccess", "payouts"], + ], + arms: { + payouts: xdr.varArray(xdr.lookup("InflationPayout"), 2147483647), + }, + defaultArm: xdr.void(), +}); // === xdr source ============================================================ // -// struct PathPaymentOp +// enum ManageDataResultCode // { -// 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 +// // 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 // }; // // =========================================================================== -xdr.struct("PathPaymentOp", [ - ["sendAsset", xdr.lookup("Asset")], - ["sendMax", xdr.lookup("Int64")], - ["destination", xdr.lookup("AccountId")], - ["destAsset", xdr.lookup("Asset")], - ["destAmount", xdr.lookup("Int64")], - ["path", xdr.varArray(xdr.lookup("Asset"), 5)], -]); +xdr.enum("ManageDataResultCode", { + manageDataSuccess: 0, + manageDataNotSupportedYet: -1, + manageDataNameNotFound: -2, + manageDataLowReserve: -3, + manageDataInvalidName: -4, +}); // === xdr source ============================================================ // -// struct ManageOfferOp +// union ManageDataResult switch (ManageDataResultCode code) // { -// 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 +// case MANAGE_DATA_SUCCESS: +// void; +// default: +// void; +// }; +// +// =========================================================================== +xdr.union("ManageDataResult", { + switchOn: xdr.lookup("ManageDataResultCode"), + switchName: "code", + switches: [ + ["manageDataSuccess", xdr.void()], + ], + arms: { + }, + defaultArm: xdr.void(), +}); + +// === xdr source ============================================================ +// +// enum OperationResultCode +// { +// opINNER = 0, // inner object result is valid // -// // 0=create a new offer, otherwise edit an existing offer -// uint64 offerID; +// opBAD_AUTH = -1, // too few valid signatures / wrong network +// opNO_ACCOUNT = -2 // source account was not found // }; // // =========================================================================== -xdr.struct("ManageOfferOp", [ - ["selling", xdr.lookup("Asset")], - ["buying", xdr.lookup("Asset")], - ["amount", xdr.lookup("Int64")], - ["price", xdr.lookup("Price")], - ["offerId", xdr.lookup("Uint64")], -]); +xdr.enum("OperationResultCode", { + opInner: 0, + opBadAuth: -1, + opNoAccount: -2, +}); // === xdr source ============================================================ // -// struct CreatePassiveOfferOp +// 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; +// } +// +// =========================================================================== +xdr.union("OperationResultTr", { + switchOn: xdr.lookup("OperationType"), + switchName: "type", + switches: [ + ["createAccount", "createAccountResult"], + ["payment", "paymentResult"], + ["pathPayment", "pathPaymentResult"], + ["manageOffer", "manageOfferResult"], + ["createPassiveOffer", "createPassiveOfferResult"], + ["setOption", "setOptionsResult"], + ["changeTrust", "changeTrustResult"], + ["allowTrust", "allowTrustResult"], + ["accountMerge", "accountMergeResult"], + ["inflation", "inflationResult"], + ["manageDatum", "manageDataResult"], + ], + arms: { + createAccountResult: xdr.lookup("CreateAccountResult"), + paymentResult: xdr.lookup("PaymentResult"), + pathPaymentResult: xdr.lookup("PathPaymentResult"), + manageOfferResult: xdr.lookup("ManageOfferResult"), + createPassiveOfferResult: xdr.lookup("ManageOfferResult"), + setOptionsResult: xdr.lookup("SetOptionsResult"), + changeTrustResult: xdr.lookup("ChangeTrustResult"), + allowTrustResult: xdr.lookup("AllowTrustResult"), + accountMergeResult: xdr.lookup("AccountMergeResult"), + inflationResult: xdr.lookup("InflationResult"), + manageDataResult: xdr.lookup("ManageDataResult"), + }, +}); + +// === xdr source ============================================================ +// +// union OperationResult switch (OperationResultCode code) // { -// 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 +// 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; // }; // // =========================================================================== -xdr.struct("CreatePassiveOfferOp", [ - ["selling", xdr.lookup("Asset")], - ["buying", xdr.lookup("Asset")], - ["amount", xdr.lookup("Int64")], - ["price", xdr.lookup("Price")], -]); +xdr.union("OperationResult", { + switchOn: xdr.lookup("OperationResultCode"), + switchName: "code", + switches: [ + ["opInner", "tr"], + ], + arms: { + tr: xdr.lookup("OperationResultTr"), + }, + defaultArm: xdr.void(), +}); // === xdr source ============================================================ // -// struct SetOptionsOp +// enum TransactionResultCode // { -// AccountID* inflationDest; // sets the inflation destination -// -// uint32* clearFlags; // which flags to clear -// uint32* setFlags; // which flags to set +// txSUCCESS = 0, // all operations succeeded // -// // account threshold manipulation -// uint32* masterWeight; // weight of the master account -// uint32* lowThreshold; -// uint32* medThreshold; -// uint32* highThreshold; +// txFAILED = -1, // one of the operations failed (none were applied) // -// string32* homeDomain; // sets the home domain +// 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 // -// // Add, update or remove a signer for the account -// // signer is deleted if the weight is 0 -// Signer* signer; +// 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 // }; // // =========================================================================== -xdr.struct("SetOptionsOp", [ - ["inflationDest", xdr.option(xdr.lookup("AccountId"))], - ["clearFlags", xdr.option(xdr.lookup("Uint32"))], - ["setFlags", xdr.option(xdr.lookup("Uint32"))], - ["masterWeight", xdr.option(xdr.lookup("Uint32"))], - ["lowThreshold", xdr.option(xdr.lookup("Uint32"))], - ["medThreshold", xdr.option(xdr.lookup("Uint32"))], - ["highThreshold", xdr.option(xdr.lookup("Uint32"))], - ["homeDomain", xdr.option(xdr.lookup("String32"))], - ["signer", xdr.option(xdr.lookup("Signer"))], -]); +xdr.enum("TransactionResultCode", { + txSuccess: 0, + txFailed: -1, + txTooEarly: -2, + txTooLate: -3, + txMissingOperation: -4, + txBadSeq: -5, + txBadAuth: -6, + txInsufficientBalance: -7, + txNoAccount: -8, + txInsufficientFee: -9, + txBadAuthExtra: -10, + txInternalError: -11, +}); // === xdr source ============================================================ // -// struct ChangeTrustOp -// { -// Asset line; -// -// // if limit is set to 0, deletes the trust line -// int64 limit; -// }; +// union switch (TransactionResultCode code) +// { +// case txSUCCESS: +// case txFAILED: +// OperationResult results<>; +// default: +// void; +// } // // =========================================================================== -xdr.struct("ChangeTrustOp", [ - ["line", xdr.lookup("Asset")], - ["limit", xdr.lookup("Int64")], -]); +xdr.union("TransactionResultResult", { + switchOn: xdr.lookup("TransactionResultCode"), + switchName: "code", + switches: [ + ["txSuccess", "results"], + ["txFailed", "results"], + ], + arms: { + results: xdr.varArray(xdr.lookup("OperationResult"), 2147483647), + }, + defaultArm: xdr.void(), +}); // === xdr source ============================================================ // -// union switch (AssetType type) +// union switch (int v) // { -// // 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 +// case 0: +// void; // } // // =========================================================================== -xdr.union("AllowTrustOpAsset", { - switchOn: xdr.lookup("AssetType"), - switchName: "type", +xdr.union("TransactionResultExt", { + switchOn: xdr.int(), + switchName: "v", switches: [ - ["assetTypeCreditAlphanum4", "assetCode4"], - ["assetTypeCreditAlphanum12", "assetCode12"], + [0, xdr.void()], ], arms: { - assetCode4: xdr.opaque(4), - assetCode12: xdr.opaque(12), }, }); // === xdr source ============================================================ // -// struct AllowTrustOp +// struct TransactionResult // { -// 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]; +// int64 feeCharged; // actual fee charged for the transaction // -// // add other asset types here in the future +// union switch (TransactionResultCode code) +// { +// case txSUCCESS: +// case txFAILED: +// OperationResult results<>; +// default: +// void; // } -// asset; +// result; // -// bool authorize; +// // reserved for future use +// union switch (int v) +// { +// case 0: +// void; +// } +// ext; // }; // // =========================================================================== -xdr.struct("AllowTrustOp", [ - ["trustor", xdr.lookup("AccountId")], - ["asset", xdr.lookup("AllowTrustOpAsset")], - ["authorize", xdr.bool()], +xdr.struct("TransactionResult", [ + ["feeCharged", xdr.lookup("Int64")], + ["result", xdr.lookup("TransactionResultResult")], + ["ext", xdr.lookup("TransactionResultExt")], ]); // === xdr source ============================================================ // -// struct ManageDataOp +// typedef opaque Value<>; +// +// =========================================================================== +xdr.typedef("Value", xdr.varOpaque()); + +// === xdr source ============================================================ +// +// struct SCPBallot // { -// string64 dataName; -// DataValue* dataValue; // set to null to clear +// uint32 counter; // n +// Value value; // x // }; // // =========================================================================== -xdr.struct("ManageDataOp", [ - ["dataName", xdr.lookup("String64")], - ["dataValue", xdr.option(xdr.lookup("DataValue"))], +xdr.struct("ScpBallot", [ + ["counter", xdr.lookup("Uint32")], + ["value", xdr.lookup("Value")], ]); // === xdr source ============================================================ // -// union switch (OperationType type) +// enum SCPStatementType +// { +// SCP_ST_PREPARE = 0, +// SCP_ST_CONFIRM = 1, +// SCP_ST_EXTERNALIZE = 2, +// SCP_ST_NOMINATE = 3 +// }; +// +// =========================================================================== +xdr.enum("ScpStatementType", { + scpStPrepare: 0, + scpStConfirm: 1, + scpStExternalize: 2, + scpStNominate: 3, +}); + +// === xdr source ============================================================ +// +// struct SCPNomination +// { +// Hash quorumSetHash; // D +// Value votes<>; // X +// Value accepted<>; // Y +// }; +// +// =========================================================================== +xdr.struct("ScpNomination", [ + ["quorumSetHash", xdr.lookup("Hash")], + ["votes", xdr.varArray(xdr.lookup("Value"), 2147483647)], + ["accepted", xdr.varArray(xdr.lookup("Value"), 2147483647)], +]); + +// === xdr source ============================================================ +// +// struct +// { +// Hash quorumSetHash; // D +// SCPBallot ballot; // b +// SCPBallot* prepared; // p +// SCPBallot* preparedPrime; // p' +// uint32 nC; // c.n +// uint32 nH; // h.n +// } +// +// =========================================================================== +xdr.struct("ScpStatementPrepare", [ + ["quorumSetHash", xdr.lookup("Hash")], + ["ballot", xdr.lookup("ScpBallot")], + ["prepared", xdr.option(xdr.lookup("ScpBallot"))], + ["preparedPrime", xdr.option(xdr.lookup("ScpBallot"))], + ["nC", xdr.lookup("Uint32")], + ["nH", xdr.lookup("Uint32")], +]); + +// === xdr source ============================================================ +// +// struct +// { +// SCPBallot ballot; // b +// uint32 nPrepared; // p.n +// uint32 nCommit; // c.n +// uint32 nH; // h.n +// Hash quorumSetHash; // D +// } +// +// =========================================================================== +xdr.struct("ScpStatementConfirm", [ + ["ballot", xdr.lookup("ScpBallot")], + ["nPrepared", xdr.lookup("Uint32")], + ["nCommit", xdr.lookup("Uint32")], + ["nH", xdr.lookup("Uint32")], + ["quorumSetHash", xdr.lookup("Hash")], +]); + +// === xdr source ============================================================ +// +// struct +// { +// SCPBallot commit; // c +// uint32 nH; // h.n +// Hash commitQuorumSetHash; // D used before EXTERNALIZE +// } +// +// =========================================================================== +xdr.struct("ScpStatementExternalize", [ + ["commit", xdr.lookup("ScpBallot")], + ["nH", xdr.lookup("Uint32")], + ["commitQuorumSetHash", xdr.lookup("Hash")], +]); + +// === xdr source ============================================================ +// +// union switch (SCPStatementType 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; +// case SCP_ST_PREPARE: +// struct +// { +// Hash quorumSetHash; // D +// SCPBallot ballot; // b +// SCPBallot* prepared; // p +// SCPBallot* preparedPrime; // p' +// uint32 nC; // c.n +// uint32 nH; // h.n +// } prepare; +// case SCP_ST_CONFIRM: +// struct +// { +// SCPBallot ballot; // b +// uint32 nPrepared; // p.n +// uint32 nCommit; // c.n +// uint32 nH; // h.n +// Hash quorumSetHash; // D +// } confirm; +// case SCP_ST_EXTERNALIZE: +// struct +// { +// SCPBallot commit; // c +// uint32 nH; // h.n +// Hash commitQuorumSetHash; // D used before EXTERNALIZE +// } externalize; +// case SCP_ST_NOMINATE: +// SCPNomination nominate; // } // // =========================================================================== -xdr.union("OperationBody", { - switchOn: xdr.lookup("OperationType"), +xdr.union("ScpStatementPledges", { + switchOn: xdr.lookup("ScpStatementType"), switchName: "type", switches: [ - ["createAccount", "createAccountOp"], - ["payment", "paymentOp"], - ["pathPayment", "pathPaymentOp"], - ["manageOffer", "manageOfferOp"], - ["createPassiveOffer", "createPassiveOfferOp"], - ["setOption", "setOptionsOp"], - ["changeTrust", "changeTrustOp"], - ["allowTrust", "allowTrustOp"], - ["accountMerge", "destination"], - ["inflation", xdr.void()], - ["manageDatum", "manageDataOp"], + ["scpStPrepare", "prepare"], + ["scpStConfirm", "confirm"], + ["scpStExternalize", "externalize"], + ["scpStNominate", "nominate"], ], arms: { - createAccountOp: xdr.lookup("CreateAccountOp"), - paymentOp: xdr.lookup("PaymentOp"), - pathPaymentOp: xdr.lookup("PathPaymentOp"), - manageOfferOp: xdr.lookup("ManageOfferOp"), - createPassiveOfferOp: xdr.lookup("CreatePassiveOfferOp"), - setOptionsOp: xdr.lookup("SetOptionsOp"), - changeTrustOp: xdr.lookup("ChangeTrustOp"), - allowTrustOp: xdr.lookup("AllowTrustOp"), - destination: xdr.lookup("AccountId"), - manageDataOp: xdr.lookup("ManageDataOp"), + prepare: xdr.lookup("ScpStatementPrepare"), + confirm: xdr.lookup("ScpStatementConfirm"), + externalize: xdr.lookup("ScpStatementExternalize"), + nominate: xdr.lookup("ScpNomination"), }, }); // === xdr source ============================================================ // -// struct Operation +// struct SCPStatement // { -// // sourceAccount is the account used to run the operation -// // if not set, the runtime defaults to "sourceAccount" specified at -// // the transaction level -// AccountID* sourceAccount; +// NodeID nodeID; // v +// uint64 slotIndex; // i // -// union switch (OperationType type) +// union switch (SCPStatementType 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; +// case SCP_ST_PREPARE: +// struct +// { +// Hash quorumSetHash; // D +// SCPBallot ballot; // b +// SCPBallot* prepared; // p +// SCPBallot* preparedPrime; // p' +// uint32 nC; // c.n +// uint32 nH; // h.n +// } prepare; +// case SCP_ST_CONFIRM: +// struct +// { +// SCPBallot ballot; // b +// uint32 nPrepared; // p.n +// uint32 nCommit; // c.n +// uint32 nH; // h.n +// Hash quorumSetHash; // D +// } confirm; +// case SCP_ST_EXTERNALIZE: +// struct +// { +// SCPBallot commit; // c +// uint32 nH; // h.n +// Hash commitQuorumSetHash; // D used before EXTERNALIZE +// } externalize; +// case SCP_ST_NOMINATE: +// SCPNomination nominate; // } -// body; +// pledges; // }; // // =========================================================================== -xdr.struct("Operation", [ - ["sourceAccount", xdr.option(xdr.lookup("AccountId"))], - ["body", xdr.lookup("OperationBody")], +xdr.struct("ScpStatement", [ + ["nodeId", xdr.lookup("NodeId")], + ["slotIndex", xdr.lookup("Uint64")], + ["pledges", xdr.lookup("ScpStatementPledges")], ]); // === xdr source ============================================================ // -// enum MemoType -// { -// MEMO_NONE = 0, -// MEMO_TEXT = 1, -// MEMO_ID = 2, -// MEMO_HASH = 3, -// MEMO_RETURN = 4 -// }; -// -// =========================================================================== -xdr.enum("MemoType", { - memoNone: 0, - memoText: 1, - memoId: 2, - memoHash: 3, - memoReturn: 4, -}); - -// === xdr source ============================================================ -// -// union Memo switch (MemoType type) +// struct SCPEnvelope // { -// 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 +// SCPStatement statement; +// Signature signature; // }; // // =========================================================================== -xdr.union("Memo", { - switchOn: xdr.lookup("MemoType"), - switchName: "type", - switches: [ - ["memoNone", xdr.void()], - ["memoText", "text"], - ["memoId", "id"], - ["memoHash", "hash"], - ["memoReturn", "retHash"], - ], - arms: { - text: xdr.string(28), - id: xdr.lookup("Uint64"), - hash: xdr.lookup("Hash"), - retHash: xdr.lookup("Hash"), - }, -}); +xdr.struct("ScpEnvelope", [ + ["statement", xdr.lookup("ScpStatement")], + ["signature", xdr.lookup("Signature")], +]); // === xdr source ============================================================ // -// struct TimeBounds +// struct SCPQuorumSet // { -// uint64 minTime; -// uint64 maxTime; // 0 here means no maxTime +// uint32 threshold; +// PublicKey validators<>; +// SCPQuorumSet innerSets<>; // }; // // =========================================================================== -xdr.struct("TimeBounds", [ - ["minTime", xdr.lookup("Uint64")], - ["maxTime", xdr.lookup("Uint64")], +xdr.struct("ScpQuorumSet", [ + ["threshold", xdr.lookup("Uint32")], + ["validators", xdr.varArray(xdr.lookup("PublicKey"), 2147483647)], + ["innerSets", xdr.varArray(xdr.lookup("ScpQuorumSet"), 2147483647)], ]); // === xdr source ============================================================ // -// union switch (int v) -// { -// case 0: -// void; -// } +// typedef PublicKey AccountID; // // =========================================================================== -xdr.union("TransactionExt", { - switchOn: xdr.int(), - switchName: "v", - switches: [ - [0, xdr.void()], - ], - arms: { - }, -}); +xdr.typedef("AccountId", xdr.lookup("PublicKey")); // === 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; -// }; +// typedef opaque Thresholds[4]; // // =========================================================================== -xdr.struct("Transaction", [ - ["sourceAccount", xdr.lookup("AccountId")], - ["fee", xdr.lookup("Uint32")], - ["seqNum", xdr.lookup("SequenceNumber")], - ["timeBounds", xdr.option(xdr.lookup("TimeBounds"))], - ["memo", xdr.lookup("Memo")], - ["operations", xdr.varArray(xdr.lookup("Operation"), 100)], - ["ext", xdr.lookup("TransactionExt")], -]); +xdr.typedef("Thresholds", xdr.opaque(4)); // === xdr source ============================================================ // -// union switch (EnvelopeType type) -// { -// case ENVELOPE_TYPE_TX: -// Transaction tx; -// /* All other values of type are invalid */ -// } +// typedef string string32<32>; // // =========================================================================== -xdr.union("TransactionSignaturePayloadTaggedTransaction", { - switchOn: xdr.lookup("EnvelopeType"), - switchName: "type", - switches: [ - ["envelopeTypeTx", "tx"], - ], - arms: { - tx: xdr.lookup("Transaction"), - }, -}); +xdr.typedef("String32", xdr.string(32)); // === xdr source ============================================================ // -// struct TransactionSignaturePayload { -// Hash networkId; -// union switch (EnvelopeType type) -// { -// case ENVELOPE_TYPE_TX: -// Transaction tx; -// /* All other values of type are invalid */ -// } taggedTransaction; -// }; +// typedef string string64<64>; // // =========================================================================== -xdr.struct("TransactionSignaturePayload", [ - ["networkId", xdr.lookup("Hash")], - ["taggedTransaction", xdr.lookup("TransactionSignaturePayloadTaggedTransaction")], -]); +xdr.typedef("String64", xdr.string(64)); // === xdr source ============================================================ // -// struct TransactionEnvelope -// { -// Transaction tx; -// /* Each decorated signature is a signature over the SHA256 hash of -// * a TransactionSignaturePayload */ -// DecoratedSignature -// signatures<20>; -// }; +// typedef uint64 SequenceNumber; // // =========================================================================== -xdr.struct("TransactionEnvelope", [ - ["tx", xdr.lookup("Transaction")], - ["signatures", xdr.varArray(xdr.lookup("DecoratedSignature"), 20)], -]); +xdr.typedef("SequenceNumber", xdr.lookup("Uint64")); // === xdr source ============================================================ // -// 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; -// }; +// typedef opaque DataValue<64>; // // =========================================================================== -xdr.struct("ClaimOfferAtom", [ - ["sellerId", xdr.lookup("AccountId")], - ["offerId", xdr.lookup("Uint64")], - ["assetSold", xdr.lookup("Asset")], - ["amountSold", xdr.lookup("Int64")], - ["assetBought", xdr.lookup("Asset")], - ["amountBought", xdr.lookup("Int64")], -]); +xdr.typedef("DataValue", xdr.varOpaque(64)); // === xdr source ============================================================ // -// enum CreateAccountResultCode +// enum AssetType // { -// // 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 +// ASSET_TYPE_NATIVE = 0, +// ASSET_TYPE_CREDIT_ALPHANUM4 = 1, +// ASSET_TYPE_CREDIT_ALPHANUM12 = 2 // }; // // =========================================================================== -xdr.enum("CreateAccountResultCode", { - createAccountSuccess: 0, - createAccountMalformed: -1, - createAccountUnderfunded: -2, - createAccountLowReserve: -3, - createAccountAlreadyExist: -4, +xdr.enum("AssetType", { + assetTypeNative: 0, + assetTypeCreditAlphanum4: 1, + assetTypeCreditAlphanum12: 2, }); // === xdr source ============================================================ // -// union CreateAccountResult switch (CreateAccountResultCode code) -// { -// case CREATE_ACCOUNT_SUCCESS: -// void; -// default: -// void; -// }; +// struct +// { +// opaque assetCode[4]; // 1 to 4 characters +// AccountID issuer; +// } // // =========================================================================== -xdr.union("CreateAccountResult", { - switchOn: xdr.lookup("CreateAccountResultCode"), - switchName: "code", - switches: [ - ["createAccountSuccess", xdr.void()], - ], - arms: { - }, - defaultArm: xdr.void(), -}); +xdr.struct("AssetAlphaNum4", [ + ["assetCode", xdr.opaque(4)], + ["issuer", xdr.lookup("AccountId")], +]); // === 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 -// PAYMENT_NO_ISSUER = -9 // missing issuer on asset -// }; +// struct +// { +// opaque assetCode[12]; // 5 to 12 characters +// AccountID issuer; +// } // // =========================================================================== -xdr.enum("PaymentResultCode", { - paymentSuccess: 0, - paymentMalformed: -1, - paymentUnderfunded: -2, - paymentSrcNoTrust: -3, - paymentSrcNotAuthorized: -4, - paymentNoDestination: -5, - paymentNoTrust: -6, - paymentNotAuthorized: -7, - paymentLineFull: -8, - paymentNoIssuer: -9, -}); +xdr.struct("AssetAlphaNum12", [ + ["assetCode", xdr.opaque(12)], + ["issuer", xdr.lookup("AccountId")], +]); // === xdr source ============================================================ // -// union PaymentResult switch (PaymentResultCode code) +// union Asset switch (AssetType type) // { -// case PAYMENT_SUCCESS: -// void; -// default: +// case ASSET_TYPE_NATIVE: // Not credit // void; +// +// case ASSET_TYPE_CREDIT_ALPHANUM4: +// struct +// { +// opaque assetCode[4]; // 1 to 4 characters +// AccountID issuer; +// } alphaNum4; +// +// case ASSET_TYPE_CREDIT_ALPHANUM12: +// struct +// { +// opaque assetCode[12]; // 5 to 12 characters +// AccountID issuer; +// } alphaNum12; +// +// // add other asset types here in the future // }; // // =========================================================================== -xdr.union("PaymentResult", { - switchOn: xdr.lookup("PaymentResultCode"), - switchName: "code", +xdr.union("Asset", { + switchOn: xdr.lookup("AssetType"), + switchName: "type", switches: [ - ["paymentSuccess", xdr.void()], + ["assetTypeNative", xdr.void()], + ["assetTypeCreditAlphanum4", "alphaNum4"], + ["assetTypeCreditAlphanum12", "alphaNum12"], ], arms: { + alphaNum4: xdr.lookup("AssetAlphaNum4"), + alphaNum12: xdr.lookup("AssetAlphaNum12"), }, - defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// enum PathPaymentResultCode +// struct Price // { -// // 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 +// int32 n; // numerator +// int32 d; // denominator // }; // // =========================================================================== -xdr.enum("PathPaymentResultCode", { - pathPaymentSuccess: 0, - pathPaymentMalformed: -1, - pathPaymentUnderfunded: -2, - pathPaymentSrcNoTrust: -3, - pathPaymentSrcNotAuthorized: -4, - pathPaymentNoDestination: -5, - pathPaymentNoTrust: -6, - pathPaymentNotAuthorized: -7, - pathPaymentLineFull: -8, - pathPaymentNoIssuer: -9, - pathPaymentTooFewOffer: -10, - pathPaymentOfferCrossSelf: -11, - pathPaymentOverSendmax: -12, -}); +xdr.struct("Price", [ + ["n", xdr.lookup("Int32")], + ["d", xdr.lookup("Int32")], +]); // === xdr source ============================================================ // -// struct SimplePaymentResult +// enum ThresholdIndexes // { -// AccountID destination; -// Asset asset; -// int64 amount; +// THRESHOLD_MASTER_WEIGHT = 0, +// THRESHOLD_LOW = 1, +// THRESHOLD_MED = 2, +// THRESHOLD_HIGH = 3 // }; // // =========================================================================== -xdr.struct("SimplePaymentResult", [ - ["destination", xdr.lookup("AccountId")], - ["asset", xdr.lookup("Asset")], - ["amount", xdr.lookup("Int64")], -]); +xdr.enum("ThresholdIndices", { + thresholdMasterWeight: 0, + thresholdLow: 1, + thresholdMed: 2, + thresholdHigh: 3, +}); // === xdr source ============================================================ // -// struct -// { -// ClaimOfferAtom offers<>; -// SimplePaymentResult last; -// } +// enum LedgerEntryType +// { +// ACCOUNT = 0, +// TRUSTLINE = 1, +// OFFER = 2, +// DATA = 3 +// }; // // =========================================================================== -xdr.struct("PathPaymentResultSuccess", [ - ["offers", xdr.varArray(xdr.lookup("ClaimOfferAtom"), 2147483647)], - ["last", xdr.lookup("SimplePaymentResult")], -]); +xdr.enum("LedgerEntryType", { + account: 0, + trustline: 1, + offer: 2, + datum: 3, +}); // === xdr source ============================================================ // -// union PathPaymentResult switch (PathPaymentResultCode code) +// struct Signer // { -// 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; +// SignerKey key; +// uint32 weight; // really only need 1byte // }; // // =========================================================================== -xdr.union("PathPaymentResult", { - switchOn: xdr.lookup("PathPaymentResultCode"), - switchName: "code", - switches: [ - ["pathPaymentSuccess", "success"], - ["pathPaymentNoIssuer", "noIssuer"], - ], - arms: { - success: xdr.lookup("PathPaymentResultSuccess"), - noIssuer: xdr.lookup("Asset"), - }, - defaultArm: xdr.void(), -}); +xdr.struct("Signer", [ + ["key", xdr.lookup("SignerKey")], + ["weight", xdr.lookup("Uint32")], +]); // === 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 -// 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 +// enum AccountFlags +// { // masks for each flag // -// MANAGE_OFFER_LOW_RESERVE = -12 // not enough funds to create a new Offer +// // 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 // }; // // =========================================================================== -xdr.enum("ManageOfferResultCode", { - manageOfferSuccess: 0, - manageOfferMalformed: -1, - manageOfferSellNoTrust: -2, - manageOfferBuyNoTrust: -3, - manageOfferSellNotAuthorized: -4, - manageOfferBuyNotAuthorized: -5, - manageOfferLineFull: -6, - manageOfferUnderfunded: -7, - manageOfferCrossSelf: -8, - manageOfferSellNoIssuer: -9, - manageOfferBuyNoIssuer: -10, - manageOfferNotFound: -11, - manageOfferLowReserve: -12, +xdr.enum("AccountFlags", { + authRequiredFlag: 1, + authRevocableFlag: 2, + authImmutableFlag: 4, }); // === xdr source ============================================================ // -// enum ManageOfferEffect -// { -// MANAGE_OFFER_CREATED = 0, -// MANAGE_OFFER_UPDATED = 1, -// MANAGE_OFFER_DELETED = 2 -// }; +// const MASK_ACCOUNT_FLAGS = 0x7; // // =========================================================================== -xdr.enum("ManageOfferEffect", { - manageOfferCreated: 0, - manageOfferUpdated: 1, - manageOfferDeleted: 2, -}); +xdr.const("MASK_ACCOUNT_FLAGS", 0x7); // === xdr source ============================================================ // -// union switch (ManageOfferEffect effect) +// union switch (int v) // { -// case MANAGE_OFFER_CREATED: -// case MANAGE_OFFER_UPDATED: -// OfferEntry offer; -// default: +// case 0: // void; // } // // =========================================================================== -xdr.union("ManageOfferSuccessResultOffer", { - switchOn: xdr.lookup("ManageOfferEffect"), - switchName: "effect", +xdr.union("AccountEntryExt", { + switchOn: xdr.int(), + switchName: "v", switches: [ - ["manageOfferCreated", "offer"], - ["manageOfferUpdated", "offer"], + [0, xdr.void()], ], arms: { - offer: xdr.lookup("OfferEntry"), }, - defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// struct ManageOfferSuccessResult +// struct AccountEntry // { -// // offers that got claimed while creating this offer -// ClaimOfferAtom offersClaimed<>; +// 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 // -// union switch (ManageOfferEffect effect) +// 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 MANAGE_OFFER_CREATED: -// case MANAGE_OFFER_UPDATED: -// OfferEntry offer; -// default: +// case 0: // void; // } -// offer; +// ext; // }; // // =========================================================================== -xdr.struct("ManageOfferSuccessResult", [ - ["offersClaimed", xdr.varArray(xdr.lookup("ClaimOfferAtom"), 2147483647)], - ["offer", xdr.lookup("ManageOfferSuccessResultOffer")], +xdr.struct("AccountEntry", [ + ["accountId", xdr.lookup("AccountId")], + ["balance", xdr.lookup("Int64")], + ["seqNum", xdr.lookup("SequenceNumber")], + ["numSubEntries", xdr.lookup("Uint32")], + ["inflationDest", xdr.option(xdr.lookup("AccountId"))], + ["flags", xdr.lookup("Uint32")], + ["homeDomain", xdr.lookup("String32")], + ["thresholds", xdr.lookup("Thresholds")], + ["signers", xdr.varArray(xdr.lookup("Signer"), 20)], + ["ext", xdr.lookup("AccountEntryExt")], ]); // === xdr source ============================================================ // -// union ManageOfferResult switch (ManageOfferResultCode code) +// enum TrustLineFlags // { -// case MANAGE_OFFER_SUCCESS: -// ManageOfferSuccessResult success; -// default: -// void; +// // issuer has authorized account to perform transactions with its credit +// AUTHORIZED_FLAG = 1 // }; // // =========================================================================== -xdr.union("ManageOfferResult", { - switchOn: xdr.lookup("ManageOfferResultCode"), - switchName: "code", +xdr.enum("TrustLineFlags", { + authorizedFlag: 1, +}); + +// === xdr source ============================================================ +// +// const MASK_TRUSTLINE_FLAGS = 1; +// +// =========================================================================== +xdr.const("MASK_TRUSTLINE_FLAGS", 1); + +// === xdr source ============================================================ +// +// union switch (int v) +// { +// case 0: +// void; +// } +// +// =========================================================================== +xdr.union("TrustLineEntryExt", { + switchOn: xdr.int(), + switchName: "v", switches: [ - ["manageOfferSuccess", "success"], + [0, xdr.void()], ], arms: { - success: xdr.lookup("ManageOfferSuccessResult"), }, - defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// enum SetOptionsResultCode +// struct TrustLineEntry // { -// // 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 +// 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.enum("SetOptionsResultCode", { - setOptionsSuccess: 0, - setOptionsLowReserve: -1, - setOptionsTooManySigner: -2, - setOptionsBadFlag: -3, - setOptionsInvalidInflation: -4, - setOptionsCantChange: -5, - setOptionsUnknownFlag: -6, - setOptionsThresholdOutOfRange: -7, - setOptionsBadSigner: -8, - setOptionsInvalidHomeDomain: -9, -}); +xdr.struct("TrustLineEntry", [ + ["accountId", xdr.lookup("AccountId")], + ["asset", xdr.lookup("Asset")], + ["balance", xdr.lookup("Int64")], + ["limit", xdr.lookup("Int64")], + ["flags", xdr.lookup("Uint32")], + ["ext", xdr.lookup("TrustLineEntryExt")], +]); // === xdr source ============================================================ // -// union SetOptionsResult switch (SetOptionsResultCode code) +// enum OfferEntryFlags // { -// case SET_OPTIONS_SUCCESS: -// void; -// default: -// void; +// // issuer has authorized account to perform transactions with its credit +// PASSIVE_FLAG = 1 // }; // -// =========================================================================== -xdr.union("SetOptionsResult", { - switchOn: xdr.lookup("SetOptionsResultCode"), - switchName: "code", - switches: [ - ["setOptionsSuccess", xdr.void()], - ], - arms: { - }, - defaultArm: xdr.void(), +// =========================================================================== +xdr.enum("OfferEntryFlags", { + passiveFlag: 1, }); // === 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 -// // cannot create with a limit of 0 -// CHANGE_TRUST_LOW_RESERVE = -4, // not enough funds to create a new trust line, -// CHANGE_TRUST_SELF_NOT_ALLOWED = -5 // trusting self is not allowed -// }; +// const MASK_OFFERENTRY_FLAGS = 1; // // =========================================================================== -xdr.enum("ChangeTrustResultCode", { - changeTrustSuccess: 0, - changeTrustMalformed: -1, - changeTrustNoIssuer: -2, - changeTrustInvalidLimit: -3, - changeTrustLowReserve: -4, - changeTrustSelfNotAllowed: -5, -}); +xdr.const("MASK_OFFERENTRY_FLAGS", 1); // === xdr source ============================================================ // -// union ChangeTrustResult switch (ChangeTrustResultCode code) -// { -// case CHANGE_TRUST_SUCCESS: -// void; -// default: -// void; -// }; +// union switch (int v) +// { +// case 0: +// void; +// } // // =========================================================================== -xdr.union("ChangeTrustResult", { - switchOn: xdr.lookup("ChangeTrustResultCode"), - switchName: "code", +xdr.union("OfferEntryExt", { + switchOn: xdr.int(), + switchName: "v", switches: [ - ["changeTrustSuccess", xdr.void()], + [0, xdr.void()], ], arms: { }, - defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// enum AllowTrustResultCode +// struct OfferEntry // { -// // 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, -// ALLOW_TRUST_SELF_NOT_ALLOWED = -5 // trusting self is not allowed +// 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.enum("AllowTrustResultCode", { - allowTrustSuccess: 0, - allowTrustMalformed: -1, - allowTrustNoTrustLine: -2, - allowTrustTrustNotRequired: -3, - allowTrustCantRevoke: -4, - allowTrustSelfNotAllowed: -5, -}); +xdr.struct("OfferEntry", [ + ["sellerId", xdr.lookup("AccountId")], + ["offerId", xdr.lookup("Uint64")], + ["selling", xdr.lookup("Asset")], + ["buying", xdr.lookup("Asset")], + ["amount", xdr.lookup("Int64")], + ["price", xdr.lookup("Price")], + ["flags", xdr.lookup("Uint32")], + ["ext", xdr.lookup("OfferEntryExt")], +]); // === xdr source ============================================================ // -// union AllowTrustResult switch (AllowTrustResultCode code) -// { -// case ALLOW_TRUST_SUCCESS: -// void; -// default: -// void; -// }; +// union switch (int v) +// { +// case 0: +// void; +// } // // =========================================================================== -xdr.union("AllowTrustResult", { - switchOn: xdr.lookup("AllowTrustResultCode"), - switchName: "code", +xdr.union("DataEntryExt", { + switchOn: xdr.int(), + switchName: "v", switches: [ - ["allowTrustSuccess", xdr.void()], + [0, xdr.void()], ], arms: { }, - defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// enum AccountMergeResultCode +// struct DataEntry // { -// // 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 +// AccountID accountID; // account this data belongs to +// string64 dataName; +// DataValue dataValue; +// +// // reserved for future use +// union switch (int v) +// { +// case 0: +// void; +// } +// ext; // }; // // =========================================================================== -xdr.enum("AccountMergeResultCode", { - accountMergeSuccess: 0, - accountMergeMalformed: -1, - accountMergeNoAccount: -2, - accountMergeImmutableSet: -3, - accountMergeHasSubEntry: -4, +xdr.struct("DataEntry", [ + ["accountId", xdr.lookup("AccountId")], + ["dataName", xdr.lookup("String64")], + ["dataValue", xdr.lookup("DataValue")], + ["ext", xdr.lookup("DataEntryExt")], +]); + +// === xdr source ============================================================ +// +// union switch (LedgerEntryType type) +// { +// case ACCOUNT: +// AccountEntry account; +// case TRUSTLINE: +// TrustLineEntry trustLine; +// case OFFER: +// OfferEntry offer; +// case DATA: +// DataEntry data; +// } +// +// =========================================================================== +xdr.union("LedgerEntryData", { + switchOn: xdr.lookup("LedgerEntryType"), + switchName: "type", + switches: [ + ["account", "account"], + ["trustline", "trustLine"], + ["offer", "offer"], + ["datum", "data"], + ], + arms: { + account: xdr.lookup("AccountEntry"), + trustLine: xdr.lookup("TrustLineEntry"), + offer: xdr.lookup("OfferEntry"), + data: xdr.lookup("DataEntry"), + }, }); // === xdr source ============================================================ // -// union AccountMergeResult switch (AccountMergeResultCode code) -// { -// case ACCOUNT_MERGE_SUCCESS: -// int64 sourceAccountBalance; // how much got transfered from source account -// default: -// void; -// }; +// union switch (int v) +// { +// case 0: +// void; +// } // // =========================================================================== -xdr.union("AccountMergeResult", { - switchOn: xdr.lookup("AccountMergeResultCode"), - switchName: "code", +xdr.union("LedgerEntryExt", { + switchOn: xdr.int(), + switchName: "v", switches: [ - ["accountMergeSuccess", "sourceAccountBalance"], + [0, xdr.void()], ], arms: { - sourceAccountBalance: xdr.lookup("Int64"), }, - defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// enum InflationResultCode +// struct LedgerEntry // { -// // codes considered as "success" for the operation -// INFLATION_SUCCESS = 0, -// // codes considered as "failure" for the operation -// INFLATION_NOT_TIME = -1 +// 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; // }; // // =========================================================================== -xdr.enum("InflationResultCode", { - inflationSuccess: 0, - inflationNotTime: -1, -}); +xdr.struct("LedgerEntry", [ + ["lastModifiedLedgerSeq", xdr.lookup("Uint32")], + ["data", xdr.lookup("LedgerEntryData")], + ["ext", xdr.lookup("LedgerEntryExt")], +]); // === xdr source ============================================================ // -// struct InflationPayout // or use PaymentResultAtom to limit types? +// enum EnvelopeType // { -// AccountID destination; -// int64 amount; +// ENVELOPE_TYPE_SCP = 1, +// ENVELOPE_TYPE_TX = 2, +// ENVELOPE_TYPE_AUTH = 3 // }; // // =========================================================================== -xdr.struct("InflationPayout", [ - ["destination", xdr.lookup("AccountId")], - ["amount", xdr.lookup("Int64")], -]); +xdr.enum("EnvelopeType", { + envelopeTypeScp: 1, + envelopeTypeTx: 2, + envelopeTypeAuth: 3, +}); + +// === xdr source ============================================================ +// +// typedef opaque UpgradeType<128>; +// +// =========================================================================== +xdr.typedef("UpgradeType", xdr.varOpaque(128)); // === xdr source ============================================================ // -// union InflationResult switch (InflationResultCode code) -// { -// case INFLATION_SUCCESS: -// InflationPayout payouts<>; -// default: -// void; -// }; +// union switch (int v) +// { +// case 0: +// void; +// } // // =========================================================================== -xdr.union("InflationResult", { - switchOn: xdr.lookup("InflationResultCode"), - switchName: "code", +xdr.union("StellarValueExt", { + switchOn: xdr.int(), + switchName: "v", switches: [ - ["inflationSuccess", "payouts"], + [0, xdr.void()], ], arms: { - payouts: xdr.varArray(xdr.lookup("InflationPayout"), 2147483647), }, - defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// enum ManageDataResultCode +// struct StellarValue // { -// // 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 +// 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 +// // max size is dictated by number of upgrade types (+ room for future) +// UpgradeType upgrades<6>; +// +// // reserved for future use +// union switch (int v) +// { +// case 0: +// void; +// } +// ext; // }; // // =========================================================================== -xdr.enum("ManageDataResultCode", { - manageDataSuccess: 0, - manageDataNotSupportedYet: -1, - manageDataNameNotFound: -2, - manageDataLowReserve: -3, - manageDataInvalidName: -4, -}); +xdr.struct("StellarValue", [ + ["txSetHash", xdr.lookup("Hash")], + ["closeTime", xdr.lookup("Uint64")], + ["upgrades", xdr.varArray(xdr.lookup("UpgradeType"), 6)], + ["ext", xdr.lookup("StellarValueExt")], +]); // === xdr source ============================================================ // -// union ManageDataResult switch (ManageDataResultCode code) -// { -// case MANAGE_DATA_SUCCESS: -// void; -// default: -// void; -// }; +// union switch (int v) +// { +// case 0: +// void; +// } // // =========================================================================== -xdr.union("ManageDataResult", { - switchOn: xdr.lookup("ManageDataResultCode"), - switchName: "code", +xdr.union("LedgerHeaderExt", { + switchOn: xdr.int(), + switchName: "v", switches: [ - ["manageDataSuccess", xdr.void()], + [0, xdr.void()], ], arms: { }, - defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// enum OperationResultCode +// struct LedgerHeader // { -// opINNER = 0, // inner object result is valid +// 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 // -// opBAD_AUTH = -1, // too few valid signatures / wrong network -// opNO_ACCOUNT = -2 // source account was not found +// uint32 ledgerSeq; // sequence number of this ledger +// +// int64 totalCoins; // total number of stroops in existence. +// // 10,000,000 stroops in 1 XLM +// +// 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 +// +// uint32 maxTxSetSize; // maximum size a transaction set can be +// +// 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.enum("OperationResultCode", { - opInner: 0, - opBadAuth: -1, - opNoAccount: -2, -}); +xdr.struct("LedgerHeader", [ + ["ledgerVersion", xdr.lookup("Uint32")], + ["previousLedgerHash", xdr.lookup("Hash")], + ["scpValue", xdr.lookup("StellarValue")], + ["txSetResultHash", xdr.lookup("Hash")], + ["bucketListHash", xdr.lookup("Hash")], + ["ledgerSeq", xdr.lookup("Uint32")], + ["totalCoins", xdr.lookup("Int64")], + ["feePool", xdr.lookup("Int64")], + ["inflationSeq", xdr.lookup("Uint32")], + ["idPool", xdr.lookup("Uint64")], + ["baseFee", xdr.lookup("Uint32")], + ["baseReserve", xdr.lookup("Uint32")], + ["maxTxSetSize", xdr.lookup("Uint32")], + ["skipList", xdr.array(xdr.lookup("Hash"), 4)], + ["ext", xdr.lookup("LedgerHeaderExt")], +]); // === 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; -// case MANAGE_DATA: -// ManageDataResult manageDataResult; -// } +// enum LedgerUpgradeType +// { +// LEDGER_UPGRADE_VERSION = 1, +// LEDGER_UPGRADE_BASE_FEE = 2, +// LEDGER_UPGRADE_MAX_TX_SET_SIZE = 3, +// LEDGER_UPGRADE_BASE_RESERVE = 4 +// }; // // =========================================================================== -xdr.union("OperationResultTr", { - switchOn: xdr.lookup("OperationType"), - switchName: "type", - switches: [ - ["createAccount", "createAccountResult"], - ["payment", "paymentResult"], - ["pathPayment", "pathPaymentResult"], - ["manageOffer", "manageOfferResult"], - ["createPassiveOffer", "createPassiveOfferResult"], - ["setOption", "setOptionsResult"], - ["changeTrust", "changeTrustResult"], - ["allowTrust", "allowTrustResult"], - ["accountMerge", "accountMergeResult"], - ["inflation", "inflationResult"], - ["manageDatum", "manageDataResult"], - ], - arms: { - createAccountResult: xdr.lookup("CreateAccountResult"), - paymentResult: xdr.lookup("PaymentResult"), - pathPaymentResult: xdr.lookup("PathPaymentResult"), - manageOfferResult: xdr.lookup("ManageOfferResult"), - createPassiveOfferResult: xdr.lookup("ManageOfferResult"), - setOptionsResult: xdr.lookup("SetOptionsResult"), - changeTrustResult: xdr.lookup("ChangeTrustResult"), - allowTrustResult: xdr.lookup("AllowTrustResult"), - accountMergeResult: xdr.lookup("AccountMergeResult"), - inflationResult: xdr.lookup("InflationResult"), - manageDataResult: xdr.lookup("ManageDataResult"), - }, +xdr.enum("LedgerUpgradeType", { + ledgerUpgradeVersion: 1, + ledgerUpgradeBaseFee: 2, + ledgerUpgradeMaxTxSetSize: 3, + ledgerUpgradeBaseReserve: 4, }); // === xdr source ============================================================ // -// union OperationResult switch (OperationResultCode code) +// union LedgerUpgrade switch (LedgerUpgradeType type) // { -// 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; +// case LEDGER_UPGRADE_VERSION: +// uint32 newLedgerVersion; // update ledgerVersion +// case LEDGER_UPGRADE_BASE_FEE: +// uint32 newBaseFee; // update baseFee +// case LEDGER_UPGRADE_MAX_TX_SET_SIZE: +// uint32 newMaxTxSetSize; // update maxTxSetSize +// case LEDGER_UPGRADE_BASE_RESERVE: +// uint32 newBaseReserve; // update baseReserve // }; // // =========================================================================== -xdr.union("OperationResult", { - switchOn: xdr.lookup("OperationResultCode"), - switchName: "code", +xdr.union("LedgerUpgrade", { + switchOn: xdr.lookup("LedgerUpgradeType"), + switchName: "type", switches: [ - ["opInner", "tr"], + ["ledgerUpgradeVersion", "newLedgerVersion"], + ["ledgerUpgradeBaseFee", "newBaseFee"], + ["ledgerUpgradeMaxTxSetSize", "newMaxTxSetSize"], + ["ledgerUpgradeBaseReserve", "newBaseReserve"], ], arms: { - tr: xdr.lookup("OperationResultTr"), + newLedgerVersion: xdr.lookup("Uint32"), + newBaseFee: xdr.lookup("Uint32"), + newMaxTxSetSize: xdr.lookup("Uint32"), + newBaseReserve: xdr.lookup("Uint32"), }, - defaultArm: xdr.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, // 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 +// { +// AccountID accountID; +// } // // =========================================================================== -xdr.enum("TransactionResultCode", { - txSuccess: 0, - txFailed: -1, - txTooEarly: -2, - txTooLate: -3, - txMissingOperation: -4, - txBadSeq: -5, - txBadAuth: -6, - txInsufficientBalance: -7, - txNoAccount: -8, - txInsufficientFee: -9, - txBadAuthExtra: -10, - txInternalError: -11, -}); +xdr.struct("LedgerKeyAccount", [ + ["accountId", xdr.lookup("AccountId")], +]); // === xdr source ============================================================ // -// union switch (TransactionResultCode code) +// struct // { -// case txSUCCESS: -// case txFAILED: -// OperationResult results<>; -// default: -// void; +// AccountID accountID; +// Asset asset; // } // // =========================================================================== -xdr.union("TransactionResultResult", { - switchOn: xdr.lookup("TransactionResultCode"), - switchName: "code", - switches: [ - ["txSuccess", "results"], - ["txFailed", "results"], - ], - arms: { - results: xdr.varArray(xdr.lookup("OperationResult"), 2147483647), - }, - defaultArm: xdr.void(), -}); +xdr.struct("LedgerKeyTrustLine", [ + ["accountId", xdr.lookup("AccountId")], + ["asset", xdr.lookup("Asset")], +]); // === xdr source ============================================================ // -// union switch (int v) +// struct // { -// case 0: -// void; +// AccountID sellerID; +// uint64 offerID; // } // // =========================================================================== -xdr.union("TransactionResultExt", { - switchOn: xdr.int(), - switchName: "v", - switches: [ - [0, xdr.void()], - ], - arms: { - }, -}); +xdr.struct("LedgerKeyOffer", [ + ["sellerId", xdr.lookup("AccountId")], + ["offerId", xdr.lookup("Uint64")], +]); // === xdr source ============================================================ // -// struct TransactionResult +// struct +// { +// AccountID accountID; +// string64 dataName; +// } +// +// =========================================================================== +xdr.struct("LedgerKeyData", [ + ["accountId", xdr.lookup("AccountId")], + ["dataName", xdr.lookup("String64")], +]); + +// === xdr source ============================================================ +// +// union LedgerKey switch (LedgerEntryType type) // { -// int64 feeCharged; // actual fee charged for the transaction +// case ACCOUNT: +// struct +// { +// AccountID accountID; +// } account; // -// union switch (TransactionResultCode code) +// case TRUSTLINE: +// struct // { -// case txSUCCESS: -// case txFAILED: -// OperationResult results<>; -// default: -// void; -// } -// result; +// AccountID accountID; +// Asset asset; +// } trustLine; // -// // reserved for future use -// union switch (int v) +// case OFFER: +// struct // { -// case 0: -// void; -// } -// ext; +// AccountID sellerID; +// uint64 offerID; +// } offer; +// +// case DATA: +// struct +// { +// AccountID accountID; +// string64 dataName; +// } data; // }; // // =========================================================================== -xdr.struct("TransactionResult", [ - ["feeCharged", xdr.lookup("Int64")], - ["result", xdr.lookup("TransactionResultResult")], - ["ext", xdr.lookup("TransactionResultExt")], -]); +xdr.union("LedgerKey", { + switchOn: xdr.lookup("LedgerEntryType"), + switchName: "type", + switches: [ + ["account", "account"], + ["trustline", "trustLine"], + ["offer", "offer"], + ["datum", "data"], + ], + arms: { + account: xdr.lookup("LedgerKeyAccount"), + trustLine: xdr.lookup("LedgerKeyTrustLine"), + offer: xdr.lookup("LedgerKeyOffer"), + data: xdr.lookup("LedgerKeyData"), + }, +}); // === xdr source ============================================================ // -// typedef opaque Hash[32]; +// enum BucketEntryType +// { +// LIVEENTRY = 0, +// DEADENTRY = 1 +// }; // // =========================================================================== -xdr.typedef("Hash", xdr.opaque(32)); +xdr.enum("BucketEntryType", { + liveentry: 0, + deadentry: 1, +}); // === xdr source ============================================================ // -// typedef opaque uint256[32]; +// union BucketEntry switch (BucketEntryType type) +// { +// case LIVEENTRY: +// LedgerEntry liveEntry; +// +// case DEADENTRY: +// LedgerKey deadEntry; +// }; // // =========================================================================== -xdr.typedef("Uint256", xdr.opaque(32)); +xdr.union("BucketEntry", { + switchOn: xdr.lookup("BucketEntryType"), + switchName: "type", + switches: [ + ["liveentry", "liveEntry"], + ["deadentry", "deadEntry"], + ], + arms: { + liveEntry: xdr.lookup("LedgerEntry"), + deadEntry: xdr.lookup("LedgerKey"), + }, +}); // === xdr source ============================================================ // -// typedef unsigned int uint32; +// struct TransactionSet +// { +// Hash previousLedgerHash; +// TransactionEnvelope txs<>; +// }; // // =========================================================================== -xdr.typedef("Uint32", xdr.uint()); +xdr.struct("TransactionSet", [ + ["previousLedgerHash", xdr.lookup("Hash")], + ["txes", xdr.varArray(xdr.lookup("TransactionEnvelope"), 2147483647)], +]); // === xdr source ============================================================ // -// typedef int int32; +// struct TransactionResultPair +// { +// Hash transactionHash; +// TransactionResult result; // result for the transaction +// }; // // =========================================================================== -xdr.typedef("Int32", xdr.int()); +xdr.struct("TransactionResultPair", [ + ["transactionHash", xdr.lookup("Hash")], + ["result", xdr.lookup("TransactionResult")], +]); // === xdr source ============================================================ // -// typedef unsigned hyper uint64; +// struct TransactionResultSet +// { +// TransactionResultPair results<>; +// }; // // =========================================================================== -xdr.typedef("Uint64", xdr.uhyper()); +xdr.struct("TransactionResultSet", [ + ["results", xdr.varArray(xdr.lookup("TransactionResultPair"), 2147483647)], +]); // === xdr source ============================================================ // -// typedef hyper int64; +// union switch (int v) +// { +// case 0: +// void; +// } // // =========================================================================== -xdr.typedef("Int64", xdr.hyper()); +xdr.union("TransactionHistoryEntryExt", { + switchOn: xdr.int(), + switchName: "v", + switches: [ + [0, xdr.void()], + ], + arms: { + }, +}); // === xdr source ============================================================ // -// enum CryptoKeyType +// struct TransactionHistoryEntry // { -// KEY_TYPE_ED25519 = 0, -// KEY_TYPE_PRE_AUTH_TX = 1, -// KEY_TYPE_HASH_X = 2 +// uint32 ledgerSeq; +// TransactionSet txSet; +// +// // reserved for future use +// union switch (int v) +// { +// case 0: +// void; +// } +// ext; // }; // // =========================================================================== -xdr.enum("CryptoKeyType", { - keyTypeEd25519: 0, - keyTypePreAuthTx: 1, - keyTypeHashX: 2, -}); +xdr.struct("TransactionHistoryEntry", [ + ["ledgerSeq", xdr.lookup("Uint32")], + ["txSet", xdr.lookup("TransactionSet")], + ["ext", xdr.lookup("TransactionHistoryEntryExt")], +]); // === xdr source ============================================================ // -// enum PublicKeyType -// { -// PUBLIC_KEY_TYPE_ED25519 = KEY_TYPE_ED25519 -// }; +// union switch (int v) +// { +// case 0: +// void; +// } // // =========================================================================== -xdr.enum("PublicKeyType", { - publicKeyTypeEd25519: 0, +xdr.union("TransactionHistoryResultEntryExt", { + switchOn: xdr.int(), + switchName: "v", + switches: [ + [0, xdr.void()], + ], + arms: { + }, }); // === xdr source ============================================================ // -// enum SignerKeyType +// struct TransactionHistoryResultEntry // { -// SIGNER_KEY_TYPE_ED25519 = KEY_TYPE_ED25519, -// SIGNER_KEY_TYPE_PRE_AUTH_TX = KEY_TYPE_PRE_AUTH_TX, -// SIGNER_KEY_TYPE_HASH_X = KEY_TYPE_HASH_X +// uint32 ledgerSeq; +// TransactionResultSet txResultSet; +// +// // reserved for future use +// union switch (int v) +// { +// case 0: +// void; +// } +// ext; // }; // // =========================================================================== -xdr.enum("SignerKeyType", { - signerKeyTypeEd25519: 0, - signerKeyTypePreAuthTx: 1, - signerKeyTypeHashX: 2, -}); +xdr.struct("TransactionHistoryResultEntry", [ + ["ledgerSeq", xdr.lookup("Uint32")], + ["txResultSet", xdr.lookup("TransactionResultSet")], + ["ext", xdr.lookup("TransactionHistoryResultEntryExt")], +]); // === xdr source ============================================================ // -// union PublicKey switch (PublicKeyType type) -// { -// case PUBLIC_KEY_TYPE_ED25519: -// uint256 ed25519; -// }; +// union switch (int v) +// { +// case 0: +// void; +// } // // =========================================================================== -xdr.union("PublicKey", { - switchOn: xdr.lookup("PublicKeyType"), - switchName: "type", +xdr.union("LedgerHeaderHistoryEntryExt", { + switchOn: xdr.int(), + switchName: "v", switches: [ - ["publicKeyTypeEd25519", "ed25519"], + [0, xdr.void()], ], arms: { - ed25519: xdr.lookup("Uint256"), }, }); // === xdr source ============================================================ // -// union SignerKey switch (SignerKeyType type) +// struct LedgerHeaderHistoryEntry // { -// case SIGNER_KEY_TYPE_ED25519: -// uint256 ed25519; -// case SIGNER_KEY_TYPE_PRE_AUTH_TX: -// /* Hash of Transaction structure */ -// uint256 preAuthTx; -// case SIGNER_KEY_TYPE_HASH_X: -// /* Hash of random 256 bit preimage X */ -// uint256 hashX; +// Hash hash; +// LedgerHeader header; +// +// // reserved for future use +// union switch (int v) +// { +// case 0: +// void; +// } +// ext; // }; // // =========================================================================== -xdr.union("SignerKey", { - switchOn: xdr.lookup("SignerKeyType"), - switchName: "type", - switches: [ - ["signerKeyTypeEd25519", "ed25519"], - ["signerKeyTypePreAuthTx", "preAuthTx"], - ["signerKeyTypeHashX", "hashX"], - ], - arms: { - ed25519: xdr.lookup("Uint256"), - preAuthTx: xdr.lookup("Uint256"), - hashX: xdr.lookup("Uint256"), - }, -}); +xdr.struct("LedgerHeaderHistoryEntry", [ + ["hash", xdr.lookup("Hash")], + ["header", xdr.lookup("LedgerHeader")], + ["ext", xdr.lookup("LedgerHeaderHistoryEntryExt")], +]); // === xdr source ============================================================ // -// typedef opaque Signature<64>; +// struct LedgerSCPMessages +// { +// uint32 ledgerSeq; +// SCPEnvelope messages<>; +// }; // // =========================================================================== -xdr.typedef("Signature", xdr.varOpaque(64)); +xdr.struct("LedgerScpMessages", [ + ["ledgerSeq", xdr.lookup("Uint32")], + ["messages", xdr.varArray(xdr.lookup("ScpEnvelope"), 2147483647)], +]); // === xdr source ============================================================ // -// typedef opaque SignatureHint[4]; +// struct SCPHistoryEntryV0 +// { +// SCPQuorumSet quorumSets<>; // additional quorum sets used by ledgerMessages +// LedgerSCPMessages ledgerMessages; +// }; // // =========================================================================== -xdr.typedef("SignatureHint", xdr.opaque(4)); +xdr.struct("ScpHistoryEntryV0", [ + ["quorumSets", xdr.varArray(xdr.lookup("ScpQuorumSet"), 2147483647)], + ["ledgerMessages", xdr.lookup("LedgerScpMessages")], +]); // === xdr source ============================================================ // -// typedef PublicKey NodeID; +// union SCPHistoryEntry switch (int v) +// { +// case 0: +// SCPHistoryEntryV0 v0; +// }; // // =========================================================================== -xdr.typedef("NodeId", xdr.lookup("PublicKey")); +xdr.union("ScpHistoryEntry", { + switchOn: xdr.int(), + switchName: "v", + switches: [ + [0, "v0"], + ], + arms: { + v0: xdr.lookup("ScpHistoryEntryV0"), + }, +}); // === xdr source ============================================================ // -// struct Curve25519Secret +// enum LedgerEntryChangeType // { -// opaque key[32]; +// 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 +// LEDGER_ENTRY_STATE = 3 // value of the entry // }; // // =========================================================================== -xdr.struct("Curve25519Secret", [ - ["key", xdr.opaque(32)], -]); +xdr.enum("LedgerEntryChangeType", { + ledgerEntryCreated: 0, + ledgerEntryUpdated: 1, + ledgerEntryRemoved: 2, + ledgerEntryState: 3, +}); // === xdr source ============================================================ // -// struct Curve25519Public +// union LedgerEntryChange switch (LedgerEntryChangeType type) // { -// opaque key[32]; +// case LEDGER_ENTRY_CREATED: +// LedgerEntry created; +// case LEDGER_ENTRY_UPDATED: +// LedgerEntry updated; +// case LEDGER_ENTRY_REMOVED: +// LedgerKey removed; +// case LEDGER_ENTRY_STATE: +// LedgerEntry state; // }; // // =========================================================================== -xdr.struct("Curve25519Public", [ - ["key", xdr.opaque(32)], -]); +xdr.union("LedgerEntryChange", { + switchOn: xdr.lookup("LedgerEntryChangeType"), + switchName: "type", + switches: [ + ["ledgerEntryCreated", "created"], + ["ledgerEntryUpdated", "updated"], + ["ledgerEntryRemoved", "removed"], + ["ledgerEntryState", "state"], + ], + arms: { + created: xdr.lookup("LedgerEntry"), + updated: xdr.lookup("LedgerEntry"), + removed: xdr.lookup("LedgerKey"), + state: xdr.lookup("LedgerEntry"), + }, +}); // === xdr source ============================================================ // -// struct HmacSha256Key -// { -// opaque key[32]; -// }; +// typedef LedgerEntryChange LedgerEntryChanges<>; // // =========================================================================== -xdr.struct("HmacSha256Key", [ - ["key", xdr.opaque(32)], -]); +xdr.typedef("LedgerEntryChanges", xdr.varArray(xdr.lookup("LedgerEntryChange"), 2147483647)); // === xdr source ============================================================ // -// struct HmacSha256Mac +// struct OperationMeta // { -// opaque mac[32]; +// LedgerEntryChanges changes; // }; // // =========================================================================== -xdr.struct("HmacSha256Mac", [ - ["mac", xdr.opaque(32)], +xdr.struct("OperationMeta", [ + ["changes", xdr.lookup("LedgerEntryChanges")], ]); // === xdr source ============================================================ // -// union switch (int v) -// { -// case 0: -// void; -// } +// union TransactionMeta switch (int v) +// { +// case 0: +// OperationMeta operations<>; +// }; // // =========================================================================== -xdr.union("FederationResponseExt", { +xdr.union("TransactionMeta", { switchOn: xdr.int(), switchName: "v", switches: [ - [0, xdr.void()], + [0, "operations"], ], arms: { + operations: xdr.varArray(xdr.lookup("OperationMeta"), 2147483647), }, }); -// === xdr source ============================================================ -// -// struct FederationResponse -// { -// -// string64 stellarAddress; // Stellar uses string32 for domain name, using double for the federation name -// AccountID accountID; -// Memo memo; -// -// // reserved for future use -// union switch (int v) -// { -// case 0: -// void; -// } -// ext; -// }; -// -// =========================================================================== -xdr.struct("FederationResponse", [ - ["stellarAddress", xdr.lookup("String64")], - ["accountId", xdr.lookup("AccountId")], - ["memo", xdr.lookup("Memo")], - ["ext", xdr.lookup("FederationResponseExt")], -]); - }); export default types; diff --git a/xdr/Stellar-federation.x b/xdr/Stellar-federation.x index c9136fd23..14ba3402a 100644 --- a/xdr/Stellar-federation.x +++ b/xdr/Stellar-federation.x @@ -1,8 +1,8 @@ -// Copyright 2015 Stellar Development Foundation and contributors. Licensed +// Copyright 2018 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" +%#include "xdr/Stellar-transaction.h" namespace stellar { diff --git a/xdr/Stellar-ledger-entries.x b/xdr/Stellar-ledger-entries.x index bcd37516e..c2969c1f6 100644 --- a/xdr/Stellar-ledger-entries.x +++ b/xdr/Stellar-ledger-entries.x @@ -88,6 +88,9 @@ enum AccountFlags 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 @@ -136,6 +139,10 @@ enum TrustLineFlags AUTHORIZED_FLAG = 1 }; + +// mask for all trustline flags +const MASK_TRUSTLINE_FLAGS = 1; + struct TrustLineEntry { AccountID accountID; // account this trustline belongs to @@ -161,6 +168,9 @@ enum OfferEntryFlags 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. diff --git a/xdr/Stellar-ledger.x b/xdr/Stellar-ledger.x index 157a6d8b3..6556ed360 100644 --- a/xdr/Stellar-ledger.x +++ b/xdr/Stellar-ledger.x @@ -2,6 +2,7 @@ // 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-SCP.h" %#include "xdr/Stellar-transaction.h" namespace stellar @@ -82,7 +83,8 @@ enum LedgerUpgradeType { LEDGER_UPGRADE_VERSION = 1, LEDGER_UPGRADE_BASE_FEE = 2, - LEDGER_UPGRADE_MAX_TX_SET_SIZE = 3 + LEDGER_UPGRADE_MAX_TX_SET_SIZE = 3, + LEDGER_UPGRADE_BASE_RESERVE = 4 }; union LedgerUpgrade switch (LedgerUpgradeType type) @@ -93,6 +95,8 @@ case LEDGER_UPGRADE_BASE_FEE: uint32 newBaseFee; // update baseFee case LEDGER_UPGRADE_MAX_TX_SET_SIZE: uint32 newMaxTxSetSize; // update maxTxSetSize +case LEDGER_UPGRADE_BASE_RESERVE: + uint32 newBaseReserve; // update baseReserve }; /* Entries used to define the bucket list */ From 8ca8bb031b09b74773db0509c79490e8600207c3 Mon Sep 17 00:00:00 2001 From: Helmuth Breitenfellner Date: Sat, 24 Feb 2018 22:43:23 +0100 Subject: [PATCH 3/3] First version of federation response object --- src/federation_response.js | 144 ++++++++++++++++++++++++++ src/index.js | 1 + test/unit/federation_response_test.js | 67 ++++++++++++ 3 files changed, 212 insertions(+) create mode 100644 src/federation_response.js create mode 100644 test/unit/federation_response_test.js diff --git a/src/federation_response.js b/src/federation_response.js new file mode 100644 index 000000000..0479692c8 --- /dev/null +++ b/src/federation_response.js @@ -0,0 +1,144 @@ +import {default as xdr} from "./generated/stellar-xdr_generated"; +import clone from "lodash/clone"; +import isString from 'lodash/isString'; +import {hash} from "./hashing"; +import {StrKey} from "./strkey"; +import {Memo} from "./memo"; + +/** + * `FederationResponse` represents response from a federation server. + * + * @param {string} stellarAddress address in the form of `user*domain` + * @param {string} accountId ID of the account (ex. `GB3KJPLFUYN5VL6R3GU3EGCGVCKFDSD7BEDX42HWG5BWFKB3KQGJJRMA`) + * @param {Memo} memo memo to be used for the stellar address + * @see [Federation concept](https://www.stellar.org/developers/guides/concepts/federation.html) + * @class FederationResponse + */ +export class FederationResponse { + constructor(stellarAddress, accountId, memo) { + if (!StrKey.isValidEd25519PublicKey(accountId)) { + throw new Error('accountId is invalid'); + } + if (memo === undefined) { + memo = Memo.none(); + } + else { + let memo2 = new Memo(memo.type, memo.value); + } + FederationResponse._validateStellarAddressValue(stellarAddress); + this._stellarAddress = stellarAddress; + this._accountId = accountId; + this._memo = memo; + } + + /** + * Contains the stellar address in the form `user*domain` + */ + get stellarAddress() { + return clone(this._stellarAddress); + } + + set stellarAddress(stellarAddress) { + throw new Error("FederationResponse is immutable"); + } + + /** + * Contains the account ID (ex. `GB3KJPLFUYN5VL6R3GU3EGCGVCKFDSD7BEDX42HWG5BWFKB3KQGJJRMA`) + */ + get accountId() { + return clone(this._accountId); + } + + set accountId(accountId) { + throw new Error("FederationResponse is immutable"); + } + + /** + * Contains the memo to be used for this stellar address + */ + get memo() { + return clone(this._memo); + } + + set memo(memo) { + throw new Error("FederationResponse is immutable"); + } + + static _validateStellarAddressValue(value) { + let error = new Error("Expects a stellar address like user*domain. Got " + value); + + if (!isString(value)) { + throw error; + } + + if (Buffer.byteLength(value, "utf8") > 64) { + throw new Error("Stellar Address should be <= 64 bytes. Got " + Buffer.byteLength(value, "utf8")); + } + + let parts = value.split("*"); + if (parts.length != 2) { + throw error; + } + + if (Buffer.byteLength(parts[1], "utf8") > 32) { + throw new Error("`domain` part of address should be <= 32 bytes. Got " + Buffer.byteLength(parts[1], "utf8")); + } + } + + /** + * Returns XDR federation response object. + * @returns {xdr.FederationResponse} + */ + toXDRObject() { + let rawKey = StrKey.decodeEd25519PublicKey(this._accountId); + return new xdr.FederationResponse({ + stellarAddress: this._stellarAddress, + accountId: xdr.AccountId.publicKeyTypeEd25519(rawKey), + memo: this._memo.toXDRObject(), + ext: new xdr.FederationResponseExt(0) + }); + } + + /** + * Returns {@link FederationResponse} from XDR federation response object. + * @param {xdr.FederationResponse} + * @returns {FederationResponse} + */ + static fromXDRObject(object) { + let memo = Memo.fromXDRObject(object.memo()); + let rawKey = object.accountId().ed25519(); + return new FederationResponse( + object.stellarAddress(), + StrKey.encodeEd25519PublicKey(rawKey), + memo + ); + } + + /** + * Returns a hash for this federation response, suitable for signing. + * @returns {Buffer} + */ + hash() { + return hash(this.toXDRObject().toXDR()); + } + + /** + * Signs the federation response with the given {@link Keypair}. + * @param {Keypair} keypair Keypair of signer + * @returns {Buffer} + */ + sign(keypair) { + let txHash = this.hash(); + return keypair.sign(txHash); + } + + /** + * Verifies the federation response with the given {@link Keypair}. + * @param {Keypair} keypair Keypair (public key is enough) to verify + * @param {Buffer} signature signature to compare with + * @returns {boolean} + */ + verify(keypair, signature) { + return keypair.verify(this.hash(), signature); + } +} diff --git a/src/index.js b/src/index.js index 49aa5c6b8..2dae7a312 100644 --- a/src/index.js +++ b/src/index.js @@ -14,5 +14,6 @@ export * from "./memo"; export {Account} from "./account"; export {Network, Networks} from "./network"; export {StrKey} from "./strkey"; +export {FederationResponse} from "./federation_response"; export default module.exports; diff --git a/test/unit/federation_response_test.js b/test/unit/federation_response_test.js new file mode 100644 index 000000000..a6f2fa410 --- /dev/null +++ b/test/unit/federation_response_test.js @@ -0,0 +1,67 @@ + +describe("FederationResponse.constructor()", function() { + it("throws error when address is invalid", function() { + expect(() => new StellarBase.FederationResponse( + "test", + "GB3KJPLFUYN5VL6R3GU3EGCGVCKFDSD7BEDX42HWG5BWFKB3KQGJJRMA") + ).to.throw(/Expects a stellar address/); + }); + it("throws error when accountid is invalid", function() { + expect(() => new StellarBase.FederationResponse( + "hugo*example.com", + "GINVALIDINVALIDINVALID") + ).to.throw(/accountId is invalid/); + }); +}); + +describe("FederationResponse.stellarAddress", function() { + it("returns a value for a correct argument", function() { + let fedResp = new StellarBase.FederationResponse( + "hugo*example.com", + "GB3KJPLFUYN5VL6R3GU3EGCGVCKFDSD7BEDX42HWG5BWFKB3KQGJJRMA" + ); + expect(fedResp.stellarAddress).to.be.equal('hugo*example.com'); + }); + + it("converts to/from xdr object", function() { + let origFedResp = new StellarBase.FederationResponse( + "hugo*example.com", + "GB3KJPLFUYN5VL6R3GU3EGCGVCKFDSD7BEDX42HWG5BWFKB3KQGJJRMA" + ); + let fedResp = origFedResp.toXDRObject(); + expect(fedResp.stellarAddress()).to.be.equal('hugo*example.com'); + + let baseFedResp = StellarBase.FederationResponse.fromXDRObject(fedResp); + expect(baseFedResp.stellarAddress).to.be.equal('hugo*example.com'); + expect(baseFedResp.accountId).to.be.equal('GB3KJPLFUYN5VL6R3GU3EGCGVCKFDSD7BEDX42HWG5BWFKB3KQGJJRMA'); + }); + + it("can be signed", function() { + let secret = "SD7X7LEHBNMUIKQGKPARG5TDJNBHKC346OUARHGZL5ITC6IJPXHILY36"; + let kp = StellarBase.Keypair.fromSecret(secret); + let fedResp = new StellarBase.FederationResponse( + "hugo*example.com", + "GB3KJPLFUYN5VL6R3GU3EGCGVCKFDSD7BEDX42HWG5BWFKB3KQGJJRMA" + ); + expect(fedResp.sign(kp).toString("base64")).to.be.equal('p0UqwQrPaO5CePMIM4APezan5Zydw+S1kWuX+Tid0fEmrQqJAuXPQKxBQHA71ZF9t/JYd+2/eGUBtSuanm2zBg=='); + let fedResp2 = new StellarBase.FederationResponse( + "szil*example.com", + "GBV5QCPOXI2AU2TKEMDIYUTSXQ7GZ6JZVCKMXV7NDBE3TYKFOJ5KMTHZ", + StellarBase.Memo.text("test") + ); + let secret2 = "SBGHL762R7UWD6QDTVNUUFU445DVBS5UANADTL5W56OMW5R2YWUDKWJJ"; + let key2 = StellarBase.Keypair.fromSecret(secret2); + expect(fedResp2.sign(key2).toString("base64")).to.be.equal("YtvWDVlbye1CXK+oeESjR0HRvHiAAWaAnJnXochGQXi7i0MKKVHwyC03Q3fLMcW4iB9W/EWkqacZtCuVv3dLAQ=="); + }); + + it("can be verified", function() { + let pub = "GDFQVQCYYB7GKCGSCUSIQYXTPLV5YJ3XWDMWGQMDNM4EAXAL7LITIBQ7"; + let kp = StellarBase.Keypair.fromPublicKey(pub); + let fedResp = new StellarBase.FederationResponse( + "hugo*example.com", + "GB3KJPLFUYN5VL6R3GU3EGCGVCKFDSD7BEDX42HWG5BWFKB3KQGJJRMA" + ); + let signature = Buffer.from('p0UqwQrPaO5CePMIM4APezan5Zydw+S1kWuX+Tid0fEmrQqJAuXPQKxBQHA71ZF9t/JYd+2/eGUBtSuanm2zBg=='); + expect(fedResp.verify(kp, signature)).to.be.truthy; + }) +});