Skip to content

Commit

Permalink
Add the Balances object to wallets and nodes.
Browse files Browse the repository at this point in the history
This provides a more human-readable view of what different balances mean.
  • Loading branch information
jklein24 committed Nov 3, 2023
1 parent 2e3ca36 commit 39a7644
Show file tree
Hide file tree
Showing 15 changed files with 638 additions and 46 deletions.
162 changes: 162 additions & 0 deletions lightspark/src/objects/account.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use crate::objects::connection::Connection;
use crate::objects::page_info::PageInfo;
use crate::objects::payment_request::PaymentRequestEnum;
use serde::Deserialize;
use std::vec::Vec;

use crate::objects::page_info::PageInfo;
use crate::objects::payment_request::PaymentRequestEnum;

#[derive(Clone, Deserialize)]
pub struct AccountToPaymentRequestsConnection {
/// The total count of objects in this connection, using the current filters. It is different from the number of objects returned in the current page (in the `entities` field).
Expand Down
8 changes: 4 additions & 4 deletions lightspark/src/objects/account_to_transactions_connection.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use crate::objects::page_info::PageInfo;
use crate::objects::currency_amount::CurrencyAmount;
use crate::objects::transaction::TransactionEnum;
use serde::Deserialize;
use std::vec::Vec;

use crate::objects::connection::Connection;
use crate::objects::currency_amount::CurrencyAmount;
use crate::objects::transaction::TransactionEnum;
use crate::objects::page_info::PageInfo;
use std::vec::Vec;

#[derive(Clone, Deserialize)]
pub struct AccountToTransactionsConnection {
Expand Down
35 changes: 35 additions & 0 deletions lightspark/src/objects/channel_snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use crate::objects::currency_amount::CurrencyAmount;
use crate::types::custom_date_formats::custom_date_format;
use crate::types::entity_wrapper::EntityWrapper;
use chrono::{DateTime, Utc};
use serde::Deserialize;

#[derive(Clone, Deserialize)]
pub struct ChannelSnapshot {
#[serde(rename = "channel_snapshot_channel")]
pub channel: EntityWrapper,

#[serde(with = "custom_date_format", rename = "channel_snapshot_timestamp")]
pub timestamp: DateTime<Utc>,

#[serde(rename = "channel_snapshot_local_balance")]
pub local_balance: Option<CurrencyAmount>,

Expand All @@ -12,11 +21,21 @@ pub struct ChannelSnapshot {

#[serde(rename = "channel_snapshot_local_channel_reserve")]
pub local_channel_reserve: Option<CurrencyAmount>,

#[serde(rename = "channel_snapshot_remote_balance")]
pub remote_balance: Option<CurrencyAmount>,

#[serde(rename = "channel_snapshot_remote_unsettled_balance")]
pub remote_unsettled_balance: Option<CurrencyAmount>,
}

pub const FRAGMENT: &str = "
fragment ChannelSnapshotFragment on ChannelSnapshot {
__typename
channel_snapshot_channel: channel {
id
}
channel_snapshot_timestamp: timestamp
channel_snapshot_local_balance: local_balance {
__typename
currency_amount_original_value: original_value
Expand All @@ -41,5 +60,21 @@ fragment ChannelSnapshotFragment on ChannelSnapshot {
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_snapshot_remote_balance: remote_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_snapshot_remote_unsettled_balance: remote_unsettled_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
";
4 changes: 4 additions & 0 deletions lightspark/src/objects/htlc_attempt_failure_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ pub enum HtlcAttemptFailureCode {
#[serde(rename = "INVALID_ONION_PAYLOAD")]
InvalidOnionPayload,

#[serde(rename = "INVALID_ONION_BLINDING")]
InvalidOnionBlinding,

#[serde(rename = "INTERNAL_FAILURE")]
InternalFailure,

Expand Down Expand Up @@ -123,6 +126,7 @@ impl fmt::Display for HtlcAttemptFailureCode {
Self::ExpiryTooFar => write!(f, "EXPIRY_TOO_FAR"),
Self::MppTimeout => write!(f, "MPP_TIMEOUT"),
Self::InvalidOnionPayload => write!(f, "INVALID_ONION_PAYLOAD"),
Self::InvalidOnionBlinding => write!(f, "INVALID_ONION_BLINDING"),
Self::InternalFailure => write!(f, "INTERNAL_FAILURE"),
Self::UnknownFailure => write!(f, "UNKNOWN_FAILURE"),
Self::UnreadableFailure => write!(f, "UNREADABLE_FAILURE"),
Expand Down
54 changes: 54 additions & 0 deletions lightspark/src/objects/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,33 @@ fragment InvoiceFragment on Invoice {
}
}
lightspark_node_with_o_s_k_uma_prescreening_utxos: uma_prescreening_utxos
lightspark_node_with_o_s_k_balances: balances {
__typename
balances_owned_balance: owned_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_send_balance: available_to_send_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_withdraw_balance: available_to_withdraw_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
lightspark_node_with_o_s_k_encrypted_signing_private_key: encrypted_signing_private_key {
__typename
secret_encrypted_value: encrypted_value
Expand Down Expand Up @@ -333,6 +360,33 @@ fragment InvoiceFragment on Invoice {
}
}
lightspark_node_with_remote_signing_uma_prescreening_utxos: uma_prescreening_utxos
lightspark_node_with_remote_signing_balances: balances {
__typename
balances_owned_balance: owned_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_send_balance: available_to_send_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_withdraw_balance: available_to_withdraw_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
}
}
}
Expand Down
62 changes: 58 additions & 4 deletions lightspark/src/objects/invoice_data.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use crate::objects::bitcoin_network::BitcoinNetwork;
use crate::objects::node::NodeEnum;
use crate::types::custom_date_formats::custom_date_format;
use chrono::{DateTime, Utc};
use serde::Deserialize;

use crate::objects::bitcoin_network::BitcoinNetwork;
use crate::objects::currency_amount::CurrencyAmount;
use crate::objects::node::NodeEnum;
use crate::objects::payment_request_data::PaymentRequestData;
use crate::types::custom_date_formats::custom_date_format;
use chrono::{DateTime, Utc};

/// This object represents the data associated with a BOLT #11 invoice. You can retrieve this object to receive the relevant data associated with a specific invoice.
#[derive(Clone, Deserialize)]
Expand Down Expand Up @@ -186,6 +186,33 @@ fragment InvoiceDataFragment on InvoiceData {
}
}
lightspark_node_with_o_s_k_uma_prescreening_utxos: uma_prescreening_utxos
lightspark_node_with_o_s_k_balances: balances {
__typename
balances_owned_balance: owned_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_send_balance: available_to_send_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_withdraw_balance: available_to_withdraw_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
lightspark_node_with_o_s_k_encrypted_signing_private_key: encrypted_signing_private_key {
__typename
secret_encrypted_value: encrypted_value
Expand Down Expand Up @@ -291,6 +318,33 @@ fragment InvoiceDataFragment on InvoiceData {
}
}
lightspark_node_with_remote_signing_uma_prescreening_utxos: uma_prescreening_utxos
lightspark_node_with_remote_signing_balances: balances {
__typename
balances_owned_balance: owned_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_send_balance: available_to_send_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_withdraw_balance: available_to_withdraw_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions lightspark/src/objects/lightspark_node.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use super::lightspark_node_with_o_s_k::LightsparkNodeWithOSK;
use super::lightspark_node_with_remote_signing::LightsparkNodeWithRemoteSigning;
use crate::objects::blockchain_balance::BlockchainBalance;
use crate::objects::currency_amount::CurrencyAmount;
use crate::objects::entity::Entity;
use crate::objects::lightspark_node_status::LightsparkNodeStatus;
use crate::objects::node::Node;
use crate::types::entity_wrapper::EntityWrapper;
use serde::{Deserialize, Deserializer};
use serde_json::Value;

use super::lightspark_node_with_remote_signing::LightsparkNodeWithRemoteSigning;
use crate::objects::balances::Balances;
use crate::types::entity_wrapper::EntityWrapper;
use std::vec::Vec;

pub trait LightsparkNode: Node + Entity {
Expand Down Expand Up @@ -36,6 +38,9 @@ pub trait LightsparkNode: Node + Entity {
/// The utxos of the channels that are connected to this node. This is used in uma flow for pre-screening.
fn get_uma_prescreening_utxos(&self) -> Vec<String>;

/// The balances that describe the funds in this node.
fn get_balances(&self) -> Option<Balances>;

fn type_name(&self) -> &'static str;
}

Expand Down
59 changes: 48 additions & 11 deletions lightspark/src/objects/lightspark_node_with_o_s_k.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use crate::error::Error;
use crate::objects::lightspark_node_to_channels_connection::LightsparkNodeToChannelsConnection;
use crate::objects::blockchain_balance::BlockchainBalance;
use crate::objects::lightspark_node::LightsparkNode;
use crate::objects::node::Node;
use crate::objects::node_address_type::NodeAddressType;
use crate::objects::node_to_addresses_connection::NodeToAddressesConnection;
use crate::types::graphql_requester::GraphQLRequester;
use chrono::{DateTime, Utc};
use serde::Deserialize;
use std::collections::HashMap;
use std::vec::Vec;

use crate::error::Error;
use crate::objects::balances::Balances;
use crate::objects::bitcoin_network::BitcoinNetwork;
use crate::objects::blockchain_balance::BlockchainBalance;
use crate::objects::channel_status::ChannelStatus;
use crate::objects::currency_amount::CurrencyAmount;
use crate::objects::entity::Entity;
use crate::objects::lightspark_node::LightsparkNode;
use crate::objects::lightspark_node_status::LightsparkNodeStatus;
use crate::objects::node::Node;
use crate::objects::node_address_type::NodeAddressType;
use crate::objects::node_to_addresses_connection::NodeToAddressesConnection;
use crate::objects::lightspark_node_to_channels_connection::LightsparkNodeToChannelsConnection;
use crate::objects::secret::Secret;
use crate::types::custom_date_formats::custom_date_format;
use crate::types::entity_wrapper::EntityWrapper;
use crate::types::get_entity::GetEntity;
use crate::types::graphql_requester::GraphQLRequester;
use chrono::{DateTime, Utc};
use serde_json::Value;
use std::vec::Vec;
use std::collections::HashMap;

/// This is a Lightspark node with OSK.
#[derive(Clone, Deserialize)]
Expand Down Expand Up @@ -100,6 +101,10 @@ pub struct LightsparkNodeWithOSK {
#[serde(rename = "lightspark_node_with_o_s_k_uma_prescreening_utxos")]
pub uma_prescreening_utxos: Vec<String>,

/// The balances that describe the funds in this node.
#[serde(rename = "lightspark_node_with_o_s_k_balances")]
pub balances: Option<Balances>,

/// The private key client is using to sign a GraphQL request which will be verified at server side.
#[serde(rename = "lightspark_node_with_o_s_k_encrypted_signing_private_key")]
pub encrypted_signing_private_key: Option<Secret>,
Expand Down Expand Up @@ -146,6 +151,11 @@ impl LightsparkNode for LightsparkNodeWithOSK {
self.uma_prescreening_utxos.clone()
}

/// The balances that describe the funds in this node.
fn get_balances(&self) -> Option<Balances> {
self.balances.clone()
}

fn type_name(&self) -> &'static str {
"LightsparkNodeWithOSK"
}
Expand Down Expand Up @@ -326,6 +336,33 @@ fragment LightsparkNodeWithOSKFragment on LightsparkNodeWithOSK {
}
}
lightspark_node_with_o_s_k_uma_prescreening_utxos: uma_prescreening_utxos
lightspark_node_with_o_s_k_balances: balances {
__typename
balances_owned_balance: owned_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_send_balance: available_to_send_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_withdraw_balance: available_to_withdraw_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
lightspark_node_with_o_s_k_encrypted_signing_private_key: encrypted_signing_private_key {
__typename
secret_encrypted_value: encrypted_value
Expand Down
Loading

0 comments on commit 39a7644

Please sign in to comment.