Skip to content

Instantly share code, notes, and snippets.

@konradkonrad
Last active October 13, 2017 08:29
Show Gist options
  • Save konradkonrad/4874a74708a3ea3cbd007830b9a2acbe to your computer and use it in GitHub Desktop.
Save konradkonrad/4874a74708a3ea3cbd007830b9a2acbe to your computer and use it in GitHub Desktop.
geth pending tx to raw tx hex
#!/usr/bin/env python
import sys
import yaml
from ethereum.transactions import Transaction
from ethereum.utils import encode_hex, decode_hex
import rlp
def geth_tx_to_raw(tx):
for field in ['blockHash', 'blockNumber', 'hash', 'transactionIndex', 'from']:
tx.pop(field)
tx['gasprice'] = tx.pop('gasPrice')
tx['startgas'] = tx.pop('gas')
tx['data'] = decode_hex(tx.pop('input')[2:])
for f in ['v', 's', 'r']:
tx[f] = int(tx.pop(f), 0)
return '0x' + encode_hex(
rlp.encode(
Transaction.serialize(
Transaction(**tx)
)
)
)
if __name__ == '__main__':
if not len(sys.argv) > 1:
print(
'convert geth pendingTransactions format to raw signed hex format\n\n'
'Usage:\n\t'
'./geth_pending_to_raw.py <geth pending tx>\n\t'
'''./geth_pending_to_raw.py "$(geth attach geth.ipc --exec 'eth.pendingTransactions')"'''
)
sys.exit(0)
data = yaml.load(
sys.argv[1]
)
if isinstance(data, dict):
data = [data]
for tx in data:
print(tx)
print(geth_tx_to_raw(tx))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment