-1

Greetings Stellar StackExchange community,

I would kindly require your assistance as I am having hard time figuring out how to get the incoming transaction amount value, and what would be the most appropriate way to do it for my personal account.

Currently I have function which return transactions, but this ones include memo, fees, hash, xdr_envelope and so on, however not amount. What I need for my "app" is TX HASH, MEMO, VALUE and PAGING token as I am storing them into database.

def get_transactions(self):
        data = server.transactions().for_account(account_id=self.public_key).include_failed(False).call()
        for tx in data['_embedded']['records']:
            te = TransactionEnvelope.from_xdr(tx['envelope_xdr'], Network.TESTNET_NETWORK_PASSPHRASE)
            pprint(te)

While pretty printing each TransactionEnvelope, I am getting back object but not values.

I have been as well looking at the post How to decode XDR of the result_xdr however due to the new package for python I "hit the wall".

I tried as well use Payments For Account while amount is returned however there is no Memo.

 data = server.payments().for_account(account_id=self.public_key).call()
 pprint(data['_embedded']['records'])

Could you please help me resolve the issues I am having?

thank you for your time, answer and assistance in advance, and hope to get response soon.

best regards

Animus

1

A stellar transaction consists of one or more operations such as payment, createAccount, setOptions.

I'm not familiar with python-sdk but I think like in other sdk's the transaction object should also have a operations method or property which should deliver all related operations. You have to iterate through the operations of a given transaction (for op in tx['operations']), figure out if it is a payment operation (if op['type'] == 'payment') and then access asset and amount on that object (op['asset'], op['amount'])

1

At first, I recommend you read this article, which describes the composition of a transaction.

Hope this example helps.

from stellar_sdk import TransactionEnvelope, Network, TextMemo, IdMemo, HashMemo, ReturnHashMemo, Payment

envelope_xdr = 'AAAAAD11sXdkWzZ8LQrxr5zWXdrI6CK5Pz/+e3RGX8RqzmPYAAAAyAAAAAAAAABlAAAAAAAAAAEAAAAKaGVsbG8gbWVtbwAAAAAAAgAAAAAAAAABAAAAANBtml/avnYRS9MeyvimlMQRJU/oq1JvHfDviocRc6feAAAAAAAAAAA7wO+gAAAAAAAAAAEAAAAAGH7pPQgWjoQcf+QW/EeDjc6Y1T1/j10jRm9kjpyvCXsAAAABWENOAAAAAACHPQ4p8zj3+dCkTJ/erv3iHXpZxAesYy04momcXmgwKwAAAAA7wO+gAAAAAAAAAAFqzmPYAAAAQBDpbZ5Nf6lv2yvxwEF0K7Sxtvft3vojJRrSAGvlnQwn9fHWAK6876/Abb0OtBUOvpxzyNrBagWGttvAiJLbaQU='

te = TransactionEnvelope.from_xdr(envelope_xdr, Network.TESTNET_NETWORK_PASSPHRASE)
tx_hash = te.hash_hex()
print(f"hash: {tx_hash}")
raw_memo = te.transaction.memo
memo = None
if isinstance(raw_memo, TextMemo):
    memo = raw_memo.memo_text
if isinstance(raw_memo, IdMemo):
    memo = raw_memo.memo_id
if isinstance(raw_memo, HashMemo):
    memo = raw_memo.memo_hash
if isinstance(raw_memo, ReturnHashMemo):
    memo = raw_memo.memo_return
print(f"memo: {memo}")
operations = te.transaction.operations
for op in operations:
    # You can check other types of operations here.
    # You can find list of operations here: https://stellar-sdk.readthedocs.io/en/latest/api.html#operation
    if isinstance(op, Payment):
        amount = op.amount
        asset_code = op.asset.code
        asset_issuer = op.asset.issuer
        destination = op.destination
        source = op.source or te.transaction.source.public_key
        print(f"{source} send {amount} {asset_code}({asset_issuer}) to {destination}")
1
  • Thank you for response
    – Animus
    Mar 12 '20 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.