From f8f5598d10930b6026974d5c2b33639e73c4fa26 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:18:24 +0200 Subject: [PATCH 1/5] Rename init() to connect() --- cli/src/main.rs | 2 +- lib/ls-sdk-bindings/src/lib.rs | 4 ++-- lib/ls-sdk-bindings/src/ls_sdk.udl | 2 +- lib/ls-sdk-bindings/tests/bindings/test_ls_sdk.kts | 2 +- lib/ls-sdk-bindings/tests/bindings/test_ls_sdk.py | 2 +- lib/ls-sdk-bindings/tests/bindings/test_ls_sdk.swift | 2 +- lib/ls-sdk-core/README.md | 2 +- lib/ls-sdk-core/src/lib.rs | 6 ++++-- lib/ls-sdk-core/src/wallet.rs | 6 +++++- 9 files changed, 17 insertions(+), 11 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 08ecbb805..5e14b506d 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -71,7 +71,7 @@ fn main() -> Result<()> { } let mnemonic = persistence.get_or_create_mnemonic()?; - let wallet = Wallet::init( + let wallet = Wallet::connect( &mnemonic.to_string(), Some(data_dir_str), Network::LiquidTestnet, diff --git a/lib/ls-sdk-bindings/src/lib.rs b/lib/ls-sdk-bindings/src/lib.rs index a519f4439..45f24290c 100644 --- a/lib/ls-sdk-bindings/src/lib.rs +++ b/lib/ls-sdk-bindings/src/lib.rs @@ -19,12 +19,12 @@ impl From for LsSdkError { } } -pub fn init( +pub fn connect( mnemonic: String, data_dir: Option, network: Network, ) -> Result, LsSdkError> { - let ln_sdk = Wallet::init(&mnemonic, data_dir, network)?; + let ln_sdk = Wallet::connect(&mnemonic, data_dir, network)?; Ok(Arc::from(BindingWallet { ln_sdk })) } diff --git a/lib/ls-sdk-bindings/src/ls_sdk.udl b/lib/ls-sdk-bindings/src/ls_sdk.udl index 034cc01da..0f0f7e763 100644 --- a/lib/ls-sdk-bindings/src/ls_sdk.udl +++ b/lib/ls-sdk-bindings/src/ls_sdk.udl @@ -58,7 +58,7 @@ dictionary ReceivePaymentResponse { namespace ls_sdk { [Throws=LsSdkError] - BindingWallet init(string mnemonic, string? data_dir, Network network); + BindingWallet connect(string mnemonic, string? data_dir, Network network); }; interface BindingWallet { diff --git a/lib/ls-sdk-bindings/tests/bindings/test_ls_sdk.kts b/lib/ls-sdk-bindings/tests/bindings/test_ls_sdk.kts index 296ecdcb6..9a1f19ec1 100644 --- a/lib/ls-sdk-bindings/tests/bindings/test_ls_sdk.kts +++ b/lib/ls-sdk-bindings/tests/bindings/test_ls_sdk.kts @@ -1,6 +1,6 @@ try { var mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about" - var sdk = ls_sdk.init(mnemonic, null, ls_sdk.Network.LIQUID_TESTNET) + var sdk = ls_sdk.connect(mnemonic, null, ls_sdk.Network.LIQUID_TESTNET) var nodeInfo = sdk.getInfo(false) println("$nodeInfo") assert(nodeInfo.pubkey.equals("03d902f35f560e0470c63313c7369168d9d7df2d49bf295fd9fb7cb109ccee0494")) diff --git a/lib/ls-sdk-bindings/tests/bindings/test_ls_sdk.py b/lib/ls-sdk-bindings/tests/bindings/test_ls_sdk.py index df486b32e..3ac2f72d8 100644 --- a/lib/ls-sdk-bindings/tests/bindings/test_ls_sdk.py +++ b/lib/ls-sdk-bindings/tests/bindings/test_ls_sdk.py @@ -2,7 +2,7 @@ def test(): mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about" - sdk = ls_sdk.init(mnemonic, None, ls_sdk.Network.LIQUID_TESTNET) + sdk = ls_sdk.connect(mnemonic, None, ls_sdk.Network.LIQUID_TESTNET) node_info = sdk.get_info(False) print(node_info) assert node_info.pubkey == "03d902f35f560e0470c63313c7369168d9d7df2d49bf295fd9fb7cb109ccee0494" diff --git a/lib/ls-sdk-bindings/tests/bindings/test_ls_sdk.swift b/lib/ls-sdk-bindings/tests/bindings/test_ls_sdk.swift index 8493d5d16..cf75c3910 100644 --- a/lib/ls-sdk-bindings/tests/bindings/test_ls_sdk.swift +++ b/lib/ls-sdk-bindings/tests/bindings/test_ls_sdk.swift @@ -1,7 +1,7 @@ import ls_sdk let mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"; -let sdk = try ls_sdk.`init`(mnemonic: mnemonic, dataDir: nil, network: .liquidTestnet); +let sdk = try ls_sdk.connect(mnemonic: mnemonic, dataDir: nil, network: .liquidTestnet); let nodeInfo = try sdk.getInfo(withScan: false); print(nodeInfo); assert(nodeInfo.pubkey == "03d902f35f560e0470c63313c7369168d9d7df2d49bf295fd9fb7cb109ccee0494", "nodeInfo.pubkey"); \ No newline at end of file diff --git a/lib/ls-sdk-core/README.md b/lib/ls-sdk-core/README.md index fa752c225..dcc621772 100644 --- a/lib/ls-sdk-core/README.md +++ b/lib/ls-sdk-core/README.md @@ -16,7 +16,7 @@ The wallet provides the ability to `backup` and `restore` ongoing swaps via the let mnemonic = "..."; let data_dir = None; let network = Network::Liquid; -let breez_wallet = Wallet::init(mnemonic, data_dir, network)?; +let breez_wallet = Wallet::connect(mnemonic, data_dir, network)?; breez_wallet.backup()?; // Backs up the pending swaps under `{data_dir}/backup{-testnet}.sql`. Overwrites previous versions. let backup_path = None; // Can also be Some(String), a path pointing to the database. Default is `{data_dir}/backup{-testnet}.sql` diff --git a/lib/ls-sdk-core/src/lib.rs b/lib/ls-sdk-core/src/lib.rs index 3c10286c4..207d83928 100644 --- a/lib/ls-sdk-core/src/lib.rs +++ b/lib/ls-sdk-core/src/lib.rs @@ -66,7 +66,8 @@ mod tests { #[test] fn normal_submarine_swap() -> Result<()> { let (_data_dir, data_dir_str) = create_temp_dir()?; - let breez_wallet = Wallet::init(TEST_MNEMONIC, Some(data_dir_str), Network::LiquidTestnet)?; + let breez_wallet = + Wallet::connect(TEST_MNEMONIC, Some(data_dir_str), Network::LiquidTestnet)?; let invoice = "lntb10u1pnqwkjrpp5j8ucv9mgww0ajk95yfpvuq0gg5825s207clrzl5thvtuzfn68h0sdqqcqzzsxqr23srzjqv8clnrfs9keq3zlg589jvzpw87cqh6rjks0f9g2t9tvuvcqgcl45f6pqqqqqfcqqyqqqqlgqqqqqqgq2qsp5jnuprlxrargr6hgnnahl28nvutj3gkmxmmssu8ztfhmmey3gq2ss9qyyssq9ejvcp6frwklf73xvskzdcuhnnw8dmxag6v44pffwqrxznsly4nqedem3p3zhn6u4ln7k79vk6zv55jjljhnac4gnvr677fyhfgn07qp4x6wrq"; breez_wallet.prepare_send_payment(&invoice)?; @@ -78,7 +79,8 @@ mod tests { #[test] fn reverse_submarine_swap() -> Result<()> { let (_data_dir, data_dir_str) = create_temp_dir()?; - let breez_wallet = Wallet::init(TEST_MNEMONIC, Some(data_dir_str), Network::LiquidTestnet)?; + let breez_wallet = + Wallet::connect(TEST_MNEMONIC, Some(data_dir_str), Network::LiquidTestnet)?; let prepare_response = breez_wallet.prepare_receive_payment(&PrepareReceiveRequest { receiver_amount_sat: Some(1000), diff --git a/lib/ls-sdk-core/src/wallet.rs b/lib/ls-sdk-core/src/wallet.rs index 174ce53f7..6615be9e5 100644 --- a/lib/ls-sdk-core/src/wallet.rs +++ b/lib/ls-sdk-core/src/wallet.rs @@ -47,7 +47,11 @@ pub struct Wallet { } impl Wallet { - pub fn init(mnemonic: &str, data_dir: Option, network: Network) -> Result> { + pub fn connect( + mnemonic: &str, + data_dir: Option, + network: Network, + ) -> Result> { let is_mainnet = network == Network::Liquid; let signer = SwSigner::new(mnemonic, is_mainnet)?; let descriptor = Wallet::get_descriptor(&signer, network)?; From 1789e6ca524db20e387a3fa72eefa5eda42f8364 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:34:11 +0200 Subject: [PATCH 2/5] Shorten commit ID for secp256k1-zkp dependency --- cli/Cargo.lock | 4 ++-- cli/Cargo.toml | 3 ++- lib/Cargo.lock | 4 ++-- lib/Cargo.toml | 3 ++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cli/Cargo.lock b/cli/Cargo.lock index a84ad0e9d..f35a6ceda 100644 --- a/cli/Cargo.lock +++ b/cli/Cargo.lock @@ -1820,7 +1820,7 @@ dependencies = [ [[package]] name = "secp256k1-zkp" version = "0.10.0" -source = "git+https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git?rev=60e631c24588a0c9e271badd61959294848c665d#60e631c24588a0c9e271badd61959294848c665d" +source = "git+https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git?rev=60e631c24#60e631c24588a0c9e271badd61959294848c665d" dependencies = [ "bitcoin-private", "rand", @@ -1832,7 +1832,7 @@ dependencies = [ [[package]] name = "secp256k1-zkp-sys" version = "0.9.1" -source = "git+https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git?rev=60e631c24588a0c9e271badd61959294848c665d#60e631c24588a0c9e271badd61959294848c665d" +source = "git+https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git?rev=60e631c24#60e631c24588a0c9e271badd61959294848c665d" dependencies = [ "cc", "secp256k1-sys 0.9.2", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index ec0581392..ad2eeaaf0 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -18,4 +18,5 @@ serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.115" [patch.crates-io] -secp256k1-zkp = {git = "https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git", rev = "60e631c24588a0c9e271badd61959294848c665d"} +# https://github.com/BlockstreamResearch/rust-secp256k1-zkp/pull/48/commits +secp256k1-zkp = {git = "https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git", rev = "60e631c24"} diff --git a/lib/Cargo.lock b/lib/Cargo.lock index 8c14fd268..f8194a998 100644 --- a/lib/Cargo.lock +++ b/lib/Cargo.lock @@ -2143,7 +2143,7 @@ dependencies = [ [[package]] name = "secp256k1-zkp" version = "0.10.0" -source = "git+https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git?rev=60e631c24588a0c9e271badd61959294848c665d#60e631c24588a0c9e271badd61959294848c665d" +source = "git+https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git?rev=60e631c24#60e631c24588a0c9e271badd61959294848c665d" dependencies = [ "bitcoin-private", "rand 0.8.5", @@ -2155,7 +2155,7 @@ dependencies = [ [[package]] name = "secp256k1-zkp-sys" version = "0.9.1" -source = "git+https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git?rev=60e631c24588a0c9e271badd61959294848c665d#60e631c24588a0c9e271badd61959294848c665d" +source = "git+https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git?rev=60e631c24#60e631c24588a0c9e271badd61959294848c665d" dependencies = [ "cc", "secp256k1-sys 0.9.2", diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 4e56c82e0..2cdc99129 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -23,4 +23,5 @@ uniffi = "0.27.1" uniffi_macros = "0.27.1" [patch.crates-io] -secp256k1-zkp = {git = "https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git", rev = "60e631c24588a0c9e271badd61959294848c665d"} +# https://github.com/BlockstreamResearch/rust-secp256k1-zkp/pull/48/commits +secp256k1-zkp = {git = "https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git", rev = "60e631c24"} From a81b9e4e6a9144fe25cd9501638ae1c24dc994f4 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:40:28 +0200 Subject: [PATCH 3/5] Update RN bindings --- .../java/com/lssdk/LiquidSwapSDKModule.kt | 19 +++++++++++++++++++ lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.m | 8 ++++++++ .../ios/RNLiquidSwapSDK.swift | 12 ++++++++++++ lib/ls-sdk-react-native/src/index.ts | 5 +++++ 4 files changed, 44 insertions(+) diff --git a/lib/ls-sdk-react-native/android/src/main/java/com/lssdk/LiquidSwapSDKModule.kt b/lib/ls-sdk-react-native/android/src/main/java/com/lssdk/LiquidSwapSDKModule.kt index e275d7b83..b1d88245d 100644 --- a/lib/ls-sdk-react-native/android/src/main/java/com/lssdk/LiquidSwapSDKModule.kt +++ b/lib/ls-sdk-react-native/android/src/main/java/com/lssdk/LiquidSwapSDKModule.kt @@ -39,6 +39,25 @@ class LiquidSwapSDKModule(reactContext: ReactApplicationContext) : ReactContextB @ReactMethod fun removeListeners(count: Int) {} + @ReactMethod + fun connect( + mnemonic: String, + dataDir: String, + network: String, + promise: Promise, + ) { + executor.execute { + try { + val dataDirTmp = dataDir.takeUnless { it.isEmpty() } + val networkTmp = asNetwork(network) + val res = connect(mnemonic, dataDirTmp, networkTmp) + promise.resolve(res) + } catch (e: Exception) { + promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e) + } + } + } + @ReactMethod fun initBindingWallet( mnemonic: String, diff --git a/lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.m b/lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.m index c0c0e9c1e..8b28059e4 100644 --- a/lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.m +++ b/lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.m @@ -2,6 +2,14 @@ #import @interface RCT_EXTERN_MODULE(RNLiquidSwapSDK, RCTEventEmitter) + +RCT_EXTERN_METHOD( + connect: (NSString*)mnemonic + dataDir: (NSString*)dataDir + network: (NSString*)network + resolve: (RCTPromiseResolveBlock)resolve + reject: (RCTPromiseRejectBlock)reject +) RCT_EXTERN_METHOD( initBindingWallet: (NSString*)mnemonic diff --git a/lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.swift b/lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.swift index e9c28dc55..31d241bfe 100644 --- a/lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.swift +++ b/lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.swift @@ -51,6 +51,18 @@ class RNLiquidSwapSDK: RCTEventEmitter { throw LsSdkError.Generic(message: "Not initialized") } + @objc(connect:dataDir:network:resolve:reject:) + func connect(_ mnemonic: String, dataDir: String, network: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + do { + let dataDirTmp = dataDir.isEmpty ? nil : dataDir + let networkTmp = try LiquidSwapSDKMapper.asNetwork(network: network) + var res = try LiquidSwapSDK.connect(mnemonic: mnemonic, dataDir: dataDirTmp, network: networkTmp) + resolve(res) + } catch let err { + rejectErr(err: err, reject: reject) + } + } + @objc(initBindingWallet:dataDir:network:resolve:reject:) func initBindingWallet(_ mnemonic: String, dataDir: String, network: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { if bindingWallet != nil { diff --git a/lib/ls-sdk-react-native/src/index.ts b/lib/ls-sdk-react-native/src/index.ts index d5181275c..465d75d21 100644 --- a/lib/ls-sdk-react-native/src/index.ts +++ b/lib/ls-sdk-react-native/src/index.ts @@ -60,6 +60,11 @@ export const init = async (mnemonic: string, dataDir: string = "", network: Netw const response = await LiquidSwapSDK.initBindingWallet(mnemonic, dataDir, network) return response } +export const connect = async (mnemonic: string, dataDir: string = "", network: Network): Promise => { + const response = await LiquidSwapSDK.connect(mnemonic, dataDir, network) + return response +} + export const getInfo = async (withScan: boolean): Promise => { const response = await LiquidSwapSDK.getInfo(withScan) From 207f3f6260ae3d9fc8c4741b662f33dea55e5570 Mon Sep 17 00:00:00 2001 From: Ross Savage Date: Mon, 29 Apr 2024 14:05:57 +0200 Subject: [PATCH 4/5] Rename the manually coded init function to connect --- .../src/gen_kotlin/mod.rs | 2 +- .../src/gen_kotlin/templates/module.kt | 4 ++-- .../src/gen_swift/mod.rs | 2 +- .../src/gen_swift/templates/extern.m | 2 +- .../src/gen_swift/templates/module.swift | 6 +++--- .../src/gen_typescript/mod.rs | 2 +- .../src/gen_typescript/templates/Helpers.ts | 5 ----- .../java/com/lssdk/LiquidSwapSDKModule.kt | 21 +------------------ lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.m | 10 +-------- .../ios/RNLiquidSwapSDK.swift | 14 +------------ lib/ls-sdk-react-native/src/index.ts | 4 ---- 11 files changed, 12 insertions(+), 60 deletions(-) diff --git a/lib/ls-sdk-bindings/bindings-react-native/src/gen_kotlin/mod.rs b/lib/ls-sdk-bindings/bindings-react-native/src/gen_kotlin/mod.rs index 570c40c19..a63d87092 100644 --- a/lib/ls-sdk-bindings/bindings-react-native/src/gen_kotlin/mod.rs +++ b/lib/ls-sdk-bindings/bindings-react-native/src/gen_kotlin/mod.rs @@ -10,7 +10,7 @@ pub use uniffi_bindgen::bindings::kotlin::gen_kotlin::*; use crate::generator::RNConfig; static IGNORED_FUNCTIONS: Lazy> = Lazy::new(|| { - let list: Vec<&str> = vec!["init"]; + let list: Vec<&str> = vec!["connect"]; HashSet::from_iter(list.into_iter().map(|s| s.to_string())) }); diff --git a/lib/ls-sdk-bindings/bindings-react-native/src/gen_kotlin/templates/module.kt b/lib/ls-sdk-bindings/bindings-react-native/src/gen_kotlin/templates/module.kt index ce6aa541d..66cc8ef0f 100644 --- a/lib/ls-sdk-bindings/bindings-react-native/src/gen_kotlin/templates/module.kt +++ b/lib/ls-sdk-bindings/bindings-react-native/src/gen_kotlin/templates/module.kt @@ -50,7 +50,7 @@ class LiquidSwapSDKModule(reactContext: ReactApplicationContext) : ReactContextB {%- endfor %} @ReactMethod - fun initBindingWallet(mnemonic: String, dataDir: String, network: String, promise: Promise) { + fun connect(mnemonic: String, dataDir: String, network: String, promise: Promise) { if (bindingWallet != null) { promise.reject("Generic", "Already initialized") return @@ -60,7 +60,7 @@ class LiquidSwapSDKModule(reactContext: ReactApplicationContext) : ReactContextB try { val dataDirTmp = dataDir.takeUnless { it.isEmpty() } ?: run { reactApplicationContext.filesDir.toString() + "/lsSdk" } val networkTmp = asNetwork(network) - bindingWallet = init(mnemonic, dataDirTmp, networkTmp) + bindingWallet = connect(mnemonic, dataDirTmp, networkTmp) promise.resolve(readableMapOf("status" to "ok")) } catch (e: Exception) { promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e) diff --git a/lib/ls-sdk-bindings/bindings-react-native/src/gen_swift/mod.rs b/lib/ls-sdk-bindings/bindings-react-native/src/gen_swift/mod.rs index c15100365..be1e17c55 100644 --- a/lib/ls-sdk-bindings/bindings-react-native/src/gen_swift/mod.rs +++ b/lib/ls-sdk-bindings/bindings-react-native/src/gen_swift/mod.rs @@ -9,7 +9,7 @@ use crate::generator::RNConfig; pub use uniffi_bindgen::bindings::swift::gen_swift::*; static IGNORED_FUNCTIONS: Lazy> = Lazy::new(|| { - let list: Vec<&str> = vec!["init"]; + let list: Vec<&str> = vec!["connect"]; HashSet::from_iter(list.into_iter().map(|s| s.to_string())) }); diff --git a/lib/ls-sdk-bindings/bindings-react-native/src/gen_swift/templates/extern.m b/lib/ls-sdk-bindings/bindings-react-native/src/gen_swift/templates/extern.m index 27d286369..4d84ddeb6 100644 --- a/lib/ls-sdk-bindings/bindings-react-native/src/gen_swift/templates/extern.m +++ b/lib/ls-sdk-bindings/bindings-react-native/src/gen_swift/templates/extern.m @@ -8,7 +8,7 @@ @interface RCT_EXTERN_MODULE(RNLiquidSwapSDK, RCTEventEmitter) {% endif %} {%- endfor %} RCT_EXTERN_METHOD( - initBindingWallet: (NSString*)mnemonic + connect: (NSString*)mnemonic dataDir: (NSString*)dataDir network: (NSString*)network resolve: (RCTPromiseResolveBlock)resolve diff --git a/lib/ls-sdk-bindings/bindings-react-native/src/gen_swift/templates/module.swift b/lib/ls-sdk-bindings/bindings-react-native/src/gen_swift/templates/module.swift index e05c5c88c..246248169 100644 --- a/lib/ls-sdk-bindings/bindings-react-native/src/gen_swift/templates/module.swift +++ b/lib/ls-sdk-bindings/bindings-react-native/src/gen_swift/templates/module.swift @@ -57,8 +57,8 @@ class RNLiquidSwapSDK: RCTEventEmitter { {% include "TopLevelFunctionTemplate.swift" %} {% endif -%} {%- endfor %} - @objc(initBindingWallet:dataDir:network:resolve:reject:) - func initBindingWallet(_ mnemonic: String, dataDir: String, network: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + @objc(connect:dataDir:network:resolve:reject:) + func connect(_ mnemonic: String, dataDir: String, network: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { if bindingWallet != nil { reject("Generic", "Already initialized", nil) return @@ -67,7 +67,7 @@ class RNLiquidSwapSDK: RCTEventEmitter { do { let dataDirTmp = dataDir.isEmpty ? RNLiquidSwapSDK.defaultDataDir.path : dataDir let networkTmp = try LiquidSwapSDKMapper.asNetwork(network: network) - bindingWallet = try LiquidSwapSDK.`init`(mnemonic: mnemonic, dataDir: dataDirTmp, network: networkTmp) + bindingWallet = try LiquidSwapSDK.connect(mnemonic: mnemonic, dataDir: dataDirTmp, network: networkTmp) resolve(["status": "ok"]) } catch let err { rejectErr(err: err, reject: reject) diff --git a/lib/ls-sdk-bindings/bindings-react-native/src/gen_typescript/mod.rs b/lib/ls-sdk-bindings/bindings-react-native/src/gen_typescript/mod.rs index 6ec045de8..a98e5f98a 100644 --- a/lib/ls-sdk-bindings/bindings-react-native/src/gen_typescript/mod.rs +++ b/lib/ls-sdk-bindings/bindings-react-native/src/gen_typescript/mod.rs @@ -26,7 +26,7 @@ static KEYWORDS: Lazy> = Lazy::new(|| { }); static IGNORED_FUNCTIONS: Lazy> = Lazy::new(|| { - let list: Vec<&str> = vec!["init"]; + let list: Vec<&str> = vec![]; HashSet::from_iter(list.into_iter().map(|s| s.to_string())) }); diff --git a/lib/ls-sdk-bindings/bindings-react-native/src/gen_typescript/templates/Helpers.ts b/lib/ls-sdk-bindings/bindings-react-native/src/gen_typescript/templates/Helpers.ts index 6944725c8..e69de29bb 100644 --- a/lib/ls-sdk-bindings/bindings-react-native/src/gen_typescript/templates/Helpers.ts +++ b/lib/ls-sdk-bindings/bindings-react-native/src/gen_typescript/templates/Helpers.ts @@ -1,5 +0,0 @@ - -export const init = async (mnemonic: string, dataDir: string = "", network: Network): Promise => { - const response = await LiquidSwapSDK.initBindingWallet(mnemonic, dataDir, network) - return response -} \ No newline at end of file diff --git a/lib/ls-sdk-react-native/android/src/main/java/com/lssdk/LiquidSwapSDKModule.kt b/lib/ls-sdk-react-native/android/src/main/java/com/lssdk/LiquidSwapSDKModule.kt index b1d88245d..1de4986ba 100644 --- a/lib/ls-sdk-react-native/android/src/main/java/com/lssdk/LiquidSwapSDKModule.kt +++ b/lib/ls-sdk-react-native/android/src/main/java/com/lssdk/LiquidSwapSDKModule.kt @@ -45,25 +45,6 @@ class LiquidSwapSDKModule(reactContext: ReactApplicationContext) : ReactContextB dataDir: String, network: String, promise: Promise, - ) { - executor.execute { - try { - val dataDirTmp = dataDir.takeUnless { it.isEmpty() } - val networkTmp = asNetwork(network) - val res = connect(mnemonic, dataDirTmp, networkTmp) - promise.resolve(res) - } catch (e: Exception) { - promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e) - } - } - } - - @ReactMethod - fun initBindingWallet( - mnemonic: String, - dataDir: String, - network: String, - promise: Promise, ) { if (bindingWallet != null) { promise.reject("Generic", "Already initialized") @@ -74,7 +55,7 @@ class LiquidSwapSDKModule(reactContext: ReactApplicationContext) : ReactContextB try { val dataDirTmp = dataDir.takeUnless { it.isEmpty() } ?: run { reactApplicationContext.filesDir.toString() + "/lsSdk" } val networkTmp = asNetwork(network) - bindingWallet = init(mnemonic, dataDirTmp, networkTmp) + bindingWallet = connect(mnemonic, dataDirTmp, networkTmp) promise.resolve(readableMapOf("status" to "ok")) } catch (e: Exception) { promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e) diff --git a/lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.m b/lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.m index 8b28059e4..773582ca9 100644 --- a/lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.m +++ b/lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.m @@ -2,17 +2,9 @@ #import @interface RCT_EXTERN_MODULE(RNLiquidSwapSDK, RCTEventEmitter) - -RCT_EXTERN_METHOD( - connect: (NSString*)mnemonic - dataDir: (NSString*)dataDir - network: (NSString*)network - resolve: (RCTPromiseResolveBlock)resolve - reject: (RCTPromiseRejectBlock)reject -) RCT_EXTERN_METHOD( - initBindingWallet: (NSString*)mnemonic + connect: (NSString*)mnemonic dataDir: (NSString*)dataDir network: (NSString*)network resolve: (RCTPromiseResolveBlock)resolve diff --git a/lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.swift b/lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.swift index 31d241bfe..a5b7b923d 100644 --- a/lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.swift +++ b/lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.swift @@ -53,18 +53,6 @@ class RNLiquidSwapSDK: RCTEventEmitter { @objc(connect:dataDir:network:resolve:reject:) func connect(_ mnemonic: String, dataDir: String, network: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { - do { - let dataDirTmp = dataDir.isEmpty ? nil : dataDir - let networkTmp = try LiquidSwapSDKMapper.asNetwork(network: network) - var res = try LiquidSwapSDK.connect(mnemonic: mnemonic, dataDir: dataDirTmp, network: networkTmp) - resolve(res) - } catch let err { - rejectErr(err: err, reject: reject) - } - } - - @objc(initBindingWallet:dataDir:network:resolve:reject:) - func initBindingWallet(_ mnemonic: String, dataDir: String, network: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { if bindingWallet != nil { reject("Generic", "Already initialized", nil) return @@ -73,7 +61,7 @@ class RNLiquidSwapSDK: RCTEventEmitter { do { let dataDirTmp = dataDir.isEmpty ? RNLiquidSwapSDK.defaultDataDir.path : dataDir let networkTmp = try LiquidSwapSDKMapper.asNetwork(network: network) - bindingWallet = try LiquidSwapSDK.`init`(mnemonic: mnemonic, dataDir: dataDirTmp, network: networkTmp) + bindingWallet = try LiquidSwapSDK.connect(mnemonic: mnemonic, dataDir: dataDirTmp, network: networkTmp) resolve(["status": "ok"]) } catch let err { rejectErr(err: err, reject: reject) diff --git a/lib/ls-sdk-react-native/src/index.ts b/lib/ls-sdk-react-native/src/index.ts index 465d75d21..3fde7a9bc 100644 --- a/lib/ls-sdk-react-native/src/index.ts +++ b/lib/ls-sdk-react-native/src/index.ts @@ -56,10 +56,6 @@ export enum Network { LIQUID_TESTNET = "liquidTestnet" } -export const init = async (mnemonic: string, dataDir: string = "", network: Network): Promise => { - const response = await LiquidSwapSDK.initBindingWallet(mnemonic, dataDir, network) - return response -} export const connect = async (mnemonic: string, dataDir: string = "", network: Network): Promise => { const response = await LiquidSwapSDK.connect(mnemonic, dataDir, network) return response From 9b68b8ec0d6c183618a015cb02465a2385e46a9e Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:35:55 +0200 Subject: [PATCH 5/5] Update RN example app --- lib/ls-sdk-react-native/example/App.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ls-sdk-react-native/example/App.js b/lib/ls-sdk-react-native/example/App.js index 3fa4c97af..707e7d1f6 100644 --- a/lib/ls-sdk-react-native/example/App.js +++ b/lib/ls-sdk-react-native/example/App.js @@ -8,7 +8,7 @@ import React, { useState } from "react" import { SafeAreaView, ScrollView, StatusBar, Text, TouchableOpacity, View } from "react-native" -import { Network, getInfo, init } from "@breeztech/react-native-liquid-swap-sdk" +import { Network, getInfo, connect } from "@breeztech/react-native-liquid-swap-sdk" import { generateMnemonic } from "@dreson4/react-native-quick-bip39" import { getSecureItem, setSecureItem } from "./utils/storage" @@ -43,8 +43,8 @@ const App = () => { setSecureItem(MNEMONIC_STORE, mnemonic) } - await init(mnemonic, undefined, Network.LIQUID) - addLine("init", null) + await connect(mnemonic, undefined, Network.LIQUID) + addLine("connect", null) let walletInfo = await getInfo(false) addLine("getInfo", JSON.stringify(walletInfo))