rpc: new get_remote_rpc() function
This commit is contained in:
parent
2c4f96e6a4
commit
3b1839c734
6 changed files with 27 additions and 15 deletions
|
|
@ -54,8 +54,10 @@ def main():
|
|||
|
||||
match cfg.coin:
|
||||
case 'RUNE':
|
||||
from .proto.rune.rpc.remote import THORChainRemoteRPCClient as cls
|
||||
cmds = get_cmds(cls.mods)
|
||||
from .rpc import get_remote_rpc
|
||||
from .protocol import init_proto
|
||||
rpc = get_remote_rpc(cfg, init_proto(cfg, cfg.coin))
|
||||
cmds = get_cmds(rpc.mods)
|
||||
case _:
|
||||
cmds = ()
|
||||
|
||||
|
|
@ -66,13 +68,13 @@ def main():
|
|||
case ['help', cmd]:
|
||||
if cmd in cmds:
|
||||
from .tool.help import gen_tool_cmd_usage
|
||||
Msg('\n'.join(gen_tool_cmd_usage(None, cmd, lambda x: cls)))
|
||||
Msg('\n'.join(gen_tool_cmd_usage(None, cmd, lambda x: rpc)))
|
||||
else:
|
||||
fs = '‘{}’: invalid command\n\nSupported commands:\n{}'
|
||||
die(1, fs.format(cmd, fmt_list(cmds, fmt='col', indent=' ' * 4)))
|
||||
case [cmd, *cmd_args] if cmd in cmds:
|
||||
args, kwargs = process_args(cmd, cmd_args, cls)
|
||||
res = getattr(cls(cfg, cfg._proto), cmd)(*args, **kwargs)
|
||||
args, kwargs = process_args(cmd, cmd_args, rpc)
|
||||
res = getattr(rpc, cmd)(*args, **kwargs)
|
||||
import json
|
||||
from .ui import colorize_json
|
||||
text = json.dumps(res, indent=2)
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ async def process_tx(tx):
|
|||
return 0
|
||||
|
||||
if tx.is_swap:
|
||||
await tx.check_swap_network()
|
||||
tx.check_swap_network()
|
||||
if not tx.check_swap_expiry():
|
||||
die(1, 'Swap quote has expired. Please re-create the transaction')
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,11 @@ import importlib
|
|||
from ..util import die, fmt, fmt_list
|
||||
from ..obj import NonNegativeInt
|
||||
|
||||
def get_remote_rpc(cfg, proto):
|
||||
return getattr(importlib.import_module(
|
||||
f'mmgen.proto.{proto.base_proto_coin.lower()}.rpc.remote'),
|
||||
proto.base_proto + 'RemoteRPCClient')(cfg=cfg, proto=proto)
|
||||
|
||||
async def rpc_init(
|
||||
cfg,
|
||||
proto = None,
|
||||
|
|
@ -30,9 +35,7 @@ async def rpc_init(
|
|||
die(1, f'rpc_init() not supported for {proto.name} protocol!')
|
||||
|
||||
if proto.rpc_type == 'remote':
|
||||
return getattr(importlib.import_module(
|
||||
f'mmgen.proto.{proto.base_proto_coin.lower()}.rpc.remote'),
|
||||
proto.base_proto + 'RemoteRPCClient')(cfg=cfg, proto=proto)
|
||||
return get_remote_rpc(cfg, proto)
|
||||
|
||||
from ..daemon import CoinDaemon
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,11 @@ def get_swap_proto_mod(swap_proto_name):
|
|||
import importlib
|
||||
return importlib.import_module(f'mmgen.swap.proto.{swap_proto_name}')
|
||||
|
||||
def get_swap_proto_rpc(cfg, coin):
|
||||
from ..protocol import init_proto
|
||||
from ..rpc import get_remote_rpc
|
||||
return get_remote_rpc(cfg, init_proto(cfg, coin))
|
||||
|
||||
def init_swap_proto(cfg, asset):
|
||||
from ..protocol import init_proto
|
||||
return init_proto(
|
||||
|
|
|
|||
|
|
@ -221,6 +221,11 @@ class Base(MMGenObject):
|
|||
keypress_confirm(self.cfg, 'Continue?', default_yes=True, do_exit=True)
|
||||
|
||||
# swap methods:
|
||||
@cached_property
|
||||
def swap_proto_rpc(self):
|
||||
from ..swap.util import get_swap_proto_rpc
|
||||
return get_swap_proto_rpc(self.cfg, self.swap_proto_mod.coin)
|
||||
|
||||
@cached_property
|
||||
def swap_proto_mod(self):
|
||||
from ..swap.util import get_swap_proto_mod
|
||||
|
|
@ -243,11 +248,8 @@ class Base(MMGenObject):
|
|||
x = '[unknown]'
|
||||
return SwapAsset._ad(x, x, x, x, x)
|
||||
|
||||
async def check_swap_network(self):
|
||||
from ..protocol import init_proto
|
||||
from ..rpc import rpc_init
|
||||
proto = init_proto(self.cfg, self.swap_proto_mod.coin)
|
||||
rpc = await rpc_init(self.cfg, proto)
|
||||
def check_swap_network(self):
|
||||
rpc = self.swap_proto_rpc
|
||||
data = rpc.inbound_addrs()
|
||||
for asset in (self.send_asset, self.recv_asset):
|
||||
if asset.name == 'RUNE':
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ class NewSwap(New):
|
|||
|
||||
await parse()
|
||||
|
||||
await self.check_swap_network()
|
||||
self.check_swap_network()
|
||||
|
||||
for asset in (self.send_asset, self.recv_asset):
|
||||
if asset.name not in sa.tested:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue