From 81b2b02fb95aa7df92c7d1c2dd2772c5d48e172e Mon Sep 17 00:00:00 2001 From: Vishal Menon Date: Mon, 16 Dec 2024 13:53:17 +0530 Subject: [PATCH] Added validateDomain param to sync --- example/lib/test_app.dart | 2 +- ios/Classes/frb_generated.h | 3 ++- lib/src/generated/api/wallet.dart | 6 ++++-- lib/src/generated/frb_generated.dart | 16 +++++++++++----- lib/src/generated/frb_generated.io.dart | 16 +++++++++++----- macos/Classes/frb_generated.h | 3 ++- rust/src/api/wallet.rs | 16 ++++++++++------ rust/src/frb_generated.io.rs | 3 ++- rust/src/frb_generated.rs | 8 +++++++- rust/src/frb_generated.web.rs | 3 ++- test/lwk_root_test.dart | 2 +- 11 files changed, 53 insertions(+), 25 deletions(-) diff --git a/example/lib/test_app.dart b/example/lib/test_app.dart index a0acb12..50e20b4 100644 --- a/example/lib/test_app.dart +++ b/example/lib/test_app.dart @@ -53,7 +53,7 @@ class TestApp extends StatefulWidget { } static Future sync(Wallet wallet) async { - await wallet.sync(electrumUrl: electrumUrl); + await wallet.sync(electrumUrl: electrumUrl, validateDomain: true); return true; } diff --git a/ios/Classes/frb_generated.h b/ios/Classes/frb_generated.h index 2cc94cb..060b404 100644 --- a/ios/Classes/frb_generated.h +++ b/ios/Classes/frb_generated.h @@ -176,7 +176,8 @@ void frbgen_lwk_dart_wire__crate__api__wallet__wallet_signed_pset_with_extra_det void frbgen_lwk_dart_wire__crate__api__wallet__wallet_sync(int64_t port_, struct wire_cst_wallet *that, - struct wire_cst_list_prim_u_8_strict *electrum_url); + struct wire_cst_list_prim_u_8_strict *electrum_url, + bool validate_domain); void frbgen_lwk_dart_wire__crate__api__wallet__wallet_txs(int64_t port_, struct wire_cst_wallet *that); diff --git a/lib/src/generated/api/wallet.dart b/lib/src/generated/api/wallet.dart index b9e8cb2..336fd3f 100644 --- a/lib/src/generated/api/wallet.dart +++ b/lib/src/generated/api/wallet.dart @@ -97,8 +97,10 @@ class Wallet { LwkCore.instance.api.crateApiWalletWalletSignedPsetWithExtraDetails( that: this, network: network, pset: pset, mnemonic: mnemonic); - Future sync({required String electrumUrl}) => LwkCore.instance.api - .crateApiWalletWalletSync(that: this, electrumUrl: electrumUrl); + Future sync( + {required String electrumUrl, required bool validateDomain}) => + LwkCore.instance.api.crateApiWalletWalletSync( + that: this, electrumUrl: electrumUrl, validateDomain: validateDomain); Future> txs() => LwkCore.instance.api.crateApiWalletWalletTxs( that: this, diff --git a/lib/src/generated/frb_generated.dart b/lib/src/generated/frb_generated.dart index 2b2e48d..21dbc24 100644 --- a/lib/src/generated/frb_generated.dart +++ b/lib/src/generated/frb_generated.dart @@ -132,7 +132,9 @@ abstract class LwkCoreApi extends BaseApi { required String mnemonic}); Future crateApiWalletWalletSync( - {required Wallet that, required String electrumUrl}); + {required Wallet that, + required String electrumUrl, + required bool validateDomain}); Future> crateApiWalletWalletTxs({required Wallet that}); @@ -588,26 +590,30 @@ class LwkCoreApiImpl extends LwkCoreApiImplPlatform implements LwkCoreApi { @override Future crateApiWalletWalletSync( - {required Wallet that, required String electrumUrl}) { + {required Wallet that, + required String electrumUrl, + required bool validateDomain}) { return handler.executeNormal(NormalTask( callFfi: (port_) { var arg0 = cst_encode_box_autoadd_wallet(that); var arg1 = cst_encode_String(electrumUrl); - return wire.wire__crate__api__wallet__wallet_sync(port_, arg0, arg1); + var arg2 = cst_encode_bool(validateDomain); + return wire.wire__crate__api__wallet__wallet_sync( + port_, arg0, arg1, arg2); }, codec: DcoCodec( decodeSuccessData: dco_decode_unit, decodeErrorData: dco_decode_lwk_error, ), constMeta: kCrateApiWalletWalletSyncConstMeta, - argValues: [that, electrumUrl], + argValues: [that, electrumUrl, validateDomain], apiImpl: this, )); } TaskConstMeta get kCrateApiWalletWalletSyncConstMeta => const TaskConstMeta( debugName: "wallet_sync", - argNames: ["that", "electrumUrl"], + argNames: ["that", "electrumUrl", "validateDomain"], ); @override diff --git a/lib/src/generated/frb_generated.io.dart b/lib/src/generated/frb_generated.io.dart index 9d4d29e..acfaabe 100644 --- a/lib/src/generated/frb_generated.io.dart +++ b/lib/src/generated/frb_generated.io.dart @@ -997,23 +997,25 @@ class LwkCoreWire implements BaseWire { int port_, ffi.Pointer that, ffi.Pointer electrum_url, + bool validate_domain, ) { return _wire__crate__api__wallet__wallet_sync( port_, that, electrum_url, + validate_domain, ); } late final _wire__crate__api__wallet__wallet_syncPtr = _lookup< ffi.NativeFunction< ffi.Void Function(ffi.Int64, ffi.Pointer, - ffi.Pointer)>>( + ffi.Pointer, ffi.Bool)>>( 'frbgen_lwk_dart_wire__crate__api__wallet__wallet_sync'); late final _wire__crate__api__wallet__wallet_sync = _wire__crate__api__wallet__wallet_syncPtr.asFunction< void Function(int, ffi.Pointer, - ffi.Pointer)>(); + ffi.Pointer, bool)>(); void wire__crate__api__wallet__wallet_txs( int port_, @@ -1213,10 +1215,14 @@ class LwkCoreWire implements BaseWire { _dummy_method_to_enforce_bundlingPtr.asFunction(); } -typedef DartPostCObjectFnType = ffi.Pointer< - ffi.NativeFunction< - ffi.Bool Function(DartPort port_id, ffi.Pointer message)>>; +typedef DartPostCObjectFnType + = ffi.Pointer>; +typedef DartPostCObjectFnTypeFunction = ffi.Bool Function( + DartPort port_id, ffi.Pointer message); +typedef DartDartPostCObjectFnTypeFunction = bool Function( + DartDartPort port_id, ffi.Pointer message); typedef DartPort = ffi.Int64; +typedef DartDartPort = int; final class wire_cst_list_prim_u_8_strict extends ffi.Struct { external ffi.Pointer ptr; diff --git a/macos/Classes/frb_generated.h b/macos/Classes/frb_generated.h index 2cc94cb..060b404 100644 --- a/macos/Classes/frb_generated.h +++ b/macos/Classes/frb_generated.h @@ -176,7 +176,8 @@ void frbgen_lwk_dart_wire__crate__api__wallet__wallet_signed_pset_with_extra_det void frbgen_lwk_dart_wire__crate__api__wallet__wallet_sync(int64_t port_, struct wire_cst_wallet *that, - struct wire_cst_list_prim_u_8_strict *electrum_url); + struct wire_cst_list_prim_u_8_strict *electrum_url, + bool validate_domain); void frbgen_lwk_dart_wire__crate__api__wallet__wallet_txs(int64_t port_, struct wire_cst_wallet *that); diff --git a/rust/src/api/wallet.rs b/rust/src/api/wallet.rs index 7d15bbb..45d15d3 100644 --- a/rust/src/api/wallet.rs +++ b/rust/src/api/wallet.rs @@ -3,7 +3,7 @@ use lwk_signer::SwSigner; use lwk_wollet::full_scan_with_electrum_client; // use lwk_wollet::elements_miniscript::descriptor; use crate::frb_generated::RustOpaque; -use log::{info, warn}; +// use log::{info, warn}; use lwk_wollet::elements::{ pset::{ serialize::{Deserialize, Serialize}, @@ -58,15 +58,19 @@ impl Wallet { let wallet = Wallet { inner: opaque }; Ok(wallet) } - pub fn sync(&self, electrum_url: String) -> anyhow::Result<(), LwkError> { + pub fn sync( + &self, + electrum_url: String, + validate_domain: bool, + ) -> anyhow::Result<(), LwkError> { let mut electrum_client: ElectrumClient = - ElectrumClient::new(&lwk_wollet::ElectrumUrl::Tls(electrum_url, true))?; - info!("{:?}", electrum_client.capabilities()); + ElectrumClient::new(&lwk_wollet::ElectrumUrl::Tls(electrum_url, validate_domain))?; + // info!("{:?}", electrum_client.capabilities()); let mut wallet = self.get_wallet()?; match full_scan_with_electrum_client(&mut wallet, &mut electrum_client) { Ok(_) => Ok(()), Err(e) => { - warn!("{:?}", e.to_string()); + // warn!("{:?}", e.to_string()); Err(e.into()) } } @@ -257,7 +261,7 @@ mod tests { let network = Network::Mainnet; let desc = Descriptor::new_confidential(network, mnemonic.to_string()).unwrap(); let wallet = Wallet::init(network, "/tmp/lwk".to_string(), desc).unwrap(); - let _ = wallet.sync(electrum_url.clone()); + let _ = wallet.sync(electrum_url.clone(), true); let _txs = wallet.txs(); for tx in _txs.unwrap() { println!("{:?}\n{:?}\n{:?}", tx.balances, tx.timestamp, tx.height) diff --git a/rust/src/frb_generated.io.rs b/rust/src/frb_generated.io.rs index 2d4bfea..f979f9c 100644 --- a/rust/src/frb_generated.io.rs +++ b/rust/src/frb_generated.io.rs @@ -532,8 +532,9 @@ pub extern "C" fn frbgen_lwk_dart_wire__crate__api__wallet__wallet_sync( port_: i64, that: *mut wire_cst_wallet, electrum_url: *mut wire_cst_list_prim_u_8_strict, + validate_domain: bool, ) { - wire__crate__api__wallet__wallet_sync_impl(port_, that, electrum_url) + wire__crate__api__wallet__wallet_sync_impl(port_, that, electrum_url, validate_domain) } #[no_mangle] diff --git a/rust/src/frb_generated.rs b/rust/src/frb_generated.rs index a061a76..8ec51dc 100644 --- a/rust/src/frb_generated.rs +++ b/rust/src/frb_generated.rs @@ -464,6 +464,7 @@ fn wire__crate__api__wallet__wallet_sync_impl( port_: flutter_rust_bridge::for_generated::MessagePort, that: impl CstDecode, electrum_url: impl CstDecode, + validate_domain: impl CstDecode, ) { FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( flutter_rust_bridge::for_generated::TaskInfo { @@ -474,9 +475,14 @@ fn wire__crate__api__wallet__wallet_sync_impl( move || { let api_that = that.cst_decode(); let api_electrum_url = electrum_url.cst_decode(); + let api_validate_domain = validate_domain.cst_decode(); move |context| { transform_result_dco::<_, _, crate::api::error::LwkError>((move || { - let output_ok = crate::api::wallet::Wallet::sync(&api_that, api_electrum_url)?; + let output_ok = crate::api::wallet::Wallet::sync( + &api_that, + api_electrum_url, + api_validate_domain, + )?; Ok(output_ok) })()) } diff --git a/rust/src/frb_generated.web.rs b/rust/src/frb_generated.web.rs index a30fa26..fd8cff4 100644 --- a/rust/src/frb_generated.web.rs +++ b/rust/src/frb_generated.web.rs @@ -547,8 +547,9 @@ pub fn wire__crate__api__wallet__wallet_sync( port_: flutter_rust_bridge::for_generated::MessagePort, that: flutter_rust_bridge::for_generated::wasm_bindgen::JsValue, electrum_url: String, + validate_domain: bool, ) { - wire__crate__api__wallet__wallet_sync_impl(port_, that, electrum_url) + wire__crate__api__wallet__wallet_sync_impl(port_, that, electrum_url, validate_domain) } #[wasm_bindgen] diff --git a/test/lwk_root_test.dart b/test/lwk_root_test.dart index 2308410..fabf863 100644 --- a/test/lwk_root_test.dart +++ b/test/lwk_root_test.dart @@ -25,7 +25,7 @@ void main() { dbpath: dbPath, descriptor: descriptor, ); - await wallet.sync(electrumUrl: electrumUrl); + await wallet.sync(electrumUrl: electrumUrl, validateDomain: true); final address = await wallet.addressLastUnused(); print(address); // print(wallet.descriptor());