From 216763e5e4ea94a910a196cc09a5f2ea88fe672c Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Tue, 12 Mar 2024 18:38:24 +0000 Subject: [PATCH] Update snippets with new connect() signature (#136) * Update snippets with new connect() signature * Update getting started and include restore only example * CI: Use matching SDK commit * Fix dart snippet * Fix go snippet * Update SDK ref commit post RN codegen * Fix RN call to connect() --------- Co-authored-by: Ross Savage --- .github/workflows/main.yml | 2 +- snippets/csharp/GettingStarted.cs | 19 +- .../dart_snippets/lib/getting_started.dart | 10 +- snippets/go/getting_started.go | 20 +- .../example/kotlinmpplib/GettingStarted.kt | 14 +- snippets/python/src/getting_started.py | 14 +- snippets/react-native/getting_started.ts | 20 +- snippets/rust/Cargo.lock | 199 +++++++++--------- snippets/rust/src/getting_started.rs | 19 +- .../Sources/GettingStarted.swift | 13 +- src/guide/getting_started.md | 73 +++++++ 11 files changed, 297 insertions(+), 106 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 333f75bc..57e024c0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,7 +25,7 @@ jobs: name: setup runs-on: ubuntu-latest outputs: - sdk-ref: ${{ inputs.sdk-ref || '0.3.1' }} + sdk-ref: ${{ inputs.sdk-ref || '05307d0c764a1efe73d7e546f77e1fcc03d63b23' }} package-version: '0.3.1' steps: - run: echo "set pre-setup output variables" diff --git a/snippets/csharp/GettingStarted.cs b/snippets/csharp/GettingStarted.cs index 6493927e..76ee4708 100644 --- a/snippets/csharp/GettingStarted.cs +++ b/snippets/csharp/GettingStarted.cs @@ -26,7 +26,8 @@ public void GettingStarted() try { // Connect to the Breez SDK make it ready for use - sdk = BreezSdkMethods.Connect(config, seed, new SdkListener()); + var connectRequest = new ConnectRequest(config, seed); + sdk = BreezSdkMethods.Connect(connectRequest, new SdkListener()); } catch (Exception) { @@ -44,6 +45,22 @@ public void OnEvent(BreezEvent e) } // ANCHOR_END: init-sdk + public void GettingStartedRestoreOnly(Config config, List seed) + { + BlockingBreezServices sdk; + try + { + // ANCHOR: init-sdk-restore-only + var connectRequest = new ConnectRequest(config, seed, true); + sdk = BreezSdkMethods.Connect(connectRequest, new SdkListener()); + // ANCHOR_END: init-sdk-restore-only + } + catch (Exception) + { + // Handle error + } + } + public void FetchNodeInfo(BlockingBreezServices sdk) { // ANCHOR: fetch-balance diff --git a/snippets/dart_snippets/lib/getting_started.dart b/snippets/dart_snippets/lib/getting_started.dart index e06f23a3..9e56933c 100644 --- a/snippets/dart_snippets/lib/getting_started.dart +++ b/snippets/dart_snippets/lib/getting_started.dart @@ -29,10 +29,18 @@ Future initializeSDK() async { config = config.copyWith(workingDir: "path to an existing directory"); // Connect to the Breez SDK make it ready for use - return await BreezSDK().connect(config: config, seed: seed); + ConnectRequest connectRequest = ConnectRequest(config: config, seed: seed); + return await BreezSDK().connect(req: connectRequest); // ANCHOR_END: init-sdk } +Future connectRestoreOnly(Config config, Uint8List seed) async { + // ANCHOR: init-sdk-restore-only + ConnectRequest connectRequest = ConnectRequest(config: config, seed: seed, restoreOnly: true); + return await BreezSDK().connect(req: connectRequest); + // ANCHOR_END: init-sdk-restore-only +} + Future fetchBalance(String lspId) async { // ANCHOR: fetch-balance NodeState? nodeInfo = await BreezSDK().nodeInfo(); diff --git a/snippets/go/getting_started.go b/snippets/go/getting_started.go index b50264b1..84b9816c 100644 --- a/snippets/go/getting_started.go +++ b/snippets/go/getting_started.go @@ -34,7 +34,8 @@ func GettingStarted() *breez_sdk.BlockingBreezServices { // Customize the config object according to your needs config.WorkingDir = "path to an existing directory" - sdk, err := breez_sdk.Connect(config, seed, BreezListener{}) + connectRequest := breez_sdk.ConnectRequest{Config: config, Seed: seed} + sdk, err := breez_sdk.Connect(connectRequest, BreezListener{}) if err != nil { log.Fatalf("Connect failed: %#v", err) } @@ -43,6 +44,23 @@ func GettingStarted() *breez_sdk.BlockingBreezServices { } // ANCHOR_END: init-sdk + +func GettingStartedRestoreOnly(config breez_sdk.Config, seed []uint8) *breez_sdk.BlockingBreezServices { + // ANCHOR: init-sdk-restore-only + restoreOnly := true + connectRequest := breez_sdk.ConnectRequest{ + Config: config, + Seed: seed, + RestoreOnly: &restoreOnly, + } + sdk, err := breez_sdk.Connect(connectRequest, BreezListener{}) + // ANCHOR_END: init-sdk-restore-only + if err != nil { + log.Fatalf("Connect failed: %#v", err) + } + return sdk +} + func FetchBalance() { // ANCHOR: fetch-balance if nodeInfo, err := sdk.NodeInfo(); err != nil { diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/GettingStarted.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/GettingStarted.kt index 8c85d7e5..afbb2e81 100644 --- a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/GettingStarted.kt +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/GettingStarted.kt @@ -26,13 +26,25 @@ class GettingStarted { try { // Connect to the Breez SDK make it ready for use - val sdk = connect(config, seed, SDKListener()) + val connectRequest = ConnectRequest(config, seed) + val sdk = connect(connectRequest, SDKListener()) } catch (e: Exception) { // handle error } // ANCHOR_END: init-sdk } + fun start_restore_only(config: Config, seed: List) { + try { + // ANCHOR: init-sdk-restore-only + val connectRequest = ConnectRequest(config, seed, true) + val sdk = connect(connectRequest, SDKListener()) + // ANCHOR_END: init-sdk-restore-only + } catch (e: Exception) { + // handle error + } + } + fun fetch_balance(sdk: BlockingBreezServices) { // ANCHOR: fetch-balance try { diff --git a/snippets/python/src/getting_started.py b/snippets/python/src/getting_started.py index 9135569b..64975093 100644 --- a/snippets/python/src/getting_started.py +++ b/snippets/python/src/getting_started.py @@ -23,7 +23,8 @@ def getting_started(API_KEY,mnemonic,temp_dir): try: # Connect to the Breez SDK make it ready for use - sdk_services = breez_sdk.connect(config, seed, SDKListener()) + connect_request = breez_sdk.ConnectRequest(config, seed) + sdk_services = breez_sdk.connect(connect_request, SDKListener()) return sdk_services except Exception as error: @@ -31,6 +32,17 @@ def getting_started(API_KEY,mnemonic,temp_dir): raise # ANCHOR_END: init-sdk +def getting_started_restore_only(config, seed): + try: + # ANCHOR: init-sdk-restore-only + connect_request = breez_sdk.ConnectRequest(config, seed, restore_only=True) + sdk_services = breez_sdk.connect(connect_request, SDKListener()) + # ANCHOR_END: init-sdk-restore-only + return sdk_services + except Exception as error: + logging.error(error) + raise + def getting_started_node_info(sdk_services): try: diff --git a/snippets/react-native/getting_started.ts b/snippets/react-native/getting_started.ts index 38fda88e..05ac853a 100644 --- a/snippets/react-native/getting_started.ts +++ b/snippets/react-native/getting_started.ts @@ -1,6 +1,8 @@ import { type BreezEvent, connect, + type Config, + type ConnectRequest, defaultConfig, EnvironmentType, mnemonicToSeed, @@ -35,13 +37,29 @@ const exampleGettingStarted = async () => { ) // Connect to the Breez SDK make it ready for use - await connect(config, seed, onBreezEvent) + const connectRequest: ConnectRequest = { config, seed } + await connect(connectRequest, onBreezEvent) } catch (err) { console.error(err) } // ANCHOR_END: init-sdk } +const onBreezEvent = (e: BreezEvent) => { + console.log(`Received event ${e.type}`) +} + +const exampleGettingRestoreOnly = async (config: Config, seed: number[]) => { + try { + // ANCHOR: init-sdk-restore-only + const connectRequest: ConnectRequest = { config, seed, restoreOnly: true } + await connect(connectRequest, onBreezEvent) + // ANCHOR_END: init-sdk-restore-only + } catch (err) { + console.error(err) + } +} + const exampleFetchNodeInfo = async () => { // ANCHOR: fetch-balance try { diff --git a/snippets/rust/Cargo.lock b/snippets/rust/Cargo.lock index beb68e94..d1d91ef9 100644 --- a/snippets/rust/Cargo.lock +++ b/snippets/rust/Cargo.lock @@ -29,9 +29,9 @@ dependencies = [ [[package]] name = "aes" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac1f845298e95f983ff1944b728ae08b8cebab80d684f0a832ed0fc74dfa27e2" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" dependencies = [ "cfg-if", "cipher", @@ -60,9 +60,9 @@ checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" [[package]] name = "ahash" -version = "0.8.7" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" +checksum = "42cd52102d3df161c77a887b608d7a4897d7cc112886a9537b738a887a03aaff" dependencies = [ "cfg-if", "once_cell", @@ -379,7 +379,7 @@ dependencies = [ "bitcoin_hashes 0.13.0", "hex-conservative", "hex_lit", - "secp256k1 0.28.1", + "secp256k1 0.28.2", ] [[package]] @@ -530,7 +530,7 @@ dependencies = [ "rusqlite_migration", "serde", "serde_json", - "serde_with 3.5.1", + "serde_with 3.6.1", "strum", "strum_macros", "tempfile", @@ -557,9 +557,9 @@ checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "bytemuck" -version = "1.14.1" +version = "1.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed2490600f404f2b94c167e31d3ed1d5f3c225a0f3b80230053b3e0b7b962bd9" +checksum = "a2ef034f05691a48569bd920a96c81b9d91bbad1ab5ac7c4616c1f6ef36cb79f" [[package]] name = "bytes" @@ -617,9 +617,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.32" +version = "0.4.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41daef31d7a747c5c847246f36de49ced6f7403b4cdabc807a97b5cc184cda7a" +checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" dependencies = [ "android-tzdata", "iana-time-zone", @@ -745,9 +745,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.20.3" +version = "0.20.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" +checksum = "fc5d6b04b3fd0ba9926f945895de7d806260a2d7431ba82e7edaecb043c4c6b8" dependencies = [ "darling_core", "darling_macro", @@ -755,9 +755,9 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.3" +version = "0.20.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" +checksum = "04e48a959bcd5c761246f5d090ebc2fbf7b9cd527a492b07a67510c108f1e7e3" dependencies = [ "fnv", "ident_case", @@ -769,9 +769,9 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.20.3" +version = "0.20.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" +checksum = "1d1545d67a2149e1d93b7e5c7752dce5a7426eb5d1357ddcfd89336b94444f77" dependencies = [ "darling_core", "quote", @@ -880,9 +880,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" [[package]] name = "encoding_rs" @@ -1223,7 +1223,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap 2.1.0", + "indexmap 2.2.3", "slab", "tokio", "tokio-util", @@ -1252,7 +1252,7 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" dependencies = [ - "ahash 0.8.7", + "ahash 0.8.8", "allocator-api2", ] @@ -1282,9 +1282,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.4" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d3d0e0f38255e7fa3cf31335b3a56f05febd18025f4db5ef7a0cfb4f8da651f" +checksum = "bd5256b483761cd23699d0da46cc6fd2ee3be420bbe6d020ae4a091e70b7e9fd" [[package]] name = "hex" @@ -1436,9 +1436,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.59" +version = "0.1.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6a67363e2aa4443928ce15e57ebae94fd8949958fd1223c4cfc0cd473ad7539" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -1486,9 +1486,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.1.0" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177" dependencies = [ "equivalent", "hashbrown 0.14.3", @@ -1513,12 +1513,12 @@ checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "is-terminal" -version = "0.4.10" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" +checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" dependencies = [ - "hermit-abi 0.3.4", - "rustix", + "hermit-abi 0.3.6", + "libc", "windows-sys 0.52.0", ] @@ -1539,9 +1539,9 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "js-sys" -version = "0.3.67" +version = "0.3.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" +checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" dependencies = [ "wasm-bindgen", ] @@ -1554,9 +1554,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.152" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "libsecp256k1" @@ -1710,9 +1710,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" dependencies = [ "adler", ] @@ -1806,21 +1806,26 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" -version = "0.1.45" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", "num-traits", ] [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" dependencies = [ "autocfg", ] @@ -1831,7 +1836,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.4", + "hermit-abi 0.3.6", "libc", ] @@ -1899,9 +1904,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-src" -version = "300.2.1+3.2.0" +version = "300.2.3+3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fe476c29791a5ca0d1273c697e96085bbabbbea2ef7afd5617e78a4b40332d3" +checksum = "5cff92b6f71555b61bb9315f7c64da3ca43d87531622120fea0195fc761b4843" dependencies = [ "cc", ] @@ -1979,23 +1984,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", - "indexmap 2.1.0", + "indexmap 2.2.3", ] [[package]] name = "pin-project" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" +checksum = "0302c4a0442c456bd56f841aee5c3bfd17967563f6fadc9ceb9f9c23cf3807e0" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" +checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" dependencies = [ "proc-macro2", "quote", @@ -2016,9 +2021,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "poly1305" @@ -2239,9 +2244,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b7fa1134405e2ec9353fd416b17f8dacd46c473d7d3fd1cf202706a14eb792a" +checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" dependencies = [ "aho-corasick", "memchr", @@ -2382,9 +2387,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.30" +version = "0.38.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" +checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" dependencies = [ "bitflags 2.4.2", "errno", @@ -2530,9 +2535,9 @@ dependencies = [ [[package]] name = "secp256k1" -version = "0.28.1" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f622567e3b4b38154fb8190bcf6b160d7a4301d70595a49195b48c116007a27" +checksum = "d24b59d129cdadea20aea4fb2352fa053712e5d713eee47d700cd4b2bc002f10" dependencies = [ "bitcoin_hashes 0.13.0", "secp256k1-sys 0.9.2", @@ -2590,9 +2595,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.195" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" dependencies = [ "serde_derive", ] @@ -2622,9 +2627,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.195" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" dependencies = [ "proc-macro2", "quote", @@ -2633,9 +2638,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.111" +version = "1.0.113" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" +checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" dependencies = [ "itoa", "ryu", @@ -2671,18 +2676,19 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.5.1" +version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5c9fdb6b00a489875b22efd4b78fe2b363b72265cc5f6eb2e2b9ee270e6140c" +checksum = "15d167997bd841ec232f5b2b8e0e26606df2e7caa4c31b95ea9ca52b200bd270" dependencies = [ "base64 0.21.7", "chrono", "hex", "indexmap 1.9.3", - "indexmap 2.1.0", + "indexmap 2.2.3", "serde", + "serde_derive", "serde_json", - "serde_with_macros 3.5.1", + "serde_with_macros 3.6.1", "time", ] @@ -2700,9 +2706,9 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "3.5.1" +version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbff351eb4b33600a2e138dfa0b10b65a238ea8ff8fb2387c422c5022a3e8298" +checksum = "865f9743393e638991566a8b7a479043c2c8da94a33e0a31f18214c9cae0a64d" dependencies = [ "darling", "proc-macro2", @@ -2853,13 +2859,12 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.9.0" +version = "3.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" +checksum = "a365e8cd18e44762ef95d87f284f4b5cd04107fec2ff3052bd6a3e6069669e67" dependencies = [ "cfg-if", "fastrand", - "redox_syscall", "rustix", "windows-sys 0.52.0", ] @@ -2881,18 +2886,18 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" [[package]] name = "thiserror" -version = "1.0.56" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.56" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" dependencies = [ "proc-macro2", "quote", @@ -2910,12 +2915,13 @@ dependencies = [ [[package]] name = "time" -version = "0.3.31" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" +checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" dependencies = [ "deranged", "itoa", + "num-conv", "powerfmt", "serde", "time-core", @@ -2930,10 +2936,11 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" +checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" dependencies = [ + "num-conv", "time-core", ] @@ -2973,9 +2980,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.35.1" +version = "1.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" +checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" dependencies = [ "backtrace", "bytes", @@ -3379,9 +3386,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.90" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" +checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -3389,9 +3396,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.90" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" +checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" dependencies = [ "bumpalo", "log", @@ -3404,9 +3411,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.40" +version = "0.4.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bde2032aeb86bdfaecc8b261eef3cba735cc426c1f3a3416d1e0791be95fc461" +checksum = "877b9c3f61ceea0e56331985743b13f3d25c406a7098d45180fb5f09bc19ed97" dependencies = [ "cfg-if", "js-sys", @@ -3416,9 +3423,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.90" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" +checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3426,9 +3433,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.90" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" +checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" dependencies = [ "proc-macro2", "quote", @@ -3439,15 +3446,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.90" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" +checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" [[package]] name = "web-sys" -version = "0.3.67" +version = "0.3.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58cd2333b6e0be7a39605f0e255892fd7418a682d8da8fe042fe25128794d2ed" +checksum = "96565907687f7aceb35bc5fc03770a8a0471d82e479f25832f54a0e3f4b28446" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/snippets/rust/src/getting_started.rs b/snippets/rust/src/getting_started.rs index 876e20eb..5f82b515 100644 --- a/snippets/rust/src/getting_started.rs +++ b/snippets/rust/src/getting_started.rs @@ -28,12 +28,29 @@ async fn getting_started() -> Result> { config.working_dir = "path to an existing directory".into(); // Connect to the Breez SDK make it ready for use - let sdk = BreezServices::connect(config, seed.to_vec(), Box::new(AppEventListener {})).await?; + let connect_request = ConnectRequest { + config, + seed: seed.to_vec(), + restore_only: None, + }; + let sdk = BreezServices::connect(connect_request, Box::new(AppEventListener {})).await?; // ANCHOR_END: init-sdk Ok(sdk) } +async fn getting_started_restore_only(config: Config, seed: Vec) -> Result> { + // ANCHOR: init-sdk-restore-only + let connect_request = ConnectRequest { + config, + seed, + restore_only: Some(true), + }; + let sdk = BreezServices::connect(connect_request, Box::new(AppEventListener {})).await?; + // ANCHOR_END: init-sdk-restore-only + Ok(sdk) +} + async fn getting_started_node_info(sdk: Arc) -> Result<()> { // ANCHOR: fetch-balance let node_state = sdk.node_info()?; diff --git a/snippets/swift/BreezSDKExamples/Sources/GettingStarted.swift b/snippets/swift/BreezSDKExamples/Sources/GettingStarted.swift index 4ec4ffcf..b20e8357 100644 --- a/snippets/swift/BreezSDKExamples/Sources/GettingStarted.swift +++ b/snippets/swift/BreezSDKExamples/Sources/GettingStarted.swift @@ -32,12 +32,21 @@ func gettingStarted() throws -> BlockingBreezServices? { guard seed != nil else { return nil } - let sdk = try? connect(config: config, seed: seed!, listener: SDKListener()) + let connectRequest = ConnectRequest(config: config, seed: seed!) + let sdk = try? connect(req: connectRequest, listener: SDKListener()) return sdk } - // ANCHOR_END: init-sdk + +func gettingStartedRestoreOnly(config: Config, seed: [UInt8]) throws -> BlockingBreezServices? { + // ANCHOR: init-sdk-restore-only + let connectRequest = ConnectRequest(config: config, seed: seed, restoreOnly: true) + let sdk = try? connect(req: connectRequest, listener: SDKListener()) + // ANCHOR_END: init-sdk-restore-only + return sdk +} + func gettingStartedNodeInfo(sdk: BlockingBreezServices) { // ANCHOR: fetch-balance if let nodeInfo = try? sdk.nodeInfo() { diff --git a/src/guide/getting_started.md b/src/guide/getting_started.md index 358a673b..00b77724 100644 --- a/src/guide/getting_started.md +++ b/src/guide/getting_started.md @@ -113,6 +113,79 @@ Now you are ready to interact with the SDK. By default the config working directory is set to `./`. Some platforms may require that you use an application specific directory that is writable within the application sandbox. For example applications running on Android or iOS. +
+ +To connect to an already existing node without registering a new one, use the `restore_only` flag in the connect request. If the node does not exist it will result in an error. + + +
Rust
+
+ +```rust,ignore +{{#include ../../snippets/rust/src/getting_started.rs:init-sdk-restore-only}} +``` + +
+ +
Swift
+
+ +```swift,ignore +{{#include ../../snippets/swift/BreezSDKExamples/Sources/GettingStarted.swift:init-sdk-restore-only}} +``` + +
+ +
Kotlin
+
+ +```kotlin,ignore +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/GettingStarted.kt:init-sdk-restore-only}} +``` + +
+ +
React Native
+
+ +```typescript +{{#include ../../snippets/react-native/getting_started.ts:init-sdk-restore-only}} +``` + +
+ +
Dart
+
+ +```dart,ignore +{{#include ../../snippets/dart_snippets/lib/getting_started.dart:init-sdk-restore-only}} +``` +
+ +
Python
+
+ +```python,ignore +{{#include ../../snippets/python/src/getting_started.py:init-sdk-restore-only}} +``` +
+ +
Go
+
+ +```go,ignore +{{#include ../../snippets/go/getting_started.go:init-sdk-restore-only}} +``` +
+ +
C#
+
+ +```cs,ignore +{{#include ../../snippets/csharp/GettingStarted.cs:init-sdk-restore-only}} +``` +
+
## Getting the Node State