From 8290cbf9989e0f7af4cd107e74b573249b702354 Mon Sep 17 00:00:00 2001 From: overcat <4catcode@gmail.com> Date: Sat, 27 Apr 2019 15:15:11 +0800 Subject: [PATCH 1/4] Upgrade to the latest XDR file. --- stellar_base/stellarxdr/StellarXDR_const.py | 111 ++++-- stellar_base/stellarxdr/StellarXDR_pack.py | 377 +++++++++++++++----- stellar_base/stellarxdr/StellarXDR_type.py | 196 ++++++++-- stellar_base/xdr/Stellar-ledger-entries.x | 19 +- stellar_base/xdr/Stellar-ledger.x | 55 ++- stellar_base/xdr/Stellar-transaction.x | 149 +++++--- 6 files changed, 678 insertions(+), 229 deletions(-) diff --git a/stellar_base/stellarxdr/StellarXDR_const.py b/stellar_base/stellarxdr/StellarXDR_const.py index 31bd7952..4f5c9f04 100644 --- a/stellar_base/stellarxdr/StellarXDR_const.py +++ b/stellar_base/stellarxdr/StellarXDR_const.py @@ -1,4 +1,4 @@ -# Generated by xdrgen.py from ../xdr/ on Sat Apr 20 11:56:38 2019 +# Generated by xdrgen.py from ../xdr/ on Sat Apr 27 13:37:03 2019 KEY_TYPE_ED25519 = 0 KEY_TYPE_PRE_AUTH_TX = 1 KEY_TYPE_HASH_X = 2 @@ -29,6 +29,12 @@ 2 : 'SCP_ST_EXTERNALIZE', 3 : 'SCP_ST_NOMINATE', } +STELLAR_VALUE_BASIC = 0 +STELLAR_VALUE_SIGNED = 1 +StellarValueType = { + 0 : 'STELLAR_VALUE_BASIC', + 1 : 'STELLAR_VALUE_SIGNED', +} LEDGER_UPGRADE_VERSION = 1 LEDGER_UPGRADE_BASE_FEE = 2 LEDGER_UPGRADE_MAX_TX_SET_SIZE = 3 @@ -39,11 +45,15 @@ 3 : 'LEDGER_UPGRADE_MAX_TX_SET_SIZE', 4 : 'LEDGER_UPGRADE_BASE_RESERVE', } +METAENTRY = -1 LIVEENTRY = 0 DEADENTRY = 1 +INITENTRY = 2 BucketEntryType = { + -1 : 'METAENTRY', 0 : 'LIVEENTRY', 1 : 'DEADENTRY', + 2 : 'INITENTRY', } LEDGER_ENTRY_CREATED = 0 LEDGER_ENTRY_UPDATED = 1 @@ -105,16 +115,18 @@ ENVELOPE_TYPE_SCP = 1 ENVELOPE_TYPE_TX = 2 ENVELOPE_TYPE_AUTH = 3 +ENVELOPE_TYPE_SCPVALUE = 4 EnvelopeType = { 1 : 'ENVELOPE_TYPE_SCP', 2 : 'ENVELOPE_TYPE_TX', 3 : 'ENVELOPE_TYPE_AUTH', + 4 : 'ENVELOPE_TYPE_SCPVALUE', } 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 @@ -122,12 +134,13 @@ INFLATION = 9 MANAGE_DATA = 10 BUMP_SEQUENCE = 11 +MANAGE_BUY_OFFER = 12 OperationType = { 0 : 'CREATE_ACCOUNT', 1 : 'PAYMENT', 2 : 'PATH_PAYMENT', - 3 : 'MANAGE_OFFER', - 4 : 'CREATE_PASSIVE_OFFER', + 3 : 'MANAGE_SELL_OFFER', + 4 : 'CREATE_PASSIVE_SELL_OFFER', 5 : 'SET_OPTIONS', 6 : 'CHANGE_TRUST', 7 : 'ALLOW_TRUST', @@ -135,6 +148,7 @@ 9 : 'INFLATION', 10 : 'MANAGE_DATA', 11 : 'BUMP_SEQUENCE', + 12 : 'MANAGE_BUY_OFFER', } MEMO_NONE = 0 MEMO_TEXT = 1 @@ -148,6 +162,7 @@ 3 : 'MEMO_HASH', 4 : 'MEMO_RETURN', } +MAX_OPS_PER_TX = 100 CREATE_ACCOUNT_SUCCESS = 0 CREATE_ACCOUNT_MALFORMED = -1 CREATE_ACCOUNT_UNDERFUNDED = -2 @@ -210,33 +225,33 @@ -11 : 'PATH_PAYMENT_OFFER_CROSS_SELF', -12 : 'PATH_PAYMENT_OVER_SENDMAX', } -MANAGE_OFFER_SUCCESS = 0 -MANAGE_OFFER_MALFORMED = -1 -MANAGE_OFFER_SELL_NO_TRUST = -2 -MANAGE_OFFER_BUY_NO_TRUST = -3 -MANAGE_OFFER_SELL_NOT_AUTHORIZED = -4 -MANAGE_OFFER_BUY_NOT_AUTHORIZED = -5 -MANAGE_OFFER_LINE_FULL = -6 -MANAGE_OFFER_UNDERFUNDED = -7 -MANAGE_OFFER_CROSS_SELF = -8 -MANAGE_OFFER_SELL_NO_ISSUER = -9 -MANAGE_OFFER_BUY_NO_ISSUER = -10 -MANAGE_OFFER_NOT_FOUND = -11 -MANAGE_OFFER_LOW_RESERVE = -12 -ManageOfferResultCode = { - 0 : 'MANAGE_OFFER_SUCCESS', - -1 : 'MANAGE_OFFER_MALFORMED', - -2 : 'MANAGE_OFFER_SELL_NO_TRUST', - -3 : 'MANAGE_OFFER_BUY_NO_TRUST', - -4 : 'MANAGE_OFFER_SELL_NOT_AUTHORIZED', - -5 : 'MANAGE_OFFER_BUY_NOT_AUTHORIZED', - -6 : 'MANAGE_OFFER_LINE_FULL', - -7 : 'MANAGE_OFFER_UNDERFUNDED', - -8 : 'MANAGE_OFFER_CROSS_SELF', - -9 : 'MANAGE_OFFER_SELL_NO_ISSUER', - -10 : 'MANAGE_OFFER_BUY_NO_ISSUER', - -11 : 'MANAGE_OFFER_NOT_FOUND', - -12 : 'MANAGE_OFFER_LOW_RESERVE', +MANAGE_SELL_OFFER_SUCCESS = 0 +MANAGE_SELL_OFFER_MALFORMED = -1 +MANAGE_SELL_OFFER_SELL_NO_TRUST = -2 +MANAGE_SELL_OFFER_BUY_NO_TRUST = -3 +MANAGE_SELL_OFFER_SELL_NOT_AUTHORIZED = -4 +MANAGE_SELL_OFFER_BUY_NOT_AUTHORIZED = -5 +MANAGE_SELL_OFFER_LINE_FULL = -6 +MANAGE_SELL_OFFER_UNDERFUNDED = -7 +MANAGE_SELL_OFFER_CROSS_SELF = -8 +MANAGE_SELL_OFFER_SELL_NO_ISSUER = -9 +MANAGE_SELL_OFFER_BUY_NO_ISSUER = -10 +MANAGE_SELL_OFFER_NOT_FOUND = -11 +MANAGE_SELL_OFFER_LOW_RESERVE = -12 +ManageSellOfferResultCode = { + 0 : 'MANAGE_SELL_OFFER_SUCCESS', + -1 : 'MANAGE_SELL_OFFER_MALFORMED', + -2 : 'MANAGE_SELL_OFFER_SELL_NO_TRUST', + -3 : 'MANAGE_SELL_OFFER_BUY_NO_TRUST', + -4 : 'MANAGE_SELL_OFFER_SELL_NOT_AUTHORIZED', + -5 : 'MANAGE_SELL_OFFER_BUY_NOT_AUTHORIZED', + -6 : 'MANAGE_SELL_OFFER_LINE_FULL', + -7 : 'MANAGE_SELL_OFFER_UNDERFUNDED', + -8 : 'MANAGE_SELL_OFFER_CROSS_SELF', + -9 : 'MANAGE_SELL_OFFER_SELL_NO_ISSUER', + -10 : 'MANAGE_SELL_OFFER_BUY_NO_ISSUER', + -11 : 'MANAGE_SELL_OFFER_NOT_FOUND', + -12 : 'MANAGE_SELL_OFFER_LOW_RESERVE', } MANAGE_OFFER_CREATED = 0 MANAGE_OFFER_UPDATED = 1 @@ -246,6 +261,34 @@ 1 : 'MANAGE_OFFER_UPDATED', 2 : 'MANAGE_OFFER_DELETED', } +MANAGE_BUY_OFFER_SUCCESS = 0 +MANAGE_BUY_OFFER_MALFORMED = -1 +MANAGE_BUY_OFFER_SELL_NO_TRUST = -2 +MANAGE_BUY_OFFER_BUY_NO_TRUST = -3 +MANAGE_BUY_OFFER_SELL_NOT_AUTHORIZED = -4 +MANAGE_BUY_OFFER_BUY_NOT_AUTHORIZED = -5 +MANAGE_BUY_OFFER_LINE_FULL = -6 +MANAGE_BUY_OFFER_UNDERFUNDED = -7 +MANAGE_BUY_OFFER_CROSS_SELF = -8 +MANAGE_BUY_OFFER_SELL_NO_ISSUER = -9 +MANAGE_BUY_OFFER_BUY_NO_ISSUER = -10 +MANAGE_BUY_OFFER_NOT_FOUND = -11 +MANAGE_BUY_OFFER_LOW_RESERVE = -12 +ManageBuyOfferResultCode = { + 0 : 'MANAGE_BUY_OFFER_SUCCESS', + -1 : 'MANAGE_BUY_OFFER_MALFORMED', + -2 : 'MANAGE_BUY_OFFER_SELL_NO_TRUST', + -3 : 'MANAGE_BUY_OFFER_BUY_NO_TRUST', + -4 : 'MANAGE_BUY_OFFER_SELL_NOT_AUTHORIZED', + -5 : 'MANAGE_BUY_OFFER_BUY_NOT_AUTHORIZED', + -6 : 'MANAGE_BUY_OFFER_LINE_FULL', + -7 : 'MANAGE_BUY_OFFER_UNDERFUNDED', + -8 : 'MANAGE_BUY_OFFER_CROSS_SELF', + -9 : 'MANAGE_BUY_OFFER_SELL_NO_ISSUER', + -10 : 'MANAGE_BUY_OFFER_BUY_NO_ISSUER', + -11 : 'MANAGE_BUY_OFFER_NOT_FOUND', + -12 : 'MANAGE_BUY_OFFER_LOW_RESERVE', +} SET_OPTIONS_SUCCESS = 0 SET_OPTIONS_LOW_RESERVE = -1 SET_OPTIONS_TOO_MANY_SIGNERS = -2 @@ -340,11 +383,15 @@ opBAD_AUTH = -1 opNO_ACCOUNT = -2 opNOT_SUPPORTED = -3 +opTOO_MANY_SUBENTRIES = -4 +opEXCEEDED_WORK_LIMIT = -5 OperationResultCode = { 0 : 'opINNER', -1 : 'opBAD_AUTH', -2 : 'opNO_ACCOUNT', -3 : 'opNOT_SUPPORTED', + -4 : 'opTOO_MANY_SUBENTRIES', + -5 : 'opEXCEEDED_WORK_LIMIT', } txSUCCESS = 0 txFAILED = -1 diff --git a/stellar_base/stellarxdr/StellarXDR_pack.py b/stellar_base/stellarxdr/StellarXDR_pack.py index 3fb23967..921cfcad 100644 --- a/stellar_base/stellarxdr/StellarXDR_pack.py +++ b/stellar_base/stellarxdr/StellarXDR_pack.py @@ -1,4 +1,4 @@ -# Generated by xdrgen.py from ../xdr/ on Sat Apr 20 11:56:38 2019 +# Generated by xdrgen.py from ../xdr/ on Sat Apr 27 13:37:03 2019 from . import StellarXDR_const as const from . import StellarXDR_type as types import xdrlib @@ -280,6 +280,23 @@ def pack_UpgradeType(self, data): raise XDRError('array length too long for data') self.pack_opaque(data) + def pack_StellarValueType(self, data): + if hasattr(self, 'filter_StellarValueType'): + data = getattr(self, 'filter_StellarValueType')(data) + if self.check_enum and data not in [const.STELLAR_VALUE_BASIC, const.STELLAR_VALUE_SIGNED]: + raise XDRError('value=%s not in enum StellarValueType' % data) + self.pack_int(data) + + def pack_LedgerCloseValueSignature(self, data): + if hasattr(self, 'filter_LedgerCloseValueSignature'): + data = getattr(self, 'filter_LedgerCloseValueSignature')(data) + if data.nodeID is None: + raise TypeError('data.nodeID == None') + self.pack_NodeID(data.nodeID) + if data.signature is None: + raise TypeError('data.signature == None') + self.pack_Signature(data.signature) + def pack_StellarValue(self, data): if hasattr(self, 'filter_StellarValue'): data = getattr(self, 'filter_StellarValue')(data) @@ -288,7 +305,7 @@ def pack_StellarValue(self, data): self.pack_Hash(data.txSetHash) if data.closeTime is None: raise TypeError('data.closeTime == None') - self.pack_uint64(data.closeTime) + self.pack_TimePoint(data.closeTime) if data.upgrades is None: raise TypeError('data.upgrades == None') if len(data.upgrades) > 6 and self.check_array: @@ -298,9 +315,13 @@ def pack_StellarValue(self, data): raise TypeError('data.ext == None') if data.ext.v is None: raise TypeError('data.ext.v == None') - self.pack_int(data.ext.v) - if data.ext.v == 0: + self.pack_StellarValueType(data.ext.v) + if data.ext.v == const.STELLAR_VALUE_BASIC: pass + elif data.ext.v == const.STELLAR_VALUE_SIGNED: + if data.ext.lcValueSignature is None: + raise TypeError('data.ext.lcValueSignature == None') + self.pack_LedgerCloseValueSignature(data.ext.lcValueSignature) else: raise XDRError('bad switch=%s' % data.ext.v) @@ -420,7 +441,7 @@ def pack_LedgerKey(self, data): self.pack_AccountID(data.offer.sellerID) if data.offer.offerID is None: raise TypeError('data.offer.offerID == None') - self.pack_uint64(data.offer.offerID) + self.pack_int64(data.offer.offerID) elif data.type == const.DATA: if data.data is None: raise TypeError('data.data == None') @@ -436,17 +457,33 @@ def pack_LedgerKey(self, data): def pack_BucketEntryType(self, data): if hasattr(self, 'filter_BucketEntryType'): data = getattr(self, 'filter_BucketEntryType')(data) - if self.check_enum and data not in [const.LIVEENTRY, const.DEADENTRY]: + if self.check_enum and data not in [const.METAENTRY, const.LIVEENTRY, const.DEADENTRY, const.INITENTRY]: raise XDRError('value=%s not in enum BucketEntryType' % data) self.pack_int(data) + def pack_BucketMetadata(self, data): + if hasattr(self, 'filter_BucketMetadata'): + data = getattr(self, 'filter_BucketMetadata')(data) + if data.ledgerVersion is None: + raise TypeError('data.ledgerVersion == None') + self.pack_uint32(data.ledgerVersion) + if data.ext is None: + raise TypeError('data.ext == None') + if data.ext.v is None: + raise TypeError('data.ext.v == None') + self.pack_int(data.ext.v) + if data.ext.v == 0: + pass + else: + raise XDRError('bad switch=%s' % data.ext.v) + def pack_BucketEntry(self, data): if hasattr(self, 'filter_BucketEntry'): data = getattr(self, 'filter_BucketEntry')(data) if data.type is None: raise TypeError('data.type == None') self.pack_BucketEntryType(data.type) - if data.type == const.LIVEENTRY: + if data.type == const.LIVEENTRY or data.type == const.INITENTRY: if data.liveEntry is None: raise TypeError('data.liveEntry == None') self.pack_LedgerEntry(data.liveEntry) @@ -454,6 +491,10 @@ def pack_BucketEntry(self, data): if data.deadEntry is None: raise TypeError('data.deadEntry == None') self.pack_LedgerKey(data.deadEntry) + elif data.type == const.METAENTRY: + if data.metaEntry is None: + raise TypeError('data.metaEntry == None') + self.pack_BucketMetadata(data.metaEntry) else: raise XDRError('bad switch=%s' % data.type) @@ -668,6 +709,8 @@ def pack_string64(self, data): pack_SequenceNumber = pack_int64 + pack_TimePoint = pack_uint64 + def pack_DataValue(self, data): if hasattr(self, 'filter_DataValue'): data = getattr(self, 'filter_DataValue')(data) @@ -675,6 +718,16 @@ def pack_DataValue(self, data): raise XDRError('array length too long for data') self.pack_opaque(data) + def pack_AssetCode4(self, data): + if hasattr(self, 'filter_AssetCode4'): + data = getattr(self, 'filter_AssetCode4')(data) + self.pack_fopaque(4, data) + + def pack_AssetCode12(self, data): + if hasattr(self, 'filter_AssetCode12'): + data = getattr(self, 'filter_AssetCode12')(data) + self.pack_fopaque(12, data) + def pack_AssetType(self, data): if hasattr(self, 'filter_AssetType'): data = getattr(self, 'filter_AssetType')(data) @@ -695,7 +748,7 @@ def pack_Asset(self, data): raise TypeError('data.alphaNum4 == None') if data.alphaNum4.assetCode is None: raise TypeError('data.alphaNum4.assetCode == None') - self.pack_fopaque(4, data.alphaNum4.assetCode) + self.pack_AssetCode4(data.alphaNum4.assetCode) if data.alphaNum4.issuer is None: raise TypeError('data.alphaNum4.issuer == None') self.pack_AccountID(data.alphaNum4.issuer) @@ -704,7 +757,7 @@ def pack_Asset(self, data): raise TypeError('data.alphaNum12 == None') if data.alphaNum12.assetCode is None: raise TypeError('data.alphaNum12.assetCode == None') - self.pack_fopaque(12, data.alphaNum12.assetCode) + self.pack_AssetCode12(data.alphaNum12.assetCode) if data.alphaNum12.issuer is None: raise TypeError('data.alphaNum12.issuer == None') self.pack_AccountID(data.alphaNum12.issuer) @@ -886,7 +939,7 @@ def pack_OfferEntry(self, data): self.pack_AccountID(data.sellerID) if data.offerID is None: raise TypeError('data.offerID == None') - self.pack_uint64(data.offerID) + self.pack_int64(data.offerID) if data.selling is None: raise TypeError('data.selling == None') self.pack_Asset(data.selling) @@ -976,7 +1029,7 @@ def pack_LedgerEntry(self, data): def pack_EnvelopeType(self, data): if hasattr(self, 'filter_EnvelopeType'): data = getattr(self, 'filter_EnvelopeType')(data) - if self.check_enum and data not in [const.ENVELOPE_TYPE_SCP, const.ENVELOPE_TYPE_TX, const.ENVELOPE_TYPE_AUTH]: + if self.check_enum and data not in [const.ENVELOPE_TYPE_SCP, const.ENVELOPE_TYPE_TX, const.ENVELOPE_TYPE_AUTH, const.ENVELOPE_TYPE_SCPVALUE]: raise XDRError('value=%s not in enum EnvelopeType' % data) self.pack_int(data) @@ -993,7 +1046,7 @@ def pack_DecoratedSignature(self, data): def pack_OperationType(self, data): if hasattr(self, 'filter_OperationType'): data = getattr(self, 'filter_OperationType')(data) - if self.check_enum and data not in [const.CREATE_ACCOUNT, const.PAYMENT, const.PATH_PAYMENT, const.MANAGE_OFFER, const.CREATE_PASSIVE_OFFER, const.SET_OPTIONS, const.CHANGE_TRUST, const.ALLOW_TRUST, const.ACCOUNT_MERGE, const.INFLATION, const.MANAGE_DATA, const.BUMP_SEQUENCE]: + if self.check_enum and data not in [const.CREATE_ACCOUNT, const.PAYMENT, const.PATH_PAYMENT, const.MANAGE_SELL_OFFER, const.CREATE_PASSIVE_SELL_OFFER, const.SET_OPTIONS, const.CHANGE_TRUST, const.ALLOW_TRUST, const.ACCOUNT_MERGE, const.INFLATION, const.MANAGE_DATA, const.BUMP_SEQUENCE, const.MANAGE_BUY_OFFER]: raise XDRError('value=%s not in enum OperationType' % data) self.pack_int(data) @@ -1044,9 +1097,9 @@ def pack_PathPaymentOp(self, data): raise XDRError('array length too long for data.path') self.pack_array(data.path, self.pack_Asset) - def pack_ManageOfferOp(self, data): - if hasattr(self, 'filter_ManageOfferOp'): - data = getattr(self, 'filter_ManageOfferOp')(data) + def pack_ManageSellOfferOp(self, data): + if hasattr(self, 'filter_ManageSellOfferOp'): + data = getattr(self, 'filter_ManageSellOfferOp')(data) if data.selling is None: raise TypeError('data.selling == None') self.pack_Asset(data.selling) @@ -1061,11 +1114,30 @@ def pack_ManageOfferOp(self, data): self.pack_Price(data.price) if data.offerID is None: raise TypeError('data.offerID == None') - self.pack_uint64(data.offerID) + self.pack_int64(data.offerID) + + def pack_ManageBuyOfferOp(self, data): + if hasattr(self, 'filter_ManageBuyOfferOp'): + data = getattr(self, 'filter_ManageBuyOfferOp')(data) + if data.selling is None: + raise TypeError('data.selling == None') + self.pack_Asset(data.selling) + if data.buying is None: + raise TypeError('data.buying == None') + self.pack_Asset(data.buying) + if data.buyAmount is None: + raise TypeError('data.buyAmount == None') + self.pack_int64(data.buyAmount) + if data.price is None: + raise TypeError('data.price == None') + self.pack_Price(data.price) + if data.offerID is None: + raise TypeError('data.offerID == None') + self.pack_int64(data.offerID) - def pack_CreatePassiveOfferOp(self, data): - if hasattr(self, 'filter_CreatePassiveOfferOp'): - data = getattr(self, 'filter_CreatePassiveOfferOp')(data) + def pack_CreatePassiveSellOfferOp(self, data): + if hasattr(self, 'filter_CreatePassiveSellOfferOp'): + data = getattr(self, 'filter_CreatePassiveSellOfferOp')(data) if data.selling is None: raise TypeError('data.selling == None') self.pack_Asset(data.selling) @@ -1152,11 +1224,11 @@ def pack_AllowTrustOp(self, data): if data.asset.type == const.ASSET_TYPE_CREDIT_ALPHANUM4: if data.asset.assetCode4 is None: raise TypeError('data.asset.assetCode4 == None') - self.pack_fopaque(4, data.asset.assetCode4) + self.pack_AssetCode4(data.asset.assetCode4) elif data.asset.type == const.ASSET_TYPE_CREDIT_ALPHANUM12: if data.asset.assetCode12 is None: raise TypeError('data.asset.assetCode12 == None') - self.pack_fopaque(12, data.asset.assetCode12) + self.pack_AssetCode12(data.asset.assetCode12) else: raise XDRError('bad switch=%s' % data.asset.type) if data.authorize is None: @@ -1207,14 +1279,14 @@ def pack_Operation(self, data): if data.body.pathPaymentOp is None: raise TypeError('data.body.pathPaymentOp == None') self.pack_PathPaymentOp(data.body.pathPaymentOp) - elif data.body.type == const.MANAGE_OFFER: - if data.body.manageOfferOp is None: - raise TypeError('data.body.manageOfferOp == None') - self.pack_ManageOfferOp(data.body.manageOfferOp) - elif data.body.type == const.CREATE_PASSIVE_OFFER: - if data.body.createPassiveOfferOp is None: - raise TypeError('data.body.createPassiveOfferOp == None') - self.pack_CreatePassiveOfferOp(data.body.createPassiveOfferOp) + elif data.body.type == const.MANAGE_SELL_OFFER: + if data.body.manageSellOfferOp is None: + raise TypeError('data.body.manageSellOfferOp == None') + self.pack_ManageSellOfferOp(data.body.manageSellOfferOp) + elif data.body.type == const.CREATE_PASSIVE_SELL_OFFER: + if data.body.createPassiveSellOfferOp is None: + raise TypeError('data.body.createPassiveSellOfferOp == None') + self.pack_CreatePassiveSellOfferOp(data.body.createPassiveSellOfferOp) elif data.body.type == const.SET_OPTIONS: if data.body.setOptionsOp is None: raise TypeError('data.body.setOptionsOp == None') @@ -1241,6 +1313,10 @@ def pack_Operation(self, data): if data.body.bumpSequenceOp is None: raise TypeError('data.body.bumpSequenceOp == None') self.pack_BumpSequenceOp(data.body.bumpSequenceOp) + elif data.body.type == const.MANAGE_BUY_OFFER: + if data.body.manageBuyOfferOp is None: + raise TypeError('data.body.manageBuyOfferOp == None') + self.pack_ManageBuyOfferOp(data.body.manageBuyOfferOp) else: raise XDRError('bad switch=%s' % data.body.type) @@ -1285,10 +1361,10 @@ def pack_TimeBounds(self, data): data = getattr(self, 'filter_TimeBounds')(data) if data.minTime is None: raise TypeError('data.minTime == None') - self.pack_uint64(data.minTime) + self.pack_TimePoint(data.minTime) if data.maxTime is None: raise TypeError('data.maxTime == None') - self.pack_uint64(data.maxTime) + self.pack_TimePoint(data.maxTime) def pack_Transaction(self, data): if hasattr(self, 'filter_Transaction'): @@ -1312,7 +1388,7 @@ def pack_Transaction(self, data): self.pack_Memo(data.memo) if data.operations is None: raise TypeError('data.operations == None') - if len(data.operations) > 100 and self.check_array: + if len(data.operations) > const.MAX_OPS_PER_TX and self.check_array: raise XDRError('array length too long for data.operations') self.pack_array(data.operations, self.pack_Operation) if data.ext is None: @@ -1363,7 +1439,7 @@ def pack_ClaimOfferAtom(self, data): self.pack_AccountID(data.sellerID) if data.offerID is None: raise TypeError('data.offerID == None') - self.pack_uint64(data.offerID) + self.pack_int64(data.offerID) if data.assetSold is None: raise TypeError('data.assetSold == None') self.pack_Asset(data.assetSold) @@ -1455,11 +1531,11 @@ def pack_PathPaymentResult(self, data): else: pass - def pack_ManageOfferResultCode(self, data): - if hasattr(self, 'filter_ManageOfferResultCode'): - data = getattr(self, 'filter_ManageOfferResultCode')(data) - if self.check_enum and data not in [const.MANAGE_OFFER_SUCCESS, const.MANAGE_OFFER_MALFORMED, const.MANAGE_OFFER_SELL_NO_TRUST, const.MANAGE_OFFER_BUY_NO_TRUST, const.MANAGE_OFFER_SELL_NOT_AUTHORIZED, const.MANAGE_OFFER_BUY_NOT_AUTHORIZED, const.MANAGE_OFFER_LINE_FULL, const.MANAGE_OFFER_UNDERFUNDED, const.MANAGE_OFFER_CROSS_SELF, const.MANAGE_OFFER_SELL_NO_ISSUER, const.MANAGE_OFFER_BUY_NO_ISSUER, const.MANAGE_OFFER_NOT_FOUND, const.MANAGE_OFFER_LOW_RESERVE]: - raise XDRError('value=%s not in enum ManageOfferResultCode' % data) + def pack_ManageSellOfferResultCode(self, data): + if hasattr(self, 'filter_ManageSellOfferResultCode'): + data = getattr(self, 'filter_ManageSellOfferResultCode')(data) + if self.check_enum and data not in [const.MANAGE_SELL_OFFER_SUCCESS, const.MANAGE_SELL_OFFER_MALFORMED, const.MANAGE_SELL_OFFER_SELL_NO_TRUST, const.MANAGE_SELL_OFFER_BUY_NO_TRUST, const.MANAGE_SELL_OFFER_SELL_NOT_AUTHORIZED, const.MANAGE_SELL_OFFER_BUY_NOT_AUTHORIZED, const.MANAGE_SELL_OFFER_LINE_FULL, const.MANAGE_SELL_OFFER_UNDERFUNDED, const.MANAGE_SELL_OFFER_CROSS_SELF, const.MANAGE_SELL_OFFER_SELL_NO_ISSUER, const.MANAGE_SELL_OFFER_BUY_NO_ISSUER, const.MANAGE_SELL_OFFER_NOT_FOUND, const.MANAGE_SELL_OFFER_LOW_RESERVE]: + raise XDRError('value=%s not in enum ManageSellOfferResultCode' % data) self.pack_int(data) def pack_ManageOfferEffect(self, data): @@ -1487,13 +1563,33 @@ def pack_ManageOfferSuccessResult(self, data): else: pass - def pack_ManageOfferResult(self, data): - if hasattr(self, 'filter_ManageOfferResult'): - data = getattr(self, 'filter_ManageOfferResult')(data) + def pack_ManageSellOfferResult(self, data): + if hasattr(self, 'filter_ManageSellOfferResult'): + data = getattr(self, 'filter_ManageSellOfferResult')(data) if data.code is None: raise TypeError('data.code == None') - self.pack_ManageOfferResultCode(data.code) - if data.code == const.MANAGE_OFFER_SUCCESS: + self.pack_ManageSellOfferResultCode(data.code) + if data.code == const.MANAGE_SELL_OFFER_SUCCESS: + if data.success is None: + raise TypeError('data.success == None') + self.pack_ManageOfferSuccessResult(data.success) + else: + pass + + def pack_ManageBuyOfferResultCode(self, data): + if hasattr(self, 'filter_ManageBuyOfferResultCode'): + data = getattr(self, 'filter_ManageBuyOfferResultCode')(data) + if self.check_enum and data not in [const.MANAGE_BUY_OFFER_SUCCESS, const.MANAGE_BUY_OFFER_MALFORMED, const.MANAGE_BUY_OFFER_SELL_NO_TRUST, const.MANAGE_BUY_OFFER_BUY_NO_TRUST, const.MANAGE_BUY_OFFER_SELL_NOT_AUTHORIZED, const.MANAGE_BUY_OFFER_BUY_NOT_AUTHORIZED, const.MANAGE_BUY_OFFER_LINE_FULL, const.MANAGE_BUY_OFFER_UNDERFUNDED, const.MANAGE_BUY_OFFER_CROSS_SELF, const.MANAGE_BUY_OFFER_SELL_NO_ISSUER, const.MANAGE_BUY_OFFER_BUY_NO_ISSUER, const.MANAGE_BUY_OFFER_NOT_FOUND, const.MANAGE_BUY_OFFER_LOW_RESERVE]: + raise XDRError('value=%s not in enum ManageBuyOfferResultCode' % data) + self.pack_int(data) + + def pack_ManageBuyOfferResult(self, data): + if hasattr(self, 'filter_ManageBuyOfferResult'): + data = getattr(self, 'filter_ManageBuyOfferResult')(data) + if data.code is None: + raise TypeError('data.code == None') + self.pack_ManageBuyOfferResultCode(data.code) + if data.code == const.MANAGE_BUY_OFFER_SUCCESS: if data.success is None: raise TypeError('data.success == None') self.pack_ManageOfferSuccessResult(data.success) @@ -1643,7 +1739,7 @@ def pack_BumpSequenceResult(self, data): def pack_OperationResultCode(self, data): if hasattr(self, 'filter_OperationResultCode'): data = getattr(self, 'filter_OperationResultCode')(data) - if self.check_enum and data not in [const.opINNER, const.opBAD_AUTH, const.opNO_ACCOUNT, const.opNOT_SUPPORTED]: + if self.check_enum and data not in [const.opINNER, const.opBAD_AUTH, const.opNO_ACCOUNT, const.opNOT_SUPPORTED, const.opTOO_MANY_SUBENTRIES, const.opEXCEEDED_WORK_LIMIT]: raise XDRError('value=%s not in enum OperationResultCode' % data) self.pack_int(data) @@ -1671,14 +1767,14 @@ def pack_OperationResult(self, data): if data.tr.pathPaymentResult is None: raise TypeError('data.tr.pathPaymentResult == None') self.pack_PathPaymentResult(data.tr.pathPaymentResult) - elif data.tr.type == const.MANAGE_OFFER: - if data.tr.manageOfferResult is None: - raise TypeError('data.tr.manageOfferResult == None') - self.pack_ManageOfferResult(data.tr.manageOfferResult) - elif data.tr.type == const.CREATE_PASSIVE_OFFER: - if data.tr.createPassiveOfferResult is None: - raise TypeError('data.tr.createPassiveOfferResult == None') - self.pack_ManageOfferResult(data.tr.createPassiveOfferResult) + elif data.tr.type == const.MANAGE_SELL_OFFER: + if data.tr.manageSellOfferResult is None: + raise TypeError('data.tr.manageSellOfferResult == None') + self.pack_ManageSellOfferResult(data.tr.manageSellOfferResult) + elif data.tr.type == const.CREATE_PASSIVE_SELL_OFFER: + if data.tr.createPassiveSellOfferResult is None: + raise TypeError('data.tr.createPassiveSellOfferResult == None') + self.pack_ManageSellOfferResult(data.tr.createPassiveSellOfferResult) elif data.tr.type == const.SET_OPTIONS: if data.tr.setOptionsResult is None: raise TypeError('data.tr.setOptionsResult == None') @@ -1707,6 +1803,10 @@ def pack_OperationResult(self, data): if data.tr.bumpSeqResult is None: raise TypeError('data.tr.bumpSeqResult == None') self.pack_BumpSequenceResult(data.tr.bumpSeqResult) + elif data.tr.type == const.MANAGE_BUY_OFFER: + if data.tr.manageBuyOfferResult is None: + raise TypeError('data.tr.manageBuyOfferResult == None') + self.pack_ManageBuyOfferResult(data.tr.manageBuyOfferResult) else: raise XDRError('bad switch=%s' % data.tr.type) else: @@ -2174,17 +2274,35 @@ def unpack_UpgradeType(self): data = getattr(self, 'filter_UpgradeType')(data) return data + def unpack_StellarValueType(self): + data = self.unpack_int() + if self.check_enum and data not in [const.STELLAR_VALUE_BASIC, const.STELLAR_VALUE_SIGNED]: + raise XDRError('value=%s not in enum StellarValueType' % data) + if hasattr(self, 'filter_StellarValueType'): + data = getattr(self, 'filter_StellarValueType')(data) + return data + + def unpack_LedgerCloseValueSignature(self): + data = types.LedgerCloseValueSignature() + data.nodeID = self.unpack_NodeID() + data.signature = self.unpack_Signature() + if hasattr(self, 'filter_LedgerCloseValueSignature'): + data = getattr(self, 'filter_LedgerCloseValueSignature')(data) + return data + def unpack_StellarValue(self): data = types.StellarValue() data.txSetHash = self.unpack_Hash() - data.closeTime = self.unpack_uint64() + data.closeTime = self.unpack_TimePoint() data.upgrades = self.unpack_array(self.unpack_UpgradeType) if len(data.upgrades) > 6 and self.check_array: raise XDRError('array length too long for data.upgrades') data.ext = nullclass() - data.ext.v = self.unpack_int() - if data.ext.v == 0: + data.ext.v = self.unpack_StellarValueType() + if data.ext.v == const.STELLAR_VALUE_BASIC: pass + elif data.ext.v == const.STELLAR_VALUE_SIGNED: + data.ext.lcValueSignature = self.unpack_LedgerCloseValueSignature() else: raise XDRError('bad switch=%s' % data.ext.v) if hasattr(self, 'filter_StellarValue'): @@ -2255,7 +2373,7 @@ def unpack_LedgerKey(self): elif data.type == const.OFFER: data.offer = nullclass() data.offer.sellerID = self.unpack_AccountID() - data.offer.offerID = self.unpack_uint64() + data.offer.offerID = self.unpack_int64() elif data.type == const.DATA: data.data = nullclass() data.data.accountID = self.unpack_AccountID() @@ -2268,19 +2386,34 @@ def unpack_LedgerKey(self): def unpack_BucketEntryType(self): data = self.unpack_int() - if self.check_enum and data not in [const.LIVEENTRY, const.DEADENTRY]: + if self.check_enum and data not in [const.METAENTRY, const.LIVEENTRY, const.DEADENTRY, const.INITENTRY]: raise XDRError('value=%s not in enum BucketEntryType' % data) if hasattr(self, 'filter_BucketEntryType'): data = getattr(self, 'filter_BucketEntryType')(data) return data + def unpack_BucketMetadata(self): + data = types.BucketMetadata() + data.ledgerVersion = self.unpack_uint32() + data.ext = nullclass() + data.ext.v = self.unpack_int() + if data.ext.v == 0: + pass + else: + raise XDRError('bad switch=%s' % data.ext.v) + if hasattr(self, 'filter_BucketMetadata'): + data = getattr(self, 'filter_BucketMetadata')(data) + return data + def unpack_BucketEntry(self): data = types.BucketEntry() data.type = self.unpack_BucketEntryType() - if data.type == const.LIVEENTRY: + if data.type == const.LIVEENTRY or data.type == const.INITENTRY: data.liveEntry = self.unpack_LedgerEntry() elif data.type == const.DEADENTRY: data.deadEntry = self.unpack_LedgerKey() + elif data.type == const.METAENTRY: + data.metaEntry = self.unpack_BucketMetadata() else: raise XDRError('bad switch=%s' % data.type) if hasattr(self, 'filter_BucketEntry'): @@ -2464,6 +2597,8 @@ def unpack_string64(self): unpack_SequenceNumber = unpack_int64 + unpack_TimePoint = unpack_uint64 + def unpack_DataValue(self): data = self.unpack_opaque() if len(data) > 64 and self.check_array: @@ -2472,6 +2607,18 @@ def unpack_DataValue(self): data = getattr(self, 'filter_DataValue')(data) return data + def unpack_AssetCode4(self): + data = self.unpack_fopaque(4) + if hasattr(self, 'filter_AssetCode4'): + data = getattr(self, 'filter_AssetCode4')(data) + return data + + def unpack_AssetCode12(self): + data = self.unpack_fopaque(12) + if hasattr(self, 'filter_AssetCode12'): + data = getattr(self, 'filter_AssetCode12')(data) + return data + def unpack_AssetType(self): data = self.unpack_int() if self.check_enum and data not in [const.ASSET_TYPE_NATIVE, const.ASSET_TYPE_CREDIT_ALPHANUM4, const.ASSET_TYPE_CREDIT_ALPHANUM12]: @@ -2487,11 +2634,11 @@ def unpack_Asset(self): pass elif data.type == const.ASSET_TYPE_CREDIT_ALPHANUM4: data.alphaNum4 = nullclass() - data.alphaNum4.assetCode = self.unpack_fopaque(4) + data.alphaNum4.assetCode = self.unpack_AssetCode4() data.alphaNum4.issuer = self.unpack_AccountID() elif data.type == const.ASSET_TYPE_CREDIT_ALPHANUM12: data.alphaNum12 = nullclass() - data.alphaNum12.assetCode = self.unpack_fopaque(12) + data.alphaNum12.assetCode = self.unpack_AssetCode12() data.alphaNum12.issuer = self.unpack_AccountID() else: raise XDRError('bad switch=%s' % data.type) @@ -2626,7 +2773,7 @@ def unpack_OfferEntryFlags(self): def unpack_OfferEntry(self): data = types.OfferEntry() data.sellerID = self.unpack_AccountID() - data.offerID = self.unpack_uint64() + data.offerID = self.unpack_int64() data.selling = self.unpack_Asset() data.buying = self.unpack_Asset() data.amount = self.unpack_int64() @@ -2684,7 +2831,7 @@ def unpack_LedgerEntry(self): def unpack_EnvelopeType(self): data = self.unpack_int() - if self.check_enum and data not in [const.ENVELOPE_TYPE_SCP, const.ENVELOPE_TYPE_TX, const.ENVELOPE_TYPE_AUTH]: + if self.check_enum and data not in [const.ENVELOPE_TYPE_SCP, const.ENVELOPE_TYPE_TX, const.ENVELOPE_TYPE_AUTH, const.ENVELOPE_TYPE_SCPVALUE]: raise XDRError('value=%s not in enum EnvelopeType' % data) if hasattr(self, 'filter_EnvelopeType'): data = getattr(self, 'filter_EnvelopeType')(data) @@ -2700,7 +2847,7 @@ def unpack_DecoratedSignature(self): def unpack_OperationType(self): data = self.unpack_int() - if self.check_enum and data not in [const.CREATE_ACCOUNT, const.PAYMENT, const.PATH_PAYMENT, const.MANAGE_OFFER, const.CREATE_PASSIVE_OFFER, const.SET_OPTIONS, const.CHANGE_TRUST, const.ALLOW_TRUST, const.ACCOUNT_MERGE, const.INFLATION, const.MANAGE_DATA, const.BUMP_SEQUENCE]: + if self.check_enum and data not in [const.CREATE_ACCOUNT, const.PAYMENT, const.PATH_PAYMENT, const.MANAGE_SELL_OFFER, const.CREATE_PASSIVE_SELL_OFFER, const.SET_OPTIONS, const.CHANGE_TRUST, const.ALLOW_TRUST, const.ACCOUNT_MERGE, const.INFLATION, const.MANAGE_DATA, const.BUMP_SEQUENCE, const.MANAGE_BUY_OFFER]: raise XDRError('value=%s not in enum OperationType' % data) if hasattr(self, 'filter_OperationType'): data = getattr(self, 'filter_OperationType')(data) @@ -2737,25 +2884,36 @@ def unpack_PathPaymentOp(self): data = getattr(self, 'filter_PathPaymentOp')(data) return data - def unpack_ManageOfferOp(self): - data = types.ManageOfferOp() + def unpack_ManageSellOfferOp(self): + data = types.ManageSellOfferOp() data.selling = self.unpack_Asset() data.buying = self.unpack_Asset() data.amount = self.unpack_int64() data.price = self.unpack_Price() - data.offerID = self.unpack_uint64() - if hasattr(self, 'filter_ManageOfferOp'): - data = getattr(self, 'filter_ManageOfferOp')(data) + data.offerID = self.unpack_int64() + if hasattr(self, 'filter_ManageSellOfferOp'): + data = getattr(self, 'filter_ManageSellOfferOp')(data) return data - def unpack_CreatePassiveOfferOp(self): - data = types.CreatePassiveOfferOp() + def unpack_ManageBuyOfferOp(self): + data = types.ManageBuyOfferOp() + data.selling = self.unpack_Asset() + data.buying = self.unpack_Asset() + data.buyAmount = self.unpack_int64() + data.price = self.unpack_Price() + data.offerID = self.unpack_int64() + if hasattr(self, 'filter_ManageBuyOfferOp'): + data = getattr(self, 'filter_ManageBuyOfferOp')(data) + return data + + def unpack_CreatePassiveSellOfferOp(self): + data = types.CreatePassiveSellOfferOp() data.selling = self.unpack_Asset() data.buying = self.unpack_Asset() data.amount = self.unpack_int64() data.price = self.unpack_Price() - if hasattr(self, 'filter_CreatePassiveOfferOp'): - data = getattr(self, 'filter_CreatePassiveOfferOp')(data) + if hasattr(self, 'filter_CreatePassiveSellOfferOp'): + data = getattr(self, 'filter_CreatePassiveSellOfferOp')(data) return data def unpack_SetOptionsOp(self): @@ -2805,9 +2963,9 @@ def unpack_AllowTrustOp(self): data.asset = nullclass() data.asset.type = self.unpack_AssetType() if data.asset.type == const.ASSET_TYPE_CREDIT_ALPHANUM4: - data.asset.assetCode4 = self.unpack_fopaque(4) + data.asset.assetCode4 = self.unpack_AssetCode4() elif data.asset.type == const.ASSET_TYPE_CREDIT_ALPHANUM12: - data.asset.assetCode12 = self.unpack_fopaque(12) + data.asset.assetCode12 = self.unpack_AssetCode12() else: raise XDRError('bad switch=%s' % data.asset.type) data.authorize = self.unpack_bool() @@ -2845,10 +3003,10 @@ def unpack_Operation(self): data.body.paymentOp = self.unpack_PaymentOp() elif data.body.type == const.PATH_PAYMENT: data.body.pathPaymentOp = self.unpack_PathPaymentOp() - elif data.body.type == const.MANAGE_OFFER: - data.body.manageOfferOp = self.unpack_ManageOfferOp() - elif data.body.type == const.CREATE_PASSIVE_OFFER: - data.body.createPassiveOfferOp = self.unpack_CreatePassiveOfferOp() + elif data.body.type == const.MANAGE_SELL_OFFER: + data.body.manageSellOfferOp = self.unpack_ManageSellOfferOp() + elif data.body.type == const.CREATE_PASSIVE_SELL_OFFER: + data.body.createPassiveSellOfferOp = self.unpack_CreatePassiveSellOfferOp() elif data.body.type == const.SET_OPTIONS: data.body.setOptionsOp = self.unpack_SetOptionsOp() elif data.body.type == const.CHANGE_TRUST: @@ -2863,6 +3021,8 @@ def unpack_Operation(self): data.body.manageDataOp = self.unpack_ManageDataOp() elif data.body.type == const.BUMP_SEQUENCE: data.body.bumpSequenceOp = self.unpack_BumpSequenceOp() + elif data.body.type == const.MANAGE_BUY_OFFER: + data.body.manageBuyOfferOp = self.unpack_ManageBuyOfferOp() else: raise XDRError('bad switch=%s' % data.body.type) if hasattr(self, 'filter_Operation'): @@ -2900,8 +3060,8 @@ def unpack_Memo(self): def unpack_TimeBounds(self): data = types.TimeBounds() - data.minTime = self.unpack_uint64() - data.maxTime = self.unpack_uint64() + data.minTime = self.unpack_TimePoint() + data.maxTime = self.unpack_TimePoint() if hasattr(self, 'filter_TimeBounds'): data = getattr(self, 'filter_TimeBounds')(data) return data @@ -2916,7 +3076,7 @@ def unpack_Transaction(self): raise XDRError('array length too long for data.timeBounds') data.memo = self.unpack_Memo() data.operations = self.unpack_array(self.unpack_Operation) - if len(data.operations) > 100 and self.check_array: + if len(data.operations) > const.MAX_OPS_PER_TX and self.check_array: raise XDRError('array length too long for data.operations') data.ext = nullclass() data.ext.v = self.unpack_int() @@ -2954,7 +3114,7 @@ def unpack_TransactionEnvelope(self): def unpack_ClaimOfferAtom(self): data = types.ClaimOfferAtom() data.sellerID = self.unpack_AccountID() - data.offerID = self.unpack_uint64() + data.offerID = self.unpack_int64() data.assetSold = self.unpack_Asset() data.amountSold = self.unpack_int64() data.assetBought = self.unpack_Asset() @@ -3033,12 +3193,12 @@ def unpack_PathPaymentResult(self): data = getattr(self, 'filter_PathPaymentResult')(data) return data - def unpack_ManageOfferResultCode(self): + def unpack_ManageSellOfferResultCode(self): data = self.unpack_int() - if self.check_enum and data not in [const.MANAGE_OFFER_SUCCESS, const.MANAGE_OFFER_MALFORMED, const.MANAGE_OFFER_SELL_NO_TRUST, const.MANAGE_OFFER_BUY_NO_TRUST, const.MANAGE_OFFER_SELL_NOT_AUTHORIZED, const.MANAGE_OFFER_BUY_NOT_AUTHORIZED, const.MANAGE_OFFER_LINE_FULL, const.MANAGE_OFFER_UNDERFUNDED, const.MANAGE_OFFER_CROSS_SELF, const.MANAGE_OFFER_SELL_NO_ISSUER, const.MANAGE_OFFER_BUY_NO_ISSUER, const.MANAGE_OFFER_NOT_FOUND, const.MANAGE_OFFER_LOW_RESERVE]: - raise XDRError('value=%s not in enum ManageOfferResultCode' % data) - if hasattr(self, 'filter_ManageOfferResultCode'): - data = getattr(self, 'filter_ManageOfferResultCode')(data) + if self.check_enum and data not in [const.MANAGE_SELL_OFFER_SUCCESS, const.MANAGE_SELL_OFFER_MALFORMED, const.MANAGE_SELL_OFFER_SELL_NO_TRUST, const.MANAGE_SELL_OFFER_BUY_NO_TRUST, const.MANAGE_SELL_OFFER_SELL_NOT_AUTHORIZED, const.MANAGE_SELL_OFFER_BUY_NOT_AUTHORIZED, const.MANAGE_SELL_OFFER_LINE_FULL, const.MANAGE_SELL_OFFER_UNDERFUNDED, const.MANAGE_SELL_OFFER_CROSS_SELF, const.MANAGE_SELL_OFFER_SELL_NO_ISSUER, const.MANAGE_SELL_OFFER_BUY_NO_ISSUER, const.MANAGE_SELL_OFFER_NOT_FOUND, const.MANAGE_SELL_OFFER_LOW_RESERVE]: + raise XDRError('value=%s not in enum ManageSellOfferResultCode' % data) + if hasattr(self, 'filter_ManageSellOfferResultCode'): + data = getattr(self, 'filter_ManageSellOfferResultCode')(data) return data def unpack_ManageOfferEffect(self): @@ -3062,15 +3222,34 @@ def unpack_ManageOfferSuccessResult(self): data = getattr(self, 'filter_ManageOfferSuccessResult')(data) return data - def unpack_ManageOfferResult(self): - data = types.ManageOfferResult() - data.code = self.unpack_ManageOfferResultCode() - if data.code == const.MANAGE_OFFER_SUCCESS: + def unpack_ManageSellOfferResult(self): + data = types.ManageSellOfferResult() + data.code = self.unpack_ManageSellOfferResultCode() + if data.code == const.MANAGE_SELL_OFFER_SUCCESS: + data.success = self.unpack_ManageOfferSuccessResult() + else: + pass + if hasattr(self, 'filter_ManageSellOfferResult'): + data = getattr(self, 'filter_ManageSellOfferResult')(data) + return data + + def unpack_ManageBuyOfferResultCode(self): + data = self.unpack_int() + if self.check_enum and data not in [const.MANAGE_BUY_OFFER_SUCCESS, const.MANAGE_BUY_OFFER_MALFORMED, const.MANAGE_BUY_OFFER_SELL_NO_TRUST, const.MANAGE_BUY_OFFER_BUY_NO_TRUST, const.MANAGE_BUY_OFFER_SELL_NOT_AUTHORIZED, const.MANAGE_BUY_OFFER_BUY_NOT_AUTHORIZED, const.MANAGE_BUY_OFFER_LINE_FULL, const.MANAGE_BUY_OFFER_UNDERFUNDED, const.MANAGE_BUY_OFFER_CROSS_SELF, const.MANAGE_BUY_OFFER_SELL_NO_ISSUER, const.MANAGE_BUY_OFFER_BUY_NO_ISSUER, const.MANAGE_BUY_OFFER_NOT_FOUND, const.MANAGE_BUY_OFFER_LOW_RESERVE]: + raise XDRError('value=%s not in enum ManageBuyOfferResultCode' % data) + if hasattr(self, 'filter_ManageBuyOfferResultCode'): + data = getattr(self, 'filter_ManageBuyOfferResultCode')(data) + return data + + def unpack_ManageBuyOfferResult(self): + data = types.ManageBuyOfferResult() + data.code = self.unpack_ManageBuyOfferResultCode() + if data.code == const.MANAGE_BUY_OFFER_SUCCESS: data.success = self.unpack_ManageOfferSuccessResult() else: pass - if hasattr(self, 'filter_ManageOfferResult'): - data = getattr(self, 'filter_ManageOfferResult')(data) + if hasattr(self, 'filter_ManageBuyOfferResult'): + data = getattr(self, 'filter_ManageBuyOfferResult')(data) return data def unpack_SetOptionsResultCode(self): @@ -3216,7 +3395,7 @@ def unpack_BumpSequenceResult(self): def unpack_OperationResultCode(self): data = self.unpack_int() - if self.check_enum and data not in [const.opINNER, const.opBAD_AUTH, const.opNO_ACCOUNT, const.opNOT_SUPPORTED]: + if self.check_enum and data not in [const.opINNER, const.opBAD_AUTH, const.opNO_ACCOUNT, const.opNOT_SUPPORTED, const.opTOO_MANY_SUBENTRIES, const.opEXCEEDED_WORK_LIMIT]: raise XDRError('value=%s not in enum OperationResultCode' % data) if hasattr(self, 'filter_OperationResultCode'): data = getattr(self, 'filter_OperationResultCode')(data) @@ -3234,10 +3413,10 @@ def unpack_OperationResult(self): data.tr.paymentResult = self.unpack_PaymentResult() elif data.tr.type == const.PATH_PAYMENT: data.tr.pathPaymentResult = self.unpack_PathPaymentResult() - elif data.tr.type == const.MANAGE_OFFER: - data.tr.manageOfferResult = self.unpack_ManageOfferResult() - elif data.tr.type == const.CREATE_PASSIVE_OFFER: - data.tr.createPassiveOfferResult = self.unpack_ManageOfferResult() + elif data.tr.type == const.MANAGE_SELL_OFFER: + data.tr.manageSellOfferResult = self.unpack_ManageSellOfferResult() + elif data.tr.type == const.CREATE_PASSIVE_SELL_OFFER: + data.tr.createPassiveSellOfferResult = self.unpack_ManageSellOfferResult() elif data.tr.type == const.SET_OPTIONS: data.tr.setOptionsResult = self.unpack_SetOptionsResult() elif data.tr.type == const.CHANGE_TRUST: @@ -3252,6 +3431,8 @@ def unpack_OperationResult(self): data.tr.manageDataResult = self.unpack_ManageDataResult() elif data.tr.type == const.BUMP_SEQUENCE: data.tr.bumpSeqResult = self.unpack_BumpSequenceResult() + elif data.tr.type == const.MANAGE_BUY_OFFER: + data.tr.manageBuyOfferResult = self.unpack_ManageBuyOfferResult() else: raise XDRError('bad switch=%s' % data.tr.type) else: diff --git a/stellar_base/stellarxdr/StellarXDR_type.py b/stellar_base/stellarxdr/StellarXDR_type.py index 6da98276..6ae3657f 100644 --- a/stellar_base/stellarxdr/StellarXDR_type.py +++ b/stellar_base/stellarxdr/StellarXDR_type.py @@ -1,4 +1,4 @@ -# Generated by xdrgen.py from ../xdr/ on Sat Apr 20 11:56:38 2019 +# Generated by xdrgen.py from ../xdr/ on Sat Apr 27 13:37:03 2019 from . import StellarXDR_const as const class PublicKey: # XDR definition: @@ -261,15 +261,41 @@ def __repr__(self): return 'SCPQuorumSet(%s)' % ', '.join(out) __str__ = __repr__ +class LedgerCloseValueSignature: + # XDR definition: + # struct LedgerCloseValueSignature { + # NodeID nodeID; + # Signature signature; + # }; + def __init__(self, nodeID=None, signature=None): + self.nodeID = nodeID + self.signature = signature + + def __getattr__(self, attr): + if attr is '__setstate__': + raise AttributeError + return getattr(self.nodeID, attr) + + def __repr__(self): + out = [] + if self.nodeID is not None: + out += ['nodeID=%s' % repr(self.nodeID)] + if self.signature is not None: + out += ['signature=%s' % repr(self.signature)] + return 'LedgerCloseValueSignature(%s)' % ', '.join(out) + __str__ = __repr__ + class StellarValue: # XDR definition: # struct StellarValue { # Hash txSetHash; - # uint64 closeTime; + # TimePoint closeTime; # UpgradeType upgrades<6>; - # union switch(int v) { - # case 0: + # union switch(StellarValueType v) { + # case STELLAR_VALUE_BASIC: # void; + # case STELLAR_VALUE_SIGNED: + # LedgerCloseValueSignature lcValueSignature; # } ext; # }; def __init__(self, txSetHash=None, closeTime=None, upgrades=None, ext=None): @@ -426,7 +452,7 @@ class LedgerKey: # case OFFER: # struct { # AccountID sellerID; - # uint64 offerID; + # int64 offerID; # } offer; # case DATA: # struct { @@ -463,20 +489,51 @@ def __repr__(self): return 'LedgerKey(%s)' % ', '.join(out) __str__ = __repr__ +class BucketMetadata: + # XDR definition: + # struct BucketMetadata { + # uint32 ledgerVersion; + # union switch(int v) { + # case 0: + # void; + # } ext; + # }; + def __init__(self, ledgerVersion=None, ext=None): + self.ledgerVersion = ledgerVersion + self.ext = ext + + def __getattr__(self, attr): + if attr is '__setstate__': + raise AttributeError + return getattr(self.ext, attr) + + def __repr__(self): + out = [] + if self.ledgerVersion is not None: + out += ['ledgerVersion=%s' % repr(self.ledgerVersion)] + if self.ext is not None: + out += ['ext=%s' % repr(self.ext)] + return 'BucketMetadata(%s)' % ', '.join(out) + __str__ = __repr__ + class BucketEntry: # XDR definition: # union BucketEntry switch(BucketEntryType type) { # case LIVEENTRY: + # case INITENTRY: # LedgerEntry liveEntry; # case DEADENTRY: # LedgerKey deadEntry; + # case METAENTRY: + # BucketMetadata metaEntry; # }; - def __init__(self, type=None, liveEntry=None, deadEntry=None): + def __init__(self, type=None, liveEntry=None, deadEntry=None, metaEntry=None): self.type = type self.liveEntry = liveEntry self.deadEntry = deadEntry + self.metaEntry = metaEntry - switch = property(lambda s: {const.LIVEENTRY:s.liveEntry,const.DEADENTRY:s.deadEntry,}[s.type]) + switch = property(lambda s: {const.LIVEENTRY:s.liveEntry,const.INITENTRY:s.liveEntry,const.DEADENTRY:s.deadEntry,const.METAENTRY:s.metaEntry,}[s.type]) def __getattr__(self, attr): if attr is '__setstate__': @@ -491,6 +548,8 @@ def __repr__(self): out += ['liveEntry=%s' % repr(self.liveEntry)] if self.deadEntry is not None: out += ['deadEntry=%s' % repr(self.deadEntry)] + if self.metaEntry is not None: + out += ['metaEntry=%s' % repr(self.metaEntry)] return 'BucketEntry(%s)' % ', '.join(out) __str__ = __repr__ @@ -813,12 +872,12 @@ class Asset: # void; # case ASSET_TYPE_CREDIT_ALPHANUM4: # struct { - # opaque assetCode[4]; + # AssetCode4 assetCode; # AccountID issuer; # } alphaNum4; # case ASSET_TYPE_CREDIT_ALPHANUM12: # struct { - # opaque assetCode[12]; + # AssetCode12 assetCode; # AccountID issuer; # } alphaNum12; # }; @@ -1019,7 +1078,7 @@ class OfferEntry: # XDR definition: # struct OfferEntry { # AccountID sellerID; - # uint64 offerID; + # int64 offerID; # Asset selling; # Asset buying; # int64 amount; @@ -1227,14 +1286,14 @@ def __repr__(self): return 'PathPaymentOp(%s)' % ', '.join(out) __str__ = __repr__ -class ManageOfferOp: +class ManageSellOfferOp: # XDR definition: - # struct ManageOfferOp { + # struct ManageSellOfferOp { # Asset selling; # Asset buying; # int64 amount; # Price price; - # uint64 offerID; + # int64 offerID; # }; def __init__(self, selling=None, buying=None, amount=None, price=None, offerID=None): self.selling = selling @@ -1255,12 +1314,43 @@ def __repr__(self): out += ['price=%s' % repr(self.price)] if self.offerID is not None: out += ['offerID=%s' % repr(self.offerID)] - return 'ManageOfferOp(%s)' % ', '.join(out) + return 'ManageSellOfferOp(%s)' % ', '.join(out) __str__ = __repr__ -class CreatePassiveOfferOp: +class ManageBuyOfferOp: # XDR definition: - # struct CreatePassiveOfferOp { + # struct ManageBuyOfferOp { + # Asset selling; + # Asset buying; + # int64 buyAmount; + # Price price; + # int64 offerID; + # }; + def __init__(self, selling=None, buying=None, buyAmount=None, price=None, offerID=None): + self.selling = selling + self.buying = buying + self.buyAmount = buyAmount + self.price = price + self.offerID = offerID + + def __repr__(self): + out = [] + if self.selling is not None: + out += ['selling=%s' % repr(self.selling)] + if self.buying is not None: + out += ['buying=%s' % repr(self.buying)] + if self.buyAmount is not None: + out += ['buyAmount=%s' % repr(self.buyAmount)] + if self.price is not None: + out += ['price=%s' % repr(self.price)] + if self.offerID is not None: + out += ['offerID=%s' % repr(self.offerID)] + return 'ManageBuyOfferOp(%s)' % ', '.join(out) + __str__ = __repr__ + +class CreatePassiveSellOfferOp: + # XDR definition: + # struct CreatePassiveSellOfferOp { # Asset selling; # Asset buying; # int64 amount; @@ -1282,7 +1372,7 @@ def __repr__(self): out += ['amount=%s' % repr(self.amount)] if self.price is not None: out += ['price=%s' % repr(self.price)] - return 'CreatePassiveOfferOp(%s)' % ', '.join(out) + return 'CreatePassiveSellOfferOp(%s)' % ', '.join(out) __str__ = __repr__ class SetOptionsOp: @@ -1362,9 +1452,9 @@ class AllowTrustOp: # AccountID trustor; # union switch(AssetType type) { # case ASSET_TYPE_CREDIT_ALPHANUM4: - # opaque assetCode4[4]; + # AssetCode4 assetCode4; # case ASSET_TYPE_CREDIT_ALPHANUM12: - # opaque assetCode12[12]; + # AssetCode12 assetCode12; # } asset; # bool authorize; # }; @@ -1429,10 +1519,10 @@ class 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: @@ -1447,6 +1537,8 @@ class Operation: # ManageDataOp manageDataOp; # case BUMP_SEQUENCE: # BumpSequenceOp bumpSequenceOp; + # case MANAGE_BUY_OFFER: + # ManageBuyOfferOp manageBuyOfferOp; # } body; # }; def __init__(self, sourceAccount=None, body=None): @@ -1513,8 +1605,8 @@ def __repr__(self): class TimeBounds: # XDR definition: # struct TimeBounds { - # uint64 minTime; - # uint64 maxTime; + # TimePoint minTime; + # TimePoint maxTime; # }; def __init__(self, minTime=None, maxTime=None): self.minTime = minTime @@ -1537,7 +1629,7 @@ class Transaction: # SequenceNumber seqNum; # TimeBounds timeBounds<1>; # Memo memo; - # Operation operations<100>; + # Operation operations; # union switch(int v) { # case 0: # void; @@ -1626,7 +1718,7 @@ class ClaimOfferAtom: # XDR definition: # struct ClaimOfferAtom { # AccountID sellerID; - # uint64 offerID; + # int64 offerID; # Asset assetSold; # int64 amountSold; # Asset assetBought; @@ -1796,10 +1888,38 @@ def __repr__(self): return 'ManageOfferSuccessResult(%s)' % ', '.join(out) __str__ = __repr__ -class ManageOfferResult: +class ManageSellOfferResult: + # XDR definition: + # union ManageSellOfferResult switch(ManageSellOfferResultCode code) { + # case MANAGE_SELL_OFFER_SUCCESS: + # ManageOfferSuccessResult success; + # default: + # void; + # }; + def __init__(self, code=None, success=None): + self.code = code + self.success = success + + switch = property(lambda s: {const.MANAGE_SELL_OFFER_SUCCESS:s.success,}.get(s.code, None)) + + def __getattr__(self, attr): + if attr is '__setstate__': + raise AttributeError + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.code is not None: + out += ['code=%s' % const.ManageSellOfferResultCode.get(self.code, self.code)] + if self.success is not None: + out += ['success=%s' % repr(self.success)] + return 'ManageSellOfferResult(%s)' % ', '.join(out) + __str__ = __repr__ + +class ManageBuyOfferResult: # XDR definition: - # union ManageOfferResult switch(ManageOfferResultCode code) { - # case MANAGE_OFFER_SUCCESS: + # union ManageBuyOfferResult switch(ManageBuyOfferResultCode code) { + # case MANAGE_BUY_OFFER_SUCCESS: # ManageOfferSuccessResult success; # default: # void; @@ -1808,7 +1928,7 @@ def __init__(self, code=None, success=None): self.code = code self.success = success - switch = property(lambda s: {const.MANAGE_OFFER_SUCCESS:s.success,}.get(s.code, None)) + switch = property(lambda s: {const.MANAGE_BUY_OFFER_SUCCESS:s.success,}.get(s.code, None)) def __getattr__(self, attr): if attr is '__setstate__': @@ -1818,10 +1938,10 @@ def __getattr__(self, attr): def __repr__(self): out = [] if self.code is not None: - out += ['code=%s' % const.ManageOfferResultCode.get(self.code, self.code)] + out += ['code=%s' % const.ManageBuyOfferResultCode.get(self.code, self.code)] if self.success is not None: out += ['success=%s' % repr(self.success)] - return 'ManageOfferResult(%s)' % ', '.join(out) + return 'ManageBuyOfferResult(%s)' % ', '.join(out) __str__ = __repr__ class SetOptionsResult: @@ -2040,10 +2160,10 @@ class OperationResult: # 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: @@ -2058,6 +2178,8 @@ class OperationResult: # ManageDataResult manageDataResult; # case BUMP_SEQUENCE: # BumpSequenceResult bumpSeqResult; + # case MANAGE_BUY_OFFER: + # ManageBuyOfferResult manageBuyOfferResult; # } tr; # default: # void; diff --git a/stellar_base/xdr/Stellar-ledger-entries.x b/stellar_base/xdr/Stellar-ledger-entries.x index ed7b09ad..b511de27 100644 --- a/stellar_base/xdr/Stellar-ledger-entries.x +++ b/stellar_base/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/stellar_base/xdr/Stellar-ledger.x b/stellar_base/xdr/Stellar-ledger.x index 5021112c..754edf7d 100644 --- a/stellar_base/xdr/Stellar-ledger.x +++ b/stellar_base/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/stellar_base/xdr/Stellar-transaction.x b/stellar_base/xdr/Stellar-transaction.x index 49276210..e84b204b 100644 --- a/stellar_base/xdr/Stellar-transaction.x +++ b/stellar_base/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: From 63c0161e72b129b339b264fe2fa57a057b45f6c9 Mon Sep 17 00:00:00 2001 From: overcat <4catcode@gmail.com> Date: Sat, 27 Apr 2019 15:15:42 +0800 Subject: [PATCH 2/4] Protocol v11 XDR changes --- stellar_base/builder.py | 127 ++++++++++++++++++++++++++ stellar_base/operation.py | 182 ++++++++++++++++++++++++++++++-------- 2 files changed, 271 insertions(+), 38 deletions(-) diff --git a/stellar_base/builder.py b/stellar_base/builder.py index 56b3b8a7..0dff4849 100644 --- a/stellar_base/builder.py +++ b/stellar_base/builder.py @@ -399,12 +399,96 @@ def append_manage_offer_op(self, :return: This builder instance. """ + warnings.warn( + "append_manage_offer_op has been deprecated, use append_manage_sell_offer_op instead.", + DeprecationWarning + ) # pragma: no cover selling = Asset(selling_code, selling_issuer) buying = Asset(buying_code, buying_issuer) op = operation.ManageOffer(selling, buying, amount, price, offer_id, source) return self.append_op(op) + def append_manage_buy_offer_op(self, + selling_code, + selling_issuer, + buying_code, + buying_issuer, + amount, + price, + offer_id=0, + source=None): + """Append a :class:`ManageBuyOfferOp ` + operation to the list of operations. + + :param str selling_code: The asset code for the asset the offer creator + is selling. + :param selling_issuer: The issuing address for the asset the offer + creator is selling. + :type selling_issuer: str, None + :param str buying_code: The asset code for the asset the offer creator + is buying. + :param buying_issuer: The issuing address for the asset the offer + creator is selling. + :type buying_issuer: str, None + :param str amount: Amount being bought. if set to. Set to 0 if you want + to delete an existing offer. + :param price: Price of thing being bought in terms of what you are selling. You can pass + in a number as a string or a dict like `{n: numerator, d: denominator}` + :type price: str, dict + :param int offer_id: The ID of the offer. 0 for new offer. Set to + existing offer ID to update or delete. + :param str source: The source address that is managing an offer on + Stellar's distributed exchange. + :return: This builder instance. + + """ + selling = Asset(selling_code, selling_issuer) + buying = Asset(buying_code, buying_issuer) + op = operation.ManageBuyOfferOp(selling, buying, amount, price, offer_id, + source) + return self.append_op(op) + + def append_manage_sell_offer_op(self, + selling_code, + selling_issuer, + buying_code, + buying_issuer, + amount, + price, + offer_id=0, + source=None): + """Append a :class:`ManageSellOffer ` + operation to the list of operations. + + :param str selling_code: The asset code for the asset the offer creator + is selling. + :param selling_issuer: The issuing address for the asset the offer + creator is selling. + :type selling_issuer: str, None + :param str buying_code: The asset code for the asset the offer creator + is buying. + :param buying_issuer: The issuing address for the asset the offer + creator is selling. + :type buying_issuer: str, None + :param str amount: Amount of the asset being sold. Set to 0 if you want + to delete an existing offer. + :param price: Price of 1 unit of selling in terms of buying. You can pass + in a number as a string or a dict like `{n: numerator, d: denominator}` + :type price: str, dict + :param int offer_id: The ID of the offer. 0 for new offer. Set to + existing offer ID to update or delete. + :param str source: The source address that is managing an offer on + Stellar's distributed exchange. + :return: This builder instance. + + """ + selling = Asset(selling_code, selling_issuer) + buying = Asset(buying_code, buying_issuer) + op = operation.ManageSellOffer(selling, buying, amount, price, offer_id, + source) + return self.append_op(op) + def append_create_passive_offer_op(self, selling_code, selling_issuer, @@ -437,12 +521,55 @@ def append_create_passive_offer_op(self, :return: This builder instance. """ + warnings.warn( + "append_create_passive_offer_op has been deprecated, use append_create_passive_sell_offer_op instead.", + DeprecationWarning + ) # pragma: no cover selling = Asset(selling_code, selling_issuer) buying = Asset(buying_code, buying_issuer) op = operation.CreatePassiveOffer(selling, buying, amount, price, source) return self.append_op(op) + def append_create_passive_sell_offer_op(self, + selling_code, + selling_issuer, + buying_code, + buying_issuer, + amount, + price, + source=None): + """Append a :class:`CreatePassiveSellOffer + ` operation to the list of + operations. + + :param str selling_code: The asset code for the asset the offer creator + is selling. + :param selling_issuer: The issuing address for the asset the offer + creator is selling. + :type selling_issuer: str, None + :param str buying_code: The asset code for the asset the offer creator + is buying. + :param buying_issuer: The issuing address for the asset the offer + creator is selling. + :type buying_issuer: str, None + :param str amount: Amount of the asset being sold. Set to 0 if you want + to delete an existing offer. + :param price: Price of 1 unit of selling in terms of buying. You can pass + in a number as a string or a dict like `{n: numerator, d: denominator}` + :type price: str, dict + :param str source: The source address that is creating a passive offer + on Stellar's distributed exchange. + :return: This builder instance. + + """ + + selling = Asset(selling_code, selling_issuer) + buying = Asset(buying_code, buying_issuer) + op = operation.CreatePassiveSellOffer(selling, buying, amount, price, + source) + return self.append_op(op) + def append_account_merge_op(self, destination, source=None): """Append a :class:`AccountMerge ` operation to the list of diff --git a/stellar_base/operation.py b/stellar_base/operation.py index 9027deef..9bc5bf55 100644 --- a/stellar_base/operation.py +++ b/stellar_base/operation.py @@ -2,6 +2,7 @@ import base64 import decimal +import warnings from decimal import Context, Decimal, Inexact from .asset import Asset @@ -737,11 +738,100 @@ def from_xdr_object(cls, op_xdr_object): signer_weight=signer_weight) -class ManageOffer(Operation): - """The :class:`ManageOffer` object, which represents a ManageOffer +class ManageBuyOffer(Operation): + """The :class:`ManageBuyOffer` object, which represents a ManageBuyOffer operation on Stellar's network. - Creates, updates, or deletes an offer. + Creates, updates, or deletes an buy offer. + + If you want to create a new offer set Offer ID to 0. + + If you want to update an existing offer set Offer ID to existing offer ID. + + If you want to delete an existing offer set Offer ID to existing offer ID + and set Amount to 0. + + Threshold: Medium + + :param Asset selling: What you're selling. + :param Asset buying: What you're buying. + :param str amount: Amount being bought. if set to 0, delete the offer. + :param price: Price of thing being bought in terms of what you are selling. + :type price: str, dict + :param int offer_id: If `0`, will create a new offer (default). Otherwise, + edits an existing offer. + :param str source: The source account (defaults to transaction source). + + """ + + @classmethod + def type_code(cls): + return Xdr.const.MANAGE_BUY_OFFER + + def __init__(self, selling, buying, amount, price, offer_id=0, + source=None): + super(ManageBuyOffer, self).__init__(source) + self.selling = selling # Asset + self.buying = buying # Asset + self.amount = amount + self.price = price + self.offer_id = offer_id + + def to_xdr_object(self): + """Creates an XDR Operation object that represents this + :class:`ManageOffer`. + + """ + selling = self.selling.to_xdr_object() + buying = self.buying.to_xdr_object() + price = Operation.to_xdr_price(self.price) + price = Xdr.types.Price(price['n'], price['d']) + + amount = Operation.to_xdr_amount(self.amount) + + manage_buy_offer_op = Xdr.types.ManageBuyOfferOp(selling, buying, amount, + price, self.offer_id) + self.body.type = Xdr.const.MANAGE_BUY_OFFER + self.body.manageBuyOfferOp = manage_buy_offer_op + return super(ManageBuyOffer, self).to_xdr_object() + + @classmethod + def from_xdr_object(cls, op_xdr_object): + """Creates a :class:`ManageOffer` object from an XDR Operation + object. + + """ + if not op_xdr_object.sourceAccount: + source = None + else: + source = encode_check( + 'account', op_xdr_object.sourceAccount[0].ed25519).decode() + + selling = Asset.from_xdr_object( + op_xdr_object.body.manageBuyOfferOp.selling) + buying = Asset.from_xdr_object(op_xdr_object.body.manageBuyOfferOp.buying) + amount = Operation.from_xdr_amount( + op_xdr_object.body.manageBuyOfferOp.buyAmount) + + n = op_xdr_object.body.manageBuyOfferOp.price.n + d = op_xdr_object.body.manageBuyOfferOp.price.d + price = division(n, d) + offer_id = op_xdr_object.body.manageBuyOfferOp.offerID + + return cls( + source=source, + selling=selling, + buying=buying, + amount=amount, + price=price, + offer_id=offer_id) + + +class ManageSellOffer(Operation): + """The :class:`ManageSellOffer` object, which represents a ManageSellOffer + operation on Stellar's network. + + Creates, updates, or deletes an sell offer. If you want to create a new offer set Offer ID to 0. @@ -767,11 +857,11 @@ class ManageOffer(Operation): @classmethod def type_code(cls): - return Xdr.const.MANAGE_OFFER + return Xdr.const.MANAGE_SELL_OFFER def __init__(self, selling, buying, amount, price, offer_id=0, source=None): - super(ManageOffer, self).__init__(source) + super(ManageSellOffer, self).__init__(source) self.selling = selling # Asset self.buying = buying # Asset self.amount = amount @@ -790,11 +880,11 @@ def to_xdr_object(self): amount = Operation.to_xdr_amount(self.amount) - manage_offer_op = Xdr.types.ManageOfferOp(selling, buying, amount, - price, self.offer_id) - self.body.type = Xdr.const.MANAGE_OFFER - self.body.manageOfferOp = manage_offer_op - return super(ManageOffer, self).to_xdr_object() + manage_sell_offer_op = Xdr.types.ManageSellOfferOp(selling, buying, amount, + price, self.offer_id) + self.body.type = Xdr.const.MANAGE_SELL_OFFER + self.body.manageSellOfferOp = manage_sell_offer_op + return super(ManageSellOffer, self).to_xdr_object() @classmethod def from_xdr_object(cls, op_xdr_object): @@ -809,15 +899,15 @@ def from_xdr_object(cls, op_xdr_object): 'account', op_xdr_object.sourceAccount[0].ed25519).decode() selling = Asset.from_xdr_object( - op_xdr_object.body.manageOfferOp.selling) - buying = Asset.from_xdr_object(op_xdr_object.body.manageOfferOp.buying) + op_xdr_object.body.manageSellOfferOp.selling) + buying = Asset.from_xdr_object(op_xdr_object.body.manageSellOfferOp.buying) amount = Operation.from_xdr_amount( - op_xdr_object.body.manageOfferOp.amount) + op_xdr_object.body.manageSellOfferOp.amount) - n = op_xdr_object.body.manageOfferOp.price.n - d = op_xdr_object.body.manageOfferOp.price.d + n = op_xdr_object.body.manageSellOfferOp.price.n + d = op_xdr_object.body.manageSellOfferOp.price.d price = division(n, d) - offer_id = op_xdr_object.body.manageOfferOp.offerID + offer_id = op_xdr_object.body.manageSellOfferOp.offerID return cls( source=source, @@ -828,25 +918,25 @@ def from_xdr_object(cls, op_xdr_object): offer_id=offer_id) -class CreatePassiveOffer(Operation): - """The :class:`CreatePassiveOffer` object, which represents a - CreatePassiveOffer operation on Stellar's network. +class CreatePassiveSellOffer(Operation): + """The :class:`CreatePassiveSellOffer` object, which represents a + CreatePassiveSellOffer operation on Stellar's network. - A passive offer is an offer that does not act on and take a reverse offer + A passive sell offer is an offer that does not act on and take a reverse offer of equal price. Instead, they only take offers of lesser price. For example, if an offer exists to buy 5 BTC for 30 XLM, and you make a passive - offer to buy 30 XLM for 5 BTC, your passive offer does not take the first + sell offer to buy 30 XLM for 5 BTC, your passive sell offer does not take the first offer. - Note that regular offers made later than your passive offer can act on and - take your passive offer, even if the regular offer is of the same price as - your passive offer. + Note that regular offers made later than your passive sell offer can act on and + take your passive sell offer, even if the regular offer is of the same price as + your passive sell offer. - Passive offers allow market makers to have zero spread. If you want to + Passive sell offers allow market makers to have zero spread. If you want to trade EUR for USD at 1:1 price and USD for EUR also at 1:1, you can create - two passive offers so the two offers don't immediately act on each other. + two passive sell offers so the two offers don't immediately act on each other. - Once the passive offer is created, you can manage it like any other offer + Once the passive sell offer is created, you can manage it like any other offer using the manage offer operation - see :class:`ManageOffer` for more details. @@ -863,10 +953,10 @@ class CreatePassiveOffer(Operation): @classmethod def type_code(cls): - return Xdr.const.CREATE_PASSIVE_OFFER + return Xdr.const.CREATE_PASSIVE_SELL_OFFER def __init__(self, selling, buying, amount, price, source=None): - super(CreatePassiveOffer, self).__init__(source) + super(CreatePassiveSellOffer, self).__init__(source) self.selling = selling self.buying = buying self.amount = amount @@ -885,11 +975,11 @@ def to_xdr_object(self): amount = Operation.to_xdr_amount(self.amount) - create_passive_offer_op = Xdr.types.CreatePassiveOfferOp( + create_passive_sell_offer_op = Xdr.types.CreatePassiveSellOfferOp( selling, buying, amount, price) - self.body.type = Xdr.const.CREATE_PASSIVE_OFFER - self.body.createPassiveOfferOp = create_passive_offer_op - return super(CreatePassiveOffer, self).to_xdr_object() + self.body.type = Xdr.const.CREATE_PASSIVE_SELL_OFFER + self.body.createPassiveSellOfferOp = create_passive_sell_offer_op + return super(CreatePassiveSellOffer, self).to_xdr_object() @classmethod def from_xdr_object(cls, op_xdr_object): @@ -904,14 +994,14 @@ def from_xdr_object(cls, op_xdr_object): 'account', op_xdr_object.sourceAccount[0].ed25519).decode() selling = Asset.from_xdr_object( - op_xdr_object.body.createPassiveOfferOp.selling) + op_xdr_object.body.createPassiveSellOfferOp.selling) buying = Asset.from_xdr_object( - op_xdr_object.body.createPassiveOfferOp.buying) + op_xdr_object.body.createPassiveSellOfferOp.buying) amount = Operation.from_xdr_amount( - op_xdr_object.body.createPassiveOfferOp.amount) + op_xdr_object.body.createPassiveSellOfferOp.amount) - n = op_xdr_object.body.createPassiveOfferOp.price.n - d = op_xdr_object.body.createPassiveOfferOp.price.d + n = op_xdr_object.body.createPassiveSellOfferOp.price.n + d = op_xdr_object.body.createPassiveSellOfferOp.price.d price = division(n, d) return cls( source=source, @@ -1141,3 +1231,19 @@ def from_xdr_object(cls, op_xdr_object): bump_to = op_xdr_object.body.bumpSequenceOp.bumpTo return cls(source=source, bump_to=bump_to) + + +def ManageOffer(*args, **kwargs): + warnings.warn( + "ManageOffer has been deprecated, use ManageSellOffer instead.", + DeprecationWarning + ) # pragma: no cover + return ManageSellOffer(*args, **kwargs) + + +def CreatePassiveOffer(*args, **kwargs): + warnings.warn( + "CreatePassiveOffer has been deprecated, use CreatePassiveSellOffer instead.", + DeprecationWarning + ) # pragma: no cover + return CreatePassiveSellOffer(*args, **kwargs) From f6a56eccfe4fe16226adcdc6b6b4d6b2c994d628 Mon Sep 17 00:00:00 2001 From: overcat <4catcode@gmail.com> Date: Sun, 5 May 2019 11:02:50 +0800 Subject: [PATCH 3/4] typo: spelling --- stellar_base/builder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stellar_base/builder.py b/stellar_base/builder.py index 0dff4849..4f2476cd 100644 --- a/stellar_base/builder.py +++ b/stellar_base/builder.py @@ -418,7 +418,7 @@ def append_manage_buy_offer_op(self, price, offer_id=0, source=None): - """Append a :class:`ManageBuyOfferOp ` + """Append a :class:`ManageBuyOffer ` operation to the list of operations. :param str selling_code: The asset code for the asset the offer creator @@ -445,7 +445,7 @@ def append_manage_buy_offer_op(self, """ selling = Asset(selling_code, selling_issuer) buying = Asset(buying_code, buying_issuer) - op = operation.ManageBuyOfferOp(selling, buying, amount, price, offer_id, + op = operation.ManageBuyOffer(selling, buying, amount, price, offer_id, source) return self.append_op(op) From 6bdbaa94957494f9419c781cb03bb4342af62437 Mon Sep 17 00:00:00 2001 From: overcat <4catcode@gmail.com> Date: Sun, 5 May 2019 11:03:29 +0800 Subject: [PATCH 4/4] test: Adapt to Protocol v11 --- tests/test_builder.py | 10 +++--- tests/test_operation.py | 74 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 73 insertions(+), 11 deletions(-) diff --git a/tests/test_builder.py b/tests/test_builder.py index 0e1c6949..054e879b 100644 --- a/tests/test_builder.py +++ b/tests/test_builder.py @@ -70,9 +70,11 @@ def test_builder_append_ops(self): append_pre_auth_tx_signer( pre_auth_tx=b"\x95\xe5\xbb\x95\x15\xd9\x9f\x82\x9d\xf9\x93\xc3'\x8e\xeb\xf1\nj!\xda\xa4\xa1\xe4\xf2<6cG}\x17\x97\xfe", signer_weight=1). \ - append_manage_offer_op(selling_code='XLM', selling_issuer=None, buying_code='BEER', + append_manage_sell_offer_op(selling_code='XLM', selling_issuer=None, buying_code='BEER', buying_issuer=bob_account, amount='1', price='10', offer_id=0). \ - append_create_passive_offer_op(selling_code='XLM', selling_issuer=None, buying_code='BEER', + append_manage_buy_offer_op(selling_code='XLM', selling_issuer=None, buying_code='BEER', + buying_issuer=bob_account, amount='1', price='10', offer_id=0). \ + append_create_passive_sell_offer_op(selling_code='XLM', selling_issuer=None, buying_code='BEER', buying_issuer=bob_account, amount='1', price={'n': 10, 'd': 1}). \ append_account_merge_op(destination=bob_account). \ append_inflation_op(). \ @@ -80,9 +82,9 @@ def test_builder_append_ops(self): append_bump_sequence_op(bump_to=938635037769749). \ add_text_memo("hello, stellar"). \ add_time_bounds({'minTime': 1534392138, 'maxTime': 1534392238}) - assert builder.hash_hex() == '82910e59edebeeafc86294372572812a251066ad1f0784e1e38ca63d3b6bdf24' + assert builder.hash_hex() == 'f646a891ed9ecde6f98bf7fb1afcb52acbc73aabd08f9390c61fdfc8f426815f' builder.sign() - assert builder.gen_xdr().decode() == 'AAAAAP4sA2cn9oggk4cfzPLqZVfpSEhmindW2FQofl5b0SjDAAAFeAADVa8AAAABAAAAAQAAAABbdPdKAAAAAFt0964AAAABAAAADmhlbGxvLCBzdGVsbGFyAAAAAAAOAAAAAAAAAAAAAAAAc9qkfqsgyI5MELIC62rtUGCe6YQwteIOIjIeAolrCt4AAAAABfXhAAAAAAAAAAAGAAAAAUJFRVIAAAAAc9qkfqsgyI5MELIC62rtUGCe6YQwteIOIjIeAolrCt4AAAACVAvkAAAAAAAAAAABAAAAAHPapH6rIMiOTBCyAutq7VBgnumEMLXiDiIyHgKJawreAAAAAAAAAAA7msoAAAAAAAAAAAIAAAABQkVFUgAAAABz2qR+qyDIjkwQsgLrau1QYJ7phDC14g4iMh4CiWsK3gAAAAA7msoAAAAAAHPapH6rIMiOTBCyAutq7VBgnumEMLXiDiIyHgKJawreAAAAAAAAAAA7msoAAAAAAQAAAAJIRUxMTwAAAAAAAAAAAAAAc9qkfqsgyI5MELIC62rtUGCe6YQwteIOIjIeAolrCt4AAAAAAAAABwAAAABz2qR+qyDIjkwQsgLrau1QYJ7phDC14g4iMh4CiWsK3gAAAAFNT0UAAAAAAQAAAAAAAAAFAAAAAAAAAAAAAAABAAAABwAAAAAAAAAAAAAAAAAAAAAAAAABAAAAC3N0ZWxsYXIub3JnAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAALn1DBqOj5wSKARkChxiKBJVvapyTAVSCbrzQMJkx8nOAAAAAEAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAGV5buVFdmfgp35k8MnjuvxCmoh2qSh5PI8NmNHfReX/gAAAAEAAAAAAAAAAwAAAAAAAAABQkVFUgAAAABz2qR+qyDIjkwQsgLrau1QYJ7phDC14g4iMh4CiWsK3gAAAAAAmJaAAAAACgAAAAEAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAFCRUVSAAAAAHPapH6rIMiOTBCyAutq7VBgnumEMLXiDiIyHgKJawreAAAAAACYloAAAAAKAAAAAQAAAAAAAAAIAAAAAHPapH6rIMiOTBCyAutq7VBgnumEMLXiDiIyHgKJawreAAAAAAAAAAkAAAAAAAAACgAAAAVoZWxsbwAAAAAAAAEAAAAFd29ybGQAAAAAAAAAAAAACwADVa8AAAAVAAAAAAAAAAFb0SjDAAAAQOeOIQNAwscAcVIdCHVou6xILLKBJTqxqmXiOxxtD4pYVsl0G2tLoDrMfcoWkSb7eyj3c68SIWNZRZEvWyusNwM=' + assert builder.gen_xdr().decode() == 'AAAAAP4sA2cn9oggk4cfzPLqZVfpSEhmindW2FQofl5b0SjDAAAF3AADVa8AAAABAAAAAQAAAABbdPdKAAAAAFt0964AAAABAAAADmhlbGxvLCBzdGVsbGFyAAAAAAAPAAAAAAAAAAAAAAAAc9qkfqsgyI5MELIC62rtUGCe6YQwteIOIjIeAolrCt4AAAAABfXhAAAAAAAAAAAGAAAAAUJFRVIAAAAAc9qkfqsgyI5MELIC62rtUGCe6YQwteIOIjIeAolrCt4AAAACVAvkAAAAAAAAAAABAAAAAHPapH6rIMiOTBCyAutq7VBgnumEMLXiDiIyHgKJawreAAAAAAAAAAA7msoAAAAAAAAAAAIAAAABQkVFUgAAAABz2qR+qyDIjkwQsgLrau1QYJ7phDC14g4iMh4CiWsK3gAAAAA7msoAAAAAAHPapH6rIMiOTBCyAutq7VBgnumEMLXiDiIyHgKJawreAAAAAAAAAAA7msoAAAAAAQAAAAJIRUxMTwAAAAAAAAAAAAAAc9qkfqsgyI5MELIC62rtUGCe6YQwteIOIjIeAolrCt4AAAAAAAAABwAAAABz2qR+qyDIjkwQsgLrau1QYJ7phDC14g4iMh4CiWsK3gAAAAFNT0UAAAAAAQAAAAAAAAAFAAAAAAAAAAAAAAABAAAABwAAAAAAAAAAAAAAAAAAAAAAAAABAAAAC3N0ZWxsYXIub3JnAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAALn1DBqOj5wSKARkChxiKBJVvapyTAVSCbrzQMJkx8nOAAAAAEAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAGV5buVFdmfgp35k8MnjuvxCmoh2qSh5PI8NmNHfReX/gAAAAEAAAAAAAAAAwAAAAAAAAABQkVFUgAAAABz2qR+qyDIjkwQsgLrau1QYJ7phDC14g4iMh4CiWsK3gAAAAAAmJaAAAAACgAAAAEAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAFCRUVSAAAAAHPapH6rIMiOTBCyAutq7VBgnumEMLXiDiIyHgKJawreAAAAAACYloAAAAAKAAAAAQAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAUJFRVIAAAAAc9qkfqsgyI5MELIC62rtUGCe6YQwteIOIjIeAolrCt4AAAAAAJiWgAAAAAoAAAABAAAAAAAAAAgAAAAAc9qkfqsgyI5MELIC62rtUGCe6YQwteIOIjIeAolrCt4AAAAAAAAACQAAAAAAAAAKAAAABWhlbGxvAAAAAAAAAQAAAAV3b3JsZAAAAAAAAAAAAAALAANVrwAAABUAAAAAAAAAAVvRKMMAAABAM1rhFzh2mbT283+lJsqeckCxnO9vC0m8ADTbyUbFXNJNAfSpI23W/kS69wgeq8qp/1knDpkn72b6e6Eac9coCw==' def test_no_stellar_secret_or_address_error_raise(self): with pytest.raises(NoStellarSecretOrAddressError): diff --git a/tests/test_operation.py b/tests/test_operation.py index 48b0b973..59c3f6ce 100644 --- a/tests/test_operation.py +++ b/tests/test_operation.py @@ -96,7 +96,25 @@ def _load_operations(): asset_code='pocketknives', authorize=True, )), - ("manage_offer_min", + ("manage_sell_offer_min", + ManageSellOffer( + selling=Asset('beer', SOURCE), + buying=Asset('beer', DEST), + amount="100", + price=3.14159, + offer_id=1, + source=SOURCE + )), + ("manage_buy_offer_min", + ManageBuyOffer( + selling=Asset('beer', SOURCE), + buying=Asset('beer', DEST), + amount="100", + price=3.14159, + offer_id=1, + source=SOURCE + )), + ("manage_deprecated_offer_min", ManageOffer( selling=Asset('beer', SOURCE), buying=Asset('beer', DEST), @@ -105,7 +123,29 @@ def _load_operations(): offer_id=1, source=SOURCE )), - ("manage_offer_dict_price", + ("manage_sell_offer_dict_price", + ManageSellOffer( + selling=Asset('beer', SOURCE), + buying=Asset('beer', DEST), + amount="100", + price={ + 'n': 314159, + 'd': 100000 + }, + offer_id=1, + )), + ("manage_buy_offer_dict_price", + ManageSellOffer( + selling=Asset('beer', SOURCE), + buying=Asset('beer', DEST), + amount="100", + price={ + 'n': 314159, + 'd': 100000 + }, + offer_id=1, + )), + ("manage_deprecated_offer_dict_price", ManageOffer( selling=Asset('beer', SOURCE), buying=Asset('beer', DEST), @@ -116,7 +156,15 @@ def _load_operations(): }, offer_id=1, )), - ("create_passive_offer_min", + ("create_passive_sell_offer_min", + CreatePassiveSellOffer( + selling=Asset('beer', SOURCE), + buying=Asset('beer', DEST), + amount="100", + price=3.14159, + source=SOURCE + )), + ("create_passive_deprecated_offer_min", CreatePassiveOffer( selling=Asset('beer', SOURCE), buying=Asset('beer', DEST), @@ -124,7 +172,17 @@ def _load_operations(): price=3.14159, source=SOURCE )), - ("create_passive_dict_offer", + ("create_passive_sell_offer_dict", + CreatePassiveSellOffer( + selling=Asset('beer', SOURCE), + buying=Asset('beer', DEST), + amount="100", + price={ + 'n': 314159, + 'd': 100000 + } + )), + ("create_passive_deprecated_offer_dict", CreatePassiveOffer( selling=Asset('beer', SOURCE), buying=Asset('beer', DEST), @@ -179,7 +237,9 @@ def test_operation(name, operation): original.pop("body") restored = dict(operation_restored.__dict__) restored.pop("body") - if name == 'manage_offer_dict_price' or name == 'create_passive_dict_offer': + if name == 'manage_sell_offer_dict_price' or name == 'manage_buy_offer_dict_price' \ + or name == 'create_passive_sell_offer_dict' or name == 'create_passive_deprecated_offer_dict' \ + or name == 'manage_deprecated_offer_dict_price': original['price'] = float(original['price']['n']) / float( original['price']['d']) if name == 'manage_data': # return `bytes` now @@ -201,10 +261,10 @@ def test_manage_data_too_long_raises(): data_value='1234567890' * 7) -def test_manage_offer_dict_price_raises(): +def test_manage_sell_offer_dict_price_raises(): msg = "You need pass `price` params as `str` or `{'n': numerator, 'd': denominator}`" with pytest.raises(NotValidParamError, match=msg): - ManageOffer( + ManageSellOffer( selling=Asset('beer', SOURCE), buying=Asset('beer', DEST), amount="100",