Skip to content

Commit

Permalink
Added validateDomain param to sync
Browse files Browse the repository at this point in the history
  • Loading branch information
i5hi committed Dec 16, 2024
1 parent e36b5cb commit 81b2b02
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 25 deletions.
2 changes: 1 addition & 1 deletion example/lib/test_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TestApp extends StatefulWidget {
}

static Future<bool> sync(Wallet wallet) async {
await wallet.sync(electrumUrl: electrumUrl);
await wallet.sync(electrumUrl: electrumUrl, validateDomain: true);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion ios/Classes/frb_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions lib/src/generated/api/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ class Wallet {
LwkCore.instance.api.crateApiWalletWalletSignedPsetWithExtraDetails(
that: this, network: network, pset: pset, mnemonic: mnemonic);

Future<void> sync({required String electrumUrl}) => LwkCore.instance.api
.crateApiWalletWalletSync(that: this, electrumUrl: electrumUrl);
Future<void> sync(
{required String electrumUrl, required bool validateDomain}) =>
LwkCore.instance.api.crateApiWalletWalletSync(
that: this, electrumUrl: electrumUrl, validateDomain: validateDomain);

Future<List<Tx>> txs() => LwkCore.instance.api.crateApiWalletWalletTxs(
that: this,
Expand Down
16 changes: 11 additions & 5 deletions lib/src/generated/frb_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ abstract class LwkCoreApi extends BaseApi {
required String mnemonic});

Future<void> crateApiWalletWalletSync(
{required Wallet that, required String electrumUrl});
{required Wallet that,
required String electrumUrl,
required bool validateDomain});

Future<List<Tx>> crateApiWalletWalletTxs({required Wallet that});

Expand Down Expand Up @@ -588,26 +590,30 @@ class LwkCoreApiImpl extends LwkCoreApiImplPlatform implements LwkCoreApi {

@override
Future<void> 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
Expand Down
16 changes: 11 additions & 5 deletions lib/src/generated/frb_generated.io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -997,23 +997,25 @@ class LwkCoreWire implements BaseWire {
int port_,
ffi.Pointer<wire_cst_wallet> that,
ffi.Pointer<wire_cst_list_prim_u_8_strict> 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<wire_cst_wallet>,
ffi.Pointer<wire_cst_list_prim_u_8_strict>)>>(
ffi.Pointer<wire_cst_list_prim_u_8_strict>, 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<wire_cst_wallet>,
ffi.Pointer<wire_cst_list_prim_u_8_strict>)>();
ffi.Pointer<wire_cst_list_prim_u_8_strict>, bool)>();

void wire__crate__api__wallet__wallet_txs(
int port_,
Expand Down Expand Up @@ -1213,10 +1215,14 @@ class LwkCoreWire implements BaseWire {
_dummy_method_to_enforce_bundlingPtr.asFunction<int Function()>();
}

typedef DartPostCObjectFnType = ffi.Pointer<
ffi.NativeFunction<
ffi.Bool Function(DartPort port_id, ffi.Pointer<ffi.Void> message)>>;
typedef DartPostCObjectFnType
= ffi.Pointer<ffi.NativeFunction<DartPostCObjectFnTypeFunction>>;
typedef DartPostCObjectFnTypeFunction = ffi.Bool Function(
DartPort port_id, ffi.Pointer<ffi.Void> message);
typedef DartDartPostCObjectFnTypeFunction = bool Function(
DartDartPort port_id, ffi.Pointer<ffi.Void> message);
typedef DartPort = ffi.Int64;
typedef DartDartPort = int;

final class wire_cst_list_prim_u_8_strict extends ffi.Struct {
external ffi.Pointer<ffi.Uint8> ptr;
Expand Down
3 changes: 2 additions & 1 deletion macos/Classes/frb_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 10 additions & 6 deletions rust/src/api/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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())
}
}
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion rust/src/frb_generated.io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 7 additions & 1 deletion rust/src/frb_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ fn wire__crate__api__wallet__wallet_sync_impl(
port_: flutter_rust_bridge::for_generated::MessagePort,
that: impl CstDecode<crate::api::wallet::Wallet>,
electrum_url: impl CstDecode<String>,
validate_domain: impl CstDecode<bool>,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::DcoCodec, _, _>(
flutter_rust_bridge::for_generated::TaskInfo {
Expand All @@ -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)
})())
}
Expand Down
3 changes: 2 additions & 1 deletion rust/src/frb_generated.web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion test/lwk_root_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 81b2b02

Please sign in to comment.