diff --git a/CHANGELOG.md b/CHANGELOG.md index 909e6b165..5c55ac1ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ As this project is pre 1.0, breaking changes may happen for minor version bumps. A breaking change will get clearly notified in this log. +## unreleased + +- Add Stellar Protocol 11 compatibility (breaking change) + - Rename `manage_offer` to `manage_sell_offer`. + - Rename `create_passive_offer` to `create_passive_sell_offer`. + - Add `manage_buy_offer`. + ## [v0.13.2](https://github.com/stellar/js-stellar-base/compare/v0.13.1...v0.13.2) - Bring DefinitelyTyped definitions into the repo for faster updating. diff --git a/Gemfile b/Gemfile index 72c1f81c2..df4f953fc 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source "https://rubygems.org" -gem 'xdrgen', git: 'git@github.com:stellar/xdrgen.git' +gem 'xdrgen', git: 'git@github.com:stellar/xdrgen.git', branch: 'enum-standard-type-discriminant' # gem "xdrgen", path: "../xdrgen" gem 'pry' gem 'octokit' gem 'netrc' -gem 'rake' \ No newline at end of file +gem 'rake' diff --git a/Gemfile.lock b/Gemfile.lock index d996b6389..6777cd100 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,7 @@ GIT remote: git@github.com:stellar/xdrgen.git - revision: c683684abb3cb2c8b8c3dc12dc7c6cc9bf1e3b60 + revision: 914c86ed6cee77e8e58883efe7cad4e0535b5ea0 + branch: enum-standard-type-discriminant specs: xdrgen (0.0.1) activesupport (~> 5) @@ -11,7 +12,7 @@ GIT GEM remote: https://rubygems.org/ specs: - activesupport (5.2.0) + activesupport (5.2.3) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) @@ -19,24 +20,24 @@ GEM addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) coderay (1.1.2) - concurrent-ruby (1.0.5) - faraday (0.15.0) + concurrent-ruby (1.1.5) + faraday (0.15.4) multipart-post (>= 1.2, < 3) - i18n (1.0.1) + i18n (1.6.0) concurrent-ruby (~> 1.0) memoist (0.11.0) - method_source (0.9.0) + method_source (0.9.2) minitest (5.11.3) multipart-post (2.0.0) netrc (0.11.0) - octokit (4.8.0) + octokit (4.14.0) sawyer (~> 0.8.0, >= 0.5.3) polyglot (0.3.5) - pry (0.11.3) + pry (0.12.2) coderay (~> 1.1.0) method_source (~> 0.9.0) - public_suffix (3.0.2) - rake (12.3.0) + public_suffix (3.0.3) + rake (12.3.2) sawyer (0.8.1) addressable (>= 2.3.5, < 2.6) faraday (~> 0.8, < 1.0) @@ -58,4 +59,4 @@ DEPENDENCIES xdrgen! BUNDLED WITH - 1.13.7 + 1.17.2 diff --git a/src/generated/stellar-xdr_generated.js b/src/generated/stellar-xdr_generated.js index 406398128..19cde5218 100644 --- a/src/generated/stellar-xdr_generated.js +++ b/src/generated/stellar-xdr_generated.js @@ -1,4 +1,4 @@ -// Automatically generated on 2018-10-16T17:42:19+02:00 +// Automatically generated on 2019-04-30T12:43:38-07:00 // DO NOT EDIT or your changes may be overwritten /* jshint maxstatements:2147483647 */ @@ -11,983 +11,835 @@ var types = XDR.config(xdr => { // === xdr source ============================================================ // -// enum ErrorCode -// { -// 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 -// }; +// typedef PublicKey AccountID; // // =========================================================================== -xdr.enum("ErrorCode", { - errMisc: 0, - errDatum: 1, - errConf: 2, - errAuth: 3, - errLoad: 4, -}); +xdr.typedef("AccountId", xdr.lookup("PublicKey")); // === xdr source ============================================================ // -// struct Error -// { -// ErrorCode code; -// string msg<100>; -// }; +// typedef opaque Thresholds[4]; // // =========================================================================== -xdr.struct("Error", [ - ["code", xdr.lookup("ErrorCode")], - ["msg", xdr.string(100)], -]); +xdr.typedef("Thresholds", xdr.opaque(4)); // === xdr source ============================================================ // -// struct AuthCert -// { -// Curve25519Public pubkey; -// uint64 expiration; -// Signature sig; -// }; +// typedef string string32<32>; // // =========================================================================== -xdr.struct("AuthCert", [ - ["pubkey", xdr.lookup("Curve25519Public")], - ["expiration", xdr.lookup("Uint64")], - ["sig", xdr.lookup("Signature")], -]); +xdr.typedef("String32", xdr.string(32)); // === xdr source ============================================================ // -// struct Hello -// { -// uint32 ledgerVersion; -// uint32 overlayVersion; -// uint32 overlayMinVersion; -// Hash networkID; -// string versionStr<100>; -// int listeningPort; -// NodeID peerID; -// AuthCert cert; -// uint256 nonce; -// }; +// typedef string string64<64>; // // =========================================================================== -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.typedef("String64", xdr.string(64)); // === xdr source ============================================================ // -// struct Auth -// { -// // Empty message, just to confirm -// // establishment of MAC keys. -// int unused; -// }; +// typedef int64 SequenceNumber; // // =========================================================================== -xdr.struct("Auth", [ - ["unused", xdr.int()], -]); +xdr.typedef("SequenceNumber", xdr.lookup("Int64")); // === xdr source ============================================================ // -// enum IPAddrType +// typedef uint64 TimePoint; +// +// =========================================================================== +xdr.typedef("TimePoint", xdr.lookup("Uint64")); + +// === xdr source ============================================================ +// +// typedef opaque DataValue<64>; +// +// =========================================================================== +xdr.typedef("DataValue", xdr.varOpaque(64)); + +// === xdr source ============================================================ +// +// typedef opaque AssetCode4[4]; +// +// =========================================================================== +xdr.typedef("AssetCode4", xdr.opaque(4)); + +// === xdr source ============================================================ +// +// typedef opaque AssetCode12[12]; +// +// =========================================================================== +xdr.typedef("AssetCode12", xdr.opaque(12)); + +// === xdr source ============================================================ +// +// enum AssetType // { -// IPv4 = 0, -// IPv6 = 1 +// ASSET_TYPE_NATIVE = 0, +// ASSET_TYPE_CREDIT_ALPHANUM4 = 1, +// ASSET_TYPE_CREDIT_ALPHANUM12 = 2 // }; // // =========================================================================== -xdr.enum("IpAddrType", { - iPv4: 0, - iPv6: 1, +xdr.enum("AssetType", { + assetTypeNative: 0, + assetTypeCreditAlphanum4: 1, + assetTypeCreditAlphanum12: 2, }); // === xdr source ============================================================ // -// union switch (IPAddrType type) +// struct // { -// case IPv4: -// opaque ipv4[4]; -// case IPv6: -// opaque ipv6[16]; +// AssetCode4 assetCode; +// AccountID issuer; // } // // =========================================================================== -xdr.union("PeerAddressIp", { - switchOn: xdr.lookup("IpAddrType"), +xdr.struct("AssetAlphaNum4", [ + ["assetCode", xdr.lookup("AssetCode4")], + ["issuer", xdr.lookup("AccountId")], +]); + +// === xdr source ============================================================ +// +// struct +// { +// AssetCode12 assetCode; +// AccountID issuer; +// } +// +// =========================================================================== +xdr.struct("AssetAlphaNum12", [ + ["assetCode", xdr.lookup("AssetCode12")], + ["issuer", xdr.lookup("AccountId")], +]); + +// === xdr source ============================================================ +// +// union Asset switch (AssetType type) +// { +// case ASSET_TYPE_NATIVE: // Not credit +// void; +// +// case ASSET_TYPE_CREDIT_ALPHANUM4: +// struct +// { +// AssetCode4 assetCode; +// AccountID issuer; +// } alphaNum4; +// +// case ASSET_TYPE_CREDIT_ALPHANUM12: +// struct +// { +// AssetCode12 assetCode; +// AccountID issuer; +// } alphaNum12; +// +// // add other asset types here in the future +// }; +// +// =========================================================================== +xdr.union("Asset", { + switchOn: xdr.lookup("AssetType"), switchName: "type", switches: [ - ["iPv4", "ipv4"], - ["iPv6", "ipv6"], + ["assetTypeNative", xdr.void()], + ["assetTypeCreditAlphanum4", "alphaNum4"], + ["assetTypeCreditAlphanum12", "alphaNum12"], ], arms: { - ipv4: xdr.opaque(4), - ipv6: xdr.opaque(16), + alphaNum4: xdr.lookup("AssetAlphaNum4"), + alphaNum12: xdr.lookup("AssetAlphaNum12"), }, }); // === xdr source ============================================================ // -// struct PeerAddress +// struct Price // { -// union switch (IPAddrType type) -// { -// case IPv4: -// opaque ipv4[4]; -// case IPv6: -// opaque ipv6[16]; -// } -// ip; -// uint32 port; -// uint32 numFailures; +// int32 n; // numerator +// int32 d; // denominator // }; // // =========================================================================== -xdr.struct("PeerAddress", [ - ["ip", xdr.lookup("PeerAddressIp")], - ["port", xdr.lookup("Uint32")], - ["numFailures", xdr.lookup("Uint32")], +xdr.struct("Price", [ + ["n", xdr.lookup("Int32")], + ["d", xdr.lookup("Int32")], ]); // === xdr source ============================================================ // -// enum MessageType +// struct Liabilities // { -// 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 +// int64 buying; +// int64 selling; // }; // // =========================================================================== -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.struct("Liabilities", [ + ["buying", xdr.lookup("Int64")], + ["selling", xdr.lookup("Int64")], +]); // === xdr source ============================================================ // -// struct DontHave +// enum ThresholdIndexes // { -// MessageType type; -// uint256 reqHash; +// THRESHOLD_MASTER_WEIGHT = 0, +// THRESHOLD_LOW = 1, +// THRESHOLD_MED = 2, +// THRESHOLD_HIGH = 3 // }; // // =========================================================================== -xdr.struct("DontHave", [ - ["type", xdr.lookup("MessageType")], - ["reqHash", xdr.lookup("Uint256")], -]); +xdr.enum("ThresholdIndices", { + thresholdMasterWeight: 0, + thresholdLow: 1, + thresholdMed: 2, + thresholdHigh: 3, +}); // === xdr source ============================================================ // -// union StellarMessage switch (MessageType type) +// enum LedgerEntryType // { -// 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<100>; -// -// 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", - 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"), 100), - 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 ============================================================ -// -// struct -// { -// uint64 sequence; -// StellarMessage message; -// HmacSha256Mac mac; -// } -// -// =========================================================================== -xdr.struct("AuthenticatedMessageV0", [ - ["sequence", xdr.lookup("Uint64")], - ["message", xdr.lookup("StellarMessage")], - ["mac", xdr.lookup("HmacSha256Mac")], -]); - -// === xdr source ============================================================ -// -// union AuthenticatedMessage switch (uint32 v) -// { -// case 0: -// struct -// { -// uint64 sequence; -// StellarMessage message; -// HmacSha256Mac mac; -// } v0; -// }; -// -// =========================================================================== -xdr.union("AuthenticatedMessage", { - switchOn: xdr.lookup("Uint32"), - switchName: "v", - switches: [ - [0, "v0"], - ], - arms: { - v0: xdr.lookup("AuthenticatedMessageV0"), - }, -}); - -// === xdr source ============================================================ -// -// typedef opaque Hash[32]; -// -// =========================================================================== -xdr.typedef("Hash", xdr.opaque(32)); - -// === xdr source ============================================================ -// -// typedef opaque uint256[32]; -// -// =========================================================================== -xdr.typedef("Uint256", xdr.opaque(32)); - -// === xdr source ============================================================ -// -// typedef unsigned int uint32; -// -// =========================================================================== -xdr.typedef("Uint32", xdr.uint()); - -// === xdr source ============================================================ -// -// typedef int int32; -// -// =========================================================================== -xdr.typedef("Int32", xdr.int()); - -// === xdr source ============================================================ -// -// typedef unsigned hyper uint64; -// -// =========================================================================== -xdr.typedef("Uint64", xdr.uhyper()); - -// === xdr source ============================================================ -// -// typedef hyper int64; -// -// =========================================================================== -xdr.typedef("Int64", xdr.hyper()); - -// === xdr source ============================================================ -// -// enum CryptoKeyType -// { -// KEY_TYPE_ED25519 = 0, -// KEY_TYPE_PRE_AUTH_TX = 1, -// KEY_TYPE_HASH_X = 2 -// }; -// -// =========================================================================== -xdr.enum("CryptoKeyType", { - keyTypeEd25519: 0, - keyTypePreAuthTx: 1, - keyTypeHashX: 2, -}); - -// === xdr source ============================================================ -// -// enum PublicKeyType -// { -// PUBLIC_KEY_TYPE_ED25519 = KEY_TYPE_ED25519 -// }; -// -// =========================================================================== -xdr.enum("PublicKeyType", { - publicKeyTypeEd25519: 0, -}); - -// === xdr source ============================================================ -// -// enum SignerKeyType -// { -// 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 +// ACCOUNT = 0, +// TRUSTLINE = 1, +// OFFER = 2, +// DATA = 3 // }; // // =========================================================================== -xdr.enum("SignerKeyType", { - signerKeyTypeEd25519: 0, - signerKeyTypePreAuthTx: 1, - signerKeyTypeHashX: 2, +xdr.enum("LedgerEntryType", { + account: 0, + trustline: 1, + offer: 2, + datum: 3, }); // === xdr source ============================================================ // -// union PublicKey switch (PublicKeyType type) +// struct Signer // { -// case PUBLIC_KEY_TYPE_ED25519: -// uint256 ed25519; +// SignerKey key; +// uint32 weight; // really only need 1 byte // }; // // =========================================================================== -xdr.union("PublicKey", { - switchOn: xdr.lookup("PublicKeyType"), - switchName: "type", - switches: [ - ["publicKeyTypeEd25519", "ed25519"], - ], - arms: { - ed25519: xdr.lookup("Uint256"), - }, -}); +xdr.struct("Signer", [ + ["key", xdr.lookup("SignerKey")], + ["weight", xdr.lookup("Uint32")], +]); // === xdr source ============================================================ // -// union SignerKey switch (SignerKeyType type) -// { -// case SIGNER_KEY_TYPE_ED25519: -// uint256 ed25519; -// case SIGNER_KEY_TYPE_PRE_AUTH_TX: -// /* SHA-256 Hash of TransactionSignaturePayload structure */ -// uint256 preAuthTx; -// case SIGNER_KEY_TYPE_HASH_X: -// /* Hash of random 256 bit preimage X */ -// uint256 hashX; +// 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 // }; // // =========================================================================== -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 ============================================================ -// -// typedef opaque Signature<64>; -// -// =========================================================================== -xdr.typedef("Signature", xdr.varOpaque(64)); - -// === xdr source ============================================================ -// -// typedef opaque SignatureHint[4]; -// -// =========================================================================== -xdr.typedef("SignatureHint", xdr.opaque(4)); - -// === xdr source ============================================================ -// -// typedef PublicKey NodeID; -// -// =========================================================================== -xdr.typedef("NodeId", xdr.lookup("PublicKey")); +xdr.enum("AccountFlags", { + authRequiredFlag: 1, + authRevocableFlag: 2, + authImmutableFlag: 4, +}); // === xdr source ============================================================ // -// struct Curve25519Secret -// { -// opaque key[32]; -// }; +// const MASK_ACCOUNT_FLAGS = 0x7; // // =========================================================================== -xdr.struct("Curve25519Secret", [ - ["key", xdr.opaque(32)], -]); +xdr.const("MASK_ACCOUNT_FLAGS", 0x7); // === xdr source ============================================================ // -// struct Curve25519Public -// { -// opaque key[32]; -// }; +// union switch (int v) +// { +// case 0: +// void; +// } // // =========================================================================== -xdr.struct("Curve25519Public", [ - ["key", xdr.opaque(32)], -]); +xdr.union("AccountEntryV1Ext", { + switchOn: xdr.int(), + switchName: "v", + switches: [ + [0, xdr.void()], + ], + arms: { + }, +}); // === xdr source ============================================================ // -// struct HmacSha256Key -// { -// opaque key[32]; -// }; +// struct +// { +// Liabilities liabilities; +// +// union switch (int v) +// { +// case 0: +// void; +// } +// ext; +// } // // =========================================================================== -xdr.struct("HmacSha256Key", [ - ["key", xdr.opaque(32)], +xdr.struct("AccountEntryV1", [ + ["liabilities", xdr.lookup("Liabilities")], + ["ext", xdr.lookup("AccountEntryV1Ext")], ]); // === xdr source ============================================================ // -// struct HmacSha256Mac -// { -// opaque mac[32]; -// }; +// union switch (int v) +// { +// case 0: +// void; +// case 1: +// struct +// { +// Liabilities liabilities; +// +// union switch (int v) +// { +// case 0: +// void; +// } +// ext; +// } v1; +// } // // =========================================================================== -xdr.struct("HmacSha256Mac", [ - ["mac", xdr.opaque(32)], -]); +xdr.union("AccountEntryExt", { + switchOn: xdr.int(), + switchName: "v", + switches: [ + [0, xdr.void()], + [1, "v1"], + ], + arms: { + v1: xdr.lookup("AccountEntryV1"), + }, +}); // === xdr source ============================================================ // -// struct DecoratedSignature +// struct AccountEntry // { -// SignatureHint hint; // last 4 bytes of the public key, used as a hint -// Signature signature; // actual signature +// 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; +// case 1: +// struct +// { +// Liabilities liabilities; +// +// union switch (int v) +// { +// case 0: +// void; +// } +// ext; +// } v1; +// } +// ext; // }; // // =========================================================================== -xdr.struct("DecoratedSignature", [ - ["hint", xdr.lookup("SignatureHint")], - ["signature", xdr.lookup("Signature")], +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 ============================================================ // -// enum OperationType +// enum TrustLineFlags // { -// 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, -// BUMP_SEQUENCE = 11 +// // issuer has authorized account to perform transactions with its credit +// AUTHORIZED_FLAG = 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, - bumpSequence: 11, +xdr.enum("TrustLineFlags", { + authorizedFlag: 1, }); // === xdr source ============================================================ // -// struct CreateAccountOp -// { -// AccountID destination; // account to create -// int64 startingBalance; // amount they end up with -// }; +// const MASK_TRUSTLINE_FLAGS = 1; // // =========================================================================== -xdr.struct("CreateAccountOp", [ - ["destination", xdr.lookup("AccountId")], - ["startingBalance", xdr.lookup("Int64")], -]); +xdr.const("MASK_TRUSTLINE_FLAGS", 1); // === xdr source ============================================================ // -// struct PaymentOp -// { -// AccountID destination; // recipient of the payment -// Asset asset; // what they end up with -// int64 amount; // amount they end up with -// }; +// union switch (int v) +// { +// case 0: +// void; +// } // // =========================================================================== -xdr.struct("PaymentOp", [ - ["destination", xdr.lookup("AccountId")], - ["asset", xdr.lookup("Asset")], - ["amount", xdr.lookup("Int64")], -]); +xdr.union("TrustLineEntryV1Ext", { + switchOn: xdr.int(), + switchName: "v", + switches: [ + [0, xdr.void()], + ], + arms: { + }, +}); // === xdr source ============================================================ // -// struct PathPaymentOp -// { -// Asset sendAsset; // asset we pay with -// int64 sendMax; // the maximum amount of sendAsset to -// // send (excluding fees). -// // The operation will fail if can't be met -// -// AccountID destination; // recipient of the payment -// Asset destAsset; // what they end up with -// int64 destAmount; // amount they end up with +// struct +// { +// Liabilities liabilities; // -// Asset path<5>; // additional hops it must go through to get there -// }; +// union switch (int v) +// { +// case 0: +// void; +// } +// ext; +// } // // =========================================================================== -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.struct("TrustLineEntryV1", [ + ["liabilities", xdr.lookup("Liabilities")], + ["ext", xdr.lookup("TrustLineEntryV1Ext")], ]); // === xdr source ============================================================ // -// struct ManageOfferOp -// { -// Asset selling; -// Asset buying; -// int64 amount; // amount being sold. if set to 0, delete the offer -// Price price; // price of thing being sold in terms of what you are buying +// union switch (int v) +// { +// case 0: +// void; +// case 1: +// struct +// { +// Liabilities liabilities; // -// // 0=create a new offer, otherwise edit an existing offer -// uint64 offerID; -// }; +// union switch (int v) +// { +// case 0: +// void; +// } +// ext; +// } v1; +// } // // =========================================================================== -xdr.struct("ManageOfferOp", [ - ["selling", xdr.lookup("Asset")], - ["buying", xdr.lookup("Asset")], - ["amount", xdr.lookup("Int64")], - ["price", xdr.lookup("Price")], - ["offerId", xdr.lookup("Uint64")], -]); +xdr.union("TrustLineEntryExt", { + switchOn: xdr.int(), + switchName: "v", + switches: [ + [0, xdr.void()], + [1, "v1"], + ], + arms: { + v1: xdr.lookup("TrustLineEntryV1"), + }, +}); // === xdr source ============================================================ // -// struct CreatePassiveOfferOp +// struct TrustLineEntry // { -// 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 +// 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; +// case 1: +// struct +// { +// Liabilities liabilities; +// +// union switch (int v) +// { +// case 0: +// void; +// } +// ext; +// } v1; +// } +// ext; // }; // // =========================================================================== -xdr.struct("CreatePassiveOfferOp", [ - ["selling", xdr.lookup("Asset")], - ["buying", xdr.lookup("Asset")], - ["amount", xdr.lookup("Int64")], - ["price", xdr.lookup("Price")], +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 ============================================================ // -// struct SetOptionsOp +// enum OfferEntryFlags // { -// AccountID* inflationDest; // sets the inflation destination -// -// uint32* clearFlags; // which flags to clear -// uint32* setFlags; // which flags to set -// -// // account threshold manipulation -// uint32* masterWeight; // weight of the master account -// uint32* lowThreshold; -// uint32* medThreshold; -// uint32* highThreshold; -// -// string32* homeDomain; // sets the home domain -// -// // Add, update or remove a signer for the account -// // signer is deleted if the weight is 0 -// Signer* signer; +// // issuer has authorized account to perform transactions with its credit +// PASSIVE_FLAG = 1 // }; // // =========================================================================== -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("OfferEntryFlags", { + passiveFlag: 1, +}); // === xdr source ============================================================ // -// struct ChangeTrustOp -// { -// Asset line; -// -// // if limit is set to 0, deletes the trust line -// int64 limit; -// }; +// const MASK_OFFERENTRY_FLAGS = 1; // // =========================================================================== -xdr.struct("ChangeTrustOp", [ - ["line", xdr.lookup("Asset")], - ["limit", xdr.lookup("Int64")], -]); +xdr.const("MASK_OFFERENTRY_FLAGS", 1); // === 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("OfferEntryExt", { + 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 OfferEntry // { -// AccountID trustor; -// union switch (AssetType type) -// { -// // ASSET_TYPE_NATIVE is not allowed -// case ASSET_TYPE_CREDIT_ALPHANUM4: -// opaque assetCode4[4]; +// AccountID sellerID; +// int64 offerID; +// Asset selling; // A +// Asset buying; // B +// int64 amount; // amount of A // -// case ASSET_TYPE_CREDIT_ALPHANUM12: -// opaque assetCode12[12]; +// /* 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 // -// // add other asset types here in the future +// // reserved for future use +// union switch (int v) +// { +// case 0: +// void; // } -// asset; -// -// bool authorize; +// ext; // }; // // =========================================================================== -xdr.struct("AllowTrustOp", [ - ["trustor", xdr.lookup("AccountId")], - ["asset", xdr.lookup("AllowTrustOpAsset")], - ["authorize", xdr.bool()], +xdr.struct("OfferEntry", [ + ["sellerId", xdr.lookup("AccountId")], + ["offerId", xdr.lookup("Int64")], + ["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 ============================================================ // -// struct ManageDataOp -// { -// string64 dataName; -// DataValue* dataValue; // set to null to clear -// }; +// union switch (int v) +// { +// case 0: +// void; +// } // // =========================================================================== -xdr.struct("ManageDataOp", [ - ["dataName", xdr.lookup("String64")], - ["dataValue", xdr.option(xdr.lookup("DataValue"))], -]); +xdr.union("DataEntryExt", { + switchOn: xdr.int(), + switchName: "v", + switches: [ + [0, xdr.void()], + ], + arms: { + }, +}); // === xdr source ============================================================ // -// struct BumpSequenceOp +// struct DataEntry // { -// SequenceNumber bumpTo; +// AccountID accountID; // account this data belongs to +// string64 dataName; +// DataValue dataValue; +// +// // reserved for future use +// union switch (int v) +// { +// case 0: +// void; +// } +// ext; // }; // // =========================================================================== -xdr.struct("BumpSequenceOp", [ - ["bumpTo", xdr.lookup("SequenceNumber")], +xdr.struct("DataEntry", [ + ["accountId", xdr.lookup("AccountId")], + ["dataName", xdr.lookup("String64")], + ["dataValue", xdr.lookup("DataValue")], + ["ext", xdr.lookup("DataEntryExt")], ]); // === xdr source ============================================================ // -// union switch (OperationType type) +// union switch (LedgerEntryType 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: +// 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 switch (int v) +// { +// case 0: // void; -// case MANAGE_DATA: -// ManageDataOp manageDataOp; -// case BUMP_SEQUENCE: -// BumpSequenceOp bumpSequenceOp; // } // // =========================================================================== -xdr.union("OperationBody", { - switchOn: xdr.lookup("OperationType"), - switchName: "type", +xdr.union("LedgerEntryExt", { + switchOn: xdr.int(), + switchName: "v", switches: [ - ["createAccount", "createAccountOp"], - ["payment", "paymentOp"], - ["pathPayment", "pathPaymentOp"], - ["manageOffer", "manageOfferOp"], - ["createPassiveOffer", "createPassiveOfferOp"], - ["setOption", "setOptionsOp"], - ["changeTrust", "changeTrustOp"], - ["allowTrust", "allowTrustOp"], - ["accountMerge", "destination"], - ["inflation", xdr.void()], - ["manageDatum", "manageDataOp"], - ["bumpSequence", "bumpSequenceOp"], + [0, xdr.void()], ], 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"), - bumpSequenceOp: xdr.lookup("BumpSequenceOp"), }, }); // === xdr source ============================================================ // -// struct Operation +// struct LedgerEntry // { -// // sourceAccount is the account used to run the operation -// // if not set, the runtime defaults to "sourceAccount" specified at -// // the transaction level -// AccountID* sourceAccount; +// uint32 lastModifiedLedgerSeq; // ledger the LedgerEntry was last changed // -// union switch (OperationType type) +// union switch (LedgerEntryType 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: +// 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; -// case MANAGE_DATA: -// ManageDataOp manageDataOp; -// case BUMP_SEQUENCE: -// BumpSequenceOp bumpSequenceOp; // } -// body; +// ext; // }; // // =========================================================================== -xdr.struct("Operation", [ - ["sourceAccount", xdr.option(xdr.lookup("AccountId"))], - ["body", xdr.lookup("OperationBody")], +xdr.struct("LedgerEntry", [ + ["lastModifiedLedgerSeq", xdr.lookup("Uint32")], + ["data", xdr.lookup("LedgerEntryData")], + ["ext", xdr.lookup("LedgerEntryExt")], ]); // === xdr source ============================================================ // -// enum MemoType +// enum EnvelopeType // { -// MEMO_NONE = 0, -// MEMO_TEXT = 1, -// MEMO_ID = 2, -// MEMO_HASH = 3, -// MEMO_RETURN = 4 +// ENVELOPE_TYPE_SCP = 1, +// ENVELOPE_TYPE_TX = 2, +// ENVELOPE_TYPE_AUTH = 3, +// ENVELOPE_TYPE_SCPVALUE = 4 // }; // // =========================================================================== -xdr.enum("MemoType", { - memoNone: 0, - memoText: 1, - memoId: 2, - memoHash: 3, - memoReturn: 4, +xdr.enum("EnvelopeType", { + envelopeTypeScp: 1, + envelopeTypeTx: 2, + envelopeTypeAuth: 3, + envelopeTypeScpvalue: 4, }); // === xdr source ============================================================ // -// union Memo switch (MemoType type) +// typedef opaque UpgradeType<128>; +// +// =========================================================================== +xdr.typedef("UpgradeType", xdr.varOpaque(128)); + +// === xdr source ============================================================ +// +// enum StellarValueType // { -// 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 +// STELLAR_VALUE_BASIC = 0, +// STELLAR_VALUE_SIGNED = 1 // }; // // =========================================================================== -xdr.union("Memo", { - switchOn: xdr.lookup("MemoType"), - switchName: "type", +xdr.enum("StellarValueType", { + stellarValueBasic: 0, + stellarValueSigned: 1, +}); + +// === xdr source ============================================================ +// +// struct LedgerCloseValueSignature +// { +// NodeID nodeID; // which node introduced the value +// Signature signature; // nodeID's signature +// }; +// +// =========================================================================== +xdr.struct("LedgerCloseValueSignature", [ + ["nodeId", xdr.lookup("NodeId")], + ["signature", xdr.lookup("Signature")], +]); + +// === xdr source ============================================================ +// +// union switch (StellarValueType v) +// { +// case STELLAR_VALUE_BASIC: +// void; +// case STELLAR_VALUE_SIGNED: +// LedgerCloseValueSignature lcValueSignature; +// } +// +// =========================================================================== +xdr.union("StellarValueExt", { + switchOn: xdr.lookup("StellarValueType"), + switchName: "v", switches: [ - ["memoNone", xdr.void()], - ["memoText", "text"], - ["memoId", "id"], - ["memoHash", "hash"], - ["memoReturn", "retHash"], + ["stellarValueBasic", xdr.void()], + ["stellarValueSigned", "lcValueSignature"], ], arms: { - text: xdr.string(28), - id: xdr.lookup("Uint64"), - hash: xdr.lookup("Hash"), - retHash: xdr.lookup("Hash"), + lcValueSignature: xdr.lookup("LedgerCloseValueSignature"), }, }); // === xdr source ============================================================ // -// struct TimeBounds +// struct StellarValue // { -// uint64 minTime; -// uint64 maxTime; // 0 here means no maxTime +// Hash txSetHash; // transaction set to apply to previous ledger +// TimePoint 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 (StellarValueType v) +// { +// case STELLAR_VALUE_BASIC: +// void; +// case STELLAR_VALUE_SIGNED: +// LedgerCloseValueSignature lcValueSignature; +// } +// ext; // }; // // =========================================================================== -xdr.struct("TimeBounds", [ - ["minTime", xdr.lookup("Uint64")], - ["maxTime", xdr.lookup("Uint64")], +xdr.struct("StellarValue", [ + ["txSetHash", xdr.lookup("Hash")], + ["closeTime", xdr.lookup("TimePoint")], + ["upgrades", xdr.varArray(xdr.lookup("UpgradeType"), 6)], + ["ext", xdr.lookup("StellarValueExt")], ]); // === xdr source ============================================================ @@ -999,7 +851,7 @@ xdr.struct("TimeBounds", [ // } // // =========================================================================== -xdr.union("TransactionExt", { +xdr.union("LedgerHeaderExt", { switchOn: xdr.int(), switchName: "v", switches: [ @@ -1011,23 +863,34 @@ xdr.union("TransactionExt", { // === xdr source ============================================================ // -// struct Transaction +// struct LedgerHeader // { -// // account used to run the transaction -// AccountID sourceAccount; +// 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 // -// // the fee the sourceAccount will pay -// uint32 fee; +// uint32 ledgerSeq; // sequence number of this ledger // -// // sequence number to consume in the account -// SequenceNumber seqNum; +// int64 totalCoins; // total number of stroops in existence. +// // 10,000,000 stroops in 1 XLM // -// // validity range (inclusive) for the last ledger close time -// TimeBounds* timeBounds; +// int64 feePool; // fees burned since last inflation run +// uint32 inflationSeq; // inflation sequence number // -// Memo memo; +// 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 // -// Operation operations<100>; +// 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) @@ -1039,1012 +902,912 @@ xdr.union("TransactionExt", { // }; // // =========================================================================== -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.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 (EnvelopeType type) -// { -// case ENVELOPE_TYPE_TX: -// Transaction tx; -// /* All other values of type are invalid */ -// } +// enum LedgerUpgradeType +// { +// LEDGER_UPGRADE_VERSION = 1, +// LEDGER_UPGRADE_BASE_FEE = 2, +// LEDGER_UPGRADE_MAX_TX_SET_SIZE = 3, +// LEDGER_UPGRADE_BASE_RESERVE = 4 +// }; +// +// =========================================================================== +xdr.enum("LedgerUpgradeType", { + ledgerUpgradeVersion: 1, + ledgerUpgradeBaseFee: 2, + ledgerUpgradeMaxTxSetSize: 3, + ledgerUpgradeBaseReserve: 4, +}); + +// === 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 +// case LEDGER_UPGRADE_BASE_RESERVE: +// uint32 newBaseReserve; // update baseReserve +// }; // // =========================================================================== -xdr.union("TransactionSignaturePayloadTaggedTransaction", { - switchOn: xdr.lookup("EnvelopeType"), +xdr.union("LedgerUpgrade", { + switchOn: xdr.lookup("LedgerUpgradeType"), switchName: "type", switches: [ - ["envelopeTypeTx", "tx"], + ["ledgerUpgradeVersion", "newLedgerVersion"], + ["ledgerUpgradeBaseFee", "newBaseFee"], + ["ledgerUpgradeMaxTxSetSize", "newMaxTxSetSize"], + ["ledgerUpgradeBaseReserve", "newBaseReserve"], ], arms: { - tx: xdr.lookup("Transaction"), + newLedgerVersion: xdr.lookup("Uint32"), + newBaseFee: xdr.lookup("Uint32"), + newMaxTxSetSize: xdr.lookup("Uint32"), + newBaseReserve: xdr.lookup("Uint32"), }, }); // === xdr source ============================================================ // -// struct TransactionSignaturePayload -// { -// Hash networkId; -// union switch (EnvelopeType type) +// struct // { -// case ENVELOPE_TYPE_TX: -// Transaction tx; -// /* All other values of type are invalid */ +// AccountID accountID; // } -// taggedTransaction; -// }; // // =========================================================================== -xdr.struct("TransactionSignaturePayload", [ - ["networkId", xdr.lookup("Hash")], - ["taggedTransaction", xdr.lookup("TransactionSignaturePayloadTaggedTransaction")], +xdr.struct("LedgerKeyAccount", [ + ["accountId", xdr.lookup("AccountId")], ]); // === xdr source ============================================================ // -// struct TransactionEnvelope -// { -// Transaction tx; -// /* Each decorated signature is a signature over the SHA256 hash of -// * a TransactionSignaturePayload */ -// DecoratedSignature signatures<20>; -// }; +// struct +// { +// AccountID accountID; +// Asset asset; +// } // // =========================================================================== -xdr.struct("TransactionEnvelope", [ - ["tx", xdr.lookup("Transaction")], - ["signatures", xdr.varArray(xdr.lookup("DecoratedSignature"), 20)], +xdr.struct("LedgerKeyTrustLine", [ + ["accountId", xdr.lookup("AccountId")], + ["asset", xdr.lookup("Asset")], ]); // === 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; -// }; +// struct +// { +// AccountID sellerID; +// int64 offerID; +// } // // =========================================================================== -xdr.struct("ClaimOfferAtom", [ +xdr.struct("LedgerKeyOffer", [ ["sellerId", xdr.lookup("AccountId")], - ["offerId", xdr.lookup("Uint64")], - ["assetSold", xdr.lookup("Asset")], - ["amountSold", xdr.lookup("Int64")], - ["assetBought", xdr.lookup("Asset")], - ["amountBought", xdr.lookup("Int64")], + ["offerId", xdr.lookup("Int64")], ]); // === xdr source ============================================================ // -// enum CreateAccountResultCode -// { -// // codes considered as "success" for the operation -// CREATE_ACCOUNT_SUCCESS = 0, // account was created -// -// // codes considered as "failure" for the operation -// CREATE_ACCOUNT_MALFORMED = -1, // invalid destination -// CREATE_ACCOUNT_UNDERFUNDED = -2, // not enough funds in source account -// CREATE_ACCOUNT_LOW_RESERVE = -// -3, // would create an account below the min reserve -// CREATE_ACCOUNT_ALREADY_EXIST = -4 // account already exists -// }; -// -// =========================================================================== -xdr.enum("CreateAccountResultCode", { - createAccountSuccess: 0, - createAccountMalformed: -1, - createAccountUnderfunded: -2, - createAccountLowReserve: -3, - createAccountAlreadyExist: -4, -}); - -// === xdr source ============================================================ -// -// union CreateAccountResult switch (CreateAccountResultCode code) -// { -// case CREATE_ACCOUNT_SUCCESS: -// void; -// default: -// void; -// }; +// struct +// { +// AccountID accountID; +// string64 dataName; +// } // // =========================================================================== -xdr.union("CreateAccountResult", { - switchOn: xdr.lookup("CreateAccountResultCode"), - switchName: "code", - switches: [ - ["createAccountSuccess", xdr.void()], - ], - arms: { - }, - defaultArm: xdr.void(), -}); +xdr.struct("LedgerKeyData", [ + ["accountId", xdr.lookup("AccountId")], + ["dataName", xdr.lookup("String64")], +]); // === xdr source ============================================================ // -// enum PaymentResultCode +// union LedgerKey switch (LedgerEntryType type) // { -// // codes considered as "success" for the operation -// PAYMENT_SUCCESS = 0, // payment successfuly completed +// case ACCOUNT: +// struct +// { +// AccountID accountID; +// } account; // -// // 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("PaymentResultCode", { - paymentSuccess: 0, - paymentMalformed: -1, - paymentUnderfunded: -2, - paymentSrcNoTrust: -3, - paymentSrcNotAuthorized: -4, - paymentNoDestination: -5, - paymentNoTrust: -6, - paymentNotAuthorized: -7, - paymentLineFull: -8, - paymentNoIssuer: -9, -}); - -// === xdr source ============================================================ -// -// union PaymentResult switch (PaymentResultCode code) -// { -// case PAYMENT_SUCCESS: -// void; -// default: -// void; +// case TRUSTLINE: +// struct +// { +// AccountID accountID; +// Asset asset; +// } trustLine; +// +// case OFFER: +// struct +// { +// AccountID sellerID; +// int64 offerID; +// } offer; +// +// case DATA: +// struct +// { +// AccountID accountID; +// string64 dataName; +// } data; // }; // // =========================================================================== -xdr.union("PaymentResult", { - switchOn: xdr.lookup("PaymentResultCode"), - switchName: "code", +xdr.union("LedgerKey", { + switchOn: xdr.lookup("LedgerEntryType"), + switchName: "type", switches: [ - ["paymentSuccess", xdr.void()], + ["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"), }, - defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// enum PathPaymentResultCode +// enum BucketEntryType // { -// // 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 +// METAENTRY = +// -1, // At-and-after protocol 11: bucket metadata, should come first. +// LIVEENTRY = 0, // Before protocol 11: created-or-updated; +// // At-and-after protocol 11: only updated. +// DEADENTRY = 1, +// INITENTRY = 2 // At-and-after protocol 11: only created. // }; // // =========================================================================== -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.enum("BucketEntryType", { + metaentry: -1, + liveentry: 0, + deadentry: 1, + initentry: 2, }); // === xdr source ============================================================ // -// struct SimplePaymentResult -// { -// AccountID destination; -// Asset asset; -// int64 amount; -// }; +// union switch (int v) +// { +// case 0: +// void; +// } // // =========================================================================== -xdr.struct("SimplePaymentResult", [ - ["destination", xdr.lookup("AccountId")], - ["asset", xdr.lookup("Asset")], - ["amount", xdr.lookup("Int64")], -]); +xdr.union("BucketMetadataExt", { + switchOn: xdr.int(), + switchName: "v", + switches: [ + [0, xdr.void()], + ], + arms: { + }, +}); // === xdr source ============================================================ // -// struct +// struct BucketMetadata +// { +// // Indicates the protocol version used to create / merge this bucket. +// uint32 ledgerVersion; +// +// // reserved for future use +// union switch (int v) // { -// ClaimOfferAtom offers<>; -// SimplePaymentResult last; +// case 0: +// void; // } +// ext; +// }; // // =========================================================================== -xdr.struct("PathPaymentResultSuccess", [ - ["offers", xdr.varArray(xdr.lookup("ClaimOfferAtom"), 2147483647)], - ["last", xdr.lookup("SimplePaymentResult")], +xdr.struct("BucketMetadata", [ + ["ledgerVersion", xdr.lookup("Uint32")], + ["ext", xdr.lookup("BucketMetadataExt")], ]); // === xdr source ============================================================ // -// union PathPaymentResult switch (PathPaymentResultCode code) +// union BucketEntry switch (BucketEntryType type) // { -// 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; +// case LIVEENTRY: +// case INITENTRY: +// LedgerEntry liveEntry; +// +// case DEADENTRY: +// LedgerKey deadEntry; +// case METAENTRY: +// BucketMetadata metaEntry; // }; // // =========================================================================== -xdr.union("PathPaymentResult", { - switchOn: xdr.lookup("PathPaymentResultCode"), - switchName: "code", +xdr.union("BucketEntry", { + switchOn: xdr.lookup("BucketEntryType"), + switchName: "type", switches: [ - ["pathPaymentSuccess", "success"], - ["pathPaymentNoIssuer", "noIssuer"], + ["liveentry", "liveEntry"], + ["initentry", "liveEntry"], + ["deadentry", "deadEntry"], + ["metaentry", "metaEntry"], ], arms: { - success: xdr.lookup("PathPaymentResultSuccess"), - noIssuer: xdr.lookup("Asset"), + liveEntry: xdr.lookup("LedgerEntry"), + deadEntry: xdr.lookup("LedgerKey"), + metaEntry: xdr.lookup("BucketMetadata"), }, - defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// enum ManageOfferResultCode +// struct TransactionSet // { -// // 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 +// Hash previousLedgerHash; +// TransactionEnvelope txs<>; // }; // // =========================================================================== -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.struct("TransactionSet", [ + ["previousLedgerHash", xdr.lookup("Hash")], + ["txes", xdr.varArray(xdr.lookup("TransactionEnvelope"), 2147483647)], +]); // === xdr source ============================================================ // -// enum ManageOfferEffect +// struct TransactionResultPair // { -// MANAGE_OFFER_CREATED = 0, -// MANAGE_OFFER_UPDATED = 1, -// MANAGE_OFFER_DELETED = 2 +// Hash transactionHash; +// TransactionResult result; // result for the transaction // }; // // =========================================================================== -xdr.enum("ManageOfferEffect", { - manageOfferCreated: 0, - manageOfferUpdated: 1, - manageOfferDeleted: 2, -}); +xdr.struct("TransactionResultPair", [ + ["transactionHash", xdr.lookup("Hash")], + ["result", xdr.lookup("TransactionResult")], +]); // === xdr source ============================================================ // -// union switch (ManageOfferEffect effect) +// struct TransactionResultSet +// { +// TransactionResultPair results<>; +// }; +// +// =========================================================================== +xdr.struct("TransactionResultSet", [ + ["results", xdr.varArray(xdr.lookup("TransactionResultPair"), 2147483647)], +]); + +// === xdr source ============================================================ +// +// 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("TransactionHistoryEntryExt", { + 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 TransactionHistoryEntry // { -// // offers that got claimed while creating this offer -// ClaimOfferAtom offersClaimed<>; +// uint32 ledgerSeq; +// TransactionSet txSet; // -// union switch (ManageOfferEffect effect) +// // 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("TransactionHistoryEntry", [ + ["ledgerSeq", xdr.lookup("Uint32")], + ["txSet", xdr.lookup("TransactionSet")], + ["ext", xdr.lookup("TransactionHistoryEntryExt")], ]); // === xdr source ============================================================ // -// union ManageOfferResult switch (ManageOfferResultCode code) -// { -// case MANAGE_OFFER_SUCCESS: -// ManageOfferSuccessResult success; -// default: -// void; -// }; +// union switch (int v) +// { +// case 0: +// void; +// } // // =========================================================================== -xdr.union("ManageOfferResult", { - switchOn: xdr.lookup("ManageOfferResultCode"), - switchName: "code", +xdr.union("TransactionHistoryResultEntryExt", { + switchOn: xdr.int(), + switchName: "v", switches: [ - ["manageOfferSuccess", "success"], + [0, xdr.void()], ], arms: { - success: xdr.lookup("ManageOfferSuccessResult"), }, - defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// enum SetOptionsResultCode +// struct TransactionHistoryResultEntry // { -// // 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 +// uint32 ledgerSeq; +// TransactionResultSet txResultSet; +// +// // 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("TransactionHistoryResultEntry", [ + ["ledgerSeq", xdr.lookup("Uint32")], + ["txResultSet", xdr.lookup("TransactionResultSet")], + ["ext", xdr.lookup("TransactionHistoryResultEntryExt")], +]); // === xdr source ============================================================ // -// union SetOptionsResult switch (SetOptionsResultCode code) -// { -// case SET_OPTIONS_SUCCESS: -// void; -// default: -// void; -// }; +// union switch (int v) +// { +// case 0: +// void; +// } // // =========================================================================== -xdr.union("SetOptionsResult", { - switchOn: xdr.lookup("SetOptionsResultCode"), - switchName: "code", +xdr.union("LedgerHeaderHistoryEntryExt", { + switchOn: xdr.int(), + switchName: "v", switches: [ - ["setOptionsSuccess", xdr.void()], + [0, xdr.void()], ], arms: { }, - defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// enum ChangeTrustResultCode +// struct LedgerHeaderHistoryEntry // { -// // 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 +// Hash hash; +// LedgerHeader header; +// +// // reserved for future use +// union switch (int v) +// { +// case 0: +// void; +// } +// ext; // }; // // =========================================================================== -xdr.enum("ChangeTrustResultCode", { - changeTrustSuccess: 0, - changeTrustMalformed: -1, - changeTrustNoIssuer: -2, - changeTrustInvalidLimit: -3, - changeTrustLowReserve: -4, - changeTrustSelfNotAllowed: -5, -}); +xdr.struct("LedgerHeaderHistoryEntry", [ + ["hash", xdr.lookup("Hash")], + ["header", xdr.lookup("LedgerHeader")], + ["ext", xdr.lookup("LedgerHeaderHistoryEntryExt")], +]); // === xdr source ============================================================ // -// union ChangeTrustResult switch (ChangeTrustResultCode code) +// struct LedgerSCPMessages // { -// case CHANGE_TRUST_SUCCESS: -// void; -// default: -// void; +// uint32 ledgerSeq; +// SCPEnvelope messages<>; // }; // // =========================================================================== -xdr.union("ChangeTrustResult", { - switchOn: xdr.lookup("ChangeTrustResultCode"), - switchName: "code", - switches: [ - ["changeTrustSuccess", xdr.void()], - ], - arms: { - }, - defaultArm: xdr.void(), -}); +xdr.struct("LedgerScpMessages", [ + ["ledgerSeq", xdr.lookup("Uint32")], + ["messages", xdr.varArray(xdr.lookup("ScpEnvelope"), 2147483647)], +]); // === xdr source ============================================================ // -// enum AllowTrustResultCode +// struct SCPHistoryEntryV0 // { -// // 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 +// SCPQuorumSet quorumSets<>; // additional quorum sets used by ledgerMessages +// LedgerSCPMessages ledgerMessages; // }; // // =========================================================================== -xdr.enum("AllowTrustResultCode", { - allowTrustSuccess: 0, - allowTrustMalformed: -1, - allowTrustNoTrustLine: -2, - allowTrustTrustNotRequired: -3, - allowTrustCantRevoke: -4, - allowTrustSelfNotAllowed: -5, -}); +xdr.struct("ScpHistoryEntryV0", [ + ["quorumSets", xdr.varArray(xdr.lookup("ScpQuorumSet"), 2147483647)], + ["ledgerMessages", xdr.lookup("LedgerScpMessages")], +]); // === xdr source ============================================================ // -// union AllowTrustResult switch (AllowTrustResultCode code) +// union SCPHistoryEntry switch (int v) // { -// case ALLOW_TRUST_SUCCESS: -// void; -// default: -// void; +// case 0: +// SCPHistoryEntryV0 v0; // }; // // =========================================================================== -xdr.union("AllowTrustResult", { - switchOn: xdr.lookup("AllowTrustResultCode"), - switchName: "code", +xdr.union("ScpHistoryEntry", { + switchOn: xdr.int(), + switchName: "v", switches: [ - ["allowTrustSuccess", xdr.void()], + [0, "v0"], ], arms: { + v0: xdr.lookup("ScpHistoryEntryV0"), }, - defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// enum AccountMergeResultCode +// enum LedgerEntryChangeType // { -// // 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 -// ACCOUNT_MERGE_SEQNUM_TOO_FAR = -5, // sequence number is over max allowed -// ACCOUNT_MERGE_DEST_FULL = -6 // can't add source balance to -// // destination balance +// 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.enum("AccountMergeResultCode", { - accountMergeSuccess: 0, - accountMergeMalformed: -1, - accountMergeNoAccount: -2, - accountMergeImmutableSet: -3, - accountMergeHasSubEntry: -4, - accountMergeSeqnumTooFar: -5, - accountMergeDestFull: -6, +xdr.enum("LedgerEntryChangeType", { + ledgerEntryCreated: 0, + ledgerEntryUpdated: 1, + ledgerEntryRemoved: 2, + ledgerEntryState: 3, }); // === xdr source ============================================================ // -// union AccountMergeResult switch (AccountMergeResultCode code) +// union LedgerEntryChange switch (LedgerEntryChangeType type) // { -// case ACCOUNT_MERGE_SUCCESS: -// int64 sourceAccountBalance; // how much got transfered from source account -// default: -// void; +// 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.union("AccountMergeResult", { - switchOn: xdr.lookup("AccountMergeResultCode"), - switchName: "code", +xdr.union("LedgerEntryChange", { + switchOn: xdr.lookup("LedgerEntryChangeType"), + switchName: "type", switches: [ - ["accountMergeSuccess", "sourceAccountBalance"], + ["ledgerEntryCreated", "created"], + ["ledgerEntryUpdated", "updated"], + ["ledgerEntryRemoved", "removed"], + ["ledgerEntryState", "state"], ], arms: { - sourceAccountBalance: xdr.lookup("Int64"), + created: xdr.lookup("LedgerEntry"), + updated: xdr.lookup("LedgerEntry"), + removed: xdr.lookup("LedgerKey"), + state: xdr.lookup("LedgerEntry"), }, - defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// enum InflationResultCode +// typedef LedgerEntryChange LedgerEntryChanges<>; +// +// =========================================================================== +xdr.typedef("LedgerEntryChanges", xdr.varArray(xdr.lookup("LedgerEntryChange"), 2147483647)); + +// === xdr source ============================================================ +// +// struct OperationMeta // { -// // codes considered as "success" for the operation -// INFLATION_SUCCESS = 0, -// // codes considered as "failure" for the operation -// INFLATION_NOT_TIME = -1 +// LedgerEntryChanges changes; // }; // // =========================================================================== -xdr.enum("InflationResultCode", { - inflationSuccess: 0, - inflationNotTime: -1, -}); +xdr.struct("OperationMeta", [ + ["changes", xdr.lookup("LedgerEntryChanges")], +]); // === xdr source ============================================================ // -// struct InflationPayout // or use PaymentResultAtom to limit types? +// struct TransactionMetaV1 // { -// AccountID destination; -// int64 amount; +// LedgerEntryChanges txChanges; // tx level changes if any +// OperationMeta operations<>; // meta for each operation // }; // // =========================================================================== -xdr.struct("InflationPayout", [ - ["destination", xdr.lookup("AccountId")], - ["amount", xdr.lookup("Int64")], +xdr.struct("TransactionMetaV1", [ + ["txChanges", xdr.lookup("LedgerEntryChanges")], + ["operations", xdr.varArray(xdr.lookup("OperationMeta"), 2147483647)], ]); // === xdr source ============================================================ // -// union InflationResult switch (InflationResultCode code) +// union TransactionMeta switch (int v) // { -// case INFLATION_SUCCESS: -// InflationPayout payouts<>; -// default: -// void; +// case 0: +// OperationMeta operations<>; +// case 1: +// TransactionMetaV1 v1; // }; // // =========================================================================== -xdr.union("InflationResult", { - switchOn: xdr.lookup("InflationResultCode"), - switchName: "code", +xdr.union("TransactionMeta", { + switchOn: xdr.int(), + switchName: "v", switches: [ - ["inflationSuccess", "payouts"], + [0, "operations"], + [1, "v1"], ], arms: { - payouts: xdr.varArray(xdr.lookup("InflationPayout"), 2147483647), + operations: xdr.varArray(xdr.lookup("OperationMeta"), 2147483647), + v1: xdr.lookup("TransactionMetaV1"), }, - defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// enum ManageDataResultCode +// enum ErrorCode // { -// // 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 +// 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.enum("ManageDataResultCode", { - manageDataSuccess: 0, - manageDataNotSupportedYet: -1, - manageDataNameNotFound: -2, - manageDataLowReserve: -3, - manageDataInvalidName: -4, +xdr.enum("ErrorCode", { + errMisc: 0, + errDatum: 1, + errConf: 2, + errAuth: 3, + errLoad: 4, }); // === xdr source ============================================================ // -// union ManageDataResult switch (ManageDataResultCode code) +// struct Error // { -// case MANAGE_DATA_SUCCESS: -// void; -// default: -// void; +// ErrorCode code; +// string msg<100>; // }; // // =========================================================================== -xdr.union("ManageDataResult", { - switchOn: xdr.lookup("ManageDataResultCode"), - switchName: "code", - switches: [ - ["manageDataSuccess", xdr.void()], - ], - arms: { - }, - defaultArm: xdr.void(), -}); +xdr.struct("Error", [ + ["code", xdr.lookup("ErrorCode")], + ["msg", xdr.string(100)], +]); // === xdr source ============================================================ // -// enum BumpSequenceResultCode +// struct AuthCert // { -// // codes considered as "success" for the operation -// BUMP_SEQUENCE_SUCCESS = 0, -// // codes considered as "failure" for the operation -// BUMP_SEQUENCE_BAD_SEQ = -1 // `bumpTo` is not within bounds +// Curve25519Public pubkey; +// uint64 expiration; +// Signature sig; +// }; +// +// =========================================================================== +xdr.struct("AuthCert", [ + ["pubkey", xdr.lookup("Curve25519Public")], + ["expiration", xdr.lookup("Uint64")], + ["sig", xdr.lookup("Signature")], +]); + +// === xdr source ============================================================ +// +// struct Hello +// { +// uint32 ledgerVersion; +// uint32 overlayVersion; +// uint32 overlayMinVersion; +// Hash networkID; +// string versionStr<100>; +// int listeningPort; +// NodeID peerID; +// AuthCert cert; +// uint256 nonce; // }; // // =========================================================================== -xdr.enum("BumpSequenceResultCode", { - bumpSequenceSuccess: 0, - bumpSequenceBadSeq: -1, -}); +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 ============================================================ // -// union BumpSequenceResult switch (BumpSequenceResultCode code) +// struct Auth // { -// case BUMP_SEQUENCE_SUCCESS: -// void; -// default: -// void; +// // Empty message, just to confirm +// // establishment of MAC keys. +// int unused; // }; // // =========================================================================== -xdr.union("BumpSequenceResult", { - switchOn: xdr.lookup("BumpSequenceResultCode"), - switchName: "code", - switches: [ - ["bumpSequenceSuccess", xdr.void()], - ], - arms: { - }, - defaultArm: xdr.void(), -}); +xdr.struct("Auth", [ + ["unused", xdr.int()], +]); // === xdr source ============================================================ // -// enum OperationResultCode +// enum IPAddrType // { -// opINNER = 0, // inner object result is valid -// -// opBAD_AUTH = -1, // too few valid signatures / wrong network -// opNO_ACCOUNT = -2, // source account was not found -// opNOT_SUPPORTED = -3 // operation not supported at this time +// IPv4 = 0, +// IPv6 = 1 // }; // // =========================================================================== -xdr.enum("OperationResultCode", { - opInner: 0, - opBadAuth: -1, - opNoAccount: -2, - opNotSupported: -3, +xdr.enum("IpAddrType", { + iPv4: 0, + iPv6: 1, }); // === xdr source ============================================================ // -// union switch (OperationType type) +// union switch (IPAddrType 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; -// case BUMP_SEQUENCE: -// BumpSequenceResult bumpSeqResult; +// case IPv4: +// opaque ipv4[4]; +// case IPv6: +// opaque ipv6[16]; // } // // =========================================================================== -xdr.union("OperationResultTr", { - switchOn: xdr.lookup("OperationType"), +xdr.union("PeerAddressIp", { + switchOn: xdr.lookup("IpAddrType"), 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"], - ["bumpSequence", "bumpSeqResult"], + ["iPv4", "ipv4"], + ["iPv6", "ipv6"], ], 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"), - bumpSeqResult: xdr.lookup("BumpSequenceResult"), + ipv4: xdr.opaque(4), + ipv6: xdr.opaque(16), }, }); // === xdr source ============================================================ // -// union OperationResult switch (OperationResultCode code) +// struct PeerAddress // { -// case opINNER: -// union switch (OperationType type) +// union switch (IPAddrType 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; -// case BUMP_SEQUENCE: -// BumpSequenceResult bumpSeqResult; +// case IPv4: +// opaque ipv4[4]; +// case IPv6: +// opaque ipv6[16]; // } -// tr; -// default: -// void; +// ip; +// uint32 port; +// uint32 numFailures; // }; // // =========================================================================== -xdr.union("OperationResult", { - switchOn: xdr.lookup("OperationResultCode"), - switchName: "code", - switches: [ - ["opInner", "tr"], - ], - arms: { - tr: xdr.lookup("OperationResultTr"), - }, - defaultArm: xdr.void(), -}); +xdr.struct("PeerAddress", [ + ["ip", xdr.lookup("PeerAddressIp")], + ["port", xdr.lookup("Uint32")], + ["numFailures", xdr.lookup("Uint32")], +]); // === xdr source ============================================================ // -// enum TransactionResultCode +// enum MessageType // { -// txSUCCESS = 0, // all operations succeeded +// ERROR_MSG = 0, +// AUTH = 2, +// DONT_HAVE = 3, // -// txFAILED = -1, // one of the operations failed (none were applied) +// GET_PEERS = 4, // gets a list of peers this guy knows about +// PEERS = 5, // -// 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 +// GET_TX_SET = 6, // gets a particular txset by hash +// TX_SET = 7, // -// 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 +// 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("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.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 ============================================================ // -// union switch (TransactionResultCode code) -// { -// case txSUCCESS: -// case txFAILED: -// OperationResult results<>; -// default: -// void; -// } +// struct DontHave +// { +// MessageType type; +// uint256 reqHash; +// }; +// +// =========================================================================== +xdr.struct("DontHave", [ + ["type", xdr.lookup("MessageType")], + ["reqHash", xdr.lookup("Uint256")], +]); + +// === xdr source ============================================================ +// +// 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<100>; +// +// 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("TransactionResultResult", { - switchOn: xdr.lookup("TransactionResultCode"), - switchName: "code", +xdr.union("StellarMessage", { + switchOn: xdr.lookup("MessageType"), + switchName: "type", switches: [ - ["txSuccess", "results"], - ["txFailed", "results"], + ["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: { - results: xdr.varArray(xdr.lookup("OperationResult"), 2147483647), + error: xdr.lookup("Error"), + hello: xdr.lookup("Hello"), + auth: xdr.lookup("Auth"), + dontHave: xdr.lookup("DontHave"), + peers: xdr.varArray(xdr.lookup("PeerAddress"), 100), + 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 ============================================================ // -// union switch (int v) -// { -// case 0: -// void; +// struct +// { +// uint64 sequence; +// StellarMessage message; +// HmacSha256Mac mac; // } // // =========================================================================== -xdr.union("TransactionResultExt", { - switchOn: xdr.int(), - switchName: "v", - switches: [ - [0, xdr.void()], - ], - arms: { - }, -}); +xdr.struct("AuthenticatedMessageV0", [ + ["sequence", xdr.lookup("Uint64")], + ["message", xdr.lookup("StellarMessage")], + ["mac", xdr.lookup("HmacSha256Mac")], +]); // === xdr source ============================================================ // -// struct TransactionResult +// union AuthenticatedMessage switch (uint32 v) // { -// int64 feeCharged; // actual fee charged for the transaction -// -// union switch (TransactionResultCode code) -// { -// case txSUCCESS: -// case txFAILED: -// OperationResult results<>; -// default: -// void; -// } -// result; -// -// // reserved for future use -// union switch (int v) -// { -// case 0: -// void; -// } -// ext; +// case 0: +// struct +// { +// uint64 sequence; +// StellarMessage message; +// HmacSha256Mac mac; +// } v0; // }; // // =========================================================================== -xdr.struct("TransactionResult", [ - ["feeCharged", xdr.lookup("Int64")], - ["result", xdr.lookup("TransactionResultResult")], - ["ext", xdr.lookup("TransactionResultExt")], -]); +xdr.union("AuthenticatedMessage", { + switchOn: xdr.lookup("Uint32"), + switchName: "v", + switches: [ + [0, "v0"], + ], + arms: { + v0: xdr.lookup("AuthenticatedMessageV0"), + }, +}); // === xdr source ============================================================ // @@ -2291,1174 +2054,1575 @@ xdr.struct("ScpQuorumSet", [ // === xdr source ============================================================ // -// typedef PublicKey AccountID; +// struct DecoratedSignature +// { +// SignatureHint hint; // last 4 bytes of the public key, used as a hint +// Signature signature; // actual signature +// }; // // =========================================================================== -xdr.typedef("AccountId", xdr.lookup("PublicKey")); +xdr.struct("DecoratedSignature", [ + ["hint", xdr.lookup("SignatureHint")], + ["signature", xdr.lookup("Signature")], +]); // === xdr source ============================================================ // -// typedef opaque Thresholds[4]; +// enum OperationType +// { +// CREATE_ACCOUNT = 0, +// PAYMENT = 1, +// PATH_PAYMENT = 2, +// MANAGE_SELL_OFFER = 3, +// CREATE_PASSIVE_SELL_OFFER = 4, +// SET_OPTIONS = 5, +// CHANGE_TRUST = 6, +// ALLOW_TRUST = 7, +// ACCOUNT_MERGE = 8, +// INFLATION = 9, +// MANAGE_DATA = 10, +// BUMP_SEQUENCE = 11, +// MANAGE_BUY_OFFER = 12 +// }; // // =========================================================================== -xdr.typedef("Thresholds", xdr.opaque(4)); +xdr.enum("OperationType", { + createAccount: 0, + payment: 1, + pathPayment: 2, + manageSellOffer: 3, + createPassiveSellOffer: 4, + setOption: 5, + changeTrust: 6, + allowTrust: 7, + accountMerge: 8, + inflation: 9, + manageDatum: 10, + bumpSequence: 11, + manageBuyOffer: 12, +}); // === xdr source ============================================================ // -// typedef string string32<32>; +// struct CreateAccountOp +// { +// AccountID destination; // account to create +// int64 startingBalance; // amount they end up with +// }; // // =========================================================================== -xdr.typedef("String32", xdr.string(32)); +xdr.struct("CreateAccountOp", [ + ["destination", xdr.lookup("AccountId")], + ["startingBalance", xdr.lookup("Int64")], +]); // === xdr source ============================================================ // -// typedef string string64<64>; +// struct PaymentOp +// { +// AccountID destination; // recipient of the payment +// Asset asset; // what they end up with +// int64 amount; // amount they end up with +// }; // // =========================================================================== -xdr.typedef("String64", xdr.string(64)); +xdr.struct("PaymentOp", [ + ["destination", xdr.lookup("AccountId")], + ["asset", xdr.lookup("Asset")], + ["amount", xdr.lookup("Int64")], +]); // === xdr source ============================================================ // -// typedef int64 SequenceNumber; +// struct PathPaymentOp +// { +// Asset sendAsset; // asset we pay with +// int64 sendMax; // the maximum amount of sendAsset to +// // send (excluding fees). +// // The operation will fail if can't be met +// +// AccountID destination; // recipient of the payment +// Asset destAsset; // what they end up with +// int64 destAmount; // amount they end up with +// +// Asset path<5>; // additional hops it must go through to get there +// }; // // =========================================================================== -xdr.typedef("SequenceNumber", xdr.lookup("Int64")); +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 DataValue<64>; +// struct ManageSellOfferOp +// { +// 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 +// int64 offerID; +// }; // // =========================================================================== -xdr.typedef("DataValue", xdr.varOpaque(64)); +xdr.struct("ManageSellOfferOp", [ + ["selling", xdr.lookup("Asset")], + ["buying", xdr.lookup("Asset")], + ["amount", xdr.lookup("Int64")], + ["price", xdr.lookup("Price")], + ["offerId", xdr.lookup("Int64")], +]); // === xdr source ============================================================ // -// enum AssetType +// struct ManageBuyOfferOp // { -// ASSET_TYPE_NATIVE = 0, -// ASSET_TYPE_CREDIT_ALPHANUM4 = 1, -// ASSET_TYPE_CREDIT_ALPHANUM12 = 2 +// Asset selling; +// Asset buying; +// int64 buyAmount; // amount being bought. if set to 0, delete the offer +// Price price; // price of thing being bought in terms of what you are +// // selling +// +// // 0=create a new offer, otherwise edit an existing offer +// int64 offerID; // }; // // =========================================================================== -xdr.enum("AssetType", { - assetTypeNative: 0, - assetTypeCreditAlphanum4: 1, - assetTypeCreditAlphanum12: 2, -}); +xdr.struct("ManageBuyOfferOp", [ + ["selling", xdr.lookup("Asset")], + ["buying", xdr.lookup("Asset")], + ["buyAmount", xdr.lookup("Int64")], + ["price", xdr.lookup("Price")], + ["offerId", xdr.lookup("Int64")], +]); + +// === xdr source ============================================================ +// +// struct CreatePassiveSellOfferOp +// { +// 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.struct("CreatePassiveSellOfferOp", [ + ["selling", xdr.lookup("Asset")], + ["buying", xdr.lookup("Asset")], + ["amount", xdr.lookup("Int64")], + ["price", xdr.lookup("Price")], +]); // === xdr source ============================================================ // -// struct -// { -// opaque assetCode[4]; // 1 to 4 characters -// AccountID issuer; -// } +// struct SetOptionsOp +// { +// AccountID* inflationDest; // sets the inflation destination +// +// uint32* clearFlags; // which flags to clear +// uint32* setFlags; // which flags to set +// +// // account threshold manipulation +// uint32* masterWeight; // weight of the master account +// uint32* lowThreshold; +// uint32* medThreshold; +// uint32* highThreshold; +// +// string32* homeDomain; // sets the home domain +// +// // Add, update or remove a signer for the account +// // signer is deleted if the weight is 0 +// Signer* signer; +// }; // // =========================================================================== -xdr.struct("AssetAlphaNum4", [ - ["assetCode", xdr.opaque(4)], - ["issuer", xdr.lookup("AccountId")], +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 ============================================================ // -// struct -// { -// opaque assetCode[12]; // 5 to 12 characters -// AccountID issuer; -// } +// struct ChangeTrustOp +// { +// Asset line; +// +// // if limit is set to 0, deletes the trust line +// int64 limit; +// }; // // =========================================================================== -xdr.struct("AssetAlphaNum12", [ - ["assetCode", xdr.opaque(12)], - ["issuer", xdr.lookup("AccountId")], +xdr.struct("ChangeTrustOp", [ + ["line", xdr.lookup("Asset")], + ["limit", xdr.lookup("Int64")], ]); // === xdr source ============================================================ // -// union Asset switch (AssetType type) -// { -// case ASSET_TYPE_NATIVE: // Not credit -// void; -// -// case ASSET_TYPE_CREDIT_ALPHANUM4: -// struct +// union switch (AssetType type) // { -// opaque assetCode[4]; // 1 to 4 characters -// AccountID issuer; -// } alphaNum4; +// // ASSET_TYPE_NATIVE is not allowed +// case ASSET_TYPE_CREDIT_ALPHANUM4: +// AssetCode4 assetCode4; // -// case ASSET_TYPE_CREDIT_ALPHANUM12: -// struct -// { -// opaque assetCode[12]; // 5 to 12 characters -// AccountID issuer; -// } alphaNum12; +// case ASSET_TYPE_CREDIT_ALPHANUM12: +// AssetCode12 assetCode12; // -// // add other asset types here in the future -// }; +// // add other asset types here in the future +// } // // =========================================================================== -xdr.union("Asset", { +xdr.union("AllowTrustOpAsset", { switchOn: xdr.lookup("AssetType"), switchName: "type", switches: [ - ["assetTypeNative", xdr.void()], - ["assetTypeCreditAlphanum4", "alphaNum4"], - ["assetTypeCreditAlphanum12", "alphaNum12"], + ["assetTypeCreditAlphanum4", "assetCode4"], + ["assetTypeCreditAlphanum12", "assetCode12"], ], arms: { - alphaNum4: xdr.lookup("AssetAlphaNum4"), - alphaNum12: xdr.lookup("AssetAlphaNum12"), + assetCode4: xdr.lookup("AssetCode4"), + assetCode12: xdr.lookup("AssetCode12"), }, }); // === xdr source ============================================================ // -// struct Price +// struct AllowTrustOp // { -// int32 n; // numerator -// int32 d; // denominator +// AccountID trustor; +// union switch (AssetType type) +// { +// // ASSET_TYPE_NATIVE is not allowed +// case ASSET_TYPE_CREDIT_ALPHANUM4: +// AssetCode4 assetCode4; +// +// case ASSET_TYPE_CREDIT_ALPHANUM12: +// AssetCode12 assetCode12; +// +// // add other asset types here in the future +// } +// asset; +// +// bool authorize; // }; // // =========================================================================== -xdr.struct("Price", [ - ["n", xdr.lookup("Int32")], - ["d", xdr.lookup("Int32")], +xdr.struct("AllowTrustOp", [ + ["trustor", xdr.lookup("AccountId")], + ["asset", xdr.lookup("AllowTrustOpAsset")], + ["authorize", xdr.bool()], ]); // === xdr source ============================================================ // -// struct Liabilities +// struct ManageDataOp // { -// int64 buying; -// int64 selling; +// string64 dataName; +// DataValue* dataValue; // set to null to clear // }; // // =========================================================================== -xdr.struct("Liabilities", [ - ["buying", xdr.lookup("Int64")], - ["selling", xdr.lookup("Int64")], +xdr.struct("ManageDataOp", [ + ["dataName", xdr.lookup("String64")], + ["dataValue", xdr.option(xdr.lookup("DataValue"))], ]); // === xdr source ============================================================ // -// enum ThresholdIndexes +// struct BumpSequenceOp // { -// THRESHOLD_MASTER_WEIGHT = 0, -// THRESHOLD_LOW = 1, -// THRESHOLD_MED = 2, -// THRESHOLD_HIGH = 3 +// SequenceNumber bumpTo; // }; // // =========================================================================== -xdr.enum("ThresholdIndices", { - thresholdMasterWeight: 0, - thresholdLow: 1, - thresholdMed: 2, - thresholdHigh: 3, -}); +xdr.struct("BumpSequenceOp", [ + ["bumpTo", xdr.lookup("SequenceNumber")], +]); // === xdr source ============================================================ // -// enum LedgerEntryType -// { -// ACCOUNT = 0, -// TRUSTLINE = 1, -// OFFER = 2, -// DATA = 3 -// }; +// union switch (OperationType type) +// { +// case CREATE_ACCOUNT: +// CreateAccountOp createAccountOp; +// case PAYMENT: +// PaymentOp paymentOp; +// case PATH_PAYMENT: +// PathPaymentOp pathPaymentOp; +// case MANAGE_SELL_OFFER: +// ManageSellOfferOp manageSellOfferOp; +// case CREATE_PASSIVE_SELL_OFFER: +// CreatePassiveSellOfferOp createPassiveSellOfferOp; +// 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 BUMP_SEQUENCE: +// BumpSequenceOp bumpSequenceOp; +// case MANAGE_BUY_OFFER: +// ManageBuyOfferOp manageBuyOfferOp; +// } // // =========================================================================== -xdr.enum("LedgerEntryType", { - account: 0, - trustline: 1, - offer: 2, - datum: 3, +xdr.union("OperationBody", { + switchOn: xdr.lookup("OperationType"), + switchName: "type", + switches: [ + ["createAccount", "createAccountOp"], + ["payment", "paymentOp"], + ["pathPayment", "pathPaymentOp"], + ["manageSellOffer", "manageSellOfferOp"], + ["createPassiveSellOffer", "createPassiveSellOfferOp"], + ["setOption", "setOptionsOp"], + ["changeTrust", "changeTrustOp"], + ["allowTrust", "allowTrustOp"], + ["accountMerge", "destination"], + ["inflation", xdr.void()], + ["manageDatum", "manageDataOp"], + ["bumpSequence", "bumpSequenceOp"], + ["manageBuyOffer", "manageBuyOfferOp"], + ], + arms: { + createAccountOp: xdr.lookup("CreateAccountOp"), + paymentOp: xdr.lookup("PaymentOp"), + pathPaymentOp: xdr.lookup("PathPaymentOp"), + manageSellOfferOp: xdr.lookup("ManageSellOfferOp"), + createPassiveSellOfferOp: xdr.lookup("CreatePassiveSellOfferOp"), + setOptionsOp: xdr.lookup("SetOptionsOp"), + changeTrustOp: xdr.lookup("ChangeTrustOp"), + allowTrustOp: xdr.lookup("AllowTrustOp"), + destination: xdr.lookup("AccountId"), + manageDataOp: xdr.lookup("ManageDataOp"), + bumpSequenceOp: xdr.lookup("BumpSequenceOp"), + manageBuyOfferOp: xdr.lookup("ManageBuyOfferOp"), + }, }); // === xdr source ============================================================ // -// struct Signer +// struct Operation // { -// SignerKey key; -// uint32 weight; // really only need 1byte -// }; -// -// =========================================================================== -xdr.struct("Signer", [ - ["key", xdr.lookup("SignerKey")], - ["weight", xdr.lookup("Uint32")], -]); - -// === xdr source ============================================================ -// -// enum AccountFlags -// { // masks for each flag +// // sourceAccount is the account used to run the operation +// // if not set, the runtime defaults to "sourceAccount" specified at +// // the transaction level +// AccountID* sourceAccount; // -// // 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("AccountFlags", { - authRequiredFlag: 1, - authRevocableFlag: 2, - authImmutableFlag: 4, -}); +// union switch (OperationType type) +// { +// case CREATE_ACCOUNT: +// CreateAccountOp createAccountOp; +// case PAYMENT: +// PaymentOp paymentOp; +// case PATH_PAYMENT: +// PathPaymentOp pathPaymentOp; +// case MANAGE_SELL_OFFER: +// ManageSellOfferOp manageSellOfferOp; +// case CREATE_PASSIVE_SELL_OFFER: +// CreatePassiveSellOfferOp createPassiveSellOfferOp; +// 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 BUMP_SEQUENCE: +// BumpSequenceOp bumpSequenceOp; +// case MANAGE_BUY_OFFER: +// ManageBuyOfferOp manageBuyOfferOp; +// } +// body; +// }; +// +// =========================================================================== +xdr.struct("Operation", [ + ["sourceAccount", xdr.option(xdr.lookup("AccountId"))], + ["body", xdr.lookup("OperationBody")], +]); // === xdr source ============================================================ // -// const MASK_ACCOUNT_FLAGS = 0x7; +// enum MemoType +// { +// MEMO_NONE = 0, +// MEMO_TEXT = 1, +// MEMO_ID = 2, +// MEMO_HASH = 3, +// MEMO_RETURN = 4 +// }; // // =========================================================================== -xdr.const("MASK_ACCOUNT_FLAGS", 0x7); +xdr.enum("MemoType", { + memoNone: 0, + memoText: 1, + memoId: 2, + memoHash: 3, + memoReturn: 4, +}); // === xdr source ============================================================ // -// union switch (int v) -// { -// case 0: -// void; -// } +// union Memo switch (MemoType type) +// { +// case MEMO_NONE: +// void; +// case MEMO_TEXT: +// string text<28>; +// case MEMO_ID: +// uint64 id; +// case MEMO_HASH: +// Hash hash; // the hash of what to pull from the content server +// case MEMO_RETURN: +// Hash retHash; // the hash of the tx you are rejecting +// }; // // =========================================================================== -xdr.union("AccountEntryV1Ext", { - switchOn: xdr.int(), - switchName: "v", +xdr.union("Memo", { + switchOn: xdr.lookup("MemoType"), + switchName: "type", switches: [ - [0, xdr.void()], + ["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 source ============================================================ // -// struct -// { -// Liabilities liabilities; -// -// union switch (int v) -// { -// case 0: -// void; -// } -// ext; -// } +// struct TimeBounds +// { +// TimePoint minTime; +// TimePoint maxTime; // 0 here means no maxTime +// }; // // =========================================================================== -xdr.struct("AccountEntryV1", [ - ["liabilities", xdr.lookup("Liabilities")], - ["ext", xdr.lookup("AccountEntryV1Ext")], +xdr.struct("TimeBounds", [ + ["minTime", xdr.lookup("TimePoint")], + ["maxTime", xdr.lookup("TimePoint")], ]); +// === xdr source ============================================================ +// +// const MAX_OPS_PER_TX = 100; +// +// =========================================================================== +xdr.const("MAX_OPS_PER_TX", 100); + // === xdr source ============================================================ // // union switch (int v) // { // case 0: // void; -// case 1: -// struct -// { -// Liabilities liabilities; -// -// union switch (int v) -// { -// case 0: -// void; -// } -// ext; -// } v1; // } // // =========================================================================== -xdr.union("AccountEntryExt", { +xdr.union("TransactionExt", { switchOn: xdr.int(), switchName: "v", switches: [ [0, xdr.void()], - [1, "v1"], ], arms: { - v1: xdr.lookup("AccountEntryV1"), }, }); // === xdr source ============================================================ // -// struct AccountEntry +// struct Transaction // { -// 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 +// // account used to run the transaction +// AccountID sourceAccount; // -// string32 homeDomain; // can be used for reverse federation and memo lookup +// // the fee the sourceAccount will pay +// uint32 fee; // -// // fields used for signatures -// // thresholds stores unsigned bytes: [weight of master|low|medium|high] -// Thresholds thresholds; +// // sequence number to consume in the account +// SequenceNumber seqNum; // -// Signer signers<20>; // possible signers for this account +// // validity range (inclusive) for the last ledger close time +// TimeBounds* timeBounds; +// +// Memo memo; +// +// Operation operations; // // // reserved for future use // union switch (int v) // { // case 0: // void; -// case 1: -// struct -// { -// Liabilities liabilities; -// -// union switch (int v) -// { -// case 0: -// void; -// } -// ext; -// } v1; // } // ext; // }; // // =========================================================================== -xdr.struct("AccountEntry", [ - ["accountId", xdr.lookup("AccountId")], - ["balance", xdr.lookup("Int64")], +xdr.struct("Transaction", [ + ["sourceAccount", xdr.lookup("AccountId")], + ["fee", xdr.lookup("Uint32")], ["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")], + ["timeBounds", xdr.option(xdr.lookup("TimeBounds"))], + ["memo", xdr.lookup("Memo")], + ["operations", xdr.varArray(xdr.lookup("Operation"), xdr.lookup("MAX_OPS_PER_TX"))], + ["ext", xdr.lookup("TransactionExt")], ]); // === xdr source ============================================================ // -// enum TrustLineFlags +// union switch (EnvelopeType type) +// { +// case ENVELOPE_TYPE_TX: +// Transaction tx; +// /* All other values of type are invalid */ +// } +// +// =========================================================================== +xdr.union("TransactionSignaturePayloadTaggedTransaction", { + switchOn: xdr.lookup("EnvelopeType"), + switchName: "type", + switches: [ + ["envelopeTypeTx", "tx"], + ], + arms: { + tx: xdr.lookup("Transaction"), + }, +}); + +// === xdr source ============================================================ +// +// struct TransactionSignaturePayload // { -// // issuer has authorized account to perform transactions with its credit -// AUTHORIZED_FLAG = 1 +// Hash networkId; +// union switch (EnvelopeType type) +// { +// case ENVELOPE_TYPE_TX: +// Transaction tx; +// /* All other values of type are invalid */ +// } +// taggedTransaction; // }; // // =========================================================================== -xdr.enum("TrustLineFlags", { - authorizedFlag: 1, -}); +xdr.struct("TransactionSignaturePayload", [ + ["networkId", xdr.lookup("Hash")], + ["taggedTransaction", xdr.lookup("TransactionSignaturePayloadTaggedTransaction")], +]); // === xdr source ============================================================ // -// const MASK_TRUSTLINE_FLAGS = 1; +// struct TransactionEnvelope +// { +// Transaction tx; +// /* Each decorated signature is a signature over the SHA256 hash of +// * a TransactionSignaturePayload */ +// DecoratedSignature signatures<20>; +// }; // // =========================================================================== -xdr.const("MASK_TRUSTLINE_FLAGS", 1); +xdr.struct("TransactionEnvelope", [ + ["tx", xdr.lookup("Transaction")], + ["signatures", xdr.varArray(xdr.lookup("DecoratedSignature"), 20)], +]); // === xdr source ============================================================ // -// union switch (int v) -// { -// case 0: -// void; -// } +// struct ClaimOfferAtom +// { +// // emitted to identify the offer +// AccountID sellerID; // Account that owns the offer +// int64 offerID; +// +// // amount and asset taken from the owner +// Asset assetSold; +// int64 amountSold; +// +// // amount and asset sent to the owner +// Asset assetBought; +// int64 amountBought; +// }; // // =========================================================================== -xdr.union("TrustLineEntryV1Ext", { - switchOn: xdr.int(), - switchName: "v", - switches: [ - [0, xdr.void()], - ], - arms: { - }, -}); +xdr.struct("ClaimOfferAtom", [ + ["sellerId", xdr.lookup("AccountId")], + ["offerId", xdr.lookup("Int64")], + ["assetSold", xdr.lookup("Asset")], + ["amountSold", xdr.lookup("Int64")], + ["assetBought", xdr.lookup("Asset")], + ["amountBought", xdr.lookup("Int64")], +]); // === xdr source ============================================================ // -// struct -// { -// Liabilities liabilities; +// enum CreateAccountResultCode +// { +// // codes considered as "success" for the operation +// CREATE_ACCOUNT_SUCCESS = 0, // account was created // -// union switch (int v) -// { -// case 0: -// void; -// } -// ext; -// } +// // 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("TrustLineEntryV1", [ - ["liabilities", xdr.lookup("Liabilities")], - ["ext", xdr.lookup("TrustLineEntryV1Ext")], -]); +xdr.enum("CreateAccountResultCode", { + createAccountSuccess: 0, + createAccountMalformed: -1, + createAccountUnderfunded: -2, + createAccountLowReserve: -3, + createAccountAlreadyExist: -4, +}); // === xdr source ============================================================ // -// union switch (int v) -// { -// case 0: -// void; -// case 1: -// struct -// { -// Liabilities liabilities; -// -// union switch (int v) -// { -// case 0: -// void; -// } -// ext; -// } v1; -// } +// union CreateAccountResult switch (CreateAccountResultCode code) +// { +// case CREATE_ACCOUNT_SUCCESS: +// void; +// default: +// void; +// }; // // =========================================================================== -xdr.union("TrustLineEntryExt", { - switchOn: xdr.int(), - switchName: "v", +xdr.union("CreateAccountResult", { + switchOn: xdr.lookup("CreateAccountResultCode"), + switchName: "code", switches: [ - [0, xdr.void()], - [1, "v1"], + ["createAccountSuccess", xdr.void()], ], arms: { - v1: xdr.lookup("TrustLineEntryV1"), }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// struct TrustLineEntry +// enum PaymentResultCode // { -// 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; -// case 1: -// struct -// { -// Liabilities liabilities; +// // codes considered as "success" for the operation +// PAYMENT_SUCCESS = 0, // payment successfuly completed // -// union switch (int v) -// { -// case 0: -// void; -// } -// ext; -// } v1; -// } -// ext; +// // 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.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.enum("PaymentResultCode", { + paymentSuccess: 0, + paymentMalformed: -1, + paymentUnderfunded: -2, + paymentSrcNoTrust: -3, + paymentSrcNotAuthorized: -4, + paymentNoDestination: -5, + paymentNoTrust: -6, + paymentNotAuthorized: -7, + paymentLineFull: -8, + paymentNoIssuer: -9, +}); // === xdr source ============================================================ // -// enum OfferEntryFlags +// union PaymentResult switch (PaymentResultCode code) // { -// // issuer has authorized account to perform transactions with its credit -// PASSIVE_FLAG = 1 +// case PAYMENT_SUCCESS: +// void; +// default: +// void; // }; // // =========================================================================== -xdr.enum("OfferEntryFlags", { - passiveFlag: 1, +xdr.union("PaymentResult", { + switchOn: xdr.lookup("PaymentResultCode"), + switchName: "code", + switches: [ + ["paymentSuccess", xdr.void()], + ], + arms: { + }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// const MASK_OFFERENTRY_FLAGS = 1; +// 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.const("MASK_OFFERENTRY_FLAGS", 1); +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 ============================================================ // -// union switch (int v) -// { -// case 0: -// void; -// } +// struct SimplePaymentResult +// { +// AccountID destination; +// Asset asset; +// int64 amount; +// }; // // =========================================================================== -xdr.union("OfferEntryExt", { - switchOn: xdr.int(), - switchName: "v", - switches: [ - [0, xdr.void()], - ], - arms: { - }, -}); +xdr.struct("SimplePaymentResult", [ + ["destination", xdr.lookup("AccountId")], + ["asset", xdr.lookup("Asset")], + ["amount", xdr.lookup("Int64")], +]); // === xdr source ============================================================ // -// struct OfferEntry -// { -// AccountID sellerID; -// uint64 offerID; -// Asset selling; // A -// Asset buying; // B -// int64 amount; // amount of A -// -// /* price for this offer: -// price of A in terms of B -// price=AmountB/AmountA=priceNumerator/priceDenominator -// price is after fees -// */ -// Price price; -// uint32 flags; // see OfferEntryFlags -// -// // reserved for future use -// union switch (int v) +// struct // { -// case 0: -// void; +// ClaimOfferAtom offers<>; +// SimplePaymentResult last; // } -// ext; -// }; // // =========================================================================== -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("PathPaymentResultSuccess", [ + ["offers", xdr.varArray(xdr.lookup("ClaimOfferAtom"), 2147483647)], + ["last", xdr.lookup("SimplePaymentResult")], ]); // === xdr source ============================================================ // -// union switch (int v) +// union PathPaymentResult switch (PathPaymentResultCode code) +// { +// case PATH_PAYMENT_SUCCESS: +// struct // { -// case 0: -// void; -// } +// ClaimOfferAtom offers<>; +// SimplePaymentResult last; +// } success; +// case PATH_PAYMENT_NO_ISSUER: +// Asset noIssuer; // the asset that caused the error +// default: +// void; +// }; // // =========================================================================== -xdr.union("DataEntryExt", { - switchOn: xdr.int(), - switchName: "v", +xdr.union("PathPaymentResult", { + switchOn: xdr.lookup("PathPaymentResultCode"), + switchName: "code", switches: [ - [0, xdr.void()], + ["pathPaymentSuccess", "success"], + ["pathPaymentNoIssuer", "noIssuer"], ], arms: { + success: xdr.lookup("PathPaymentResultSuccess"), + noIssuer: xdr.lookup("Asset"), }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// struct DataEntry +// enum ManageSellOfferResultCode // { -// AccountID accountID; // account this data belongs to -// string64 dataName; -// DataValue dataValue; +// // codes considered as "success" for the operation +// MANAGE_SELL_OFFER_SUCCESS = 0, // -// // reserved for future use -// union switch (int v) -// { -// case 0: -// void; -// } -// ext; +// // codes considered as "failure" for the operation +// MANAGE_SELL_OFFER_MALFORMED = -1, // generated offer would be invalid +// MANAGE_SELL_OFFER_SELL_NO_TRUST = -2, // no trust line for what we're selling +// MANAGE_SELL_OFFER_BUY_NO_TRUST = -3, // no trust line for what we're buying +// MANAGE_SELL_OFFER_SELL_NOT_AUTHORIZED = -4, // not authorized to sell +// MANAGE_SELL_OFFER_BUY_NOT_AUTHORIZED = -5, // not authorized to buy +// MANAGE_SELL_OFFER_LINE_FULL = -6, // can't receive more of what it's buying +// MANAGE_SELL_OFFER_UNDERFUNDED = -7, // doesn't hold what it's trying to sell +// MANAGE_SELL_OFFER_CROSS_SELF = -8, // would cross an offer from the same user +// MANAGE_SELL_OFFER_SELL_NO_ISSUER = -9, // no issuer for what we're selling +// MANAGE_SELL_OFFER_BUY_NO_ISSUER = -10, // no issuer for what we're buying +// +// // update errors +// MANAGE_SELL_OFFER_NOT_FOUND = -11, // offerID does not match an existing offer +// +// MANAGE_SELL_OFFER_LOW_RESERVE = -12 // not enough funds to create a new Offer // }; // // =========================================================================== -xdr.struct("DataEntry", [ - ["accountId", xdr.lookup("AccountId")], - ["dataName", xdr.lookup("String64")], - ["dataValue", xdr.lookup("DataValue")], - ["ext", xdr.lookup("DataEntryExt")], -]); +xdr.enum("ManageSellOfferResultCode", { + manageSellOfferSuccess: 0, + manageSellOfferMalformed: -1, + manageSellOfferSellNoTrust: -2, + manageSellOfferBuyNoTrust: -3, + manageSellOfferSellNotAuthorized: -4, + manageSellOfferBuyNotAuthorized: -5, + manageSellOfferLineFull: -6, + manageSellOfferUnderfunded: -7, + manageSellOfferCrossSelf: -8, + manageSellOfferSellNoIssuer: -9, + manageSellOfferBuyNoIssuer: -10, + manageSellOfferNotFound: -11, + manageSellOfferLowReserve: -12, +}); // === xdr source ============================================================ // -// union switch (LedgerEntryType type) -// { -// case ACCOUNT: -// AccountEntry account; -// case TRUSTLINE: -// TrustLineEntry trustLine; -// case OFFER: -// OfferEntry offer; -// case DATA: -// DataEntry data; -// } +// enum ManageOfferEffect +// { +// MANAGE_OFFER_CREATED = 0, +// MANAGE_OFFER_UPDATED = 1, +// MANAGE_OFFER_DELETED = 2 +// }; // // =========================================================================== -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("ManageOfferEffect", { + manageOfferCreated: 0, + manageOfferUpdated: 1, + manageOfferDeleted: 2, }); // === xdr source ============================================================ // -// union switch (int v) +// union switch (ManageOfferEffect effect) // { -// case 0: +// case MANAGE_OFFER_CREATED: +// case MANAGE_OFFER_UPDATED: +// OfferEntry offer; +// default: // void; // } // // =========================================================================== -xdr.union("LedgerEntryExt", { - switchOn: xdr.int(), - switchName: "v", +xdr.union("ManageOfferSuccessResultOffer", { + switchOn: xdr.lookup("ManageOfferEffect"), + switchName: "effect", switches: [ - [0, xdr.void()], + ["manageOfferCreated", "offer"], + ["manageOfferUpdated", "offer"], ], arms: { + offer: xdr.lookup("OfferEntry"), }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// struct LedgerEntry +// struct ManageOfferSuccessResult // { -// uint32 lastModifiedLedgerSeq; // ledger the LedgerEntry was last changed +// // offers that got claimed while creating this offer +// ClaimOfferAtom offersClaimed<>; // -// union switch (LedgerEntryType type) +// union switch (ManageOfferEffect effect) // { -// case ACCOUNT: -// AccountEntry account; -// case TRUSTLINE: -// TrustLineEntry trustLine; -// case OFFER: +// case MANAGE_OFFER_CREATED: +// case MANAGE_OFFER_UPDATED: // OfferEntry offer; -// case DATA: -// DataEntry data; -// } -// data; -// -// // reserved for future use -// union switch (int v) -// { -// case 0: +// default: // void; // } -// ext; +// offer; // }; // // =========================================================================== -xdr.struct("LedgerEntry", [ - ["lastModifiedLedgerSeq", xdr.lookup("Uint32")], - ["data", xdr.lookup("LedgerEntryData")], - ["ext", xdr.lookup("LedgerEntryExt")], +xdr.struct("ManageOfferSuccessResult", [ + ["offersClaimed", xdr.varArray(xdr.lookup("ClaimOfferAtom"), 2147483647)], + ["offer", xdr.lookup("ManageOfferSuccessResultOffer")], ]); // === xdr source ============================================================ // -// enum EnvelopeType +// union ManageSellOfferResult switch (ManageSellOfferResultCode code) // { -// ENVELOPE_TYPE_SCP = 1, -// ENVELOPE_TYPE_TX = 2, -// ENVELOPE_TYPE_AUTH = 3 +// case MANAGE_SELL_OFFER_SUCCESS: +// ManageOfferSuccessResult success; +// default: +// void; // }; // // =========================================================================== -xdr.enum("EnvelopeType", { - envelopeTypeScp: 1, - envelopeTypeTx: 2, - envelopeTypeAuth: 3, +xdr.union("ManageSellOfferResult", { + switchOn: xdr.lookup("ManageSellOfferResultCode"), + switchName: "code", + switches: [ + ["manageSellOfferSuccess", "success"], + ], + arms: { + success: xdr.lookup("ManageOfferSuccessResult"), + }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// typedef opaque UpgradeType<128>; +// enum ManageBuyOfferResultCode +// { +// // codes considered as "success" for the operation +// MANAGE_BUY_OFFER_SUCCESS = 0, +// +// // codes considered as "failure" for the operation +// MANAGE_BUY_OFFER_MALFORMED = -1, // generated offer would be invalid +// MANAGE_BUY_OFFER_SELL_NO_TRUST = -2, // no trust line for what we're selling +// MANAGE_BUY_OFFER_BUY_NO_TRUST = -3, // no trust line for what we're buying +// MANAGE_BUY_OFFER_SELL_NOT_AUTHORIZED = -4, // not authorized to sell +// MANAGE_BUY_OFFER_BUY_NOT_AUTHORIZED = -5, // not authorized to buy +// MANAGE_BUY_OFFER_LINE_FULL = -6, // can't receive more of what it's buying +// MANAGE_BUY_OFFER_UNDERFUNDED = -7, // doesn't hold what it's trying to sell +// MANAGE_BUY_OFFER_CROSS_SELF = -8, // would cross an offer from the same user +// MANAGE_BUY_OFFER_SELL_NO_ISSUER = -9, // no issuer for what we're selling +// MANAGE_BUY_OFFER_BUY_NO_ISSUER = -10, // no issuer for what we're buying +// +// // update errors +// MANAGE_BUY_OFFER_NOT_FOUND = -11, // offerID does not match an existing offer +// +// MANAGE_BUY_OFFER_LOW_RESERVE = -12 // not enough funds to create a new Offer +// }; // // =========================================================================== -xdr.typedef("UpgradeType", xdr.varOpaque(128)); +xdr.enum("ManageBuyOfferResultCode", { + manageBuyOfferSuccess: 0, + manageBuyOfferMalformed: -1, + manageBuyOfferSellNoTrust: -2, + manageBuyOfferBuyNoTrust: -3, + manageBuyOfferSellNotAuthorized: -4, + manageBuyOfferBuyNotAuthorized: -5, + manageBuyOfferLineFull: -6, + manageBuyOfferUnderfunded: -7, + manageBuyOfferCrossSelf: -8, + manageBuyOfferSellNoIssuer: -9, + manageBuyOfferBuyNoIssuer: -10, + manageBuyOfferNotFound: -11, + manageBuyOfferLowReserve: -12, +}); // === xdr source ============================================================ // -// union switch (int v) -// { -// case 0: -// void; -// } +// union ManageBuyOfferResult switch (ManageBuyOfferResultCode code) +// { +// case MANAGE_BUY_OFFER_SUCCESS: +// ManageOfferSuccessResult success; +// default: +// void; +// }; // // =========================================================================== -xdr.union("StellarValueExt", { - switchOn: xdr.int(), - switchName: "v", +xdr.union("ManageBuyOfferResult", { + switchOn: xdr.lookup("ManageBuyOfferResultCode"), + switchName: "code", switches: [ - [0, xdr.void()], + ["manageBuyOfferSuccess", "success"], ], arms: { + success: xdr.lookup("ManageOfferSuccessResult"), }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// struct StellarValue +// enum SetOptionsResultCode // { -// 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; +// // 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.struct("StellarValue", [ - ["txSetHash", xdr.lookup("Hash")], - ["closeTime", xdr.lookup("Uint64")], - ["upgrades", xdr.varArray(xdr.lookup("UpgradeType"), 6)], - ["ext", xdr.lookup("StellarValueExt")], -]); +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 (int v) -// { -// case 0: -// void; -// } +// union SetOptionsResult switch (SetOptionsResultCode code) +// { +// case SET_OPTIONS_SUCCESS: +// void; +// default: +// void; +// }; // // =========================================================================== -xdr.union("LedgerHeaderExt", { - switchOn: xdr.int(), - switchName: "v", +xdr.union("SetOptionsResult", { + switchOn: xdr.lookup("SetOptionsResultCode"), + switchName: "code", switches: [ - [0, xdr.void()], + ["setOptionsSuccess", xdr.void()], ], arms: { }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// struct LedgerHeader +// enum ChangeTrustResultCode // { -// 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 -// -// 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; +// // 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("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.enum("ChangeTrustResultCode", { + changeTrustSuccess: 0, + changeTrustMalformed: -1, + changeTrustNoIssuer: -2, + changeTrustInvalidLimit: -3, + changeTrustLowReserve: -4, + changeTrustSelfNotAllowed: -5, +}); // === xdr source ============================================================ // -// enum LedgerUpgradeType +// union ChangeTrustResult switch (ChangeTrustResultCode code) // { -// LEDGER_UPGRADE_VERSION = 1, -// LEDGER_UPGRADE_BASE_FEE = 2, -// LEDGER_UPGRADE_MAX_TX_SET_SIZE = 3, -// LEDGER_UPGRADE_BASE_RESERVE = 4 +// case CHANGE_TRUST_SUCCESS: +// void; +// default: +// void; // }; // // =========================================================================== -xdr.enum("LedgerUpgradeType", { - ledgerUpgradeVersion: 1, - ledgerUpgradeBaseFee: 2, - ledgerUpgradeMaxTxSetSize: 3, - ledgerUpgradeBaseReserve: 4, +xdr.union("ChangeTrustResult", { + switchOn: xdr.lookup("ChangeTrustResultCode"), + switchName: "code", + switches: [ + ["changeTrustSuccess", xdr.void()], + ], + arms: { + }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// union LedgerUpgrade switch (LedgerUpgradeType type) +// enum AllowTrustResultCode // { -// 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 +// // 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.union("LedgerUpgrade", { - switchOn: xdr.lookup("LedgerUpgradeType"), - switchName: "type", +xdr.enum("AllowTrustResultCode", { + allowTrustSuccess: 0, + allowTrustMalformed: -1, + allowTrustNoTrustLine: -2, + allowTrustTrustNotRequired: -3, + allowTrustCantRevoke: -4, + allowTrustSelfNotAllowed: -5, +}); + +// === xdr source ============================================================ +// +// union AllowTrustResult switch (AllowTrustResultCode code) +// { +// case ALLOW_TRUST_SUCCESS: +// void; +// default: +// void; +// }; +// +// =========================================================================== +xdr.union("AllowTrustResult", { + switchOn: xdr.lookup("AllowTrustResultCode"), + switchName: "code", switches: [ - ["ledgerUpgradeVersion", "newLedgerVersion"], - ["ledgerUpgradeBaseFee", "newBaseFee"], - ["ledgerUpgradeMaxTxSetSize", "newMaxTxSetSize"], - ["ledgerUpgradeBaseReserve", "newBaseReserve"], + ["allowTrustSuccess", xdr.void()], ], arms: { - newLedgerVersion: xdr.lookup("Uint32"), - newBaseFee: xdr.lookup("Uint32"), - newMaxTxSetSize: xdr.lookup("Uint32"), - newBaseReserve: xdr.lookup("Uint32"), }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// struct -// { -// AccountID accountID; -// } +// enum AccountMergeResultCode +// { +// // codes considered as "success" for the operation +// ACCOUNT_MERGE_SUCCESS = 0, +// // codes considered as "failure" for the operation +// ACCOUNT_MERGE_MALFORMED = -1, // can't merge onto itself +// ACCOUNT_MERGE_NO_ACCOUNT = -2, // destination does not exist +// ACCOUNT_MERGE_IMMUTABLE_SET = -3, // source account has AUTH_IMMUTABLE set +// ACCOUNT_MERGE_HAS_SUB_ENTRIES = -4, // account has trust lines/offers +// ACCOUNT_MERGE_SEQNUM_TOO_FAR = -5, // sequence number is over max allowed +// ACCOUNT_MERGE_DEST_FULL = -6 // can't add source balance to +// // destination balance +// }; // // =========================================================================== -xdr.struct("LedgerKeyAccount", [ - ["accountId", xdr.lookup("AccountId")], -]); +xdr.enum("AccountMergeResultCode", { + accountMergeSuccess: 0, + accountMergeMalformed: -1, + accountMergeNoAccount: -2, + accountMergeImmutableSet: -3, + accountMergeHasSubEntry: -4, + accountMergeSeqnumTooFar: -5, + accountMergeDestFull: -6, +}); // === xdr source ============================================================ // -// struct -// { -// AccountID accountID; -// Asset asset; -// } +// union AccountMergeResult switch (AccountMergeResultCode code) +// { +// case ACCOUNT_MERGE_SUCCESS: +// int64 sourceAccountBalance; // how much got transfered from source account +// default: +// void; +// }; // // =========================================================================== -xdr.struct("LedgerKeyTrustLine", [ - ["accountId", xdr.lookup("AccountId")], - ["asset", xdr.lookup("Asset")], -]); +xdr.union("AccountMergeResult", { + switchOn: xdr.lookup("AccountMergeResultCode"), + switchName: "code", + switches: [ + ["accountMergeSuccess", "sourceAccountBalance"], + ], + arms: { + sourceAccountBalance: xdr.lookup("Int64"), + }, + defaultArm: xdr.void(), +}); // === xdr source ============================================================ // -// struct -// { -// AccountID sellerID; -// uint64 offerID; -// } +// enum InflationResultCode +// { +// // codes considered as "success" for the operation +// INFLATION_SUCCESS = 0, +// // codes considered as "failure" for the operation +// INFLATION_NOT_TIME = -1 +// }; // // =========================================================================== -xdr.struct("LedgerKeyOffer", [ - ["sellerId", xdr.lookup("AccountId")], - ["offerId", xdr.lookup("Uint64")], -]); +xdr.enum("InflationResultCode", { + inflationSuccess: 0, + inflationNotTime: -1, +}); // === xdr source ============================================================ // -// struct -// { -// AccountID accountID; -// string64 dataName; -// } +// struct InflationPayout // or use PaymentResultAtom to limit types? +// { +// AccountID destination; +// int64 amount; +// }; // // =========================================================================== -xdr.struct("LedgerKeyData", [ - ["accountId", xdr.lookup("AccountId")], - ["dataName", xdr.lookup("String64")], +xdr.struct("InflationPayout", [ + ["destination", xdr.lookup("AccountId")], + ["amount", xdr.lookup("Int64")], ]); // === xdr source ============================================================ // -// union LedgerKey switch (LedgerEntryType type) +// union InflationResult switch (InflationResultCode code) // { -// 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; +// case INFLATION_SUCCESS: +// InflationPayout payouts<>; +// default: +// void; // }; // // =========================================================================== -xdr.union("LedgerKey", { - switchOn: xdr.lookup("LedgerEntryType"), - switchName: "type", +xdr.union("InflationResult", { + switchOn: xdr.lookup("InflationResultCode"), + switchName: "code", switches: [ - ["account", "account"], - ["trustline", "trustLine"], - ["offer", "offer"], - ["datum", "data"], + ["inflationSuccess", "payouts"], ], arms: { - account: xdr.lookup("LedgerKeyAccount"), - trustLine: xdr.lookup("LedgerKeyTrustLine"), - offer: xdr.lookup("LedgerKeyOffer"), - data: xdr.lookup("LedgerKeyData"), + payouts: xdr.varArray(xdr.lookup("InflationPayout"), 2147483647), }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// enum BucketEntryType +// enum ManageDataResultCode // { -// LIVEENTRY = 0, -// DEADENTRY = 1 +// // 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.enum("BucketEntryType", { - liveentry: 0, - deadentry: 1, +xdr.enum("ManageDataResultCode", { + manageDataSuccess: 0, + manageDataNotSupportedYet: -1, + manageDataNameNotFound: -2, + manageDataLowReserve: -3, + manageDataInvalidName: -4, }); // === xdr source ============================================================ // -// union BucketEntry switch (BucketEntryType type) +// union ManageDataResult switch (ManageDataResultCode code) // { -// case LIVEENTRY: -// LedgerEntry liveEntry; -// -// case DEADENTRY: -// LedgerKey deadEntry; +// case MANAGE_DATA_SUCCESS: +// void; +// default: +// void; // }; // // =========================================================================== -xdr.union("BucketEntry", { - switchOn: xdr.lookup("BucketEntryType"), - switchName: "type", +xdr.union("ManageDataResult", { + switchOn: xdr.lookup("ManageDataResultCode"), + switchName: "code", switches: [ - ["liveentry", "liveEntry"], - ["deadentry", "deadEntry"], + ["manageDataSuccess", xdr.void()], ], arms: { - liveEntry: xdr.lookup("LedgerEntry"), - deadEntry: xdr.lookup("LedgerKey"), }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// struct TransactionSet +// enum BumpSequenceResultCode // { -// Hash previousLedgerHash; -// TransactionEnvelope txs<>; +// // codes considered as "success" for the operation +// BUMP_SEQUENCE_SUCCESS = 0, +// // codes considered as "failure" for the operation +// BUMP_SEQUENCE_BAD_SEQ = -1 // `bumpTo` is not within bounds // }; // // =========================================================================== -xdr.struct("TransactionSet", [ - ["previousLedgerHash", xdr.lookup("Hash")], - ["txes", xdr.varArray(xdr.lookup("TransactionEnvelope"), 2147483647)], -]); +xdr.enum("BumpSequenceResultCode", { + bumpSequenceSuccess: 0, + bumpSequenceBadSeq: -1, +}); // === xdr source ============================================================ // -// struct TransactionResultPair +// union BumpSequenceResult switch (BumpSequenceResultCode code) // { -// Hash transactionHash; -// TransactionResult result; // result for the transaction +// case BUMP_SEQUENCE_SUCCESS: +// void; +// default: +// void; // }; // // =========================================================================== -xdr.struct("TransactionResultPair", [ - ["transactionHash", xdr.lookup("Hash")], - ["result", xdr.lookup("TransactionResult")], -]); +xdr.union("BumpSequenceResult", { + switchOn: xdr.lookup("BumpSequenceResultCode"), + switchName: "code", + switches: [ + ["bumpSequenceSuccess", xdr.void()], + ], + arms: { + }, + defaultArm: xdr.void(), +}); // === xdr source ============================================================ // -// struct TransactionResultSet +// enum OperationResultCode // { -// TransactionResultPair results<>; +// opINNER = 0, // inner object result is valid +// +// opBAD_AUTH = -1, // too few valid signatures / wrong network +// opNO_ACCOUNT = -2, // source account was not found +// opNOT_SUPPORTED = -3, // operation not supported at this time +// opTOO_MANY_SUBENTRIES = -4, // max number of subentries already reached +// opEXCEEDED_WORK_LIMIT = -5 // operation did too much work // }; // // =========================================================================== -xdr.struct("TransactionResultSet", [ - ["results", xdr.varArray(xdr.lookup("TransactionResultPair"), 2147483647)], -]); +xdr.enum("OperationResultCode", { + opInner: 0, + opBadAuth: -1, + opNoAccount: -2, + opNotSupported: -3, + opTooManySubentry: -4, + opExceededWorkLimit: -5, +}); // === xdr source ============================================================ // -// union switch (int v) +// union switch (OperationType type) // { -// case 0: -// void; +// case CREATE_ACCOUNT: +// CreateAccountResult createAccountResult; +// case PAYMENT: +// PaymentResult paymentResult; +// case PATH_PAYMENT: +// PathPaymentResult pathPaymentResult; +// case MANAGE_SELL_OFFER: +// ManageSellOfferResult manageSellOfferResult; +// case CREATE_PASSIVE_SELL_OFFER: +// ManageSellOfferResult createPassiveSellOfferResult; +// 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; +// case BUMP_SEQUENCE: +// BumpSequenceResult bumpSeqResult; +// case MANAGE_BUY_OFFER: +// ManageBuyOfferResult manageBuyOfferResult; // } // // =========================================================================== -xdr.union("TransactionHistoryEntryExt", { - switchOn: xdr.int(), - switchName: "v", +xdr.union("OperationResultTr", { + switchOn: xdr.lookup("OperationType"), + switchName: "type", switches: [ - [0, xdr.void()], + ["createAccount", "createAccountResult"], + ["payment", "paymentResult"], + ["pathPayment", "pathPaymentResult"], + ["manageSellOffer", "manageSellOfferResult"], + ["createPassiveSellOffer", "createPassiveSellOfferResult"], + ["setOption", "setOptionsResult"], + ["changeTrust", "changeTrustResult"], + ["allowTrust", "allowTrustResult"], + ["accountMerge", "accountMergeResult"], + ["inflation", "inflationResult"], + ["manageDatum", "manageDataResult"], + ["bumpSequence", "bumpSeqResult"], + ["manageBuyOffer", "manageBuyOfferResult"], ], arms: { + createAccountResult: xdr.lookup("CreateAccountResult"), + paymentResult: xdr.lookup("PaymentResult"), + pathPaymentResult: xdr.lookup("PathPaymentResult"), + manageSellOfferResult: xdr.lookup("ManageSellOfferResult"), + createPassiveSellOfferResult: xdr.lookup("ManageSellOfferResult"), + setOptionsResult: xdr.lookup("SetOptionsResult"), + changeTrustResult: xdr.lookup("ChangeTrustResult"), + allowTrustResult: xdr.lookup("AllowTrustResult"), + accountMergeResult: xdr.lookup("AccountMergeResult"), + inflationResult: xdr.lookup("InflationResult"), + manageDataResult: xdr.lookup("ManageDataResult"), + bumpSeqResult: xdr.lookup("BumpSequenceResult"), + manageBuyOfferResult: xdr.lookup("ManageBuyOfferResult"), }, }); // === xdr source ============================================================ // -// struct TransactionHistoryEntry +// union OperationResult switch (OperationResultCode code) // { -// uint32 ledgerSeq; -// TransactionSet txSet; -// -// // reserved for future use -// union switch (int v) +// case opINNER: +// union switch (OperationType type) // { -// case 0: -// void; +// case CREATE_ACCOUNT: +// CreateAccountResult createAccountResult; +// case PAYMENT: +// PaymentResult paymentResult; +// case PATH_PAYMENT: +// PathPaymentResult pathPaymentResult; +// case MANAGE_SELL_OFFER: +// ManageSellOfferResult manageSellOfferResult; +// case CREATE_PASSIVE_SELL_OFFER: +// ManageSellOfferResult createPassiveSellOfferResult; +// 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; +// case BUMP_SEQUENCE: +// BumpSequenceResult bumpSeqResult; +// case MANAGE_BUY_OFFER: +// ManageBuyOfferResult manageBuyOfferResult; // } -// ext; +// tr; +// default: +// void; // }; // // =========================================================================== -xdr.struct("TransactionHistoryEntry", [ - ["ledgerSeq", xdr.lookup("Uint32")], - ["txSet", xdr.lookup("TransactionSet")], - ["ext", xdr.lookup("TransactionHistoryEntryExt")], -]); - -// === xdr source ============================================================ -// -// union switch (int v) -// { -// case 0: -// void; -// } -// -// =========================================================================== -xdr.union("TransactionHistoryResultEntryExt", { - switchOn: xdr.int(), - switchName: "v", +xdr.union("OperationResult", { + switchOn: xdr.lookup("OperationResultCode"), + switchName: "code", switches: [ - [0, xdr.void()], + ["opInner", "tr"], ], arms: { + tr: xdr.lookup("OperationResultTr"), }, + defaultArm: xdr.void(), }); // === xdr source ============================================================ // -// struct TransactionHistoryResultEntry +// enum TransactionResultCode // { -// uint32 ledgerSeq; -// TransactionResultSet txResultSet; +// txSUCCESS = 0, // all operations succeeded // -// // reserved for future use -// union switch (int v) -// { -// case 0: -// void; -// } -// ext; +// 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 // }; // // =========================================================================== -xdr.struct("TransactionHistoryResultEntry", [ - ["ledgerSeq", xdr.lookup("Uint32")], - ["txResultSet", xdr.lookup("TransactionResultSet")], - ["ext", xdr.lookup("TransactionHistoryResultEntryExt")], -]); +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 ============================================================ +// +// union switch (TransactionResultCode code) +// { +// case txSUCCESS: +// case txFAILED: +// OperationResult results<>; +// default: +// void; +// } +// +// =========================================================================== +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 ============================================================ // @@ -3469,7 +3633,7 @@ xdr.struct("TransactionHistoryResultEntry", [ // } // // =========================================================================== -xdr.union("LedgerHeaderHistoryEntryExt", { +xdr.union("TransactionResultExt", { switchOn: xdr.int(), switchName: "v", switches: [ @@ -3481,10 +3645,19 @@ xdr.union("LedgerHeaderHistoryEntryExt", { // === xdr source ============================================================ // -// struct LedgerHeaderHistoryEntry +// struct TransactionResult // { -// Hash hash; -// LedgerHeader header; +// int64 feeCharged; // actual fee charged for the transaction +// +// union switch (TransactionResultCode code) +// { +// case txSUCCESS: +// case txFAILED: +// OperationResult results<>; +// default: +// void; +// } +// result; // // // reserved for future use // union switch (int v) @@ -3496,166 +3669,216 @@ xdr.union("LedgerHeaderHistoryEntryExt", { // }; // // =========================================================================== -xdr.struct("LedgerHeaderHistoryEntry", [ - ["hash", xdr.lookup("Hash")], - ["header", xdr.lookup("LedgerHeader")], - ["ext", xdr.lookup("LedgerHeaderHistoryEntryExt")], +xdr.struct("TransactionResult", [ + ["feeCharged", xdr.lookup("Int64")], + ["result", xdr.lookup("TransactionResultResult")], + ["ext", xdr.lookup("TransactionResultExt")], ]); // === xdr source ============================================================ // -// struct LedgerSCPMessages +// typedef opaque Hash[32]; +// +// =========================================================================== +xdr.typedef("Hash", xdr.opaque(32)); + +// === xdr source ============================================================ +// +// typedef opaque uint256[32]; +// +// =========================================================================== +xdr.typedef("Uint256", xdr.opaque(32)); + +// === xdr source ============================================================ +// +// typedef unsigned int uint32; +// +// =========================================================================== +xdr.typedef("Uint32", xdr.uint()); + +// === xdr source ============================================================ +// +// typedef int int32; +// +// =========================================================================== +xdr.typedef("Int32", xdr.int()); + +// === xdr source ============================================================ +// +// typedef unsigned hyper uint64; +// +// =========================================================================== +xdr.typedef("Uint64", xdr.uhyper()); + +// === xdr source ============================================================ +// +// typedef hyper int64; +// +// =========================================================================== +xdr.typedef("Int64", xdr.hyper()); + +// === xdr source ============================================================ +// +// enum CryptoKeyType // { -// uint32 ledgerSeq; -// SCPEnvelope messages<>; +// KEY_TYPE_ED25519 = 0, +// KEY_TYPE_PRE_AUTH_TX = 1, +// KEY_TYPE_HASH_X = 2 // }; // // =========================================================================== -xdr.struct("LedgerScpMessages", [ - ["ledgerSeq", xdr.lookup("Uint32")], - ["messages", xdr.varArray(xdr.lookup("ScpEnvelope"), 2147483647)], -]); +xdr.enum("CryptoKeyType", { + keyTypeEd25519: 0, + keyTypePreAuthTx: 1, + keyTypeHashX: 2, +}); // === xdr source ============================================================ // -// struct SCPHistoryEntryV0 +// enum PublicKeyType // { -// SCPQuorumSet quorumSets<>; // additional quorum sets used by ledgerMessages -// LedgerSCPMessages ledgerMessages; +// PUBLIC_KEY_TYPE_ED25519 = KEY_TYPE_ED25519 // }; // // =========================================================================== -xdr.struct("ScpHistoryEntryV0", [ - ["quorumSets", xdr.varArray(xdr.lookup("ScpQuorumSet"), 2147483647)], - ["ledgerMessages", xdr.lookup("LedgerScpMessages")], -]); +xdr.enum("PublicKeyType", { + publicKeyTypeEd25519: 0, +}); // === xdr source ============================================================ // -// union SCPHistoryEntry switch (int v) +// enum SignerKeyType // { -// case 0: -// SCPHistoryEntryV0 v0; +// 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.union("ScpHistoryEntry", { - switchOn: xdr.int(), - switchName: "v", - switches: [ - [0, "v0"], - ], - arms: { - v0: xdr.lookup("ScpHistoryEntryV0"), - }, +xdr.enum("SignerKeyType", { + signerKeyTypeEd25519: 0, + signerKeyTypePreAuthTx: 1, + signerKeyTypeHashX: 2, }); // === xdr source ============================================================ // -// enum LedgerEntryChangeType +// union PublicKey switch (PublicKeyType type) // { -// 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 +// case PUBLIC_KEY_TYPE_ED25519: +// uint256 ed25519; // }; // // =========================================================================== -xdr.enum("LedgerEntryChangeType", { - ledgerEntryCreated: 0, - ledgerEntryUpdated: 1, - ledgerEntryRemoved: 2, - ledgerEntryState: 3, +xdr.union("PublicKey", { + switchOn: xdr.lookup("PublicKeyType"), + switchName: "type", + switches: [ + ["publicKeyTypeEd25519", "ed25519"], + ], + arms: { + ed25519: xdr.lookup("Uint256"), + }, }); // === xdr source ============================================================ // -// union LedgerEntryChange switch (LedgerEntryChangeType type) +// union SignerKey switch (SignerKeyType type) // { -// 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 SIGNER_KEY_TYPE_ED25519: +// uint256 ed25519; +// case SIGNER_KEY_TYPE_PRE_AUTH_TX: +// /* SHA-256 Hash of TransactionSignaturePayload structure */ +// uint256 preAuthTx; +// case SIGNER_KEY_TYPE_HASH_X: +// /* Hash of random 256 bit preimage X */ +// uint256 hashX; // }; // // =========================================================================== -xdr.union("LedgerEntryChange", { - switchOn: xdr.lookup("LedgerEntryChangeType"), +xdr.union("SignerKey", { + switchOn: xdr.lookup("SignerKeyType"), switchName: "type", switches: [ - ["ledgerEntryCreated", "created"], - ["ledgerEntryUpdated", "updated"], - ["ledgerEntryRemoved", "removed"], - ["ledgerEntryState", "state"], + ["signerKeyTypeEd25519", "ed25519"], + ["signerKeyTypePreAuthTx", "preAuthTx"], + ["signerKeyTypeHashX", "hashX"], ], arms: { - created: xdr.lookup("LedgerEntry"), - updated: xdr.lookup("LedgerEntry"), - removed: xdr.lookup("LedgerKey"), - state: xdr.lookup("LedgerEntry"), + ed25519: xdr.lookup("Uint256"), + preAuthTx: xdr.lookup("Uint256"), + hashX: xdr.lookup("Uint256"), }, }); // === xdr source ============================================================ // -// typedef LedgerEntryChange LedgerEntryChanges<>; +// typedef opaque Signature<64>; // // =========================================================================== -xdr.typedef("LedgerEntryChanges", xdr.varArray(xdr.lookup("LedgerEntryChange"), 2147483647)); +xdr.typedef("Signature", xdr.varOpaque(64)); // === xdr source ============================================================ // -// struct OperationMeta +// typedef opaque SignatureHint[4]; +// +// =========================================================================== +xdr.typedef("SignatureHint", xdr.opaque(4)); + +// === xdr source ============================================================ +// +// typedef PublicKey NodeID; +// +// =========================================================================== +xdr.typedef("NodeId", xdr.lookup("PublicKey")); + +// === xdr source ============================================================ +// +// struct Curve25519Secret // { -// LedgerEntryChanges changes; +// opaque key[32]; // }; // // =========================================================================== -xdr.struct("OperationMeta", [ - ["changes", xdr.lookup("LedgerEntryChanges")], +xdr.struct("Curve25519Secret", [ + ["key", xdr.opaque(32)], ]); // === xdr source ============================================================ // -// struct TransactionMetaV1 +// struct Curve25519Public // { -// LedgerEntryChanges txChanges; // tx level changes if any -// OperationMeta operations<>; // meta for each operation +// opaque key[32]; // }; // // =========================================================================== -xdr.struct("TransactionMetaV1", [ - ["txChanges", xdr.lookup("LedgerEntryChanges")], - ["operations", xdr.varArray(xdr.lookup("OperationMeta"), 2147483647)], +xdr.struct("Curve25519Public", [ + ["key", xdr.opaque(32)], ]); // === xdr source ============================================================ // -// union TransactionMeta switch (int v) +// struct HmacSha256Key // { -// case 0: -// OperationMeta operations<>; -// case 1: -// TransactionMetaV1 v1; +// opaque key[32]; // }; // // =========================================================================== -xdr.union("TransactionMeta", { - switchOn: xdr.int(), - switchName: "v", - switches: [ - [0, "operations"], - [1, "v1"], - ], - arms: { - operations: xdr.varArray(xdr.lookup("OperationMeta"), 2147483647), - v1: xdr.lookup("TransactionMetaV1"), - }, -}); +xdr.struct("HmacSha256Key", [ + ["key", xdr.opaque(32)], +]); + +// === xdr source ============================================================ +// +// struct HmacSha256Mac +// { +// opaque mac[32]; +// }; +// +// =========================================================================== +xdr.struct("HmacSha256Mac", [ + ["mac", xdr.opaque(32)], +]); }); export default types; diff --git a/src/operation.js b/src/operation.js index 22a731b92..c50ec1514 100644 --- a/src/operation.js +++ b/src/operation.js @@ -45,8 +45,9 @@ export const AuthImmutableFlag = 1 << 2; * * `{@link Operation.createAccount}` * * `{@link Operation.payment}` * * `{@link Operation.pathPayment}` - * * `{@link Operation.manageOffer}` - * * `{@link Operation.createPassiveOffer}` + * * `{@link Operation.manageSellOffer}` + * * `{@link Operation.manageBuyOffer}` + * * `{@link Operation.createPassiveSellOffer}` * * `{@link Operation.setOptions}` * * `{@link Operation.changeTrust}` * * `{@link Operation.allowTrust}` @@ -178,8 +179,8 @@ export class Operation { } break; } - case 'manageOffer': { - result.type = 'manageOffer'; + case 'manageSellOffer': { + result.type = 'manageSellOffer'; result.selling = Asset.fromOperation(attrs.selling()); result.buying = Asset.fromOperation(attrs.buying()); result.amount = this._fromXDRAmount(attrs.amount()); @@ -187,8 +188,17 @@ export class Operation { result.offerId = attrs.offerId().toString(); break; } - case 'createPassiveOffer': { - result.type = 'createPassiveOffer'; + case 'manageBuyOffer': { + result.type = 'manageBuyOffer'; + result.selling = Asset.fromOperation(attrs.selling()); + result.buying = Asset.fromOperation(attrs.buying()); + result.buyAmount = this._fromXDRAmount(attrs.buyAmount()); + result.price = this._fromXDRPrice(attrs.price()); + result.offerId = attrs.offerId().toString(); + break; + } + case 'createPassiveSellOffer': { + result.type = 'createPassiveSellOffer'; result.selling = Asset.fromOperation(attrs.selling()); result.buying = Asset.fromOperation(attrs.buying()); result.amount = this._fromXDRAmount(attrs.amount()); @@ -354,10 +364,11 @@ Operation.allowTrust = ops.allowTrust; Operation.bumpSequence = ops.bumpSequence; Operation.changeTrust = ops.changeTrust; Operation.createAccount = ops.createAccount; -Operation.createPassiveOffer = ops.createPassiveOffer; +Operation.createPassiveSellOffer = ops.createPassiveSellOffer; Operation.inflation = ops.inflation; Operation.manageData = ops.manageData; -Operation.manageOffer = ops.manageOffer; +Operation.manageSellOffer = ops.manageSellOffer; +Operation.manageBuyOffer = ops.manageBuyOffer; Operation.pathPayment = ops.pathPayment; Operation.payment = ops.payment; Operation.setOptions = ops.setOptions; diff --git a/src/operations/create_passive_offer.js b/src/operations/create_passive_sell_offer.js similarity index 78% rename from src/operations/create_passive_offer.js rename to src/operations/create_passive_sell_offer.js index 573ab5de3..93d1e0812 100644 --- a/src/operations/create_passive_offer.js +++ b/src/operations/create_passive_sell_offer.js @@ -2,12 +2,12 @@ import isUndefined from 'lodash/isUndefined'; import xdr from '../generated/stellar-xdr_generated'; /** - * Returns a XDR CreatePasiveOfferOp. A "create passive offer" operation creates an + * Returns a XDR CreatePasiveSellOfferOp. A "create passive offer" operation creates an * offer that won't consume a counter offer that exactly matches this offer. This is * useful for offers just used as 1:1 exchanges for path payments. Use manage offer * to manage this offer after using this operation to create it. * @function - * @alias Operation.createPassiveOffer + * @alias Operation.createPassiveSellOffer * @param {object} opts Options object * @param {Asset} opts.selling - What you're selling. * @param {Asset} opts.buying - What you're buying. @@ -17,9 +17,9 @@ import xdr from '../generated/stellar-xdr_generated'; * @param {number} opts.price.d - If `opts.price` is an object: the price denominator * @param {string} [opts.source] - The source account (defaults to transaction source). * @throws {Error} Throws `Error` when the best rational approximation of `price` cannot be found. - * @returns {xdr.CreatePassiveOfferOp} Create Passive Offer operation + * @returns {xdr.CreatePassiveSellOfferOp} Create Passive Sell Offer operation */ -export function createPassiveOffer(opts) { +export function createPassiveSellOffer(opts) { const attributes = {}; attributes.selling = opts.selling.toXDRObject(); attributes.buying = opts.buying.toXDRObject(); @@ -31,11 +31,11 @@ export function createPassiveOffer(opts) { throw new TypeError('price argument is required'); } attributes.price = this._toXDRPrice(opts.price); - const createPassiveOfferOp = new xdr.CreatePassiveOfferOp(attributes); + const createPassiveSellOfferOp = new xdr.CreatePassiveSellOfferOp(attributes); const opAttributes = {}; - opAttributes.body = xdr.OperationBody.createPassiveOffer( - createPassiveOfferOp + opAttributes.body = xdr.OperationBody.createPassiveSellOffer( + createPassiveSellOfferOp ); this.setSourceAccount(opAttributes, opts); diff --git a/src/operations/index.js b/src/operations/index.js index 1dec1af3c..9e4dc9772 100644 --- a/src/operations/index.js +++ b/src/operations/index.js @@ -3,10 +3,11 @@ export { allowTrust } from './allow_trust'; export { bumpSequence } from './bump_sequence'; export { changeTrust } from './change_trust'; export { createAccount } from './create_account'; -export { createPassiveOffer } from './create_passive_offer'; +export { createPassiveSellOffer } from './create_passive_sell_offer'; export { inflation } from './inflation'; export { manageData } from './manage_data'; -export { manageOffer } from './manage_offer'; +export { manageSellOffer } from './manage_sell_offer'; +export { manageBuyOffer } from './manage_buy_offer'; export { pathPayment } from './path_payment'; export { payment } from './payment'; export { setOptions } from './set_options'; diff --git a/src/operations/manage_buy_offer.js b/src/operations/manage_buy_offer.js new file mode 100644 index 000000000..345afc464 --- /dev/null +++ b/src/operations/manage_buy_offer.js @@ -0,0 +1,48 @@ +import isUndefined from 'lodash/isUndefined'; +import { Hyper } from 'js-xdr'; +import xdr from '../generated/stellar-xdr_generated'; +/** + * Returns a XDR ManageBuyOfferOp. A "manage buy offer" operation creates, updates, or + * deletes a buy offer. + * @function + * @alias Operation.manageBuyOffer + * @param {object} opts Options object + * @param {Asset} opts.selling - What you're selling. + * @param {Asset} opts.buying - What you're buying. + * @param {string} opts.buyAmount - The total amount you're buying. If 0, deletes the offer. + * @param {number|string|BigNumber|Object} opts.price - Price of 1 unit of `selling` in terms of `buying`. + * @param {number} opts.price.n - If `opts.price` is an object: the price numerator + * @param {number} opts.price.d - If `opts.price` is an object: the price denominator + * @param {number|string} [opts.offerId ] - If `0`, will create a new offer (default). Otherwise, edits an exisiting offer. + * @param {string} [opts.source] - The source account (defaults to transaction source). + * @throws {Error} Throws `Error` when the best rational approximation of `price` cannot be found. + * @returns {xdr.ManageBuyOfferOp} Manage Buy Offer operation + */ +export function manageBuyOffer(opts) { + const attributes = {}; + attributes.selling = opts.selling.toXDRObject(); + attributes.buying = opts.buying.toXDRObject(); + if (!this.isValidAmount(opts.buyAmount, true)) { + throw new TypeError(this.constructAmountRequirementsError('buyAmount')); + } + attributes.buyAmount = this._toXDRAmount(opts.buyAmount); + if (isUndefined(opts.price)) { + throw new TypeError('price argument is required'); + } + attributes.price = this._toXDRPrice(opts.price); + + if (!isUndefined(opts.offerId)) { + opts.offerId = opts.offerId.toString(); + } else { + opts.offerId = '0'; + } + + attributes.offerId = Hyper.fromString(opts.offerId); + const manageBuyOfferOp = new xdr.ManageBuyOfferOp(attributes); + + const opAttributes = {}; + opAttributes.body = xdr.OperationBody.manageBuyOffer(manageBuyOfferOp); + this.setSourceAccount(opAttributes, opts); + + return new xdr.Operation(opAttributes); +} diff --git a/src/operations/manage_offer.js b/src/operations/manage_sell_offer.js similarity index 78% rename from src/operations/manage_offer.js rename to src/operations/manage_sell_offer.js index fbbd9d3b0..4bb7f3881 100644 --- a/src/operations/manage_offer.js +++ b/src/operations/manage_sell_offer.js @@ -1,11 +1,11 @@ import isUndefined from 'lodash/isUndefined'; -import { UnsignedHyper } from 'js-xdr'; +import { Hyper } from 'js-xdr'; import xdr from '../generated/stellar-xdr_generated'; /** - * Returns a XDR ManageOfferOp. A "manage offer" operation creates, updates, or + * Returns a XDR ManageSellOfferOp. A "manage sell offer" operation creates, updates, or * deletes an offer. * @function - * @alias Operation.manageOffer + * @alias Operation.manageSellOffer * @param {object} opts Options object * @param {Asset} opts.selling - What you're selling. * @param {Asset} opts.buying - What you're buying. @@ -16,9 +16,9 @@ import xdr from '../generated/stellar-xdr_generated'; * @param {number|string} [opts.offerId ] - If `0`, will create a new offer (default). Otherwise, edits an exisiting offer. * @param {string} [opts.source] - The source account (defaults to transaction source). * @throws {Error} Throws `Error` when the best rational approximation of `price` cannot be found. - * @returns {xdr.ManageOfferOp} Manage Offer operation + * @returns {xdr.ManageSellOfferOp} Manage Sell Offer operation */ -export function manageOffer(opts) { +export function manageSellOffer(opts) { const attributes = {}; attributes.selling = opts.selling.toXDRObject(); attributes.buying = opts.buying.toXDRObject(); @@ -37,11 +37,11 @@ export function manageOffer(opts) { opts.offerId = '0'; } - attributes.offerId = UnsignedHyper.fromString(opts.offerId); - const manageOfferOp = new xdr.ManageOfferOp(attributes); + attributes.offerId = Hyper.fromString(opts.offerId); + const manageSellOfferOp = new xdr.ManageSellOfferOp(attributes); const opAttributes = {}; - opAttributes.body = xdr.OperationBody.manageOffer(manageOfferOp); + opAttributes.body = xdr.OperationBody.manageSellOffer(manageSellOfferOp); this.setSourceAccount(opAttributes, opts); return new xdr.Operation(opAttributes); diff --git a/test/unit/operation_test.js b/test/unit/operation_test.js index 3fa80c9dc..497b6d41d 100644 --- a/test/unit/operation_test.js +++ b/test/unit/operation_test.js @@ -1,5 +1,6 @@ import BigNumber from 'bignumber.js'; import isString from 'lodash/isString'; +import { Hyper } from 'js-xdr'; describe('Operation', function() { describe('.createAccount()', function() { @@ -619,8 +620,8 @@ describe('Operation', function() { }); }); - describe('.manageOffer', function() { - it('creates a manageOfferOp (string price)', function() { + describe('.manageSellOffer', function() { + it('creates a manageSellOfferOp (string price)', function() { var opts = {}; opts.selling = new StellarBase.Asset( 'USD', @@ -633,13 +634,13 @@ describe('Operation', function() { opts.amount = '3.1234560'; opts.price = '8.141592'; opts.offerId = '1'; - let op = StellarBase.Operation.manageOffer(opts); + let op = StellarBase.Operation.manageSellOffer(opts); var xdr = op.toXDR('hex'); var operation = StellarBase.xdr.Operation.fromXDR( Buffer.from(xdr, 'hex') ); var obj = StellarBase.Operation.fromXDRObject(operation); - expect(obj.type).to.be.equal('manageOffer'); + expect(obj.type).to.be.equal('manageSellOffer'); expect(obj.selling.equals(opts.selling)).to.be.true; expect(obj.buying.equals(opts.buying)).to.be.true; expect( @@ -653,7 +654,8 @@ describe('Operation', function() { expect(obj.price).to.be.equal(opts.price); expect(obj.offerId).to.be.equal(opts.offerId); }); - it('creates a manageOfferOp (price fraction)', function() { + + it('creates a manageSellOfferOp (price fraction)', function() { var opts = {}; opts.selling = new StellarBase.Asset( 'USD', @@ -669,7 +671,7 @@ describe('Operation', function() { d: 10 }; opts.offerId = '1'; - let op = StellarBase.Operation.manageOffer(opts); + let op = StellarBase.Operation.manageSellOffer(opts); var xdr = op.toXDR('hex'); var operation = StellarBase.xdr.Operation.fromXDR( Buffer.from(xdr, 'hex') @@ -680,7 +682,7 @@ describe('Operation', function() { ); }); - it('creates an invalid manageOfferOp (price fraction)', function() { + it('creates an invalid manageSellOfferOp (price fraction)', function() { var opts = {}; opts.selling = new StellarBase.Asset( 'USD', @@ -696,11 +698,12 @@ describe('Operation', function() { d: -1 }; opts.offerId = '1'; - expect(() => StellarBase.Operation.manageOffer(opts)).to.throw( + expect(() => StellarBase.Operation.manageSellOffer(opts)).to.throw( /price must be positive/ ); }); - it('creates a manageOfferOp (number price)', function() { + + it('creates a manageSellOfferOp (number price)', function() { var opts = {}; opts.selling = new StellarBase.Asset( 'USD', @@ -712,18 +715,18 @@ describe('Operation', function() { ); opts.amount = '3.123456'; opts.price = 3.07; - opts.offerId = 1; - let op = StellarBase.Operation.manageOffer(opts); + opts.offerId = '1'; + let op = StellarBase.Operation.manageSellOffer(opts); var xdr = op.toXDR('hex'); var operation = StellarBase.xdr.Operation.fromXDR( Buffer.from(xdr, 'hex') ); var obj = StellarBase.Operation.fromXDRObject(operation); - expect(obj.type).to.be.equal('manageOffer'); + expect(obj.type).to.be.equal('manageSellOffer'); expect(obj.price).to.be.equal(opts.price.toString()); }); - it('creates a manageOfferOp (BigNumber price)', function() { + it('creates a manageSellOfferOp (BigNumber price)', function() { var opts = {}; opts.selling = new StellarBase.Asset( 'USD', @@ -736,17 +739,17 @@ describe('Operation', function() { opts.amount = '3.123456'; opts.price = new BigNumber(5).dividedBy(4); opts.offerId = '1'; - let op = StellarBase.Operation.manageOffer(opts); + let op = StellarBase.Operation.manageSellOffer(opts); var xdr = op.toXDR('hex'); var operation = StellarBase.xdr.Operation.fromXDR( Buffer.from(xdr, 'hex') ); var obj = StellarBase.Operation.fromXDRObject(operation); - expect(obj.type).to.be.equal('manageOffer'); + expect(obj.type).to.be.equal('manageSellOffer'); expect(obj.price).to.be.equal('1.25'); }); - it('creates a manageOfferOp with no offerId', function() { + it('creates a manageSellOfferOp with no offerId', function() { var opts = {}; opts.selling = new StellarBase.Asset( 'USD', @@ -758,13 +761,13 @@ describe('Operation', function() { ); opts.amount = '1000.0000000'; opts.price = '3.141592'; - let op = StellarBase.Operation.manageOffer(opts); + let op = StellarBase.Operation.manageSellOffer(opts); var xdr = op.toXDR('hex'); var operation = StellarBase.xdr.Operation.fromXDR( Buffer.from(xdr, 'hex') ); var obj = StellarBase.Operation.fromXDRObject(operation); - expect(obj.type).to.be.equal('manageOffer'); + expect(obj.type).to.be.equal('manageSellOffer'); expect(obj.selling.equals(opts.selling)).to.be.true; expect(obj.buying.equals(opts.buying)).to.be.true; expect( @@ -792,13 +795,13 @@ describe('Operation', function() { opts.amount = '0.0000000'; opts.price = '3.141592'; opts.offerId = '1'; - let op = StellarBase.Operation.manageOffer(opts); + let op = StellarBase.Operation.manageSellOffer(opts); var xdr = op.toXDR('hex'); var operation = StellarBase.xdr.Operation.fromXDR( Buffer.from(xdr, 'hex') ); var obj = StellarBase.Operation.fromXDRObject(operation); - expect(obj.type).to.be.equal('manageOffer'); + expect(obj.type).to.be.equal('manageSellOffer'); expect(obj.selling.equals(opts.selling)).to.be.true; expect(obj.buying.equals(opts.buying)).to.be.true; expect( @@ -813,7 +816,7 @@ describe('Operation', function() { expect(obj.offerId).to.be.equal('1'); // 0=create a new offer, otherwise edit an existing offer }); - it('fails to create manageOffer operation with an invalid amount', function() { + it('fails to create manageSellOffer operation with an invalid amount', function() { let opts = { amount: 20, price: '10', @@ -826,12 +829,12 @@ describe('Operation', function() { 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' ) }; - expect(() => StellarBase.Operation.manageOffer(opts)).to.throw( + expect(() => StellarBase.Operation.manageSellOffer(opts)).to.throw( /amount argument must be of type String/ ); }); - it('fails to create manageOffer operation with missing price', function() { + it('fails to create manageSellOffer operation with missing price', function() { let opts = { amount: '20', selling: new StellarBase.Asset( @@ -843,12 +846,12 @@ describe('Operation', function() { 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' ) }; - expect(() => StellarBase.Operation.manageOffer(opts)).to.throw( + expect(() => StellarBase.Operation.manageSellOffer(opts)).to.throw( /price argument is required/ ); }); - it('fails to create manageOffer operation with negative price', function() { + it('fails to create manageSellOffer operation with negative price', function() { let opts = { amount: '20', price: '-1', @@ -861,12 +864,12 @@ describe('Operation', function() { 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' ) }; - expect(() => StellarBase.Operation.manageOffer(opts)).to.throw( + expect(() => StellarBase.Operation.manageSellOffer(opts)).to.throw( /price must be positive/ ); }); - it('fails to create manageOffer operation with invalid price', function() { + it('fails to create manageSellOffer operation with invalid price', function() { let opts = { amount: '20', price: 'test', @@ -879,14 +882,282 @@ describe('Operation', function() { 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' ) }; - expect(() => StellarBase.Operation.manageOffer(opts)).to.throw( + expect(() => StellarBase.Operation.manageSellOffer(opts)).to.throw( + /not a number/ + ); + }); + }); + + describe('.manageBuyOffer', function() { + it('creates a manageBuyOfferOp (string price)', function() { + var opts = {}; + opts.selling = new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ); + opts.buying = new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ); + opts.buyAmount = '3.1234560'; + opts.price = '8.141592'; + opts.offerId = '1'; + let op = StellarBase.Operation.manageBuyOffer(opts); + var xdr = op.toXDR('hex'); + var operation = StellarBase.xdr.Operation.fromXDR( + Buffer.from(xdr, 'hex') + ); + var obj = StellarBase.Operation.fromXDRObject(operation); + expect(obj.type).to.be.equal('manageBuyOffer'); + expect(obj.selling.equals(opts.selling)).to.be.true; + expect(obj.buying.equals(opts.buying)).to.be.true; + expect( + operation + .body() + .value() + .buyAmount() + .toString() + ).to.be.equal('31234560'); + expect(obj.buyAmount).to.be.equal(opts.buyAmount); + expect(obj.price).to.be.equal(opts.price); + expect(obj.offerId).to.be.equal(opts.offerId); + }); + + it('creates a manageBuyOfferOp (price fraction)', function() { + var opts = {}; + opts.selling = new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ); + opts.buying = new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ); + opts.buyAmount = '3.123456'; + opts.price = { + n: 11, + d: 10 + }; + opts.offerId = '1'; + let op = StellarBase.Operation.manageBuyOffer(opts); + var xdr = op.toXDR('hex'); + var operation = StellarBase.xdr.Operation.fromXDR( + Buffer.from(xdr, 'hex') + ); + var obj = StellarBase.Operation.fromXDRObject(operation); + expect(obj.price).to.be.equal( + new BigNumber(opts.price.n).div(opts.price.d).toString() + ); + }); + + it('creates an invalid manageBuyOfferOp (price fraction)', function() { + var opts = {}; + opts.selling = new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ); + opts.buying = new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ); + opts.buyAmount = '3.123456'; + opts.price = { + n: 11, + d: -1 + }; + opts.offerId = '1'; + expect(() => StellarBase.Operation.manageBuyOffer(opts)).to.throw( + /price must be positive/ + ); + }); + + it('creates a manageBuyOfferOp (number price)', function() { + var opts = {}; + opts.selling = new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ); + opts.buying = new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ); + opts.buyAmount = '3.123456'; + opts.price = 3.07; + opts.offerId = '1'; + let op = StellarBase.Operation.manageBuyOffer(opts); + var xdr = op.toXDR('hex'); + var operation = StellarBase.xdr.Operation.fromXDR( + Buffer.from(xdr, 'hex') + ); + var obj = StellarBase.Operation.fromXDRObject(operation); + expect(obj.type).to.be.equal('manageBuyOffer'); + expect(obj.price).to.be.equal(opts.price.toString()); + }); + + it('creates a manageBuyOfferOp (BigNumber price)', function() { + var opts = {}; + opts.selling = new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ); + opts.buying = new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ); + opts.buyAmount = '3.123456'; + opts.price = new BigNumber(5).dividedBy(4); + opts.offerId = '1'; + let op = StellarBase.Operation.manageBuyOffer(opts); + var xdr = op.toXDR('hex'); + var operation = StellarBase.xdr.Operation.fromXDR( + Buffer.from(xdr, 'hex') + ); + var obj = StellarBase.Operation.fromXDRObject(operation); + expect(obj.type).to.be.equal('manageBuyOffer'); + expect(obj.price).to.be.equal('1.25'); + }); + + it('creates a manageBuyOfferOp with no offerId', function() { + var opts = {}; + opts.selling = new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ); + opts.buying = new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ); + opts.buyAmount = '1000.0000000'; + opts.price = '3.141592'; + let op = StellarBase.Operation.manageBuyOffer(opts); + var xdr = op.toXDR('hex'); + var operation = StellarBase.xdr.Operation.fromXDR( + Buffer.from(xdr, 'hex') + ); + var obj = StellarBase.Operation.fromXDRObject(operation); + expect(obj.type).to.be.equal('manageBuyOffer'); + expect(obj.selling.equals(opts.selling)).to.be.true; + expect(obj.buying.equals(opts.buying)).to.be.true; + expect( + operation + .body() + .value() + .buyAmount() + .toString() + ).to.be.equal('10000000000'); + expect(obj.buyAmount).to.be.equal(opts.buyAmount); + expect(obj.price).to.be.equal(opts.price); + expect(obj.offerId).to.be.equal('0'); // 0=create a new offer, otherwise edit an existing offer + }); + + it('cancels offer', function() { + var opts = {}; + opts.selling = new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ); + opts.buying = new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ); + opts.buyAmount = '0.0000000'; + opts.price = '3.141592'; + opts.offerId = '1'; + let op = StellarBase.Operation.manageBuyOffer(opts); + var xdr = op.toXDR('hex'); + var operation = StellarBase.xdr.Operation.fromXDR( + Buffer.from(xdr, 'hex') + ); + var obj = StellarBase.Operation.fromXDRObject(operation); + expect(obj.type).to.be.equal('manageBuyOffer'); + expect(obj.selling.equals(opts.selling)).to.be.true; + expect(obj.buying.equals(opts.buying)).to.be.true; + expect( + operation + .body() + .value() + .buyAmount() + .toString() + ).to.be.equal('0'); + expect(obj.buyAmount).to.be.equal(opts.buyAmount); + expect(obj.price).to.be.equal(opts.price); + expect(obj.offerId).to.be.equal('1'); // 0=create a new offer, otherwise edit an existing offer + }); + + it('fails to create manageBuyOffer operation with an invalid amount', function() { + let opts = { + buyAmount: 20, + price: '10', + selling: new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ), + buying: new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ) + }; + expect(() => StellarBase.Operation.manageBuyOffer(opts)).to.throw( + /buyAmount argument must be of type String/ + ); + }); + + it('fails to create manageBuyOffer operation with missing price', function() { + let opts = { + buyAmount: '20', + selling: new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ), + buying: new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ) + }; + expect(() => StellarBase.Operation.manageBuyOffer(opts)).to.throw( + /price argument is required/ + ); + }); + + it('fails to create manageBuyOffer operation with negative price', function() { + let opts = { + buyAmount: '20', + price: '-1', + selling: new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ), + buying: new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ) + }; + expect(() => StellarBase.Operation.manageBuyOffer(opts)).to.throw( + /price must be positive/ + ); + }); + + it('fails to create manageBuyOffer operation with invalid price', function() { + let opts = { + buyAmount: '20', + price: 'test', + selling: new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ), + buying: new StellarBase.Asset( + 'USD', + 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' + ) + }; + expect(() => StellarBase.Operation.manageBuyOffer(opts)).to.throw( /not a number/ ); }); }); - describe('.createPassiveOffer', function() { - it('creates a createPassiveOfferOp (string price)', function() { + describe('.createPassiveSellOffer', function() { + it('creates a createPassiveSellOfferOp (string price)', function() { var opts = {}; opts.selling = new StellarBase.Asset( 'USD', @@ -898,13 +1169,13 @@ describe('Operation', function() { ); opts.amount = '11.2782700'; opts.price = '3.07'; - let op = StellarBase.Operation.createPassiveOffer(opts); + let op = StellarBase.Operation.createPassiveSellOffer(opts); var xdr = op.toXDR('hex'); var operation = StellarBase.xdr.Operation.fromXDR( Buffer.from(xdr, 'hex') ); var obj = StellarBase.Operation.fromXDRObject(operation); - expect(obj.type).to.be.equal('createPassiveOffer'); + expect(obj.type).to.be.equal('createPassiveSellOffer'); expect(obj.selling.equals(opts.selling)).to.be.true; expect(obj.buying.equals(opts.buying)).to.be.true; expect( @@ -918,7 +1189,7 @@ describe('Operation', function() { expect(obj.price).to.be.equal(opts.price); }); - it('creates a createPassiveOfferOp (number price)', function() { + it('creates a createPassiveSellOfferOp (number price)', function() { var opts = {}; opts.selling = new StellarBase.Asset( 'USD', @@ -930,13 +1201,13 @@ describe('Operation', function() { ); opts.amount = '11.2782700'; opts.price = 3.07; - let op = StellarBase.Operation.createPassiveOffer(opts); + let op = StellarBase.Operation.createPassiveSellOffer(opts); var xdr = op.toXDR('hex'); var operation = StellarBase.xdr.Operation.fromXDR( Buffer.from(xdr, 'hex') ); var obj = StellarBase.Operation.fromXDRObject(operation); - expect(obj.type).to.be.equal('createPassiveOffer'); + expect(obj.type).to.be.equal('createPassiveSellOffer'); expect(obj.selling.equals(opts.selling)).to.be.true; expect(obj.buying.equals(opts.buying)).to.be.true; expect( @@ -950,7 +1221,7 @@ describe('Operation', function() { expect(obj.price).to.be.equal(opts.price.toString()); }); - it('creates a createPassiveOfferOp (BigNumber price)', function() { + it('creates a createPassiveSellOfferOp (BigNumber price)', function() { var opts = {}; opts.selling = new StellarBase.Asset( 'USD', @@ -962,13 +1233,13 @@ describe('Operation', function() { ); opts.amount = '11.2782700'; opts.price = new BigNumber(5).dividedBy(4); - let op = StellarBase.Operation.createPassiveOffer(opts); + let op = StellarBase.Operation.createPassiveSellOffer(opts); var xdr = op.toXDR('hex'); var operation = StellarBase.xdr.Operation.fromXDR( Buffer.from(xdr, 'hex') ); var obj = StellarBase.Operation.fromXDRObject(operation); - expect(obj.type).to.be.equal('createPassiveOffer'); + expect(obj.type).to.be.equal('createPassiveSellOffer'); expect(obj.selling.equals(opts.selling)).to.be.true; expect(obj.buying.equals(opts.buying)).to.be.true; expect( @@ -982,7 +1253,7 @@ describe('Operation', function() { expect(obj.price).to.be.equal('1.25'); }); - it('fails to create createPassiveOffer operation with an invalid amount', function() { + it('fails to create createPassiveSellOffer operation with an invalid amount', function() { let opts = { amount: 20, price: '10', @@ -995,12 +1266,12 @@ describe('Operation', function() { 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' ) }; - expect(() => StellarBase.Operation.createPassiveOffer(opts)).to.throw( + expect(() => StellarBase.Operation.createPassiveSellOffer(opts)).to.throw( /amount argument must be of type String/ ); }); - it('fails to create createPassiveOffer operation with missing price', function() { + it('fails to create createPassiveSellOffer operation with missing price', function() { let opts = { amount: '20', selling: new StellarBase.Asset( @@ -1012,12 +1283,12 @@ describe('Operation', function() { 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' ) }; - expect(() => StellarBase.Operation.createPassiveOffer(opts)).to.throw( + expect(() => StellarBase.Operation.createPassiveSellOffer(opts)).to.throw( /price argument is required/ ); }); - it('fails to create createPassiveOffer operation with negative price', function() { + it('fails to create createPassiveSellOffer operation with negative price', function() { let opts = { amount: '20', price: '-2', @@ -1030,7 +1301,7 @@ describe('Operation', function() { 'GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7' ) }; - expect(() => StellarBase.Operation.createPassiveOffer(opts)).to.throw( + expect(() => StellarBase.Operation.createPassiveSellOffer(opts)).to.throw( /price must be positive/ ); }); diff --git a/types/index.d.ts b/types/index.d.ts index cd4159f86..d72f8e477 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -191,8 +191,9 @@ export namespace OperationType { type CreateAccount = 'createAccount'; type Payment = 'payment'; type PathPayment = 'pathPayment'; - type CreatePassiveOffer = 'createPassiveOffer'; - type ManageOffer = 'manageOffer'; + type CreatePassiveSellOffer = 'createPassiveSellOffer'; + type ManageSellOffer = 'manageSellOffer'; + type ManageBuyOffer = 'manageBuyOffer'; type SetOptions = 'setOptions'; type ChangeTrust = 'changeTrust'; type AllowTrust = 'allowTrust'; @@ -205,8 +206,9 @@ export type OperationType = | OperationType.CreateAccount | OperationType.Payment | OperationType.PathPayment - | OperationType.CreatePassiveOffer - | OperationType.ManageOffer + | OperationType.CreatePassiveSellOffer + | OperationType.ManageSellOffer + | OperationType.ManageBuyOffer | OperationType.SetOptions | OperationType.ChangeTrust | OperationType.AllowTrust @@ -235,13 +237,20 @@ export namespace OperationOptions { destination: string; startingBalance: string; } - interface CreatePassiveOffer extends BaseOptions { + interface CreatePassiveSellOffer extends BaseOptions { selling: Asset; buying: Asset; amount: string; price: number | string | object /* bignumber.js */; } - interface ManageOffer extends CreatePassiveOffer { + interface ManageSellOffer extends CreatePassiveSellOffer { + offerId?: number | string; + } + interface ManageBuyOffer { + selling: Asset; + buying: Asset; + buyAmount: string; + price: number | string | object /* bignumber.js */; offerId?: number | string; } // tslint:disable-next-line @@ -284,8 +293,9 @@ export type OperationOptions = | OperationOptions.CreateAccount | OperationOptions.Payment | OperationOptions.PathPayment - | OperationOptions.CreatePassiveOffer - | OperationOptions.ManageOffer + | OperationOptions.CreatePassiveSellOffer + | OperationOptions.ManageSellOffer + | OperationOptions.ManageBuyOffer | OperationOptions.SetOptions | OperationOptions.ChangeTrust | OperationOptions.AllowTrust @@ -332,16 +342,16 @@ export namespace Operation { options: OperationOptions.CreateAccount ): xdr.Operation; - interface CreatePassiveOffer - extends BaseOperation { + interface CreatePassiveSellOffer + extends BaseOperation { selling: Asset; buying: Asset; amount: string; price: string; } - function createPassiveOffer( - options: OperationOptions.CreatePassiveOffer - ): xdr.Operation; + function createPassiveSellOffer( + options: OperationOptions.CreatePassiveSellOffer + ): xdr.Operation; interface Inflation extends BaseOperation {} function inflation( @@ -356,16 +366,28 @@ export namespace Operation { options: OperationOptions.ManageData ): xdr.Operation; - interface ManageOffer extends BaseOperation { + interface ManageSellOffer + extends BaseOperation { selling: Asset; buying: Asset; amount: string; price: string; offerId: string; } - function manageOffer( - options: OperationOptions.ManageOffer - ): xdr.Operation; + function manageSellOffer( + options: OperationOptions.ManageSellOffer + ): xdr.Operation; + + interface ManageBuyOffer extends BaseOperation { + selling: Asset; + buying: Asset; + buyAmount: string; + price: string; + offerId: string; + } + function manageBuyOffer( + options: OperationOptions.ManageBuyOffer + ): xdr.Operation; interface PathPayment extends BaseOperation { sendAsset: Asset; @@ -423,8 +445,9 @@ export type Operation = | Operation.CreateAccount | Operation.Payment | Operation.PathPayment - | Operation.CreatePassiveOffer - | Operation.ManageOffer + | Operation.CreatePassiveSellOffer + | Operation.ManageSellOffer + | Operation.ManageBuyOffer | Operation.SetOptions | Operation.ChangeTrust | Operation.AllowTrust diff --git a/xdr/Stellar-ledger-entries.x b/xdr/Stellar-ledger-entries.x index ed7b09ade..b511de272 100644 --- a/xdr/Stellar-ledger-entries.x +++ b/xdr/Stellar-ledger-entries.x @@ -12,8 +12,15 @@ typedef opaque Thresholds[4]; typedef string string32<32>; typedef string string64<64>; typedef int64 SequenceNumber; +typedef uint64 TimePoint; typedef opaque DataValue<64>; +// 1-4 alphanumeric characters right-padded with 0 bytes +typedef opaque AssetCode4[4]; + +// 5-12 alphanumeric characters right-padded with 0 bytes +typedef opaque AssetCode12[12]; + enum AssetType { ASSET_TYPE_NATIVE = 0, @@ -29,14 +36,14 @@ case ASSET_TYPE_NATIVE: // Not credit case ASSET_TYPE_CREDIT_ALPHANUM4: struct { - opaque assetCode[4]; // 1 to 4 characters + AssetCode4 assetCode; AccountID issuer; } alphaNum4; case ASSET_TYPE_CREDIT_ALPHANUM12: struct { - opaque assetCode[12]; // 5 to 12 characters + AssetCode12 assetCode; AccountID issuer; } alphaNum12; @@ -77,7 +84,7 @@ enum LedgerEntryType struct Signer { SignerKey key; - uint32 weight; // really only need 1byte + uint32 weight; // really only need 1 byte }; enum AccountFlags @@ -105,7 +112,6 @@ const MASK_ACCOUNT_FLAGS = 0x7; Other ledger entries created require an account. */ - struct AccountEntry { AccountID accountID; // master public key for this account @@ -210,7 +216,7 @@ const MASK_OFFERENTRY_FLAGS = 1; struct OfferEntry { AccountID sellerID; - uint64 offerID; + int64 offerID; Asset selling; // A Asset buying; // B int64 amount; // amount of A @@ -283,6 +289,7 @@ enum EnvelopeType { ENVELOPE_TYPE_SCP = 1, ENVELOPE_TYPE_TX = 2, - ENVELOPE_TYPE_AUTH = 3 + ENVELOPE_TYPE_AUTH = 3, + ENVELOPE_TYPE_SCPVALUE = 4 }; } diff --git a/xdr/Stellar-ledger.x b/xdr/Stellar-ledger.x index 5021112c8..754edf7d8 100644 --- a/xdr/Stellar-ledger.x +++ b/xdr/Stellar-ledger.x @@ -10,12 +10,24 @@ namespace stellar typedef opaque UpgradeType<128>; +enum StellarValueType +{ + STELLAR_VALUE_BASIC = 0, + STELLAR_VALUE_SIGNED = 1 +}; + +struct LedgerCloseValueSignature +{ + NodeID nodeID; // which node introduced the value + Signature signature; // nodeID's signature +}; + /* StellarValue is the value used by SCP to reach consensus on a given ledger -*/ + */ struct StellarValue { - Hash txSetHash; // transaction set to apply to previous ledger - uint64 closeTime; // network close time + Hash txSetHash; // transaction set to apply to previous ledger + TimePoint 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 @@ -25,17 +37,19 @@ struct StellarValue UpgradeType upgrades<6>; // reserved for future use - union switch (int v) + union switch (StellarValueType v) { - case 0: + case STELLAR_VALUE_BASIC: void; + case STELLAR_VALUE_SIGNED: + LedgerCloseValueSignature lcValueSignature; } ext; }; /* The LedgerHeader is the highest level structure representing the * state of a ledger, cryptographically linked to previous ledgers. -*/ + */ struct LedgerHeader { uint32 ledgerVersion; // the protocol version of the ledger @@ -120,7 +134,7 @@ case OFFER: struct { AccountID sellerID; - uint64 offerID; + int64 offerID; } offer; case DATA: @@ -133,17 +147,38 @@ case DATA: enum BucketEntryType { - LIVEENTRY = 0, - DEADENTRY = 1 + METAENTRY = + -1, // At-and-after protocol 11: bucket metadata, should come first. + LIVEENTRY = 0, // Before protocol 11: created-or-updated; + // At-and-after protocol 11: only updated. + DEADENTRY = 1, + INITENTRY = 2 // At-and-after protocol 11: only created. +}; + +struct BucketMetadata +{ + // Indicates the protocol version used to create / merge this bucket. + uint32 ledgerVersion; + + // reserved for future use + union switch (int v) + { + case 0: + void; + } + ext; }; union BucketEntry switch (BucketEntryType type) { case LIVEENTRY: +case INITENTRY: LedgerEntry liveEntry; case DEADENTRY: LedgerKey deadEntry; +case METAENTRY: + BucketMetadata metaEntry; }; // Transaction sets are the unit used by SCP to decide on transitions @@ -268,7 +303,7 @@ struct OperationMeta struct TransactionMetaV1 { LedgerEntryChanges txChanges; // tx level changes if any - OperationMeta operations<>; // meta for each operation + OperationMeta operations<>; // meta for each operation }; // this is the meta produced when applying transactions diff --git a/xdr/Stellar-transaction.x b/xdr/Stellar-transaction.x index 49276210f..e84b204b8 100644 --- a/xdr/Stellar-transaction.x +++ b/xdr/Stellar-transaction.x @@ -18,15 +18,16 @@ enum OperationType CREATE_ACCOUNT = 0, PAYMENT = 1, PATH_PAYMENT = 2, - MANAGE_OFFER = 3, - CREATE_PASSIVE_OFFER = 4, + MANAGE_SELL_OFFER = 3, + CREATE_PASSIVE_SELL_OFFER = 4, SET_OPTIONS = 5, CHANGE_TRUST = 6, ALLOW_TRUST = 7, ACCOUNT_MERGE = 8, INFLATION = 9, MANAGE_DATA = 10, - BUMP_SEQUENCE = 11 + BUMP_SEQUENCE = 11, + MANAGE_BUY_OFFER = 12 }; /* CreateAccount @@ -37,7 +38,6 @@ Threshold: med Result: CreateAccountResult */ - struct CreateAccountOp { AccountID destination; // account to create @@ -88,10 +88,10 @@ struct PathPaymentOp Threshold: med -Result: ManageOfferResult +Result: ManageSellOfferResult */ -struct ManageOfferOp +struct ManageSellOfferOp { Asset selling; Asset buying; @@ -99,17 +99,36 @@ struct ManageOfferOp 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; + int64 offerID; +}; + +/* Creates, updates or deletes an offer with amount in terms of buying asset + +Threshold: med + +Result: ManageBuyOfferResult + +*/ +struct ManageBuyOfferOp +{ + Asset selling; + Asset buying; + int64 buyAmount; // amount being bought. if set to 0, delete the offer + Price price; // price of thing being bought in terms of what you are + // selling + + // 0=create a new offer, otherwise edit an existing offer + int64 offerID; }; /* Creates an offer that doesn't take offers of the same price Threshold: med -Result: CreatePassiveOfferResult +Result: CreatePassiveSellOfferResult */ -struct CreatePassiveOfferOp +struct CreatePassiveSellOfferOp { Asset selling; // A Asset buying; // B @@ -126,7 +145,6 @@ struct CreatePassiveOfferOp Result: SetOptionsResult */ - struct SetOptionsOp { AccountID* inflationDest; // sets the inflation destination @@ -178,10 +196,10 @@ struct AllowTrustOp { // ASSET_TYPE_NATIVE is not allowed case ASSET_TYPE_CREDIT_ALPHANUM4: - opaque assetCode4[4]; + AssetCode4 assetCode4; case ASSET_TYPE_CREDIT_ALPHANUM12: - opaque assetCode12[12]; + AssetCode12 assetCode12; // add other asset types here in the future } @@ -215,7 +233,6 @@ Result: InflationResult Result: ManageDataResult */ - struct ManageDataOp { string64 dataName; @@ -230,7 +247,6 @@ struct ManageDataOp Result: BumpSequenceResult */ - struct BumpSequenceOp { SequenceNumber bumpTo; @@ -252,10 +268,10 @@ struct Operation PaymentOp paymentOp; case PATH_PAYMENT: PathPaymentOp pathPaymentOp; - case MANAGE_OFFER: - ManageOfferOp manageOfferOp; - case CREATE_PASSIVE_OFFER: - CreatePassiveOfferOp createPassiveOfferOp; + case MANAGE_SELL_OFFER: + ManageSellOfferOp manageSellOfferOp; + case CREATE_PASSIVE_SELL_OFFER: + CreatePassiveSellOfferOp createPassiveSellOfferOp; case SET_OPTIONS: SetOptionsOp setOptionsOp; case CHANGE_TRUST: @@ -270,6 +286,8 @@ struct Operation ManageDataOp manageDataOp; case BUMP_SEQUENCE: BumpSequenceOp bumpSequenceOp; + case MANAGE_BUY_OFFER: + ManageBuyOfferOp manageBuyOfferOp; } body; }; @@ -299,10 +317,13 @@ case MEMO_RETURN: struct TimeBounds { - uint64 minTime; - uint64 maxTime; // 0 here means no maxTime + TimePoint minTime; + TimePoint maxTime; // 0 here means no maxTime }; +// maximum number of operations per transaction +const MAX_OPS_PER_TX = 100; + /* a transaction is a container for a set of operations - is executed by an account - fees are collected from the account @@ -310,7 +331,6 @@ struct TimeBounds either all operations are applied or none are if any returns a failing code */ - struct Transaction { // account used to run the transaction @@ -327,7 +347,7 @@ struct Transaction Memo memo; - Operation operations<100>; + Operation operations; // reserved for future use union switch (int v) @@ -366,7 +386,7 @@ struct ClaimOfferAtom { // emitted to identify the offer AccountID sellerID; // Account that owns the offer - uint64 offerID; + int64 offerID; // amount and asset taken from the owner Asset assetSold; @@ -470,29 +490,29 @@ default: void; }; -/******* ManageOffer Result ********/ +/******* ManageSellOffer Result ********/ -enum ManageOfferResultCode +enum ManageSellOfferResultCode { // codes considered as "success" for the operation - MANAGE_OFFER_SUCCESS = 0, + MANAGE_SELL_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 + MANAGE_SELL_OFFER_MALFORMED = -1, // generated offer would be invalid + MANAGE_SELL_OFFER_SELL_NO_TRUST = -2, // no trust line for what we're selling + MANAGE_SELL_OFFER_BUY_NO_TRUST = -3, // no trust line for what we're buying + MANAGE_SELL_OFFER_SELL_NOT_AUTHORIZED = -4, // not authorized to sell + MANAGE_SELL_OFFER_BUY_NOT_AUTHORIZED = -5, // not authorized to buy + MANAGE_SELL_OFFER_LINE_FULL = -6, // can't receive more of what it's buying + MANAGE_SELL_OFFER_UNDERFUNDED = -7, // doesn't hold what it's trying to sell + MANAGE_SELL_OFFER_CROSS_SELF = -8, // would cross an offer from the same user + MANAGE_SELL_OFFER_SELL_NO_ISSUER = -9, // no issuer for what we're selling + MANAGE_SELL_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_SELL_OFFER_NOT_FOUND = -11, // offerID does not match an existing offer - MANAGE_OFFER_LOW_RESERVE = -12 // not enough funds to create a new Offer + MANAGE_SELL_OFFER_LOW_RESERVE = -12 // not enough funds to create a new Offer }; enum ManageOfferEffect @@ -518,9 +538,42 @@ struct ManageOfferSuccessResult offer; }; -union ManageOfferResult switch (ManageOfferResultCode code) +union ManageSellOfferResult switch (ManageSellOfferResultCode code) +{ +case MANAGE_SELL_OFFER_SUCCESS: + ManageOfferSuccessResult success; +default: + void; +}; + +/******* ManageBuyOffer Result ********/ + +enum ManageBuyOfferResultCode +{ + // codes considered as "success" for the operation + MANAGE_BUY_OFFER_SUCCESS = 0, + + // codes considered as "failure" for the operation + MANAGE_BUY_OFFER_MALFORMED = -1, // generated offer would be invalid + MANAGE_BUY_OFFER_SELL_NO_TRUST = -2, // no trust line for what we're selling + MANAGE_BUY_OFFER_BUY_NO_TRUST = -3, // no trust line for what we're buying + MANAGE_BUY_OFFER_SELL_NOT_AUTHORIZED = -4, // not authorized to sell + MANAGE_BUY_OFFER_BUY_NOT_AUTHORIZED = -5, // not authorized to buy + MANAGE_BUY_OFFER_LINE_FULL = -6, // can't receive more of what it's buying + MANAGE_BUY_OFFER_UNDERFUNDED = -7, // doesn't hold what it's trying to sell + MANAGE_BUY_OFFER_CROSS_SELF = -8, // would cross an offer from the same user + MANAGE_BUY_OFFER_SELL_NO_ISSUER = -9, // no issuer for what we're selling + MANAGE_BUY_OFFER_BUY_NO_ISSUER = -10, // no issuer for what we're buying + + // update errors + MANAGE_BUY_OFFER_NOT_FOUND = -11, // offerID does not match an existing offer + + MANAGE_BUY_OFFER_LOW_RESERVE = -12 // not enough funds to create a new Offer +}; + +union ManageBuyOfferResult switch (ManageBuyOfferResultCode code) { -case MANAGE_OFFER_SUCCESS: +case MANAGE_BUY_OFFER_SUCCESS: ManageOfferSuccessResult success; default: void; @@ -565,7 +618,7 @@ enum ChangeTrustResultCode // 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 + CHANGE_TRUST_SELF_NOT_ALLOWED = -5 // trusting self is not allowed }; union ChangeTrustResult switch (ChangeTrustResultCode code) @@ -695,7 +748,9 @@ enum OperationResultCode opBAD_AUTH = -1, // too few valid signatures / wrong network opNO_ACCOUNT = -2, // source account was not found - opNOT_SUPPORTED = -3 // operation not supported at this time + opNOT_SUPPORTED = -3, // operation not supported at this time + opTOO_MANY_SUBENTRIES = -4, // max number of subentries already reached + opEXCEEDED_WORK_LIMIT = -5 // operation did too much work }; union OperationResult switch (OperationResultCode code) @@ -709,10 +764,10 @@ case opINNER: PaymentResult paymentResult; case PATH_PAYMENT: PathPaymentResult pathPaymentResult; - case MANAGE_OFFER: - ManageOfferResult manageOfferResult; - case CREATE_PASSIVE_OFFER: - ManageOfferResult createPassiveOfferResult; + case MANAGE_SELL_OFFER: + ManageSellOfferResult manageSellOfferResult; + case CREATE_PASSIVE_SELL_OFFER: + ManageSellOfferResult createPassiveSellOfferResult; case SET_OPTIONS: SetOptionsResult setOptionsResult; case CHANGE_TRUST: @@ -727,6 +782,8 @@ case opINNER: ManageDataResult manageDataResult; case BUMP_SEQUENCE: BumpSequenceResult bumpSeqResult; + case MANAGE_BUY_OFFER: + ManageBuyOfferResult manageBuyOfferResult; } tr; default: diff --git a/yarn.lock b/yarn.lock index e51b707c3..246116408 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1150,10 +1150,6 @@ binary-extensions@^1.0.0: version "1.11.0" resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.11.0.tgz#46aa1751fb6a2f93ee5e689bb1087d4b14c6c205" -bindings@^1.2.1: - version "1.3.0" - resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.3.0.tgz#b346f6ecf6a95f5a815c5839fc7cdb22502f1ed7" - bl@^1.0.0: version "1.2.2" resolved "https://registry.yarnpkg.com/bl/-/bl-1.2.2.tgz#a160911717103c07410cef63ef51b397c025af9c" @@ -1797,11 +1793,16 @@ core-js@^2.2.0: resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.4.tgz#b8897c062c4d769dd30a0ac5c73976c47f92ea0d" integrity sha512-05qQ5hXShcqGkPZpXEFLIpxayZscVD2kuMBZewxiIPPEagukO4mqgPA9CWhUvFBJfy3ODdK2p9xyHh7FTU9/7A== -core-js@^2.4.0, core-js@^2.5.0, core-js@^2.6.3: +core-js@^2.4.0, core-js@^2.5.0: version "2.6.3" resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.3.tgz#4b70938bdffdaf64931e66e2db158f0892289c49" integrity sha512-l00tmFFZOBHtYhN4Cz7k32VM7vTn3rE2ANjQDxdEN6zmXZ/xq1jQuutnmHvMG1ZJ7xd72+TA5YpUK8wz3rWsfQ== +core-js@^2.6.3: + version "2.6.5" + resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.5.tgz#44bc8d249e7fb2ff5d00e0341a7ffb94fbf67895" + integrity sha512-klh/kDpwX8hryYL14M9w/xei6vrv6sE8gTHDG7/T/+SEovB/G4ejwcfE/CBzO6Edsu+OETZMZ3wcX/EjUkrl5A== + core-util-is@1.0.2, core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" @@ -1909,6 +1910,7 @@ currently-unhandled@^0.4.1: cursor@^0.1.5: version "0.1.5" resolved "https://registry.yarnpkg.com/cursor/-/cursor-0.1.5.tgz#ea778c2b09d33c2e564fd92147076750483ebb2c" + integrity sha1-6neMKwnTPC5WT9khRwdnUEg+uyw= custom-event@~1.0.0: version "1.0.1" @@ -2179,13 +2181,6 @@ ecc-jsbn@~0.1.1: dependencies: jsbn "~0.1.0" -ed25519@0.0.4: - version "0.0.4" - resolved "https://registry.yarnpkg.com/ed25519/-/ed25519-0.0.4.tgz#e56218ace2fc903d259593aef0b2a9639f475beb" - dependencies: - bindings "^1.2.1" - nan "^2.0.9" - ee-first@1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" @@ -3857,7 +3852,7 @@ inherits@2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1" -ini@^1.3.4, ini@~1.3.0: +ini@^1.3.4, ini@^1.3.5, ini@~1.3.0: version "1.3.5" resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927" @@ -4298,9 +4293,9 @@ js-tokens@^3.0.2: integrity sha1-mGbfOVECEw449/mWvOtlRDIJwls= js-xdr@^1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/js-xdr/-/js-xdr-1.1.1.tgz#38b1dbba77e4b381b9603e564fe1d374649ce2e1" - integrity sha512-csYOkKC78umSY2r3oDUONGH1ZcyTex7VlzpfmjKdzlNoeqFQtOA1rhBE9/e3mFNiO0Do65EVvyWx2jHHtRYPPg== + version "1.1.2" + resolved "https://registry.yarnpkg.com/js-xdr/-/js-xdr-1.1.2.tgz#aba1f0952508c83f33dd7e774fa9231b3073992b" + integrity sha512-ipiz1CnsyjLsba+QQd5jezGXddNKGa4oO9EODy0kWr3G3R8MNslIxkhQFpyRfY3yoY7YplhRVfC3cmXb4AobZQ== dependencies: core-js "^2.6.3" cursor "^0.1.5" @@ -4848,11 +4843,11 @@ lodash.templatesettings@^3.0.0: lodash._reinterpolate "^3.0.0" lodash.escape "^3.0.0" -lodash@4.17.10, lodash@^4.0.0, lodash@^4.0.1, lodash@^4.16.6, lodash@^4.17.10, lodash@^4.17.5, lodash@^4.8.0, lodash@~4.17.2: +lodash@4.17.10, lodash@^4.0.0, lodash@^4.0.1, lodash@^4.16.6, lodash@^4.17.10, lodash@^4.8.0, lodash@~4.17.2: version "4.17.10" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7" -lodash@^4.13.1, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.5.0: +lodash@^4.13.1, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.5.0: version "4.17.11" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg== @@ -4914,6 +4909,7 @@ lolex@1.3.2: long@^2.2.3: version "2.4.0" resolved "https://registry.yarnpkg.com/long/-/long-2.4.0.tgz#9fa180bb1d9500cdc29c4156766a1995e1f4524f" + integrity sha1-n6GAux2VAM3CnEFWdmoZleH0Uk8= longest@^1.0.1: version "1.0.1" @@ -5215,7 +5211,12 @@ mute-stream@0.0.7: resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab" integrity sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s= -nan@^2.0.9, nan@^2.9.2: +nan@^2.4.0: + version "2.13.2" + resolved "https://registry.yarnpkg.com/nan/-/nan-2.13.2.tgz#f51dc7ae66ba7d5d55e1e6d4d8092e802c9aefe7" + integrity sha512-TghvYc72wlMGMVMluVo9WRJc0mB8KxxF/gZ4YYFy7V2ZQX9l7rgbPg7vjS9mt6U5HXODVFVI2bOduCzwOMv/lw== + +nan@^2.9.2: version "2.10.0" resolved "https://registry.yarnpkg.com/nan/-/nan-2.10.0.tgz#96d0cd610ebd58d4b4de9cc0c6828cda99c7548f" @@ -5262,6 +5263,11 @@ nice-try@^1.0.4: resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ== +node-gyp-build@^3.0.0: + version "3.9.0" + resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-3.9.0.tgz#53a350187dd4d5276750da21605d1cb681d09e25" + integrity sha512-zLcTg6P4AbcHPq465ZMFNXx7XpKKJh+7kkN699NiQWisR2uWYOWNWqRHAmbnmKiL4e9aLSlmy5U7rEMUXV59+A== + node-libs-browser@^0.7.0: version "0.7.0" resolved "https://registry.yarnpkg.com/node-libs-browser/-/node-libs-browser-0.7.0.tgz#3e272c0819e308935e26674408d7af0e1491b83b" @@ -6843,6 +6849,15 @@ socket.io@2.1.1: socket.io-client "2.1.1" socket.io-parser "~3.2.0" +sodium-native@^2.3.0: + version "2.4.2" + resolved "https://registry.yarnpkg.com/sodium-native/-/sodium-native-2.4.2.tgz#de3c99675899555a8c83f5be3ed97f28653aa2b2" + integrity sha512-qwHcUnzFpRSGSm6F49j/h5SnxPFBgSNdDwZkAqjvuAoHQIVBFOXYb+oCUTJV80K5hRqSYCihpbX06vbrtPbilg== + dependencies: + ini "^1.3.5" + nan "^2.4.0" + node-gyp-build "^3.0.0" + source-list-map@~0.1.7: version "0.1.8" resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-0.1.8.tgz#c550b2ab5427f6b3f21f5afead88c4f5587b2106"