Add examples for adding extra TLVs to a spontaneous payment

This commit is contained in:
Ross Savage
2024-01-29 17:11:25 +01:00
parent 60552e8b35
commit 37a46fa4d6
23 changed files with 290 additions and 55 deletions

View File

@@ -86,6 +86,7 @@ checksum = "c258c1a017ecaccfb34c8fa46ecbb2f5402584e31082c12b5caf0be82ac5ac44"
dependencies = [
"anyhow",
"atomic",
"backtrace",
"chrono",
]
@@ -449,7 +450,8 @@ dependencies = [
[[package]]
name = "bolt-derive"
version = "0.2.0"
source = "git+https://gitlab.com/cdecker/vls?tag=snapshot-20230920#b8d42d68bb3a525a8b7340b132220a0de922d62f"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b4a20c5d2dd939142aa8edcfcaa5126bf0e4483d8edce6502037c2b0adbe069"
dependencies = [
"proc-macro2",
"quote",
@@ -458,8 +460,8 @@ dependencies = [
[[package]]
name = "breez-sdk-core"
version = "0.2.10"
source = "git+https://github.com/breez/breez-sdk?tag=0.2.10#d18529988eb7b1038473161e44c88225c7a0236d"
version = "0.2.15"
source = "git+https://github.com/breez/breez-sdk?tag=0.2.15#5486f167e046d28b0a3f9885b4bf9c44cd3e1ba8"
dependencies = [
"aes",
"anyhow",
@@ -476,8 +478,8 @@ dependencies = [
"gl-client",
"hex",
"lazy_static",
"lightning 0.0.115",
"lightning-invoice 0.23.0",
"lightning 0.0.118",
"lightning-invoice 0.26.0",
"log",
"miniz_oxide",
"once_cell",
@@ -606,7 +608,8 @@ dependencies = [
[[package]]
name = "cln-grpc"
version = "0.1.7"
source = "git+https://github.com/cdecker/lightning.git?tag=gl-20231113#075927b2c5f38fdbde4c0764135be58340b0ce08"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e745ebc04340d421c7bc8305942a60d3dd8531d94df24f1b8c3906942735f0d"
dependencies = [
"anyhow",
"bitcoin 0.30.1",
@@ -935,12 +938,13 @@ dependencies = [
[[package]]
name = "flutter_rust_bridge"
version = "1.80.1"
version = "1.82.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd0305ebc9f097d9826530a55fc2acd63222e912c663f7adce3ab641ecc0f346"
checksum = "23a5a7a1cd030cd63f53eafe2496eb4e40f520800e6e9b78cae6f3f3ba7f3c2b"
dependencies = [
"allo-isolate",
"anyhow",
"backtrace",
"build-target",
"bytemuck",
"cc",
@@ -1131,7 +1135,7 @@ checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
[[package]]
name = "gl-client"
version = "0.1.9"
source = "git+https://github.com/Blockstream/greenlight.git?rev=84a66ac3c467569365285814ef5a691b5b97f60d#84a66ac3c467569365285814ef5a691b5b97f60d"
source = "git+https://github.com/Blockstream/greenlight.git?rev=556eedf47a837b71c4277ba6ee84322f5cbd80de#556eedf47a837b71c4277ba6ee84322f5cbd80de"
dependencies = [
"anyhow",
"async-trait",
@@ -1145,7 +1149,7 @@ dependencies = [
"hex",
"http",
"http-body",
"lightning-invoice 0.24.0",
"lightning-invoice 0.26.0",
"log",
"mockall",
"pin-project",
@@ -1585,9 +1589,9 @@ dependencies = [
[[package]]
name = "lightning"
version = "0.0.116"
version = "0.0.118"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90a0f2155316f1570446a0447c993480673f840748c8ed25bbc59dfc442ac770"
checksum = "d52cec5fa9382154fe9671e8df93095b800c7d77abc66e2a5ef839d672521c5e"
dependencies = [
"bitcoin 0.29.2",
]
@@ -1608,14 +1612,14 @@ dependencies = [
[[package]]
name = "lightning-invoice"
version = "0.24.0"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1788c0158526ec27a502043c2911ea6ea58fdc656bdf8749484942c07b790d23"
checksum = "3eb24878b0f4ef75f020976c886d9ad1503867802329cc963e0ab4623ea3b25c"
dependencies = [
"bech32",
"bitcoin 0.29.2",
"bitcoin_hashes 0.11.0",
"lightning 0.0.116",
"lightning 0.0.118",
"num-traits",
"secp256k1 0.24.3",
]
@@ -3212,8 +3216,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "vls-core"
version = "0.10.0"
source = "git+https://gitlab.com/cdecker/vls?tag=snapshot-20230920#b8d42d68bb3a525a8b7340b132220a0de922d62f"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7465dd7f8cc004b67c52c6610ebf157695a93daf33f6a69c1b06b0f4e1fecbc0"
dependencies = [
"anyhow",
"backtrace",
@@ -3239,7 +3244,8 @@ dependencies = [
[[package]]
name = "vls-persist"
version = "0.10.0"
source = "git+https://gitlab.com/cdecker/vls?tag=snapshot-20230920#b8d42d68bb3a525a8b7340b132220a0de922d62f"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86279e60e9dcdd3bcc135b7979655f1c80c6b99c38fee25d390725bfc5a24994"
dependencies = [
"hex",
"log",
@@ -3252,7 +3258,8 @@ dependencies = [
[[package]]
name = "vls-protocol"
version = "0.10.0"
source = "git+https://gitlab.com/cdecker/vls?tag=snapshot-20230920#b8d42d68bb3a525a8b7340b132220a0de922d62f"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55e525ef3cb95a27b240662fb518ea283d25b1f51afe899f0f253747acc284f4"
dependencies = [
"as-any",
"bitcoin-consensus-derive",
@@ -3265,7 +3272,8 @@ dependencies = [
[[package]]
name = "vls-protocol-signer"
version = "0.10.0"
source = "git+https://gitlab.com/cdecker/vls?tag=snapshot-20230920#b8d42d68bb3a525a8b7340b132220a0de922d62f"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a766ac452520406eed1e7d8ad1c744156fc3ceaf6bdcefe3f3a44bd5f5ea0b29"
dependencies = [
"bit-vec",
"log",

View File

@@ -6,6 +6,6 @@ edition = "2021"
[dependencies]
anyhow = "1"
bip39 = { version = "2", features = ["rand"] }
breez-sdk-core = { git = "https://github.com/breez/breez-sdk", tag = "0.2.10" }
breez-sdk-core = { git = "https://github.com/breez/breez-sdk", tag = "0.2.15" }
log = "0.4"
tokio = "1.29"

View File

@@ -1,14 +1,13 @@
use anyhow::Result;
use breez_sdk_core::*;
fn production_node_config() -> Result<NodeConfig> {
// ANCHOR: moving-to-production
// Read your Greenlight credentials from secure storage
let device_key: Vec<u8> = vec![];
let device_cert: Vec<u8> = vec![];
let greenlight_credentials = GreenlightCredentials {
device_key,
device_key,
device_cert,
};

View File

@@ -12,8 +12,14 @@ async fn generate_receive_onchain_address(sdk: Arc<BreezServices>) -> Result<()>
// Send your funds to the below bitcoin address
let address = swap_info.bitcoin_address;
info!("Minimum amount allowed to deposit in sats: {}", swap_info.min_allowed_deposit);
info!("Maximum amount allowed to deposit in sats: {}", swap_info.max_allowed_deposit);
info!(
"Minimum amount allowed to deposit in sats: {}",
swap_info.min_allowed_deposit
);
info!(
"Maximum amount allowed to deposit in sats: {}",
swap_info.max_allowed_deposit
);
// ANCHOR_END: generate-receive-onchain-address
Ok(())

View File

@@ -32,14 +32,9 @@ async fn list_current_fees(current_fees: ReverseSwapPairInfo) -> Result<()> {
async fn max_reverse_swap_amount(sdk: Arc<BreezServices>) -> Result<()> {
// ANCHOR: max-reverse-swap-amount
let max_amount = sdk
.max_reverse_swap_amount()
.await?;
let max_amount = sdk.max_reverse_swap_amount().await?;
info!(
"Max reverse swap amount: {:?}",
max_amount.total_sat
);
info!("Max reverse swap amount: {:?}", max_amount.total_sat);
// ANCHOR_END: max-reverse-swap-amount
Ok(())

View File

@@ -10,9 +10,29 @@ async fn send_spontaneous_payment(sdk: Arc<BreezServices>) -> Result<()> {
sdk.send_spontaneous_payment(SendSpontaneousPaymentRequest {
amount_msat: 3_000_000,
node_id,
extra_tlvs: None,
})
.await?;
// ANCHOR_END: send-spontaneous-payment
Ok(())
}
async fn send_spontaneous_payment_with_tlvs(sdk: Arc<BreezServices>) -> Result<()> {
// ANCHOR: send-spontaneous-payment-with-tlvs
let node_id = "...".into();
let extra_tlvs = vec![TlvEntry {
field_number: 34349334,
value: "Hello world!".as_bytes().to_vec(),
}];
sdk.send_spontaneous_payment(SendSpontaneousPaymentRequest {
amount_msat: 3_000_000,
node_id,
extra_tlvs: Some(extra_tlvs),
})
.await?;
// ANCHOR_END: send-spontaneous-payment-with-tlvs
Ok(())
}

View File

@@ -1,19 +1,23 @@
use std::sync::Arc;
use anyhow::Result;
use breez_sdk_core::*;
use std::sync::Arc;
async fn webhook(sdk: Arc<BreezServices>) -> Result<()> {
// ANCHOR: register-webook
sdk.register_webhook("https://yourapplication.com".to_string()).await?;
sdk.register_webhook("https://yourapplication.com".to_string())
.await?;
// ANCHOR_END: register-webook
Ok(())
}
async fn payment_webhook(sdk: Arc<BreezServices>) -> Result<()> {
// ANCHOR: register-payment-webook
sdk.register_webhook("https://your-nds-service.com/notify?platform=ios&token=<PUSH_TOKEN>".to_string()).await?;
// ANCHOR_END: register-payment-webook
// ANCHOR: register-payment-webook
sdk.register_webhook(
"https://your-nds-service.com/notify?platform=ios&token=<PUSH_TOKEN>".to_string(),
)
.await?;
// ANCHOR_END: register-payment-webook
Ok(())
Ok(())
}