From 23eca7e24d1d084a92e9fcfd9a4bad9b03999fa8 Mon Sep 17 00:00:00 2001 From: overcat <4catcode@gmail.com> Date: Sat, 23 May 2020 15:32:21 +0800 Subject: [PATCH 1/8] refactor: Reverted support for SEP-0023. --- docs/en/api.rst | 6 - docs/zh_CN/api.rst | 6 - examples/payment_muxed_account.py | 30 -- stellar_sdk/__init__.py | 2 - stellar_sdk/account.py | 15 +- stellar_sdk/fee_bump_transaction.py | 15 +- stellar_sdk/muxed_account.py | 112 -------- stellar_sdk/operation/account_merge.py | 20 +- stellar_sdk/operation/allow_trust.py | 3 +- stellar_sdk/operation/bump_sequence.py | 5 +- stellar_sdk/operation/change_trust.py | 3 +- stellar_sdk/operation/create_account.py | 3 +- .../operation/create_passive_sell_offer.py | 3 +- stellar_sdk/operation/inflation.py | 5 +- stellar_sdk/operation/manage_buy_offer.py | 3 +- stellar_sdk/operation/manage_data.py | 3 +- stellar_sdk/operation/manage_sell_offer.py | 3 +- stellar_sdk/operation/operation.py | 20 +- stellar_sdk/operation/path_payment.py | 5 +- .../operation/path_payment_strict_receive.py | 18 +- .../operation/path_payment_strict_send.py | 18 +- stellar_sdk/operation/payment.py | 18 +- stellar_sdk/operation/set_options.py | 3 +- stellar_sdk/operation/utils.py | 17 +- stellar_sdk/sep/stellar_web_authentication.py | 4 +- stellar_sdk/server.py | 20 +- stellar_sdk/strkey.py | 64 +---- stellar_sdk/transaction.py | 21 +- stellar_sdk/transaction_builder.py | 49 ++-- tests/sep/test_stellar_web_authentication.py | 50 +--- tests/test_account.py | 3 +- tests/test_muxed_account.py | 72 ----- tests/test_operation.py | 263 +----------------- tests/test_server.py | 53 +--- tests/test_strkey.py | 72 +---- tests/test_transaction.py | 58 +--- 36 files changed, 150 insertions(+), 915 deletions(-) delete mode 100644 examples/payment_muxed_account.py delete mode 100644 stellar_sdk/muxed_account.py delete mode 100644 tests/test_muxed_account.py diff --git a/docs/en/api.rst b/docs/en/api.rst index e4b82340..49967cfc 100644 --- a/docs/en/api.rst +++ b/docs/en/api.rst @@ -326,12 +326,6 @@ ReturnHashMemo .. autoclass:: stellar_sdk.memo.ReturnHashMemo :members: -MuxedAccount -^^^^^^^^^^^^ - -.. autoclass:: stellar_sdk.muxed_account.MuxedAccount - :members: - Network ^^^^^^^ diff --git a/docs/zh_CN/api.rst b/docs/zh_CN/api.rst index 5215c73e..b7b27210 100644 --- a/docs/zh_CN/api.rst +++ b/docs/zh_CN/api.rst @@ -326,12 +326,6 @@ ReturnHashMemo .. autoclass:: stellar_sdk.memo.ReturnHashMemo :members: -MuxedAccount -^^^^^^^^^^^^ - -.. autoclass:: stellar_sdk.muxed_account.MuxedAccount - :members: - Network ^^^^^^^ diff --git a/examples/payment_muxed_account.py b/examples/payment_muxed_account.py deleted file mode 100644 index 84c14139..00000000 --- a/examples/payment_muxed_account.py +++ /dev/null @@ -1,30 +0,0 @@ -import pprint - -from stellar_sdk import Keypair, Server, MuxedAccount, TransactionBuilder, Network - -horizon_url = "https://horizon-testnet.stellar.org/" -network_passphrase = Network.TESTNET_NETWORK_PASSPHRASE - -alice_secret = "SC5O7VZUXDJ6JBDSZ74DSERXL7W3Y5LTOAMRF7RQRL3TAGAPS7LUVG3L" -bob_account = MuxedAccount( - account_id="GBVKI23OQZCANDUZ2SI7XU7W6ICYKYT74JBXDD2CYRDAFZHZNRPASSQK", - account_id_id=12387, -) -print(f"account_id_muxed: {bob_account.account_id_muxed}") - -alice_keypair = Keypair.from_secret(alice_secret) - -server = Server(horizon_url=horizon_url) -alice_account = server.load_account(alice_keypair.public_key) -transaction = TransactionBuilder( - source_account=alice_account, - network_passphrase=network_passphrase, - base_fee=100, - v1=True, # If you want to build Protocol 13 transactions, you need to set `v1` to `True` -) \ - .append_payment_op(destination=bob_account, amount="100", asset_code="XLM") \ - .build() - -transaction.sign(alice_keypair) -resp = server.submit_transaction(transaction) -pprint.pprint(resp) diff --git a/stellar_sdk/__init__.py b/stellar_sdk/__init__.py index b7f71bed..d3f64f3a 100644 --- a/stellar_sdk/__init__.py +++ b/stellar_sdk/__init__.py @@ -17,7 +17,6 @@ from .fee_bump_transaction_envelope import FeeBumpTransactionEnvelope from .keypair import Keypair from .memo import Memo, NoneMemo, TextMemo, IdMemo, HashMemo, ReturnHashMemo -from .muxed_account import MuxedAccount from .network import Network from .price import Price from .server import Server @@ -50,7 +49,6 @@ "IdMemo", "HashMemo", "ReturnHashMemo", - "MuxedAccount", "Network", "Price", "Server", diff --git a/stellar_sdk/account.py b/stellar_sdk/account.py index cbfc26bf..686886cc 100644 --- a/stellar_sdk/account.py +++ b/stellar_sdk/account.py @@ -1,6 +1,5 @@ -from typing import Optional, List, Union +from typing import Optional, List -from .muxed_account import MuxedAccount from .sep.ed25519_public_key_signer import Ed25519PublicKeySigner from .strkey import StrKey @@ -17,9 +16,8 @@ class Account: See `Accounts`_ For more information about the formats used for asset codes and how issuers work on Stellar's network, - :param account_id: MuxedAccount or Account ID of the + :param account_id: Account ID of the account (ex. `GB3KJPLFUYN5VL6R3GU3EGCGVCKFDSD7BEDX42HWG5BWFKB3KQGJJRMA`) - or muxed account (ex. `MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY`) :param sequence: sequence current sequence number of the account :raises: :exc:`Ed25519PublicKeyInvalidError `: if ``account_id`` @@ -29,11 +27,10 @@ class Account: https://stellar.org/developers/learn/concepts/accounts.html """ - def __init__(self, account_id: Union[str, MuxedAccount], sequence: int) -> None: - if isinstance(account_id, str): - account_id = MuxedAccount.from_account(account_id) - self.account_id: MuxedAccount = account_id - self.sequence: int = sequence + def __init__(self, account_id: str, sequence: int) -> None: + StrKey.decode_ed25519_public_key(account_id) + self.account_id: str = account_id + self.sequence = sequence # The following properties will change in 3.0 self.signers: Optional[dict] = None diff --git a/stellar_sdk/fee_bump_transaction.py b/stellar_sdk/fee_bump_transaction.py index 7e2662fe..e79db376 100644 --- a/stellar_sdk/fee_bump_transaction.py +++ b/stellar_sdk/fee_bump_transaction.py @@ -6,7 +6,6 @@ from .transaction import Transaction from .transaction_envelope import TransactionEnvelope from .xdr import Xdr -from .muxed_account import MuxedAccount BASE_FEE = 100 @@ -26,7 +25,7 @@ class FeeBumpTransaction: def __init__( self, - fee_source: Union[Keypair, MuxedAccount, str], + fee_source: Union[Keypair, str], base_fee: int, inner_transaction_envelope: TransactionEnvelope, ) -> None: @@ -37,11 +36,9 @@ def __init__( raise ValueError("Invalid `inner_transaction`, it should be TransactionV1.") if isinstance(fee_source, str): - fee_source = MuxedAccount.from_account(fee_source) - if isinstance(fee_source, Keypair): - fee_source = MuxedAccount.from_account(fee_source.public_key) + fee_source = Keypair.from_public_key(fee_source) - self.fee_source: MuxedAccount = fee_source + self.fee_source: Keypair = fee_source self.base_fee = base_fee self.inner_transaction_envelope = inner_transaction_envelope self._inner_transaction = inner_transaction_envelope.transaction @@ -63,7 +60,7 @@ def to_xdr_object(self) -> Xdr.types.FeeBumpTransaction: :return: XDR Transaction object """ - fee_source = self.fee_source.to_xdr_object() + fee_source = self.fee_source.xdr_muxed_account() fee = self.base_fee * (len(self._inner_transaction.operations) + 1) ext = Xdr.nullclass() ext.v = 0 @@ -85,7 +82,9 @@ def from_xdr_object( :return: A new :class:`FeeBumpTransaction` object from the given XDR Transaction object. """ - source = MuxedAccount.from_xdr_object(tx_xdr_object.feeSource) + source = StrKey.encode_ed25519_public_key( + tx_xdr_object.feeSource.ed25519 + ) inner_transaction_envelope = TransactionEnvelope.from_xdr_object( tx_xdr_object.innerTx, network_passphrase ) diff --git a/stellar_sdk/muxed_account.py b/stellar_sdk/muxed_account.py deleted file mode 100644 index e7f8eb3f..00000000 --- a/stellar_sdk/muxed_account.py +++ /dev/null @@ -1,112 +0,0 @@ -from typing import Optional - -from .exceptions import ValueError, MuxedEd25519AccountInvalidError -from .strkey import StrKey, encode_check, decode_check -from .utils import check_ed25519_public_key -from .xdr import Xdr - -__all__ = ["MuxedAccount"] - - -class MuxedAccount: - """The :class:`MuxedAccount` object, which represents a multiplexed account on Stellar's network. - - See `SEP-0023 `_ for more - information. - - :param account_id: account id, for example: `GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD` - :param account_id_id: account multiplexing id, for example: `1234` - """ - - def __init__(self, account_id: str, account_id_id: int = None) -> None: - check_ed25519_public_key(account_id) - self.account_id: str = account_id - self.account_id_id: Optional[int] = account_id_id - - @property - def account_id_muxed(self) -> Optional[str]: - """Get the multiplex address starting with `M`, return `None` if `account_id_id` is `None` - """ - if self.account_id_id is None: - return None - packer = Xdr.StellarXDRPacker() - packer.pack_int64(self.account_id_id) - packer.pack_uint256(StrKey.decode_ed25519_public_key(self.account_id)) - data = packer.get_buffer() - return encode_check("muxed_account", data) - - @account_id_muxed.setter - def account_id_muxed(self, value): - raise AttributeError( - "Can't set attribute, use `MuxedAccount.from_account` instead." - ) - - @classmethod - def from_account(cls, account: str) -> "MuxedAccount": - """Create a :class:`MuxedAccount` from account id or muxed account id. - - :param account: account id or muxed account id, - for example: `GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD` or - `MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY` - """ - # There is a little confusion here, we used the new XDR generator in v3, - # let us optimize it in v3. - data_length = len(account) - if data_length == 56: - return cls(account_id=account, account_id_id=None) - elif data_length == 69: - try: - xdr = decode_check("muxed_account", account) - except Exception: - raise MuxedEd25519AccountInvalidError( - "Invalid Muxed Account: {}".format(account) - ) - unpacker = Xdr.StellarXDRUnpacker(xdr) - account_id_id = unpacker.unpack_int64() - ed25519 = unpacker.unpack_uint256() - account_id = StrKey.encode_ed25519_public_key(ed25519) - return cls(account_id=account_id, account_id_id=account_id_id) - else: - raise ValueError("This is not a valid account.") - - def to_xdr_object(self) -> Xdr.types.MuxedAccount: - """Returns the xdr object for this MuxedAccount object. - - :return: XDR MuxedAccount object - """ - if self.account_id_id is None: - return StrKey.decode_muxed_account(self.account_id) - return StrKey.decode_muxed_account(self.account_id_muxed) - - @classmethod - def from_xdr_object( - cls, muxed_account_xdr_object: Xdr.types.MuxedAccount - ) -> "MuxedAccount": - """Create a :class:`MuxedAccount` from an XDR Asset object. - - :param muxed_account_xdr_object: The MuxedAccount Price object. - :return: A new :class:`MuxedAccount` object from the given XDR MuxedAccount object. - """ - if muxed_account_xdr_object.type == Xdr.const.KEY_TYPE_ED25519: - account_id = StrKey.encode_ed25519_public_key( - muxed_account_xdr_object.ed25519 - ) - return cls(account_id=account_id, account_id_id=None) - account_id_id = muxed_account_xdr_object.med25519.id - account_id = StrKey.encode_ed25519_public_key( - muxed_account_xdr_object.med25519.ed25519 - ) - return cls(account_id=account_id, account_id_id=account_id_id) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, self.__class__): - return NotImplemented # pragma: no cover - return ( - self.account_id == other.account_id - and self.account_id_id == other.account_id_id - ) - - def __str__(self): - return "".format( - account_id=self.account_id, account_id_id=self.account_id_id - ) diff --git a/stellar_sdk/operation/account_merge.py b/stellar_sdk/operation/account_merge.py index 6c002edf..aec8c003 100644 --- a/stellar_sdk/operation/account_merge.py +++ b/stellar_sdk/operation/account_merge.py @@ -1,8 +1,7 @@ -from typing import Union - from .operation import Operation -from .utils import parse_mux_account_from_account -from ..muxed_account import MuxedAccount +from .utils import check_ed25519_public_key +from ..keypair import Keypair +from ..strkey import StrKey from ..xdr import Xdr @@ -22,11 +21,12 @@ class AccountMerge(Operation): def __init__( self, - destination: Union[MuxedAccount, str], - source: Union[MuxedAccount, str] = None, + destination: str, + source: str = None, ) -> None: super().__init__(source) - self.destination: MuxedAccount = parse_mux_account_from_account(destination) + check_ed25519_public_key(destination) + self.destination: str = destination @classmethod def type_code(cls) -> int: @@ -35,7 +35,7 @@ def type_code(cls) -> int: def _to_operation_body(self) -> Xdr.nullclass: body = Xdr.nullclass() body.type = Xdr.const.ACCOUNT_MERGE - body.destination = self.destination.to_xdr_object() + body.destination = Keypair.from_public_key(self.destination).xdr_muxed_account() return body @classmethod @@ -47,7 +47,7 @@ def from_xdr_object( """ source = Operation.get_source_from_xdr_obj(operation_xdr_object) - destination = MuxedAccount.from_xdr_object( - operation_xdr_object.body.destination + destination = StrKey.encode_ed25519_public_key( + operation_xdr_object.body.destination.ed25519 ) return cls(source=source, destination=destination) diff --git a/stellar_sdk/operation/allow_trust.py b/stellar_sdk/operation/allow_trust.py index 617bd831..1f137747 100644 --- a/stellar_sdk/operation/allow_trust.py +++ b/stellar_sdk/operation/allow_trust.py @@ -5,7 +5,6 @@ from .utils import check_ed25519_public_key, check_asset_code from ..asset import Asset from ..keypair import Keypair -from ..muxed_account import MuxedAccount from ..strkey import StrKey from ..xdr import Xdr @@ -53,7 +52,7 @@ def __init__( trustor: str, asset_code: str, authorize: Union[TrustLineEntryFlag, bool], - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> None: super().__init__(source) check_ed25519_public_key(trustor) diff --git a/stellar_sdk/operation/bump_sequence.py b/stellar_sdk/operation/bump_sequence.py index a44b967c..602b4195 100644 --- a/stellar_sdk/operation/bump_sequence.py +++ b/stellar_sdk/operation/bump_sequence.py @@ -1,7 +1,4 @@ -from typing import Union - from .operation import Operation -from ..muxed_account import MuxedAccount from ..xdr import Xdr @@ -21,7 +18,7 @@ class BumpSequence(Operation): """ - def __init__(self, bump_to: int, source: Union[MuxedAccount, str] = None) -> None: + def __init__(self, bump_to: int, source: str = None) -> None: super().__init__(source) self.bump_to: int = bump_to diff --git a/stellar_sdk/operation/change_trust.py b/stellar_sdk/operation/change_trust.py index 4042b28a..7f14b674 100644 --- a/stellar_sdk/operation/change_trust.py +++ b/stellar_sdk/operation/change_trust.py @@ -4,7 +4,6 @@ from .operation import Operation from .utils import check_amount from ..asset import Asset -from ..muxed_account import MuxedAccount from ..xdr import Xdr @@ -31,7 +30,7 @@ def __init__( self, asset: Asset, limit: Union[str, Decimal] = None, - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> None: super().__init__(source) self.asset: Asset = asset diff --git a/stellar_sdk/operation/create_account.py b/stellar_sdk/operation/create_account.py index 977eac24..48339d8d 100644 --- a/stellar_sdk/operation/create_account.py +++ b/stellar_sdk/operation/create_account.py @@ -4,7 +4,6 @@ from .operation import Operation from .utils import check_ed25519_public_key, check_amount from ..keypair import Keypair -from ..muxed_account import MuxedAccount from ..strkey import StrKey from ..xdr import Xdr @@ -31,7 +30,7 @@ def __init__( self, destination: str, starting_balance: Union[str, Decimal], - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> None: super().__init__(source) check_ed25519_public_key(destination) diff --git a/stellar_sdk/operation/create_passive_sell_offer.py b/stellar_sdk/operation/create_passive_sell_offer.py index 90820d92..ec31cdd4 100644 --- a/stellar_sdk/operation/create_passive_sell_offer.py +++ b/stellar_sdk/operation/create_passive_sell_offer.py @@ -4,7 +4,6 @@ from .operation import Operation from .utils import check_amount, check_price from ..asset import Asset -from ..muxed_account import MuxedAccount from ..price import Price from ..xdr import Xdr @@ -47,7 +46,7 @@ def __init__( buying: Asset, amount: Union[str, Decimal], price: Union[Price, str, Decimal], - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> None: super().__init__(source) check_amount(amount) diff --git a/stellar_sdk/operation/inflation.py b/stellar_sdk/operation/inflation.py index bfc5180d..ad51ba94 100644 --- a/stellar_sdk/operation/inflation.py +++ b/stellar_sdk/operation/inflation.py @@ -1,7 +1,4 @@ -from typing import Union - from .operation import Operation -from ..muxed_account import MuxedAccount from ..xdr import Xdr @@ -17,7 +14,7 @@ class Inflation(Operation): """ - def __init__(self, source: Union[MuxedAccount, str] = None) -> None: + def __init__(self, source: str = None) -> None: super().__init__(source) @classmethod diff --git a/stellar_sdk/operation/manage_buy_offer.py b/stellar_sdk/operation/manage_buy_offer.py index 867a713b..81d339d5 100644 --- a/stellar_sdk/operation/manage_buy_offer.py +++ b/stellar_sdk/operation/manage_buy_offer.py @@ -4,7 +4,6 @@ from .operation import Operation from .utils import check_price, check_amount from ..asset import Asset -from ..muxed_account import MuxedAccount from ..price import Price from ..xdr import Xdr @@ -41,7 +40,7 @@ def __init__( amount: Union[str, Decimal], price: Union[Price, str, Decimal], offer_id: int = 0, - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> None: super().__init__(source) check_amount(amount) diff --git a/stellar_sdk/operation/manage_data.py b/stellar_sdk/operation/manage_data.py index cb8b5293..ae4e9de5 100644 --- a/stellar_sdk/operation/manage_data.py +++ b/stellar_sdk/operation/manage_data.py @@ -2,7 +2,6 @@ from .operation import Operation from ..exceptions import ValueError -from ..muxed_account import MuxedAccount from ..utils import pack_xdr_array, unpack_xdr_array from ..xdr import Xdr @@ -31,7 +30,7 @@ def __init__( self, data_name: str, data_value: Union[str, bytes, None], - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> None: # TODO: bytes only? super().__init__(source) self.data_name: str = data_name diff --git a/stellar_sdk/operation/manage_sell_offer.py b/stellar_sdk/operation/manage_sell_offer.py index dc6ab37b..46010fa7 100644 --- a/stellar_sdk/operation/manage_sell_offer.py +++ b/stellar_sdk/operation/manage_sell_offer.py @@ -4,7 +4,6 @@ from .operation import Operation from .utils import check_price, check_amount from ..asset import Asset -from ..muxed_account import MuxedAccount from ..price import Price from ..xdr import Xdr @@ -41,7 +40,7 @@ def __init__( amount: Union[str, Decimal], price: Union[Price, str, Decimal], offer_id: int = 0, - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> None: super().__init__(source) check_price(price) diff --git a/stellar_sdk/operation/operation.py b/stellar_sdk/operation/operation.py index 72305853..e457740d 100644 --- a/stellar_sdk/operation/operation.py +++ b/stellar_sdk/operation/operation.py @@ -3,9 +3,10 @@ from decimal import Decimal, Context, Inexact from typing import Optional, List, Union -from .utils import parse_mux_account_from_account +from .utils import check_source +from ..keypair import Keypair from ..exceptions import ValueError, TypeError -from ..muxed_account import MuxedAccount +from ..strkey import StrKey from ..xdr import Xdr @@ -38,11 +39,10 @@ class Operation(metaclass=ABCMeta): _ONE = Decimal(10 ** 7) - def __init__(self, source: Union[MuxedAccount, str] = None) -> None: - if source is None: - self.source = None - else: - self.source: Optional[MuxedAccount] = parse_mux_account_from_account(source) + def __init__(self, source: str = None) -> None: + check_source(source) + self.source = source + self.source: Optional[str] = source @classmethod def type_code(cls) -> int: @@ -121,7 +121,7 @@ def to_xdr_object(self) -> Xdr.types.Operation: """ source_account: List[Xdr.types.MuxedAccount] = [] if self.source is not None: - source_account = [self.source.to_xdr_object()] + source_account = [Keypair.from_public_key(self.source).xdr_muxed_account()] return Xdr.types.Operation(source_account, self._to_operation_body()) @@ -144,14 +144,14 @@ def from_xdr_object(cls, operation_xdr_object: Xdr.types.Operation) -> "Operatio @staticmethod def get_source_from_xdr_obj( xdr_object: Xdr.types.Operation, - ) -> Optional[MuxedAccount]: + ) -> Optional[str]: """Get the source account from account the operation xdr object. :param xdr_object: the operation xdr object. :return: The source account from account the operation xdr object. """ if xdr_object.sourceAccount: - return MuxedAccount.from_xdr_object(xdr_object.sourceAccount[0]) + return StrKey.encode_ed25519_public_key(xdr_object.sourceAccount[0].ed25519) return None def __eq__(self, other: object) -> bool: diff --git a/stellar_sdk/operation/path_payment.py b/stellar_sdk/operation/path_payment.py index 590ca96c..a37aab4c 100644 --- a/stellar_sdk/operation/path_payment.py +++ b/stellar_sdk/operation/path_payment.py @@ -4,7 +4,6 @@ from .path_payment_strict_receive import PathPaymentStrictReceive from ..asset import Asset -from ..muxed_account import MuxedAccount class PathPayment(PathPaymentStrictReceive): @@ -29,13 +28,13 @@ class PathPayment(PathPaymentStrictReceive): def __init__( self, - destination: Union[MuxedAccount, str], + destination: str, send_asset: Asset, send_max: Union[str, Decimal], dest_asset: Asset, dest_amount: Union[str, Decimal], path: List[Asset], - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> None: warnings.warn( "Will be removed in version v3.0.0, " diff --git a/stellar_sdk/operation/path_payment_strict_receive.py b/stellar_sdk/operation/path_payment_strict_receive.py index b4690df8..36e88a20 100644 --- a/stellar_sdk/operation/path_payment_strict_receive.py +++ b/stellar_sdk/operation/path_payment_strict_receive.py @@ -2,9 +2,10 @@ from typing import List, Union from .operation import Operation -from .utils import check_amount, parse_mux_account_from_account +from .utils import check_amount, check_ed25519_public_key from ..asset import Asset -from ..muxed_account import MuxedAccount +from ..keypair import Keypair +from ..strkey import StrKey from ..xdr import Xdr @@ -30,18 +31,19 @@ class PathPaymentStrictReceive(Operation): def __init__( self, - destination: Union[MuxedAccount, str], + destination: str, send_asset: Asset, send_max: Union[str, Decimal], dest_asset: Asset, dest_amount: Union[str, Decimal], path: List[Asset], - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> None: super().__init__(source) check_amount(send_max) check_amount(dest_amount) - self.destination: MuxedAccount = parse_mux_account_from_account(destination) + check_ed25519_public_key(destination) + self.destination: str = destination self.send_asset: Asset = send_asset self.send_max: Union[str, Decimal] = send_max self.dest_asset: Asset = dest_asset @@ -53,7 +55,7 @@ def type_code(cls) -> int: return Xdr.const.PATH_PAYMENT_STRICT_RECEIVE def _to_operation_body(self) -> Xdr.nullclass: - destination = self.destination.to_xdr_object() + destination = Keypair.from_public_key(self.destination).xdr_muxed_account() send_asset = self.send_asset.to_xdr_object() dest_asset = self.dest_asset.to_xdr_object() path = [asset.to_xdr_object() for asset in self.path] @@ -80,8 +82,8 @@ def from_xdr_object( """ source = Operation.get_source_from_xdr_obj(operation_xdr_object) - destination = MuxedAccount.from_xdr_object( - operation_xdr_object.body.pathPaymentStrictReceiveOp.destination + destination = StrKey.encode_ed25519_public_key( + operation_xdr_object.body.pathPaymentStrictReceiveOp.destination.ed25519 ) send_asset = Asset.from_xdr_object( operation_xdr_object.body.pathPaymentStrictReceiveOp.sendAsset diff --git a/stellar_sdk/operation/path_payment_strict_send.py b/stellar_sdk/operation/path_payment_strict_send.py index cf8b4d41..bff17bae 100644 --- a/stellar_sdk/operation/path_payment_strict_send.py +++ b/stellar_sdk/operation/path_payment_strict_send.py @@ -2,9 +2,10 @@ from typing import List, Union from .operation import Operation -from .utils import check_amount, parse_mux_account_from_account +from .utils import check_amount, check_ed25519_public_key from ..asset import Asset -from ..muxed_account import MuxedAccount +from ..keypair import Keypair +from ..strkey import StrKey from ..xdr import Xdr @@ -30,18 +31,19 @@ class PathPaymentStrictSend(Operation): def __init__( self, - destination: Union[MuxedAccount, str], + destination: str, send_asset: Asset, send_amount: Union[str, Decimal], dest_asset: Asset, dest_min: Union[str, Decimal], path: List[Asset], - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> None: super().__init__(source) check_amount(send_amount) check_amount(dest_min) - self.destination: MuxedAccount = parse_mux_account_from_account(destination) + check_ed25519_public_key(destination) + self.destination: str = destination self.send_asset: Asset = send_asset self.send_amount: Union[str, Decimal] = send_amount self.dest_asset: Asset = dest_asset @@ -53,7 +55,7 @@ def type_code(cls) -> int: return Xdr.const.PATH_PAYMENT_STRICT_SEND def _to_operation_body(self) -> Xdr.nullclass: - destination = self.destination.to_xdr_object() + destination = Keypair.from_public_key(self.destination).xdr_muxed_account() send_asset = self.send_asset.to_xdr_object() dest_asset = self.dest_asset.to_xdr_object() path = [asset.to_xdr_object() for asset in self.path] @@ -80,8 +82,8 @@ def from_xdr_object( """ source = Operation.get_source_from_xdr_obj(operation_xdr_object) - destination = MuxedAccount.from_xdr_object( - operation_xdr_object.body.pathPaymentStrictSendOp.destination + destination = StrKey.encode_ed25519_public_key( + operation_xdr_object.body.pathPaymentStrictSendOp.destination.ed25519 ) send_asset = Asset.from_xdr_object( operation_xdr_object.body.pathPaymentStrictSendOp.sendAsset diff --git a/stellar_sdk/operation/payment.py b/stellar_sdk/operation/payment.py index 011a96ed..d6817e1e 100644 --- a/stellar_sdk/operation/payment.py +++ b/stellar_sdk/operation/payment.py @@ -2,9 +2,10 @@ from typing import Union from .operation import Operation -from .utils import check_amount, parse_mux_account_from_account +from .utils import check_amount, check_ed25519_public_key +from ..keypair import Keypair from ..asset import Asset -from ..muxed_account import MuxedAccount +from ..strkey import StrKey from ..xdr import Xdr @@ -26,14 +27,15 @@ class Payment(Operation): def __init__( self, - destination: Union[MuxedAccount, str], + destination: str, asset: Asset, amount: Union[str, Decimal], - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> None: super().__init__(source) check_amount(amount) - self.destination: MuxedAccount = parse_mux_account_from_account(destination) + check_ed25519_public_key(destination) + self.destination: str = destination self.asset: Asset = asset self.amount: Union[str, Decimal] = amount @@ -43,7 +45,7 @@ def type_code(cls) -> int: def _to_operation_body(self) -> Xdr.nullclass: asset = self.asset.to_xdr_object() - destination = self.destination.to_xdr_object() + destination = Keypair.from_public_key(self.destination).xdr_muxed_account() amount = Operation.to_xdr_amount(self.amount) payment_op = Xdr.types.PaymentOp(destination, asset, amount) body = Xdr.nullclass() @@ -59,8 +61,8 @@ def from_xdr_object(cls, operation_xdr_object: Xdr.types.Operation) -> "Payment" """ source = Operation.get_source_from_xdr_obj(operation_xdr_object) - destination = MuxedAccount.from_xdr_object( - operation_xdr_object.body.paymentOp.destination + destination = StrKey.encode_ed25519_public_key( + operation_xdr_object.body.paymentOp.destination.ed25519 ) asset = Asset.from_xdr_object(operation_xdr_object.body.paymentOp.asset) amount = Operation.from_xdr_amount(operation_xdr_object.body.paymentOp.amount) diff --git a/stellar_sdk/operation/set_options.py b/stellar_sdk/operation/set_options.py index 79ea1ace..6935a16e 100644 --- a/stellar_sdk/operation/set_options.py +++ b/stellar_sdk/operation/set_options.py @@ -4,7 +4,6 @@ from .operation import Operation from .utils import check_ed25519_public_key from ..keypair import Keypair -from ..muxed_account import MuxedAccount from ..signer import Signer from ..strkey import StrKey from ..utils import pack_xdr_array, unpack_xdr_array @@ -81,7 +80,7 @@ def __init__( high_threshold: int = None, signer: Signer = None, home_domain: str = None, - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> None: super().__init__(source) if inflation_dest is not None: diff --git a/stellar_sdk/operation/utils.py b/stellar_sdk/operation/utils.py index f73bd166..91b8ffbd 100644 --- a/stellar_sdk/operation/utils.py +++ b/stellar_sdk/operation/utils.py @@ -4,9 +4,7 @@ from ..asset import Asset from ..exceptions import ValueError, TypeError from ..keypair import Keypair -from ..muxed_account import MuxedAccount from ..price import Price -from ..strkey import StrKey _LOWER_LIMIT = "0" _UPPER_LIMIT = "922337203685.4775807" @@ -15,17 +13,12 @@ def check_source(source: Optional[str]) -> None: if source is not None: - check_muxed_ed25519_account(source) + check_ed25519_public_key(source) def check_ed25519_public_key(public_key: str) -> None: Keypair.from_public_key(public_key) - -def check_muxed_ed25519_account(muxed_account: str) -> None: - StrKey.decode_muxed_account(muxed_account) - - def check_asset_code(asset_code: str) -> None: Asset.check_if_asset_code_is_valid(asset_code) @@ -54,10 +47,4 @@ def check_amount(amount: Union[str, Decimal]) -> None: raise ValueError( "Value of '{}' must represent a positive number " "and the max valid value is {}.".format(amount, _UPPER_LIMIT) - ) - - -def parse_mux_account_from_account(account: Union[str, MuxedAccount]) -> MuxedAccount: - if isinstance(account, str): - return MuxedAccount.from_account(account) - return account + ) \ No newline at end of file diff --git a/stellar_sdk/sep/stellar_web_authentication.py b/stellar_sdk/sep/stellar_web_authentication.py index ffe0e569..2cda9dfa 100644 --- a/stellar_sdk/sep/stellar_web_authentication.py +++ b/stellar_sdk/sep/stellar_web_authentication.py @@ -120,7 +120,7 @@ def read_challenge_transaction( transaction = transaction_envelope.transaction # verify that transaction source account is equal to the server's signing key - if transaction.source.account_id != server_account_id: + if transaction.source.public_key != server_account_id: raise InvalidSep10ChallengeError( "Transaction source account is not equal to server's account." ) @@ -181,7 +181,7 @@ def read_challenge_transaction( ) # TODO: I don't think this is a good idea. - return transaction_envelope, client_account.account_id + return transaction_envelope, client_account def verify_challenge_transaction_signers( diff --git a/stellar_sdk/server.py b/stellar_sdk/server.py index 78d214db..89422fcb 100644 --- a/stellar_sdk/server.py +++ b/stellar_sdk/server.py @@ -1,9 +1,9 @@ import warnings from typing import Union, Coroutine, Any, Dict, List, Tuple, Generator -from stellar_sdk.base_transaction_envelope import BaseTransactionEnvelope from .account import Account, Thresholds from .asset import Asset +from .base_transaction_envelope import BaseTransactionEnvelope from .call_builder.accounts_call_builder import AccountsCallBuilder from .call_builder.assets_call_builder import AssetsCallBuilder from .call_builder.data_call_builder import DataCallBuilder @@ -32,7 +32,6 @@ from .helpers import parse_transaction_envelope_from_xdr from .keypair import Keypair from .memo import NoneMemo -from .muxed_account import MuxedAccount from .sep.exceptions import AccountRequiresMemoError from .transaction import Transaction from .transaction_envelope import TransactionEnvelope @@ -370,7 +369,7 @@ def transactions(self) -> TransactionsCallBuilder: ) def load_account( - self, account_id: Union[MuxedAccount, Keypair, str] + self, account_id: Union[Keypair, str] ) -> Union[Account, Coroutine[Any, Any, Account]]: """Fetches an account's most current state in the ledger and then creates and returns an :class:`stellar_sdk.account.Account` object. @@ -384,18 +383,17 @@ def load_account( :exc:`BadResponseError ` :exc:`UnknownRequestError ` """ - if isinstance(account_id, str): - account = MuxedAccount.from_account(account_id) - elif isinstance(account_id, Keypair): - account = MuxedAccount.from_account(account_id.public_key) + + if isinstance(account_id, Keypair): + account = account_id.public_key else: account = account_id if self.__async: return self.__load_account_async(account) return self.__load_account_sync(account) - async def __load_account_async(self, account_id: MuxedAccount) -> Account: - resp = await self.accounts().account_id(account_id=account_id.account_id).call() + async def __load_account_async(self, account_id: str) -> Account: + resp = await self.accounts().account_id(account_id=account_id).call() sequence = int(resp["sequence"]) thresholds = Thresholds( resp["thresholds"]["low_threshold"], @@ -407,8 +405,8 @@ async def __load_account_async(self, account_id: MuxedAccount) -> Account: account.thresholds = thresholds return account - def __load_account_sync(self, account_id: MuxedAccount) -> Account: - resp = self.accounts().account_id(account_id=account_id.account_id).call() + def __load_account_sync(self, account_id: str) -> Account: + resp = self.accounts().account_id(account_id=account_id).call() sequence = int(resp["sequence"]) thresholds = Thresholds( resp["thresholds"]["low_threshold"], diff --git a/stellar_sdk/strkey.py b/stellar_sdk/strkey.py index 5aae63b3..b68afb28 100644 --- a/stellar_sdk/strkey.py +++ b/stellar_sdk/strkey.py @@ -8,11 +8,9 @@ from .exceptions import ( Ed25519SecretSeedInvalidError, Ed25519PublicKeyInvalidError, - MuxedEd25519AccountInvalidError, ValueError, TypeError, ) -from .xdr import Xdr __all__ = ["StrKey"] @@ -21,14 +19,9 @@ "ed25519_secret_seed": binascii.a2b_hex("90"), # S 144 18 << 3 "pre_auth_tx": binascii.a2b_hex("98"), # T 152 19 << 3 "sha256_hash": binascii.a2b_hex("b8"), # X 184 23 << 3 - "muxed_account": binascii.a2b_hex("60"), # M 96 12 << 3 } -# https://github.com/stellar/js-stellar-base/pull/330/files -# https://github.com/stellar/js-stellar-base/pull/327/files - - class StrKey: """StrKey is a helper class that allows encoding and decoding strkey. @@ -159,59 +152,6 @@ def decode_sha256_hash(data: str) -> bytes: """ return decode_check("sha256_hash", data) - @staticmethod - def encode_muxed_account(data: Xdr.types.MuxedAccount) -> str: - """Encodes data to strkey muxed account. - - :param data: data to encode - :return: strkey muxed account - :raises: - :exc:`ValueError ` - :exc:`TypeError ` - """ - if data.type == Xdr.const.KEY_TYPE_ED25519: - return StrKey.encode_ed25519_public_key(data.ed25519) - packer = Xdr.StellarXDRPacker() - packer.pack_int64(data.med25519.id) - packer.pack_uint256(data.med25519.ed25519) - data = packer.get_buffer() - return encode_check("muxed_account", data) - - @staticmethod - def decode_muxed_account(data: str) -> Xdr.types.MuxedAccount: - """Decodes strkey muxed account to raw data. - - :param data: strkey muxed account - :return: raw bytes - :raises: - :exc:`ValueError ` - :exc:`TypeError ` - """ - data_length = len(data) - if data_length == 56: - muxed = Xdr.types.MuxedAccount( - type=Xdr.const.KEY_TYPE_ED25519, - ed25519=StrKey.decode_ed25519_public_key(data), - ) - elif data_length == 69: - # let's optimize it in v3. - try: - xdr = decode_check("muxed_account", data) - except Exception: - raise MuxedEd25519AccountInvalidError( - "Invalid Muxed Account: {}".format(data) - ) - unpacker = Xdr.StellarXDRUnpacker(xdr) - med25519 = Xdr.nullclass() - med25519.id = unpacker.unpack_int64() - med25519.ed25519 = unpacker.unpack_uint256() - muxed = Xdr.types.MuxedAccount( - type=Xdr.const.KEY_TYPE_MUXED_ED25519, med25519=med25519 - ) - else: - raise ValueError("Invalid encoded string, this is not a valid account.") - return muxed - def decode_check(version_byte_name: str, encoded: str) -> bytes: encoded_data = _bytes_from_decode_data(encoded) @@ -234,7 +174,7 @@ def decode_check(version_byte_name: str, encoded: str) -> bytes: if expected_version is None: raise TypeError( '{} is not a valid version byte name. expected one of "ed25519_public_key", ' - '"ed25519_secret_seed", "pre_auth_tx", "sha256_hash", "muxed_account"'.format( + '"ed25519_secret_seed", "pre_auth_tx", "sha256_hash"'.format( version_byte_name ) ) @@ -261,7 +201,7 @@ def encode_check(version_byte_name: str, data: bytes) -> str: if version_byte is None: raise TypeError( '{} is not a valid version byte name. expected one of "ed25519_public_key", ' - '"ed25519_secret_seed", "pre_auth_tx", "sha256_hash", "muxed_account"'.format( + '"ed25519_secret_seed", "pre_auth_tx", "sha256_hash"'.format( version_byte_name ) ) diff --git a/stellar_sdk/transaction.py b/stellar_sdk/transaction.py index 1ef39386..b44ab265 100644 --- a/stellar_sdk/transaction.py +++ b/stellar_sdk/transaction.py @@ -2,12 +2,11 @@ from .keypair import Keypair from .memo import NoneMemo, Memo -from .muxed_account import MuxedAccount from .operation.operation import Operation -from .xdr import Xdr from .strkey import StrKey from .time_bounds import TimeBounds from .utils import pack_xdr_array, unpack_xdr_array +from .xdr import Xdr __all__ = ["Transaction"] @@ -51,7 +50,7 @@ class Transaction: def __init__( self, - source: Union[Keypair, MuxedAccount, str], + source: Union[Keypair, str], sequence: int, fee: int, operations: List[Operation], @@ -65,12 +64,10 @@ def __init__( if memo is None: memo = NoneMemo() - if isinstance(source, Keypair): - source = MuxedAccount(account_id=source.public_key, account_id_id=None) if isinstance(source, str): - source = MuxedAccount.from_account(source) + source = Keypair.from_public_key(source) - self.source: [MuxedAccount, str] = source + self.source: Keypair = source self.sequence: int = sequence self.operations: List[Operation] = operations self.memo: Memo = memo @@ -91,13 +88,11 @@ def to_xdr_object(self) -> Union[Xdr.types.Transaction, Xdr.types.TransactionV0] ext = Xdr.nullclass() ext.v = 0 if self.v1: - source_xdr = self.source.to_xdr_object() + source_xdr = self.source.xdr_muxed_account() return Xdr.types.Transaction( source_xdr, self.fee, self.sequence, time_bounds, memo, operations, ext, ) - source_xdr = ( - Keypair.from_public_key(self.source.account_id).xdr_account_id().ed25519 - ) + source_xdr = self.source.xdr_public_key().ed25519 return Xdr.types.TransactionV0( source_xdr, self.fee, self.sequence, time_bounds, memo, operations, ext, ) @@ -119,7 +114,9 @@ def from_xdr_object( :return: A new :class:`Transaction` object from the given XDR Transaction object. """ if v1: - source = MuxedAccount.from_xdr_object(tx_xdr_object.sourceAccount) + source = StrKey.encode_ed25519_public_key( + tx_xdr_object.sourceAccount.ed25519 + ) else: source = StrKey.encode_ed25519_public_key( tx_xdr_object.sourceAccountEd25519 diff --git a/stellar_sdk/transaction_builder.py b/stellar_sdk/transaction_builder.py index b561805f..cdc68c7c 100644 --- a/stellar_sdk/transaction_builder.py +++ b/stellar_sdk/transaction_builder.py @@ -10,7 +10,6 @@ from .fee_bump_transaction_envelope import FeeBumpTransactionEnvelope from .keypair import Keypair from .memo import * -from .muxed_account import MuxedAccount from .network import Network from .operation import * from .price import Price @@ -89,7 +88,7 @@ def build(self) -> TransactionEnvelope: @staticmethod def build_fee_bump_transaction( - fee_source: Union[MuxedAccount, Keypair, str], + fee_source: Union[Keypair, str], base_fee: int, inner_transaction_envelope: TransactionEnvelope, network_passphrase: str = Network.TESTNET_NETWORK_PASSPHRASE, @@ -276,7 +275,7 @@ def append_create_account_op( self, destination: str, starting_balance: Union[str, Decimal], - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> "TransactionBuilder": """Append a :class:`CreateAccount ` operation to the list of @@ -298,7 +297,7 @@ def append_change_trust_op( asset_code: str, asset_issuer: str, limit: Union[str, Decimal] = None, - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> "TransactionBuilder": """Append a :class:`ChangeTrust ` operation to the list of operations. @@ -316,11 +315,11 @@ def append_change_trust_op( def append_payment_op( self, - destination: Union[MuxedAccount, str], + destination: str, amount: Union[str, Decimal], asset_code: str = "XLM", asset_issuer: Optional[str] = None, - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> "TransactionBuilder": """Append a :class:`Payment ` operation to the list of operations. @@ -339,7 +338,7 @@ def append_payment_op( def append_path_payment_op( self, - destination: Union[MuxedAccount, str], + destination: str, send_code: str, send_issuer: Optional[str], send_max: Union[str, Decimal], @@ -347,7 +346,7 @@ def append_path_payment_op( dest_issuer: Optional[str], dest_amount: Union[str, Decimal], path: List[Asset], - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> "TransactionBuilder": """Append a :class:`PathPayment ` operation to the list of operations. @@ -395,7 +394,7 @@ def append_path_payment_op( def append_path_payment_strict_receive_op( self, - destination: Union[MuxedAccount, str], + destination: str, send_code: str, send_issuer: Optional[str], send_max: Union[str, Decimal], @@ -403,7 +402,7 @@ def append_path_payment_strict_receive_op( dest_issuer: Optional[str], dest_amount: Union[str, Decimal], path: List[Asset], - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> "TransactionBuilder": """Append a :class:`PathPaymentStrictReceive ` operation to the list of operations. @@ -445,7 +444,7 @@ def append_path_payment_strict_receive_op( def append_path_payment_strict_send_op( self, - destination: Union[MuxedAccount, str], + destination: str, send_code: str, send_issuer: Optional[str], send_amount: Union[str, Decimal], @@ -453,7 +452,7 @@ def append_path_payment_strict_send_op( dest_issuer: Optional[str], dest_min: Union[str, Decimal], path: List[Asset], - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> "TransactionBuilder": """Append a :class:`PathPaymentStrictSend ` operation to the list of operations. @@ -496,7 +495,7 @@ def append_allow_trust_op( trustor: str, asset_code: str, authorize: Union[TrustLineEntryFlag, bool], - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> "TransactionBuilder": """Append an :class:`AllowTrust ` operation to the list of operations. @@ -526,7 +525,7 @@ def append_set_options_op( high_threshold: int = None, home_domain: str = None, signer: Signer = None, - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> "TransactionBuilder": """Append a :class:`SetOptions ` operation to the list of operations. @@ -578,7 +577,7 @@ def append_set_options_op( return self.append_operation(op) def append_ed25519_public_key_signer( - self, account_id: str, weight: int, source: Union[MuxedAccount, str] = None + self, account_id: str, weight: int, source: str = None ) -> "TransactionBuilder": """Add a ed25519 public key signer to an account. @@ -600,7 +599,7 @@ def append_hashx_signer( self, sha256_hash: [bytes, str], weight: int, - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> "TransactionBuilder": """Add a sha256 hash(HashX) signer to an account. @@ -625,7 +624,7 @@ def append_pre_auth_tx_signer( self, pre_auth_tx_hash: bytes, weight: int, - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> "TransactionBuilder": """Add a PreAuthTx signer to an account. @@ -656,7 +655,7 @@ def append_manage_buy_offer_op( amount: Union[str, Decimal], price: Union[str, Decimal, Price], offer_id: int = 0, - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> "TransactionBuilder": """Append a :class:`ManageBuyOffer ` operation to the list of operations. @@ -700,7 +699,7 @@ def append_manage_sell_offer_op( amount: Union[str, Decimal], price: Union[str, Price, Decimal], offer_id: int = 0, - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> "TransactionBuilder": """Append a :class:`ManageSellOffer ` operation to the list of operations. @@ -743,7 +742,7 @@ def append_create_passive_sell_offer_op( buying_issuer: Optional[str], amount: Union[str, Decimal], price: Union[str, Price, Decimal], - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> "TransactionBuilder": """Append a :class:`CreatePassiveSellOffer ` operation to the list of @@ -773,8 +772,8 @@ def append_create_passive_sell_offer_op( def append_account_merge_op( self, - destination: Union[MuxedAccount, str], - source: Union[MuxedAccount, str] = None, + destination: str, + source: str = None, ) -> "TransactionBuilder": """Append a :class:`AccountMerge ` operation to the list of @@ -791,7 +790,7 @@ def append_account_merge_op( return self.append_operation(op) def append_inflation_op( - self, source: Union[MuxedAccount, str] = None + self, source: str = None ) -> "TransactionBuilder": """Append a :class:`Inflation ` operation to the list of @@ -809,7 +808,7 @@ def append_manage_data_op( self, data_name: str, data_value: Union[str, bytes, None], - source: Union[MuxedAccount, str] = None, + source: str = None, ) -> "TransactionBuilder": """Append a :class:`ManageData ` operation to the list of operations. @@ -829,7 +828,7 @@ def append_manage_data_op( return self.append_operation(op) def append_bump_sequence_op( - self, bump_to: int, source: Union[MuxedAccount, str] = None + self, bump_to: int, source: str = None ) -> "TransactionBuilder": """Append a :class:`BumpSequence ` operation to the list of operations. diff --git a/tests/sep/test_stellar_web_authentication.py b/tests/sep/test_stellar_web_authentication.py index 63ee6390..66cfce4b 100644 --- a/tests/sep/test_stellar_web_authentication.py +++ b/tests/sep/test_stellar_web_authentication.py @@ -4,7 +4,7 @@ import pytest -from stellar_sdk import Keypair, Network, Account, MuxedAccount +from stellar_sdk import Keypair, Network, Account from stellar_sdk.exceptions import ValueError from stellar_sdk.operation import ManageData from stellar_sdk.sep.ed25519_public_key_signer import Ed25519PublicKeySigner @@ -47,7 +47,7 @@ def test_challenge_transaction(self): assert op.data_name == "SDF auth" assert len(op.data_value) == 64 assert len(base64.b64decode(op.data_value)) == 48 - assert op.source == MuxedAccount(client_account_id) + assert op.source == client_account_id now = int(time.time()) assert now - 3 < transaction.time_bounds.min_time < now + 3 @@ -55,29 +55,9 @@ def test_challenge_transaction(self): transaction.time_bounds.max_time - transaction.time_bounds.min_time == timeout ) - assert transaction.source == MuxedAccount.from_account(server_kp.public_key) + assert transaction.source == server_kp.public_key assert transaction.sequence == 0 - def test_challenge_transaction_mux_client_account_id_raise(self): - server_kp = Keypair.random() - client_account_id = ( - "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" - ) - timeout = 600 - network_passphrase = Network.TESTNET_NETWORK_PASSPHRASE - anchor_name = "SDF" - with pytest.raises( - ValueError, - match="Invalid client_account_id, multiplexed account are not supported.", - ): - build_challenge_transaction( - server_secret=server_kp.secret, - client_account_id=client_account_id, - anchor_name=anchor_name, - network_passphrase=network_passphrase, - timeout=timeout, - ) - def test_verify_challenge_transaction(self): server_kp = Keypair.random() client_kp = Keypair.random() @@ -790,30 +770,6 @@ def test_verify_challenge_transaction_threshold_raise_not_meet_threshold(self): signers, ) - def test_read_challenge_transaction_mux_server_id_raise(self): - server_kp = Keypair.random() - client_account_id = "GBDIT5GUJ7R5BXO3GJHFXJ6AZ5UQK6MNOIDMPQUSMXLIHTUNR2Q5CFNF" - timeout = 600 - network_passphrase = Network.TESTNET_NETWORK_PASSPHRASE - anchor_name = "SDF" - - challenge = build_challenge_transaction( - server_secret=server_kp.secret, - client_account_id=client_account_id, - anchor_name=anchor_name, - network_passphrase=network_passphrase, - timeout=timeout, - ) - with pytest.raises( - ValueError, - match="Invalid server_account_id, multiplexed account are not supported.", - ): - read_challenge_transaction( - challenge, - "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY", - network_passphrase, - ) - def test_read_challenge_transaction_fee_bump_transaction_raise(self): inner_keypair = Keypair.from_secret( "SBKTIFHJSS3JJWEZO2W74DZSA45WZU56LOL3AY7GAW63BXPEJQFYV53E" diff --git a/tests/test_account.py b/tests/test_account.py index 5c4beae8..b2827d63 100644 --- a/tests/test_account.py +++ b/tests/test_account.py @@ -1,6 +1,5 @@ import pytest -from stellar_sdk import MuxedAccount from stellar_sdk.account import Account from stellar_sdk.exceptions import Ed25519PublicKeyInvalidError from stellar_sdk.sep.ed25519_public_key_signer import Ed25519PublicKeySigner @@ -12,7 +11,7 @@ def test_account(self): sequence = 123123 account = Account(account_id=account_id, sequence=sequence) assert account.sequence == sequence - assert account.account_id == MuxedAccount(account_id) + assert account.account_id == account_id other_account = Account(account_id=account_id, sequence=sequence) assert account == other_account diff --git a/tests/test_muxed_account.py b/tests/test_muxed_account.py deleted file mode 100644 index 776361dc..00000000 --- a/tests/test_muxed_account.py +++ /dev/null @@ -1,72 +0,0 @@ -import pytest - -from stellar_sdk.exceptions import ValueError -from stellar_sdk.muxed_account import MuxedAccount -from stellar_sdk.strkey import StrKey -from stellar_sdk.xdr import Xdr - - -class TestMuxedAccount: - def test_init_with_account_id_id(self): - account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" - account_id_id = 1234 - account_id_muxed = ( - "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" - ) - med25519 = Xdr.nullclass() - med25519.id = account_id_id - med25519.ed25519 = StrKey.decode_ed25519_public_key(account_id) - muxed_account_xdr = Xdr.types.MuxedAccount( - type=Xdr.const.KEY_TYPE_MUXED_ED25519, med25519=med25519 - ) - muxed_account = MuxedAccount(account_id, account_id_id) - assert muxed_account.account_id_muxed == account_id_muxed - assert muxed_account.to_xdr_object().to_xdr() == muxed_account_xdr.to_xdr() - assert MuxedAccount.from_xdr_object(muxed_account_xdr) == muxed_account - - def test_init_without_account_id_id(self): - account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" - account_id_id = None - muxed_account_xdr = Xdr.types.MuxedAccount( - type=Xdr.const.KEY_TYPE_ED25519, - ed25519=StrKey.decode_ed25519_public_key(account_id), - ) - muxed_account = MuxedAccount(account_id, account_id_id) - assert muxed_account.account_id_muxed is None - assert muxed_account.to_xdr_object().to_xdr() == muxed_account_xdr.to_xdr() - assert MuxedAccount.from_xdr_object(muxed_account_xdr) == muxed_account - - def test_from_account_muxed_account(self): - account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" - account_id_id = 1234 - account_id_muxed = ( - "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" - ) - muxed_account = MuxedAccount.from_account(account_id_muxed) - assert muxed_account.account_id == account_id - assert muxed_account.account_id_id == account_id_id - - def test_from_account_ed25519_account(self): - account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" - account_id_id = None - muxed_account = MuxedAccount.from_account(account_id) - assert muxed_account.account_id == account_id - assert muxed_account.account_id_id == account_id_id - - def test_set_muxed_account_raise(self): - account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" - account_id_id = 1234 - account_id_muxed = ( - "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" - ) - muxed_account = MuxedAccount(account_id, account_id_id) - with pytest.raises( - AttributeError, - match="Can't set attribute, use `MuxedAccount.from_account` instead.", - ): - muxed_account.account_id_muxed = account_id_muxed - - def test_from_account_invalid_account_raise(self): - invalid_account = "A" * 100 - with pytest.raises(ValueError, match="This is not a valid account."): - MuxedAccount.from_account(invalid_account) diff --git a/tests/test_operation.py b/tests/test_operation.py index 19aeb72c..4920ca61 100644 --- a/tests/test_operation.py +++ b/tests/test_operation.py @@ -28,7 +28,6 @@ ) from stellar_sdk.signer import Signer from stellar_sdk.utils import sha256 -from stellar_sdk.muxed_account import MuxedAccount class TestBaseOperation: @@ -87,18 +86,6 @@ def test_to_xdr_amount_raise(self, origin_amount, exception, reason): def test_from_xdr_amount(self, origin_amount, expect_value): assert Operation.from_xdr_amount(origin_amount) == expect_value - def test_get_source_exist_from_xdr_obj(self): # BAD TEST - source = "GDL635DMMORJHKEHHQIIB4VPYM6YGEMPLORYHHM2DEHAUOUXLSTMHQDV" - destination = "GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ" - starting_balance = "1000.00" - origin_op = CreateAccount(destination, starting_balance, source) - origin_xdr_obj = origin_op.to_xdr_object() - - op = Operation.from_xdr_object(origin_xdr_obj) - assert op.source == MuxedAccount.from_account(source) - assert op.starting_balance == "1000" - assert op.destination == destination - def test_get_source_no_exist_from_xdr_obj(self): # BAD TEST destination = "GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ" starting_balance = "1000.00" @@ -110,32 +97,6 @@ def test_get_source_no_exist_from_xdr_obj(self): # BAD TEST assert op.starting_balance == "1000" assert op.destination == destination - def test_get_muxed_account_str_source_exist_from_xdr_obj(self): # BAD TEST - source = "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" - destination = "GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ" - starting_balance = "1000.00" - origin_op = CreateAccount(destination, starting_balance, source) - origin_xdr_obj = origin_op.to_xdr_object() - - op = Operation.from_xdr_object(origin_xdr_obj) - assert op.source == MuxedAccount.from_account(source) - assert op.starting_balance == "1000" - assert op.destination == destination - - def test_get_muxed_account_source_exist_from_xdr_obj(self): # BAD TEST - source = MuxedAccount( - "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY", 1234 - ) - destination = "GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ" - starting_balance = "1000.00" - origin_op = CreateAccount(destination, starting_balance, source) - origin_xdr_obj = origin_op.to_xdr_object() - - op = Operation.from_xdr_object(origin_xdr_obj) - assert op.source == source - assert op.starting_balance == "1000" - assert op.destination == destination - def test_equal(self): op1 = ManageData("a", "b") op2 = ManageData("a", "b") @@ -203,7 +164,7 @@ def test_from_xdr_obj(self): op = Operation.from_xdr_object(origin_xdr_obj) assert ( - op.source == source if source is None else MuxedAccount.from_account(source) + op.source == source ) assert op.starting_balance == "1000" assert op.destination == destination @@ -227,7 +188,7 @@ def test_from_xdr_obj(self): op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, BumpSequence) assert ( - op.source == source if source is None else MuxedAccount.from_account(source) + op.source == source ) assert op.bump_to == bump_to @@ -247,7 +208,7 @@ def test_from_xdr_obj(self): op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, Inflation) assert ( - op.source == source if source is None else MuxedAccount.from_account(source) + op.source == source ) @@ -268,37 +229,12 @@ def test_from_xdr_obj(self): op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, AccountMerge) assert ( - op.source == source if source is None else MuxedAccount.from_account(source) - ) - assert op.destination == MuxedAccount.from_account(destination) - - def test_from_xdr_obj_muxed_str_account(self): - source = "GDL635DMMORJHKEHHQIIB4VPYM6YGEMPLORYHHM2DEHAUOUXLSTMHQDV" - destination = ( - "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" - ) - origin_xdr_obj = AccountMerge(destination, source).to_xdr_object() - op = Operation.from_xdr_object(origin_xdr_obj) - assert isinstance(op, AccountMerge) - assert ( - op.source == source if source is None else MuxedAccount.from_account(source) - ) - assert op.destination == MuxedAccount.from_account(destination) - - def test_from_xdr_obj_muxed_account(self): - source = "GDL635DMMORJHKEHHQIIB4VPYM6YGEMPLORYHHM2DEHAUOUXLSTMHQDV" - destination = MuxedAccount( - "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY", 1234 - ) - origin_xdr_obj = AccountMerge(destination, source).to_xdr_object() - op = Operation.from_xdr_object(origin_xdr_obj) - assert isinstance(op, AccountMerge) - assert ( - op.source == source if source is None else MuxedAccount.from_account(source) + op.source == source ) assert op.destination == destination + class TestChangeTrust: @pytest.mark.parametrize( "limit, xdr", @@ -335,7 +271,7 @@ def test_from_xdr_obj(self): op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, ChangeTrust) assert ( - op.source == source if source is None else MuxedAccount.from_account(source) + op.source == source ) assert op.limit == limit assert op.asset == asset @@ -378,47 +314,14 @@ def test_from_xdr_obj(self): op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, Payment) assert ( - op.source == source if source is None else MuxedAccount.from_account(source) - ) - assert op.destination == MuxedAccount.from_account(destination) - assert op.amount == "1000" - assert op.asset == asset - - def test_from_xdr_obj_mux_account_str(self): - source = "GDL635DMMORJHKEHHQIIB4VPYM6YGEMPLORYHHM2DEHAUOUXLSTMHQDV" - destination = ( - "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" - ) - amount = "1000.0000000" - asset = Asset("USD", "GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7") - origin_xdr_obj = Payment(destination, asset, amount, source).to_xdr_object() - op = Operation.from_xdr_object(origin_xdr_obj) - assert isinstance(op, Payment) - assert ( - op.source == source if source is None else MuxedAccount.from_account(source) - ) - assert op.destination == MuxedAccount.from_account(destination) - assert op.amount == "1000" - assert op.asset == asset - - def test_from_xdr_obj_mux_account(self): - source = "GDL635DMMORJHKEHHQIIB4VPYM6YGEMPLORYHHM2DEHAUOUXLSTMHQDV" - destination = MuxedAccount( - "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY", 1234 - ) - amount = "1000.0000000" - asset = Asset("USD", "GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7") - origin_xdr_obj = Payment(destination, asset, amount, source).to_xdr_object() - op = Operation.from_xdr_object(origin_xdr_obj) - assert isinstance(op, Payment) - assert ( - op.source == source if source is None else MuxedAccount.from_account(source) + op.source == source ) assert op.destination == destination assert op.amount == "1000" assert op.asset == asset + class TestPathPayment: def test_to_xdr_obj(self): source = "GDL635DMMORJHKEHHQIIB4VPYM6YGEMPLORYHHM2DEHAUOUXLSTMHQDV" @@ -488,9 +391,9 @@ def test_from_xdr_obj(self): op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, PathPaymentStrictReceive) assert ( - op.source == source if source is None else MuxedAccount.from_account(source) + op.source == source ) - assert op.destination == MuxedAccount.from_account(destination) + assert op.destination == destination assert op.send_asset == send_asset assert op.dest_asset == dest_asset assert op.send_max == "3.007" @@ -563,71 +466,7 @@ def test_from_xdr_obj(self): op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, PathPaymentStrictReceive) assert ( - op.source == source if source is None else MuxedAccount.from_account(source) - ) - assert op.destination == MuxedAccount.from_account(destination) - assert op.send_asset == send_asset - assert op.dest_asset == dest_asset - assert op.send_max == "3.007" - assert op.dest_amount == "3.1415" - assert op.path == path - - def test_from_xdr_obj_muxed_account_str(self): - source = "GDL635DMMORJHKEHHQIIB4VPYM6YGEMPLORYHHM2DEHAUOUXLSTMHQDV" - destination = ( - "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" - ) - send_asset = Asset( - "USD", "GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7" - ) - dest_asset = Asset( - "USD", "GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7" - ) - send_max = "3.0070000" - dest_amount = "3.1415000" - path = [ - Asset("USD", "GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB"), - Asset("EUR", "GDTNXRLOJD2YEBPKK7KCMR7J33AAG5VZXHAJTHIG736D6LVEFLLLKPDL"), - ] - origin_xdr_obj = PathPaymentStrictReceive( - destination, send_asset, send_max, dest_asset, dest_amount, path, source - ).to_xdr_object() - op = Operation.from_xdr_object(origin_xdr_obj) - assert isinstance(op, PathPaymentStrictReceive) - assert ( - op.source == source if source is None else MuxedAccount.from_account(source) - ) - assert op.destination == MuxedAccount.from_account(destination) - assert op.send_asset == send_asset - assert op.dest_asset == dest_asset - assert op.send_max == "3.007" - assert op.dest_amount == "3.1415" - assert op.path == path - - def test_from_xdr_obj_muxed_account(self): - source = "GDL635DMMORJHKEHHQIIB4VPYM6YGEMPLORYHHM2DEHAUOUXLSTMHQDV" - destination = MuxedAccount( - "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY", 1234 - ) - send_asset = Asset( - "USD", "GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7" - ) - dest_asset = Asset( - "USD", "GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7" - ) - send_max = "3.0070000" - dest_amount = "3.1415000" - path = [ - Asset("USD", "GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB"), - Asset("EUR", "GDTNXRLOJD2YEBPKK7KCMR7J33AAG5VZXHAJTHIG736D6LVEFLLLKPDL"), - ] - origin_xdr_obj = PathPaymentStrictReceive( - destination, send_asset, send_max, dest_asset, dest_amount, path, source - ).to_xdr_object() - op = Operation.from_xdr_object(origin_xdr_obj) - assert isinstance(op, PathPaymentStrictReceive) - assert ( - op.source == source if source is None else MuxedAccount.from_account(source) + op.source == source ) assert op.destination == destination assert op.send_asset == send_asset @@ -702,71 +541,7 @@ def test_from_xdr_obj(self): op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, PathPaymentStrictSend) assert ( - op.source == source if source is None else MuxedAccount.from_account(source) - ) - assert op.destination == MuxedAccount.from_account(destination) - assert op.send_asset == send_asset - assert op.dest_asset == dest_asset - assert op.send_amount == "3.1415" - assert op.dest_min == "3.007" - assert op.path == path - - def test_from_xdr_obj_muxed_account_str(self): - source = "GDL635DMMORJHKEHHQIIB4VPYM6YGEMPLORYHHM2DEHAUOUXLSTMHQDV" - destination = ( - "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" - ) - send_asset = Asset( - "USD", "GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7" - ) - dest_asset = Asset( - "USD", "GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7" - ) - send_amount = "3.1415000" - dest_min = "3.0070000" - path = [ - Asset("USD", "GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB"), - Asset("EUR", "GDTNXRLOJD2YEBPKK7KCMR7J33AAG5VZXHAJTHIG736D6LVEFLLLKPDL"), - ] - origin_xdr_obj = PathPaymentStrictSend( - destination, send_asset, send_amount, dest_asset, dest_min, path, source - ).to_xdr_object() - op = Operation.from_xdr_object(origin_xdr_obj) - assert isinstance(op, PathPaymentStrictSend) - assert ( - op.source == source if source is None else MuxedAccount.from_account(source) - ) - assert op.destination == MuxedAccount.from_account(destination) - assert op.send_asset == send_asset - assert op.dest_asset == dest_asset - assert op.send_amount == "3.1415" - assert op.dest_min == "3.007" - assert op.path == path - - def test_from_xdr_obj_muxed_account(self): - source = "GDL635DMMORJHKEHHQIIB4VPYM6YGEMPLORYHHM2DEHAUOUXLSTMHQDV" - destination = MuxedAccount( - "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY", 1234 - ) - send_asset = Asset( - "USD", "GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7" - ) - dest_asset = Asset( - "USD", "GDGU5OAPHNPU5UCLE5RDJHG7PXZFQYWKCFOEXSXNMR6KRQRI5T6XXCD7" - ) - send_amount = "3.1415000" - dest_min = "3.0070000" - path = [ - Asset("USD", "GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB"), - Asset("EUR", "GDTNXRLOJD2YEBPKK7KCMR7J33AAG5VZXHAJTHIG736D6LVEFLLLKPDL"), - ] - origin_xdr_obj = PathPaymentStrictSend( - destination, send_asset, send_amount, dest_asset, dest_min, path, source - ).to_xdr_object() - op = Operation.from_xdr_object(origin_xdr_obj) - assert isinstance(op, PathPaymentStrictSend) - assert ( - op.source == source if source is None else MuxedAccount.from_account(source) + op.source == source ) assert op.destination == destination assert op.send_asset == send_asset @@ -827,7 +602,7 @@ def test_from_xdr_obj(self, asset_code, authorize): op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, AllowTrust) assert ( - op.source == source if source is None else MuxedAccount.from_account(source) + op.source == source ) assert op.trustor == trustor assert op.asset_code == asset_code @@ -891,7 +666,7 @@ def test_from_xdr_obj(self, name, value): op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, ManageData) assert ( - op.source == source if source is None else MuxedAccount.from_account(source) + op.source == source ) assert op.data_name == name if isinstance(value, str): @@ -1010,8 +785,6 @@ def test_to_xdr( assert isinstance(from_instance, SetOptions) assert ( from_instance.source == source - if source is None - else MuxedAccount.from_account(source) ) assert from_instance.clear_flags == clear_flags assert from_instance.set_flags == set_flags @@ -1074,8 +847,6 @@ def test_to_xdr(self, selling, buying, amount, price, offer_id, source, xdr): assert isinstance(from_instance, ManageSellOffer) assert ( from_instance.source == source - if source is None - else MuxedAccount.from_account(source) ) assert from_instance.buying == buying assert from_instance.selling == selling @@ -1137,8 +908,6 @@ def test_to_xdr(self, selling, buying, amount, price, offer_id, source, xdr): assert isinstance(from_instance, ManageBuyOffer) assert ( from_instance.source == source - if source is None - else MuxedAccount.from_account(source) ) assert from_instance.buying == buying assert from_instance.selling == selling @@ -1197,8 +966,6 @@ def test_to_xdr(self, selling, buying, amount, price, source, xdr): assert isinstance(from_instance, CreatePassiveSellOffer) assert ( from_instance.source == source - if source is None - else MuxedAccount.from_account(source) ) assert from_instance.buying == buying assert from_instance.selling == selling @@ -1222,7 +989,7 @@ def test_check_source(self): ), ( "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHBAD", - "Invalid Muxed Account: ", + "Invalid Ed25519 Public Key: ", ), ], ) diff --git a/tests/test_server.py b/tests/test_server.py index c74cfa48..49788f9c 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -1,6 +1,5 @@ import pytest -from stellar_sdk import MuxedAccount from stellar_sdk.account import Thresholds from stellar_sdk.asset import Asset from stellar_sdk.call_builder import FeeStatsCallBuilder @@ -38,73 +37,25 @@ class TestServer: def test_load_acount_sync(self): account_id = "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D" horizon_url = "https://horizon.stellar.org" - with Server(horizon_url) as server: - account = server.load_account(account_id) - assert account.account_id == MuxedAccount.from_account(account_id) - assert isinstance(account.sequence, int) - assert account.thresholds == Thresholds(1, 2, 3) - - def test_load_acount_muxed_account_str_sync(self): - account_id = ( - "MAAAAAAAAAAAJUXL4LKO7RYSP6IIDETQ7BBRSBW4F5GVGZVGBPCPNHYIIX6CTUDGHDUWO" - ) - horizon_url = "https://horizon.stellar.org" - with Server(horizon_url) as server: - account = server.load_account(account_id) - assert account.account_id == MuxedAccount.from_account( - "MAAAAAAAAAAAJUXL4LKO7RYSP6IIDETQ7BBRSBW4F5GVGZVGBPCPNHYIIX6CTUDGHDUWO" - ) - assert isinstance(account.sequence, int) - assert account.thresholds == Thresholds(1, 2, 3) - - def test_load_acount_muxed_account_sync(self): - account_id = MuxedAccount( - "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D", 1234 - ) - horizon_url = "https://horizon.stellar.org" with Server(horizon_url) as server: account = server.load_account(account_id) assert account.account_id == account_id assert isinstance(account.sequence, int) assert account.thresholds == Thresholds(1, 2, 3) + @pytest.mark.asyncio async def test_load_acount_async(self): account_id = "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D" horizon_url = "https://horizon.stellar.org" client = AiohttpClient() - async with Server(horizon_url, client) as server: - account = await server.load_account(account_id) - assert account.account_id == MuxedAccount.from_account(account_id) - assert isinstance(account.sequence, int) - assert account.thresholds == Thresholds(1, 2, 3) - - @pytest.mark.asyncio - async def test_load_acount_muxed_account_str_async(self): - account_id = ( - "MAAAAAAAAAAAJUXL4LKO7RYSP6IIDETQ7BBRSBW4F5GVGZVGBPCPNHYIIX6CTUDGHDUWO" - ) - horizon_url = "https://horizon.stellar.org" - client = AiohttpClient() - async with Server(horizon_url, client) as server: - account = await server.load_account(account_id) - assert account.account_id == MuxedAccount.from_account(account_id) - assert isinstance(account.sequence, int) - assert account.thresholds == Thresholds(1, 2, 3) - - @pytest.mark.asyncio - async def test_load_acount_muxed_account_async(self): - account_id = MuxedAccount( - "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D", 1234 - ) - horizon_url = "https://horizon.stellar.org" - client = AiohttpClient() async with Server(horizon_url, client) as server: account = await server.load_account(account_id) assert account.account_id == account_id assert isinstance(account.sequence, int) assert account.thresholds == Thresholds(1, 2, 3) + def test_fetch_base_fee_sync(self): horizon_url = "https://horizon.stellar.org" with Server(horizon_url) as server: diff --git a/tests/test_strkey.py b/tests/test_strkey.py index 78193c3f..7c0effb0 100644 --- a/tests/test_strkey.py +++ b/tests/test_strkey.py @@ -1,72 +1,2 @@ -import pytest - -from stellar_sdk.strkey import StrKey -from stellar_sdk.xdr import Xdr - - class TestStrKey: - # TODO: we need more tests here - @pytest.mark.parametrize( - "key", - [ - ("GAAAAAAAACGC6",), - ("MAAAAAAAAAAAAAB7BQ2L7E5NBWMXDUCMZSIPOBKRDSBYVLMXGSSKF6YNPIB7Y77ITLVL7",), - ("GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZA",), - ("GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUACUSI",), - ("G47QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVP2I",), - ("MCAAAAAAAAAAAAB7BQ2L7E5NBWMXDUCMZSIPOBKRDSBYVLMXGSSKF6YNPIB7Y77ITKNOGA",), - ( - "MAAAAAAAAAAAAAB7BQ2L7E5NBWMXDUCMZSIPOBKRDSBYVLMXGSSKF6YNPIB7Y77ITIADJPA", - ), - ("M4AAAAAAAAAAAAB7BQ2L7E5NBWMXDUCMZSIPOBKRDSBYVLMXGSSKF6YNPIB7Y77ITIU2K",), - ( - "MAAAAAAAAAAAAAB7BQ2L7E5NBWMXDUCMZSIPOBKRDSBYVLMXGSSKF6YNPIB7Y77ITLVL6===", - ), - ("MAAAAAAAAAAAAAB7BQ2L7E5NBWMXDUCMZSIPOBKRDSBYVLMXGSSKF6YNPIB7Y77ITLVL4",), - ], - ) - def test_decode_invalid_muxed_account_raise(self, key): - with pytest.raises(ValueError): - StrKey.decode_muxed_account(key) - - def test_decode_muxed_account_med25519(self): - # account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" - # account_id_id = 1234 - account_id_muxed = ( - "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" - ) - decoded = StrKey.decode_muxed_account(account_id_muxed).to_xdr() - assert decoded == "AAABAAAAAAAAAATSIAB1furlg/xQ3Wafl2c6zCXsclgjrHP69sffMa0x5Qk=" - - def test_decode_muxed_account_ed25519(self): - account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" - # account_id_id = 1234 - # account_id_muxed = "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" - decoded = StrKey.decode_muxed_account(account_id) - assert ( - decoded.to_xdr() - == Xdr.types.MuxedAccount( - type=Xdr.const.KEY_TYPE_ED25519, - ed25519=StrKey.decode_ed25519_public_key(account_id), - ).to_xdr() - ) - - def test_encode_muxed_account_ed25519(self): - account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" - data = Xdr.types.MuxedAccount( - type=Xdr.const.KEY_TYPE_ED25519, - ed25519=StrKey.decode_ed25519_public_key(account_id), - ) - encoded = StrKey.encode_muxed_account(data) - assert encoded == StrKey.encode_ed25519_public_key( - StrKey.decode_ed25519_public_key(account_id) - ) - - def test_encode_muxed_account_med25519(self): - data = Xdr.types.MuxedAccount.from_xdr( - "AAABAAAAAAAAAATSIAB1furlg/xQ3Wafl2c6zCXsclgjrHP69sffMa0x5Qk=" - ) - expected = ( - "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" - ) - assert StrKey.encode_muxed_account(data) == expected + pass diff --git a/tests/test_transaction.py b/tests/test_transaction.py index f13b08cb..da27167a 100644 --- a/tests/test_transaction.py +++ b/tests/test_transaction.py @@ -1,4 +1,4 @@ -from stellar_sdk import Keypair, IdMemo, Asset, NoneMemo, MuxedAccount +from stellar_sdk import Keypair, IdMemo, Asset, NoneMemo from stellar_sdk.operation import Payment, ManageData from stellar_sdk.time_bounds import TimeBounds from stellar_sdk.transaction import Transaction @@ -28,7 +28,7 @@ def test_to_xdr_v1(self): restore_transaction = Transaction.from_xdr_object(tx_object, v1=True) assert isinstance(restore_transaction, Transaction) - assert restore_transaction.source == MuxedAccount.from_account( + assert restore_transaction.source == Keypair.from_public_key( source.public_key ) assert restore_transaction.fee == fee @@ -56,53 +56,7 @@ def test_to_xdr_str_source_v1(self): restore_transaction = Transaction.from_xdr(xdr, True) assert isinstance(restore_transaction, Transaction) - assert restore_transaction.source == MuxedAccount.from_account(source) - assert restore_transaction.fee == fee - assert restore_transaction.memo == memo - assert restore_transaction.time_bounds == time_bounds - assert restore_transaction.sequence == sequence - - def test_to_xdr_str_muxed_account_str_source_v1(self): - source = "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" - destination = "GDJJRRMBK4IWLEPJGIE6SXD2LP7REGZODU7WDC3I2D6MR37F4XSHBKX2" - amount = "1000.0" - sequence = 1 - memo = IdMemo(100) - fee = 200 - asset = Asset.native() - time_bounds = TimeBounds(12345, 56789) - ops = [Payment(destination, asset, amount), ManageData("hello", "world")] - - tx_object = Transaction( - source, sequence, fee, ops, memo, time_bounds, True - ).to_xdr_object() - restore_transaction = Transaction.from_xdr(tx_object.to_xdr(), True) - assert isinstance(restore_transaction, Transaction) - assert restore_transaction.source == MuxedAccount.from_account(source) - assert restore_transaction.fee == fee - assert restore_transaction.memo == memo - assert restore_transaction.time_bounds == time_bounds - assert restore_transaction.sequence == sequence - - def test_to_xdr_str_muxed_account_source_v1(self): - source = MuxedAccount( - "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY", 1234 - ) - destination = "GDJJRRMBK4IWLEPJGIE6SXD2LP7REGZODU7WDC3I2D6MR37F4XSHBKX2" - amount = "1000.0" - sequence = 1 - memo = IdMemo(100) - fee = 200 - asset = Asset.native() - time_bounds = TimeBounds(12345, 56789) - ops = [Payment(destination, asset, amount), ManageData("hello", "world")] - - tx_object = Transaction( - source, sequence, fee, ops, memo, time_bounds, True - ).to_xdr_object() - restore_transaction = Transaction.from_xdr(tx_object.to_xdr(), True) - assert isinstance(restore_transaction, Transaction) - assert restore_transaction.source == source + assert restore_transaction.source == Keypair.from_public_key(source) assert restore_transaction.fee == fee assert restore_transaction.memo == memo assert restore_transaction.time_bounds == time_bounds @@ -141,9 +95,7 @@ def test_to_xdr_v0(self): restore_transaction = Transaction.from_xdr_object(tx_object, False) assert isinstance(restore_transaction, Transaction) - assert restore_transaction.source == MuxedAccount.from_account( - source.public_key - ) + assert restore_transaction.source == source assert restore_transaction.fee == fee assert restore_transaction.memo == memo assert restore_transaction.time_bounds == time_bounds @@ -170,7 +122,7 @@ def test_to_xdr_str_source_v0(self): restore_transaction = Transaction.from_xdr(tx_object.to_xdr(), False) assert isinstance(restore_transaction, Transaction) - assert restore_transaction.source == MuxedAccount.from_account(source) + assert restore_transaction.source == Keypair.from_public_key(source) assert restore_transaction.fee == fee assert restore_transaction.memo == memo assert restore_transaction.time_bounds == time_bounds From 4674110f4120448c7b1651bc4007b76d5abefcc6 Mon Sep 17 00:00:00 2001 From: overcat <4catcode@gmail.com> Date: Sat, 23 May 2020 15:37:43 +0800 Subject: [PATCH 2/8] refactor: Reverted support for SEP-0023. --- stellar_sdk/exceptions.py | 6 -- tests/test_fee_bump_transaction.py | 148 +---------------------------- 2 files changed, 2 insertions(+), 152 deletions(-) diff --git a/stellar_sdk/exceptions.py b/stellar_sdk/exceptions.py index 483d72d5..ed609759 100644 --- a/stellar_sdk/exceptions.py +++ b/stellar_sdk/exceptions.py @@ -65,12 +65,6 @@ class Ed25519PublicKeyInvalidError(ValueError): """ -class MuxedEd25519AccountInvalidError(ValueError): - """Muxed Ed25519 public key is incorrect. - - """ - - class Ed25519SecretSeedInvalidError(ValueError): """Ed25519 secret seed is incorrect. diff --git a/tests/test_fee_bump_transaction.py b/tests/test_fee_bump_transaction.py index b257db3c..fd9406bb 100644 --- a/tests/test_fee_bump_transaction.py +++ b/tests/test_fee_bump_transaction.py @@ -6,8 +6,7 @@ Network, Keypair, FeeBumpTransactionEnvelope, - FeeBumpTransaction, - MuxedAccount, + FeeBumpTransaction ) from stellar_sdk.exceptions import ValueError @@ -55,150 +54,7 @@ def test_to_xdr(self): assert isinstance(restore_te, FeeBumpTransactionEnvelope) restore_tx = restore_te.transaction assert isinstance(restore_tx, FeeBumpTransaction) - assert restore_tx.fee_source == MuxedAccount.from_account(fee_source.public_key) - assert restore_tx.base_fee == base_fee - assert restore_tx.inner_transaction_envelope.to_xdr() == inner_tx.to_xdr() - - def test_to_xdr_with_muxed_account_str_fee_source(self): - inner_keypair = Keypair.from_secret( - "SBKTIFHJSS3JJWEZO2W74DZSA45WZU56LOL3AY7GAW63BXPEJQFYV53E" - ) - inner_source = Account( - "MAAAAAAAAAAAH2A4KTYT4R7Z6VLHNSFMAK33N3TSKX2OJBSKSXHU4EUFNE3EVMLXYA662", 7 - ) - destination = "GDQERENWDDSQZS7R7WKHZI3BSOYMV3FSWR7TFUYFTKQ447PIX6NREOJM" - amount = "2000.0000000" - inner_tx = ( - TransactionBuilder( - inner_source, Network.TESTNET_NETWORK_PASSPHRASE, 200, v1=True - ) - .append_payment_op(destination=destination, amount=amount, asset_code="XLM") - .add_time_bounds(0, 0) - .build() - ) - inner_tx.sign(inner_keypair) - fee_source = Keypair.from_secret( - "SB7ZMPZB3YMMK5CUWENXVLZWBK4KYX4YU5JBXQNZSK2DP2Q7V3LVTO5V" - ) - base_fee = 200 - fee_bump_tx = TransactionBuilder.build_fee_bump_transaction( - fee_source.public_key, - base_fee, - inner_tx, - Network.TESTNET_NETWORK_PASSPHRASE, - ) - fee_bump_tx.sign(fee_source) - # xdr = "AAAABQAAAADgSJG2GOUMy/H9lHyjYZOwyuyytH8y0wWaoc596L+bEgAAAAAAAAGQAAAAAgAAAAAcVPE+R/n1VnbIrAK3tu5yVfTkhkqVz04ShWk2SrF3wAAAAMgAAAAAAAAACAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAADgSJG2GOUMy/H9lHyjYZOwyuyytH8y0wWaoc596L+bEgAAAAAAAAAEqBfIAAAAAAAAAAABSrF3wAAAAEAordQh63kT50muRLVYaWW7Pgtt8i1tc4t9Bv9MWFWFN3WfTHSU2Jxv7hedjZEyfBPvaS/XnwvYJFcHgPDd1JkNAAAAAAAAAAHov5sSAAAAQKu/RuArXn/P13IIJ8WlnVDStwOquXM0CsWzA4ooZY6gqJ3k1EfmMVIJ0cir0bMTJD9r+g2IUZCANU7wdC38PA0=" - # assert fee_bump_tx.to_xdr() == xdr - restore_te = FeeBumpTransactionEnvelope.from_xdr( - fee_bump_tx.to_xdr(), Network.TESTNET_NETWORK_PASSPHRASE - ) - assert ( - restore_te.to_xdr() - == TransactionBuilder.from_xdr( - fee_bump_tx.to_xdr(), Network.TESTNET_NETWORK_PASSPHRASE - ).to_xdr() - ) - assert isinstance(restore_te, FeeBumpTransactionEnvelope) - restore_tx = restore_te.transaction - assert isinstance(restore_tx, FeeBumpTransaction) - assert restore_tx.fee_source == MuxedAccount.from_account(fee_source.public_key) - assert restore_tx.base_fee == base_fee - assert restore_tx.inner_transaction_envelope.to_xdr() == inner_tx.to_xdr() - - def test_to_xdr_with_muxed_account_fee_source(self): - inner_keypair = Keypair.from_secret( - "SBKTIFHJSS3JJWEZO2W74DZSA45WZU56LOL3AY7GAW63BXPEJQFYV53E" - ) - inner_source = Account( - MuxedAccount( - "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY", 1234 - ), - 7, - ) - destination = "GDQERENWDDSQZS7R7WKHZI3BSOYMV3FSWR7TFUYFTKQ447PIX6NREOJM" - amount = "2000.0000000" - inner_tx = ( - TransactionBuilder( - inner_source, Network.TESTNET_NETWORK_PASSPHRASE, 200, v1=True - ) - .append_payment_op(destination=destination, amount=amount, asset_code="XLM") - .add_time_bounds(0, 0) - .build() - ) - inner_tx.sign(inner_keypair) - fee_source_keypair = Keypair.from_secret( - "SB7ZMPZB3YMMK5CUWENXVLZWBK4KYX4YU5JBXQNZSK2DP2Q7V3LVTO5V" - ) - fee_source = MuxedAccount(fee_source_keypair.public_key, 1234) - base_fee = 200 - fee_bump_tx = TransactionBuilder.build_fee_bump_transaction( - fee_source, base_fee, inner_tx, Network.TESTNET_NETWORK_PASSPHRASE, - ) - fee_bump_tx.sign(fee_source_keypair) - # xdr = "AAAABQAAAADgSJG2GOUMy/H9lHyjYZOwyuyytH8y0wWaoc596L+bEgAAAAAAAAGQAAAAAgAAAAAcVPE+R/n1VnbIrAK3tu5yVfTkhkqVz04ShWk2SrF3wAAAAMgAAAAAAAAACAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAADgSJG2GOUMy/H9lHyjYZOwyuyytH8y0wWaoc596L+bEgAAAAAAAAAEqBfIAAAAAAAAAAABSrF3wAAAAEAordQh63kT50muRLVYaWW7Pgtt8i1tc4t9Bv9MWFWFN3WfTHSU2Jxv7hedjZEyfBPvaS/XnwvYJFcHgPDd1JkNAAAAAAAAAAHov5sSAAAAQKu/RuArXn/P13IIJ8WlnVDStwOquXM0CsWzA4ooZY6gqJ3k1EfmMVIJ0cir0bMTJD9r+g2IUZCANU7wdC38PA0=" - # assert fee_bump_tx.to_xdr() == xdr - restore_te = FeeBumpTransactionEnvelope.from_xdr( - fee_bump_tx.to_xdr(), Network.TESTNET_NETWORK_PASSPHRASE - ) - assert ( - restore_te.to_xdr() - == TransactionBuilder.from_xdr( - fee_bump_tx.to_xdr(), Network.TESTNET_NETWORK_PASSPHRASE - ).to_xdr() - ) - assert isinstance(restore_te, FeeBumpTransactionEnvelope) - restore_tx = restore_te.transaction - assert isinstance(restore_tx, FeeBumpTransaction) - assert restore_tx.fee_source == fee_source - assert restore_tx.base_fee == base_fee - assert restore_tx.inner_transaction_envelope.to_xdr() == inner_tx.to_xdr() - - def test_to_xdr_with_inner_muxed_account_source(self): - inner_keypair = Keypair.from_secret( - "SBKTIFHJSS3JJWEZO2W74DZSA45WZU56LOL3AY7GAW63BXPEJQFYV53E" - ) - inner_source = Account(inner_keypair.public_key, 7) - destination = "GDQERENWDDSQZS7R7WKHZI3BSOYMV3FSWR7TFUYFTKQ447PIX6NREOJM" - amount = "2000.0000000" - inner_tx = ( - TransactionBuilder( - inner_source, Network.TESTNET_NETWORK_PASSPHRASE, 200, v1=True - ) - .append_payment_op(destination=destination, amount=amount, asset_code="XLM") - .add_time_bounds(0, 0) - .build() - ) - inner_tx.sign(inner_keypair) - fee_source = Keypair.from_secret( - "SB7ZMPZB3YMMK5CUWENXVLZWBK4KYX4YU5JBXQNZSK2DP2Q7V3LVTO5V" - ) - base_fee = 200 - fee_bump_tx = TransactionBuilder.build_fee_bump_transaction( - "MAAAAAAAAAAAH2HAJCI3MGHFBTF7D7MUPSRWDE5QZLWLFND7GLJQLGVBZZ66RP43CKRMY", - base_fee, - inner_tx, - Network.TESTNET_NETWORK_PASSPHRASE, - ) - fee_bump_tx.sign(fee_source) - # xdr = "AAAABQAAAADgSJG2GOUMy/H9lHyjYZOwyuyytH8y0wWaoc596L+bEgAAAAAAAAGQAAAAAgAAAAAcVPE+R/n1VnbIrAK3tu5yVfTkhkqVz04ShWk2SrF3wAAAAMgAAAAAAAAACAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAADgSJG2GOUMy/H9lHyjYZOwyuyytH8y0wWaoc596L+bEgAAAAAAAAAEqBfIAAAAAAAAAAABSrF3wAAAAEAordQh63kT50muRLVYaWW7Pgtt8i1tc4t9Bv9MWFWFN3WfTHSU2Jxv7hedjZEyfBPvaS/XnwvYJFcHgPDd1JkNAAAAAAAAAAHov5sSAAAAQKu/RuArXn/P13IIJ8WlnVDStwOquXM0CsWzA4ooZY6gqJ3k1EfmMVIJ0cir0bMTJD9r+g2IUZCANU7wdC38PA0=" - - # assert fee_bump_tx.to_xdr() == xdr - restore_te = FeeBumpTransactionEnvelope.from_xdr( - fee_bump_tx.to_xdr(), Network.TESTNET_NETWORK_PASSPHRASE - ) - assert ( - restore_te.to_xdr() - == TransactionBuilder.from_xdr( - fee_bump_tx.to_xdr(), Network.TESTNET_NETWORK_PASSPHRASE - ).to_xdr() - ) - assert isinstance(restore_te, FeeBumpTransactionEnvelope) - restore_tx = restore_te.transaction - assert isinstance(restore_tx, FeeBumpTransaction) - assert restore_tx.fee_source == MuxedAccount.from_account( - "MAAAAAAAAAAAH2HAJCI3MGHFBTF7D7MUPSRWDE5QZLWLFND7GLJQLGVBZZ66RP43CKRMY" - ) + assert restore_tx.fee_source.public_key == fee_source.public_key assert restore_tx.base_fee == base_fee assert restore_tx.inner_transaction_envelope.to_xdr() == inner_tx.to_xdr() From c3775d3b432e3a0bb8e892672656866177fd7488 Mon Sep 17 00:00:00 2001 From: overcat <4catcode@gmail.com> Date: Sat, 23 May 2020 15:44:59 +0800 Subject: [PATCH 3/8] refactor: Reverted support for SEP-0023. --- stellar_sdk/server.py | 2 +- stellar_sdk/transaction_builder.py | 2 +- tests/sep/test_account_memo_requirements.py | 23 --------------------- 3 files changed, 2 insertions(+), 25 deletions(-) diff --git a/stellar_sdk/server.py b/stellar_sdk/server.py index 89422fcb..371d1517 100644 --- a/stellar_sdk/server.py +++ b/stellar_sdk/server.py @@ -477,7 +477,7 @@ def __get_check_memo_required_destinations( ) for index, operation in enumerate(transaction.operations): if operation.type_code() in memo_required_operation_code: - destination: str = operation.destination.account_id + destination: str = operation.destination else: continue if destination in destinations: diff --git a/stellar_sdk/transaction_builder.py b/stellar_sdk/transaction_builder.py index cdc68c7c..9e5e9729 100644 --- a/stellar_sdk/transaction_builder.py +++ b/stellar_sdk/transaction_builder.py @@ -148,7 +148,7 @@ def from_xdr( ) source_account = Account( - transaction_envelope.transaction.source, + transaction_envelope.transaction.source.public_key, transaction_envelope.transaction.sequence - 1, ) transaction_builder = TransactionBuilder( diff --git a/tests/sep/test_account_memo_requirements.py b/tests/sep/test_account_memo_requirements.py index c19abeff..2e3289e7 100644 --- a/tests/sep/test_account_memo_requirements.py +++ b/tests/sep/test_account_memo_requirements.py @@ -34,9 +34,6 @@ class TestAccountMemoRequirements: DESTINATION_ACCOUNT_FETCH_ERROR = ( "GB7WNQUTDLD6YJ4MR3KQN3Y6ZIDIGTA7GRKNH47HOGMP2ETFGRSLD6OG" ) - ACCOUNT_ID_MUXED = ( - "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" - ) def test_check_memo_required_with_memo_sync(self, httpserver): self.__inject_mock_server(httpserver) @@ -930,16 +927,6 @@ def test_check_memo_required_with_fee_bump_transaction_sync(self, httpserver): transaction = ( TransactionBuilder(account, v1=True) .append_payment_op(self.DESTINATION_ACCOUNT_MEMO_REQUIRED_A, "10", "XLM") - .append_path_payment_strict_receive_op( - self.ACCOUNT_ID_MUXED, - "XLM", - None, - "10", - "BTC", - "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2", - "1", - [], - ) .append_path_payment_strict_send_op( self.DESTINATION_ACCOUNT_MEMO_REQUIRED_C, "XLM", @@ -979,16 +966,6 @@ async def test_check_memo_required_with_fee_bump_transaction_async( .append_payment_op( self.DESTINATION_ACCOUNT_MEMO_REQUIRED_A, "10", "XLM" ) - .append_path_payment_strict_receive_op( - self.ACCOUNT_ID_MUXED, - "XLM", - None, - "10", - "BTC", - "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2", - "1", - [], - ) .append_path_payment_strict_send_op( self.DESTINATION_ACCOUNT_MEMO_REQUIRED_C, "XLM", From 653dd27d70c3eadf4083d7864d9f7879a4334dda Mon Sep 17 00:00:00 2001 From: overcat <4catcode@gmail.com> Date: Sat, 23 May 2020 15:50:19 +0800 Subject: [PATCH 4/8] refactor: Reverted support for SEP-0023. --- stellar_sdk/utils.py | 10 ---------- tests/sep/test_stellar_web_authentication.py | 2 +- tests/test_utils.py | 15 --------------- 3 files changed, 1 insertion(+), 26 deletions(-) diff --git a/stellar_sdk/utils.py b/stellar_sdk/utils.py index a8957d0a..9eb60f6e 100644 --- a/stellar_sdk/utils.py +++ b/stellar_sdk/utils.py @@ -87,16 +87,6 @@ def urljoin_with_query(base: str, path: str) -> str: return url -def parse_ed25519_account_id(data: str) -> str: - if data.startswith(ED25519_PUBLIC_KEY_STARTING_LETTER): - return data - if data.startswith(MUXED_ACCOUNT_STARTING_LETTER): - xdr = decode_check("muxed_account", data) - unpacker = Xdr.StellarXDRUnpacker(xdr) - _ = unpacker.unpack_int64() - ed25519 = unpacker.unpack_uint256() - return StrKey.encode_ed25519_public_key(ed25519) - def check_ed25519_public_key(public_key: str) -> None: StrKey.decode_ed25519_public_key(public_key) diff --git a/tests/sep/test_stellar_web_authentication.py b/tests/sep/test_stellar_web_authentication.py index 66cfce4b..2d9db0b1 100644 --- a/tests/sep/test_stellar_web_authentication.py +++ b/tests/sep/test_stellar_web_authentication.py @@ -55,7 +55,7 @@ def test_challenge_transaction(self): transaction.time_bounds.max_time - transaction.time_bounds.min_time == timeout ) - assert transaction.source == server_kp.public_key + assert transaction.source.public_key == server_kp.public_key assert transaction.sequence == 0 def test_verify_challenge_transaction(self): diff --git a/tests/test_utils.py b/tests/test_utils.py index 3bedd636..cdedc81d 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -126,18 +126,3 @@ def test_hex_to_bytes_type_raise(self, input_value): def test_urljoin_with_query(self, base, path, output): assert output == urljoin_with_query(base, path) - @pytest.mark.parametrize( - "input, output", - [ - ( - "GCBS5PNHHDSRQY2X64ARM36TBQ6K34LNVPZQWWYZH4MZNF2Z6KKASHUC", - "GCBS5PNHHDSRQY2X64ARM36TBQ6K34LNVPZQWWYZH4MZNF2Z6KKASHUC", - ), - ( - "MAAAAAAAAAAAAAMDF262OOHFDBRVP5YBCZX5GDB4VXYW3K7TBNNRSPYZS2LVT4UUBHQGS", - "GCBS5PNHHDSRQY2X64ARM36TBQ6K34LNVPZQWWYZH4MZNF2Z6KKASHUC", - ), - ], - ) - def test_parse_ed25519_account_id(self, input, output): - assert parse_ed25519_account_id(input) == output From b0fdbf958634d826c9178026a5af287bd70efe08 Mon Sep 17 00:00:00 2001 From: overcat <4catcode@gmail.com> Date: Sat, 23 May 2020 16:01:12 +0800 Subject: [PATCH 5/8] code format --- stellar_sdk/exceptions.py | 2 +- stellar_sdk/fee_bump_transaction.py | 4 +- stellar_sdk/operation/account_merge.py | 6 +-- stellar_sdk/operation/change_trust.py | 5 +-- stellar_sdk/operation/manage_data.py | 5 +-- stellar_sdk/operation/operation.py | 4 +- stellar_sdk/operation/utils.py | 3 +- stellar_sdk/server.py | 12 +++-- stellar_sdk/transaction_builder.py | 23 +++------- stellar_sdk/utils.py | 4 +- tests/test_fee_bump_transaction.py | 2 +- tests/test_operation.py | 62 +++++++------------------- tests/test_server.py | 2 - tests/test_transaction.py | 4 +- tests/test_utils.py | 4 +- 15 files changed, 41 insertions(+), 101 deletions(-) diff --git a/stellar_sdk/exceptions.py b/stellar_sdk/exceptions.py index ed609759..62240a49 100644 --- a/stellar_sdk/exceptions.py +++ b/stellar_sdk/exceptions.py @@ -29,7 +29,7 @@ "BadResponseError", "UnknownRequestError", "NotPageableError", - "StreamClientError" + "StreamClientError", ] diff --git a/stellar_sdk/fee_bump_transaction.py b/stellar_sdk/fee_bump_transaction.py index e79db376..aa29fbc6 100644 --- a/stellar_sdk/fee_bump_transaction.py +++ b/stellar_sdk/fee_bump_transaction.py @@ -82,9 +82,7 @@ def from_xdr_object( :return: A new :class:`FeeBumpTransaction` object from the given XDR Transaction object. """ - source = StrKey.encode_ed25519_public_key( - tx_xdr_object.feeSource.ed25519 - ) + source = StrKey.encode_ed25519_public_key(tx_xdr_object.feeSource.ed25519) inner_transaction_envelope = TransactionEnvelope.from_xdr_object( tx_xdr_object.innerTx, network_passphrase ) diff --git a/stellar_sdk/operation/account_merge.py b/stellar_sdk/operation/account_merge.py index aec8c003..87233d62 100644 --- a/stellar_sdk/operation/account_merge.py +++ b/stellar_sdk/operation/account_merge.py @@ -19,11 +19,7 @@ class AccountMerge(Operation): """ - def __init__( - self, - destination: str, - source: str = None, - ) -> None: + def __init__(self, destination: str, source: str = None,) -> None: super().__init__(source) check_ed25519_public_key(destination) self.destination: str = destination diff --git a/stellar_sdk/operation/change_trust.py b/stellar_sdk/operation/change_trust.py index 7f14b674..9e6e36be 100644 --- a/stellar_sdk/operation/change_trust.py +++ b/stellar_sdk/operation/change_trust.py @@ -27,10 +27,7 @@ class ChangeTrust(Operation): _DEFAULT_LIMIT = "922337203685.4775807" def __init__( - self, - asset: Asset, - limit: Union[str, Decimal] = None, - source: str = None, + self, asset: Asset, limit: Union[str, Decimal] = None, source: str = None, ) -> None: super().__init__(source) self.asset: Asset = asset diff --git a/stellar_sdk/operation/manage_data.py b/stellar_sdk/operation/manage_data.py index ae4e9de5..13aa7656 100644 --- a/stellar_sdk/operation/manage_data.py +++ b/stellar_sdk/operation/manage_data.py @@ -27,10 +27,7 @@ class ManageData(Operation): """ def __init__( - self, - data_name: str, - data_value: Union[str, bytes, None], - source: str = None, + self, data_name: str, data_value: Union[str, bytes, None], source: str = None, ) -> None: # TODO: bytes only? super().__init__(source) self.data_name: str = data_name diff --git a/stellar_sdk/operation/operation.py b/stellar_sdk/operation/operation.py index e457740d..24efc57f 100644 --- a/stellar_sdk/operation/operation.py +++ b/stellar_sdk/operation/operation.py @@ -142,9 +142,7 @@ def from_xdr_object(cls, operation_xdr_object: Xdr.types.Operation) -> "Operatio ) @staticmethod - def get_source_from_xdr_obj( - xdr_object: Xdr.types.Operation, - ) -> Optional[str]: + def get_source_from_xdr_obj(xdr_object: Xdr.types.Operation,) -> Optional[str]: """Get the source account from account the operation xdr object. :param xdr_object: the operation xdr object. diff --git a/stellar_sdk/operation/utils.py b/stellar_sdk/operation/utils.py index 91b8ffbd..5ae3353b 100644 --- a/stellar_sdk/operation/utils.py +++ b/stellar_sdk/operation/utils.py @@ -19,6 +19,7 @@ def check_source(source: Optional[str]) -> None: def check_ed25519_public_key(public_key: str) -> None: Keypair.from_public_key(public_key) + def check_asset_code(asset_code: str) -> None: Asset.check_if_asset_code_is_valid(asset_code) @@ -47,4 +48,4 @@ def check_amount(amount: Union[str, Decimal]) -> None: raise ValueError( "Value of '{}' must represent a positive number " "and the max valid value is {}.".format(amount, _UPPER_LIMIT) - ) \ No newline at end of file + ) diff --git a/stellar_sdk/server.py b/stellar_sdk/server.py index 371d1517..29357822 100644 --- a/stellar_sdk/server.py +++ b/stellar_sdk/server.py @@ -84,7 +84,9 @@ def __init__( def submit_transaction( self, - transaction_envelope: Union[TransactionEnvelope, FeeBumpTransactionEnvelope, str], + transaction_envelope: Union[ + TransactionEnvelope, FeeBumpTransactionEnvelope, str + ], skip_memo_required_check: bool = False, ) -> Union[Dict[str, Any], Coroutine[Any, Any, Dict[str, Any]]]: """Submits a transaction to the network. @@ -110,7 +112,9 @@ def submit_transaction( def __submit_transaction_sync( self, - transaction_envelope: Union[TransactionEnvelope, FeeBumpTransactionEnvelope, str], + transaction_envelope: Union[ + TransactionEnvelope, FeeBumpTransactionEnvelope, str + ], skip_memo_required_check: bool, ) -> Dict[str, Any]: url = urljoin_with_query(self.horizon_url, "transactions") @@ -126,7 +130,9 @@ def __submit_transaction_sync( async def __submit_transaction_async( self, - transaction_envelope: Union[TransactionEnvelope, FeeBumpTransactionEnvelope, str], + transaction_envelope: Union[ + TransactionEnvelope, FeeBumpTransactionEnvelope, str + ], skip_memo_required_check: bool, ) -> Dict[str, Any]: url = urljoin_with_query(self.horizon_url, "transactions") diff --git a/stellar_sdk/transaction_builder.py b/stellar_sdk/transaction_builder.py index 9e5e9729..015df0c5 100644 --- a/stellar_sdk/transaction_builder.py +++ b/stellar_sdk/transaction_builder.py @@ -596,10 +596,7 @@ def append_ed25519_public_key_signer( return self.append_set_options_op(signer=signer, source=source) def append_hashx_signer( - self, - sha256_hash: [bytes, str], - weight: int, - source: str = None, + self, sha256_hash: [bytes, str], weight: int, source: str = None, ) -> "TransactionBuilder": """Add a sha256 hash(HashX) signer to an account. @@ -621,10 +618,7 @@ def append_hashx_signer( return self.append_set_options_op(signer=signer, source=source) def append_pre_auth_tx_signer( - self, - pre_auth_tx_hash: bytes, - weight: int, - source: str = None, + self, pre_auth_tx_hash: bytes, weight: int, source: str = None, ) -> "TransactionBuilder": """Add a PreAuthTx signer to an account. @@ -771,9 +765,7 @@ def append_create_passive_sell_offer_op( return self.append_operation(op) def append_account_merge_op( - self, - destination: str, - source: str = None, + self, destination: str, source: str = None, ) -> "TransactionBuilder": """Append a :class:`AccountMerge ` operation to the list of @@ -789,9 +781,7 @@ def append_account_merge_op( op = AccountMerge(destination, source) return self.append_operation(op) - def append_inflation_op( - self, source: str = None - ) -> "TransactionBuilder": + def append_inflation_op(self, source: str = None) -> "TransactionBuilder": """Append a :class:`Inflation ` operation to the list of operations. @@ -805,10 +795,7 @@ def append_inflation_op( return self.append_operation(op) def append_manage_data_op( - self, - data_name: str, - data_value: Union[str, bytes, None], - source: str = None, + self, data_name: str, data_value: Union[str, bytes, None], source: str = None, ) -> "TransactionBuilder": """Append a :class:`ManageData ` operation to the list of operations. diff --git a/stellar_sdk/utils.py b/stellar_sdk/utils.py index 9eb60f6e..799bde2a 100644 --- a/stellar_sdk/utils.py +++ b/stellar_sdk/utils.py @@ -6,8 +6,7 @@ from .asset import Asset from .exceptions import NoApproximationError, TypeError -from .strkey import decode_check, StrKey -from .xdr import Xdr +from .strkey import StrKey MUXED_ACCOUNT_STARTING_LETTER: str = "M" ED25519_PUBLIC_KEY_STARTING_LETTER: str = "G" @@ -87,6 +86,5 @@ def urljoin_with_query(base: str, path: str) -> str: return url - def check_ed25519_public_key(public_key: str) -> None: StrKey.decode_ed25519_public_key(public_key) diff --git a/tests/test_fee_bump_transaction.py b/tests/test_fee_bump_transaction.py index fd9406bb..e92fbc2f 100644 --- a/tests/test_fee_bump_transaction.py +++ b/tests/test_fee_bump_transaction.py @@ -6,7 +6,7 @@ Network, Keypair, FeeBumpTransactionEnvelope, - FeeBumpTransaction + FeeBumpTransaction, ) from stellar_sdk.exceptions import ValueError diff --git a/tests/test_operation.py b/tests/test_operation.py index 4920ca61..fba4300c 100644 --- a/tests/test_operation.py +++ b/tests/test_operation.py @@ -163,9 +163,7 @@ def test_from_xdr_obj(self): origin_xdr_obj = origin_op.to_xdr_object() op = Operation.from_xdr_object(origin_xdr_obj) - assert ( - op.source == source - ) + assert op.source == source assert op.starting_balance == "1000" assert op.destination == destination @@ -187,9 +185,7 @@ def test_from_xdr_obj(self): origin_xdr_obj = BumpSequence(bump_to, source).to_xdr_object() op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, BumpSequence) - assert ( - op.source == source - ) + assert op.source == source assert op.bump_to == bump_to @@ -207,9 +203,7 @@ def test_from_xdr_obj(self): origin_xdr_obj = Inflation(source).to_xdr_object() op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, Inflation) - assert ( - op.source == source - ) + assert op.source == source class TestAccountMerge: @@ -228,13 +222,10 @@ def test_from_xdr_obj(self): origin_xdr_obj = AccountMerge(destination, source).to_xdr_object() op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, AccountMerge) - assert ( - op.source == source - ) + assert op.source == source assert op.destination == destination - class TestChangeTrust: @pytest.mark.parametrize( "limit, xdr", @@ -270,9 +261,7 @@ def test_from_xdr_obj(self): origin_xdr_obj = ChangeTrust(asset, limit, source).to_xdr_object() op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, ChangeTrust) - assert ( - op.source == source - ) + assert op.source == source assert op.limit == limit assert op.asset == asset @@ -313,15 +302,12 @@ def test_from_xdr_obj(self): origin_xdr_obj = Payment(destination, asset, amount, source).to_xdr_object() op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, Payment) - assert ( - op.source == source - ) + assert op.source == source assert op.destination == destination assert op.amount == "1000" assert op.asset == asset - class TestPathPayment: def test_to_xdr_obj(self): source = "GDL635DMMORJHKEHHQIIB4VPYM6YGEMPLORYHHM2DEHAUOUXLSTMHQDV" @@ -390,9 +376,7 @@ def test_from_xdr_obj(self): ).to_xdr_object() op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, PathPaymentStrictReceive) - assert ( - op.source == source - ) + assert op.source == source assert op.destination == destination assert op.send_asset == send_asset assert op.dest_asset == dest_asset @@ -465,9 +449,7 @@ def test_from_xdr_obj(self): ).to_xdr_object() op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, PathPaymentStrictReceive) - assert ( - op.source == source - ) + assert op.source == source assert op.destination == destination assert op.send_asset == send_asset assert op.dest_asset == dest_asset @@ -540,9 +522,7 @@ def test_from_xdr_obj(self): ).to_xdr_object() op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, PathPaymentStrictSend) - assert ( - op.source == source - ) + assert op.source == source assert op.destination == destination assert op.send_asset == send_asset assert op.dest_asset == dest_asset @@ -601,9 +581,7 @@ def test_from_xdr_obj(self, asset_code, authorize): ).to_xdr_object() op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, AllowTrust) - assert ( - op.source == source - ) + assert op.source == source assert op.trustor == trustor assert op.asset_code == asset_code assert op.authorize == authorize @@ -665,9 +643,7 @@ def test_from_xdr_obj(self, name, value): origin_xdr_obj = ManageData(name, value, source).to_xdr_object() op = Operation.from_xdr_object(origin_xdr_obj) assert isinstance(op, ManageData) - assert ( - op.source == source - ) + assert op.source == source assert op.data_name == name if isinstance(value, str): value = value.encode() @@ -783,9 +759,7 @@ def test_to_xdr( assert xdr_obj.to_xdr() == xdr from_instance = Operation.from_xdr_object(xdr_obj) assert isinstance(from_instance, SetOptions) - assert ( - from_instance.source == source - ) + assert from_instance.source == source assert from_instance.clear_flags == clear_flags assert from_instance.set_flags == set_flags assert from_instance.master_weight == master_weight @@ -845,9 +819,7 @@ def test_to_xdr(self, selling, buying, amount, price, offer_id, source, xdr): assert xdr_obj.to_xdr() == xdr from_instance = Operation.from_xdr_object(xdr_obj) assert isinstance(from_instance, ManageSellOffer) - assert ( - from_instance.source == source - ) + assert from_instance.source == source assert from_instance.buying == buying assert from_instance.selling == selling assert from_instance.amount == amount @@ -906,9 +878,7 @@ def test_to_xdr(self, selling, buying, amount, price, offer_id, source, xdr): assert xdr_obj.to_xdr() == xdr from_instance = Operation.from_xdr_object(xdr_obj) assert isinstance(from_instance, ManageBuyOffer) - assert ( - from_instance.source == source - ) + assert from_instance.source == source assert from_instance.buying == buying assert from_instance.selling == selling assert from_instance.amount == amount @@ -964,9 +934,7 @@ def test_to_xdr(self, selling, buying, amount, price, source, xdr): assert xdr_obj.to_xdr() == xdr from_instance = Operation.from_xdr_object(xdr_obj) assert isinstance(from_instance, CreatePassiveSellOffer) - assert ( - from_instance.source == source - ) + assert from_instance.source == source assert from_instance.buying == buying assert from_instance.selling == selling assert Decimal(from_instance.amount) == Decimal(amount) diff --git a/tests/test_server.py b/tests/test_server.py index 49788f9c..b8754493 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -43,7 +43,6 @@ def test_load_acount_sync(self): assert isinstance(account.sequence, int) assert account.thresholds == Thresholds(1, 2, 3) - @pytest.mark.asyncio async def test_load_acount_async(self): account_id = "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D" @@ -55,7 +54,6 @@ async def test_load_acount_async(self): assert isinstance(account.sequence, int) assert account.thresholds == Thresholds(1, 2, 3) - def test_fetch_base_fee_sync(self): horizon_url = "https://horizon.stellar.org" with Server(horizon_url) as server: diff --git a/tests/test_transaction.py b/tests/test_transaction.py index da27167a..d363459c 100644 --- a/tests/test_transaction.py +++ b/tests/test_transaction.py @@ -28,9 +28,7 @@ def test_to_xdr_v1(self): restore_transaction = Transaction.from_xdr_object(tx_object, v1=True) assert isinstance(restore_transaction, Transaction) - assert restore_transaction.source == Keypair.from_public_key( - source.public_key - ) + assert restore_transaction.source == Keypair.from_public_key(source.public_key) assert restore_transaction.fee == fee assert restore_transaction.memo == memo assert restore_transaction.time_bounds == time_bounds diff --git a/tests/test_utils.py b/tests/test_utils.py index cdedc81d..d0fed421 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -4,8 +4,7 @@ from stellar_sdk.utils import ( best_rational_approximation, hex_to_bytes, - urljoin_with_query, - parse_ed25519_account_id, + urljoin_with_query ) @@ -125,4 +124,3 @@ def test_hex_to_bytes_type_raise(self, input_value): ) def test_urljoin_with_query(self, base, path, output): assert output == urljoin_with_query(base, path) - From 924cf8029f82254c28d83d490bf8ea4d03c6dc9e Mon Sep 17 00:00:00 2001 From: overcat <4catcode@gmail.com> Date: Sat, 23 May 2020 16:17:25 +0800 Subject: [PATCH 6/8] code clean --- stellar_sdk/utils.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/stellar_sdk/utils.py b/stellar_sdk/utils.py index 799bde2a..227e4560 100644 --- a/stellar_sdk/utils.py +++ b/stellar_sdk/utils.py @@ -6,7 +6,6 @@ from .asset import Asset from .exceptions import NoApproximationError, TypeError -from .strkey import StrKey MUXED_ACCOUNT_STARTING_LETTER: str = "M" ED25519_PUBLIC_KEY_STARTING_LETTER: str = "G" @@ -84,7 +83,3 @@ def urljoin_with_query(base: str, path: str) -> str: (split_url.scheme, split_url.netloc, real_path, query, split_url.fragment) ) return url - - -def check_ed25519_public_key(public_key: str) -> None: - StrKey.decode_ed25519_public_key(public_key) From 48c7f068d4eca1be24a5b829ca0409575a8b52c3 Mon Sep 17 00:00:00 2001 From: overcat <4catcode@gmail.com> Date: Sat, 23 May 2020 18:20:22 +0800 Subject: [PATCH 7/8] We will drop the memo id of MuxedAccounts and use G-strkeys when parse XDR --- stellar_sdk/fee_bump_transaction.py | 6 +++-- stellar_sdk/operation/account_merge.py | 5 ++-- stellar_sdk/operation/operation.py | 6 +++-- .../operation/path_payment_strict_receive.py | 7 ++--- .../operation/path_payment_strict_send.py | 7 ++--- stellar_sdk/operation/payment.py | 6 ++--- stellar_sdk/transaction.py | 10 ++++--- stellar_sdk/utils.py | 10 +++++++ tests/test_utils.py | 27 ++++++++++++++++++- 9 files changed, 65 insertions(+), 19 deletions(-) diff --git a/stellar_sdk/fee_bump_transaction.py b/stellar_sdk/fee_bump_transaction.py index aa29fbc6..4d037c2b 100644 --- a/stellar_sdk/fee_bump_transaction.py +++ b/stellar_sdk/fee_bump_transaction.py @@ -2,9 +2,9 @@ from .exceptions import ValueError from .keypair import Keypair -from .strkey import StrKey from .transaction import Transaction from .transaction_envelope import TransactionEnvelope +from .utils import parse_ed25519_account_id_from_muxed_account_xdr_object from .xdr import Xdr BASE_FEE = 100 @@ -82,7 +82,9 @@ def from_xdr_object( :return: A new :class:`FeeBumpTransaction` object from the given XDR Transaction object. """ - source = StrKey.encode_ed25519_public_key(tx_xdr_object.feeSource.ed25519) + source = parse_ed25519_account_id_from_muxed_account_xdr_object( + tx_xdr_object.feeSource + ) inner_transaction_envelope = TransactionEnvelope.from_xdr_object( tx_xdr_object.innerTx, network_passphrase ) diff --git a/stellar_sdk/operation/account_merge.py b/stellar_sdk/operation/account_merge.py index 87233d62..3f978a72 100644 --- a/stellar_sdk/operation/account_merge.py +++ b/stellar_sdk/operation/account_merge.py @@ -1,7 +1,7 @@ from .operation import Operation from .utils import check_ed25519_public_key from ..keypair import Keypair -from ..strkey import StrKey +from ..utils import parse_ed25519_account_id_from_muxed_account_xdr_object from ..xdr import Xdr @@ -43,7 +43,8 @@ def from_xdr_object( """ source = Operation.get_source_from_xdr_obj(operation_xdr_object) - destination = StrKey.encode_ed25519_public_key( + destination = parse_ed25519_account_id_from_muxed_account_xdr_object( operation_xdr_object.body.destination.ed25519 ) + return cls(source=source, destination=destination) diff --git a/stellar_sdk/operation/operation.py b/stellar_sdk/operation/operation.py index 24efc57f..41105606 100644 --- a/stellar_sdk/operation/operation.py +++ b/stellar_sdk/operation/operation.py @@ -6,7 +6,7 @@ from .utils import check_source from ..keypair import Keypair from ..exceptions import ValueError, TypeError -from ..strkey import StrKey +from ..utils import parse_ed25519_account_id_from_muxed_account_xdr_object from ..xdr import Xdr @@ -149,7 +149,9 @@ def get_source_from_xdr_obj(xdr_object: Xdr.types.Operation,) -> Optional[str]: :return: The source account from account the operation xdr object. """ if xdr_object.sourceAccount: - return StrKey.encode_ed25519_public_key(xdr_object.sourceAccount[0].ed25519) + return parse_ed25519_account_id_from_muxed_account_xdr_object( + xdr_object.sourceAccount[0] + ) return None def __eq__(self, other: object) -> bool: diff --git a/stellar_sdk/operation/path_payment_strict_receive.py b/stellar_sdk/operation/path_payment_strict_receive.py index 36e88a20..9ef498c6 100644 --- a/stellar_sdk/operation/path_payment_strict_receive.py +++ b/stellar_sdk/operation/path_payment_strict_receive.py @@ -5,7 +5,7 @@ from .utils import check_amount, check_ed25519_public_key from ..asset import Asset from ..keypair import Keypair -from ..strkey import StrKey +from ..utils import parse_ed25519_account_id_from_muxed_account_xdr_object from ..xdr import Xdr @@ -82,9 +82,10 @@ def from_xdr_object( """ source = Operation.get_source_from_xdr_obj(operation_xdr_object) - destination = StrKey.encode_ed25519_public_key( - operation_xdr_object.body.pathPaymentStrictReceiveOp.destination.ed25519 + destination = parse_ed25519_account_id_from_muxed_account_xdr_object( + operation_xdr_object.body.pathPaymentStrictReceiveOp.destination ) + send_asset = Asset.from_xdr_object( operation_xdr_object.body.pathPaymentStrictReceiveOp.sendAsset ) diff --git a/stellar_sdk/operation/path_payment_strict_send.py b/stellar_sdk/operation/path_payment_strict_send.py index bff17bae..976cc9e4 100644 --- a/stellar_sdk/operation/path_payment_strict_send.py +++ b/stellar_sdk/operation/path_payment_strict_send.py @@ -5,7 +5,7 @@ from .utils import check_amount, check_ed25519_public_key from ..asset import Asset from ..keypair import Keypair -from ..strkey import StrKey +from ..utils import parse_ed25519_account_id_from_muxed_account_xdr_object from ..xdr import Xdr @@ -82,9 +82,10 @@ def from_xdr_object( """ source = Operation.get_source_from_xdr_obj(operation_xdr_object) - destination = StrKey.encode_ed25519_public_key( - operation_xdr_object.body.pathPaymentStrictSendOp.destination.ed25519 + destination = parse_ed25519_account_id_from_muxed_account_xdr_object( + operation_xdr_object.body.pathPaymentStrictSendOp.destination ) + send_asset = Asset.from_xdr_object( operation_xdr_object.body.pathPaymentStrictSendOp.sendAsset ) diff --git a/stellar_sdk/operation/payment.py b/stellar_sdk/operation/payment.py index d6817e1e..8888eb7e 100644 --- a/stellar_sdk/operation/payment.py +++ b/stellar_sdk/operation/payment.py @@ -5,7 +5,7 @@ from .utils import check_amount, check_ed25519_public_key from ..keypair import Keypair from ..asset import Asset -from ..strkey import StrKey +from ..utils import parse_ed25519_account_id_from_muxed_account_xdr_object from ..xdr import Xdr @@ -61,8 +61,8 @@ def from_xdr_object(cls, operation_xdr_object: Xdr.types.Operation) -> "Payment" """ source = Operation.get_source_from_xdr_obj(operation_xdr_object) - destination = StrKey.encode_ed25519_public_key( - operation_xdr_object.body.paymentOp.destination.ed25519 + destination = parse_ed25519_account_id_from_muxed_account_xdr_object( + operation_xdr_object.body.paymentOp.destination ) asset = Asset.from_xdr_object(operation_xdr_object.body.paymentOp.asset) amount = Operation.from_xdr_amount(operation_xdr_object.body.paymentOp.amount) diff --git a/stellar_sdk/transaction.py b/stellar_sdk/transaction.py index b44ab265..df6c09b3 100644 --- a/stellar_sdk/transaction.py +++ b/stellar_sdk/transaction.py @@ -5,7 +5,11 @@ from .operation.operation import Operation from .strkey import StrKey from .time_bounds import TimeBounds -from .utils import pack_xdr_array, unpack_xdr_array +from .utils import ( + pack_xdr_array, + unpack_xdr_array, + parse_ed25519_account_id_from_muxed_account_xdr_object, +) from .xdr import Xdr __all__ = ["Transaction"] @@ -114,8 +118,8 @@ def from_xdr_object( :return: A new :class:`Transaction` object from the given XDR Transaction object. """ if v1: - source = StrKey.encode_ed25519_public_key( - tx_xdr_object.sourceAccount.ed25519 + source = parse_ed25519_account_id_from_muxed_account_xdr_object( + tx_xdr_object.sourceAccount ) else: source = StrKey.encode_ed25519_public_key( diff --git a/stellar_sdk/utils.py b/stellar_sdk/utils.py index 227e4560..30fdecb5 100644 --- a/stellar_sdk/utils.py +++ b/stellar_sdk/utils.py @@ -6,6 +6,8 @@ from .asset import Asset from .exceptions import NoApproximationError, TypeError +from .strkey import StrKey +from .xdr import Xdr MUXED_ACCOUNT_STARTING_LETTER: str = "M" ED25519_PUBLIC_KEY_STARTING_LETTER: str = "G" @@ -83,3 +85,11 @@ def urljoin_with_query(base: str, path: str) -> str: (split_url.scheme, split_url.netloc, real_path, query, split_url.fragment) ) return url + + +def parse_ed25519_account_id_from_muxed_account_xdr_object( + data: Xdr.types.MuxedAccount, +) -> str: + if data.ed25519 is not None: + return StrKey.encode_ed25519_public_key(data.ed25519) + return StrKey.encode_ed25519_public_key(data.med25519.ed25519) diff --git a/tests/test_utils.py b/tests/test_utils.py index d0fed421..7bbf99b5 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,11 +1,14 @@ import pytest from stellar_sdk.exceptions import NoApproximationError, TypeError +from stellar_sdk.strkey import StrKey from stellar_sdk.utils import ( best_rational_approximation, hex_to_bytes, - urljoin_with_query + urljoin_with_query, + parse_ed25519_account_id_from_muxed_account_xdr_object, ) +from stellar_sdk.xdr import Xdr class TestUtils: @@ -124,3 +127,25 @@ def test_hex_to_bytes_type_raise(self, input_value): ) def test_urljoin_with_query(self, base, path, output): assert output == urljoin_with_query(base, path) + + def test_parse_ed25519_account_id_from_muxed_account_xdr_object_ed25519(self): + account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" + muxed = Xdr.types.MuxedAccount( + type=Xdr.const.KEY_TYPE_ED25519, + ed25519=StrKey.decode_ed25519_public_key(account_id), + ) + assert ( + parse_ed25519_account_id_from_muxed_account_xdr_object(muxed) == account_id + ) + + def test_parse_ed25519_account_id_from_muxed_account_xdr_object_muxed_account(self): + account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" + med25519 = Xdr.nullclass() + med25519.ed25519 = StrKey.decode_ed25519_public_key(account_id) + med25519.id = 1234 + muxed = Xdr.types.MuxedAccount( + type=Xdr.const.KEY_TYPE_MUXED_ED25519, med25519=med25519 + ) + assert ( + parse_ed25519_account_id_from_muxed_account_xdr_object(muxed) == account_id + ) From a4d1ba07add8d0d4e3e04802e97f97db17dd5d01 Mon Sep 17 00:00:00 2001 From: overcat <4catcode@gmail.com> Date: Sat, 23 May 2020 18:29:46 +0800 Subject: [PATCH 8/8] fix --- stellar_sdk/operation/account_merge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellar_sdk/operation/account_merge.py b/stellar_sdk/operation/account_merge.py index 3f978a72..c595c1fc 100644 --- a/stellar_sdk/operation/account_merge.py +++ b/stellar_sdk/operation/account_merge.py @@ -44,7 +44,7 @@ def from_xdr_object( """ source = Operation.get_source_from_xdr_obj(operation_xdr_object) destination = parse_ed25519_account_id_from_muxed_account_xdr_object( - operation_xdr_object.body.destination.ed25519 + operation_xdr_object.body.destination ) return cls(source=source, destination=destination)