diff --git a/lib/generated/rust/api/psbt.dart b/lib/generated/rust/api/psbt.dart index 705dd66..3afd2e5 100644 --- a/lib/generated/rust/api/psbt.dart +++ b/lib/generated/rust/api/psbt.dart @@ -4,6 +4,7 @@ // ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import import '../frb_generated.dart'; +import '../lib.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; import 'structs.dart'; diff --git a/lib/generated/rust/api/structs.dart b/lib/generated/rust/api/structs.dart index d404871..c040198 100644 --- a/lib/generated/rust/api/structs.dart +++ b/lib/generated/rust/api/structs.dart @@ -4,6 +4,7 @@ // ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import import '../frb_generated.dart'; +import '../lib.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; import 'package:freezed_annotation/freezed_annotation.dart' hide protected; part 'structs.freezed.dart'; @@ -47,7 +48,7 @@ sealed class OutputSpendStatus with _$OutputSpendStatus { class OwnedOutput { final int blockheight; - final String tweak; + final U8Array32 tweak; final Amount amount; final String script; final String? label; diff --git a/lib/generated/rust/api/wallet.dart b/lib/generated/rust/api/wallet.dart index f77a987..336ed1c 100644 --- a/lib/generated/rust/api/wallet.dart +++ b/lib/generated/rust/api/wallet.dart @@ -4,6 +4,7 @@ // ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import import '../frb_generated.dart'; +import '../lib.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; import 'structs.dart'; diff --git a/lib/generated/rust/frb_generated.dart b/lib/generated/rust/frb_generated.dart index 420a44e..171799b 100644 --- a/lib/generated/rust/frb_generated.dart +++ b/lib/generated/rust/frb_generated.dart @@ -13,6 +13,7 @@ import 'dart:convert'; import 'frb_generated.dart'; import 'frb_generated.io.dart' if (dart.library.js_interop) 'frb_generated.web.dart'; +import 'lib.dart'; import 'logger.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; import 'stream.dart'; @@ -992,7 +993,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { throw Exception('unexpected arr length: expect 6 but see ${arr.length}'); return OwnedOutput( blockheight: dco_decode_u_32(arr[0]), - tweak: dco_decode_String(arr[1]), + tweak: dco_decode_u_8_array_32(arr[1]), amount: dco_decode_amount(arr[2]), script: dco_decode_String(arr[3]), label: dco_decode_opt_String(arr[4]), @@ -1129,6 +1130,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return raw as int; } + @protected + U8Array32 dco_decode_u_8_array_32(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return U8Array32(dco_decode_list_prim_u_8_strict(raw)); + } + @protected void dco_decode_unit(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs @@ -1395,7 +1402,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { OwnedOutput sse_decode_owned_output(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs var var_blockheight = sse_decode_u_32(deserializer); - var var_tweak = sse_decode_String(deserializer); + var var_tweak = sse_decode_u_8_array_32(deserializer); var var_amount = sse_decode_amount(deserializer); var var_script = sse_decode_String(deserializer); var var_label = sse_decode_opt_String(deserializer); @@ -1519,6 +1526,13 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return deserializer.buffer.getUint8(); } + @protected + U8Array32 sse_decode_u_8_array_32(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var inner = sse_decode_list_prim_u_8_strict(deserializer); + return U8Array32(inner); + } + @protected void sse_decode_unit(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -1781,7 +1795,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { void sse_encode_owned_output(OwnedOutput self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs sse_encode_u_32(self.blockheight, serializer); - sse_encode_String(self.tweak, serializer); + sse_encode_u_8_array_32(self.tweak, serializer); sse_encode_amount(self.amount, serializer); sse_encode_String(self.script, serializer); sse_encode_opt_String(self.label, serializer); @@ -1882,6 +1896,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { serializer.buffer.putUint8(self); } + @protected + void sse_encode_u_8_array_32(U8Array32 self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_list_prim_u_8_strict(self.inner, serializer); + } + @protected void sse_encode_unit(void self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs diff --git a/lib/generated/rust/frb_generated.io.dart b/lib/generated/rust/frb_generated.io.dart index 1a73696..c7c7ae1 100644 --- a/lib/generated/rust/frb_generated.io.dart +++ b/lib/generated/rust/frb_generated.io.dart @@ -12,6 +12,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:ffi' as ffi; import 'frb_generated.dart'; +import 'lib.dart'; import 'logger.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated_io.dart'; import 'stream.dart'; @@ -144,6 +145,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected int dco_decode_u_8(dynamic raw); + @protected + U8Array32 dco_decode_u_8_array_32(dynamic raw); + @protected void dco_decode_unit(dynamic raw); @@ -283,6 +287,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected int sse_decode_u_8(SseDeserializer deserializer); + @protected + U8Array32 sse_decode_u_8_array_32(SseDeserializer deserializer); + @protected void sse_decode_unit(SseDeserializer deserializer); @@ -423,6 +430,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected void sse_encode_u_8(int self, SseSerializer serializer); + @protected + void sse_encode_u_8_array_32(U8Array32 self, SseSerializer serializer); + @protected void sse_encode_unit(void self, SseSerializer serializer); diff --git a/lib/generated/rust/frb_generated.web.dart b/lib/generated/rust/frb_generated.web.dart index da12f80..9d3af0f 100644 --- a/lib/generated/rust/frb_generated.web.dart +++ b/lib/generated/rust/frb_generated.web.dart @@ -14,6 +14,7 @@ import 'api/wallet.dart'; import 'dart:async'; import 'dart:convert'; import 'frb_generated.dart'; +import 'lib.dart'; import 'logger.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated_web.dart'; import 'stream.dart'; @@ -146,6 +147,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected int dco_decode_u_8(dynamic raw); + @protected + U8Array32 dco_decode_u_8_array_32(dynamic raw); + @protected void dco_decode_unit(dynamic raw); @@ -285,6 +289,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected int sse_decode_u_8(SseDeserializer deserializer); + @protected + U8Array32 sse_decode_u_8_array_32(SseDeserializer deserializer); + @protected void sse_decode_unit(SseDeserializer deserializer); @@ -425,6 +432,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected void sse_encode_u_8(int self, SseSerializer serializer); + @protected + void sse_encode_u_8_array_32(U8Array32 self, SseSerializer serializer); + @protected void sse_encode_unit(void self, SseSerializer serializer); diff --git a/lib/generated/rust/lib.dart b/lib/generated/rust/lib.dart new file mode 100644 index 0000000..8e685c4 --- /dev/null +++ b/lib/generated/rust/lib.dart @@ -0,0 +1,22 @@ +// This file is automatically generated, so please do not edit it. +// Generated by `flutter_rust_bridge`@ 2.3.0. + +// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import + +import 'frb_generated.dart'; +import 'package:collection/collection.dart'; +import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; + +class U8Array32 extends NonGrowableListView { + static const arraySize = 32; + + @internal + Uint8List get inner => _inner; + final Uint8List _inner; + + U8Array32(this._inner) + : assert(_inner.length == arraySize), + super(_inner); + + U8Array32.init() : this(Uint8List(arraySize)); +} diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 12d2d96..f18b14c 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -234,9 +234,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "cc" @@ -756,9 +756,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.7" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ "bytes", "futures-channel", @@ -769,7 +769,6 @@ dependencies = [ "pin-project-lite", "socket2", "tokio", - "tower", "tower-service", "tracing", ] @@ -837,9 +836,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" [[package]] name = "itoa" @@ -1024,26 +1023,6 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" -[[package]] -name = "pin-project" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -1298,12 +1277,10 @@ dependencies = [ "bip39", "flutter_rust_bridge", "futures", - "hex", "lazy_static", "log", "once_cell", "pushtx", - "reqwest", "serde", "serde_json", "serde_with", @@ -1326,9 +1303,9 @@ checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustls" -version = "0.23.12" +version = "0.23.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ "once_cell", "ring", @@ -1356,9 +1333,9 @@ checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" [[package]] name = "rustls-webpki" -version = "0.102.7" +version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84678086bd54edf2b415183ed7a94d0efb049f1b646a33e22a36f3794be6ae56" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ "ring", "rustls-pki-types", @@ -1611,18 +1588,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", @@ -1724,27 +1701,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tokio", - "tower-layer", - "tower-service", -] - -[[package]] -name = "tower-layer" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" - [[package]] name = "tower-service" version = "0.3.3" @@ -1920,9 +1876,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.26.5" +version = "0.26.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bd24728e5af82c6c4ec1b66ac4844bdf8156257fccda846ec58b42cd0cdbe6a" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" dependencies = [ "rustls-pki-types", ] diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 4c383aa..9e49350 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -15,11 +15,9 @@ serde = { version = "1.0.188", features = ["derive"] } serde_json = "1.0.107" once_cell = "1.18.0" bip39 = { version = "2.0.0", features = ["rand"] } -hex = { version = "0.4.3", features = ["serde"] } serde_with = "3.6.0" log = "0.4.20" simplelog = "0.12.1" -reqwest = { version = "0.12.4", features = ["rustls-tls"], default-features = false } tokio = { version = "1", features = ["macros", "rt-multi-thread"] } pushtx = { git = "https://github.com/cygnet3/pushtx", branch = "master" } futures = "0.3" diff --git a/rust/src/api/chain.rs b/rust/src/api/chain.rs index 078743b..f946ef5 100644 --- a/rust/src/api/chain.rs +++ b/rust/src/api/chain.rs @@ -1,13 +1,7 @@ -use reqwest::Url; - -use crate::blindbit; +use sp_client::{BlindbitBackend, ChainBackend}; pub async fn get_chain_height(blindbit_url: String) -> anyhow::Result { - let url = Url::parse(&blindbit_url)?; - let blindbit_client = blindbit::BlindbitClient::new(url); + let backend = BlindbitBackend::new(blindbit_url)?; - blindbit_client - .block_height() - .await - .map(|height| height.to_consensus_u32()) + Ok(backend.block_height().await?.to_consensus_u32()) } diff --git a/rust/src/api/structs.rs b/rust/src/api/structs.rs index a336564..3041bf5 100644 --- a/rust/src/api/structs.rs +++ b/rust/src/api/structs.rs @@ -60,7 +60,7 @@ impl Amount { #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] pub struct OwnedOutput { pub blockheight: u32, - pub tweak: String, + pub tweak: [u8; 32], pub amount: Amount, pub script: String, pub label: Option, @@ -71,7 +71,7 @@ impl From for OwnedOutput { fn from(value: sp_client::OwnedOutput) -> Self { OwnedOutput { blockheight: value.blockheight.to_consensus_u32(), - tweak: hex::encode(value.tweak), + tweak: value.tweak, amount: value.amount.into(), script: value.script.to_hex_string(), label: value.label, @@ -84,7 +84,7 @@ impl From for sp_client::OwnedOutput { fn from(value: OwnedOutput) -> Self { sp_client::OwnedOutput { blockheight: Height::from_consensus(value.blockheight).unwrap(), - tweak: hex::decode(value.tweak).unwrap().try_into().unwrap(), + tweak: value.tweak, amount: value.amount.into(), script: ScriptBuf::from_hex(&value.script).unwrap(), label: value.label, diff --git a/rust/src/api/wallet.rs b/rust/src/api/wallet.rs index b2e2f6c..62b9bda 100644 --- a/rust/src/api/wallet.rs +++ b/rust/src/api/wallet.rs @@ -1,18 +1,15 @@ use std::str::FromStr; -use crate::{ - backend::BlindbitBackend, - wallet::{utils::derive_keys_from_seed, SpWallet, WalletUpdater}, -}; +use crate::wallet::{utils::derive_keys_from_seed, SpWallet, WalletUpdater}; use anyhow::{Error, Result}; -use reqwest::Url; +//use reqwest::Url; use sp_client::{ bitcoin::{ absolute::Height, secp256k1::{PublicKey, SecretKey}, Network, OutPoint, Txid, }, - ChainBackend, SpClient, SpScanner, SpendKey, + BlindbitBackend, ChainBackend, SpClient, SpScanner, SpendKey, }; use super::structs::{Amount, Recipient, WalletStatus}; @@ -97,8 +94,7 @@ pub async fn scan_to_tip( ) -> Result<()> { let wallet: SpWallet = serde_json::from_str(&encoded_wallet)?; - let blindbit_url = Url::parse(&blindbit_url)?; - let backend = BlindbitBackend::new(blindbit_url); + let backend = BlindbitBackend::new(blindbit_url)?; let dust_limit = sp_client::bitcoin::Amount::from_sat(dust_limit); diff --git a/rust/src/backend/backend.rs b/rust/src/backend/backend.rs deleted file mode 100644 index 03066f4..0000000 --- a/rust/src/backend/backend.rs +++ /dev/null @@ -1,83 +0,0 @@ -use std::{ops::RangeInclusive, pin::Pin, sync::Arc}; - -use async_trait::async_trait; -use futures::{stream, Stream, StreamExt}; -use reqwest::Url; -use sp_client::{ - bitcoin::{absolute::Height, Amount}, - BlockData, ChainBackend, SpentIndexData, UtxoData, -}; - -use anyhow::Result; - -use crate::blindbit::BlindbitClient; - -const CONCURRENT_FILTER_REQUESTS: usize = 200; - -pub struct BlindbitBackend { - client: BlindbitClient, -} - -impl BlindbitBackend { - pub fn new(host_url: Url) -> Self { - Self { - client: BlindbitClient::new(host_url), - } - } -} - -#[async_trait] -impl ChainBackend for BlindbitBackend { - /// High-level function to get block data for a range of blocks. - /// Block data includes all the information needed to determine if a block is relevant for scanning, - /// but does not include utxos, or spent index. - /// These need to be fetched separately afterwards, if it is determined this block is relevant. - fn get_block_data_for_range( - &self, - range: RangeInclusive, - dust_limit: Amount, - ) -> Pin> + Send>> { - let client = Arc::new(self.client.clone()); - - let res = stream::iter(range) - .map(move |n| { - let client = client.clone(); - - async move { - let blkheight = Height::from_consensus(n)?; - let tweaks = client.tweak_index(blkheight, dust_limit).await?; - let new_utxo_filter = client.filter_new_utxos(blkheight).await?; - let spent_filter = client.filter_spent(blkheight).await?; - let blkhash = new_utxo_filter.block_hash; - Ok(BlockData { - blkheight, - blkhash, - tweaks, - new_utxo_filter: new_utxo_filter.into(), - spent_filter: spent_filter.into(), - }) - } - }) - .buffered(CONCURRENT_FILTER_REQUESTS); - - Box::pin(res) - } - - async fn spent_index(&self, block_height: Height) -> Result { - self.client.spent_index(block_height).await.map(Into::into) - } - - async fn utxos(&self, block_height: Height) -> Result> { - Ok(self - .client - .utxos(block_height) - .await? - .into_iter() - .map(Into::into) - .collect()) - } - - async fn block_height(&self) -> Result { - self.client.block_height().await - } -} diff --git a/rust/src/backend/mod.rs b/rust/src/backend/mod.rs deleted file mode 100644 index e48b365..0000000 --- a/rust/src/backend/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod backend; - -pub use backend::BlindbitBackend; diff --git a/rust/src/blindbit/client.rs b/rust/src/blindbit/client.rs deleted file mode 100644 index 1b021a3..0000000 --- a/rust/src/blindbit/client.rs +++ /dev/null @@ -1,105 +0,0 @@ -#![allow(dead_code)] -use std::time::Duration; - -use reqwest::{Client, Url}; -use sp_client::bitcoin::{absolute::Height, secp256k1::PublicKey, Amount}; - -use anyhow::Result; - -use super::{BlockHeightResponse, FilterResponse, SpentIndexResponse, UtxoResponse}; - -#[derive(Clone)] -pub struct BlindbitClient { - client: Client, - host_url: Url, -} - -impl BlindbitClient { - pub fn new(mut host_url: Url) -> Self { - let client = reqwest::Client::new(); - - // we need a trailing slash, if not present we append it - if !host_url.path().ends_with('/') { - host_url.set_path(&format!("{}/", host_url.path())); - } - - BlindbitClient { client, host_url } - } - pub async fn block_height(&self) -> Result { - let url = self.host_url.join("block-height")?; - - let res = self - .client - .get(url) - .timeout(Duration::from_secs(5)) - .send() - .await?; - let blkheight: BlockHeightResponse = serde_json::from_str(&res.text().await?)?; - Ok(blkheight.block_height) - } - - pub async fn tweaks(&self, block_height: Height) -> Result> { - let url = self.host_url.join(&format!("tweaks/{}", block_height))?; - - let res = self.client.get(url).send().await?; - Ok(serde_json::from_str(&res.text().await?)?) - } - - pub async fn tweak_index( - &self, - block_height: Height, - dust_limit: Amount, - ) -> Result> { - let url = self - .host_url - .join(&format!("tweak-index/{}", block_height))?; - - let res = self - .client - .get(url) - .query(&[("dustLimit", format!("{}", dust_limit.to_sat()))]) - .send() - .await?; - Ok(serde_json::from_str(&res.text().await?)?) - } - - pub async fn utxos(&self, block_height: Height) -> Result> { - let url = self.host_url.join(&format!("utxos/{}", block_height))?; - let res = self.client.get(url).send().await?; - - Ok(serde_json::from_str(&res.text().await?)?) - } - - pub async fn spent_index(&self, block_height: Height) -> Result { - let url = self - .host_url - .join(&format!("spent-index/{}", block_height))?; - let res = self.client.get(url).send().await?; - - Ok(serde_json::from_str(&res.text().await?)?) - } - - pub async fn filter_new_utxos(&self, block_height: Height) -> Result { - let url = self - .host_url - .join(&format!("filter/new-utxos/{}", block_height))?; - - let res = self.client.get(url).send().await?; - - Ok(serde_json::from_str(&res.text().await?)?) - } - - pub async fn filter_spent(&self, block_height: Height) -> Result { - let url = self - .host_url - .join(&format!("filter/spent/{}", block_height))?; - - let res = self.client.get(url).send().await?; - - Ok(serde_json::from_str(&res.text().await?)?) - } - - pub async fn forward_tx(&self) { - // not needed - } -} diff --git a/rust/src/blindbit/mod.rs b/rust/src/blindbit/mod.rs deleted file mode 100644 index bf3b91d..0000000 --- a/rust/src/blindbit/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -mod client; -mod structs; - -pub use structs::*; - -pub use client::*; diff --git a/rust/src/blindbit/structs.rs b/rust/src/blindbit/structs.rs deleted file mode 100644 index 35ae915..0000000 --- a/rust/src/blindbit/structs.rs +++ /dev/null @@ -1,72 +0,0 @@ -use serde::Deserialize; -use sp_client::{ - bitcoin::{absolute::Height, Amount, BlockHash, ScriptBuf, Txid}, - FilterData, SpentIndexData, UtxoData, -}; - -#[derive(Debug, Deserialize)] -pub struct BlockHeightResponse { - pub block_height: Height, -} - -#[derive(Debug, Deserialize)] -pub struct UtxoResponse { - pub txid: Txid, - pub vout: u32, - pub value: Amount, - pub scriptpubkey: ScriptBuf, - pub block_height: Height, - pub block_hash: BlockHash, - pub timestamp: i32, - pub spent: bool, -} - -impl From for UtxoData { - fn from(value: UtxoResponse) -> Self { - Self { - txid: value.txid, - vout: value.vout, - value: value.value, - scriptpubkey: value.scriptpubkey, - spent: value.spent, - } - } -} - -#[derive(Debug, Deserialize)] -pub struct SpentIndexResponse { - pub block_hash: BlockHash, - pub data: Vec, -} - -impl From for SpentIndexData { - fn from(value: SpentIndexResponse) -> Self { - Self { - data: value.data.into_iter().map(|x| x.hex).collect(), - } - } -} - -#[derive(Deserialize, Debug)] -#[serde(transparent)] -pub struct MyHex { - #[serde(with = "hex::serde")] - pub hex: Vec, -} - -#[derive(Debug, Deserialize)] -pub struct FilterResponse { - pub block_hash: BlockHash, - pub block_height: Height, - pub data: MyHex, - pub filter_type: i32, -} - -impl From for FilterData { - fn from(value: FilterResponse) -> Self { - Self { - block_hash: value.block_hash, - data: value.data.hex, - } - } -} diff --git a/rust/src/frb_generated.rs b/rust/src/frb_generated.rs index 95141c7..06a28a6 100644 --- a/rust/src/frb_generated.rs +++ b/rust/src/frb_generated.rs @@ -1112,7 +1112,7 @@ impl SseDecode for crate::api::structs::OwnedOutput { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { let mut var_blockheight = ::sse_decode(deserializer); - let mut var_tweak = ::sse_decode(deserializer); + let mut var_tweak = <[u8; 32]>::sse_decode(deserializer); let mut var_amount = ::sse_decode(deserializer); let mut var_script = ::sse_decode(deserializer); let mut var_label = >::sse_decode(deserializer); @@ -1260,6 +1260,14 @@ impl SseDecode for u8 { } } +impl SseDecode for [u8; 32] { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut inner = >::sse_decode(deserializer); + return flutter_rust_bridge::for_generated::from_vec_to_array(inner); + } +} + impl SseDecode for () { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {} @@ -1831,7 +1839,7 @@ impl SseEncode for crate::api::structs::OwnedOutput { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { ::sse_encode(self.blockheight, serializer); - ::sse_encode(self.tweak, serializer); + <[u8; 32]>::sse_encode(self.tweak, serializer); ::sse_encode(self.amount, serializer); ::sse_encode(self.script, serializer); >::sse_encode(self.label, serializer); @@ -1940,6 +1948,19 @@ impl SseEncode for u8 { } } +impl SseEncode for [u8; 32] { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + >::sse_encode( + { + let boxed: Box<[_]> = Box::new(self); + boxed.into_vec() + }, + serializer, + ); + } +} + impl SseEncode for () { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {} diff --git a/rust/src/lib.rs b/rust/src/lib.rs index d2bcf70..32f2609 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1,6 +1,4 @@ pub mod api; -mod backend; -mod blindbit; mod frb_generated; /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */ mod logger; mod stream;