feat: add FIRO withdrawal and Spark address caching functionality

This commit is contained in:
Dhaval Chaudhari
2025-11-20 00:22:03 +05:30
parent cd98a8eb64
commit 0bf4af100a
2 changed files with 55 additions and 0 deletions

View File

@@ -2981,6 +2981,21 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
self.log.info_s(f"In txn: {txid}") self.log.info_s(f"In txn: {txid}")
return txid return txid
def withdrawFIRO(self, type_from, value, addr_to, subfee: bool) -> str:
ci = self.ci(Coins.FIRO)
self.log.info(
"withdrawFIRO{}".format(
""
if self.log.safe_logs
else " {} {} to {} {}".format(
value, type_from, addr_to, " subfee" if subfee else ""
)
)
)
txid = ci.withdrawCoin(value, type_from, addr_to, subfee)
self.log.info_s(f"In txn: {txid}")
return txid
def withdrawParticl( def withdrawParticl(
self, type_from: str, type_to: str, value, addr_to: str, subfee: bool self, type_from: str, type_to: str, value, addr_to: str, subfee: bool
) -> str: ) -> str:
@@ -3130,6 +3145,15 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
self.setStringKV(key_str, addr) self.setStringKV(key_str, addr)
return addr return addr
def cacheNewSparkAddressForCoin(self, coin_type):
"""Cache a new Spark address for FIRO."""
self.log.debug(f"cacheNewSparkAddressForCoin {Coins(coin_type).name}")
ci = self.ci(coin_type)
key_str = "spark_addr_" + ci.coin_name().lower()
addr = ci.getNewSparkAddress()
self.setStringKV(key_str, addr)
return addr
def getCachedStealthAddressForCoin(self, coin_type, cursor=None): def getCachedStealthAddressForCoin(self, coin_type, cursor=None):
self.log.debug(f"getCachedStealthAddressForCoin {Coins(coin_type).name}") self.log.debug(f"getCachedStealthAddressForCoin {Coins(coin_type).name}")
@@ -3149,6 +3173,23 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
self.closeDB(use_cursor) self.closeDB(use_cursor)
return addr return addr
def getCachedSparkAddressForCoin(self, coin_type, cursor=None):
"""Get cached Spark address for FIRO, generating one if needed."""
self.log.debug(f"getCachedSparkAddressForCoin {Coins(coin_type).name}")
ci = self.ci(coin_type)
key_str = "spark_addr_" + ci.coin_name().lower()
use_cursor = self.openDB(cursor)
try:
addr = self.getStringKV(key_str, use_cursor)
if addr is None:
addr = ci.getNewSparkAddress()
self.log.info(f"Generated new Spark address for {ci.coin_name()}")
self.setStringKV(key_str, addr, use_cursor)
finally:
if cursor is None:
self.closeDB(use_cursor)
return addr
def getCachedWalletRestoreHeight(self, ci, cursor=None): def getCachedWalletRestoreHeight(self, ci, cursor=None):
self.log.debug(f"getCachedWalletRestoreHeight {ci.coin_name()}") self.log.debug(f"getCachedWalletRestoreHeight {ci.coin_name()}")
@@ -11618,6 +11659,17 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
rv["mweb_pending"] = ( rv["mweb_pending"] = (
walletinfo["mweb_unconfirmed"] + walletinfo["mweb_immature"] walletinfo["mweb_unconfirmed"] + walletinfo["mweb_immature"]
) )
elif coin == Coins.FIRO:
try:
rv["spark_address"] = self.getCachedSparkAddressForCoin(Coins.FIRO)
except Exception as e:
self.log.warning(
f"getCachedSparkAddressForCoin for {ci.coin_name()} failed with: {e}."
)
rv["spark_balance"] = walletinfo["spark_balance"]
rv["spark_pending"] = (
walletinfo["spark_unconfirmed"] + walletinfo["spark_immature"]
)
return rv return rv
except Exception as e: except Exception as e:

View File

@@ -82,6 +82,9 @@ def withdraw_coin(swap_client, coin_type, post_string, is_json):
elif coin_type == Coins.LTC: elif coin_type == Coins.LTC:
type_from = get_data_entry_or(post_data, "type_from", "plain") type_from = get_data_entry_or(post_data, "type_from", "plain")
txid_hex = swap_client.withdrawLTC(type_from, value, address, subfee) txid_hex = swap_client.withdrawLTC(type_from, value, address, subfee)
elif coin_type == Coins.FIRO:
type_from = get_data_entry_or(post_data, "type_from", "plain")
txid_hex = swap_client.withdrawFIRO(type_from, value, address, subfee)
elif coin_type in (Coins.XMR, Coins.WOW): elif coin_type in (Coins.XMR, Coins.WOW):
txid_hex = swap_client.withdrawCoin(coin_type, value, address, sweepall) txid_hex = swap_client.withdrawCoin(coin_type, value, address, sweepall)
else: else: