5

So my code is:

envelope = Te(tx=tx, opts={"network_id": "TESTNET"})
envelope.sign(receiving_account)

xdr = envelope.xdr()
response = horizon.submit(xdr)  # TO DO: Have to check if done well
print('CHANGE TRUST RESPONSE')
print(response['result_xdr'])
print('==========================================')

Unlike Asset and Transaction I find no way to decode the XDR of TransactionResult. On submitting the transaction I want to know whether it is successful or not.

Thanks

3 Answers 3

5

It is possible to decode XDR objects by using the stellar_base.stellarxdr module.

from stellar_base.stellarxdr import Xdr
import base64

result_bytes = base64.b64decode(response['result_xdr'])
tx_result = Xdr.StellarXDRUnpacker(result_bytes).unpack_TransactionResult()

To get a hold of the contents as readable text:
import jsonpickle

p = jsonpickle.Pickler(keys=True)
print(p.flatten(tx_result))

Note that if you just want to check if the transaction was successful you can see that from the horizon response without the need to decode the transaction result.

2
  • Thanks for your response, it prints TransactionResult(feeCharged=100, result=<stellar_base.stellarxdr.StellarXDR_pack.nullclass object at 0x10aa60ef0>, ext=<stellar_base.stellarxdr.StellarXDR_pack.nullclass object at 0x10aa79668>) From this, how do I extract the result part as it's shown in XDR? I want to store the result text for audit purpose otherwise I know that JSON text should be suffice
    – Volatil3
    May 20, 2018 at 18:09
  • For accepted valid transactions via Horizon, you get JSON like: { "_links": { "transaction": { "href": "horizon-testnet.XXX" } }, "hash": "XXX", "ledger": 9072556, "envelope_xdr": "XXX", "result_xdr": "XXX", "result_meta_xdr": "XXX" }......how about making a quick query against Horizon, using "hash" at http: //__HORIZON__/transactions/<<HASH>>?
    – cesarm
    May 21, 2018 at 1:29
0

Or try the UI version for XDR decoder at Lab, if just handling a few XDR?

https://www.stellar.org/laboratory/#xdr-viewer?type=TransactionEnvelope&network=test

Need to choose the "XDR type".

0

Added this to the answer:

To get a hold of the contents as readable text:

import jsonpickle

p = jsonpickle.Pickler(keys=True)
print(p.flatten(tx_result))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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