mirror of
https://github.com/basicswap/basicswap.git
synced 2026-03-19 08:17:25 +01:00
feat: add FIRO withdrawal and Spark address caching functionality
This commit is contained in:
@@ -2981,6 +2981,21 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
self.log.info_s(f"In txn: {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(
|
||||
self, type_from: str, type_to: str, value, addr_to: str, subfee: bool
|
||||
) -> str:
|
||||
@@ -3130,6 +3145,15 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
self.setStringKV(key_str, 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):
|
||||
self.log.debug(f"getCachedStealthAddressForCoin {Coins(coin_type).name}")
|
||||
|
||||
@@ -3149,6 +3173,23 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
self.closeDB(use_cursor)
|
||||
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):
|
||||
self.log.debug(f"getCachedWalletRestoreHeight {ci.coin_name()}")
|
||||
|
||||
@@ -11618,6 +11659,17 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
rv["mweb_pending"] = (
|
||||
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
|
||||
except Exception as e:
|
||||
|
||||
@@ -82,6 +82,9 @@ def withdraw_coin(swap_client, coin_type, post_string, is_json):
|
||||
elif coin_type == Coins.LTC:
|
||||
type_from = get_data_entry_or(post_data, "type_from", "plain")
|
||||
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):
|
||||
txid_hex = swap_client.withdrawCoin(coin_type, value, address, sweepall)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user