commit b2f46c5eebfa26bc6e5fa770cc5bedd45eb6ca16
parent 14d935bb6e801e92da7e842d61d1025a3de2ab21
Author: lash <dev@holbrook.no>
Date: Thu, 27 Jun 2024 16:11:09 +0100
Encode v value in tx src as hex
Diffstat:
3 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,3 +1,5 @@
+- 0.6.4
+ * Encode v value in tx src as hex to make compatible with go-ethereum parsing
- 0.6.3
* Accept both "input" and "data" as parameter key for payload in base tx source
- 0.6.2
diff --git a/chainlib/eth/tx.py b/chainlib/eth/tx.py
@@ -2,6 +2,7 @@
import logging
import enum
import re
+import math
# external imports
import coincurve
@@ -12,6 +13,8 @@ from hexathon import (
compact,
to_int as hex_to_int,
same as hex_same,
+ unpad as hex_unpad,
+ int_to_minbytes,
)
from rlp import decode as rlp_decode
from rlp import encode as rlp_encode
@@ -216,6 +219,10 @@ def __unpack_raw(tx_raw_bytes, chain_id=1):
except:
data = '0x'
+ v_bytes = int_to_minbytes(v)
+ v_hex = v_bytes.hex()
+ v_hex = hex_unpad(v_hex)
+
return {
'from': a,
'to': to,
@@ -224,7 +231,7 @@ def __unpack_raw(tx_raw_bytes, chain_id=1):
'gas': d[2],
'value': d[4],
'data': data,
- 'v': v,
+ 'v': add_0x(v_hex, pad=False),
'recovery_byte': vb,
'r': add_0x(sig[:32].hex()),
's': add_0x(sig[32:64].hex()),
@@ -654,9 +661,20 @@ class Tx(BaseTx, Src):
except KeyError:
logg.debug('no inline raw tx self.src, and no raw rendering implemented, field will be "None"')
- self.v = self.src.get('v')
+ v = self.src.get('v')
+ if type(v).__name__ == 'int':
+ v = int_to_minbytes(v)
+ v = v.hex()
+ if len(v) == 0:
+ v = '0'
+ else:
+ v = hex_unpad(v)
+ v = add_0x(v, pad=False)
+ self.src['v'] = v
+
self.r = self.src.get('r')
self.s = self.src.get('s')
+ self.v = self.src.get('v')
def as_dict(self):
diff --git a/setup.cfg b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = chainlib-eth
-version = 0.6.3
+version = 0.6.4
description = Ethereum implementation of the chainlib interface
author = Louis Holbrook
author_email = dev@holbrook.no