-1

I have a struct pack like

def encode_number(value):
    return struct.pack('>I', value)


def decode_number(raw):
    return int.from_bytes(raw, byteorder='big') 

>>> encode_number(1) b'\x00\x00\x00\x01'

>>> decode_number(b'\x00\x00\x00\x01') 1

while the transcations given via curl are given in Hex like curl http://localhost:26657/broadcast_tx_commit?tx=0x01

So 0x01 is 1 in hex,how do you convert your binary string to hex easily for curl command ? (preferable in a linux terminal)

Gautham Santhosh
  • 797
  • 1
  • 10
  • 21

1 Answers1

0

Just did a google search and came across this: https://unix.stackexchange.com/questions/65280/binary-to-hexadecimal-and-decimal-in-a-shell-script

The example they use for Binary to Hex (Bash/Linux Terminal):

$ printf '%x\n' "$((2#101010101))"
155
Caleb Lawrence
  • 131
  • 1
  • 4
  • 11
  • so do you `curl http://localhost:26657/broadcast_tx_commit?tx=0x115` or `curl http://localhost:26657/broadcast_tx_commit?tx=115` ? I tired both and was showing errors – Gautham Santhosh Nov 20 '18 at 19:27
  • Not sure really. My guess is that it would depend on the backend. Can you try both? The "0x115" makes more sense to me. – Caleb Lawrence Nov 20 '18 at 19:29