Add raw tx to error logging when tx send fails

This commit is contained in:
nolash 2021-01-27 13:33:52 +01:00
parent e6072da8e4
commit c8ce2659a3
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
5 changed files with 20 additions and 7 deletions

View File

@ -4,3 +4,7 @@ class UnknownAccountError(Exception):
class TransactionRevertError(Exception): class TransactionRevertError(Exception):
pass pass
class NetworkError(Exception):
pass

View File

@ -3,6 +3,7 @@ import logging
# local imports # local imports
from crypto_dev_signer.helper import TxExecutor from crypto_dev_signer.helper import TxExecutor
from crypto_dev_signer.error import NetworkError
logg = logging.getLogger() logg = logging.getLogger()
logging.getLogger('web3').setLevel(logging.CRITICAL) logging.getLogger('web3').setLevel(logging.CRITICAL)
@ -30,7 +31,14 @@ class EthTxExecutor(TxExecutor):
def dispatcher(self, tx): def dispatcher(self, tx):
return self.w3.eth.sendRawTransaction(tx) error_object = None
try:
tx_hash = self.w3.eth.sendRawTransaction(tx)
except ValueError as e:
error_object = e.args[0]
logg.error('node could not intepret rlp {}'.format(tx))
if error_object != None:
raise NetworkError(error_object)
def reporter(self, tx): def reporter(self, tx):

View File

@ -165,14 +165,14 @@ def process_input(j):
return (rpc_id, methods[m](p)) return (rpc_id, methods[m](p))
def start_server_lo(spec): def start_server_tcp(spec):
s = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM) s = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM)
s.bind(spec) s.bind(spec)
logg.debug('created tcp socket {}'.format(spec)) logg.debug('created tcp socket {}'.format(spec))
start_server(s) start_server(s)
def start_server_ipc(socket_path): def start_server_unix(socket_path):
socket_dir = os.path.dirname(socket_path) socket_dir = os.path.dirname(socket_path)
try: try:
fi = os.stat(socket_dir) fi = os.stat(socket_dir)
@ -190,6 +190,7 @@ def start_server_ipc(socket_path):
logg.debug('created unix ipc socket {}'.format(socket_path)) logg.debug('created unix ipc socket {}'.format(socket_path))
start_server(s) start_server(s)
def start_server(s): def start_server(s):
s.listen(10) s.listen(10)
logg.debug('server started') logg.debug('server started')
@ -251,9 +252,9 @@ def main():
if len(socket_spec) == 2: if len(socket_spec) == 2:
host = socket_spec[0] host = socket_spec[0]
port = int(socket_spec[1]) port = int(socket_spec[1])
start_server_lo((host, port)) start_server_tcp((host, port))
else: else:
start_server_ipc(socket_path) start_server_unix(socket_path)
sys.exit(0) sys.exit(0)
(rpc_id, response) = process_input(arg) (rpc_id, response) = process_input(arg)

View File

@ -24,7 +24,7 @@ f.close()
setup( setup(
name="crypto-dev-signer", name="crypto-dev-signer",
version="0.4.13b11", version="0.4.13b12",
description="A signer and keystore daemon and library for cryptocurrency software development", description="A signer and keystore daemon and library for cryptocurrency software development",
author="Louis Holbrook", author="Louis Holbrook",
author_email="dev@holbrook.no", author_email="dev@holbrook.no",

View File

@ -81,7 +81,7 @@ class TestHelper(unittest.TestCase):
def test_eth_helper(self): def test_eth_helper(self):
backend = MockEthTxBackend() backend = MockEthTxBackend()
w3 = web3.Web3(web3.Web3.HTTPProvider('http://localhost:8545')) w3 = web3.Web3(web3.Web3.HTTPProvider('http://localhost:8545'))
executor = EthTxExecutor(w3, self.address_hex, self.signer, 8996) executor = EthTxExecutor(w3, self.address_hex, self.signer, 1337)
tx_ish = {'from': self.address_hex} tx_ish = {'from': self.address_hex}
#executor.sign_and_send([backend.builder, backend.builder_two]) #executor.sign_and_send([backend.builder, backend.builder_two])