Configurable cache dir (#567)

* Add a configurable cache dir

* Fix UDL field position
This commit is contained in:
Ross Savage
2024-11-18 13:36:38 +01:00
committed by GitHub
parent f65a8ae2c3
commit 802e9eece7
16 changed files with 84 additions and 17 deletions

View File

@@ -16,6 +16,9 @@ pub(crate) struct Args {
#[clap(short, long)] #[clap(short, long)]
pub(crate) data_dir: Option<String>, pub(crate) data_dir: Option<String>,
#[clap(short, long)]
pub(crate) cache_dir: Option<String>,
#[clap(short, long)] #[clap(short, long)]
pub(crate) log_file: Option<String>, pub(crate) log_file: Option<String>,
@@ -75,6 +78,7 @@ async fn main() -> Result<()> {
.map(|var| var.into_string().expect("Expected valid API key string")); .map(|var| var.into_string().expect("Expected valid API key string"));
let mut config = LiquidSdk::default_config(network, breez_api_key)?; let mut config = LiquidSdk::default_config(network, breez_api_key)?;
config.working_dir = data_dir_str; config.working_dir = data_dir_str;
config.cache_dir = args.cache_dir;
let sdk = LiquidSdk::connect(ConnectRequest { let sdk = LiquidSdk::connect(ConnectRequest {
mnemonic: mnemonic.to_string(), mnemonic: mnemonic.to_string(),
config, config,

View File

@@ -22,6 +22,7 @@ import breez_sdk_liquid_notification.job.Job
import breez_sdk_liquid_notification.job.LnurlPayInfoJob import breez_sdk_liquid_notification.job.LnurlPayInfoJob
import breez_sdk_liquid_notification.job.LnurlPayInvoiceJob import breez_sdk_liquid_notification.job.LnurlPayInvoiceJob
import breez_sdk_liquid_notification.job.SwapUpdatedJob import breez_sdk_liquid_notification.job.SwapUpdatedJob
import kotlin.io.path.Path
import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@@ -110,6 +111,10 @@ abstract class ForegroundService : SdkForegroundService, EventListener, Service(
// Connect to SDK if source intent has data message with valid payload // Connect to SDK if source intent has data message with valid payload
getConnectRequest()?.let { connectRequest -> getConnectRequest()?.let { connectRequest ->
if (connectRequest.config.cacheDir == null) {
connectRequest.config.cacheDir = Path(connectRequest.config.workingDir, "pluginCache").toString()
}
getJobFromIntent(intent)?.also { job -> getJobFromIntent(intent)?.also { job ->
launchSdkConnection(connectRequest, job) launchSdkConnection(connectRequest, job)
} ?: run { } ?: run {

View File

@@ -439,6 +439,7 @@ typedef struct wire_cst_config {
struct wire_cst_list_prim_u_8_strict *bitcoin_electrum_url; struct wire_cst_list_prim_u_8_strict *bitcoin_electrum_url;
struct wire_cst_list_prim_u_8_strict *mempoolspace_url; struct wire_cst_list_prim_u_8_strict *mempoolspace_url;
struct wire_cst_list_prim_u_8_strict *working_dir; struct wire_cst_list_prim_u_8_strict *working_dir;
struct wire_cst_list_prim_u_8_strict *cache_dir;
int32_t network; int32_t network;
uint64_t payment_timeout_sec; uint64_t payment_timeout_sec;
uint32_t zero_conf_min_fee_rate_msat; uint32_t zero_conf_min_fee_rate_msat;

View File

@@ -20,12 +20,16 @@ open class SDKNotificationService: UNNotificationServiceExtension {
self.contentHandler = contentHandler self.contentHandler = contentHandler
self.bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) self.bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
guard let connectRequest = self.getConnectRequest() else { guard var connectRequest = self.getConnectRequest() else {
if let content = bestAttemptContent { if let content = bestAttemptContent {
contentHandler(content) contentHandler(content)
} }
return return
} }
if connectRequest.config.cacheDir == nil {
connectRequest.config.cacheDir = URL(filePath: connectRequest.config.workingDir).appendingPathComponent("pluginCache").path
}
if let currentTask = self.getTaskFromNotification() { if let currentTask = self.getTaskFromNotification() {
self.currentTask = currentTask self.currentTask = currentTask

View File

@@ -311,6 +311,7 @@ dictionary Config {
u64 payment_timeout_sec; u64 payment_timeout_sec;
u32 zero_conf_min_fee_rate_msat; u32 zero_conf_min_fee_rate_msat;
string? breez_api_key; string? breez_api_key;
string? cache_dir;
u64? zero_conf_max_amount_sat; u64? zero_conf_max_amount_sat;
}; };

View File

@@ -2283,6 +2283,7 @@ impl SseDecode for crate::model::Config {
let mut var_bitcoinElectrumUrl = <String>::sse_decode(deserializer); let mut var_bitcoinElectrumUrl = <String>::sse_decode(deserializer);
let mut var_mempoolspaceUrl = <String>::sse_decode(deserializer); let mut var_mempoolspaceUrl = <String>::sse_decode(deserializer);
let mut var_workingDir = <String>::sse_decode(deserializer); let mut var_workingDir = <String>::sse_decode(deserializer);
let mut var_cacheDir = <Option<String>>::sse_decode(deserializer);
let mut var_network = <crate::model::LiquidNetwork>::sse_decode(deserializer); let mut var_network = <crate::model::LiquidNetwork>::sse_decode(deserializer);
let mut var_paymentTimeoutSec = <u64>::sse_decode(deserializer); let mut var_paymentTimeoutSec = <u64>::sse_decode(deserializer);
let mut var_zeroConfMinFeeRateMsat = <u32>::sse_decode(deserializer); let mut var_zeroConfMinFeeRateMsat = <u32>::sse_decode(deserializer);
@@ -2293,6 +2294,7 @@ impl SseDecode for crate::model::Config {
bitcoin_electrum_url: var_bitcoinElectrumUrl, bitcoin_electrum_url: var_bitcoinElectrumUrl,
mempoolspace_url: var_mempoolspaceUrl, mempoolspace_url: var_mempoolspaceUrl,
working_dir: var_workingDir, working_dir: var_workingDir,
cache_dir: var_cacheDir,
network: var_network, network: var_network,
payment_timeout_sec: var_paymentTimeoutSec, payment_timeout_sec: var_paymentTimeoutSec,
zero_conf_min_fee_rate_msat: var_zeroConfMinFeeRateMsat, zero_conf_min_fee_rate_msat: var_zeroConfMinFeeRateMsat,
@@ -4324,6 +4326,7 @@ impl flutter_rust_bridge::IntoDart for crate::model::Config {
self.bitcoin_electrum_url.into_into_dart().into_dart(), self.bitcoin_electrum_url.into_into_dart().into_dart(),
self.mempoolspace_url.into_into_dart().into_dart(), self.mempoolspace_url.into_into_dart().into_dart(),
self.working_dir.into_into_dart().into_dart(), self.working_dir.into_into_dart().into_dart(),
self.cache_dir.into_into_dart().into_dart(),
self.network.into_into_dart().into_dart(), self.network.into_into_dart().into_dart(),
self.payment_timeout_sec.into_into_dart().into_dart(), self.payment_timeout_sec.into_into_dart().into_dart(),
self.zero_conf_min_fee_rate_msat self.zero_conf_min_fee_rate_msat
@@ -6293,6 +6296,7 @@ impl SseEncode for crate::model::Config {
<String>::sse_encode(self.bitcoin_electrum_url, serializer); <String>::sse_encode(self.bitcoin_electrum_url, serializer);
<String>::sse_encode(self.mempoolspace_url, serializer); <String>::sse_encode(self.mempoolspace_url, serializer);
<String>::sse_encode(self.working_dir, serializer); <String>::sse_encode(self.working_dir, serializer);
<Option<String>>::sse_encode(self.cache_dir, serializer);
<crate::model::LiquidNetwork>::sse_encode(self.network, serializer); <crate::model::LiquidNetwork>::sse_encode(self.network, serializer);
<u64>::sse_encode(self.payment_timeout_sec, serializer); <u64>::sse_encode(self.payment_timeout_sec, serializer);
<u32>::sse_encode(self.zero_conf_min_fee_rate_msat, serializer); <u32>::sse_encode(self.zero_conf_min_fee_rate_msat, serializer);
@@ -8236,6 +8240,7 @@ mod io {
bitcoin_electrum_url: self.bitcoin_electrum_url.cst_decode(), bitcoin_electrum_url: self.bitcoin_electrum_url.cst_decode(),
mempoolspace_url: self.mempoolspace_url.cst_decode(), mempoolspace_url: self.mempoolspace_url.cst_decode(),
working_dir: self.working_dir.cst_decode(), working_dir: self.working_dir.cst_decode(),
cache_dir: self.cache_dir.cst_decode(),
network: self.network.cst_decode(), network: self.network.cst_decode(),
payment_timeout_sec: self.payment_timeout_sec.cst_decode(), payment_timeout_sec: self.payment_timeout_sec.cst_decode(),
zero_conf_min_fee_rate_msat: self.zero_conf_min_fee_rate_msat.cst_decode(), zero_conf_min_fee_rate_msat: self.zero_conf_min_fee_rate_msat.cst_decode(),
@@ -9593,6 +9598,7 @@ mod io {
bitcoin_electrum_url: core::ptr::null_mut(), bitcoin_electrum_url: core::ptr::null_mut(),
mempoolspace_url: core::ptr::null_mut(), mempoolspace_url: core::ptr::null_mut(),
working_dir: core::ptr::null_mut(), working_dir: core::ptr::null_mut(),
cache_dir: core::ptr::null_mut(),
network: Default::default(), network: Default::default(),
payment_timeout_sec: Default::default(), payment_timeout_sec: Default::default(),
zero_conf_min_fee_rate_msat: Default::default(), zero_conf_min_fee_rate_msat: Default::default(),
@@ -11497,6 +11503,7 @@ mod io {
bitcoin_electrum_url: *mut wire_cst_list_prim_u_8_strict, bitcoin_electrum_url: *mut wire_cst_list_prim_u_8_strict,
mempoolspace_url: *mut wire_cst_list_prim_u_8_strict, mempoolspace_url: *mut wire_cst_list_prim_u_8_strict,
working_dir: *mut wire_cst_list_prim_u_8_strict, working_dir: *mut wire_cst_list_prim_u_8_strict,
cache_dir: *mut wire_cst_list_prim_u_8_strict,
network: i32, network: i32,
payment_timeout_sec: u64, payment_timeout_sec: u64,
zero_conf_min_fee_rate_msat: u32, zero_conf_min_fee_rate_msat: u32,

View File

@@ -36,10 +36,12 @@ pub struct Config {
pub bitcoin_electrum_url: String, pub bitcoin_electrum_url: String,
/// The mempool.space API URL, has to be in the format: `https://mempool.space/api` /// The mempool.space API URL, has to be in the format: `https://mempool.space/api`
pub mempoolspace_url: String, pub mempoolspace_url: String,
/// Directory in which all SDK files (DB, log, cache) are stored. /// Directory in which the DB and log files are stored.
/// ///
/// Prefix can be a relative or absolute path to this directory. /// Prefix can be a relative or absolute path to this directory.
pub working_dir: String, pub working_dir: String,
/// Directory in which the Liquid wallet cache is stored. Defaults to `working_dir`
pub cache_dir: Option<String>,
pub network: LiquidNetwork, pub network: LiquidNetwork,
/// Send payment timeout. See [crate::sdk::LiquidSdk::send_payment] /// Send payment timeout. See [crate::sdk::LiquidSdk::send_payment]
pub payment_timeout_sec: u64, pub payment_timeout_sec: u64,
@@ -59,6 +61,7 @@ impl Config {
bitcoin_electrum_url: "bitcoin-mainnet.blockstream.info:50002".to_string(), bitcoin_electrum_url: "bitcoin-mainnet.blockstream.info:50002".to_string(),
mempoolspace_url: "https://mempool.space/api".to_string(), mempoolspace_url: "https://mempool.space/api".to_string(),
working_dir: ".".to_string(), working_dir: ".".to_string(),
cache_dir: None,
network: LiquidNetwork::Mainnet, network: LiquidNetwork::Mainnet,
payment_timeout_sec: 15, payment_timeout_sec: 15,
zero_conf_min_fee_rate_msat: DEFAULT_ZERO_CONF_MIN_FEE_RATE_MAINNET, zero_conf_min_fee_rate_msat: DEFAULT_ZERO_CONF_MIN_FEE_RATE_MAINNET,
@@ -73,6 +76,7 @@ impl Config {
bitcoin_electrum_url: "bitcoin-testnet.blockstream.info:50002".to_string(), bitcoin_electrum_url: "bitcoin-testnet.blockstream.info:50002".to_string(),
mempoolspace_url: "https://mempool.space/testnet/api".to_string(), mempoolspace_url: "https://mempool.space/testnet/api".to_string(),
working_dir: ".".to_string(), working_dir: ".".to_string(),
cache_dir: None,
network: LiquidNetwork::Testnet, network: LiquidNetwork::Testnet,
payment_timeout_sec: 15, payment_timeout_sec: 15,
zero_conf_min_fee_rate_msat: DEFAULT_ZERO_CONF_MIN_FEE_RATE_TESTNET, zero_conf_min_fee_rate_msat: DEFAULT_ZERO_CONF_MIN_FEE_RATE_TESTNET,
@@ -81,8 +85,12 @@ impl Config {
} }
} }
pub(crate) fn get_wallet_working_dir(&self, fingerprint_hex: String) -> anyhow::Result<String> { pub(crate) fn get_wallet_dir(
Ok(PathBuf::from(self.working_dir.clone()) &self,
base_dir: &str,
fingerprint_hex: &str,
) -> anyhow::Result<String> {
Ok(PathBuf::from(base_dir)
.join(match self.network { .join(match self.network {
LiquidNetwork::Mainnet => "mainnet", LiquidNetwork::Mainnet => "mainnet",
LiquidNetwork::Testnet => "testnet", LiquidNetwork::Testnet => "testnet",
@@ -459,7 +467,7 @@ pub struct GetInfoResponse {
pub pending_send_sat: u64, pub pending_send_sat: u64,
/// Incoming amount that is pending from ongoing Receive swaps /// Incoming amount that is pending from ongoing Receive swaps
pub pending_receive_sat: u64, pub pending_receive_sat: u64,
/// The wallet's fingerprint. It is used to build the working directory in [Config::get_wallet_working_dir]. /// The wallet's fingerprint. It is used to build the working directory in [Config::get_wallet_dir].
pub fingerprint: String, pub fingerprint: String,
/// The wallet's pubkey. Used to verify signed messages. /// The wallet's pubkey. Used to verify signed messages.
pub pubkey: String, pub pubkey: String,

View File

@@ -153,14 +153,18 @@ impl LiquidSdk {
fs::create_dir_all(&config.working_dir)?; fs::create_dir_all(&config.working_dir)?;
let fingerprint_hex: String = let fingerprint_hex: String =
Xpub::decode(signer.xpub()?.as_slice())?.identifier()[0..4].to_hex(); Xpub::decode(signer.xpub()?.as_slice())?.identifier()[0..4].to_hex();
let working_dir = config.get_wallet_working_dir(fingerprint_hex)?; let working_dir = config.get_wallet_dir(&config.working_dir, &fingerprint_hex)?;
let cache_dir = config.get_wallet_dir(
config.cache_dir.as_ref().unwrap_or(&config.working_dir),
&fingerprint_hex,
)?;
let persister = Arc::new(Persister::new(&working_dir, config.network)?); let persister = Arc::new(Persister::new(&working_dir, config.network)?);
persister.init()?; persister.init()?;
let onchain_wallet = Arc::new(LiquidOnchainWallet::new( let onchain_wallet = Arc::new(LiquidOnchainWallet::new(
config.clone(), config.clone(),
&working_dir, &cache_dir,
persister.clone(), persister.clone(),
signer.clone(), signer.clone(),
)?); )?);

View File

@@ -1,5 +1,6 @@
use std::fs; use std::fs::{self, create_dir_all};
use std::io::Write; use std::io::Write;
use std::path::PathBuf;
use std::{path::Path, str::FromStr, sync::Arc}; use std::{path::Path, str::FromStr, sync::Arc};
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
@@ -109,6 +110,11 @@ impl LiquidOnchainWallet {
let signer = crate::signer::SdkLwkSigner::new(user_signer.clone())?; let signer = crate::signer::SdkLwkSigner::new(user_signer.clone())?;
let wollet = Self::create_wallet(&config, working_dir, &signer)?; let wollet = Self::create_wallet(&config, working_dir, &signer)?;
let working_dir_buf = PathBuf::from_str(working_dir)?;
if !working_dir_buf.exists() {
create_dir_all(&working_dir_buf)?;
}
Ok(Self { Ok(Self {
config, config,
persister, persister,

View File

@@ -1652,17 +1652,18 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
Config dco_decode_config(dynamic raw) { Config dco_decode_config(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs // Codec=Dco (DartCObject based), see doc to use other codecs
final arr = raw as List<dynamic>; final arr = raw as List<dynamic>;
if (arr.length != 9) throw Exception('unexpected arr length: expect 9 but see ${arr.length}'); if (arr.length != 10) throw Exception('unexpected arr length: expect 10 but see ${arr.length}');
return Config( return Config(
liquidElectrumUrl: dco_decode_String(arr[0]), liquidElectrumUrl: dco_decode_String(arr[0]),
bitcoinElectrumUrl: dco_decode_String(arr[1]), bitcoinElectrumUrl: dco_decode_String(arr[1]),
mempoolspaceUrl: dco_decode_String(arr[2]), mempoolspaceUrl: dco_decode_String(arr[2]),
workingDir: dco_decode_String(arr[3]), workingDir: dco_decode_String(arr[3]),
network: dco_decode_liquid_network(arr[4]), cacheDir: dco_decode_opt_String(arr[4]),
paymentTimeoutSec: dco_decode_u_64(arr[5]), network: dco_decode_liquid_network(arr[5]),
zeroConfMinFeeRateMsat: dco_decode_u_32(arr[6]), paymentTimeoutSec: dco_decode_u_64(arr[6]),
zeroConfMaxAmountSat: dco_decode_opt_box_autoadd_u_64(arr[7]), zeroConfMinFeeRateMsat: dco_decode_u_32(arr[7]),
breezApiKey: dco_decode_opt_String(arr[8]), zeroConfMaxAmountSat: dco_decode_opt_box_autoadd_u_64(arr[8]),
breezApiKey: dco_decode_opt_String(arr[9]),
); );
} }
@@ -3440,6 +3441,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
var var_bitcoinElectrumUrl = sse_decode_String(deserializer); var var_bitcoinElectrumUrl = sse_decode_String(deserializer);
var var_mempoolspaceUrl = sse_decode_String(deserializer); var var_mempoolspaceUrl = sse_decode_String(deserializer);
var var_workingDir = sse_decode_String(deserializer); var var_workingDir = sse_decode_String(deserializer);
var var_cacheDir = sse_decode_opt_String(deserializer);
var var_network = sse_decode_liquid_network(deserializer); var var_network = sse_decode_liquid_network(deserializer);
var var_paymentTimeoutSec = sse_decode_u_64(deserializer); var var_paymentTimeoutSec = sse_decode_u_64(deserializer);
var var_zeroConfMinFeeRateMsat = sse_decode_u_32(deserializer); var var_zeroConfMinFeeRateMsat = sse_decode_u_32(deserializer);
@@ -3450,6 +3452,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
bitcoinElectrumUrl: var_bitcoinElectrumUrl, bitcoinElectrumUrl: var_bitcoinElectrumUrl,
mempoolspaceUrl: var_mempoolspaceUrl, mempoolspaceUrl: var_mempoolspaceUrl,
workingDir: var_workingDir, workingDir: var_workingDir,
cacheDir: var_cacheDir,
network: var_network, network: var_network,
paymentTimeoutSec: var_paymentTimeoutSec, paymentTimeoutSec: var_paymentTimeoutSec,
zeroConfMinFeeRateMsat: var_zeroConfMinFeeRateMsat, zeroConfMinFeeRateMsat: var_zeroConfMinFeeRateMsat,
@@ -5355,6 +5358,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_String(self.bitcoinElectrumUrl, serializer); sse_encode_String(self.bitcoinElectrumUrl, serializer);
sse_encode_String(self.mempoolspaceUrl, serializer); sse_encode_String(self.mempoolspaceUrl, serializer);
sse_encode_String(self.workingDir, serializer); sse_encode_String(self.workingDir, serializer);
sse_encode_opt_String(self.cacheDir, serializer);
sse_encode_liquid_network(self.network, serializer); sse_encode_liquid_network(self.network, serializer);
sse_encode_u_64(self.paymentTimeoutSec, serializer); sse_encode_u_64(self.paymentTimeoutSec, serializer);
sse_encode_u_32(self.zeroConfMinFeeRateMsat, serializer); sse_encode_u_32(self.zeroConfMinFeeRateMsat, serializer);

View File

@@ -2026,6 +2026,7 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
wireObj.bitcoin_electrum_url = cst_encode_String(apiObj.bitcoinElectrumUrl); wireObj.bitcoin_electrum_url = cst_encode_String(apiObj.bitcoinElectrumUrl);
wireObj.mempoolspace_url = cst_encode_String(apiObj.mempoolspaceUrl); wireObj.mempoolspace_url = cst_encode_String(apiObj.mempoolspaceUrl);
wireObj.working_dir = cst_encode_String(apiObj.workingDir); wireObj.working_dir = cst_encode_String(apiObj.workingDir);
wireObj.cache_dir = cst_encode_opt_String(apiObj.cacheDir);
wireObj.network = cst_encode_liquid_network(apiObj.network); wireObj.network = cst_encode_liquid_network(apiObj.network);
wireObj.payment_timeout_sec = cst_encode_u_64(apiObj.paymentTimeoutSec); wireObj.payment_timeout_sec = cst_encode_u_64(apiObj.paymentTimeoutSec);
wireObj.zero_conf_min_fee_rate_msat = cst_encode_u_32(apiObj.zeroConfMinFeeRateMsat); wireObj.zero_conf_min_fee_rate_msat = cst_encode_u_32(apiObj.zeroConfMinFeeRateMsat);
@@ -5613,6 +5614,8 @@ final class wire_cst_config extends ffi.Struct {
external ffi.Pointer<wire_cst_list_prim_u_8_strict> working_dir; external ffi.Pointer<wire_cst_list_prim_u_8_strict> working_dir;
external ffi.Pointer<wire_cst_list_prim_u_8_strict> cache_dir;
@ffi.Int32() @ffi.Int32()
external int network; external int network;

View File

@@ -119,10 +119,13 @@ class Config {
/// The mempool.space API URL, has to be in the format: `https://mempool.space/api` /// The mempool.space API URL, has to be in the format: `https://mempool.space/api`
final String mempoolspaceUrl; final String mempoolspaceUrl;
/// Directory in which all SDK files (DB, log, cache) are stored. /// Directory in which the DB and log files are stored.
/// ///
/// Prefix can be a relative or absolute path to this directory. /// Prefix can be a relative or absolute path to this directory.
final String workingDir; final String workingDir;
/// Directory in which the Liquid wallet cache is stored. Defaults to `working_dir`
final String? cacheDir;
final LiquidNetwork network; final LiquidNetwork network;
/// Send payment timeout. See [crate::sdk::LiquidSdk::send_payment] /// Send payment timeout. See [crate::sdk::LiquidSdk::send_payment]
@@ -143,6 +146,7 @@ class Config {
required this.bitcoinElectrumUrl, required this.bitcoinElectrumUrl,
required this.mempoolspaceUrl, required this.mempoolspaceUrl,
required this.workingDir, required this.workingDir,
this.cacheDir,
required this.network, required this.network,
required this.paymentTimeoutSec, required this.paymentTimeoutSec,
required this.zeroConfMinFeeRateMsat, required this.zeroConfMinFeeRateMsat,
@@ -156,6 +160,7 @@ class Config {
bitcoinElectrumUrl.hashCode ^ bitcoinElectrumUrl.hashCode ^
mempoolspaceUrl.hashCode ^ mempoolspaceUrl.hashCode ^
workingDir.hashCode ^ workingDir.hashCode ^
cacheDir.hashCode ^
network.hashCode ^ network.hashCode ^
paymentTimeoutSec.hashCode ^ paymentTimeoutSec.hashCode ^
zeroConfMinFeeRateMsat.hashCode ^ zeroConfMinFeeRateMsat.hashCode ^
@@ -171,6 +176,7 @@ class Config {
bitcoinElectrumUrl == other.bitcoinElectrumUrl && bitcoinElectrumUrl == other.bitcoinElectrumUrl &&
mempoolspaceUrl == other.mempoolspaceUrl && mempoolspaceUrl == other.mempoolspaceUrl &&
workingDir == other.workingDir && workingDir == other.workingDir &&
cacheDir == other.cacheDir &&
network == other.network && network == other.network &&
paymentTimeoutSec == other.paymentTimeoutSec && paymentTimeoutSec == other.paymentTimeoutSec &&
zeroConfMinFeeRateMsat == other.zeroConfMinFeeRateMsat && zeroConfMinFeeRateMsat == other.zeroConfMinFeeRateMsat &&
@@ -211,7 +217,7 @@ class GetInfoResponse {
/// Incoming amount that is pending from ongoing Receive swaps /// Incoming amount that is pending from ongoing Receive swaps
final BigInt pendingReceiveSat; final BigInt pendingReceiveSat;
/// The wallet's fingerprint. It is used to build the working directory in [Config::get_wallet_working_dir]. /// The wallet's fingerprint. It is used to build the working directory in [Config::get_wallet_dir].
final String fingerprint; final String fingerprint;
/// The wallet's pubkey. Used to verify signed messages. /// The wallet's pubkey. Used to verify signed messages.

View File

@@ -4372,6 +4372,8 @@ final class wire_cst_config extends ffi.Struct {
external ffi.Pointer<wire_cst_list_prim_u_8_strict> working_dir; external ffi.Pointer<wire_cst_list_prim_u_8_strict> working_dir;
external ffi.Pointer<wire_cst_list_prim_u_8_strict> cache_dir;
@ffi.Int32() @ffi.Int32()
external int network; external int network;

View File

@@ -261,6 +261,7 @@ fun asConfig(config: ReadableMap): Config? {
val paymentTimeoutSec = config.getDouble("paymentTimeoutSec").toULong() val paymentTimeoutSec = config.getDouble("paymentTimeoutSec").toULong()
val zeroConfMinFeeRateMsat = config.getInt("zeroConfMinFeeRateMsat").toUInt() val zeroConfMinFeeRateMsat = config.getInt("zeroConfMinFeeRateMsat").toUInt()
val breezApiKey = if (hasNonNullKey(config, "breezApiKey")) config.getString("breezApiKey") else null val breezApiKey = if (hasNonNullKey(config, "breezApiKey")) config.getString("breezApiKey") else null
val cacheDir = if (hasNonNullKey(config, "cacheDir")) config.getString("cacheDir") else null
val zeroConfMaxAmountSat = val zeroConfMaxAmountSat =
if (hasNonNullKey( if (hasNonNullKey(
config, config,
@@ -280,6 +281,7 @@ fun asConfig(config: ReadableMap): Config? {
paymentTimeoutSec, paymentTimeoutSec,
zeroConfMinFeeRateMsat, zeroConfMinFeeRateMsat,
breezApiKey, breezApiKey,
cacheDir,
zeroConfMaxAmountSat, zeroConfMaxAmountSat,
) )
} }
@@ -294,6 +296,7 @@ fun readableMapOf(config: Config): ReadableMap =
"paymentTimeoutSec" to config.paymentTimeoutSec, "paymentTimeoutSec" to config.paymentTimeoutSec,
"zeroConfMinFeeRateMsat" to config.zeroConfMinFeeRateMsat, "zeroConfMinFeeRateMsat" to config.zeroConfMinFeeRateMsat,
"breezApiKey" to config.breezApiKey, "breezApiKey" to config.breezApiKey,
"cacheDir" to config.cacheDir,
"zeroConfMaxAmountSat" to config.zeroConfMaxAmountSat, "zeroConfMaxAmountSat" to config.zeroConfMaxAmountSat,
) )

View File

@@ -314,6 +314,13 @@ enum BreezSDKLiquidMapper {
} }
breezApiKey = breezApiKeyTmp breezApiKey = breezApiKeyTmp
} }
var cacheDir: String?
if hasNonNilKey(data: config, key: "cacheDir") {
guard let cacheDirTmp = config["cacheDir"] as? String else {
throw SdkError.Generic(message: errUnexpectedValue(fieldName: "cacheDir"))
}
cacheDir = cacheDirTmp
}
var zeroConfMaxAmountSat: UInt64? var zeroConfMaxAmountSat: UInt64?
if hasNonNilKey(data: config, key: "zeroConfMaxAmountSat") { if hasNonNilKey(data: config, key: "zeroConfMaxAmountSat") {
guard let zeroConfMaxAmountSatTmp = config["zeroConfMaxAmountSat"] as? UInt64 else { guard let zeroConfMaxAmountSatTmp = config["zeroConfMaxAmountSat"] as? UInt64 else {
@@ -322,7 +329,7 @@ enum BreezSDKLiquidMapper {
zeroConfMaxAmountSat = zeroConfMaxAmountSatTmp zeroConfMaxAmountSat = zeroConfMaxAmountSatTmp
} }
return Config(liquidElectrumUrl: liquidElectrumUrl, bitcoinElectrumUrl: bitcoinElectrumUrl, mempoolspaceUrl: mempoolspaceUrl, workingDir: workingDir, network: network, paymentTimeoutSec: paymentTimeoutSec, zeroConfMinFeeRateMsat: zeroConfMinFeeRateMsat, breezApiKey: breezApiKey, zeroConfMaxAmountSat: zeroConfMaxAmountSat) return Config(liquidElectrumUrl: liquidElectrumUrl, bitcoinElectrumUrl: bitcoinElectrumUrl, mempoolspaceUrl: mempoolspaceUrl, workingDir: workingDir, network: network, paymentTimeoutSec: paymentTimeoutSec, zeroConfMinFeeRateMsat: zeroConfMinFeeRateMsat, breezApiKey: breezApiKey, cacheDir: cacheDir, zeroConfMaxAmountSat: zeroConfMaxAmountSat)
} }
static func dictionaryOf(config: Config) -> [String: Any?] { static func dictionaryOf(config: Config) -> [String: Any?] {
@@ -335,6 +342,7 @@ enum BreezSDKLiquidMapper {
"paymentTimeoutSec": config.paymentTimeoutSec, "paymentTimeoutSec": config.paymentTimeoutSec,
"zeroConfMinFeeRateMsat": config.zeroConfMinFeeRateMsat, "zeroConfMinFeeRateMsat": config.zeroConfMinFeeRateMsat,
"breezApiKey": config.breezApiKey == nil ? nil : config.breezApiKey, "breezApiKey": config.breezApiKey == nil ? nil : config.breezApiKey,
"cacheDir": config.cacheDir == nil ? nil : config.cacheDir,
"zeroConfMaxAmountSat": config.zeroConfMaxAmountSat == nil ? nil : config.zeroConfMaxAmountSat, "zeroConfMaxAmountSat": config.zeroConfMaxAmountSat == nil ? nil : config.zeroConfMaxAmountSat,
] ]
} }

View File

@@ -66,6 +66,7 @@ export interface Config {
paymentTimeoutSec: number paymentTimeoutSec: number
zeroConfMinFeeRateMsat: number zeroConfMinFeeRateMsat: number
breezApiKey?: string breezApiKey?: string
cacheDir?: string
zeroConfMaxAmountSat?: number zeroConfMaxAmountSat?: number
} }