Skip to content

Commit 8f7b08c

Browse files
committed
final fixups
1 parent cf2c657 commit 8f7b08c

5 files changed

Lines changed: 33 additions & 19 deletions

File tree

orange-sdk/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ graduated-rebalancer = { path = "../graduated-rebalancer", version = "0.1.0" }
2525

2626
ldk-node = { version = "0.7.0" }
2727
lightning-macros = "0.2.0"
28-
bitcoin-payment-instructions = { workspace = true }
28+
bitcoin-payment-instructions = { workspace = true, features = ["http"] }
2929
chrono = { version = "0.4", default-features = false }
3030
rand = { version = "0.8.5", optional = true }
3131
breez-sdk-spark = { git = "https://github.com/breez/spark-sdk.git", rev = "1f2e9995230cd582d6b4aa7d06d76b99defb635e", default-features = false, features = ["rustls-tls"], optional = true }
@@ -36,8 +36,8 @@ serde_json = { version = "1.0", optional = true }
3636
async-trait = "0.1"
3737
log = "0.4.28"
3838

39-
corepc-node = { version = "0.10.1", features = ["27_2", "download"], optional = true }
40-
electrsd = { version = "0.36.1", default-features = false, features = ["esplora_a33e97e1", "corepc-node_27_2"], optional = true }
39+
corepc-node = { version = "0.10.1", features = ["29_0", "download"], optional = true }
40+
electrsd = { version = "0.36.1", default-features = false, features = ["esplora_a33e97e1", "corepc-node_29_0"], optional = true }
4141
cdk-ldk-node = { version = "0.14.2", optional = true }
4242
cdk-sqlite = { version = "0.14.2", optional = true }
4343
cdk-axum = { version = "0.14.2", optional = true }

orange-sdk/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,13 +1277,13 @@ impl Wallet {
12771277
Ok(())
12781278
}
12791279

1280-
/// Authenticates the user via [LNURL-auth] for the given LNURL string.
1281-
///
1282-
/// [LNURL-auth]: https://github.com/lnurl/luds/blob/luds/04.md
1283-
pub fn lnurl_auth(&self, _lnurl: &str) -> Result<(), WalletError> {
1284-
// todo wait for merge, self.inner.ln_wallet.inner.ldk_node.lnurl_auth(lnurl)?;
1285-
Ok(())
1286-
}
1280+
// Authenticates the user via [LNURL-auth] for the given LNURL string.
1281+
//
1282+
// [LNURL-auth]: https://github.com/lnurl/luds/blob/luds/04.md
1283+
// pub fn lnurl_auth(&self, _lnurl: &str) -> Result<(), WalletError> {
1284+
// // todo wait for merge, self.inner.ln_wallet.inner.ldk_node.lnurl_auth(lnurl)?;
1285+
// Ok(())
1286+
// }
12871287

12881288
/// Returns the wallet's configured tunables.
12891289
pub fn get_tunables(&self) -> Tunables {

orange-sdk/src/lightning_wallet.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,15 +393,12 @@ impl LightningWallet {
393393
let channels = self.inner.ldk_node.list_channels();
394394
let channel = channels.iter().find(|c| c.counterparty_node_id == self.inner.lsp_node_id);
395395

396-
// todo fix this, for now leave some onchain balance for fees
397-
let amt = amount.saturating_sub(Amount::from_sats(10_000).unwrap());
398-
399396
match channel {
400397
Some(chan) => {
401398
self.inner.ldk_node.splice_in(
402399
&chan.user_channel_id,
403400
chan.counterparty_node_id,
404-
amt.sats_rounding_up(),
401+
amount.sats_rounding_up(),
405402
)?;
406403
Ok(chan.user_channel_id)
407404
},
@@ -561,6 +558,18 @@ impl graduated_rebalancer::LightningWallet for LightningWallet {
561558
fn splice_to_lsp_channel(
562559
&self, amt: Amount,
563560
) -> Pin<Box<dyn Future<Output = Result<u128, Self::Error>> + Send + '_>> {
561+
let bal = self.inner.ldk_node.list_balances();
562+
// if we don't have enough onchain balance, return error
563+
// if we are within 1,000 sats of the amount, reduce the amount to account for fees
564+
if bal.spendable_onchain_balance_sats < amt.sats_rounding_up() {
565+
return Box::pin(async move { Err(NodeError::InsufficientFunds) });
566+
} else if bal.spendable_onchain_balance_sats < amt.sats_rounding_up() + 1_000 {
567+
let reduced_amt = amt.saturating_sub(Amount::from_sats(1_000).expect("valid amount"));
568+
return Box::pin(async move {
569+
self.splice_balance_into_channel(reduced_amt).await.map(|c| c.0)
570+
});
571+
}
572+
564573
Box::pin(async move { self.splice_balance_into_channel(amt).await.map(|c| c.0) })
565574
}
566575

orange-sdk/src/trusted_wallet/spark/spark_store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
use std::sync::Arc;
44

55
use crate::io;
6-
use ldk_node::DynStore;
7-
use ldk_node::lightning::util::persist::KVStore;
86

97
use breez_sdk_spark::{
108
DepositInfo, ListPaymentsRequest, Payment, PaymentDetails, PaymentMetadata, StorageError,
119
UpdateDepositPayload,
1210
};
11+
use ldk_node::DynStore;
1312
use ldk_node::lightning::util::persist::KVSTORE_NAMESPACE_KEY_MAX_LEN;
13+
use ldk_node::lightning::util::persist::KVStore;
1414

1515
const SPARK_PRIMARY_NAMESPACE: &str = "spark";
1616
const SPARK_CACHE_NAMESPACE: &str = "cache";

orange-sdk/tests/test_utils.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ fn create_third_party(uuid: Uuid, bitcoind: &Bitcoind) -> Arc<Node> {
235235

236236
async fn fund_node(node: &Node, bitcoind: &Bitcoind, electrsd: &ElectrsD) {
237237
let addr = node.onchain_payment().new_address().unwrap();
238-
bitcoind.client.send_to_address(&addr, bitcoin::Amount::from_btc(1.0).unwrap()).unwrap();
238+
let res = bitcoind.client.send_to_address(&addr, bitcoin::Amount::from_btc(1.0).unwrap()).unwrap();
239+
wait_for_tx(&electrsd.client, res.txid().unwrap()).await;
239240
generate_blocks(bitcoind, electrsd, 6).await;
240241
}
241242

@@ -333,7 +334,7 @@ async fn build_test_nodes() -> TestParams {
333334

334335
// take esplora url and just get the port, as we know it's running on localhost
335336
let base_url = electrsd.esplora_url.as_ref().unwrap();
336-
let port = base_url.split(':').last().unwrap();
337+
let port = base_url.split(':').next_back().unwrap();
337338
let esplora_url = format!("http://localhost:{port}");
338339

339340
let wallet_config = WalletConfig {
@@ -468,7 +469,11 @@ async fn build_test_nodes() -> TestParams {
468469
mint
469470
};
470471

471-
let esplora_url = format!("http://{}", electrsd.esplora_url.as_ref().unwrap());
472+
// take esplora url and just get the port, as we know it's running on localhost
473+
let base_url = electrsd.esplora_url.as_ref().unwrap();
474+
let port = base_url.split(':').next_back().unwrap();
475+
let esplora_url = format!("http://localhost:{port}");
476+
472477
let tmp = temp_dir().join(format!("orange-test-{test_id}/wallet"));
473478
let wallet_config = WalletConfig {
474479
storage_config: StorageConfig::LocalSQLite(tmp.to_str().unwrap().to_string()),

0 commit comments

Comments
 (0)