funga

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

commit 2c34777ff13a24859a4d291cc75d9cf480384bea
parent 14e3581b3d760157d8649392e335ac1166077d87
Author: nolash <dev@holbrook.no>
Date:   Sat, 17 Oct 2020 14:47:01 +0200

No middleware if no ipc, add prefix env var

Diffstat:
MCHANGELOG | 3+++
Mconfig/config.ini | 1-
Mcrypto_dev_signer/eth/web3ext/__init__.py | 7++++---
Mcrypto_dev_signer/eth/web3ext/middleware.py | 5+++--
Mcrypto_dev_signer/keystore/postgres.py | 1+
Mscripts/crypto-dev-daemon | 19++++++++++++-------
Msetup.py | 2+-
7 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -1,3 +1,6 @@ +* 0.2.5 + - Add default env override + - Do not create middleware if ipc no set * 0.2.4 - Remove hardcoded ipc path in middleware * 0.2.3 diff --git a/config/config.ini b/config/config.ini @@ -1,4 +1,3 @@ [signer] secret = deadbeef -database = crypto-dev-signer socket_path = /tmp/crypto-dev-signer/jsonrpc.ipc diff --git a/crypto_dev_signer/eth/web3ext/__init__.py b/crypto_dev_signer/eth/web3ext/__init__.py @@ -8,14 +8,13 @@ re_websocket = re.compile('^wss?://') re_http = re.compile('^https?://') -#def create_middleware(ipcaddr='/var/run/cic-platform/cic.ipc'): def create_middleware(ipcpath): PlatformMiddleware.ipcaddr = ipcpath return PlatformMiddleware # overrides the original Web3 constructor -def Web3(blockchain_provider='ws://localhost:8546', ipcpath='/run/crypto-dev-signer/jsonrpc.ipc'): +def Web3(blockchain_provider='ws://localhost:8546', ipcpath=None): provider = None if re.match(re_websocket, blockchain_provider) != None: provider = WebsocketProvider(blockchain_provider) @@ -24,6 +23,8 @@ def Web3(blockchain_provider='ws://localhost:8546', ipcpath='/run/crypto-dev-sig w3 = Web3super(provider) - w3.middleware_onion.add(create_middleware(ipcpath)) + if ipcpath != None: + w3.middleware_onion.add(create_middleware(ipcpath)) + w3.eth.personal = w3.geth.personal return w3 diff --git a/crypto_dev_signer/eth/web3ext/middleware.py b/crypto_dev_signer/eth/web3ext/middleware.py @@ -23,12 +23,13 @@ class PlatformMiddleware: # hack workaround id_seq = -1 re_personal = re.compile('^personal_.*') - ipcaddr = '/tmp/foo.ipc' + ipcaddr = None def __init__(self, make_request, w3): self.w3 = w3 self.make_request = make_request + raise AttributeError('ipcaddr not set') # TODO: understand what format input params come in @@ -51,7 +52,7 @@ class PlatformMiddleware: def __call__(self, method, suspect_params): self.id_seq += 1 - logg.debug('in middleware method {} params {}'.format(method, suspect_params)) + logg.debug('in middleware method {} params {} ipcpath {}'.format(method, suspect_params, self.ipcaddr)) if self.re_personal.match(method) != None: params = PlatformMiddleware._translate_params(suspect_params) diff --git a/crypto_dev_signer/keystore/postgres.py b/crypto_dev_signer/keystore/postgres.py @@ -39,6 +39,7 @@ class ReferenceKeystore(Keystore): logg.debug('dsn {}'.format(dsn)) self.conn = psycopg2.connect(make_dsn(dsn)) self.cur = self.conn.cursor() + self.cur.execute(self.schema[0]) self.symmetric_key = kwargs.get('symmetric_key') diff --git a/scripts/crypto-dev-daemon b/scripts/crypto-dev-daemon @@ -28,29 +28,32 @@ socket_path = '/run/crypto-dev-signer/jsonrpc.ipc' argparser = argparse.ArgumentParser() argparser.add_argument('-c', type=str, default=config_dir, help='config file') -argparser.add_argument('--env-prefix', dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration') +argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration') argparser.add_argument('-i', type=int, help='default chain id for EIP155') argparser.add_argument('-s', type=str, help='socket path') argparser.add_argument('-v', action='store_true', help='be verbose') argparser.add_argument('-vv', action='store_true', help='be more verbose') args = argparser.parse_args() -config = confini.Config(args.c, args.env_prefix) -config.process() - if args.vv: logging.getLogger().setLevel(logging.DEBUG) elif args.v: logging.getLogger().setLevel(logging.INFO) +config = confini.Config(args.c, args.env_prefix) +config.process() +config.censor('PASSWORD', 'DATABASE') +config.censor('SECRET', 'SIGNER') +logg.debug('config loaded from {}:\n{}'.format(config_dir, config)) + if args.i: chainId = args.i - if args.s: socket_path = args.s elif config.get('SIGNER_SOCKET_PATH'): socket_path = config.get('SIGNER_SOCKET_PATH') + # connect to database dsn = 'postgresql://{}:{}@{}:{}/{}'.format( config.get('DATABASE_USER'), @@ -60,6 +63,10 @@ dsn = 'postgresql://{}:{}@{}:{}/{}'.format( config.get('DATABASE_NAME'), ) +logg.info('using dsn {}'.format(dsn)) +logg.info('using socket {}'.format(socket_path)) + + class MissingSecretError(BaseException): def __init__(self, message): @@ -201,8 +208,6 @@ def init(): kw = { 'symmetric_key': secret, } - #db = ReferenceKeystore(os.environ.get('SIGNER_DATABASE', 'cic_signer'), **kw) - #db = ReferenceKeystore(config.get('SIGNER_DATABASE'), **kw) db = ReferenceKeystore(dsn, **kw) signer = ReferenceSigner(db) diff --git a/setup.py b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name="crypto-dev-signer", - version="0.2.4", + version="0.2.5", description="A signer and keystore daemon and library for cryptocurrency software development", author="Louis Holbrook", author_email="dev@holbrook.no",