Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f86e9c970
|
||
|
|
abc619d7b2
|
||
|
|
42aa809500
|
||
|
|
e31367853c
|
||
|
|
9522729fa0
|
||
|
|
097a6f4b53
|
||
|
|
8d0a1f589b
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@ build/
|
|||||||
*.egg-info
|
*.egg-info
|
||||||
*.sqlite
|
*.sqlite
|
||||||
.coverage
|
.coverage
|
||||||
|
.chaind
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
from chainlib.interface import ChainInterface
|
from chainlib.interface import ChainInterface
|
||||||
from chainlib.eth.block import (
|
from chainlib.eth.block import (
|
||||||
block_by_number,
|
block_by_number,
|
||||||
|
block_latest,
|
||||||
Block,
|
Block,
|
||||||
)
|
)
|
||||||
from chainlib.eth.tx import (
|
from chainlib.eth.tx import (
|
||||||
@@ -16,3 +17,4 @@ class EthChainInterface(ChainInterface):
|
|||||||
self._block_from_src = Block.from_src
|
self._block_from_src = Block.from_src
|
||||||
self._tx_receipt = receipt
|
self._tx_receipt = receipt
|
||||||
self._src_normalize = Tx.src_normalize
|
self._src_normalize = Tx.src_normalize
|
||||||
|
self._block_latest = block_latest
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import signal
|
|||||||
# external imports
|
# external imports
|
||||||
import chainlib.eth.cli
|
import chainlib.eth.cli
|
||||||
import chaind.cli
|
import chaind.cli
|
||||||
|
import chainqueue.cli
|
||||||
from chaind.session import SessionController
|
from chaind.session import SessionController
|
||||||
from chaind.setup import Environment
|
from chaind.setup import Environment
|
||||||
from chaind.error import (
|
from chaind.error import (
|
||||||
@@ -27,11 +28,12 @@ from chainqueue.cache import CacheTokenTx
|
|||||||
from chainlib.encode import TxHexNormalizer
|
from chainlib.encode import TxHexNormalizer
|
||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
from chaind.adapters.fs import ChaindFsAdapter
|
from chaind.adapters.fs import ChaindFsAdapter
|
||||||
|
from chaind.dispatch import DispatchProcessor
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from chaind.eth.dispatch import EthDispatcher
|
|
||||||
from chaind.eth.cache import EthCacheTx
|
from chaind.eth.cache import EthCacheTx
|
||||||
from chaind.eth.settings import ChaindEthSettings
|
from chaind.eth.settings import ChaindEthSettings
|
||||||
|
from chaind.eth.dispatch import EthDispatcher
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
@@ -44,14 +46,18 @@ env = Environment(domain='eth', env=os.environ)
|
|||||||
arg_flags = chainlib.eth.cli.argflag_std_read
|
arg_flags = chainlib.eth.cli.argflag_std_read
|
||||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
||||||
|
|
||||||
|
queue_arg_flags = 0
|
||||||
|
chainqueue.cli.process_flags(argparser, queue_arg_flags)
|
||||||
|
|
||||||
local_arg_flags = chaind.cli.argflag_local_base | chaind.cli.ChaindFlag.DISPATCH | chaind.cli.ChaindFlag.SOCKET
|
local_arg_flags = chaind.cli.argflag_local_base | chaind.cli.ChaindFlag.DISPATCH | chaind.cli.ChaindFlag.SOCKET
|
||||||
chaind.cli.process_flags(argparser, local_arg_flags)
|
chaind.cli.process_flags(argparser, local_arg_flags)
|
||||||
|
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
base_config_dir = [chaind.cli.config_dir]
|
base_config_dir = [chainqueue.cli.config_dir, chaind.cli.config_dir]
|
||||||
config = chainlib.eth.cli.Config.from_args(args, arg_flags, base_config_dir=base_config_dir)
|
config = chainlib.eth.cli.Config.from_args(args, arg_flags, base_config_dir=base_config_dir)
|
||||||
config = chaind.cli.process_config(config, args, local_arg_flags)
|
config = chaind.cli.process_config(config, args, local_arg_flags)
|
||||||
|
config = chainqueue.cli.process_config(config, args, queue_arg_flags)
|
||||||
config.add('eth', 'CHAIND_ENGINE', False)
|
config.add('eth', 'CHAIND_ENGINE', False)
|
||||||
config.add('queue', 'CHAIND_COMPONENT', False)
|
config.add('queue', 'CHAIND_COMPONENT', False)
|
||||||
logg.debug('config loaded:\n{}'.format(config))
|
logg.debug('config loaded:\n{}'.format(config))
|
||||||
@@ -61,33 +67,16 @@ settings.process(config)
|
|||||||
|
|
||||||
logg.debug('settings:\n{}'.format(settings))
|
logg.debug('settings:\n{}'.format(settings))
|
||||||
|
|
||||||
|
|
||||||
def process_outgoing(chain_spec, adapter, rpc, limit=100):
|
|
||||||
upcoming = adapter.upcoming()
|
|
||||||
logg.info('process {} {} {}'.format(chain_spec, adapter, rpc))
|
|
||||||
logg.info('upcoming {}'.format(upcoming))
|
|
||||||
i = 0
|
|
||||||
for tx_hash in upcoming:
|
|
||||||
if adapter.dispatch(tx_hash):
|
|
||||||
i += 1
|
|
||||||
return i
|
|
||||||
|
|
||||||
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
|
||||||
|
|
||||||
rpc = chainlib.eth.cli.Rpc()
|
rpc = chainlib.eth.cli.Rpc()
|
||||||
conn = rpc.connect_by_config(config)
|
conn = rpc.connect_by_config(config)
|
||||||
|
|
||||||
tx_normalizer = TxHexNormalizer().tx_hash
|
tx_normalizer = TxHexNormalizer().tx_hash
|
||||||
token_cache_store = CacheTokenTx(chain_spec, normalizer=tx_normalizer)
|
token_cache_store = CacheTokenTx(settings.get('CHAIN_SPEC'), normalizer=tx_normalizer)
|
||||||
dispatcher = EthDispatcher(conn)
|
|
||||||
queue_adapter = ChaindFsAdapter(
|
dispatcher = EthDispatcher(conn)
|
||||||
settings.get('CHAIN_SPEC'),
|
processor = DispatchProcessor(settings.get('CHAIN_SPEC'), settings.dir_for('queue'), dispatcher)
|
||||||
settings.get('SESSION_DATA_DIR'),
|
ctrl = SessionController(settings, processor.process)
|
||||||
EthCacheTx,
|
|
||||||
dispatcher,
|
|
||||||
)
|
|
||||||
|
|
||||||
ctrl = SessionController(settings, queue_adapter, process_outgoing)
|
|
||||||
signal.signal(signal.SIGINT, ctrl.shutdown)
|
signal.signal(signal.SIGINT, ctrl.shutdown)
|
||||||
signal.signal(signal.SIGTERM, ctrl.shutdown)
|
signal.signal(signal.SIGTERM, ctrl.shutdown)
|
||||||
|
|
||||||
@@ -113,6 +102,14 @@ def main():
|
|||||||
ctrl.process(conn)
|
ctrl.process(conn)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
queue_adapter = ChaindFsAdapter(
|
||||||
|
settings.get('CHAIN_SPEC'),
|
||||||
|
settings.dir_for('queue'),
|
||||||
|
EthCacheTx,
|
||||||
|
dispatcher,
|
||||||
|
store_sync=False,
|
||||||
|
)
|
||||||
|
|
||||||
result_data = None
|
result_data = None
|
||||||
r = 0 # no error
|
r = 0 # no error
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import socket
|
|||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
import chainlib.eth.cli
|
import chainlib.eth.cli
|
||||||
|
import chainqueue.cli
|
||||||
import chaind.cli
|
import chaind.cli
|
||||||
from chaind.setup import Environment
|
from chaind.setup import Environment
|
||||||
from chainlib.eth.gas import price
|
from chainlib.eth.gas import price
|
||||||
@@ -37,12 +38,15 @@ argparser.add_positional('source', required=False, type=str, help='Transaction s
|
|||||||
local_arg_flags = chaind.cli.argflag_local_socket_client | chaind.cli.ChaindFlag.TOKEN
|
local_arg_flags = chaind.cli.argflag_local_socket_client | chaind.cli.ChaindFlag.TOKEN
|
||||||
chaind.cli.process_flags(argparser, local_arg_flags)
|
chaind.cli.process_flags(argparser, local_arg_flags)
|
||||||
|
|
||||||
|
chainqueue.cli.process_flags(argparser, 0)
|
||||||
|
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
env = Environment(domain='eth', env=os.environ)
|
env = Environment(domain='eth', env=os.environ)
|
||||||
|
|
||||||
base_config_dir = [chaind.cli.config_dir]
|
base_config_dir = [chaind.cli.config_dir, chainqueue.cli.config_dir]
|
||||||
config = chainlib.eth.cli.Config.from_args(args, arg_flags, base_config_dir=base_config_dir)
|
config = chainlib.eth.cli.Config.from_args(args, arg_flags, base_config_dir=base_config_dir)
|
||||||
|
config = chainqueue.cli.process_config(config, args, 0)
|
||||||
config = chaind.cli.process_config(config, args, local_arg_flags)
|
config = chaind.cli.process_config(config, args, local_arg_flags)
|
||||||
config.add(args.source, '_SOURCE', False)
|
config.add(args.source, '_SOURCE', False)
|
||||||
config.add('eth', 'CHAIND_ENGINE', False)
|
config.add('eth', 'CHAIND_ENGINE', False)
|
||||||
@@ -114,7 +118,7 @@ def main():
|
|||||||
m = GasTokenResolver
|
m = GasTokenResolver
|
||||||
token_resolver = m(chain_spec, rpc.get_sender_address(), rpc.get_signer(), rpc.get_gas_oracle(), rpc.get_nonce_oracle())
|
token_resolver = m(chain_spec, rpc.get_sender_address(), rpc.get_signer(), rpc.get_gas_oracle(), rpc.get_nonce_oracle())
|
||||||
|
|
||||||
processor = Processor(token_resolver, config.get('_SOURCE'))
|
processor = Processor(token_resolver, config.get('_SOURCE'), use_checksum=not config.get('_UNSAFE'))
|
||||||
processor.add_processor(CSVProcessor())
|
processor.add_processor(CSVProcessor())
|
||||||
|
|
||||||
sends = None
|
sends = None
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import chainsyncer.cli
|
|||||||
import chaind.cli
|
import chaind.cli
|
||||||
from chaind.setup import Environment
|
from chaind.setup import Environment
|
||||||
from chaind.filter import StateFilter
|
from chaind.filter import StateFilter
|
||||||
from chaind.adapters.fs import ChaindFsAdapter
|
|
||||||
from chainlib.eth.block import block_latest
|
from chainlib.eth.block import block_latest
|
||||||
from hexathon import strip_0x
|
from hexathon import strip_0x
|
||||||
from chainsyncer.store.fs import SyncFsStore
|
from chainsyncer.store.fs import SyncFsStore
|
||||||
@@ -57,14 +56,9 @@ settings.process(config)
|
|||||||
|
|
||||||
logg.debug('settings:\n{}'.format(settings))
|
logg.debug('settings:\n{}'.format(settings))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
queue_adapter = ChaindFsAdapter(
|
fltr = StateFilter(settings.get('CHAIN_SPEC'), settings.dir_for('queue'), EthCacheTx)
|
||||||
settings.get('CHAIN_SPEC'),
|
|
||||||
settings.dir_for('queue'),
|
|
||||||
EthCacheTx,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
fltr = StateFilter(queue_adapter)
|
|
||||||
sync_store = SyncFsStore(settings.get('SESSION_DATA_DIR'), session_id=settings.get('SESSION_ID'))
|
sync_store = SyncFsStore(settings.get('SESSION_DATA_DIR'), session_id=settings.get('SESSION_ID'))
|
||||||
sync_store.register(fltr)
|
sync_store.register(fltr)
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ logg = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class BaseTokenResolver:
|
class BaseTokenResolver:
|
||||||
|
|
||||||
def __init__(self, chain_spec, sender, signer, gas_oracle, nonce_oracle):
|
def __init__(self, chain_spec, sender, signer, gas_oracle, nonce_oracle, advance_nonce=False):
|
||||||
self.chain_spec = chain_spec
|
self.chain_spec = chain_spec
|
||||||
self.chain_id = chain_spec.chain_id()
|
self.chain_id = chain_spec.chain_id()
|
||||||
self.signer = signer
|
self.signer = signer
|
||||||
@@ -19,6 +19,10 @@ class BaseTokenResolver:
|
|||||||
self.factory = None
|
self.factory = None
|
||||||
self.gas_limit_start = None
|
self.gas_limit_start = None
|
||||||
self.gas_price_start = None
|
self.gas_price_start = None
|
||||||
|
if advance_nonce:
|
||||||
|
self.nonce_getter = self.nonce_oracle.next_nonce
|
||||||
|
else:
|
||||||
|
self.nonce_getter = self.nonce_oracle.get_nonce
|
||||||
|
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
@@ -28,7 +32,7 @@ class BaseTokenResolver:
|
|||||||
|
|
||||||
|
|
||||||
def get_values(self, gas_value, value, executable_address=None):
|
def get_values(self, gas_value, value, executable_address=None):
|
||||||
nonce = self.nonce_oracle.get_nonce()
|
nonce = self.nonce_getter()
|
||||||
|
|
||||||
if executable_address == None:
|
if executable_address == None:
|
||||||
return (value, 0, nonce)
|
return (value, 0, nonce)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from chaind.eth.token import BaseTokenResolver
|
|||||||
class GasTokenResolver(BaseTokenResolver):
|
class GasTokenResolver(BaseTokenResolver):
|
||||||
|
|
||||||
def __init__(self, chain_spec, sender, signer, gas_oracle, nonce_oracle):
|
def __init__(self, chain_spec, sender, signer, gas_oracle, nonce_oracle):
|
||||||
super(GasTokenResolver, self).__init__(chain_spec, sender, signer, gas_oracle, nonce_oracle)
|
super(GasTokenResolver, self).__init__(chain_spec, sender, signer, gas_oracle, nonce_oracle, advance_nonce=True)
|
||||||
self.factory = Gas(self.chain_spec, signer=self.signer, gas_oracle=self.gas_oracle, nonce_oracle=self.nonce_oracle)
|
self.factory = Gas(self.chain_spec, signer=self.signer, gas_oracle=self.gas_oracle, nonce_oracle=self.nonce_oracle)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ import logging
|
|||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
from chaind.error import TxSourceError
|
from chaind.error import TxSourceError
|
||||||
from chainlib.eth.address import is_checksum_address
|
from chainlib.eth.address import (
|
||||||
|
is_checksum_address,
|
||||||
|
to_checksum_address,
|
||||||
|
)
|
||||||
from chainlib.eth.tx import unpack
|
from chainlib.eth.tx import unpack
|
||||||
from chainlib.eth.gas import Gas
|
from chainlib.eth.gas import Gas
|
||||||
from hexathon import (
|
from hexathon import (
|
||||||
@@ -17,10 +20,11 @@ logg = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class Processor:
|
class Processor:
|
||||||
|
|
||||||
def __init__(self, resolver, source):
|
def __init__(self, resolver, source, use_checksum=True):
|
||||||
self.resolver = resolver
|
self.resolver = resolver
|
||||||
self.source = source
|
self.source = source
|
||||||
self.processor = []
|
self.processor = []
|
||||||
|
self.safe = use_checksum
|
||||||
self.conn = None
|
self.conn = None
|
||||||
|
|
||||||
|
|
||||||
@@ -50,9 +54,14 @@ class Processor:
|
|||||||
txs = []
|
txs = []
|
||||||
for i, r in enumerate(self.content):
|
for i, r in enumerate(self.content):
|
||||||
logg.debug('processing {}'.format(r))
|
logg.debug('processing {}'.format(r))
|
||||||
if not is_checksum_address(r[0]):
|
address = r[0]
|
||||||
raise ValueError('invalid checksum address {} in record {}'.format(r[0], i))
|
if self.safe:
|
||||||
self.content[i][0] = add_0x(r[0])
|
if not is_checksum_address(address):
|
||||||
|
raise ValueError('invalid checksum address {} in record {}'.format(address, i))
|
||||||
|
else:
|
||||||
|
address = to_checksum_address(address)
|
||||||
|
|
||||||
|
self.content[i][0] = add_0x(address)
|
||||||
try:
|
try:
|
||||||
self.content[i][1] = int(r[1])
|
self.content[i][1] = int(r[1])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
chaind~=0.1.1
|
chaind~=0.2.4
|
||||||
hexathon~=0.1.5
|
hexathon~=0.1.5
|
||||||
chainlib-eth~=0.1.0
|
chainlib-eth~=0.1.1
|
||||||
pyxdg~=0.27
|
pyxdg~=0.27
|
||||||
shep~=0.2.3
|
shep~=0.2.5
|
||||||
funga-eth~=0.6.0
|
funga-eth~=0.6.0
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = chaind-eth
|
name = chaind-eth
|
||||||
version = 0.1.3
|
version = 0.2.3
|
||||||
description = Queue server for ethereum
|
description = Queue server for ethereum
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -27,7 +27,7 @@ while True:
|
|||||||
l = f.readline()
|
l = f.readline()
|
||||||
if l == '':
|
if l == '':
|
||||||
break
|
break
|
||||||
test_requirements.append(l.rstrip())
|
erc20_requirements.append(l.rstrip())
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from chainlib.chain import ChainSpec
|
|||||||
from chainqueue.cache import CacheTokenTx
|
from chainqueue.cache import CacheTokenTx
|
||||||
from chainlib.error import RPCException
|
from chainlib.error import RPCException
|
||||||
from chainlib.status import Status as TxStatus
|
from chainlib.status import Status as TxStatus
|
||||||
from chaind.unittest.common import TestChaindFsBase
|
from chaind.unittest.fs import TestChaindFsBase
|
||||||
from chaind.driver import QueueDriver
|
from chaind.driver import QueueDriver
|
||||||
from chaind.filter import StateFilter
|
from chaind.filter import StateFilter
|
||||||
from chainlib.eth.gas import Gas
|
from chainlib.eth.gas import Gas
|
||||||
|
|||||||
Reference in New Issue
Block a user