'PYTHON - decoding terra transaction data
I'm trying to get all transactions info from the Terra block.
The transactions ale encoded in base64, after I decode them I get a byte string.
b'\n\x99\x07\n\xac\x01\n&/terra.wasm.v1beta1.MsgExecuteContract\x12\x81\x01\n,terra1wcj0ms2tdygtt7dc3rupyctk2khvgpczyle0ek\x12,terra1e25zllgag7j9xsun3me4stnye2pcg66234je3u\x1a#{"retract_bid":{"bid_idx":"74682"}}\n\xb0\x01\n&/terra.wasm.v1beta1.MsgExecuteContract\x12\x85\x01\n,terra1wcj0ms2tdygtt7dc3rupyctk2khvgpczyle0ek\x12,terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s\x1a\x15{"deposit_stable":{}}*\x10\n\x04uusd\x12\x0860000000\n\xa3\x04\n&/terra.wasm.v1beta1.MsgExecuteContract\x12\xf8\x03\n,terra1wcj0ms2tdygtt7dc3rupyctk2khvgpczyle0ek\x12,terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu\x1a\x99\x03{"send":{"amount":"50436243","contract":"terra13nk2cjepdzzwfqy740pxzpe3x75pd6g0grxm2z","msg":"eyJzdWJtaXRfYmlkIjp7InByZW1pdW1fc2xvdCI6NiwiY29sbGF0ZXJhbF90b2tlbiI6InRlcnJhMWtjODdtdTQ2MGZ3a3F0ZTI5cnF1aDRoYzIwbTU0Znh3dHN4N2dwIiwic3RyYXRlZ3kiOnsiYWN0aXZhdGVfYXQiOnsibHR2Ijo5NSwiY3VtdWxhdGl2ZV92YWx1ZSI6IjIwMDAwMDAwMDAwMDAifSwiZGVhY3RpdmF0ZV9hdCI6eyJsdHYiOjk1LCJjdW11bGF0aXZlX3ZhbHVlIjoiMTAwMDAwMDAwMDAwIn19fX0="}}\x12\x0forca.kujira.app\x12i\nQ\nF\n\x1f/cosmos.crypto.secp256k1.PubKey\x12#\n!\x03\t\x16k\xd7\xd6\xfc\xfd4\xe7\x88\x91.\x1b\x01\xbe\xfa\x13E\xda\x95k:e\xbbR!p!\x97?r?\x12\x04\n\x02\x08\x01\x18\xf1\x02\x12\x14\n\x0e\n\x04uusd\x12\x06246255\x10\xde\x99d\x1a@X\x04H\xaeU6\xa2H@\xfe\x93/,b\x80g\xeaKT\xe1\xb2\xacg\xc7\x12\xff\xe7\x0c\x0c\x1d\x1f\x84\x18\xdf\xd51\xcd\x90TU\xe7\xaa\x93\n\xcc\xf1)a~\xef\xf5A\xb8)\\N\xbf\xfc\xc58\xd5\xdb~\xb3'
However I'm unable to decode the byte string.
Any idea how to decode this to get the transaction details in json?
Solution 1:[1]
It seems to me, that this is possible with terra sdk. And the overall code will be something like:
from terra_sdk.client.lcd import LCDClient
from terra_sdk.core.tx import Tx
terra = LCDClient(chain_id="columbus-5", url="https://lcd.terra.dev")
block = terra.tendermint.block_info()
tx = block['block']['data']['txs'][0]
tx = terra.tx.decode(tx)
Tx.from_proto(tx)
However right now there are some bugs in the SDK itself, but the maintainer promises these will be fixed ASAP.
See this thread for additional info: https://github.com/terra-money/terra.py/issues/55
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | stolpa4 |
