From fcb5924fe80b8d945512d6ec26f0abccf2bc8ab5 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 12 Oct 2026 10:04:48 +0000 Subject: [PATCH] SwapAsset: new `sanitize_input` param --- mmgen/proto/rune/rpc/remote.py | 4 ++-- mmgen/swap/asset.py | 7 ++++++- mmgen/swap/util.py | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/mmgen/proto/rune/rpc/remote.py b/mmgen/proto/rune/rpc/remote.py index 36cdde27..d06033bf 100644 --- a/mmgen/proto/rune/rpc/remote.py +++ b/mmgen/proto/rune/rpc/remote.py @@ -142,8 +142,8 @@ class THORChainRemoteRPCClient(RemoteRPCClient): def quote(self, send_asset: str, recv_asset: str, amt: Decimal): "get a swap quote for a given send asset, receive asset and amount" from ....swap.util import init_swap_proto, get_swap_asset - from_asset = get_swap_asset(self.cfg, send_asset, direction='send') - to_asset = get_swap_asset(self.cfg, recv_asset, direction='recv') + from_asset = get_swap_asset(self.cfg, send_asset, direction='send', sanitize_input=True) + to_asset = get_swap_asset(self.cfg, recv_asset, direction='recv', sanitize_input=True) send_amt = init_swap_proto(self.cfg, from_asset).coin_amt(str(amt)) return self.do_quote(from_asset, to_asset, send_amt) diff --git a/mmgen/swap/asset.py b/mmgen/swap/asset.py index cee40f49..7a5779ae 100644 --- a/mmgen/swap/asset.py +++ b/mmgen/swap/asset.py @@ -93,7 +93,12 @@ class SwapAsset: def memo_asset_name(self): return self.data.abbr or self.data.full_name - def __init__(self, name, direction): + def __init__(self, name, direction, sanitize_input=False): + + if sanitize_input: + name = name.upper() + if '.' in name and (ss := name.split('.', 1)) and ss[0] == ss[1]: # BTC.BTC -> BTC + name = ss[0] if name not in self.assets_data: die('SwapAssetError', f'{name!r}: unrecognized asset') diff --git a/mmgen/swap/util.py b/mmgen/swap/util.py index 0106105f..9e4e00d8 100644 --- a/mmgen/swap/util.py +++ b/mmgen/swap/util.py @@ -27,7 +27,7 @@ def init_swap_proto(cfg, asset): tokensym = asset.tokensym, need_amt = True) -def get_swap_asset(cfg, asset, *, direction='send'): +def get_swap_asset(cfg, asset, *, direction='send', sanitize_input=False): "given an asset symbol, and optionally direction, return a swap asset instance" assert isinstance(asset, str), '‘asset’ must be a string' - return get_swap_proto_mod(cfg.swap_proto).SwapAsset(asset, direction) + return get_swap_proto_mod(cfg.swap_proto).SwapAsset(asset, direction, sanitize_input=sanitize_input)