def test_check_memo_required_with_fee_bump_transaction_sync(
         self, httpserver):
     self.__inject_mock_server(httpserver)
     horizon_url = httpserver.url_for("/")
     server = Server(horizon_url)
     keypair = Keypair.from_secret(
         "SDQXFKA32UVQHUTLYJ42N56ZUEM5PNVVI4XE7EA5QFMLA2DHDCQX3GPY")
     account = Account(keypair.public_key, 1)
     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,
     )
     server.submit_transaction(fee_bump_tx)
 def test_check_memo_required_with_fetch_account_error_raise_sync(
         self, httpserver):
     self.__inject_mock_server(httpserver)
     horizon_url = httpserver.url_for("/")
     server = Server(horizon_url)
     keypair = Keypair.from_secret(
         "SDQXFKA32UVQHUTLYJ42N56ZUEM5PNVVI4XE7EA5QFMLA2DHDCQX3GPY")
     account = Account(keypair.public_key, 1)
     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:
         server.submit_transaction(transaction)
     assert err.value.status == 400
 def test_check_memo_required_with_memo_muxed_account_sync(
         self, httpserver):
     self.__inject_mock_server(httpserver)
     horizon_url = httpserver.url_for("/")
     server = Server(horizon_url)
     keypair = Keypair.from_secret(
         "SDQXFKA32UVQHUTLYJ42N56ZUEM5PNVVI4XE7EA5QFMLA2DHDCQX3GPY")
     account = Account(keypair.public_key, 1)
     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)
     server.submit_transaction(transaction)
 def test_check_memo_required_with_no_destination_operation_sync(
         self, httpserver):
     self.__inject_mock_server(httpserver)
     horizon_url = httpserver.url_for("/")
     server = Server(horizon_url)
     keypair = Keypair.from_secret(
         "SDQXFKA32UVQHUTLYJ42N56ZUEM5PNVVI4XE7EA5QFMLA2DHDCQX3GPY")
     account = Account(keypair.public_key, 1)
     transaction = (TransactionBuilder(account).append_manage_data_op(
         "Hello", "world").build())
     transaction.sign(keypair)
     server.submit_transaction(transaction)
 def test_check_memo_required_with_two_operation_with_same_destination_sync(
         self, httpserver):
     self.__inject_mock_server(httpserver)
     horizon_url = httpserver.url_for("/")
     server = Server(horizon_url)
     keypair = Keypair.from_secret(
         "SDQXFKA32UVQHUTLYJ42N56ZUEM5PNVVI4XE7EA5QFMLA2DHDCQX3GPY")
     account = Account(keypair.public_key, 1)
     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:
         server.submit_transaction(transaction)
     assert err.value.account_id == self.DESTINATION_ACCOUNT_MEMO_REQUIRED_D
     assert err.value.operation_index == 3
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="PMN").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)
예제 #7
0
from kuknos_sdk import TransactionBuilder, Server, Network, Keypair

server = Server(horizon_url="https://hz1-test.kuknos.org")
source = Keypair.from_secret("SBFZCHU5645DOKRWYBXVOXY2ELGJKFRX6VGGPRYUWHQ7PMXXJNDZFMKD")
destination = Keypair.random()

source_account = server.load_account(account_id=source.public_key)
transaction = TransactionBuilder(
    source_account=source_account,
    network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
    base_fee=100) \
    .append_create_account_op(destination=destination.public_key, starting_balance="12.25") \
    .build()
transaction.sign(source)
response = server.submit_transaction(transaction)
print("Transaction hash: {}".format(response["hash"]))
print("New Keypair: \n\taccount id: {account_id}\n\tsecret seed: {secret_seed}".format(
    account_id=destination.public_key, secret_seed=destination.secret))
예제 #8
0
predicate_left = ClaimPredicate.predicate_before_relative_time(60 * 60 * 24 *
                                                               7)
predicate_right = ClaimPredicate.predicate_not(
    ClaimPredicate.predicate_before_relative_time(60 * 3))
predicate = ClaimPredicate.predicate_and(predicate_left, predicate_right)
claimant = Claimant(destination=claimant_keypair.public_key,
                    predicate=predicate)
create_claimable_balance_te = TransactionBuilder(
    source_account=sponsor_account,
    network_passphrase=network_passphrase).append_create_claimable_balance_op(
        asset=Asset.native(),
        amount="100",
        claimants=[claimant],
        source=sponsor_keypair.public_key).build()
create_claimable_balance_te.sign(sponsor_keypair)
create_claimable_balance_resp = server.submit_transaction(
    create_claimable_balance_te)
print(create_claimable_balance_resp)

# Claim Claimable Balance
balance_id = "00000000550e14acbdafcd3089289363b3b0c8bec9b4edd87298c690655b4b2456d68ba0"
claimant_account = server.load_account(claimant_keypair.public_key)
claim_claimable_balance_te = TransactionBuilder(
    source_account=claimant_account,
    network_passphrase=network_passphrase).append_claim_claimable_balance_op(
        balance_id=balance_id, source=claimant_keypair.public_key).build()

claim_claimable_balance_te.sign(claimant_keypair)
claim_claimable_balance_resp = server.submit_transaction(
    claim_claimable_balance_te)
print(claim_claimable_balance_resp)
sponsoring_account_creation_te = TransactionBuilder(
    source_account=sponsor_account,
    network_passphrase=network_passphrase
).append_begin_sponsoring_future_reserves_op(
    sponsored_id=newly_created_keypair.public_key,
    source=sponsor_keypair.public_key
).append_create_account_op(
    destination=newly_created_keypair.public_key,
    starting_balance="10",
    source=sponsor_keypair.public_key
).append_end_sponsoring_future_reserves_op(
    source=newly_created_keypair.public_key
).build()
sponsoring_account_creation_te.sign(sponsor_keypair)
sponsoring_account_creation_te.sign(new_account_secret)
sponsoring_account_creation_resp = server.submit_transaction(sponsoring_account_creation_te)
print(sponsoring_account_creation_resp)

# Revoke Account Sponsorship
sponsor_account = server.load_account(sponsor_keypair.public_key)
revoke_account_sponsorship_te = TransactionBuilder(
    source_account=sponsor_account,
    network_passphrase=network_passphrase
).append_revoke_account_sponsorship_op(
    account_id=newly_created_keypair.public_key,
    source=sponsor_keypair.public_key
).build()
revoke_account_sponsorship_te.sign(sponsor_keypair)
revoke_account_sponsorship_resp = server.submit_transaction(revoke_account_sponsorship_te)
print(revoke_account_sponsorship_resp)
예제 #10
0
bob_secret = "SBVFXGIXA22LSNZQKXCTNBRBFHBPRWBGZ7KNWAEINCYCPMNFGJDFPWA2"
eve_public = "GAPE2V77237AQJGTFNYNI3RBMERSFLTUYPVXDMANXUGUN6IEWCVY3VXN"

network_passphrase = Network.TESTNET_NETWORK_PASSPHRASE
server = Server(horizon_url="https://hz1-test.kuknos.org")

escrow_account = server.load_account(eve_public)
base_fee = 100

transaction = TransactionBuilder(
    source_account=escrow_account,
    network_passphrase=network_passphrase,
    base_fee=base_fee,
).add_text_memo("Hello, Kuknos!") \
    .append_payment_op(eve_public, "100", "PMN") \
    .set_timeout(30) \
    .build()

# Now Alice signs this transaction and sends the generated XDR to Bob
transaction.sign(alice_secret)
xdr = transaction.to_xdr()
print(f"xdr: {xdr}")

# Bob receives this XDR and signs it.
transaction = TransactionEnvelope.from_xdr(xdr, network_passphrase)
transaction.sign(bob_secret)
print(f"xdr: {transaction.to_xdr()}")

# Last, you can submit it to the network
resp = server.submit_transaction(transaction)