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_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_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)
 async def test_check_memo_required_with_account_not_found_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_FOUND, "10",
             "PMN").append_path_payment_strict_receive_op(
                 self.DESTINATION_ACCOUNT_NO_FOUND,
                 "PMN",
                 None,
                 "10",
                 "BTC",
                 "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2",
                 "1",
                 [],
             ).append_path_payment_strict_send_op(
                 self.DESTINATION_ACCOUNT_NO_FOUND,
                 "PMN",
                 None,
                 "10",
                 "BTC",
                 "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2",
                 "1",
                 [],
             ).append_account_merge_op(
                 self.DESTINATION_ACCOUNT_NO_FOUND).build())
         transaction.sign(keypair)
         await 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
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 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}")
Beispiel #10
0
from kuknos_sdk import Server, TransactionBuilder, Keypair, Network
from kuknos_sdk.exceptions import NotFoundError
from kuknos_sdk.sep.exceptions import InvalidSep10ChallengeError
from kuknos_sdk.sep.kuknos_web_authentication import build_challenge_transaction, read_challenge_transaction, \
    verify_challenge_transaction_threshold, verify_challenge_transaction_signed_by_client_master_key

server_keypair = Keypair.from_secret(
    "SBGCNEOQGECW5R4A55C26ZFS736IONKCHY5PPPSFZVXSJSU63MWNM4K6")
client_master_keypair = Keypair.from_secret(
    "SDWZHXKWSHTQ2YGPT6YQQSOJWJX5JX2IEU7KOLGQ2XEJEECIQHUU3RMR")
client_signer_keypair1 = Keypair.from_secret(
    "SCKJFEF2H767XINUY5YFBORUO7AAWOAXSTQ2B2YHSI6N4UF23HFV42I7")
client_signer_keypair2 = Keypair.from_secret(
    "SCE2JBZ6FKPTQ5LM4X4NIZOOZPIC5DXVG6VP2TKSBZCQAGXABJV55IN5")

server = Server("https://hz1-test.kuknos.org")
home_domain = "example.com"
web_auth_domain = "auth.example.com"
network_passphrase = Network.TESTNET_NETWORK_PASSPHRASE


def setup_multisig():
    client_master_account = server.load_account(
        client_master_keypair.public_key)
    te = TransactionBuilder(client_master_account, network_passphrase) \
        .append_ed25519_public_key_signer(client_signer_keypair1.public_key, 40) \
        .append_ed25519_public_key_signer(client_signer_keypair2.public_key, 60) \
        .append_set_options_op(master_weight=0, low_threshold=1, med_threshold=10, high_threshold=100) \
        .build()
    te.sign(client_master_keypair)
    resp = server.submit_transaction(te)
Beispiel #11
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))
Beispiel #12
0
from kuknos_sdk import Server, TransactionBuilder, Signer, Network, Keypair

server = Server(horizon_url="https://hz1-test.kuknos.org/")
root_keypair = Keypair.from_secret("SA6XHAH4GNLRWWWF6TEVEWNS44CBNFAJWHWOPZCVZOUXSQA7BOYN7XHC")
root_account = server.load_account(account_id=root_keypair.public_key)
secondary_keypair = Keypair.from_secret("SAMZUAAPLRUH62HH3XE7NVD6ZSMTWPWGM6DS4X47HLVRHEBKP4U2H5E7")

secondary_signer = Signer.ed25519_public_key(account_id=secondary_keypair.public_key, weight=1)
transaction = TransactionBuilder(
    source_account=root_account,
    network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
    base_fee=100) \
    .append_set_options_op(
    master_weight=1,  # set master key weight
    low_threshold=1,
    med_threshold=2,  # a payment is medium threshold
    high_threshold=2,  # make sure to have enough weight to add up to the high threshold!
    signer=secondary_signer) \
    .set_timeout(30) \
    .build()

# only need to sign with the root signer as the 2nd signer won't
# be added to the account till after this transaction completes
transaction.sign(root_keypair)
response = server.submit_transaction(transaction)
print(response)

# now create a payment with the account that has two signers
destination = "GBA5SMM5OYAOOPL6R773MV7O3CCLUDVLCWHIVVL3W4XTD3DA5FJ4JSEZ"
transaction = TransactionBuilder(
    source_account=root_account,
from kuknos_sdk import Server, TransactionBuilder, Keypair, Network

sponsor_secret = "SAOJHTVFCYVKUMPNQI7RUSI566GKWXP7RXOHP4SV6JAVUQKSIWGPZFPJ"
new_account_secret = "SCN5D72JHQAHUHGIA23SLS3LBYCPHJWD7HLYNJRBBZIG4PD74UCGQBYM"

sponsor_keypair = Keypair.from_secret(sponsor_secret)
newly_created_keypair = Keypair.from_secret(new_account_secret)

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

# Sponsoring Account Creation
# https://github.com/kuknos/kuknos-protocol/blob/master/core/cap-0033.md#example-sponsoring-account-creation
sponsor_account = server.load_account(sponsor_keypair.public_key)
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)
import pprint

from kuknos_sdk import Keypair, Server, TransactionBuilder, Network
from kuknos_sdk.exceptions import BadRequestError

horizon_url = "https://hz1-test.kuknos.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="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)
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}")
Beispiel #16
0
from kuknos_sdk import Server, TransactionBuilder, Keypair, ClaimPredicate, Claimant, Asset, Network

sponsor_secret = "SAOJHTVFCYVKUMPNQI7RUSI566GKWXP7RXOHP4SV6JAVUQKSIWGPZFPJ"
claimant_secret = "SBOLGU7D7A7MTY4JZ3WZUKSKB6NZBQFNQG3BZT4HZW4AAVZJRG7TWXGQ"

sponsor_keypair = Keypair.from_secret(sponsor_secret)
claimant_keypair = Keypair.from_secret(claimant_secret)

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

# Create Claimable Balance
sponsor_account = server.load_account(sponsor_keypair.public_key)

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)
Beispiel #17
0
3. Access to Python Kuknos SDK (https://github.com/javadnikbakht/py-kuknos-base) through Python shell.
"""
from kuknos_sdk import Server, Keypair, TransactionBuilder, Network

# The source account is the account we will be signing and sending from.
source_secret_key = "SBFZCHU5645DOKRWYBXVOXY2ELGJKFRX6VGGPRYUWHQ7PMXXJNDZFMKD"

# Derive Keypair object and public key (that starts with a G) from the secret
source_keypair = Keypair.from_secret(source_secret_key)
source_public_key = source_keypair.public_key

receiver_public_key = "GA7YNBW5CBTJZ3ZZOWX3ZNBKD6OE7A7IHUQVWMY62W2ZBG2SGZVOOPVH"

# Configure KuknosSdk to talk to the horizon instance hosted by Kuknos.org
# To use the live network, set the hostname to 'horizon.kuknos.org'
server = Server(horizon_url="https://hz1-test.kuknos.org")

# 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 = server.load_account(source_public_key)

base_fee = 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
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}")
Beispiel #19
0
from kuknos_sdk import Server

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

# get a list of transactions that occurred in ledger 1400
transactions = server.transactions().for_ledger(1400).call()
print(transactions)

# get a list of transactions submitted by a particular account
transactions = server.transactions() \
    .for_account(account_id="GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW") \
    .call()
print(transactions)
from kuknos_sdk import Server

server = Server(horizon_url="https://hz1-test.kuknos.org")
account_id = "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW"
last_cursor = 'now'  # or load where you left off


def tx_handler(tx_response):
    print(tx_response)


for tx in server.transactions().for_account(account_id).cursor(last_cursor).stream():
    tx_handler(tx)
# Let's assume Alice and Bob hold an escrow account and now they want to
# send 100 PMN from the escrow account to Eve, the following code shows how to achieve it.
from kuknos_sdk import Server, TransactionBuilder, Network, TransactionEnvelope

escrow_public = "GD7ZZHKFKFPV2KR6JPE5L6QOZ43LV6HBJWLITCC73V6R7YFERSAITE4S"
alice_secret = "SDKE26TSKMJDWPTWMA5YJYSIA6VQ5QNBUS5VEUR7P6NY4F7ITL7ZILQG"
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)