Add upcoming getter
This commit is contained in:
13
chainqueue/adapters/base.py
Normal file
13
chainqueue/adapters/base.py
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
class Adapter:
|
||||
|
||||
def __init__(self, backend):
|
||||
self.backend = backend
|
||||
|
||||
|
||||
def process(self, chain_spec):
|
||||
raise NotImplementedEror()
|
||||
|
||||
|
||||
def add(self, chain_spec, bytecode):
|
||||
raise NotImplementedEror()
|
||||
@@ -1,21 +1,49 @@
|
||||
# external imports
|
||||
from chainlib.eth.constant import ZERO_ADDRESS
|
||||
from chainlib.eth.tx import (
|
||||
unpack,
|
||||
)
|
||||
from hexathon import add_0x
|
||||
from hexathon import (
|
||||
add_0x,
|
||||
strip_0x,
|
||||
)
|
||||
|
||||
# local imports
|
||||
from chainqueue.adapters.base import Adapter
|
||||
from chainqueue.enum import StatusBits
|
||||
|
||||
|
||||
class EthAdapter:
|
||||
class EthAdapter(Adapter):
|
||||
|
||||
def __init__(self, backend):
|
||||
self.backend = backend
|
||||
|
||||
def translate(self, chain_spec, bytecode):
|
||||
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
|
||||
|
||||
|
||||
def add(self, chain_spec, bytecode):
|
||||
tx = unpack(bytecode, chain_spec)
|
||||
tx = self.translate(chain_spec, bytecode)
|
||||
session = self.backend.create_session()
|
||||
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()
|
||||
session.close()
|
||||
return r
|
||||
|
||||
|
||||
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()
|
||||
return r
|
||||
|
||||
|
||||
def process(self, chain_spec):
|
||||
return self.backend.get(chain_spec, StatusBits.QUEUED, unpack)
|
||||
|
||||
Reference in New Issue
Block a user