Skip to content

Instantly share code, notes, and snippets.

@davaymne
Created December 13, 2020 18:57
Show Gist options
  • Save davaymne/a72af558016ae59bc407bd1361a53384 to your computer and use it in GitHub Desktop.
Save davaymne/a72af558016ae59bc407bd1361a53384 to your computer and use it in GitHub Desktop.
# Script to convert ipfs to b58decode, eg QmTN6gMCBCYTgbis33eSvr6sLsQoQ3R6a2KzR7CqmMABQP -> '0xdfffeffgkjfijfoiqfioqmfqiomfdfffeffgkjfijfoiqfioqmfqiomf
# Require: file with list of ipfs: each row is one ipfs
# Usage: python3 convert-ipfs-to-bytes32.py file.csv
import binascii
import base58
import sys
def ipfs_b32(ipfs):
output = base58.b58decode(ipfs)
output = output[2:]
# print(output)
return '0x' + binascii.hexlify(output).decode("utf-8")
#ipfs_b32('QmTN6gMCBCYTgbis33eSvr6sLsQoQ3R6a2KzR7CqmMABQP')
with open(sys.argv[1], 'r') as input_file:
with open(sys.argv[2], 'a+') as output_file:
for line in input_file:
b32 = ipfs_b32(line.strip())
output_file.write('{},{}'.format(line.strip(), b32))
print(b32)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment