2021-07-18 12:02:14 +02:00
|
|
|
|
# standard imports
|
|
|
|
|
import logging
|
|
|
|
|
|
2021-06-03 11:03:17 +02:00
|
|
|
|
# external imports
|
|
|
|
|
from chainlib.eth.constant import ZERO_ADDRESS
|
|
|
|
|
from chainlib.eth.tx import (
|
|
|
|
|
unpack,
|
|
|
|
|
raw,
|
|
|
|
|
)
|
|
|
|
|
from hexathon import (
|
|
|
|
|
add_0x,
|
|
|
|
|
strip_0x,
|
|
|
|
|
)
|
2021-07-18 12:02:14 +02:00
|
|
|
|
from chainqueue.enum import StatusBits
|
2021-06-03 11:03:17 +02:00
|
|
|
|
|
|
|
|
|
# local imports
|
|
|
|
|
from chainqueue.adapters.base import Adapter
|
|
|
|
|
|
2021-07-18 12:02:14 +02:00
|
|
|
|
#logg = logging.getLogger(__name__)
|
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
|
2021-06-03 11:03:17 +02:00
|
|
|
|
|
|
|
|
|
class EthAdapter(Adapter):
|
|
|
|
|
|
2021-07-18 12:02:14 +02:00
|
|
|
|
def translate(self, bytecode, chain_spec):
|
|
|
|
|
logg.debug('bytecode {}'.format(bytecode))
|
2021-06-03 11:03:17 +02:00
|
|
|
|
tx = unpack(bytecode, chain_spec)
|
|
|
|
|
tx['source_token'] = ZERO_ADDRESS
|
|
|
|
|
tx['destination_token'] = ZERO_ADDRESS
|
|
|
|
|
tx['from_value'] = tx['value']
|
|
|
|
|
tx['to_value'] = tx['value']
|
|
|
|
|
return tx
|
|
|
|
|
|
|
|
|
|
|
2021-07-17 08:22:02 +02:00
|
|
|
|
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?
|
|
|
|
|
|
|
|
|
|
|
2021-07-18 12:02:14 +02:00
|
|
|
|
def add(self, bytecode, chain_spec, session=None):
|
|
|
|
|
tx = self.translate(bytecode, chain_spec)
|
2021-06-03 11:03:17 +02:00
|
|
|
|
r = self.backend.create(chain_spec, tx['nonce'], tx['from'], tx['hash'], add_0x(bytecode.hex()), session=session)
|
|
|
|
|
if r:
|
|
|
|
|
session.rollback()
|
|
|
|
|
session.close()
|
|
|
|
|
return r
|
|
|
|
|
r = self.backend.cache(tx, session=session)
|
|
|
|
|
session.commit()
|
|
|
|
|
return r
|
|
|
|
|
|
|
|
|
|
|
2021-06-04 20:48:19 +02:00
|
|
|
|
# def cache(self, chain_spec):
|
|
|
|
|
# session = self.backend.create_session()
|
|
|
|
|
# r = self.backend.create(chain_spec, tx['nonce'], tx['from'], tx['hash'], add_0x(bytecode.hex()), session=session)
|
|
|
|
|
# session.close()
|
2021-06-03 11:03:17 +02:00
|
|
|
|
|