Revert "Add tx reverse re-pack"

This reverts commit b9788adb18.
This commit is contained in:
nolash 2021-06-15 11:22:35 +02:00
parent 8f05913261
commit 9f799a9805
4 changed files with 6 additions and 80 deletions

View File

@ -14,7 +14,6 @@ from rlp import decode as rlp_decode
from rlp import encode as rlp_encode
from crypto_dev_signer.eth.transaction import EIP155Transaction
from crypto_dev_signer.encoding import public_key_to_address
from crypto_dev_signer.eth.encoding import chain_id_to_v
from potaahto.symbols import snake_and_camel
@ -72,25 +71,6 @@ def count_confirmed(address):
return count(address, True)
def pack(tx_src, chain_spec):
if isinstance(tx_src, Tx):
tx_src = tx_src.as_dict()
tx = EIP155Transaction(tx_src, tx_src['nonce'], chain_spec.chain_id())
signature = bytearray(65)
cursor = 0
for a in [
tx_src['r'],
tx_src['s'],
]:
for b in bytes.fromhex(strip_0x(a)):
signature[cursor] = b
cursor += 1
signature[cursor] = tx_src['v']
tx.apply_signature(chain_spec.chain_id(), signature, literal_v=True)
return tx.rlp_serialize()
def unpack(tx_raw_bytes, chain_spec):
chain_id = chain_spec.chain_id()
tx = __unpack_raw(tx_raw_bytes, chain_id)
@ -174,11 +154,10 @@ def __unpack_raw(tx_raw_bytes, chain_id=1):
'gas': d[2],
'value': d[4],
'data': data,
'v': v,
'recovery_byte': vb,
'v': chain_id,
'r': add_0x(sig[:32].hex()),
's': add_0x(sig[32:64].hex()),
'chainId': vb, #chain_id,
'chainId': chain_id,
'hash': add_0x(signed_hash.hex()),
'hash_unsigned': add_0x(unsigned_hash.hex()),
}
@ -398,10 +377,6 @@ class Tx:
return snake_and_camel(src)
def as_dict(self):
return self.src
def apply_receipt(self, rcpt):
rcpt = self.src_normalize(rcpt)
logg.debug('rcpt {}'.format(rcpt))

View File

@ -1,4 +1,4 @@
crypto-dev-signer~=0.4.14b5
crypto-dev-signer~=0.4.14b3
pysha3==1.0.2
hexathon~=0.0.1a7
websocket-client==0.57.0

View File

@ -1,6 +1,6 @@
[metadata]
name = chainlib
version = 0.0.3rc4
version = 0.0.3rc3
description = Generic blockchain access library and tooling
author = Louis Holbrook
author_email = dev@holbrook.no

View File

@ -1,7 +1,5 @@
# standard imports
import os
import unittest
import logging
# local imports
from chainlib.eth.unittest.ethtester import EthTesterCase
@ -12,26 +10,9 @@ from chainlib.eth.gas import (
)
from chainlib.eth.tx import (
unpack,
pack,
raw,
transaction,
TxFormat,
TxFactory,
Tx,
)
from chainlib.eth.contract import (
ABIContractEncoder,
ABIContractType,
)
from chainlib.eth.address import to_checksum_address
from hexathon import (
strip_0x,
add_0x,
)
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
from hexathon import strip_0x
class TxTestCase(EthTesterCase):
@ -45,35 +26,5 @@ class TxTestCase(EthTesterCase):
self.assertEqual(tx['to'], self.accounts[1])
def test_tx_pack(self):
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
gas_oracle = RPCGasOracle(self.rpc)
mock_contract = to_checksum_address(add_0x(os.urandom(20).hex()))
f = TxFactory(self.chain_spec, signer=self.rpc)
enc = ABIContractEncoder()
enc.method('fooMethod')
enc.typ(ABIContractType.UINT256)
enc.uint256(13)
data = enc.get()
tx = f.template(self.accounts[0], mock_contract, use_nonce=True)
tx = f.set_code(tx, data)
(tx_hash, tx_signed_raw_hex) = f.finalize(tx, TxFormat.RLP_SIGNED)
logg.debug('tx result {}'.format(tx))
o = raw(tx_signed_raw_hex)
r = self.rpc.do(o)
o = transaction(tx_hash)
tx_rpc_src = self.rpc.do(o)
logg.debug('rpc src {}'.format(tx_rpc_src))
tx_signed_raw_bytes = bytes.fromhex(strip_0x(tx_signed_raw_hex))
tx_src = unpack(tx_signed_raw_bytes, self.chain_spec)
txo = Tx(tx_src)
tx_signed_raw_bytes_recovered = pack(txo, self.chain_spec)
logg.debug('o {}'.format(tx_signed_raw_bytes.hex()))
logg.debug('r {}'.format(tx_signed_raw_bytes_recovered.hex()))
self.assertEqual(tx_signed_raw_bytes, tx_signed_raw_bytes_recovered)
if __name__ == '__main__':
unittest.main()