def sendPathPayment(): try: _json = request.json _amount = _json['amount'] _senderPubKey = _json['sender_pubKey'] _senderSecKey = _json['sender_secKey'] _senderAssetCode = _json['sender_assetCode'] _receiverPubKey = _json['receiver_pubKey'] _receiverSecKey = _json['receiver_secKey'] _receiverAssetCode = _json['receiver_assetCode']
server = Server(horizon_url="https://horizon-testnet.stellar.org")
source_keypair = Keypair.from_secret(_senderSecKey)
source_account = server.load_account(account_id=_senderPubKey)
# # checking user stellar wallets
server = Server("https://horizon-testnet.stellar.org")
account = server.accounts().account_id(_receiverPubKey).call()
balances = account['balances']
assetIss = ""
for bal in balances:
if bal['asset_type'] != "native":
if _receiverAssetCode == bal['asset_code']:
assetIss = bal['asset_issuer']
print(assetIss)
# DISPLAY ORDERS
order_data = requests.get("https://horizon-testnet.stellar.org/offers?buying=" + _receiverAssetCode + ":" + assetIss + "&selling=" + _senderAssetCode)
order_res = order_data.json()
print(order_res)
receiver_amount = order_res['_embedded']['records'][0]['amount']
print(receiver_amount)
transaction = (
TransactionBuilder(
source_account=source_account,
network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
base_fee=100,
)
.append_path_payment_strict_send_op(
destination= _receiverPubKey,
send_asset= Asset(_senderAssetCode, _senderPubKey),
send_amount=_amount,
dest_asset=Asset(_receiverAssetCode, _receiverPubKey),
dest_min=receiver_amount,
)
.set_timeout(30)
.build()
)
transaction.sign(source_keypair)
res = server.submit_transaction(transaction)
response = make_response(403, res['extras']['result_codes'])
return response
except Exception as e:
data = json.loads(str(e))
response = make_response(403, data['extras']['result_codes'])
return response