Add base config
This commit is contained in:
parent
388910a4ac
commit
a6420eacfb
18
chaind_eth/data/config/config.ini
Normal file
18
chaind_eth/data/config/config.ini
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
[session]
|
||||||
|
socket_path =
|
||||||
|
runtime_dir =
|
||||||
|
id =
|
||||||
|
data_dir =
|
||||||
|
|
||||||
|
[chain]
|
||||||
|
spec = evm:ethereum:1
|
||||||
|
|
||||||
|
[database]
|
||||||
|
engine =
|
||||||
|
name = chaind_eth
|
||||||
|
driver =
|
||||||
|
user =
|
||||||
|
password =
|
||||||
|
host =
|
||||||
|
port =
|
||||||
|
debug = 0
|
@ -26,6 +26,9 @@ from chainqueue.adapters.eth import EthAdapter
|
|||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
||||||
|
|
||||||
env = Environment(domain='eth', env=os.environ)
|
env = Environment(domain='eth', env=os.environ)
|
||||||
|
|
||||||
argparser = argparse.ArgumentParser('chainqueue transaction submission and trigger server')
|
argparser = argparse.ArgumentParser('chainqueue transaction submission and trigger server')
|
||||||
@ -45,11 +48,11 @@ elif args.v:
|
|||||||
logg.setLevel(logging.INFO)
|
logg.setLevel(logging.INFO)
|
||||||
|
|
||||||
# process config
|
# process config
|
||||||
config = confini.Config(args.c)
|
config = confini.Config(config_dir, override_dirs=[args.c])
|
||||||
config.process()
|
config.process()
|
||||||
args_override = {
|
args_override = {
|
||||||
'SESSION_RUNTIME_DIR': getattr(args, 'runtime_dir'),
|
'SESSION_RUNTIME_DIR': getattr(args, 'runtime_dir'),
|
||||||
'SESSION_CHAIN_SPEC': getattr(args, 'i'),
|
'CHAIN_SPEC': getattr(args, 'i'),
|
||||||
'RPC_ENDPOINT': getattr(args, 'p'),
|
'RPC_ENDPOINT': getattr(args, 'p'),
|
||||||
'SESSION_DATA_DIR': getattr(args, 'data_dir'),
|
'SESSION_DATA_DIR': getattr(args, 'data_dir'),
|
||||||
'SESSION_ID': getattr(args, 'session_id'),
|
'SESSION_ID': getattr(args, 'session_id'),
|
||||||
@ -115,13 +118,21 @@ ctrl = SessionController(config)
|
|||||||
signal.signal(signal.SIGINT, ctrl.shutdown)
|
signal.signal(signal.SIGINT, ctrl.shutdown)
|
||||||
signal.signal(signal.SIGTERM, ctrl.shutdown)
|
signal.signal(signal.SIGTERM, ctrl.shutdown)
|
||||||
|
|
||||||
chain_spec = ChainSpec.from_chain_str(config.get('SESSION_CHAIN_SPEC'))
|
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
||||||
|
|
||||||
dsn = dsn_from_config(config)
|
dsn = dsn_from_config(config)
|
||||||
backend = SQLBackend(dsn, debug=config.true('DATABASE_DEBUG'))
|
backend = SQLBackend(dsn, debug=config.true('DATABASE_DEBUG'))
|
||||||
adapter = EthAdapter(backend)
|
adapter = EthAdapter(backend)
|
||||||
rpc = EthHTTPConnection(url=config.get('RPC_ENDPOINT'), chain_spec=chain_spec)
|
rpc = EthHTTPConnection(url=config.get('RPC_ENDPOINT'), chain_spec=chain_spec)
|
||||||
|
|
||||||
|
|
||||||
|
def process_outgoing(chain_spec, adapter, rpc):
|
||||||
|
dispatcher = Dispatcher(chain_spec, adapter)
|
||||||
|
session = adapter.create_session()
|
||||||
|
r = dispatcher.process(rpc, session)
|
||||||
|
session.close()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
havesends = 0
|
havesends = 0
|
||||||
while True:
|
while True:
|
||||||
@ -140,10 +151,7 @@ def main():
|
|||||||
break
|
break
|
||||||
if srvs == None:
|
if srvs == None:
|
||||||
logg.debug('timeout (remote socket is none)')
|
logg.debug('timeout (remote socket is none)')
|
||||||
dispatcher = Dispatcher(chain_spec, adapter)
|
process_outgoing(chain_spec, adapter, rpc)
|
||||||
session = backend.create_session()
|
|
||||||
r = dispatcher.process(rpc, session)
|
|
||||||
session.close()
|
|
||||||
if r > 0:
|
if r > 0:
|
||||||
ctrl.srv.settimeout(0.1)
|
ctrl.srv.settimeout(0.1)
|
||||||
else:
|
else:
|
||||||
|
@ -24,6 +24,16 @@ class EthAdapter(Adapter):
|
|||||||
return tx
|
return tx
|
||||||
|
|
||||||
|
|
||||||
|
def dispatch(self, chain_spec, rpc, tx_hash, signed_tx, session=None):
|
||||||
|
o = raw(signed_tx)
|
||||||
|
r = self.backend.dispatch(chain_spec, rpc, tx_hash, o)
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
def upcoming(self, chain_spec, session=None):
|
||||||
|
return self.backend.get(chain_spec, StatusBits.QUEUED, self.translate) # possible maldesign, up-stack should use our session?
|
||||||
|
|
||||||
|
|
||||||
def add(self, chain_spec, bytecode, session=None):
|
def add(self, chain_spec, bytecode, session=None):
|
||||||
tx = self.translate(chain_spec, bytecode)
|
tx = self.translate(chain_spec, bytecode)
|
||||||
r = self.backend.create(chain_spec, tx['nonce'], tx['from'], tx['hash'], add_0x(bytecode.hex()), session=session)
|
r = self.backend.create(chain_spec, tx['nonce'], tx['from'], tx['hash'], add_0x(bytecode.hex()), session=session)
|
||||||
|
Loading…
Reference in New Issue
Block a user