diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..e705e7e --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include *requirements.txt diff --git a/cic_sync_filter/base.py b/cic_sync_filter/base.py index 1d722a5..22b3898 100644 --- a/cic_sync_filter/base.py +++ b/cic_sync_filter/base.py @@ -1,10 +1,12 @@ # external imports from chainlib.eth.constant import ZERO_ADDRESS +from chainsyncer.filter import SyncFilter as BaseSyncFilter -class SyncFilter: +class SyncFilter(BaseSyncFilter): def __init__(self, chain_spec, registry, queue, caller_address=ZERO_ADDRESS): + super(SyncFilter, self).__init__() self.exec_count = 0 self.match_count = 0 self.queue = queue @@ -13,7 +15,7 @@ class SyncFilter: self.caller_address = caller_address - def filter(self, conn, block, tx, db_session): + def filter(self, conn, block, tx): self.exec_count += 1 diff --git a/cic_sync_filter/callback.py b/cic_sync_filter/callback.py index fdfef11..1a47027 100644 --- a/cic_sync_filter/callback.py +++ b/cic_sync_filter/callback.py @@ -80,8 +80,8 @@ class CallbackFilter(SyncFilter): return (transfer_type, transfer_data) - def filter(self, conn, block, tx, db_session=None): - super(CallbackFilter, self).filter(conn, block, tx, db_session) + def filter(self, conn, block, tx): + super(CallbackFilter, self).filter(conn, block, tx) transfer_data = None transfer_type = None try: diff --git a/cic_sync_filter/gas.py b/cic_sync_filter/gas.py index 7716c96..f7e932d 100644 --- a/cic_sync_filter/gas.py +++ b/cic_sync_filter/gas.py @@ -8,14 +8,15 @@ from hexathon import ( ) from chainlib.eth.tx import unpack from chainqueue.db.enum import StatusBits -from chainqueue.db.models.tx import TxCache -from chainqueue.db.models.otx import Otx +#from chainqueue.db.models.tx import TxCache +#from chainqueue.db.models.otx import Otx from chainlib.eth.address import to_checksum_address - -# local imports -from cic_eth.db.models.base import SessionBase +#from cic_eth.db.models.base import SessionBase +from cic_eth.queue.query import get_account_tx_local from cic_eth.eth.gas import create_check_gas_task from cic_eth.queue.query import get_paused_tx + +# local imports from cic_eth.encode import tx_normalize from .base import SyncFilter @@ -24,30 +25,24 @@ logg = logging.getLogger() class GasFilter(SyncFilter): - def filter(self, conn, block, tx, db_session): - super(GasFilter, self).filter(conn, block, tx, db_session) + def filter(self, conn, block, tx): + super(GasFilter, self).filter(conn, block, tx) if tx.value > 0 or len(tx.payload) == 0: tx_hash_hex = add_0x(tx.hash) sender_target = tx_normalize.wallet_address(tx.inputs[0]) - session = SessionBase.bind_session(db_session) - q = session.query(TxCache.recipient) - q = q.filter(TxCache.sender==sender_target) - r = q.all() + txc = get_account_tx_local(self.chain_spec, sender_target, as_recipient=False) logline = None - if len(r) == 0: - logline = 'unsolicited gas refill tx {}; cannot find {} among senders'.format(tx_hash_hex, tx.outputs[0]) + if len(txc) == 0: + logline = 'unsolicited gas refill tx {}; cannot find {} among senders'.format(tx_hash_hex, sender_target) logline = self.to_logline(block, tx, logline) logg.info(logline) - SessionBase.release_session(session) return None self.register_match() - txs = get_paused_tx(self.chain_spec, status=StatusBits.GAS_ISSUES, sender=sender_target, session=session, decoder=unpack) - - SessionBase.release_session(session) + txs = get_paused_tx(self.chain_spec, status=StatusBits.GAS_ISSUES, sender=sender_target, decoder=unpack) t = None address = to_checksum_address(sender_target) diff --git a/cic_sync_filter/log.py b/cic_sync_filter/log.py index d61e8bf..38c7e3e 100644 --- a/cic_sync_filter/log.py +++ b/cic_sync_filter/log.py @@ -3,7 +3,7 @@ from .base import SyncFilter class LogFilter(SyncFilter): - def filter(self, conn, block, tx, db_session=None): + def filter(self, conn, block, tx): logg.debug('block {} tx {}'.format(block, tx)) diff --git a/cic_sync_filter/register.py b/cic_sync_filter/register.py index a86da6c..7d587a8 100644 --- a/cic_sync_filter/register.py +++ b/cic_sync_filter/register.py @@ -25,8 +25,8 @@ class RegistrationFilter(SyncFilter): self.contract_address = registry.by_name('AccountRegistry', sender_address=caller_address) - def filter(self, conn, block, tx, db_session=None): - super(RegistrationFilter, self).filter(conn, block, tx, db_session) + def filter(self, conn, block, tx): + super(RegistrationFilter, self).filter(conn, block, tx) if self.contract_address != tx.inputs[0]: logg.debug('not an account registry tx; {} != {}'.format(self.contract_address, tx.inputs[0])) return None diff --git a/cic_sync_filter/straggler.py b/cic_sync_filter/straggler.py index 80218ad..feb80e6 100644 --- a/cic_sync_filter/straggler.py +++ b/cic_sync_filter/straggler.py @@ -23,8 +23,8 @@ class StragglerFilter(SyncFilter): gas_balance_threshold = 0 - def filter(self, conn, block, tx, db_session=None): - txc = get_tx_cache(self.chain_spec, tx.hash, session=db_session) + def filter(self, conn, block, tx): + txc = get_tx_cache(self.chain_spec, tx.hash) if txc['status_code'] & StatusBits.GAS_ISSUES > 0: o = balance(tx.outputs[0]) r = conn.do(o) diff --git a/cic_sync_filter/token.py b/cic_sync_filter/token.py index e72b439..d2f9e30 100644 --- a/cic_sync_filter/token.py +++ b/cic_sync_filter/token.py @@ -24,8 +24,8 @@ logg = logging.getLogger(__name__) class TokenFilter(SyncFilter): - def filter(self, conn, block, tx, db_session=None): - super(TokenFilter, self).filter(conn, block, tx, db_session) + def filter(self, conn, block, tx): + super(TokenFilter, self).filter(conn, block, tx) if not tx.payload: return None diff --git a/cic_sync_filter/transferauth.py b/cic_sync_filter/transferauth.py index 7288d34..3437635 100644 --- a/cic_sync_filter/transferauth.py +++ b/cic_sync_filter/transferauth.py @@ -33,7 +33,8 @@ class TransferAuthFilter(SyncFilter): self.transfer_request_contract = registry.by_name('TransferAuthorization', sender_address=call_address) - def filter(self, conn, block, tx, db_session): #rcpt, chain_str, session=None): + def filter(self, conn, block, tx): + super(TransferAuthFilter, self).filter(conn, block, tx) if tx.payload == None: logg.debug('no payload') diff --git a/cic_sync_filter/tx.py b/cic_sync_filter/tx.py index 07b5959..dd61b87 100644 --- a/cic_sync_filter/tx.py +++ b/cic_sync_filter/tx.py @@ -18,8 +18,8 @@ logg = logging.getLogger(__name__) class TxFilter(SyncFilter): - def filter(self, conn, block, tx, db_session=None): - super(TxFilter, self).filter(conn, block, tx, db_session=db_session) + def filter(self, conn, block, tx): + super(TxFilter, self).filter(conn, block) try: get_tx_local(self.chain_spec, tx.hash) diff --git a/tests/test_bogus_filter.py b/tests/test_bogus_filter.py index dacf479..1bca5d0 100644 --- a/tests/test_bogus_filter.py +++ b/tests/test_bogus_filter.py @@ -40,7 +40,7 @@ def test_filter_bogus( for fltr in fltrs: r = None try: - r = fltr.filter(eth_rpc, bogus_tx_block[0], bogus_tx_block[1], db_session=init_database) + r = fltr.filter(eth_rpc, bogus_tx_block[0], bogus_tx_block[1]) except: pass assert not r diff --git a/tests/test_gas_filter.py b/tests/test_gas_filter.py index 7384c30..2edf15c 100644 --- a/tests/test_gas_filter.py +++ b/tests/test_gas_filter.py @@ -106,7 +106,7 @@ def test_filter_gas( for v in r: logg.info('have row {}'.format(v)) - t = fltr.filter(eth_rpc, block, tx, db_session=init_database) + t = fltr.filter(eth_rpc, block, tx) t.get_leaf() assert t.successful() diff --git a/tests/test_register_filter.py b/tests/test_register_filter.py index 707fadc..7071464 100644 --- a/tests/test_register_filter.py +++ b/tests/test_register_filter.py @@ -80,7 +80,7 @@ def test_register_filter( registry = CICRegistry(default_chain_spec, eth_rpc) queue = None fltr = RegistrationFilter(default_chain_spec, registry, queue, caller_address=contract_roles['CONTRACT_DEPLOYER']) - t = fltr.filter(eth_rpc, block, tx, db_session=init_database) + t = fltr.filter(eth_rpc, block, tx) assert t != None t.get_leaf() assert t.successful() @@ -139,5 +139,5 @@ def test_register_filter_nomatch( registry = CICRegistry(default_chain_spec, eth_rpc) queue = None fltr = RegistrationFilter(default_chain_spec, registry, queue, caller_address=contract_roles['CONTRACT_DEPLOYER']) - t = fltr.filter(eth_rpc, block, tx, db_session=init_database) + t = fltr.filter(eth_rpc, block, tx) assert t == None diff --git a/tests/test_straggler_filter.py b/tests/test_straggler_filter.py index c252170..9485e29 100644 --- a/tests/test_straggler_filter.py +++ b/tests/test_straggler_filter.py @@ -96,7 +96,7 @@ def test_straggler_tx( tx_signed_raw_bytes = bytes.fromhex(strip_0x(tx_signed_raw_hex)) tx_src = unpack(tx_signed_raw_bytes, default_chain_spec) tx = Tx(tx_src, block=block) - t = fltr.filter(None, block, tx, db_session=init_database) + t = fltr.filter(None, block, tx) logg.debug('foo') tx_hash_hex_successor = t.get_leaf() logg.debug('bar') @@ -163,7 +163,7 @@ def test_waitforgas_tx( tx_src = unpack(tx_signed_raw_bytes, default_chain_spec) tx = Tx(tx_src, block=block) - t = fltr.filter(eth_rpc, block, tx, db_session=init_database) + t = fltr.filter(eth_rpc, block, tx) t.get_leaf() assert t.successful() @@ -181,7 +181,7 @@ def test_waitforgas_tx( assert r['status'] == 1 - t = fltr.filter(eth_rpc, block, tx, db_session=init_database) + t = fltr.filter(eth_rpc, block, tx) t.get_leaf() assert t.successful() @@ -201,7 +201,7 @@ def test_waitforgas_tx( init_database.commit() - t = fltr.filter(eth_rpc, block, tx, db_session=init_database) + t = fltr.filter(eth_rpc, block, tx) t.get_leaf() otx = get_tx_local(default_chain_spec, tx.hash, session=init_database) diff --git a/tests/test_token_filter.py b/tests/test_token_filter.py index 56c9b96..3aebfdd 100644 --- a/tests/test_token_filter.py +++ b/tests/test_token_filter.py @@ -73,7 +73,7 @@ def test_filter_gas( tx_src = unpack(tx_signed_raw_bytes, default_chain_spec) tx = Tx(tx_src, block=block) tx.apply_receipt(rcpt) - t = fltr.filter(eth_rpc, block, tx, db_session=init_database) + t = fltr.filter(eth_rpc, block, tx) assert t.get() == None nonce_oracle = RPCNonceOracle(contract_roles['CONTRACT_DEPLOYER'], eth_rpc) @@ -84,7 +84,7 @@ def test_filter_gas( r = eth_rpc.do(o) assert r['status'] == 1 - t = fltr.filter(eth_rpc, block, tx, db_session=init_database) + t = fltr.filter(eth_rpc, block, tx) r = t.get_leaf() assert t.successful() @@ -127,4 +127,4 @@ def test_filter_unknown_contract_error( tx_signed_raw_bytes = bytes.fromhex(strip_0x(tx_signed_raw_hex)) tx_src = unpack(tx_signed_raw_bytes, default_chain_spec) tx = Tx(tx_src) - t = fltr.filter(eth_rpc, None, tx, db_session=init_database) + t = fltr.filter(eth_rpc, None, tx) diff --git a/tests/test_transferauth_filter.py b/tests/test_transferauth_filter.py index 7f2636f..f1b22d6 100644 --- a/tests/test_transferauth_filter.py +++ b/tests/test_transferauth_filter.py @@ -62,7 +62,7 @@ def test_filter_transferauth( tx = Tx(tx_src, block=block) fltr = TransferAuthFilter(cic_registry, default_chain_spec, eth_rpc, call_address=contract_roles['CONTRACT_DEPLOYER']) - t = fltr.filter(eth_rpc, block, tx, db_session=init_database) + t = fltr.filter(eth_rpc, block, tx) t.get_leaf() assert t.successful() diff --git a/tests/test_tx_filter.py b/tests/test_tx_filter.py index 339f66b..add5ef0 100644 --- a/tests/test_tx_filter.py +++ b/tests/test_tx_filter.py @@ -97,7 +97,7 @@ def test_filter_tx( tx_signed_raw_bytes = bytes.fromhex(strip_0x(tx_signed_raw_hex)) tx_src = unpack(tx_signed_raw_bytes, default_chain_spec) tx = Tx(tx_src, block=block) - t = fltr.filter(eth_rpc, block, tx, db_session=init_database) + t = fltr.filter(eth_rpc, block, tx) t.get() assert t.successful()