From 37a46fa4d623c95705743b69b09b2d7647ebc8bd Mon Sep 17 00:00:00 2001 From: Ross Savage Date: Mon, 29 Jan 2024 17:11:25 +0100 Subject: [PATCH] Add examples for adding extra TLVs to a spontaneous payment --- .github/workflows/main.yml | 4 +- snippets/csharp/SendSpontaneousPayment.cs | 23 ++++++ .../lib/send_spontaneous_payment.dart | 21 ++++++ snippets/go/go.mod | 2 +- snippets/go/send_spontaneous_payment.go | 20 ++++++ .../kotlin_mpp_lib/shared/build.gradle.kts | 2 +- .../kotlinmpplib/SendSpontaneousPayment.kt | 16 +++++ snippets/python/main.py | 3 +- .../python/src/send_spontaneous_payment.py | 17 ++++- .../react-native/send_spontaneous_payment.ts | 28 +++++++- snippets/react-native/yarn.lock | 8 +-- snippets/rust/Cargo.lock | 48 +++++++------ snippets/rust/Cargo.toml | 2 +- snippets/rust/src/production.rs | 3 +- snippets/rust/src/receive_onchain.rs | 10 ++- snippets/rust/src/send_onchain.rs | 9 +-- snippets/rust/src/send_spontaneous_payment.rs | 20 ++++++ snippets/rust/src/webhook.rs | 16 +++-- .../swift/BreezSDKExamples/Package.resolved | 4 +- snippets/swift/BreezSDKExamples/Package.swift | 2 +- .../Sources/SendSpontaneous.swift | 13 +++- src/guide/install.md | 2 +- src/guide/send_spontaneous_payment.md | 70 +++++++++++++++++++ 23 files changed, 289 insertions(+), 54 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3a54d0b4..4487c800 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,8 +25,8 @@ jobs: name: setup runs-on: ubuntu-latest outputs: - sdk-ref: ${{ inputs.sdk-ref || '0.2.10' }} - package-version: '0.2.10' + sdk-ref: ${{ inputs.sdk-ref || '0.2.15' }} + package-version: '0.2.15' steps: - run: echo "set pre-setup output variables" diff --git a/snippets/csharp/SendSpontaneousPayment.cs b/snippets/csharp/SendSpontaneousPayment.cs index 6bc32b20..d5982aa0 100644 --- a/snippets/csharp/SendSpontaneousPayment.cs +++ b/snippets/csharp/SendSpontaneousPayment.cs @@ -1,4 +1,6 @@ using Breez.Sdk; +using System; +using System.Text; public class SendSpontaneousPaymentSnippets { @@ -17,5 +19,26 @@ public void SendSpontaneousPayment(BlockingBreezServices sdk) // Handle error } // ANCHOR_END: send-spontaneous-payment + } + + public void SendSpontaneousPaymentWithTlvs(BlockingBreezServices sdk) + { + // ANCHOR: send-spontaneous-payment-with-tlvs + var nodeId = "..."; + ulong amountMsat = 3_000_000; + var extraTlvs = new List{ + new TlvEntry(34349334, Encoding.ASCII.GetBytes("Hello world!").ToList()) + }; + + try + { + var response = sdk.SendSpontaneousPayment( + new SendSpontaneousPaymentRequest(nodeId, amountMsat, extraTlvs)); + } + catch (Exception) + { + // Handle error + } + // ANCHOR_END: send-spontaneous-payment-with-tlvs } } diff --git a/snippets/dart_snippets/lib/send_spontaneous_payment.dart b/snippets/dart_snippets/lib/send_spontaneous_payment.dart index 8cdbb7be..06711c86 100644 --- a/snippets/dart_snippets/lib/send_spontaneous_payment.dart +++ b/snippets/dart_snippets/lib/send_spontaneous_payment.dart @@ -1,5 +1,6 @@ import 'package:breez_sdk/breez_sdk.dart'; import 'package:breez_sdk/bridge_generated.dart'; +import 'dart:convert'; Future sendSpontaneousPayment({ required String nodeId, @@ -13,3 +14,23 @@ Future sendSpontaneousPayment({ // ANCHOR_END: send-spontaneous-payment return resp; } + +Future sendSpontaneousPaymentWithTlvs({ + required String nodeId, +}) async { + // ANCHOR: send-spontaneous-payment-with-tlvs + List extraTlvs = [ + TlvEntry( + fieldNumber: 34349334, + value: utf8.encode("Hello world!"), + ) + ]; + SendSpontaneousPaymentRequest req = SendSpontaneousPaymentRequest( + amountMsat: 3000000, + nodeId: nodeId, + extraTlvs: extraTlvs, + ); + SendPaymentResponse resp = await BreezSDK().sendSpontaneousPayment(req: req); + // ANCHOR_END: send-spontaneous-payment-with-tlvs + return resp; +} diff --git a/snippets/go/go.mod b/snippets/go/go.mod index dfe8a584..72cea3c4 100644 --- a/snippets/go/go.mod +++ b/snippets/go/go.mod @@ -2,6 +2,6 @@ module main go 1.19 -require github.com/breez/breez-sdk-go v0.2.10 +require github.com/breez/breez-sdk-go v0.2.15 replace github.com/breez/breez-sdk-go => ./packages/breez-sdk-go diff --git a/snippets/go/send_spontaneous_payment.go b/snippets/go/send_spontaneous_payment.go index a4930b57..a2d1773a 100644 --- a/snippets/go/send_spontaneous_payment.go +++ b/snippets/go/send_spontaneous_payment.go @@ -1,6 +1,7 @@ package example import ( + "encoding/hex" "log" "github.com/breez/breez-sdk-go/breez_sdk" @@ -17,3 +18,22 @@ func SendSpontaneousPayment() { } // ANCHOR_END: send-spontaneous-payment } +func SendSpontaneousPaymentWithTlvs() { + // ANCHOR: send-spontaneous-payment-with-tlvs + value, _ := hex.DecodeString("Hello world!") + extraTlvs := []breez_sdk.TlvEntry{ + breez_sdk.TlvEntry{ + FieldNumber: uint64(34349334), + Value: value, + }, + } + sendSpontaneousPaymentRequest := breez_sdk.SendSpontaneousPaymentRequest{ + NodeId: "...", + AmountMsat: uint64(3_000_000), + ExtraTlvs: &extraTlvs, + } + if response, err := sdk.SendSpontaneousPayment(sendSpontaneousPaymentRequest); err == nil { + log.Printf("%#v", response) + } + // ANCHOR_END: send-spontaneous-payment-with-tlvs +} diff --git a/snippets/kotlin_mpp_lib/shared/build.gradle.kts b/snippets/kotlin_mpp_lib/shared/build.gradle.kts index a5a045af..180d0431 100644 --- a/snippets/kotlin_mpp_lib/shared/build.gradle.kts +++ b/snippets/kotlin_mpp_lib/shared/build.gradle.kts @@ -34,7 +34,7 @@ kotlin { } val commonMain by getting { dependencies { - implementation("technology.breez:breez-sdk-kmp:0.2.10") + implementation("technology.breez:breez-sdk-kmp:0.2.15") } } } diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendSpontaneousPayment.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendSpontaneousPayment.kt index 1d0948f8..67c5b539 100644 --- a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendSpontaneousPayment.kt +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendSpontaneousPayment.kt @@ -14,4 +14,20 @@ class SendSpontaneousPayment { } // ANCHOR_END: send-spontaneous-payment } + + fun send_spontaneous_payment_with_tlvs(sdk: BlockingBreezServices) { + // ANCHOR: send-spontaneous-payment-with-tlvs + val nodeId = "..." + val amountMsat = 3_000_000.toULong() + val extraTlvs = listOf( + TlvEntry(34_349_334.toULong(), "Hello world!".encodeToByteArray().asUByteArray().toList()) + ) + try { + val response = sdk.sendSpontaneousPayment( + SendSpontaneousPaymentRequest(nodeId, amountMsat, extraTlvs)) + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: send-spontaneous-payment-with-tlvs + } } \ No newline at end of file diff --git a/snippets/python/main.py b/snippets/python/main.py index c0343bd8..50036a7a 100755 --- a/snippets/python/main.py +++ b/snippets/python/main.py @@ -7,7 +7,7 @@ from src.buy_btc import buy from src.send_onchain import get_current_fees, list_current_fees, check_reverse_swap_status, start_reverse_swap from src.static_channel_backup import retrieve_backup_files -from src.send_spontaneous_payment import send_spontaneous_payment +from src.send_spontaneous_payment import send_spontaneous_payment, send_spontaneous_payment_with_tlvs from src.receive_payment import receive_payment from src.receive_onchain import generate_receive_onchain_address, get_in_progress_swap, list_refundables, execute_refund, get_channel_opening_fees from src.fiat_currencies import list_supported_fiat_currencies, get_current_rates @@ -73,6 +73,7 @@ def main(): #send spontaneous payment send_spontaneous_payment(sdk_services) + send_spontaneous_payment_with_tlvs(sdk_services) # fiat currencies list_supported_fiat_currencies(sdk_services) diff --git a/snippets/python/src/send_spontaneous_payment.py b/snippets/python/src/send_spontaneous_payment.py index 5ffefe75..4e5d68bd 100644 --- a/snippets/python/src/send_spontaneous_payment.py +++ b/snippets/python/src/send_spontaneous_payment.py @@ -7,10 +7,25 @@ def send_spontaneous_payment(sdk_services): node_id = "..." amount_msat = 300000 try: - req = breez_sdk.SendSpontaneousPaymentRequest(node_id,amount_msat) + req = breez_sdk.SendSpontaneousPaymentRequest(node_id, amount_msat) result = sdk_services.send_spontaneous_payment(req) # ANCHOR: send-spontaneous-payment return result + except Exception as error: + print(error) + raise + + +def send_spontaneous_payment_with_tlvs(sdk_services): + # ANCHOR: send-spontaneous-payment-with-tlvs + node_id = "..." + amount_msat = 300000 + extra_tlvs = [breez_sdk.TlvEntry(34349334, str.encode("Hello world!"))] + try: + req = breez_sdk.SendSpontaneousPaymentRequest(node_id, amount_msat, extra_tlvs) + result = sdk_services.send_spontaneous_payment(req) + # ANCHOR: send-spontaneous-payment-with-tlvs + return result except Exception as error: print(error) raise \ No newline at end of file diff --git a/snippets/react-native/send_spontaneous_payment.ts b/snippets/react-native/send_spontaneous_payment.ts index bdfcbc24..2a784a3e 100644 --- a/snippets/react-native/send_spontaneous_payment.ts +++ b/snippets/react-native/send_spontaneous_payment.ts @@ -1,4 +1,7 @@ -import { sendSpontaneousPayment } from '@breeztech/react-native-breez-sdk' +import { + sendSpontaneousPayment, + type TlvEntry +} from '@breeztech/react-native-breez-sdk' const exampleSendSpontaneousPayment = async () => { // ANCHOR: send-spontaneous-payment @@ -10,3 +13,26 @@ const exampleSendSpontaneousPayment = async () => { }) // ANCHOR_END: send-spontaneous-payment } + +const stringToBytes = (str: string): number[] => { + const bytes: number[] = [] + for (let i = 0; i < str.length; ++i) { + bytes.push(str.charCodeAt(i)) + } + return bytes +} + +const exampleSendSpontaneousPaymentWithTlvs = async () => { + // ANCHOR: send-spontaneous-payment-with-tlvs + const nodeId = '...' + const extraTlvs: TlvEntry[] = [ + { fieldNumber: 34349334, value: stringToBytes('Hello world!') } + ] + + const sendPaymentResponse = await sendSpontaneousPayment({ + nodeId, + amountMsat: 3000000, + extraTlvs + }) + // ANCHOR_END: send-spontaneous-payment-with-tlvs +} diff --git a/snippets/react-native/yarn.lock b/snippets/react-native/yarn.lock index 844c0908..d50c6934 100644 --- a/snippets/react-native/yarn.lock +++ b/snippets/react-native/yarn.lock @@ -714,10 +714,10 @@ "@babel/helper-validator-identifier" "^7.22.20" to-fast-properties "^2.0.0" -"@breeztech/react-native-breez-sdk@0.2.10": - version "0.2.10" - resolved "https://registry.yarnpkg.com/@breeztech/react-native-breez-sdk/-/react-native-breez-sdk-0.2.10.tgz#072b00f57028b5276c600a462cbcaac93d3dee22" - integrity sha512-81wtbkKGxhDaIweIQkD+LLDUL7WTtbI3qEb9vx4Itiu1hGzM8Q2RlYNF5R1jh2m4wdYKUKMWSBd3O4VRnywf1Q== +"@breeztech/react-native-breez-sdk@0.2.15": + version "0.2.15" + resolved "https://registry.yarnpkg.com/@breeztech/react-native-breez-sdk/-/react-native-breez-sdk-0.2.15.tgz#0a415747e94b08f0dbbca8aae23f2d4231881db3" + integrity sha512-VxT4wdZCyDrhZBe6heHJKUJc1nbVJ4Y0qbOm1B+LJa6JOq0YDooUFnbtHMq1PHQ3xviwuM1pCzAco0orWqnvDA== "@esbuild/android-arm64@0.18.20": version "0.18.20" diff --git a/snippets/rust/Cargo.lock b/snippets/rust/Cargo.lock index e8d7560c..a2fa7a72 100644 --- a/snippets/rust/Cargo.lock +++ b/snippets/rust/Cargo.lock @@ -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", diff --git a/snippets/rust/Cargo.toml b/snippets/rust/Cargo.toml index ff6a3f1e..839b036d 100644 --- a/snippets/rust/Cargo.toml +++ b/snippets/rust/Cargo.toml @@ -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" \ No newline at end of file diff --git a/snippets/rust/src/production.rs b/snippets/rust/src/production.rs index bc38dead..85ae4a04 100644 --- a/snippets/rust/src/production.rs +++ b/snippets/rust/src/production.rs @@ -1,14 +1,13 @@ use anyhow::Result; use breez_sdk_core::*; - fn production_node_config() -> Result { // ANCHOR: moving-to-production // Read your Greenlight credentials from secure storage let device_key: Vec = vec![]; let device_cert: Vec = vec![]; let greenlight_credentials = GreenlightCredentials { - device_key, + device_key, device_cert, }; diff --git a/snippets/rust/src/receive_onchain.rs b/snippets/rust/src/receive_onchain.rs index 452c3216..b2157743 100644 --- a/snippets/rust/src/receive_onchain.rs +++ b/snippets/rust/src/receive_onchain.rs @@ -12,8 +12,14 @@ async fn generate_receive_onchain_address(sdk: Arc) -> 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(()) diff --git a/snippets/rust/src/send_onchain.rs b/snippets/rust/src/send_onchain.rs index 4b7e1f80..1380501f 100644 --- a/snippets/rust/src/send_onchain.rs +++ b/snippets/rust/src/send_onchain.rs @@ -32,14 +32,9 @@ async fn list_current_fees(current_fees: ReverseSwapPairInfo) -> Result<()> { async fn max_reverse_swap_amount(sdk: Arc) -> 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(()) diff --git a/snippets/rust/src/send_spontaneous_payment.rs b/snippets/rust/src/send_spontaneous_payment.rs index 001bd449..89af0f11 100644 --- a/snippets/rust/src/send_spontaneous_payment.rs +++ b/snippets/rust/src/send_spontaneous_payment.rs @@ -10,9 +10,29 @@ async fn send_spontaneous_payment(sdk: Arc) -> 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) -> 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(()) +} diff --git a/snippets/rust/src/webhook.rs b/snippets/rust/src/webhook.rs index a055e588..3fcc0ec3 100644 --- a/snippets/rust/src/webhook.rs +++ b/snippets/rust/src/webhook.rs @@ -1,19 +1,23 @@ -use std::sync::Arc; use anyhow::Result; use breez_sdk_core::*; +use std::sync::Arc; async fn webhook(sdk: Arc) -> 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) -> Result<()> { - // ANCHOR: register-payment-webook - sdk.register_webhook("https://your-nds-service.com/notify?platform=ios&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=".to_string(), + ) + .await?; + // ANCHOR_END: register-payment-webook - Ok(()) + Ok(()) } diff --git a/snippets/swift/BreezSDKExamples/Package.resolved b/snippets/swift/BreezSDKExamples/Package.resolved index 2079673f..2efd42e5 100644 --- a/snippets/swift/BreezSDKExamples/Package.resolved +++ b/snippets/swift/BreezSDKExamples/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/breez/breez-sdk-swift", "state" : { - "revision" : "74402afba8218ff84a0f32d1bc0d4ddc7698f576", - "version" : "0.2.10" + "revision" : "73c7bf88ce51471f4a6313aa583fa1a5394442f7", + "version" : "0.2.15" } }, { diff --git a/snippets/swift/BreezSDKExamples/Package.swift b/snippets/swift/BreezSDKExamples/Package.swift index 86f6df79..6a774d45 100644 --- a/snippets/swift/BreezSDKExamples/Package.swift +++ b/snippets/swift/BreezSDKExamples/Package.swift @@ -8,7 +8,7 @@ let package = Package( platforms: [.macOS(.v12)], dependencies: [ .package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.3"), - .package(url: "https://github.com/breez/breez-sdk-swift", from:"0.2.10") + .package(url: "https://github.com/breez/breez-sdk-swift", from:"0.2.15") ], targets: [ // Targets are the basic building blocks of a package, defining a module or a test suite. diff --git a/snippets/swift/BreezSDKExamples/Sources/SendSpontaneous.swift b/snippets/swift/BreezSDKExamples/Sources/SendSpontaneous.swift index a5302eb3..173a7f50 100644 --- a/snippets/swift/BreezSDKExamples/Sources/SendSpontaneous.swift +++ b/snippets/swift/BreezSDKExamples/Sources/SendSpontaneous.swift @@ -16,6 +16,17 @@ func sendSpontaneousPayment(sdk: BlockingBreezServices) -> SendPaymentResponse? nodeId: "...", amountMsat: 3_000_000)) // ANCHOR_END: send-spontaneous-payment + return response +} + +func sendSpontaneousPaymentWithTlvs(sdk: BlockingBreezServices) -> SendPaymentResponse? { + // ANCHOR: send-spontaneous-payment-with-tlvs + let extraTlvs = [TlvEntry(fieldNumber: 34_349_334, value: Array("Hello world!".utf8))] + let response = try? sdk.sendSpontaneousPayment( + req: SendSpontaneousPaymentRequest( + nodeId: "...", + amountMsat: 3_000_000, + extraTlvs: extraTlvs)) + // ANCHOR_END: send-spontaneous-payment-with-tlvs return response - } diff --git a/src/guide/install.md b/src/guide/install.md index a491490b..023769e7 100644 --- a/src/guide/install.md +++ b/src/guide/install.md @@ -93,7 +93,7 @@ Check https://github.com/breez/breez-sdk/releases for the latest version. ```toml [dependencies] -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" } ``` ## Flutter/Dart diff --git a/src/guide/send_spontaneous_payment.md b/src/guide/send_spontaneous_payment.md index 778f0ba0..9f1e9cc1 100644 --- a/src/guide/send_spontaneous_payment.md +++ b/src/guide/send_spontaneous_payment.md @@ -67,3 +67,73 @@ They can even be spontaneous payments to a node without a bolt11 invoice. ``` + +## Adding Extra TLVs to a Spontaneous Payment + +A list of extra TLV data can also be sent with the sponaneous payment. + + +
Rust
+
+ +```rust,ignore +{{#include ../../snippets/rust/src/send_spontaneous_payment.rs:send-spontaneous-payment-with-tlvs}} +``` +
+ +
Swift
+
+ +```swift,ignore +{{#include ../../snippets/swift/BreezSDKExamples/Sources/SendSpontaneous.swift:send-spontaneous-payment-with-tlvs}} +``` +
+ +
Kotlin
+
+ +```kotlin,ignore +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendSpontaneousPayment.kt:send-spontaneous-payment-with-tlvs}} +``` +
+ +
React Native
+
+ +```typescript +{{#include ../../snippets/react-native/send_spontaneous_payment.ts:send-spontaneous-payment-with-tlvs}} +``` +
+ +
Dart
+
+ +```dart,ignore +{{#include ../../snippets/dart_snippets/lib/send_spontaneous_payment.dart:send-spontaneous-payment-with-tlvs}} +``` +
+ +
Python
+
+ +```python,ignore +{{#include ../../snippets/python/src/send_spontaneous_payment.py:send-spontaneous-payment-with-tlvs}} +``` +
+ +
Go
+
+ +```go,ignore +{{#include ../../snippets/go/send_spontaneous_payment.go:send-spontaneous-payment-with-tlvs}} +``` +
+ +
C#
+
+ +```cs,ignore +{{#include ../../snippets/csharp/SendSpontaneousPayment.cs:send-spontaneous-payment-with-tlvs}} +``` +
+