add tx dispatch

This commit is contained in:
nolash
2021-06-02 15:05:48 +02:00
parent 99af484f30
commit 3872d0d9b4
3 changed files with 45 additions and 7 deletions

View File

@@ -2,6 +2,7 @@
from chainlib.eth.constant import ZERO_ADDRESS
from chainlib.eth.tx import (
unpack,
raw,
)
from hexathon import (
add_0x,
@@ -15,8 +16,7 @@ from chainqueue.enum import StatusBits
class EthAdapter(Adapter):
def translate(self, chain_spec, bytecode):
def translate(self, bytecode, chain_spec):
tx = unpack(bytecode, chain_spec)
tx['source_token'] = ZERO_ADDRESS
tx['destination_token'] = ZERO_ADDRESS
@@ -26,7 +26,7 @@ class EthAdapter(Adapter):
def add(self, chain_spec, bytecode):
tx = self.translate(chain_spec, bytecode)
tx = self.translate(bytecode, 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)
if r:
@@ -45,5 +45,13 @@ class EthAdapter(Adapter):
session.close()
def process(self, chain_spec):
def upcoming(self, chain_spec):
return self.backend.get(chain_spec, StatusBits.QUEUED, unpack)
def dispatch(self, chain_spec, rpc, tx_hash, signed_tx):
o = raw(signed_tx)
session = self.backend.create_session()
r = self.backend.dispatch(chain_spec, rpc, tx_hash, o)
session.close()
return r