Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add freezed annotation on SDK structs used through Dart bindings #910

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libs/sdk-core/src/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//!
//! The first option loses the `SdkError` type. The second option keeps the type, which we can retrieve
//! with `anyhow::Error::downcast_ref` (or equivalent Dart method). We therefore use the second approach.

#![allow(unused_imports)]
use std::future::Future;
use std::sync::Arc;

Expand All @@ -30,7 +30,7 @@ use crate::input_parser::{self, InputType, LnUrlAuthRequestData};
use crate::invoice::{self, LNInvoice};
use crate::lnurl::pay::model::LnUrlPayResult;
use crate::lsp::LspInformation;
use crate::models::{Config, LogEntry, NodeState, Payment, SwapInfo};
use crate::models::{Config, GreenlightCredentials, LogEntry, NodeState, Payment, SwapInfo};
use crate::{
BackupStatus, BuyBitcoinRequest, BuyBitcoinResponse, CheckMessageRequest, CheckMessageResponse,
ConfigureNodeRequest, ConnectRequest, EnvironmentType, ListPaymentsRequest,
Expand Down
6 changes: 6 additions & 0 deletions libs/sdk-core/src/fiat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ use crate::error::SdkResult;
use crate::grpc::RatesRequest;
use crate::models::FiatAPI;
use crate::{breez_services::BreezServer, error::SdkError};
use flutter_rust_bridge::frb;
use serde::{Deserialize, Serialize};
use tonic::Request;

/// Settings for the symbol representation of a currency
#[derive(Clone, Serialize, Deserialize, Debug)]
#[frb(dart_metadata=("freezed"))]
pub struct Symbol {
pub grapheme: Option<String>,
pub template: Option<String>,
Expand All @@ -18,6 +20,7 @@ pub struct Symbol {

/// Locale-specific settings for the representation of a currency
#[derive(Clone, Serialize, Deserialize, Debug)]
#[frb(dart_metadata=("freezed"))]
pub struct LocaleOverrides {
pub locale: String,
pub spacing: Option<u32>,
Expand All @@ -26,6 +29,7 @@ pub struct LocaleOverrides {

/// Localized name of a currency
#[derive(Clone, Serialize, Deserialize, Debug)]
#[frb(dart_metadata=("freezed"))]
pub struct LocalizedName {
pub locale: String,
pub name: String,
Expand All @@ -34,6 +38,7 @@ pub struct LocalizedName {
/// Details about a supported currency in the fiat rate feed
#[derive(Clone, Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
#[frb(dart_metadata=("freezed"))]
pub struct CurrencyInfo {
pub name: String,
pub fraction_size: u32,
Expand All @@ -46,6 +51,7 @@ pub struct CurrencyInfo {

/// Wrapper around the [CurrencyInfo] of a fiat currency
#[derive(Clone, Debug, Serialize, Deserialize)]
#[frb(dart_metadata=("freezed"))]
pub struct FiatCurrency {
pub id: String,
pub info: CurrencyInfo,
Expand Down
6 changes: 6 additions & 0 deletions libs/sdk-core/src/input_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::time::Duration;

use anyhow::{anyhow, Result};
use bip21::Uri;
use flutter_rust_bridge::frb;
use serde::Deserialize;
use serde::Serialize;

Expand Down Expand Up @@ -501,6 +502,7 @@ impl From<LnUrlRequestData> for InputType {

/// Wrapped in a [LnUrlError], this represents a LNURL-endpoint error.
#[derive(Deserialize, Debug, Serialize)]
#[frb(dart_metadata=("freezed"))]
pub struct LnUrlErrorData {
pub reason: String,
}
Expand All @@ -512,6 +514,7 @@ pub struct LnUrlErrorData {
/// See <https://github.com/lnurl/luds/blob/luds/06.md>
#[derive(Clone, Deserialize, Debug, Serialize)]
#[serde(rename_all = "camelCase")]
#[frb(dart_metadata=("freezed"))]
pub struct LnUrlPayRequestData {
pub callback: String,
/// The minimum amount, in millisats, that this LNURL-pay endpoint accepts
Expand Down Expand Up @@ -567,6 +570,7 @@ impl LnUrlPayRequestData {
/// See <https://github.com/lnurl/luds/blob/luds/03.md>
#[derive(Deserialize, Debug, Serialize)]
#[serde(rename_all = "camelCase")]
#[frb(dart_metadata=("freezed"))]
pub struct LnUrlWithdrawRequestData {
pub callback: String,
pub k1: String,
Expand Down Expand Up @@ -595,6 +599,7 @@ impl LnUrlWithdrawRequestData {
///
/// See <https://github.com/lnurl/luds/blob/luds/04.md>
#[derive(Deserialize, Debug, Serialize)]
#[frb(dart_metadata=("freezed"))]
pub struct LnUrlAuthRequestData {
/// Hex encoded 32 bytes of challenge
pub k1: String,
Expand Down Expand Up @@ -622,6 +627,7 @@ pub struct MetadataItem {

/// Wrapped in a [BitcoinAddress], this is the result of [parse] when given a plain or BIP-21 BTC address.
#[derive(Debug, Serialize)]
#[frb(dart_metadata=("freezed"))]
pub struct BitcoinAddressData {
pub address: String,
pub network: crate::models::Network,
Expand Down
4 changes: 4 additions & 0 deletions libs/sdk-core/src/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::str::FromStr;
use std::time::{SystemTimeError, UNIX_EPOCH};

use anyhow::anyhow;
use flutter_rust_bridge::frb;
use hex::ToHex;
use regex::Regex;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -64,6 +65,7 @@ impl From<SystemTimeError> for InvoiceError {

/// Wrapper for a BOLT11 LN invoice
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[frb(dart_metadata=("freezed"))]
pub struct LNInvoice {
pub bolt11: String,
pub network: Network,
Expand All @@ -89,6 +91,7 @@ impl LNInvoice {

/// Details of a specific hop in a larger route hint
#[derive(Clone, Default, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[frb(dart_metadata=("freezed"))]
pub struct RouteHintHop {
/// The node_id of the non-target end of the route
pub src_node_id: String,
Expand All @@ -108,6 +111,7 @@ pub struct RouteHintHop {

/// A route hint for a LN payment
#[derive(Clone, Default, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[frb(dart_metadata=("freezed"))]
pub struct RouteHint {
pub hops: Vec<RouteHintHop>,
}
Expand Down
2 changes: 2 additions & 0 deletions libs/sdk-core/src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ use crate::grpc::{
use crate::models::{LspAPI, OpeningFeeParams, OpeningFeeParamsMenu};

use anyhow::{anyhow, Result};
use flutter_rust_bridge::frb;
use prost::Message;
use serde::{Deserialize, Serialize};
use tonic::Request;

/// Details of supported LSP
#[derive(Clone, Debug, Serialize, Deserialize)]
#[frb(dart_metadata=("freezed"))]
pub struct LspInformation {
pub id: String,

Expand Down
24 changes: 24 additions & 0 deletions libs/sdk-core/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::str::FromStr;

use anyhow::{anyhow, ensure, Result};
use chrono::{DateTime, Duration, Utc};
use flutter_rust_bridge::frb;
use ripemd::Digest;
use ripemd::Ripemd160;
use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef};
Expand Down Expand Up @@ -329,6 +330,7 @@ impl FullReverseSwapInfo {

/// Simplified version of [FullReverseSwapInfo], containing only the user-relevant fields
#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone)]
#[frb(dart_metadata=("freezed"))]
pub struct ReverseSwapInfo {
pub id: String,
pub claim_pubkey: String,
Expand Down Expand Up @@ -460,6 +462,7 @@ pub struct LogEntry {
/// Use [Config::production] or [Config::staging] for default configs of the different supported
/// environments.
#[derive(Clone)]
#[frb(dart_metadata=("freezed"))]
pub struct Config {
pub breezserver: String,
pub chainnotifier_url: String,
Expand Down Expand Up @@ -532,6 +535,7 @@ pub enum NodeCredentials {
}

#[derive(Clone)]
#[frb(dart_metadata=("freezed"))]
pub struct GreenlightNodeConfig {
pub partner_credentials: Option<GreenlightCredentials>,
pub invite_code: Option<String>,
Expand Down Expand Up @@ -649,6 +653,7 @@ pub struct BackupStatus {
/// which may result in some short-lived inconsistencies
/// (e.g., `channels_balance_msat` may be updated before `inbound_liquidity_msats`).
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
#[frb(dart_metadata=("freezed"))]
pub struct NodeState {
pub id: String,
pub block_height: u32,
Expand Down Expand Up @@ -684,6 +689,7 @@ pub enum PaymentStatus {

/// Represents a payment, including its [PaymentType] and [PaymentDetails]
#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
#[frb(dart_metadata=("freezed"))]
pub struct Payment {
pub id: String,
pub payment_type: PaymentType,
Expand Down Expand Up @@ -712,6 +718,7 @@ pub struct PaymentExternalInfo {

/// Represents a list payments request.
#[derive(Default)]
#[frb(dart_metadata=("freezed"))]
pub struct ListPaymentsRequest {
pub filters: Option<Vec<PaymentTypeFilter>>,
pub metadata_filters: Option<Vec<MetadataFilter>>,
Expand Down Expand Up @@ -760,6 +767,7 @@ impl PaymentDetails {

/// Details of a LN payment, as included in a [Payment]
#[derive(PartialEq, Eq, Debug, Clone, Deserialize, Serialize)]
#[frb(dart_metadata=("freezed"))]
pub struct LnPaymentDetails {
pub payment_hash: String,
pub label: String,
Expand Down Expand Up @@ -800,6 +808,7 @@ pub struct LnPaymentDetails {

/// Represents the funds that were on the user side of the channel at the time it was closed.
#[derive(PartialEq, Eq, Debug, Clone, Deserialize, Serialize)]
#[frb(dart_metadata=("freezed"))]
pub struct ClosedChannelPaymentDetails {
pub state: ChannelState,
pub funding_txid: String,
Expand Down Expand Up @@ -834,6 +843,7 @@ pub struct MaxChannelAmount {

/// Represents a receive payment request.
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
#[frb(dart_metadata=("freezed"))]
pub struct ReceivePaymentRequest {
/// The amount in satoshis for this payment request
pub amount_msat: u64,
Expand All @@ -859,6 +869,7 @@ pub struct ReceivePaymentRequest {
/// be opened automatically when the invoice is paid, and the fees will be described in the
/// `opening_fee_params` and `opening_fee_msat` fields.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[frb(dart_metadata=("freezed"))]
pub struct ReceivePaymentResponse {
/// The generated invoice, including any necessary routing hints
pub ln_invoice: LNInvoice,
Expand Down Expand Up @@ -888,6 +899,7 @@ pub struct TlvEntry {

/// Represents a send spontaneous payment request.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[frb(dart_metadata=("freezed"))]
pub struct SendSpontaneousPaymentRequest {
/// The node id to send this payment is
pub node_id: String,
Expand All @@ -899,6 +911,7 @@ pub struct SendSpontaneousPaymentRequest {

/// Represents a send payment response.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[frb(dart_metadata=("freezed"))]
pub struct SendPaymentResponse {
pub payment: Payment,
}
Expand Down Expand Up @@ -927,6 +940,7 @@ pub enum HealthCheckStatus {

/// Represents a service health check response.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[frb(dart_metadata=("freezed"))]
pub struct ServiceHealthCheckResponse {
pub status: HealthCheckStatus,
}
Expand Down Expand Up @@ -971,17 +985,20 @@ pub struct OpenChannelFeeResponse {
}

#[derive(Clone, Debug, Default, Serialize, Deserialize)]
#[frb(dart_metadata=("freezed"))]
pub struct ReceiveOnchainRequest {
pub opening_fee_params: Option<OpeningFeeParams>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[frb(dart_metadata=("freezed"))]
pub struct BuyBitcoinRequest {
pub provider: BuyBitcoinProvider,
pub opening_fee_params: Option<OpeningFeeParams>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[frb(dart_metadata=("freezed"))]
pub struct BuyBitcoinResponse {
pub url: String,
pub opening_fee_params: Option<OpeningFeeParams>,
Expand All @@ -1006,6 +1023,7 @@ pub struct SendOnchainRequest {
pub sat_per_vbyte: u32,
}

#[frb(dart_metadata=("freezed"))]
pub struct SendOnchainResponse {
pub reverse_swap_info: ReverseSwapInfo,
}
Expand Down Expand Up @@ -1088,6 +1106,7 @@ pub struct RefundResponse {
/// After they are received, the client shouldn't change them when calling LSP methods,
/// otherwise the LSP may reject the call.
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
#[frb(dart_metadata=("freezed"))]
pub struct OpeningFeeParams {
/// The minimum value in millisatoshi we will require for incoming HTLCs on the channel
pub min_msat: u64,
Expand Down Expand Up @@ -1165,6 +1184,7 @@ pub enum DynamicFeeType {

/// See [OpeningFeeParamsMenu::try_from]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[frb(dart_metadata=("freezed"))]
pub struct OpeningFeeParamsMenu {
pub values: Vec<OpeningFeeParams>,
}
Expand Down Expand Up @@ -1336,6 +1356,7 @@ impl TryFrom<i32> for SwapStatus {
///

#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[frb(dart_metadata=("freezed"))]
pub struct SwapInfo {
/// Bitcoin address for this swap. Sats sent to this address will be swapped.
pub bitcoin_address: String,
Expand Down Expand Up @@ -1498,6 +1519,7 @@ pub(crate) fn format_short_channel_id(id: u64) -> String {

/// UTXO known to the LN node
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
#[frb(dart_metadata=("freezed"))]
pub struct UnspentTransactionOutput {
pub txid: Vec<u8>,
pub outnum: u32,
Expand Down Expand Up @@ -1530,6 +1552,7 @@ pub enum LnUrlCallbackStatus {
}

#[derive(Debug, Serialize, Deserialize)]
#[frb(dart_metadata=("freezed"))]
pub struct LnUrlWithdrawRequest {
/// Request data containing information on how to call the lnurl withdraw
/// endpoint. Typically retrieved by calling `parse()` on a lnurl withdraw
Expand All @@ -1547,6 +1570,7 @@ pub struct LnUrlWithdrawRequest {

/// Represents a LNURL-pay request.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[frb(dart_metadata=("freezed"))]
pub struct LnUrlPayRequest {
/// The [LnUrlPayRequestData] returned by [crate::input_parser::parse]
pub data: LnUrlPayRequestData,
Expand Down
Loading
Loading