Skip to content

Commit

Permalink
feat: add blockchain_details to GetInfoResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
hydra-yse committed Dec 27, 2024
1 parent 4068be2 commit 812b31f
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,11 @@ typedef struct wire_cst_list_refundable_swap {
int32_t len;
} wire_cst_list_refundable_swap;

typedef struct wire_cst_blockchain_details {
uint32_t liquid_tip;
uint32_t bitcoin_tip;
} wire_cst_blockchain_details;

typedef struct wire_cst_check_message_response {
bool is_valid;
} wire_cst_check_message_response;
Expand All @@ -698,6 +703,7 @@ typedef struct wire_cst_get_info_response {
uint64_t pending_receive_sat;
struct wire_cst_list_prim_u_8_strict *fingerprint;
struct wire_cst_list_prim_u_8_strict *pubkey;
struct wire_cst_blockchain_details blockchain_details;
} wire_cst_get_info_response;

typedef struct wire_cst_InputType_BitcoinAddress {
Expand Down
6 changes: 6 additions & 0 deletions lib/bindings/src/breez_sdk_liquid.udl
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,18 @@ dictionary ConnectWithSignerRequest {
Config config;
};

dictionary BlockchainDetails {
u32 liquid_tip;
u32 bitcoin_tip;
};

dictionary GetInfoResponse {
u64 balance_sat;
u64 pending_send_sat;
u64 pending_receive_sat;
string fingerprint;
string pubkey;
BlockchainDetails blockchain_details;
};

dictionary SignMessageRequest {
Expand Down
76 changes: 76 additions & 0 deletions lib/core/src/frb_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2306,6 +2306,18 @@ impl SseDecode for crate::bindings::BitcoinAddressData {
}
}

impl SseDecode for crate::model::BlockchainDetails {
// 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_liquidTip = <u32>::sse_decode(deserializer);
let mut var_bitcoinTip = <u32>::sse_decode(deserializer);
return crate::model::BlockchainDetails {
liquid_tip: var_liquidTip,
bitcoin_tip: var_bitcoinTip,
};
}
}

impl SseDecode for bool {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
Expand Down Expand Up @@ -2472,12 +2484,14 @@ impl SseDecode for crate::model::GetInfoResponse {
let mut var_pendingReceiveSat = <u64>::sse_decode(deserializer);
let mut var_fingerprint = <String>::sse_decode(deserializer);
let mut var_pubkey = <String>::sse_decode(deserializer);
let mut var_blockchainDetails = <crate::model::BlockchainDetails>::sse_decode(deserializer);
return crate::model::GetInfoResponse {
balance_sat: var_balanceSat,
pending_send_sat: var_pendingSendSat,
pending_receive_sat: var_pendingReceiveSat,
fingerprint: var_fingerprint,
pubkey: var_pubkey,
blockchain_details: var_blockchainDetails,
};
}
}
Expand Down Expand Up @@ -4579,6 +4593,27 @@ impl flutter_rust_bridge::IntoIntoDart<FrbWrapper<crate::bindings::BitcoinAddres
}
}
// Codec=Dco (DartCObject based), see doc to use other codecs
impl flutter_rust_bridge::IntoDart for crate::model::BlockchainDetails {
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
[
self.liquid_tip.into_into_dart().into_dart(),
self.bitcoin_tip.into_into_dart().into_dart(),
]
.into_dart()
}
}
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive
for crate::model::BlockchainDetails
{
}
impl flutter_rust_bridge::IntoIntoDart<crate::model::BlockchainDetails>
for crate::model::BlockchainDetails
{
fn into_into_dart(self) -> crate::model::BlockchainDetails {
self
}
}
// Codec=Dco (DartCObject based), see doc to use other codecs
impl flutter_rust_bridge::IntoDart for crate::model::BuyBitcoinProvider {
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
match self {
Expand Down Expand Up @@ -4785,6 +4820,7 @@ impl flutter_rust_bridge::IntoDart for crate::model::GetInfoResponse {
self.pending_receive_sat.into_into_dart().into_dart(),
self.fingerprint.into_into_dart().into_dart(),
self.pubkey.into_into_dart().into_dart(),
self.blockchain_details.into_into_dart().into_dart(),
]
.into_dart()
}
Expand Down Expand Up @@ -6727,6 +6763,14 @@ impl SseEncode for crate::bindings::BitcoinAddressData {
}
}

impl SseEncode for crate::model::BlockchainDetails {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
<u32>::sse_encode(self.liquid_tip, serializer);
<u32>::sse_encode(self.bitcoin_tip, serializer);
}
}

impl SseEncode for bool {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
Expand Down Expand Up @@ -6848,6 +6892,7 @@ impl SseEncode for crate::model::GetInfoResponse {
<u64>::sse_encode(self.pending_receive_sat, serializer);
<String>::sse_encode(self.fingerprint, serializer);
<String>::sse_encode(self.pubkey, serializer);
<crate::model::BlockchainDetails>::sse_encode(self.blockchain_details, serializer);
}
}

Expand Down Expand Up @@ -8542,6 +8587,15 @@ mod io {
}
}
}
impl CstDecode<crate::model::BlockchainDetails> for wire_cst_blockchain_details {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> crate::model::BlockchainDetails {
crate::model::BlockchainDetails {
liquid_tip: self.liquid_tip.cst_decode(),
bitcoin_tip: self.bitcoin_tip.cst_decode(),
}
}
}
impl CstDecode<crate::bindings::AesSuccessActionData> for *mut wire_cst_aes_success_action_data {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> crate::bindings::AesSuccessActionData {
Expand Down Expand Up @@ -9009,6 +9063,7 @@ mod io {
pending_receive_sat: self.pending_receive_sat.cst_decode(),
fingerprint: self.fingerprint.cst_decode(),
pubkey: self.pubkey.cst_decode(),
blockchain_details: self.blockchain_details.cst_decode(),
}
}
}
Expand Down Expand Up @@ -10391,6 +10446,19 @@ mod io {
Self::new_with_null_ptr()
}
}
impl NewWithNullPtr for wire_cst_blockchain_details {
fn new_with_null_ptr() -> Self {
Self {
liquid_tip: Default::default(),
bitcoin_tip: Default::default(),
}
}
}
impl Default for wire_cst_blockchain_details {
fn default() -> Self {
Self::new_with_null_ptr()
}
}
impl NewWithNullPtr for wire_cst_buy_bitcoin_request {
fn new_with_null_ptr() -> Self {
Self {
Expand Down Expand Up @@ -10520,6 +10588,7 @@ mod io {
pending_receive_sat: Default::default(),
fingerprint: core::ptr::null_mut(),
pubkey: core::ptr::null_mut(),
blockchain_details: Default::default(),
}
}
}
Expand Down Expand Up @@ -12493,6 +12562,12 @@ mod io {
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_blockchain_details {
liquid_tip: u32,
bitcoin_tip: u32,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_buy_bitcoin_request {
prepare_response: wire_cst_prepare_buy_bitcoin_response,
redirect_url: *mut wire_cst_list_prim_u_8_strict,
Expand Down Expand Up @@ -12564,6 +12639,7 @@ mod io {
pending_receive_sat: u64,
fingerprint: *mut wire_cst_list_prim_u_8_strict,
pubkey: *mut wire_cst_list_prim_u_8_strict,
blockchain_details: wire_cst_blockchain_details,
}
#[repr(C)]
#[derive(Clone, Copy)]
Expand Down
9 changes: 9 additions & 0 deletions lib/core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,12 @@ pub struct RefundResponse {
pub refund_tx_id: String,
}

#[derive(Debug, Serialize, Deserialize, Default)]
pub struct BlockchainDetails {
pub liquid_tip: u32,
pub bitcoin_tip: u32,
}

/// Returned when calling [crate::sdk::LiquidSdk::get_info].
#[derive(Debug, Serialize, Deserialize)]
pub struct GetInfoResponse {
Expand All @@ -542,6 +548,9 @@ pub struct GetInfoResponse {
pub fingerprint: String,
/// The wallet's pubkey. Used to verify signed messages.
pub pubkey: String,
#[serde(default)]
/// Details regarding onchain data, such as the current Liquid/Bitcoin tip
pub blockchain_details: BlockchainDetails,
}

/// An argument when calling [crate::sdk::LiquidSdk::sign_message].
Expand Down
7 changes: 7 additions & 0 deletions lib/core/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2493,12 +2493,19 @@ impl LiquidSdk {
}
}

let liquid_tip = self.liquid_chain_service.lock().await.tip().await?.height;
let bitcoin_tip = self.bitcoin_chain_service.lock().await.tip()?.height as u32;

let info_response = GetInfoResponse {
balance_sat: wallet_amount_sat as u64,
pending_send_sat,
pending_receive_sat,
fingerprint: self.onchain_wallet.fingerprint()?,
pubkey: self.onchain_wallet.pubkey()?,
blockchain_details: BlockchainDetails {
liquid_tip,
bitcoin_tip,
},
};
self.persister.set_wallet_info(&info_response)
}
Expand Down
34 changes: 32 additions & 2 deletions packages/dart/lib/src/frb_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,17 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
);
}

@protected
BlockchainDetails dco_decode_blockchain_details(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
final arr = raw as List<dynamic>;
if (arr.length != 2) throw Exception('unexpected arr length: expect 2 but see ${arr.length}');
return BlockchainDetails(
liquidTip: dco_decode_u_32(arr[0]),
bitcoinTip: dco_decode_u_32(arr[1]),
);
}

@protected
bool dco_decode_bool(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
Expand Down Expand Up @@ -1777,13 +1788,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
GetInfoResponse dco_decode_get_info_response(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
final arr = raw as List<dynamic>;
if (arr.length != 5) throw Exception('unexpected arr length: expect 5 but see ${arr.length}');
if (arr.length != 6) throw Exception('unexpected arr length: expect 6 but see ${arr.length}');
return GetInfoResponse(
balanceSat: dco_decode_u_64(arr[0]),
pendingSendSat: dco_decode_u_64(arr[1]),
pendingReceiveSat: dco_decode_u_64(arr[2]),
fingerprint: dco_decode_String(arr[3]),
pubkey: dco_decode_String(arr[4]),
blockchainDetails: dco_decode_blockchain_details(arr[5]),
);
}

Expand Down Expand Up @@ -3310,6 +3322,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
message: var_message);
}

@protected
BlockchainDetails sse_decode_blockchain_details(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
var var_liquidTip = sse_decode_u_32(deserializer);
var var_bitcoinTip = sse_decode_u_32(deserializer);
return BlockchainDetails(liquidTip: var_liquidTip, bitcoinTip: var_bitcoinTip);
}

@protected
bool sse_decode_bool(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
Expand Down Expand Up @@ -3747,12 +3767,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
var var_pendingReceiveSat = sse_decode_u_64(deserializer);
var var_fingerprint = sse_decode_String(deserializer);
var var_pubkey = sse_decode_String(deserializer);
var var_blockchainDetails = sse_decode_blockchain_details(deserializer);
return GetInfoResponse(
balanceSat: var_balanceSat,
pendingSendSat: var_pendingSendSat,
pendingReceiveSat: var_pendingReceiveSat,
fingerprint: var_fingerprint,
pubkey: var_pubkey);
pubkey: var_pubkey,
blockchainDetails: var_blockchainDetails);
}

@protected
Expand Down Expand Up @@ -5465,6 +5487,13 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_opt_String(self.message, serializer);
}

@protected
void sse_encode_blockchain_details(BlockchainDetails self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
sse_encode_u_32(self.liquidTip, serializer);
sse_encode_u_32(self.bitcoinTip, serializer);
}

@protected
void sse_encode_bool(bool self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
Expand Down Expand Up @@ -5879,6 +5908,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_u_64(self.pendingReceiveSat, serializer);
sse_encode_String(self.fingerprint, serializer);
sse_encode_String(self.pubkey, serializer);
sse_encode_blockchain_details(self.blockchainDetails, serializer);
}

@protected
Expand Down
Loading

0 comments on commit 812b31f

Please sign in to comment.