Rehabilitate faucet and gifter callback
This commit is contained in:
parent
2720e9ce6a
commit
1edacf70cf
@ -457,6 +457,7 @@ class AdminApi:
|
|||||||
tx_unpacked = unpack_signed_raw_tx(bytes.fromhex(tx['signed_tx'][2:]), chain_spec.chain_id())
|
tx_unpacked = unpack_signed_raw_tx(bytes.fromhex(tx['signed_tx'][2:]), chain_spec.chain_id())
|
||||||
tx['gas_price'] = tx_unpacked['gasPrice']
|
tx['gas_price'] = tx_unpacked['gasPrice']
|
||||||
tx['gas_limit'] = tx_unpacked['gas']
|
tx['gas_limit'] = tx_unpacked['gas']
|
||||||
|
tx['data'] = tx_unpacked['data']
|
||||||
|
|
||||||
s = celery.signature(
|
s = celery.signature(
|
||||||
'cic_eth.queue.tx.get_state_log',
|
'cic_eth.queue.tx.get_state_log',
|
||||||
|
@ -9,6 +9,7 @@ from cic_registry import CICRegistry
|
|||||||
from cic_registry import zero_address
|
from cic_registry import zero_address
|
||||||
from cic_registry.chain import ChainSpec
|
from cic_registry.chain import ChainSpec
|
||||||
from hexathon import strip_0x
|
from hexathon import strip_0x
|
||||||
|
from chainlib.status import Status as TxStatus
|
||||||
|
|
||||||
# platform imports
|
# platform imports
|
||||||
from cic_eth.db.models.tx import TxCache
|
from cic_eth.db.models.tx import TxCache
|
||||||
@ -478,6 +479,8 @@ class ExtendedTx:
|
|||||||
self.destination_token_symbol = ''
|
self.destination_token_symbol = ''
|
||||||
self.source_token_decimals = ExtendedTx._default_decimals
|
self.source_token_decimals = ExtendedTx._default_decimals
|
||||||
self.destination_token_decimals = ExtendedTx._default_decimals
|
self.destination_token_decimals = ExtendedTx._default_decimals
|
||||||
|
self.status = TxStatus.PENDING.name
|
||||||
|
self.status_code = TxStatus.PENDING.value
|
||||||
|
|
||||||
|
|
||||||
def set_actors(self, sender, recipient, trusted_declarator_addresses=None):
|
def set_actors(self, sender, recipient, trusted_declarator_addresses=None):
|
||||||
@ -505,10 +508,18 @@ class ExtendedTx:
|
|||||||
self.destination_token_value = destination_value
|
self.destination_token_value = destination_value
|
||||||
|
|
||||||
|
|
||||||
|
def set_status(self, n):
|
||||||
|
if n:
|
||||||
|
self.status = TxStatus.ERROR.name
|
||||||
|
else:
|
||||||
|
self.status = TxStatus.SUCCESS.name
|
||||||
|
self.status_code = n
|
||||||
|
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
o = {}
|
o = {}
|
||||||
for attr in dir(self):
|
for attr in dir(self):
|
||||||
if attr[0] == '_' or attr in ['set_actors', 'set_tokens', 'to_dict']:
|
if attr[0] == '_' or attr in ['set_actors', 'set_tokens', 'set_status', 'to_dict']:
|
||||||
continue
|
continue
|
||||||
o[attr] = getattr(self, attr)
|
o[attr] = getattr(self, attr)
|
||||||
return o
|
return o
|
||||||
|
@ -6,6 +6,8 @@ import web3
|
|||||||
import celery
|
import celery
|
||||||
from cic_registry.error import UnknownContractError
|
from cic_registry.error import UnknownContractError
|
||||||
from chainlib.status import Status as TxStatus
|
from chainlib.status import Status as TxStatus
|
||||||
|
from chainlib.eth.address import to_checksum
|
||||||
|
from hexathon import strip_0x
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from .base import SyncFilter
|
from .base import SyncFilter
|
||||||
@ -35,12 +37,13 @@ class CallbackFilter(SyncFilter):
|
|||||||
|
|
||||||
|
|
||||||
def call_back(self, transfer_type, result):
|
def call_back(self, transfer_type, result):
|
||||||
|
logg.debug('result {}'.format(result))
|
||||||
s = celery.signature(
|
s = celery.signature(
|
||||||
self.method,
|
self.method,
|
||||||
[
|
[
|
||||||
result,
|
result,
|
||||||
transfer_type,
|
transfer_type,
|
||||||
int(rcpt.status == 0),
|
int(result['status_code'] == 0),
|
||||||
],
|
],
|
||||||
queue=self.queue,
|
queue=self.queue,
|
||||||
)
|
)
|
||||||
@ -60,39 +63,40 @@ class CallbackFilter(SyncFilter):
|
|||||||
|
|
||||||
|
|
||||||
def parse_data(self, tx):
|
def parse_data(self, tx):
|
||||||
#transfer_type = 'transfer'
|
|
||||||
transfer_type = None
|
transfer_type = None
|
||||||
transfer_data = None
|
transfer_data = None
|
||||||
logg.debug('have payload {}'.format(tx.payload))
|
logg.debug('have payload {}'.format(tx.payload))
|
||||||
method_signature = tx.payload[:8]
|
method_signature = tx.payload[:8]
|
||||||
|
|
||||||
if tx.status == TxStatus.ERROR:
|
logg.debug('tx status {}'.format(tx.status))
|
||||||
logg.error('tx {} has failed, no callbacks will be called'.format(tx.hash))
|
if method_signature == transfer_method_signature:
|
||||||
|
transfer_data = unpack_transfer(tx.payload)
|
||||||
|
transfer_data['from'] = tx['from']
|
||||||
|
transfer_data['token_address'] = tx['to']
|
||||||
|
|
||||||
else:
|
elif method_signature == transferfrom_method_signature:
|
||||||
logg.debug('tx status {}'.format(tx.status))
|
transfer_type = 'transferfrom'
|
||||||
if method_signature == transfer_method_signature:
|
transfer_data = unpack_transferfrom(tx.payload)
|
||||||
transfer_data = unpack_transfer(tx.payload)
|
transfer_data['token_address'] = tx['to']
|
||||||
transfer_data['from'] = tx['from']
|
|
||||||
transfer_data['token_address'] = tx['to']
|
|
||||||
|
|
||||||
elif method_signature == transferfrom_method_signature:
|
# TODO: do not rely on logs here
|
||||||
transfer_type = 'transferfrom'
|
elif method_signature == giveto_method_signature:
|
||||||
transfer_data = unpack_transferfrom(tx.payload)
|
transfer_type = 'tokengift'
|
||||||
transfer_data['token_address'] = tx['to']
|
transfer_data = unpack_gift(tx.payload)
|
||||||
|
for l in tx.logs:
|
||||||
|
topics = l['topics']
|
||||||
|
logg.debug('topixx {}'.format(topics))
|
||||||
|
if strip_0x(topics[0]) == '45c201a59ac545000ead84f30b2db67da23353aa1d58ac522c48505412143ffa':
|
||||||
|
transfer_data['value'] = web3.Web3.toInt(hexstr=strip_0x(l['data']))
|
||||||
|
#token_address_bytes = topics[2][32-20:]
|
||||||
|
token_address = strip_0x(topics[2])[64-40:]
|
||||||
|
transfer_data['token_address'] = to_checksum(token_address)
|
||||||
|
transfer_data['from'] = tx.inputs[0]
|
||||||
|
|
||||||
# TODO: do not rely on logs here
|
logg.debug('resolved method {}'.format(transfer_type))
|
||||||
elif method_signature == giveto_method_signature:
|
|
||||||
transfer_type = 'tokengift'
|
|
||||||
transfer_data = unpack_gift(tx.payload)
|
|
||||||
for l in tx.logs:
|
|
||||||
if l.topics[0].hex() == '0x45c201a59ac545000ead84f30b2db67da23353aa1d58ac522c48505412143ffa':
|
|
||||||
transfer_data['value'] = web3.Web3.toInt(hexstr=l.data)
|
|
||||||
token_address_bytes = l.topics[2][32-20:]
|
|
||||||
transfer_data['token_address'] = web3.Web3.toChecksumAddress(token_address_bytes.hex())
|
|
||||||
transfer_data['from'] = tx.to
|
|
||||||
|
|
||||||
logg.debug('resolved method {}'.format(transfer_type))
|
if transfer_data != None:
|
||||||
|
transfer_data['status'] = tx.status
|
||||||
|
|
||||||
return (transfer_type, transfer_data)
|
return (transfer_type, transfer_data)
|
||||||
|
|
||||||
@ -122,7 +126,11 @@ class CallbackFilter(SyncFilter):
|
|||||||
tokentx = ExtendedTx(tx.hash, self.chain_spec)
|
tokentx = ExtendedTx(tx.hash, self.chain_spec)
|
||||||
tokentx.set_actors(transfer_data['from'], transfer_data['to'], self.trusted_addresses)
|
tokentx.set_actors(transfer_data['from'], transfer_data['to'], self.trusted_addresses)
|
||||||
tokentx.set_tokens(transfer_data['token_address'], transfer_data['value'])
|
tokentx.set_tokens(transfer_data['token_address'], transfer_data['value'])
|
||||||
t = self.call_back(tokentx.to_dict())
|
if transfer_data['status'] == 0:
|
||||||
|
tokentx.set_status(1)
|
||||||
|
else:
|
||||||
|
tokentx.set_status(0)
|
||||||
|
t = self.call_back(transfer_type, tokentx.to_dict())
|
||||||
logg.info('callback success task id {} tx {}'.format(t, tx.hash))
|
logg.info('callback success task id {} tx {}'.format(t, tx.hash))
|
||||||
except UnknownContractError:
|
except UnknownContractError:
|
||||||
logg.debug('callback filter {}:{} skipping "transfer" method on unknown contract {} tx {}'.format(tc.queue, tc.method, transfer_data['to'], tx.hash))
|
logg.debug('callback filter {}:{} skipping "transfer" method on unknown contract {} tx {}'.format(tc.queue, tc.method, transfer_data['to'], tx.hash))
|
||||||
|
@ -18,6 +18,7 @@ import web3
|
|||||||
from cic_registry import CICRegistry
|
from cic_registry import CICRegistry
|
||||||
from cic_registry.chain import ChainSpec
|
from cic_registry.chain import ChainSpec
|
||||||
from cic_registry.chain import ChainRegistry
|
from cic_registry.chain import ChainRegistry
|
||||||
|
from hexathon import add_0x
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from cic_eth.api import AdminApi
|
from cic_eth.api import AdminApi
|
||||||
@ -69,6 +70,8 @@ config.censor('PASSWORD', 'DATABASE')
|
|||||||
config.censor('PASSWORD', 'SSL')
|
config.censor('PASSWORD', 'SSL')
|
||||||
logg.debug('config loaded from {}:\n{}'.format(config_dir, config))
|
logg.debug('config loaded from {}:\n{}'.format(config_dir, config))
|
||||||
|
|
||||||
|
config.add(add_0x(args.query), '_QUERY', True)
|
||||||
|
|
||||||
re_websocket = re.compile('^wss?://')
|
re_websocket = re.compile('^wss?://')
|
||||||
re_http = re.compile('^https?://')
|
re_http = re.compile('^https?://')
|
||||||
blockchain_provider = config.get('ETH_PROVIDER')
|
blockchain_provider = config.get('ETH_PROVIDER')
|
||||||
@ -152,18 +155,18 @@ def render_lock(o, **kwargs):
|
|||||||
def main():
|
def main():
|
||||||
txs = []
|
txs = []
|
||||||
renderer = render_tx
|
renderer = render_tx
|
||||||
if len(args.query) > 66:
|
if len(config.get('_QUERY')) > 66:
|
||||||
txs = [admin_api.tx(chain_spec, tx_raw=args.query)]
|
txs = [admin_api.tx(chain_spec, tx_raw=config.get('_QUERY'))]
|
||||||
elif len(args.query) > 42:
|
elif len(config.get('_QUERY')) > 42:
|
||||||
txs = [admin_api.tx(chain_spec, tx_hash=args.query)]
|
txs = [admin_api.tx(chain_spec, tx_hash=config.get('_QUERY'))]
|
||||||
elif len(args.query) == 42:
|
elif len(config.get('_QUERY')) == 42:
|
||||||
txs = admin_api.account(chain_spec, args.query, include_recipient=False)
|
txs = admin_api.account(chain_spec, config.get('_QUERY'), include_recipient=False)
|
||||||
renderer = render_account
|
renderer = render_account
|
||||||
elif len(args.query) >= 4 and args.query[:4] == 'lock':
|
elif len(config.get('_QUERY')) >= 4 and config.get('_QUERY')[:4] == 'lock':
|
||||||
txs = admin_api.get_lock()
|
txs = admin_api.get_lock()
|
||||||
renderer = render_lock
|
renderer = render_lock
|
||||||
else:
|
else:
|
||||||
raise ValueError('cannot parse argument {}'.format(args.query))
|
raise ValueError('cannot parse argument {}'.format(config.get('_QUERY')))
|
||||||
|
|
||||||
if len(txs) == 0:
|
if len(txs) == 0:
|
||||||
logg.info('no matches found')
|
logg.info('no matches found')
|
||||||
|
@ -107,7 +107,7 @@ RUN cd cic-bancor/python && \
|
|||||||
|
|
||||||
|
|
||||||
RUN apt-get install -y cargo
|
RUN apt-get install -y cargo
|
||||||
ARG cic_base_version=0.1.1a4
|
ARG cic_base_version=0.1.1a7
|
||||||
RUN pip install --extra-index-url $pip_extra_index_url cic-base[full_graph]==$cic_base_version
|
RUN pip install --extra-index-url $pip_extra_index_url cic-base[full_graph]==$cic_base_version
|
||||||
|
|
||||||
ARG cic_registry_version=0.5.3a21
|
ARG cic_registry_version=0.5.3a21
|
||||||
|
@ -42,6 +42,6 @@ rlp==2.0.1
|
|||||||
cryptocurrency-cli-tools==0.0.4
|
cryptocurrency-cli-tools==0.0.4
|
||||||
giftable-erc20-token==0.0.7b12
|
giftable-erc20-token==0.0.7b12
|
||||||
hexathon==0.0.1a3
|
hexathon==0.0.1a3
|
||||||
chainlib==0.0.1a18
|
chainlib==0.0.1a19
|
||||||
chainsyncer==0.0.1a18
|
chainsyncer==0.0.1a18
|
||||||
cic-registry==0.5.3.a21
|
cic-registry==0.5.3.a21
|
||||||
|
Loading…
Reference in New Issue
Block a user