Merge pull request #166 from bacoinin/fix_part_balances_checks
Some checks are pending
lint / build (3.12) (push) Waiting to run

Fix part balances checks
This commit is contained in:
tecnovert 2024-11-26 18:37:43 +00:00 committed by GitHub
commit b1b00b5342
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 4 deletions

View file

@ -166,7 +166,13 @@ class PARTInterface(BTCInterface):
def getUnspentsByAddr(self): def getUnspentsByAddr(self):
unspent_addr = dict() unspent_addr = dict()
unspent = self.rpc_wallet("listunspent") balance_type = self.balance_type()
if balance_type == BalanceTypes.PLAIN:
unspent = self.rpc_wallet("listunspent")
elif balance_type == BalanceTypes.BLIND:
unspent = self.rpc_wallet("listunspentblind")
else:
raise ValueError(f"getUnspentsByAddr not implemented for {balance_type} type")
for u in unspent: for u in unspent:
if u["spendable"] is not True: if u["spendable"] is not True:
continue continue

View file

@ -374,6 +374,20 @@ def main():
wallet_from = read_json_api_wallet( wallet_from = read_json_api_wallet(
"wallets/{}".format(coin_from_data["ticker"]) "wallets/{}".format(coin_from_data["ticker"])
) )
coin_ticker = coin_from_data["ticker"]
if coin_ticker=="PART" and "variant" in coin_from_data:
coin_variant = coin_from_data["variant"]
if coin_variant == "Anon":
coin_from_data_name = "PART_ANON"
wallet_balance: float = float(wallet_from["anon_balance"])
elif coin_variant == "Blind":
coin_from_data_name = "PART_BLIND"
wallet_balance: float = float(wallet_from["blind_balance"])
else:
raise ValueError(f"{coin_ticker} variant {coin_variant} not handled")
else:
coin_from_data_name = coin_ticker
wallet_balance: float = float(wallet_from["balance"])
for offer in sent_offers: for offer in sent_offers:
created_offers = script_state.get("offers", {}) created_offers = script_state.get("offers", {})
@ -390,7 +404,7 @@ def main():
None, None,
): ):
offers_found += 1 offers_found += 1
if float(wallet_from["balance"]) <= float( if wallet_balance <= float(
offer_template["min_coin_from_amt"] offer_template["min_coin_from_amt"]
): ):
offer_id = offer["offer_id"] offer_id = offer["offer_id"]
@ -409,7 +423,7 @@ def main():
min_offer_amount: float = offer_template.get( min_offer_amount: float = offer_template.get(
"amount_step", max_offer_amount "amount_step", max_offer_amount
) )
wallet_balance: float = float(wallet_from["balance"])
min_wallet_from_amount: float = float( min_wallet_from_amount: float = float(
offer_template["min_coin_from_amt"] offer_template["min_coin_from_amt"]
) )
@ -471,7 +485,7 @@ def main():
"addr_from": ( "addr_from": (
-1 if template_from_addr == "auto" else template_from_addr -1 if template_from_addr == "auto" else template_from_addr
), ),
"coin_from": coin_from_data["ticker"], "coin_from": coin_from_data_name,
"coin_to": coin_to_data["ticker"], "coin_to": coin_to_data["ticker"],
"amt_from": offer_amount, "amt_from": offer_amount,
"amt_var": offer_template["amount_variable"], "amt_var": offer_template["amount_variable"],