From c47919fef9988c0241607b7153bb26b3ca20755e Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Tue, 29 Sep 2026 09:23:31 +0000 Subject: [PATCH] CoinAmt, swap: minor cleanups --- mmgen/amt.py | 22 ++++++++++------------ mmgen/proto/rune/params.py | 6 +++--- mmgen/swap/proto/thorchain/thornode.py | 2 +- mmgen/tx/new_swap.py | 3 ++- test/cmdtest_d/httpd/thornode/rpc.py | 4 +++- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/mmgen/amt.py b/mmgen/amt.py index 91ea1ba6..7c3e0bd5 100755 --- a/mmgen/amt.py +++ b/mmgen/amt.py @@ -125,45 +125,43 @@ class CoinAmt(Decimal, Hilite, InitErrors): # abstract class def __repr__(self): return "{}('{}')".format(type(self).__name__, self.__str__()) + def incorrect_type_error(self, other): + raise TypeError( + f'operand {other} is of incorrect type ({type(other).__name__} != {type(self).__name__})') + def __add__(self, other): """ we must allow other to be int(0) to use the sum() builtin """ if type(other) is type(self) or (other == 0 and isinstance(other, int)): return type(self)(Decimal.__add__(self, other), from_decimal=True) - raise TypeError( - f'operand {other} is of incorrect type ({type(other).__name__} != {type(self).__name__})') + self.incorrect_type_error(other) __radd__ = __add__ def __sub__(self, other): if type(other) is type(self): return type(self)(Decimal.__sub__(Decimal(self), Decimal(other)), from_decimal=True) - raise TypeError( - f'operand {other} is of incorrect type ({type(other).__name__} != {type(self).__name__})') + self.incorrect_type_error(other) def __rsub__(self, other): if type(other) is type(self): return type(self)(Decimal.__rsub__(self, other), from_decimal=True) - raise TypeError( - f'operand {other} is of incorrect type ({type(other).__name__} != {type(self).__name__})') + self.incorrect_type_error(other) def __mul__(self, other): return type(self)('{:0.{p}f}'.format( - Decimal.__mul__(self, Decimal(other)), - p = self.max_prec)) + Decimal.__mul__(self, Decimal(other)), p=self.max_prec)) __rmul__ = __mul__ def __truediv__(self, other): return type(self)('{:0.{p}f}'.format( - Decimal.__truediv__(self, Decimal(other)), - p = self.max_prec)) + Decimal.__truediv__(self, Decimal(other)), p=self.max_prec)) def __rtruediv__(self, other): return type(self)('{:0.{p}f}'.format( - Decimal.__rtruediv__(self, Decimal(other)), - p = self.max_prec)) + Decimal.__rtruediv__(self, Decimal(other)), p=self.max_prec)) def __neg__(self): self.method_not_implemented() diff --git a/mmgen/proto/rune/params.py b/mmgen/proto/rune/params.py index 369a53b8..a4da6192 100755 --- a/mmgen/proto/rune/params.py +++ b/mmgen/proto/rune/params.py @@ -49,7 +49,7 @@ class mainnet(CoinProtocol.Secp256k1): rpc_remote_params = {'server_domain': Hostname('liquify.com')} rpc_remote_rest_params = {'host': Hostname('gateway.liquify.com/chain/thorchain_api')} rpc_remote_rpc_params = {'host': Hostname('gateway.liquify.com/chain/thorchain_rpc')} - rpc_swap_params = {'host': Hostname('gateway.liquify.com/chain/thorchain_api')} + rpc_remote_swap_params = {'host': Hostname('gateway.liquify.com/chain/thorchain_api')} def decode_addr(self, addr): hrp, data = bech32.bech32_decode(addr) @@ -70,7 +70,7 @@ class testnet(mainnet): # testnet is stagenet bech32_hrp = 'sthor' rpc_remote_rest_params = {'host': Hostname('stagenet-thornode.ninerealms.com')} rpc_remote_rpc_params = {'host': Hostname('stagenet-rpc.ninerealms.com')} - rpc_swap_params = {'host': Hostname('stagenet-thornode.ninerealms.com')} + rpc_remote_swap_params = {'host': Hostname('stagenet-thornode.ninerealms.com')} class regtest(testnet): # regtest is deprecated testnet bech32_hrp = 'tthor' @@ -81,4 +81,4 @@ class regtest(testnet): # regtest is deprecated testnet 'host': Hostname('localhost:18800'), 'verify': False} rpc_remote_rpc_params = rpc_remote_rest_params - rpc_swap_params = rpc_remote_rest_params | {'host': Hostname('localhost:18900')} + rpc_remote_swap_params = rpc_remote_rest_params | {'host': Hostname('localhost:18900')} diff --git a/mmgen/swap/proto/thorchain/thornode.py b/mmgen/swap/proto/thorchain/thornode.py index efc68ec2..442c9196 100755 --- a/mmgen/swap/proto/thorchain/thornode.py +++ b/mmgen/swap/proto/thorchain/thornode.py @@ -32,7 +32,7 @@ class ThornodeSwapClient(HTTPClient): def __init__(self, tx, *, network_proto=None, host=None): rune_proto = init_proto(tx.cfg, 'rune', network=tx.cfg._proto.network) - for k, v in rune_proto.rpc_swap_params.items(): + for k, v in rune_proto.rpc_remote_swap_params.items(): setattr(self, k, v) super().__init__(tx.cfg, network_proto=network_proto, host=host) diff --git a/mmgen/tx/new_swap.py b/mmgen/tx/new_swap.py index ac2f4d3a..eb4d0d55 100755 --- a/mmgen/tx/new_swap.py +++ b/mmgen/tx/new_swap.py @@ -14,10 +14,11 @@ tx.new_swap: new swap transaction class from collections import namedtuple -from .new import New from ..amt import UniAmt from ..swap.util import get_swap_proto_mod, init_swap_proto +from .new import New + def get_send_proto(cfg): try: arg = cfg._args.pop(0) diff --git a/test/cmdtest_d/httpd/thornode/rpc.py b/test/cmdtest_d/httpd/thornode/rpc.py index e9a409d9..8d822102 100755 --- a/test/cmdtest_d/httpd/thornode/rpc.py +++ b/test/cmdtest_d/httpd/thornode/rpc.py @@ -25,6 +25,8 @@ class ThornodeRPCServer(ThornodeServer): class responses: + # pylint: disable=unsubscriptable-object + def get_balance(m, length): return [ {'denom': 'foocoin', 'amount': 321321321321}, @@ -34,7 +36,7 @@ class ThornodeRPCServer(ThornodeServer): def get_account_info(m, length): return { 'value': { - 'address': m[1], # pylint: disable=unsubscriptable-object + 'address': m[1], 'pub_key': 'PubKeySecp256k1{0000}', 'account_number': '1234', 'sequence': '333444'}}