Skip to content

Releases: StellarCN/py-stellar-base

2.4.2-alpha2

18 May 11:59
Compare
Choose a tag to compare
2.4.2-alpha2 Pre-release
Pre-release
  • fix: monkey patch aiohttp.streams.StreamReader.readline to solve the problem that aiohttp_sse_client cannot read long stream messages.

View at: https://pypi.org/project/stellar-sdk/2.4.2a2/

2.4.2-alpha1

17 May 14:43
Compare
Choose a tag to compare
2.4.2-alpha1 Pre-release
Pre-release
  • refactor: separating client GET and POST timeout values. (#315)

  • refactor: optimize the use of stellar_sdk.client.AiohttpClient, it may throw a stellar_sdk.exceptions.StreamClientError exception now, and you should catch it. (#317)

    import asyncio
    import logging
    
    from stellar_sdk import AiohttpClient, Server
    from stellar_sdk.exceptions import StreamClientError
    
    horizon_url = "https://horizon-testnet.stellar.org"
    
    async def listen_transactions():
        async with Server(horizon_url, AiohttpClient()) as server:
            cursor = "now"
            while True:
                try:
                    async for transaction in server.transactions().cursor(cursor).stream():
                        print(f"Transaction: {transaction}")
                except StreamClientError as e:
                    logging.error(f'A StreamClientError was encountered while reading the SSE message, which was caused by {e.current_cursor}.')
                    cursor = e.current_cursor
    
    
    if __name__ == '__main__':
        asyncio.run(listen_transactions())

View at: https://pypi.org/project/stellar-sdk/2.4.2a1/

3.0.0-alpha1

10 May 03:36
5fa4da7
Compare
Choose a tag to compare
3.0.0-alpha1 Pre-release
Pre-release

This update include breaking changes.

This version brings new XDR code generated by the new XDR generator, full type hint support for the Horizon response and lots of code optimization.

Added

  • New XDR code generated by the new XDR generator. (See XDR)
  • Full type hint support for the Horizon response.
  • Add stellar_sdk.response.WrappedResponse which makes it easy to use Horizon response.

Update

  • Lots of code optimization.

Breaking changes

  • The way to get horizon response has changed.

    # In v2.x
    from stellar_sdk import Server
    
    server = Server(horizon_url="https://horizon.stellar.org")
    
    # get a list of transactions that occurred in ledger 29576671
    transactions = server.transactions().for_ledger(29576671).call()
    print(transactions)  # get raw data
    
    # In v3.x
    from stellar_sdk import Server
    
    server = Server(horizon_url="https://horizon.stellar.org")
    
    # get a list of transactions that occurred in ledger 29576671
    transactions = server.transactions().for_ledger(29576671).call()
    # You can use raw data or parsed data to get a better development experience.
    # print(transactions.raw_data)
    print(transactions.parse_data())
    
  • The old XDR code has been deprecated, please use new XDR code now.

    # parse XDR in v3.x
    from stellar_sdk import xdr
    result_xdr = "AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAA="
    parsed_result = xdr.TransactionResult.from_xdr(result_xdr)
    print(parsed_result.result.code)
    
  • stellar_sdk.TransactionBuilder.network_id, stellar_sdk.TransactionEnvelope.network_id and stellar_sdk.FeeBumpTransactionEnvelope.network_id fields have been removed, use stellar_sdk.TransactionBuilder.network_passphrase, stellar_sdk.TransactionEnvelope.network_passphrase and stellar_sdk.FeeBumpTransactionEnvelope.network_passphrase instead.

  • stellar_sdk.operation.Operation.type_code() has been removed, use stellar_sdk.operation.Operation.TYPE_CODE instead.

  • stellar_sdk.operation.set_options.Flag has been removed, use stellar_sdk.operation.set_options.AuthorizationFlag instead.

  • stellar_sdk.call_builder.CallBuilder.prev() and stellar_sdk.call_builder.CallBuilder.next() has been removed, use stellar_sdk.response.WrappedResponse.prev() and stellar_sdk.response.WrappedResponse.next() instead.

2.4.1

10 May 11:12
b452f0f
Compare
Choose a tag to compare
  • fix type hint for stellar_sdk.Server.submit_transaction().
  • fix broken links in examples.

2.4.0

05 May 14:03
66254b0
Compare
Choose a tag to compare

This update include breaking changes.

This version brings protocol 13 support with backwards compatibility support for protocol 12.

Added

  • Add stellar_sdk.MuxedAccount which makes it easy to use muxed account. (#311).
  • Add TransactionBuilder.build_fee_bump_transaction which makes it easy to create FeeBumpTransaction, we have written an example, please click here to view it (#298).
  • Adds a feature flag which allow consumers of this library to create V1 (Protocol 13) transactions using the TransactionBuilder (#298).
  • Add support for CAP-0027: First-class multiplexed accounts (#300).
  • Add Keypair.xdr_muxed_account which creates a new MuxedAccount(#300).
  • Add FeeBumpTransaction and FeeBumpTransactionEnvelope which makes it easy to work with fee bump transactions (#298).
  • Add stellar_sdk.helpers.parse_transaction_envelope_from_xdr which makes it easy to parse TransactionEnvelope and FeeBumpTransactionEnvelope(#298).

Update

  • Update XDR definitions with protocol 13.
  • Extend TransactionEnvelope to work with TransactionEnvelopeand FeeBumpTransactionEnvelope (#298).
  • Add backward compatibility support for CAP-0018 (#307).

Breaking changes

  • The following fields, which were previously an str are now a stellar_sdk.MuxedAccount (#311):

    • stellar_sdk.Account.account_id
    • stellar_sdk.Transaction.source
    • stellar_sdk.FeeBumpTransaction.fee_source
    • stellar_sdk.operation.Operation.source
    • stellar_sdk.operation.AccountMerge.destination
    • stellar_sdk.operation.PathPaymentStrictReceive.destination
    • stellar_sdk.operation.PathPaymentStrictSend.destination
    • stellar_sdk.operation.PathPayment.destination
    • stellar_sdk.operation.Payment.destination
  • In this version, some changes have occurred in the XDR files. If you relay on them, please click here to view the changes.

Example

Some examples let you quickly learn about these changes.

  1. MuxedAccount

    from stellar_sdk import MuxedAccount
    
    account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY"
    account_id_id = 1234
    account_id_muxed = "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY"
    
    # generate account_id_muxed
    muxed = MuxedAccount(account_id=account_id, account_id_id=account_id_id)  # account_id_id is optional.
    print(f"account_id_muxed: {muxed.account_id_muxed}")
    
    # parse account_id_muxed
    muxed = MuxedAccount.from_account(account_id_muxed)
    print(f"account_id: {muxed.account_id}\naccount_id_id: {muxed.account_id_id}")
    
    # without `account_id_id`
    muxed = MuxedAccount.from_account(account_id)
    print(f"account_id_muxed: {muxed.account_id_muxed}")  # None
  2. Pay to muxed account

    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) 
  3. Build fee bump transaction

    import pprint
    
    from stellar_sdk import Keypair, Server, TransactionBuilder, Network
    from stellar_sdk.exceptions import BadRequestError
    
    horizon_url = "https://horizon-testnet.stellar.org/"
    network_passphrase = Network.TESTNET_NETWORK_PASSPHRASE
    
    fee_source_keypair = Keypair.from_secret("SASZKBDB6PFHXN6LRH4NQNTRGLGDTI3PSUVIKMZMLTYYBB7NDVMA6DSL")
    inner_source_keypair = Keypair.from_secret("SC5O7VZUXDJ6JBDSZ74DSERXL7W3Y5LTOAMRF7RQRL3TAGAPS7LUVG3L")
    destination_address = "GBVKI23OQZCANDUZ2SI7XU7W6ICYKYT74JBXDD2CYRDAFZHZNRPASSQK"
    
    server = Server(horizon_url=horizon_url)
    inner_account = server.load_account(inner_source_keypair)
    
    inner_tx = TransactionBuilder(
        source_account=inner_account,
        network_passphrase=network_passphrase,
        base_fee=50,
        v1=True) \
        .append_payment_op(destination=destination_address, amount="100", asset_code="XLM") \
        .build()
    
    inner_tx.sign(inner_source_keypair)
    
    try:
        # This transaction will fail.
        tx_insufficient_fee_resp = server.submit_transaction(inner_tx)
    except BadRequestError as e:
        print(e)
    
    fee_bump_tx = TransactionBuilder.build_fee_bump_transaction(
        fee_source=fee_source_keypair,
        base_fee=200,
        inner_transaction_envelope=inner_tx, network_passphrase=network_passphrase
    )
    fee_bump_tx.sign(fee_source_keypair)
    response = server.submit_transaction(fee_bump_tx)
    pprint.pprint(response)

2.4.0-alpha2

03 May 01:51
1c1ea5a
Compare
Choose a tag to compare
2.4.0-alpha2 Pre-release
Pre-release

Added

  • Add stellar_sdk.MuxedAccount which makes it easy to use muxed account. (#311).

Breaking changes

  • The following fields, which were previously an str are now a stellar_sdk.MuxedAccount (#311):

    • stellar_sdk.Account.account_id
    • stellar_sdk.Transaction.source
    • stellar_sdk.FeeBumpTransaction.fee_source
    • stellar_sdk.operation.Operation.source
    • stellar_sdk.operation.AccountMerge.destination
    • stellar_sdk.operation.AllowTrust.destination
    • stellar_sdk.operation.PathPaymentStrictReceive.destination
    • stellar_sdk.operation.PathPaymentStrictSend.destination
    • stellar_sdk.operation.PathPayment.destination
    • stellar_sdk.operation.Payment.destination

2.3.2

01 May 15:32
af3ee5d
Compare
Choose a tag to compare
  • fix: typo in fetching previous page.(#312)

2.4.0-alpha1

26 Apr 12:15
c947839
Compare
Choose a tag to compare
2.4.0-alpha1 Pre-release
Pre-release

This update include breaking changes.

This version brings protocol 13 support with backwards compatibility support for protocol 12.

If you want to help us test this alpha version, you can install it by running pip install stellar-sdk==2.4.0a1, please do not use this alpha version in production.

Added

  • Add TransactionBuilder.build_fee_bump_transaction which makes it easy to create FeeBumpTransaction, we have written an example, please click here to view it (#298).
  • Adds a feature flag which allow consumers of this library to create V1 (Protocol 13) transactions using the TransactionBuilder (#298).
  • Add support for CAP-0027: First-class multiplexed accounts (#300).
  • Add Keypair.xdr_muxed_account which creates a new MuxedAccount(#300).
  • Add FeeBumpTransaction and FeeBumpTransactionEnvelope which makes it easy to work with fee bump transactions (#298).
  • Add stellar_sdk.helpers.parse_transaction_envelope_from_xdr which makes it easy to parse TransactionEnvelope and FeeBumpTransactionEnvelope(#298).

Update

  • Update XDR definitions with protocol 13.
  • Extend TransactionEnvelope to work with TransactionEnvelopeand FeeBumpTransactionEnvelope (#298).
  • Add backward compatibility support for CAP-0018 (#307).

Breaking changes

  • The type of Transaction.source changes from Keypair to str.

  • In this version, some changes have occurred in the XDR files. If you depend on them, please click here to view the changes.

  • The following XDR fields, which were previously an AccountID are now a MuxedAccount (#300):

    • PaymentOp.destination
    • PathPaymentStrictReceiveOp.destination
    • PathPaymentStrictSendOp.destination
    • OperationOp.source
    • Operation.destination (for ACCOUNT_MERGE)
    • Transaction.source
    • FeeBumpTransaction.feeSource

    You can get the string representation by calling StrKey.encode_muxed_account which will return a G.. or M.. account.

2.3.1

12 Apr 07:41
519ccbb
Compare
Choose a tag to compare
  • Update dependencies.

2.3.0

31 Mar 14:05
f409fa8
Compare
Choose a tag to compare

Added

  • Add SEP-0029 (memo required) support. (#291)
    Extends Server.submit_transaction to always run a memo required check before
    sending the transaction. If any of the destinations require a memo and the
    transaction doesn't include one, then an AccountRequiresMemoError will be thrown.

    This may degrade performance, but you can skip this check by passing skip_memo_required_check=True to Server.submit_transaction:

    server.submit_transaction(tx, skip_memo_required_check=True)
    

    The check runs for each operation of type:

    • Payment
    • PathPaymentStrictReceive
    • PathPaymentStrictSend
    • AccountMerge

    If the transaction includes a memo, then memo required checking is skipped.

    See SEP-0029 for more information about memo required check.

Changed

  • Optimize the processing of horizon parameters. (#289)

View at: https://pypi.org/project/stellar-sdk/2.3.0/