Skip to content

Commit

Permalink
GetInfoResponse: add fingerprint (#532)
Browse files Browse the repository at this point in the history
* GetInfoResponse: add fingerprint

* Re-generate dart ffi with `just ffigen`

* Re-generate dart ffi with `just gen`
  • Loading branch information
ok300 authored Oct 17, 2024
1 parent b5a1d95 commit cbe835b
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ typedef struct wire_cst_get_info_response {
uint64_t balance_sat;
uint64_t pending_send_sat;
uint64_t pending_receive_sat;
struct wire_cst_list_prim_u_8_strict *fingerprint;
struct wire_cst_list_prim_u_8_strict *pubkey;
} wire_cst_get_info_response;

Expand Down
1 change: 1 addition & 0 deletions lib/bindings/src/breez_sdk_liquid.udl
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ dictionary GetInfoResponse {
u64 balance_sat;
u64 pending_send_sat;
u64 pending_receive_sat;
string fingerprint;
string pubkey;
};

Expand Down
7 changes: 7 additions & 0 deletions lib/core/src/frb_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2362,11 +2362,13 @@ impl SseDecode for crate::model::GetInfoResponse {
let mut var_balanceSat = <u64>::sse_decode(deserializer);
let mut var_pendingSendSat = <u64>::sse_decode(deserializer);
let mut var_pendingReceiveSat = <u64>::sse_decode(deserializer);
let mut var_fingerprint = <String>::sse_decode(deserializer);
let mut var_pubkey = <String>::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,
};
}
Expand Down Expand Up @@ -4400,6 +4402,7 @@ impl flutter_rust_bridge::IntoDart for crate::model::GetInfoResponse {
self.balance_sat.into_into_dart().into_dart(),
self.pending_send_sat.into_into_dart().into_dart(),
self.pending_receive_sat.into_into_dart().into_dart(),
self.fingerprint.into_into_dart().into_dart(),
self.pubkey.into_into_dart().into_dart(),
]
.into_dart()
Expand Down Expand Up @@ -6334,6 +6337,7 @@ impl SseEncode for crate::model::GetInfoResponse {
<u64>::sse_encode(self.balance_sat, serializer);
<u64>::sse_encode(self.pending_send_sat, serializer);
<u64>::sse_encode(self.pending_receive_sat, serializer);
<String>::sse_encode(self.fingerprint, serializer);
<String>::sse_encode(self.pubkey, serializer);
}
}
Expand Down Expand Up @@ -8256,6 +8260,7 @@ mod io {
balance_sat: self.balance_sat.cst_decode(),
pending_send_sat: self.pending_send_sat.cst_decode(),
pending_receive_sat: self.pending_receive_sat.cst_decode(),
fingerprint: self.fingerprint.cst_decode(),
pubkey: self.pubkey.cst_decode(),
}
}
Expand Down Expand Up @@ -9628,6 +9633,7 @@ mod io {
balance_sat: Default::default(),
pending_send_sat: Default::default(),
pending_receive_sat: Default::default(),
fingerprint: core::ptr::null_mut(),
pubkey: core::ptr::null_mut(),
}
}
Expand Down Expand Up @@ -11495,6 +11501,7 @@ mod io {
balance_sat: u64,
pending_send_sat: u64,
pending_receive_sat: u64,
fingerprint: *mut wire_cst_list_prim_u_8_strict,
pubkey: *mut wire_cst_list_prim_u_8_strict,
}
#[repr(C)]
Expand Down
3 changes: 3 additions & 0 deletions lib/core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ pub struct GetInfoResponse {
pub pending_send_sat: u64,
/// Incoming amount that is pending from ongoing Receive swaps
pub pending_receive_sat: u64,
/// The wallet's fingerprint. It is used to build the working directory in [Config::get_wallet_working_dir].
pub fingerprint: String,
/// The wallet's pubkey. Used to verify signed messages.
pub pubkey: String,
}

Expand Down
1 change: 1 addition & 0 deletions lib/core/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ impl LiquidSdk {
balance_sat: confirmed_received_sat - confirmed_sent_sat - pending_send_sat,
pending_send_sat,
pending_receive_sat,
fingerprint: self.onchain_wallet.fingerprint(),
pubkey: self.onchain_wallet.pubkey(),
})
}
Expand Down
4 changes: 4 additions & 0 deletions lib/core/src/test_utils/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ impl OnchainWallet for MockWallet {
unimplemented!()
}

fn fingerprint(&self) -> String {
unimplemented!()
}

fn pubkey(&self) -> String {
unimplemented!()
}
Expand Down
7 changes: 6 additions & 1 deletion lib/core/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use lwk_common::Signer;
use lwk_common::{singlesig_desc, Singlesig};
use lwk_signer::{AnySigner, SwSigner};
use lwk_wollet::{
elements::{Address, Transaction},
elements::{hex::ToHex, Address, Transaction},
ElectrumClient, ElectrumUrl, ElementsNetwork, FsPersister, Tip, WalletTx, Wollet,
WolletDescriptor,
};
Expand Down Expand Up @@ -61,6 +61,7 @@ pub trait OnchainWallet: Send + Sync {

/// Get the public key of the wallet
fn pubkey(&self) -> String;
fn fingerprint(&self) -> String;

fn derive_bip32_key(&self, path: Vec<ChildNumber>) -> Result<ExtendedPrivKey, PaymentError>;

Expand Down Expand Up @@ -262,4 +263,8 @@ impl OnchainWallet for LiquidOnchainWallet {
let pk = PublicKey::from_str(pubkey)?;
Ok(verify(message.as_bytes(), signature, &pk))
}

fn fingerprint(&self) -> String {
self.lwk_signer.fingerprint().to_hex()
}
}
8 changes: 6 additions & 2 deletions packages/dart/lib/src/frb_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1708,12 +1708,13 @@ 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 != 4) throw Exception('unexpected arr length: expect 4 but see ${arr.length}');
if (arr.length != 5) throw Exception('unexpected arr length: expect 5 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]),
pubkey: dco_decode_String(arr[3]),
fingerprint: dco_decode_String(arr[3]),
pubkey: dco_decode_String(arr[4]),
);
}

Expand Down Expand Up @@ -3486,11 +3487,13 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
var var_balanceSat = sse_decode_u_64(deserializer);
var var_pendingSendSat = sse_decode_u_64(deserializer);
var var_pendingReceiveSat = sse_decode_u_64(deserializer);
var var_fingerprint = sse_decode_String(deserializer);
var var_pubkey = sse_decode_String(deserializer);
return GetInfoResponse(
balanceSat: var_balanceSat,
pendingSendSat: var_pendingSendSat,
pendingReceiveSat: var_pendingReceiveSat,
fingerprint: var_fingerprint,
pubkey: var_pubkey);
}

Expand Down Expand Up @@ -5362,6 +5365,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_u_64(self.balanceSat, serializer);
sse_encode_u_64(self.pendingSendSat, serializer);
sse_encode_u_64(self.pendingReceiveSat, serializer);
sse_encode_String(self.fingerprint, serializer);
sse_encode_String(self.pubkey, serializer);
}

Expand Down
3 changes: 3 additions & 0 deletions packages/dart/lib/src/frb_generated.io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2029,6 +2029,7 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
wireObj.balance_sat = cst_encode_u_64(apiObj.balanceSat);
wireObj.pending_send_sat = cst_encode_u_64(apiObj.pendingSendSat);
wireObj.pending_receive_sat = cst_encode_u_64(apiObj.pendingReceiveSat);
wireObj.fingerprint = cst_encode_String(apiObj.fingerprint);
wireObj.pubkey = cst_encode_String(apiObj.pubkey);
}

Expand Down Expand Up @@ -5792,6 +5793,8 @@ final class wire_cst_get_info_response extends ffi.Struct {
@ffi.Uint64()
external int pending_receive_sat;

external ffi.Pointer<wire_cst_list_prim_u_8_strict> fingerprint;

external ffi.Pointer<wire_cst_list_prim_u_8_strict> pubkey;
}

Expand Down
13 changes: 12 additions & 1 deletion packages/dart/lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,28 @@ class GetInfoResponse {

/// Incoming amount that is pending from ongoing Receive swaps
final BigInt pendingReceiveSat;

/// The wallet's fingerprint. It is used to build the working directory in [Config::get_wallet_working_dir].
final String fingerprint;

/// The wallet's pubkey. Used to verify signed messages.
final String pubkey;

const GetInfoResponse({
required this.balanceSat,
required this.pendingSendSat,
required this.pendingReceiveSat,
required this.fingerprint,
required this.pubkey,
});

@override
int get hashCode =>
balanceSat.hashCode ^ pendingSendSat.hashCode ^ pendingReceiveSat.hashCode ^ pubkey.hashCode;
balanceSat.hashCode ^
pendingSendSat.hashCode ^
pendingReceiveSat.hashCode ^
fingerprint.hashCode ^
pubkey.hashCode;

@override
bool operator ==(Object other) =>
Expand All @@ -231,6 +241,7 @@ class GetInfoResponse {
balanceSat == other.balanceSat &&
pendingSendSat == other.pendingSendSat &&
pendingReceiveSat == other.pendingReceiveSat &&
fingerprint == other.fingerprint &&
pubkey == other.pubkey;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4480,6 +4480,8 @@ final class wire_cst_get_info_response extends ffi.Struct {
@ffi.Uint64()
external int pending_receive_sat;

external ffi.Pointer<wire_cst_list_prim_u_8_strict> fingerprint;

external ffi.Pointer<wire_cst_list_prim_u_8_strict> pubkey;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ fun asGetInfoResponse(getInfoResponse: ReadableMap): GetInfoResponse? {
"balanceSat",
"pendingSendSat",
"pendingReceiveSat",
"fingerprint",
"pubkey",
),
)
Expand All @@ -435,15 +436,17 @@ fun asGetInfoResponse(getInfoResponse: ReadableMap): GetInfoResponse? {
val balanceSat = getInfoResponse.getDouble("balanceSat").toULong()
val pendingSendSat = getInfoResponse.getDouble("pendingSendSat").toULong()
val pendingReceiveSat = getInfoResponse.getDouble("pendingReceiveSat").toULong()
val fingerprint = getInfoResponse.getString("fingerprint")!!
val pubkey = getInfoResponse.getString("pubkey")!!
return GetInfoResponse(balanceSat, pendingSendSat, pendingReceiveSat, pubkey)
return GetInfoResponse(balanceSat, pendingSendSat, pendingReceiveSat, fingerprint, pubkey)
}

fun readableMapOf(getInfoResponse: GetInfoResponse): ReadableMap =
readableMapOf(
"balanceSat" to getInfoResponse.balanceSat,
"pendingSendSat" to getInfoResponse.pendingSendSat,
"pendingReceiveSat" to getInfoResponse.pendingReceiveSat,
"fingerprint" to getInfoResponse.fingerprint,
"pubkey" to getInfoResponse.pubkey,
)

Expand Down
6 changes: 5 additions & 1 deletion packages/react-native/ios/BreezSDKLiquidMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -505,18 +505,22 @@ enum BreezSDKLiquidMapper {
guard let pendingReceiveSat = getInfoResponse["pendingReceiveSat"] as? UInt64 else {
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "pendingReceiveSat", typeName: "GetInfoResponse"))
}
guard let fingerprint = getInfoResponse["fingerprint"] as? String else {
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "fingerprint", typeName: "GetInfoResponse"))
}
guard let pubkey = getInfoResponse["pubkey"] as? String else {
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "pubkey", typeName: "GetInfoResponse"))
}

return GetInfoResponse(balanceSat: balanceSat, pendingSendSat: pendingSendSat, pendingReceiveSat: pendingReceiveSat, pubkey: pubkey)
return GetInfoResponse(balanceSat: balanceSat, pendingSendSat: pendingSendSat, pendingReceiveSat: pendingReceiveSat, fingerprint: fingerprint, pubkey: pubkey)
}

static func dictionaryOf(getInfoResponse: GetInfoResponse) -> [String: Any?] {
return [
"balanceSat": getInfoResponse.balanceSat,
"pendingSendSat": getInfoResponse.pendingSendSat,
"pendingReceiveSat": getInfoResponse.pendingReceiveSat,
"fingerprint": getInfoResponse.fingerprint,
"pubkey": getInfoResponse.pubkey,
]
}
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export interface GetInfoResponse {
balanceSat: number
pendingSendSat: number
pendingReceiveSat: number
fingerprint: string
pubkey: string
}

Expand Down

0 comments on commit cbe835b

Please sign in to comment.