Ejemplo n.º 1
0
 def test_submit_transaction_with_xdr(self):
     xdr = "AAAAAHI7fpgo+b7tgpiFyYWimjV7L7IOYLwmQS7k7F8SronXAAAAZAE+QT4AAAAJAAAAAQAAAAAAAAAAAAAAAF1MG8cAAAAAAAAAAQAAAAAAAAAAAAAAAOvi1O/HEn+QgZJw+EMZBtwvTVNmpgvE9p8IRfwp0GY4AAAAAAExLQAAAAAAAAAAARKuidcAAABAJVc1ASGp35hUquGNbzzSqWPoTG0zgc89zc4p+19QkgbPqsdyEfHs7+ng9VJA49YneEXRa6Fv7pfKpEigb3VTCg=="
     horizon_url = "https://testhorizon.paydex.io/"
     client = RequestsClient()
     with Server(horizon_url, client) as server:
         resp = server.submit_transaction(xdr)
         assert resp["envelope_xdr"] == xdr
Ejemplo n.º 2
0
 def test_load_acount_sync(self):
     account_id = "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D"
     horizon_url = "https://testhorizon.paydex.io/"
     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)
Ejemplo n.º 3
0
 async def test_submit_transaction_with_te(self):
     xdr = "AAAAAHI7fpgo+b7tgpiFyYWimjV7L7IOYLwmQS7k7F8SronXAAAAZAE+QT4AAAAJAAAAAQAAAAAAAAAAAAAAAF1MG8cAAAAAAAAAAQAAAAAAAAAAAAAAAOvi1O/HEn+QgZJw+EMZBtwvTVNmpgvE9p8IRfwp0GY4AAAAAAExLQAAAAAAAAAAARKuidcAAABAJVc1ASGp35hUquGNbzzSqWPoTG0zgc89zc4p+19QkgbPqsdyEfHs7+ng9VJA49YneEXRa6Fv7pfKpEigb3VTCg=="
     te = TransactionEnvelope.from_xdr(xdr,
                                       Network.PUBLIC_NETWORK_PASSPHRASE)
     horizon_url = "https://testhorizon.paydex.io/"
     client = AiohttpClient()
     async with Server(horizon_url, client) as server:
         resp = await server.submit_transaction(te)
         assert resp["envelope_xdr"] == xdr
Ejemplo n.º 4
0
 def test_bad_type_client_raise(self):
     horizon_url = "https://testhorizon.paydex.io/"
     client = "BAD TYPE"
     with pytest.raises(
             TypeError,
             match="This `client` class should be an instance "
             "of `paydex_base_sdk.client.base_async_client.BaseAsyncClient` "
             "or `paydex_base_sdk.client.base_sync_client.BaseSyncClient`.",
     ):
         Server(horizon_url, client)
Ejemplo n.º 5
0
async def main():
    # Configure paydexSdk to talk to the horizon instance hosted by paydex.org
    # When we use the `with` syntax, it automatically releases the resources it occupies.
    async with Server(horizon_url="https://testhorizon.paydex.io//",
                      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, paydex!")  # Add a memo
            # Add a payment operation to the transaction
            # Send 350.1234567 PAYDEX to receiver
            # Specify 350.1234567 lumens. Lumens are divisible to seven digits past the decimal.
            .append_payment_op(receiver_public_key, "350.1234567", "PAYDEX").
            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 paydex_base_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)
Ejemplo n.º 6
0
from paydex_base_sdk.server import Server

server = Server(horizon_url="https://testhorizon.paydex.io//")
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)
Ejemplo n.º 7
0
from paydex_base_sdk.asset import Asset
from paydex_base_sdk.keypair import Keypair
from paydex_base_sdk.network import Network
from paydex_base_sdk.server import Server
from paydex_base_sdk.transaction_builder import TransactionBuilder

server = Server(horizon_url="https://testhorizon.paydex.io//")
source_keypair = Keypair.from_secret(
    "SA6XHAH4GNLRWWWF6TEVEWNS44CBNFAJWHWOPZCVZOUXSQA7BOYN7XHC")

source_account = server.load_account(account_id=source_keypair.public_key)

path = [
    Asset("USD", "GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB"),
    Asset("EUR", "GDTNXRLOJD2YEBPKK7KCMR7J33AAG5VZXHAJTHIG736D6LVEFLLLKPDL")
]
transaction = TransactionBuilder(
    source_account=source_account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, base_fee=100) \
    .append_path_payment_op(destination="GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB",
                            send_code="PAYDEX", send_issuer=None, send_max="1000", dest_code="GBP",
                            dest_issuer="GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW",
                            dest_amount="5.50", path=path) \
    .set_timeout(30) \
    .build()
transaction.sign(source_keypair)
response = server.submit_transaction(transaction)
Ejemplo n.º 8
0
    def test_endpoint(self):
        horizon_url = "https://testhorizon.paydex.io/"
        client = RequestsClient()
        with Server(horizon_url, client) as server:
            assert server.accounts() == AccountsCallBuilder(
                horizon_url, client)
            assert server.assets() == AssetsCallBuilder(horizon_url, client)
            assert server.data(
                "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D",
                "hello") == DataCallBuilder(
                    horizon_url,
                    client,
                    "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D",
                    "hello",
                )
            assert server.effects() == EffectsCallBuilder(horizon_url, client)
            assert server.fee_stats() == FeeStatsCallBuilder(
                horizon_url, client)
            assert server.ledgers() == LedgersCallBuilder(horizon_url, client)
            assert server.offers() == OffersCallBuilder(horizon_url, client)
            assert server.operations() == OperationsCallBuilder(
                horizon_url, client)
            buying = Asset.native()
            selling = Asset(
                "MOE",
                "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D")
            assert server.orderbook(buying, selling) == OrderbookCallBuilder(
                horizon_url, client, buying, selling)
            source_account = "GABUVMDURJFF477AEDAXOG5TL7JBHGDAKJQLH5K6FB5QONMLEV52C6IO"
            destination_account = (
                "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D")
            destination_asset = Asset.native()
            destination_amount = "100.0"
            assert server.paths(
                source_account,
                destination_account,
                destination_asset,
                destination_amount,
            ) == PathsCallBuilder(
                horizon_url,
                client,
                source_account,
                destination_account,
                destination_asset,
                destination_amount,
            )
            source = "GAYSHLG75RPSMXWJ5KX7O7STE6RSZTD6NE4CTWAXFZYYVYIFRUVJIBJH"
            destination_asset = Asset(
                "EUR",
                "GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN")
            destination_amount = "20.0"
            assert server.strict_receive_paths(
                source, destination_asset,
                destination_amount) == StrictReceivePathsCallBuilder(
                    horizon_url, client, source, destination_asset,
                    destination_amount)

            source_asset = Asset(
                "EUR",
                "GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN")
            source_amount = "10.25"
            destination = "GARSFJNXJIHO6ULUBK3DBYKVSIZE7SC72S5DYBCHU7DKL22UXKVD7MXP"
            assert server.strict_send_paths(
                source_asset, source_amount,
                destination) == StrictSendPathsCallBuilder(
                    horizon_url, client, source_asset, source_amount,
                    destination)
            assert server.payments() == PaymentsCallBuilder(
                horizon_url, client)
            assert server.root() == RootCallBuilder(horizon_url, client)
            base = Asset.native()
            counter = Asset(
                "MOE",
                "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D")
            resolution = 3600000
            start_time = 1565272000000
            end_time = 1565278000000
            offset = 3600000
            assert server.trade_aggregations(
                base, counter, resolution, start_time, end_time,
                offset) == TradeAggregationsCallBuilder(
                    horizon_url,
                    client,
                    base,
                    counter,
                    resolution,
                    start_time,
                    end_time,
                    offset,
                )
            assert server.trades() == TradesCallBuilder(horizon_url, client)
            assert server.transactions() == TransactionsCallBuilder(
                horizon_url, client)
Ejemplo n.º 9
0
 async def test_fetch_base_fee_async(self):
     horizon_url = "https://testhorizon.paydex.io/"
     client = AiohttpClient()
     async with Server(horizon_url, client) as server:
         base_fee = await server.fetch_base_fee()
         assert isinstance(base_fee, int)
Ejemplo n.º 10
0
 def test_fetch_base_fee_sync(self):
     horizon_url = "https://testhorizon.paydex.io/"
     with Server(horizon_url) as server:
         base_fee = server.fetch_base_fee()
         assert base_fee == 100
Ejemplo n.º 11
0
from paydex_base_sdk.keypair import Keypair
from paydex_base_sdk.network import Network
from paydex_base_sdk.server import Server
from paydex_base_sdk.transaction_builder import TransactionBuilder

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"


server = Server(horizon_url="https://testhorizon.paydex.io/")

# Transactions require a valid sequence number that is specific to this account.
source_account = server.load_account(source_public_key)

base_fee = server.fetch_base_fee()

transaction = (
    TransactionBuilder(
        source_account=source_account,
        network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
        base_fee=base_fee,
    )
        .add_text_memo("Hello, Paydex!")  # Add a memo
        # Add a payment operation to the transaction
        # Send 350.1234567 PAYDEX to receiver
Ejemplo n.º 12
0
from paydex_base_sdk.server import Server

server = Server(horizon_url="https://testhorizon.paydex.io//")

# 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 paydex_base_sdk.sep.exceptions import InvalidSep10ChallengeError
from paydex_base_sdk.sep.paydex_web_authentication import build_challenge_transaction, read_challenge_transaction, \
    verify_challenge_transaction_threshold, verify_challenge_transaction_signed_by_client_master_key
from paydex_base_sdk.server import Server
from paydex_base_sdk.transaction_builder import TransactionBuilder

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://testhorizon.paydex.io/")
anchor_name = "hello"
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)
    print(resp)