Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename init() to connect() #119

Merged
merged 6 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub use uniffi_bindgen::bindings::kotlin::gen_kotlin::*;
use crate::generator::RNConfig;

static IGNORED_FUNCTIONS: Lazy<HashSet<String>> = 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()))
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::generator::RNConfig;
pub use uniffi_bindgen::bindings::swift::gen_swift::*;

static IGNORED_FUNCTIONS: Lazy<HashSet<String>> = 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()))
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static KEYWORDS: Lazy<HashSet<String>> = Lazy::new(|| {
});

static IGNORED_FUNCTIONS: Lazy<HashSet<String>> = Lazy::new(|| {
let list: Vec<&str> = vec!["init"];
let list: Vec<&str> = vec![];
HashSet::from_iter(list.into_iter().map(|s| s.to_string()))
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@

export const init = async (mnemonic: string, dataDir: string = "", network: Network): Promise<void> => {
const response = await LiquidSwapSDK.initBindingWallet(mnemonic, dataDir, network)
return response
}
4 changes: 2 additions & 2 deletions lib/ls-sdk-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ impl From<anyhow::Error> for LsSdkError {
}
}

pub fn init(
pub fn connect(
mnemonic: String,
data_dir: Option<String>,
network: Network,
) -> Result<Arc<BindingWallet>, 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 }))
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ls-sdk-bindings/src/ls_sdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/ls-sdk-bindings/tests/bindings/test_ls_sdk.kts
Original file line number Diff line number Diff line change
@@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion lib/ls-sdk-bindings/tests/bindings/test_ls_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/ls-sdk-bindings/tests/bindings/test_ls_sdk.swift
Original file line number Diff line number Diff line change
@@ -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");
2 changes: 1 addition & 1 deletion lib/ls-sdk-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 4 additions & 2 deletions lib/ls-sdk-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -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),
Expand Down
6 changes: 5 additions & 1 deletion lib/ls-sdk-core/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ pub struct Wallet {
}

impl Wallet {
pub fn init(mnemonic: &str, data_dir: Option<String>, network: Network) -> Result<Arc<Wallet>> {
pub fn connect(
mnemonic: &str,
data_dir: Option<String>,
network: Network,
) -> Result<Arc<Wallet>> {
let is_mainnet = network == Network::Liquid;
let signer = SwSigner::new(mnemonic, is_mainnet)?;
let descriptor = Wallet::get_descriptor(&signer, network)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class LiquidSwapSDKModule(reactContext: ReactApplicationContext) : ReactContextB
fun removeListeners(count: Int) {}

@ReactMethod
fun initBindingWallet(
fun connect(
mnemonic: String,
dataDir: String,
network: String,
Expand All @@ -55,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)
Expand Down
6 changes: 3 additions & 3 deletions lib/ls-sdk-react-native/example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@interface RCT_EXTERN_MODULE(RNLiquidSwapSDK, RCTEventEmitter)

RCT_EXTERN_METHOD(
initBindingWallet: (NSString*)mnemonic
connect: (NSString*)mnemonic
dataDir: (NSString*)dataDir
network: (NSString*)network
resolve: (RCTPromiseResolveBlock)resolve
Expand Down
6 changes: 3 additions & 3 deletions lib/ls-sdk-react-native/ios/RNLiquidSwapSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class RNLiquidSwapSDK: RCTEventEmitter {
throw LsSdkError.Generic(message: "Not initialized")
}

@objc(initBindingWallet:dataDir:network:resolve:reject:)
func initBindingWallet(_ mnemonic: String, dataDir: String, network: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
@objc(connect:dataDir:network:resolve:reject:)
func connect(_ mnemonic: String, dataDir: String, network: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
if bindingWallet != nil {
reject("Generic", "Already initialized", nil)
return
Expand All @@ -61,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)
Expand Down
5 changes: 3 additions & 2 deletions lib/ls-sdk-react-native/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ export enum Network {
LIQUID_TESTNET = "liquidTestnet"
}

export const init = async (mnemonic: string, dataDir: string = "", network: Network): Promise<void> => {
const response = await LiquidSwapSDK.initBindingWallet(mnemonic, dataDir, network)
export const connect = async (mnemonic: string, dataDir: string = "", network: Network): Promise<BindingWallet> => {
const response = await LiquidSwapSDK.connect(mnemonic, dataDir, network)
return response
}


export const getInfo = async (withScan: boolean): Promise<WalletInfo> => {
const response = await LiquidSwapSDK.getInfo(withScan)
return response
Expand Down
Loading