CoinAmt, swap: minor cleanups

This commit is contained in:
The MMGen Project 2026-09-29 09:23:31 +00:00
commit c47919fef9
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
5 changed files with 19 additions and 18 deletions

View file

@ -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()

View file

@ -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')}

View file

@ -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)

View file

@ -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)

View file

@ -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'}}