def list_asset_balance(wallet_file, asset, issuer, domain=None, test_mode=False, trezor_mode=False): network_settings = get_network_settings(test_mode=test_mode) if not trezor_mode: (private_key, public_key) = load_wallet(wallet_file=wallet_file) k = Keypair.from_secret(secret=private_key) else: public_key = get_trezor_public_key() k = Keypair.from_public_key(public_key=public_key) server = Server(network_settings.get("horizon_url")) response = server.accounts().account_id(account_id=k.public_key).call() balances = response.get("balances") for b in balances: balance = b.get("balance") asset_code = b.get("asset_code") asset_issuer = b.get("asset_issuer") if asset_code == asset and asset_issuer == issuer: if asset_code is None and asset_issuer is None: print("{} XLM".format(balance)) else: if domain is None: print("{} {} issued by {}".format(balance, asset_code, asset_issuer)) else: print("{} {}@{} issued by {}".format( balance, asset_code, domain, asset_issuer))
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", "XLM").append_path_payment_strict_receive_op( self.DESTINATION_ACCOUNT_NO_MEMO_REQUIRED, "XLM", None, "10", "BTC", "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2", "1", [], ).append_path_payment_strict_send_op( self.DESTINATION_ACCOUNT_NO_MEMO_REQUIRED, "XLM", 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 hello_world(request): """Responds to any HTTP request. Args: request (flask.Request): HTTP request object. Returns: The response text or any set of values that can be turned into a Response object using `make_response <http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response>`. """ if request.method == 'OPTIONS': # Allows GET requests from any origin with the Content-Type # header and caches preflight response for an 3600s headers = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET,POST', 'Access-Control-Allow-Headers': 'Content-Type', 'Access-Control-Max-Age': '3600' } return ('okay done', 204, headers) from stellar_sdk import Server, Keypair, TransactionBuilder, Network, Asset request_json = request.get_json() cash = request_json["money"] print(cash) source_keypair = Keypair.from_secret("xxxxxxxxxxxxxxxxxxxxxxxxxxx") server = Server(horizon_url="https://horizon-testnet.stellar.org") source_account = server.load_account(account_id=source_keypair.public_key) base_fee = server.fetch_base_fee() path = [] transaction = (TransactionBuilder( source_account=source_account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, base_fee=base_fee, ).append_path_payment_op( destination="GDYC7QBANT5HCU3CAJVYDBDMGKUMOSWRULN737XRSDV56HIGSIUEQ6WJ", send_code="XLM", send_issuer=None, send_max="100", dest_code="USD", dest_issuer="GACN4CNWBINPRWT2YKXXMEIPIBL5PEJNSKEBNOGCCXDKZBE5M44YFNXB", dest_amount=str(cash), path=path).set_timeout(30).build()) transaction.sign(source_keypair) res = server.submit_transaction(transaction) print(res) import json import flask request_json = request.get_json() response = flask.jsonify( "https://horizon-testnet.stellar.org/accounts/GDYC7QBANT5HCU3CAJVYDBDMGKUMOSWRULN737XRSDV56HIGSIUEQ6WJ" ) response.headers.set('Access-Control-Allow-Origin', '*') response.headers.set('Access-Control-Allow-Methods', 'GET, POST') response.headers.set('Access-Control-Allow-Headers', 'Content-Type') return response
def make_account(): keypair = Keypair.random() print("Public Key: " + keypair.public_key) print("Secret Seed: " + keypair.secret) server = Server(horizon_url="https://horizon-testnet.stellar.org") url = 'https://friendbot.stellar.org' response = requests.get(url, params={'addr': keypair.public_key}) print(response) source_keypair = Keypair.from_secret(keypair.secret) source_public_key = source_keypair.public_key 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, ).append_change_trust_op( "SAVEPOINTS", "GDG4SRXHATOQPRDAMK45YHL42N3RMQ6UJYAS2ETJQ2I5XZYSIQLCSGV6"). set_timeout( 30) # Make this transaction valid for the next 30 seconds only .build()) transaction.sign(source_keypair) print(transaction.to_xdr()) response = server.submit_transaction(transaction) #print(response) return keypair.public_key, keypair.secret
def handle(self, *args, **options): server = Server(horizon_url="https://horizon-testnet.stellar.org") ledgers = server.ledgers().order(desc=True).call() Ledger.objects.all().delete() Ledger(raw_json=json.dumps(ledgers)).save()
def getKeysSettings(): global horizon, server, NET_PASS, keypair #ensures keys.txt exists before continuing while os.path.isfile('keys.txt') is not True: writeStatus("Keys have not been created.") time.sleep(30) #Load keypair and settings from filesystem with open("keys.txt", "r") as f: keyData=f.read() #Process data and set up global variables listKeyData=[x.strip() for x in keyData.split(',')] if listKeyData[0] == "MAINNET": horizon="https://horizon.stellar.org/" server=Server(horizon) NET_PASS=Network.PUBLIC_NETWORK_PASSPHRASE else: horizon="https://horizon-testnet.stellar.org/" server=Server(horizon) NET_PASS=Network.TESTNET_NETWORK_PASSPHRASE keypair=Keypair.from_secret(listKeyData[2])
def verificarCuentaActivada(self, destino): server = Server(horizon_url=self.Horizon_url) try: transactions = server.load_account(account_id=destino) return [True, transactions] except exceptions.NotFoundError as e: return [False, e]
def configurarBilleteraPrimeraVez(self, listaUsuarios, umbralLista): server = Server(horizon_url=self.Horizon_url) root_keypair = Keypair.from_secret(self.sLlave) root_account = server.load_account(account_id=root_keypair.public_key) base_fee = server.fetch_base_fee() transaction = TransactionBuilder( base_fee=base_fee, network_passphrase=self.networkTrabajar, source_account=root_account)\ .append_set_options_op(master_weight=1, low_threshold=int(umbralLista[1])-1, med_threshold=int(umbralLista[1]), high_threshold=int(umbralLista[0]))\ .set_timeout(30) for i in listaUsuarios: transaction.append_ed25519_public_key_signer(account_id=i[3], weight=1) transaction = transaction.build() transaction.sign(root_keypair) try: response = server.submit_transaction(transaction) return [True, response] except exceptions.BadRequestError as d: return [False, d] except exceptions.NotFoundError as n: return [False, n]
def make_bids(asset_code, issuing_keypair, distributing_keypair, market_supply): # Talk to Horizon testnet instance. server = Server(horizon_url=TESTNET) # Fetch the current sequence number for the source account from Horizon. source_account = server.load_account(distributing_keypair.public_key) # Build transaction around manage buy offer operation (setting market bids). transaction = ( TransactionBuilder( source_account=source_account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, base_fee=100, # too lazy to fetch :) ).append_manage_buy_offer_op( 'XLM', None, asset_code, issuing_keypair.public_key, market_supply, '.08').append_manage_buy_offer_op( 'XLM', None, asset_code, issuing_keypair.public_key, market_supply, '.09').append_manage_buy_offer_op('XLM', None, asset_code, issuing_keypair.public_key, market_supply, '.10').build()) # Sign transaction with distributor private key. transaction.sign(distributing_keypair) # Submit signed transaction to Horizon. response = server.submit_transaction(transaction) print(json.dumps(response, indent=2))
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", "XLM").append_path_payment_strict_receive_op( self.DESTINATION_ACCOUNT_MEMO_REQUIRED_B, "XLM", None, "10", "BTC", "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2", "1", [], ).append_path_payment_strict_send_op( self.DESTINATION_ACCOUNT_MEMO_REQUIRED_C, "XLM", 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", "XLM").append_path_payment_strict_send_op( self.DESTINATION_ACCOUNT_MEMO_REQUIRED_C, "XLM", 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 verify_destination(public_key): server = Server("https://horizon-testnet.stellar.org") try: server.load_account(public_key) except NotFoundError: return False return True
def broadcast_tx(transaction, test_mode=True): network_settings = get_network_settings(test_mode=test_mode) server = Server(network_settings.get("horizon_url")) try: transaction_resp = server.submit_transaction(transaction) print("{}".format(json.dumps(transaction_resp, indent=4))) except BaseHorizonError as e: print("Error: {}".format(str(e)))
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 list_transactions(wallet_file, test_mode=True, trezor_mode=False): network_settings = get_network_settings(test_mode=test_mode) if not trezor_mode: (private_key, public_key) = load_wallet(wallet_file=wallet_file) k = Keypair.from_secret(secret=private_key) else: public_key = get_trezor_public_key() k = Keypair.from_public_key(public_key=public_key) server = Server(network_settings.get("horizon_url")) response = server.transactions().for_account( account_id=k.public_key).call() print(json.dumps(response, indent=4))
def pagoEncuesta(self, Destino, monto, firmantes): validarCuenta = self.verificarCuentaActivada(destino=Destino) if validarCuenta[0]: server = Server(horizon_url=self.Horizon_url) root_keypair = Keypair.from_secret(self.sLlave) root_account = server.load_account( account_id=root_keypair.public_key) base_fee = server.fetch_base_fee() transaction = TransactionBuilder( source_account=root_account, network_passphrase=self.networkTrabajar, base_fee=base_fee) \ .append_payment_op( # add a payment operation to the transaction destination=Destino, asset_code="XLM", amount=str(monto)) \ .set_timeout(30) \ .build() # mark this transaction as valid only for the next 30 seconds # transaction.sign(root_keypair) for i in firmantes: transaction.sign(Keypair.from_secret(i)) try: response = server.submit_transaction(transaction) return [True, response] except exceptions.BadRequestError as d: # print(d) return [False, d] else: server = Server(horizon_url=self.Horizon_url) root_keypair = Keypair.from_secret(self.sLlave) root_account = server.load_account( account_id=root_keypair.public_key) base_fee = server.fetch_base_fee() transaction = TransactionBuilder( source_account=root_account, network_passphrase=self.networkTrabajar, base_fee=base_fee) \ .append_create_account_op(destination=Destino,starting_balance=str(monto))\ .set_timeout(30)\ .build() # transaction.sign(root_keypair) for i in firmantes: transaction.sign(Keypair.from_secret(i)) try: response = server.submit_transaction(transaction) return [True, response] except exceptions.BadRequestError as d: # print(d) return [False, d]
def assetsActivo(self, direccionEmisor, codigo): pLlave = self.pLlave try: server = Server(horizon_url=self.Horizon_url) cuenta = server.accounts().account_id(pLlave).call() resultado = False for balance in cuenta['balances']: if balance['asset_type'] != 'native': if balance['asset_code'] == codigo and balance[ 'asset_issuer'] == direccionEmisor: resultado = True except exceptions.NotFoundError: return resultado return resultado
def sendXLM(secret, toAddress): server = Server(horizon_url="https://horizon-testnet.stellar.org") source_keypair = Keypair.from_secret(secret) source_account = server.load_account(account_id=source_keypair.public_key) transaction = TransactionBuilder( source_account=source_account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, base_fee=100) \ .append_path_payment_strict_receive_op(destination=toAddress, send_code="XLM", send_issuer=None, send_max="1000", dest_code="XLM", dest_amount="5.50", path=path) \ .set_timeout(30) \ .build() transaction.sign(source_keypair) response = server.submit_transaction(transaction)
def sendPayment(sender_sKey, destination_pKey, amount, asset_code): server - Server("https://horizon-testnet.stellar.org") source_key = Keypair.from_secret(sender_sKey) destination_id = destination_pKey try: server.load_account(destination_id) except NotFoundError: #Shouldn't be a problem since we're using fundraiser wallets (will verify when creating fundraisers/accounts) raise Exception("THe destination account is invalid") # If there was no error, load up-to-date information on your account. source_account = server.load_account(source_key.public_key) # Let's fetch base_fee from network base_fee = server.fetch_base_fee() transaction = ( TransactionBuilder( source_account=source_account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, base_fee=base_fee).append_payment_op(destination=destination_id, amount=str(amount), asset_code=asset_code) # .add_text_memo() // COULD ADD DETAILS TO TRANSACTION .set_timeout(10).build()) #Proof of identity of sender transaction.sign(source_key) try: #Sending the transaction to Stellar response = server.submit_transaction(transaction) print(f"Response: {response}") except (BadRequestError, BadResponseError) as err: print(f"Something went wrong!\n{err}")
def crearAssets(self, codigo, monto, emisor): server = Server(horizon_url=self.Horizon_url) root_keypair = Keypair.from_secret(self.sLlave) root_account = server.load_account(account_id=root_keypair.public_key) transaction = TransactionBuilder( source_account=root_account, network_passphrase=self.networkTrabajar, base_fee=100).append_change_trust_op(limit=monto, asset_code=str(codigo), asset_issuer=emisor).build() transaction.sign(root_keypair) try: response = server.submit_transaction(transaction) return [True, response] except exceptions.BadRequestError as d: return [False, d]
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", "XLM").append_path_payment_strict_receive_op( self.DESTINATION_ACCOUNT_NO_FOUND, "XLM", None, "10", "BTC", "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2", "1", [], ).append_path_payment_strict_send_op( self.DESTINATION_ACCOUNT_NO_FOUND, "XLM", None, "10", "BTC", "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2", "1", [], ).append_account_merge_op( self.DESTINATION_ACCOUNT_NO_FOUND).build()) transaction.sign(keypair) await server.submit_transaction(transaction)
def get_balance(public_key, asset=0, public=False): if public: server = Server(horizon_url="https://horizon.stellar.org") else: server = Server(horizon_url="https://horizon-testnet.stellar.org") account = server.accounts().account_id(public_key).call() if asset: for b in account['balances']: if b['asset_code'] == asset[0] and b['asset_issuer'] == asset[ 1]: balance = float(b['balance']) break else: for b in account['balances']: if b['asset_type'] == 'native': balance = float(b['balance']) return balance
def transfer_points(source_secret_key, receiver_public_key, num_points, memo=""): #source is distributor source_keypair = Keypair.from_secret(source_secret_key) source_public_key = source_keypair.public_key server = Server(horizon_url="https://horizon-testnet.stellar.org") source_account = server.load_account(source_public_key) base_fee = server.fetch_base_fee() # if you want to submit to the public network, please use `Network.PUBLIC_NETWORK_PASSPHRASE`. if memo == "": transaction = ( TransactionBuilder( source_account=source_account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, base_fee=base_fee, ).append_payment_op( receiver_public_key, str(num_points), "SAVEPOINTS", "GDG4SRXHATOQPRDAMK45YHL42N3RMQ6UJYAS2ETJQ2I5XZYSIQLCSGV6"). set_timeout( 30) # Make this transaction valid for the next 30 seconds only .build()) else: transaction = ( TransactionBuilder( source_account=source_account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, base_fee=base_fee, ).append_payment_op( receiver_public_key, str(num_points), "SAVEPOINTS", "GDG4SRXHATOQPRDAMK45YHL42N3RMQ6UJYAS2ETJQ2I5XZYSIQLCSGV6"). add_text_memo(memo).set_timeout( 30) # Make this transaction valid for the next 30 seconds only .build()) transaction.sign(source_keypair) print(transaction.to_xdr()) response = server.submit_transaction(transaction) print(response)
def __init__(self, horizon_url: str, integrated_coins): helpers = Helpers() secret_details = helpers.read_json_file(file_name="walletSecrets.json") # Load Stellar wallet secrets public_details = helpers.read_json_file(file_name="hotWallets.json") # Load hot wallet details self.integrated_coins = integrated_coins self.public_key = public_details["xlm"] self.dev_key = public_details["xlmDev"] self.private_key = secret_details['stellar'] self.root_keypair = Keypair.from_secret(self.private_key) self.root_account = Account(account_id=self.root_keypair.public_key, sequence=1) self.server = Server(horizon_url=horizon_url) # Testnet # Decide network type if horizon_url == "https://horizon-testnet.stellar.org": self.network_phrase = Network.TESTNET_NETWORK_PASSPHRASE self.network_type = 'testnet' else: self.network_phrase = Network.PUBLIC_NETWORK_PASSPHRASE self.network_type = 'pub-net'
def add_trust(wallet_file, asset, issuer, test_mode=True, trezor_mode=False, vzero=False, timeout=3600): network_settings = get_network_settings(test_mode=test_mode) if timeout is None: timeout = 3600 v1_mode = not vzero if not trezor_mode: (private_key, public_key) = load_wallet(wallet_file=wallet_file) k = Keypair.from_secret(secret=private_key) else: public_key = get_trezor_public_key() k = Keypair.from_public_key(public_key=public_key) v1_mode = False server = Server(network_settings.get("horizon_url")) stellar_asset = Asset(asset, issuer) account = server.load_account(account_id=k.public_key) transaction = (TransactionBuilder( source_account=account, network_passphrase=network_settings.get("network_passphrase"), base_fee=100, v1=v1_mode).append_change_trust_op( asset_code=stellar_asset.code, asset_issuer=stellar_asset.issuer, ).set_timeout(timeout).build()) if not trezor_mode: transaction.sign(k) else: transaction = sign_trezor_transaction( transaction, k, network_passphrase=network_settings.get("network_passphrase")) try: transaction_resp = server.submit_transaction(transaction) print("{}".format(json.dumps(transaction_resp, indent=4))) except BaseHorizonError as e: print("Error: {}".format(str(e)))
def informacionAssets(self): pLlave = self.pLlave try: texto = "Assets\n➖➖➖➖➖➖➖➖➖➖➖➖➖➖\n" #asset_issuer="" server = Server(horizon_url=self.Horizon_url) cuenta = server.accounts().account_id(pLlave).call() for i in cuenta['balances']: if i['asset_type'] != "native": asset_issuer = i['asset_issuer'] texto += ("Asset Code:" + i['asset_code'] + "\n") texto += ("Limit:" + i['limit'] + "\n") Assets = server.assets().for_code( i['asset_code']).for_issuer(asset_issuer).call() for e in Assets['_embedded']['records']: texto += ("Amount:" + str(e['amount'])) texto += ("\nNum Accounts:" + str(e['num_accounts'])) texto += ("\n➖➖➖➖➖➖➖➖➖➖➖➖➖➖\n") return texto except: return "Sorry you have not created any assets, please click the button (Create Assets)"
def send_txn(self, origin, dest, merge): keys=Keypair.from_secret(origin) server=Server("https://horizon.stellar.org/") NET_PASS=Network.PUBLIC_NETWORK_PASSPHRASE basefee=server.fetch_base_fee() txnSent=False while txnSent is False: try: account=server.load_account(keys.public_key) if merge != None and merge == True: txn=TransactionBuilder( source_account=account, network_passphrase=NET_PASS, base_fee=basefee, ).append_account_merge_op( destination=dest ).set_timeout(10000).build() else: txn=TransactionBuilder( source_account=account, network_passphrase=NET_PASS, base_fee=basefee, ).append_create_account_op( destination=dest, starting_balance="1.11").set_timeout(1000).build() txn.sign(keys) server.submit_transaction(txn) txnSent=True except: time.sleep(0.5)
def send_asset(issuing_keypair, distributing_keypair, asset_code, supply): # Talk to Horizon testnet instance. server = Server(horizon_url=TESTNET) # Fetch the current sequence number for the source account from Horizon. source_account = server.load_account(issuing_keypair.public_key) # Build transaction around payment operation (sending asset to distributor). transaction = ( TransactionBuilder( source_account=source_account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, base_fee=100, # too lazy to fetch :) ).append_payment_op(distributing_keypair.public_key, supply, asset_code, issuing_keypair.public_key).build()) # Sign transaction with issuing private key. transaction.sign(issuing_keypair) # Submit signed transaction to Horizon. response = server.submit_transaction(transaction) print(json.dumps(response, indent=2))
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", "XLM").append_path_payment_strict_receive_op( self.DESTINATION_ACCOUNT_NO_MEMO_REQUIRED, "XLM", None, "10", "BTC", "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2", "1", [], ).append_path_payment_strict_send_op( self.DESTINATION_ACCOUNT_NO_MEMO_REQUIRED, "XLM", 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
def pagoAssets(self, Destino, monto, codigo, asset_usuario): server = Server(horizon_url=self.Horizon_url) root_keypair = Keypair.from_secret(self.sLlave) root_account = server.load_account(account_id=root_keypair.public_key) base_fee = server.fetch_base_fee() transaction = TransactionBuilder( source_account=root_account, network_passphrase=self.networkTrabajar, base_fee=base_fee) \ .append_payment_op( # add a payment operation to the transaction destination=Destino, asset_code=str(codigo), amount=str(monto), asset_issuer=asset_usuario) \ .set_timeout(30) \ .build() # mark this transaction as valid only for the next 30 seconds transaction.sign(root_keypair) try: response = server.submit_transaction(transaction) return [True, response] except exceptions.BadRequestError as d: # print(d) return [False, d]