Add configs
This commit is contained in:
parent
44c62a658b
commit
06962b3365
@ -1,3 +1,5 @@
|
|||||||
|
* 0.2.2
|
||||||
|
- Use confini for configurations
|
||||||
* 0.2.1
|
* 0.2.1
|
||||||
- Fix hardcoded daemon signTransaction nonce
|
- Fix hardcoded daemon signTransaction nonce
|
||||||
* 0.2.0
|
* 0.2.0
|
||||||
|
4
config/config.ini
Normal file
4
config/config.ini
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[signer]
|
||||||
|
secret = deadbeef
|
||||||
|
database = crypto-dev-signer
|
||||||
|
socket_path = /tmp/crypto-dev-signer/jsonrpc.ipc
|
@ -1,23 +1,55 @@
|
|||||||
#!/usr/bin/python3
|
# standard imports
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import stat
|
||||||
import socket
|
import socket
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import argparse
|
||||||
import os
|
|
||||||
|
|
||||||
|
# third-party imports
|
||||||
|
import confini
|
||||||
from jsonrpc.exceptions import *
|
from jsonrpc.exceptions import *
|
||||||
|
|
||||||
|
# local imports
|
||||||
from crypto_dev_signer.eth.signer import ReferenceSigner
|
from crypto_dev_signer.eth.signer import ReferenceSigner
|
||||||
from crypto_dev_signer.eth.transaction import EIP155Transaction
|
from crypto_dev_signer.eth.transaction import EIP155Transaction
|
||||||
from crypto_dev_signer.keystore import ReferenceKeystore
|
from crypto_dev_signer.keystore import ReferenceKeystore
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
#logging.basicConfig(level=logging.DEBUG)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
|
config_dir = os.path.join('/usr/local/etc/cic-eth')
|
||||||
|
|
||||||
db = None
|
db = None
|
||||||
signer = None
|
signer = None
|
||||||
chainId = 8995
|
chainId = 8995
|
||||||
|
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('-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)
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
|
||||||
class MissingSecretError(BaseException):
|
class MissingSecretError(BaseException):
|
||||||
@ -25,8 +57,6 @@ class MissingSecretError(BaseException):
|
|||||||
def __init__(self, message):
|
def __init__(self, message):
|
||||||
super(MissingSecretError, self).__init__(message)
|
super(MissingSecretError, self).__init__(message)
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def personal_new_account(p):
|
def personal_new_account(p):
|
||||||
password = p
|
password = p
|
||||||
@ -108,12 +138,20 @@ def process_input(j):
|
|||||||
|
|
||||||
|
|
||||||
def start_server():
|
def start_server():
|
||||||
|
socket_dir = os.path.dirname(socket_path)
|
||||||
try:
|
try:
|
||||||
os.unlink('/tmp/foo.ipc')
|
fi = os.stat(socket_dir)
|
||||||
|
if not stat.S_ISDIR:
|
||||||
|
RuntimeError('socket path {} is not a directory'.format(socket_dir))
|
||||||
|
except FileNotFoundError:
|
||||||
|
os.mkdir(socket_dir)
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.unlink(socket_path)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
s = socket.socket(family = socket.AF_UNIX, type = socket.SOCK_STREAM)
|
s = socket.socket(family = socket.AF_UNIX, type = socket.SOCK_STREAM)
|
||||||
s.bind('/tmp/foo.ipc')
|
s.bind(socket_path)
|
||||||
s.listen(10)
|
s.listen(10)
|
||||||
while True:
|
while True:
|
||||||
(csock, caddr) = s.accept()
|
(csock, caddr) = s.accept()
|
||||||
@ -131,8 +169,10 @@ def start_server():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
(rpc_id, r) = process_input(j)
|
(rpc_id, r) = process_input(j)
|
||||||
csock.send(json.dumps(jsonrpc_ok(rpc_id, r)).encode('utf-8'))
|
r = jsonrpc_ok(rpc_id, r)
|
||||||
except Exception as e:
|
j = json.dumps(r).encode('utf-8')
|
||||||
|
csock.send(j)
|
||||||
|
except ValueError as e:
|
||||||
# TODO: handle cases to give better error context to caller
|
# TODO: handle cases to give better error context to caller
|
||||||
logg.error('process error {}'.format(e))
|
logg.error('process error {}'.format(e))
|
||||||
csock.send(json.dumps(jsonrpc_error(j['id'], JSONRPCServerError)).encode('utf-8'))
|
csock.send(json.dumps(jsonrpc_error(j['id'], JSONRPCServerError)).encode('utf-8'))
|
||||||
@ -140,22 +180,21 @@ def start_server():
|
|||||||
csock.close()
|
csock.close()
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
os.unlink('/tmp/foo.ipc')
|
os.unlink(socket_path)
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
global db, signer
|
global db, signer
|
||||||
secret_hex = ''
|
secret_hex = config.get('SIGNER_SECRET')
|
||||||
try:
|
if secret_hex == None:
|
||||||
secret_hex = os.environ['SIGNER_SECRET']
|
raise MissingSecretError('please provide a valid hex value for the SIGNER_SECRET configuration variable')
|
||||||
except KeyError as e:
|
|
||||||
raise MissingSecretError('please set the SIGNER_SECRET environment variable to a valid hex value')
|
|
||||||
|
|
||||||
secret = bytes.fromhex(secret_hex)
|
secret = bytes.fromhex(secret_hex)
|
||||||
kw = {
|
kw = {
|
||||||
'symmetric_key': secret,
|
'symmetric_key': secret,
|
||||||
}
|
}
|
||||||
db = ReferenceKeystore(os.environ.get('SIGNER_DATABASE', 'cic_signer'), **kw)
|
#db = ReferenceKeystore(os.environ.get('SIGNER_DATABASE', 'cic_signer'), **kw)
|
||||||
|
db = ReferenceKeystore(config.get('SIGNER_DATABASE'), **kw)
|
||||||
signer = ReferenceSigner(db)
|
signer = ReferenceSigner(db)
|
||||||
|
|
||||||
|
|
||||||
|
3
setup.cfg
Normal file
3
setup.cfg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[metadata]
|
||||||
|
license = GPLv3
|
||||||
|
license_file = LICENSE.txt
|
13
setup.py
13
setup.py
@ -2,7 +2,7 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="crypto-dev-signer",
|
name="crypto-dev-signer",
|
||||||
version="0.2.1",
|
version="0.2.2",
|
||||||
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",
|
||||||
@ -13,7 +13,16 @@ setup(
|
|||||||
'crypto_dev_signer.keystore',
|
'crypto_dev_signer.keystore',
|
||||||
'crypto_dev_signer',
|
'crypto_dev_signer',
|
||||||
],
|
],
|
||||||
install_requires=['web3', 'psycopg2', 'cryptography', 'eth-keys', 'pysha3', 'rlp', 'json-rpc'],
|
install_requires=[
|
||||||
|
'web3',
|
||||||
|
'psycopg2',
|
||||||
|
'cryptography',
|
||||||
|
'eth-keys',
|
||||||
|
'pysha3',
|
||||||
|
'rlp',
|
||||||
|
'json-rpc',
|
||||||
|
'confini==0.2.1',
|
||||||
|
],
|
||||||
scripts = [
|
scripts = [
|
||||||
'scripts/crypto-dev-daemon',
|
'scripts/crypto-dev-daemon',
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user