async def test_check_memo_required_with_fee_bump_transaction_async(
         self, httpserver):
     self.__inject_mock_server(httpserver)
     horizon_url = httpserver.url_for("/")
     keypair = Keypair.from_secret(
         "SDQXFKA32UVQHUTLYJ42N56ZUEM5PNVVI4XE7EA5QFMLA2DHDCQX3GPY")
     account = Account(keypair.public_key, 1)
     async with Server(horizon_url, AiohttpClient()) as server:
         transaction = (TransactionBuilder(
             account, v1=True).append_payment_op(
                 self.DESTINATION_ACCOUNT_MEMO_REQUIRED_A, "10", "PMN"
             ).append_path_payment_strict_send_op(
                 self.DESTINATION_ACCOUNT_MEMO_REQUIRED_C,
                 "PMN",
                 None,
                 "10",
                 "BTC",
                 "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2",
                 "1",
                 [],
             ).append_account_merge_op(
                 self.DESTINATION_ACCOUNT_MEMO_REQUIRED_D).add_text_memo(
                     "hello, world").build())
         transaction.sign(keypair)
         fee_bump_tx = TransactionBuilder.build_fee_bump_transaction(
             fee_source=Keypair.random().public_key,
             base_fee=200,
             inner_transaction_envelope=transaction,
             network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
         )
         await server.submit_transaction(fee_bump_tx)
 async def test_check_memo_required_with_memo_muxed_account_async(
         self, httpserver):
     self.__inject_mock_server(httpserver)
     horizon_url = httpserver.url_for("/")
     keypair = Keypair.from_secret(
         "SDQXFKA32UVQHUTLYJ42N56ZUEM5PNVVI4XE7EA5QFMLA2DHDCQX3GPY")
     account = Account(keypair.public_key, 1)
     async with Server(horizon_url, AiohttpClient()) as server:
         transaction = (TransactionBuilder(account).append_payment_op(
             self.DESTINATION_ACCOUNT_MEMO_REQUIRED_A, "10",
             "PMN").append_path_payment_strict_receive_op(
                 self.DESTINATION_ACCOUNT_MEMO_REQUIRED_B,
                 "PMN",
                 None,
                 "10",
                 "BTC",
                 "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2",
                 "1",
                 [],
             ).append_path_payment_strict_send_op(
                 self.DESTINATION_ACCOUNT_MEMO_REQUIRED_C,
                 "PMN",
                 None,
                 "10",
                 "BTC",
                 "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2",
                 "1",
                 [],
             ).append_account_merge_op(
                 self.DESTINATION_ACCOUNT_MEMO_REQUIRED_D).add_text_memo(
                     "hello, world").build())
         transaction.sign(keypair)
         await server.submit_transaction(transaction)
 async def test_check_memo_required_with_fetch_account_error_raise_async(
         self, httpserver):
     self.__inject_mock_server(httpserver)
     horizon_url = httpserver.url_for("/")
     keypair = Keypair.from_secret(
         "SDQXFKA32UVQHUTLYJ42N56ZUEM5PNVVI4XE7EA5QFMLA2DHDCQX3GPY")
     account = Account(keypair.public_key, 1)
     async with Server(horizon_url, AiohttpClient()) as server:
         transaction = (TransactionBuilder(account).append_payment_op(
             self.DESTINATION_ACCOUNT_FETCH_ERROR, "10",
             "PMN").append_path_payment_strict_receive_op(
                 self.DESTINATION_ACCOUNT_NO_MEMO_REQUIRED,
                 "PMN",
                 None,
                 "10",
                 "BTC",
                 "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2",
                 "1",
                 [],
             ).append_path_payment_strict_send_op(
                 self.DESTINATION_ACCOUNT_NO_MEMO_REQUIRED,
                 "PMN",
                 None,
                 "10",
                 "BTC",
                 "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2",
                 "1",
                 [],
             ).append_account_merge_op(
                 self.DESTINATION_ACCOUNT_NO_MEMO_REQUIRED).build())
         transaction.sign(keypair)
         with pytest.raises(BadRequestError) as err:
             await server.submit_transaction(transaction)
         assert err.value.status == 400
 async def test_check_memo_required_with_no_destination_operation_async(
         self, httpserver):
     self.__inject_mock_server(httpserver)
     horizon_url = httpserver.url_for("/")
     keypair = Keypair.from_secret(
         "SDQXFKA32UVQHUTLYJ42N56ZUEM5PNVVI4XE7EA5QFMLA2DHDCQX3GPY")
     account = Account(keypair.public_key, 1)
     async with Server(horizon_url, AiohttpClient()) as server:
         transaction = (TransactionBuilder(account).append_manage_data_op(
             "Hello", "world").build())
         transaction.sign(keypair)
         await server.submit_transaction(transaction)
Ejemplo n.º 5
0
async def main():
    # Configure KuknosSdk to talk to the horizon instance hosted by Kuknos.org
    # To use the live network, set the hostname to 'horizon.kuknos.org'
    # When we use the `with` syntax, it automatically releases the resources it occupies.
    async with Server(
            horizon_url="https://hz1-test.kuknos.org", client=AiohttpClient()
    ) as server:
        # Transactions require a valid sequence number that is specific to this account.
        # We can fetch the current sequence number for the source account from Horizon.
        source_account = await server.load_account(source_public_key)

        base_fee = await server.fetch_base_fee()
        # we are going to submit the transaction to the test network,
        # so network_passphrase is `Network.TESTNET_NETWORK_PASSPHRASE`,
        # if you want to submit to the public network, please use `Network.PUBLIC_NETWORK_PASSPHRASE`.
        transaction = (
            TransactionBuilder(
                source_account=source_account,
                network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
                base_fee=base_fee,
            )
                .add_text_memo("Hello, Kuknos!")  # Add a memo
                # Add a payment operation to the transaction
                # Send 350.1234567 PMN to receiver
                # Specify 350.1234567 paymons. Paymons are divisible to seven digits past the decimal.
                .append_payment_op(receiver_public_key, "350.1234567", "PMN")
                .set_timeout(30)  # Make this transaction valid for the next 30 seconds only
                .build()
        )

        # Sign this transaction with the secret key
        # NOTE: signing is transaction is network specific. Test network transactions
        # won't work in the public network. To switch networks, use the Network object
        # as explained above (look for kuknos_sdk.network.Network).
        transaction.sign(source_keypair)

        # Let's see the XDR (encoded in base64) of the transaction we just built
        print(transaction.to_xdr())

        # Submit the transaction to the Horizon server.
        # The Horizon server will then submit the transaction into the network for us.
        response = await server.submit_transaction(transaction)
        print(response)
 async def test_check_memo_required_with_two_operation_with_same_destination_async(
         self, httpserver):
     self.__inject_mock_server(httpserver)
     horizon_url = httpserver.url_for("/")
     keypair = Keypair.from_secret(
         "SDQXFKA32UVQHUTLYJ42N56ZUEM5PNVVI4XE7EA5QFMLA2DHDCQX3GPY")
     account = Account(keypair.public_key, 1)
     async with Server(horizon_url, AiohttpClient()) as server:
         transaction = (TransactionBuilder(account).append_payment_op(
             self.DESTINATION_ACCOUNT_NO_MEMO_REQUIRED, "10",
             "PMN").append_path_payment_strict_receive_op(
                 self.DESTINATION_ACCOUNT_NO_MEMO_REQUIRED,
                 "PMN",
                 None,
                 "10",
                 "BTC",
                 "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2",
                 "1",
                 [],
             ).append_path_payment_strict_send_op(
                 self.DESTINATION_ACCOUNT_NO_MEMO_REQUIRED,
                 "PMN",
                 None,
                 "10",
                 "BTC",
                 "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2",
                 "1",
                 [],
             ).append_account_merge_op(
                 self.DESTINATION_ACCOUNT_MEMO_REQUIRED_D).build())
         transaction.sign(keypair)
         with pytest.raises(
                 AccountRequiresMemoError,
                 match=
                 "Destination account requires a memo in the transaction.",
         ) as err:
             await server.submit_transaction(transaction)
         assert err.value.account_id == self.DESTINATION_ACCOUNT_MEMO_REQUIRED_D
         assert err.value.operation_index == 3
async def payments():
    async with Server(HORIZON_URL, AiohttpClient()) as server:
        async for payment in server.payments().cursor(cursor="now").stream():
            print(f"Payment: {payment}")
async def transactions():
    async with Server(HORIZON_URL, AiohttpClient()) as server:
        async for transaction in server.transactions().cursor(
                cursor="now").stream():
            print(f"Transaction: {transaction}")
async def operations():
    async with Server(HORIZON_URL, AiohttpClient()) as server:
        async for operation in server.operations().cursor(
                cursor="now").stream():
            print(f"Operation: {operation}")
async def effects():
    async with Server(HORIZON_URL, AiohttpClient()) as server:
        async for effect in server.effects().cursor(cursor="now").stream():
            print(f"Effect: {effect}")