funga

Signer and keystore daemon and library for cryptocurrency software development
Log | Files | Refs | README | LICENSE

commit e6072da8e409ef16d32d3ab25aa655437536efaa
parent 5b8f07bafc1c5bdd1491c7421e321cddd202fa3d
Author: nolash <dev@holbrook.no>
Date:   Mon, 25 Jan 2021 18:22:06 +0100

Add tcp server

Diffstat:
MCHANGELOG | 1+
Mcrypto_dev_signer/runnable/signer.py | 26++++++++++++++++++++++----
Msetup.py | 2+-
3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -3,6 +3,7 @@ - Remove unused insert_key method in keystore interface - Add transaction executor helper, with adapter helper for eth - Fix bitlength of integers in all tx fields before rlp encoding + - Add tcp server * 0.4.12 - Enforce hex strings in signer backend for sign message * 0.4.11 diff --git a/crypto_dev_signer/runnable/signer.py b/crypto_dev_signer/runnable/signer.py @@ -17,10 +17,10 @@ from crypto_dev_signer.eth.transaction import EIP155Transaction from crypto_dev_signer.keystore import ReferenceKeystore from crypto_dev_signer.error import UnknownAccountError -#logging.basicConfig(level=logging.DEBUG) +logging.basicConfig(level=logging.WARNING) logg = logging.getLogger() -config_dir = os.path.join('/usr/local/etc/cic-eth') +config_dir = '.' db = None signer = None @@ -165,7 +165,14 @@ def process_input(j): return (rpc_id, methods[m](p)) -def start_server(): +def start_server_lo(spec): + s = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM) + s.bind(spec) + logg.debug('created tcp socket {}'.format(spec)) + start_server(s) + + +def start_server_ipc(socket_path): socket_dir = os.path.dirname(socket_path) try: fi = os.stat(socket_dir) @@ -180,7 +187,12 @@ def start_server(): pass s = socket.socket(family = socket.AF_UNIX, type = socket.SOCK_STREAM) s.bind(socket_path) + logg.debug('created unix ipc socket {}'.format(socket_path)) + start_server(s) + +def start_server(s): s.listen(10) + logg.debug('server started') while True: (csock, caddr) = s.accept() d = csock.recv(4096) @@ -235,7 +247,13 @@ def main(): arg = json.loads(sys.argv[1]) except: logg.info('no json rpc command detected, starting socket server') - start_server() + socket_spec = socket_path.split(':') + if len(socket_spec) == 2: + host = socket_spec[0] + port = int(socket_spec[1]) + start_server_lo((host, port)) + else: + start_server_ipc(socket_path) sys.exit(0) (rpc_id, response) = process_input(arg) diff --git a/setup.py b/setup.py @@ -24,7 +24,7 @@ f.close() setup( name="crypto-dev-signer", - version="0.4.13b10", + version="0.4.13b11", description="A signer and keystore daemon and library for cryptocurrency software development", author="Louis Holbrook", author_email="dev@holbrook.no",