From fb05230e8093d64951290176d51d6ea8301fcf54 Mon Sep 17 00:00:00 2001 From: Zhen Lu Date: Fri, 5 Jan 2024 11:02:05 -0800 Subject: [PATCH] Regenerate SDK. (#27) --- lightspark/src/objects/account.rs | 14 +++- .../objects/account_to_channels_connection.rs | 33 +++++++++ .../objects/account_to_nodes_connection.rs | 3 +- .../account_to_payment_requests_connection.rs | 6 +- .../account_to_transactions_connection.rs | 6 +- lightspark/src/objects/connection.rs | 8 +++ .../src/objects/daily_liquidity_forecast.rs | 40 +++++++++++ lightspark/src/objects/invoice_data.rs | 6 +- .../objects/lightning_payment_direction.rs | 32 +++++++++ lightspark/src/objects/lightspark_node.rs | 10 +-- ...to_daily_liquidity_forecasts_connection.rs | 51 ++++++++++++++ .../src/objects/lightspark_node_with_o_s_k.rs | 70 ++++++++++++++++--- .../lightspark_node_with_remote_signing.rs | 70 ++++++++++++++++--- lightspark/src/objects/mod.rs | 5 ++ lightspark/src/objects/outgoing_payment.rs | 22 +++--- .../wallet_to_payment_requests_connection.rs | 6 +- .../wallet_to_transactions_connection.rs | 6 +- .../objects/withdrawal_fee_estimate_input.rs | 15 ++++ .../objects/withdrawal_fee_estimate_output.rs | 24 +++++++ 19 files changed, 370 insertions(+), 57 deletions(-) create mode 100644 lightspark/src/objects/daily_liquidity_forecast.rs create mode 100644 lightspark/src/objects/lightning_payment_direction.rs create mode 100644 lightspark/src/objects/lightspark_node_to_daily_liquidity_forecasts_connection.rs create mode 100644 lightspark/src/objects/withdrawal_fee_estimate_input.rs create mode 100644 lightspark/src/objects/withdrawal_fee_estimate_output.rs diff --git a/lightspark/src/objects/account.rs b/lightspark/src/objects/account.rs index a24b266..cffafb5 100644 --- a/lightspark/src/objects/account.rs +++ b/lightspark/src/objects/account.rs @@ -655,6 +655,7 @@ impl Account { Ok(result) } + #[allow(clippy::too_many_arguments)] pub async fn get_channels( &self, requester: &impl GraphQLRequester, @@ -663,13 +664,21 @@ impl Account { after_date: Option>, before_date: Option>, first: Option, + after: Option, ) -> Result { - let query = "query FetchAccountToChannelsConnection($entity_id: ID!, $bitcoin_network: BitcoinNetwork!, $lightning_node_id: ID, $after_date: DateTime, $before_date: DateTime, $first: Int) { + let query = "query FetchAccountToChannelsConnection($entity_id: ID!, $bitcoin_network: BitcoinNetwork!, $lightning_node_id: ID, $after_date: DateTime, $before_date: DateTime, $first: Int, $after: String) { entity(id: $entity_id) { ... on Account { - channels(, bitcoin_network: $bitcoin_network, lightning_node_id: $lightning_node_id, after_date: $after_date, before_date: $before_date, first: $first) { + channels(, bitcoin_network: $bitcoin_network, lightning_node_id: $lightning_node_id, after_date: $after_date, before_date: $before_date, first: $first, after: $after) { __typename account_to_channels_connection_count: count + account_to_channels_connection_page_info: page_info { + __typename + page_info_has_next_page: has_next_page + page_info_has_previous_page: has_previous_page + page_info_start_cursor: start_cursor + page_info_end_cursor: end_cursor + } account_to_channels_connection_entities: entities { __typename channel_id: id @@ -775,6 +784,7 @@ impl Account { variables.insert("after_date", after_date.map(|dt| dt.to_rfc3339()).into()); variables.insert("before_date", before_date.map(|dt| dt.to_rfc3339()).into()); variables.insert("first", first.into()); + variables.insert("after", after.into()); let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; let result = requester.execute_graphql(query, Some(value)).await?; diff --git a/lightspark/src/objects/account_to_channels_connection.rs b/lightspark/src/objects/account_to_channels_connection.rs index 4ce686e..677980d 100644 --- a/lightspark/src/objects/account_to_channels_connection.rs +++ b/lightspark/src/objects/account_to_channels_connection.rs @@ -1,5 +1,7 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved use crate::objects::channel::Channel; +use crate::objects::connection::Connection; +use crate::objects::page_info::PageInfo; use serde::{Deserialize, Serialize}; use std::vec::Vec; @@ -9,15 +11,46 @@ pub struct AccountToChannelsConnection { #[serde(rename = "account_to_channels_connection_count")] pub count: i64, + /// An object that holds pagination information about the objects in this connection. + #[serde(rename = "account_to_channels_connection_page_info")] + pub page_info: PageInfo, + /// The channels for the current page of this connection. #[serde(rename = "account_to_channels_connection_entities")] pub entities: Vec, + + /// The typename of the object + #[serde(rename = "__typename")] + pub typename: String, +} + +impl Connection for AccountToChannelsConnection { + /// 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). + fn get_count(&self) -> i64 { + self.count + } + + /// An object that holds pagination information about the objects in this connection. + fn get_page_info(&self) -> PageInfo { + self.page_info.clone() + } + + fn type_name(&self) -> &'static str { + "AccountToChannelsConnection" + } } pub const FRAGMENT: &str = " fragment AccountToChannelsConnectionFragment on AccountToChannelsConnection { __typename account_to_channels_connection_count: count + account_to_channels_connection_page_info: page_info { + __typename + page_info_has_next_page: has_next_page + page_info_has_previous_page: has_previous_page + page_info_start_cursor: start_cursor + page_info_end_cursor: end_cursor + } account_to_channels_connection_entities: entities { id } diff --git a/lightspark/src/objects/account_to_nodes_connection.rs b/lightspark/src/objects/account_to_nodes_connection.rs index 7311782..f627e8a 100644 --- a/lightspark/src/objects/account_to_nodes_connection.rs +++ b/lightspark/src/objects/account_to_nodes_connection.rs @@ -1,9 +1,8 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved -use serde::{Deserialize, Serialize}; - use crate::objects::connection::Connection; use crate::objects::lightspark_node::LightsparkNodeEnum; use crate::objects::page_info::PageInfo; +use serde::{Deserialize, Serialize}; use std::vec::Vec; /// A connection between an account and the nodes it manages. diff --git a/lightspark/src/objects/account_to_payment_requests_connection.rs b/lightspark/src/objects/account_to_payment_requests_connection.rs index 6326302..44a9c22 100644 --- a/lightspark/src/objects/account_to_payment_requests_connection.rs +++ b/lightspark/src/objects/account_to_payment_requests_connection.rs @@ -1,10 +1,10 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use serde::{Deserialize, Serialize}; +use std::vec::Vec; + use crate::objects::connection::Connection; use crate::objects::page_info::PageInfo; use crate::objects::payment_request::PaymentRequestEnum; -use serde::{Deserialize, Serialize}; - -use std::vec::Vec; #[derive(Debug, Clone, Deserialize, Serialize)] pub struct AccountToPaymentRequestsConnection { diff --git a/lightspark/src/objects/account_to_transactions_connection.rs b/lightspark/src/objects/account_to_transactions_connection.rs index 00825e4..2fa1974 100644 --- a/lightspark/src/objects/account_to_transactions_connection.rs +++ b/lightspark/src/objects/account_to_transactions_connection.rs @@ -1,11 +1,11 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved -use crate::objects::connection::Connection; +use crate::objects::transaction::TransactionEnum; use serde::{Deserialize, Serialize}; +use std::vec::Vec; +use crate::objects::connection::Connection; use crate::objects::currency_amount::CurrencyAmount; use crate::objects::page_info::PageInfo; -use crate::objects::transaction::TransactionEnum; -use std::vec::Vec; #[derive(Debug, Clone, Deserialize, Serialize)] pub struct AccountToTransactionsConnection { diff --git a/lightspark/src/objects/connection.rs b/lightspark/src/objects/connection.rs index 6660794..41d57c7 100644 --- a/lightspark/src/objects/connection.rs +++ b/lightspark/src/objects/connection.rs @@ -1,6 +1,7 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved use super::account_to_api_tokens_connection::AccountToApiTokensConnection; +use super::account_to_channels_connection::AccountToChannelsConnection; use super::account_to_nodes_connection::AccountToNodesConnection; use super::account_to_payment_requests_connection::AccountToPaymentRequestsConnection; use super::account_to_transactions_connection::AccountToTransactionsConnection; @@ -31,6 +32,7 @@ pub trait Connection { #[derive(Debug, Clone, Serialize)] pub enum ConnectionEnum { AccountToApiTokensConnection(AccountToApiTokensConnection), + AccountToChannelsConnection(AccountToChannelsConnection), AccountToNodesConnection(AccountToNodesConnection), AccountToPaymentRequestsConnection(AccountToPaymentRequestsConnection), AccountToTransactionsConnection(AccountToTransactionsConnection), @@ -59,6 +61,12 @@ impl<'de> Deserialize<'de> for ConnectionEnum { })?; Ok(ConnectionEnum::AccountToApiTokensConnection(obj)) } + "AccountToChannelsConnection" => { + let obj = AccountToChannelsConnection::deserialize(value).map_err(|err| { + serde::de::Error::custom(format!("Serde JSON Error {}", err)) + })?; + Ok(ConnectionEnum::AccountToChannelsConnection(obj)) + } "AccountToNodesConnection" => { let obj = AccountToNodesConnection::deserialize(value).map_err(|err| { serde::de::Error::custom(format!("Serde JSON Error {}", err)) diff --git a/lightspark/src/objects/daily_liquidity_forecast.rs b/lightspark/src/objects/daily_liquidity_forecast.rs new file mode 100644 index 0000000..405417f --- /dev/null +++ b/lightspark/src/objects/daily_liquidity_forecast.rs @@ -0,0 +1,40 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use crate::objects::currency_amount::CurrencyAmount; +use crate::objects::lightning_payment_direction::LightningPaymentDirection; +use crate::types::custom_date_formats::custom_date_only_format; +use chrono::NaiveDate; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct DailyLiquidityForecast { + /// The date for which this forecast was generated. + #[serde( + with = "custom_date_only_format", + rename = "daily_liquidity_forecast_date" + )] + pub date: NaiveDate, + + /// The direction for which this forecast was generated. + #[serde(rename = "daily_liquidity_forecast_direction")] + pub direction: LightningPaymentDirection, + + /// The value of the forecast. It represents the amount of msats that we think will be moved for that specified direction, for that node, on that date. + #[serde(rename = "daily_liquidity_forecast_amount")] + pub amount: CurrencyAmount, +} + +pub const FRAGMENT: &str = " +fragment DailyLiquidityForecastFragment on DailyLiquidityForecast { + __typename + daily_liquidity_forecast_date: date + daily_liquidity_forecast_direction: direction + daily_liquidity_forecast_amount: amount { + __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 + } +} +"; diff --git a/lightspark/src/objects/invoice_data.rs b/lightspark/src/objects/invoice_data.rs index dd95c64..27635d4 100644 --- a/lightspark/src/objects/invoice_data.rs +++ b/lightspark/src/objects/invoice_data.rs @@ -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::objects::payment_request_data::PaymentRequestData; use crate::types::custom_date_formats::custom_date_format; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; -use crate::objects::bitcoin_network::BitcoinNetwork; use crate::objects::currency_amount::CurrencyAmount; -use crate::objects::payment_request_data::PaymentRequestData; -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(Debug, Clone, Deserialize, Serialize)] diff --git a/lightspark/src/objects/lightning_payment_direction.rs b/lightspark/src/objects/lightning_payment_direction.rs new file mode 100644 index 0000000..fffeea4 --- /dev/null +++ b/lightspark/src/objects/lightning_payment_direction.rs @@ -0,0 +1,32 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use serde::{Deserialize, Serialize}; +use serde_json::Value; +use std::fmt; + +/// This is an enum identifying the payment direction. +#[derive(Debug, Clone, Deserialize, Serialize)] +pub enum LightningPaymentDirection { + /// A payment that is received by the node. + + #[serde(rename = "INCOMING")] + Incoming, + /// A payment that is sent by the node. + + #[serde(rename = "OUTGOING")] + Outgoing, +} + +impl From for Value { + fn from(val: LightningPaymentDirection) -> Self { + Value::from(val.to_string()) + } +} + +impl fmt::Display for LightningPaymentDirection { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Self::Incoming => write!(f, "INCOMING"), + Self::Outgoing => write!(f, "OUTGOING"), + } + } +} diff --git a/lightspark/src/objects/lightspark_node.rs b/lightspark/src/objects/lightspark_node.rs index 07adf47..917a15a 100644 --- a/lightspark/src/objects/lightspark_node.rs +++ b/lightspark/src/objects/lightspark_node.rs @@ -1,17 +1,17 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved -use crate::objects::blockchain_balance::BlockchainBalance; +use super::lightspark_node_with_o_s_k::LightsparkNodeWithOSK; use crate::objects::entity::Entity; -use crate::objects::lightspark_node_status::LightsparkNodeStatus; use crate::objects::node::Node; +use serde::{Deserialize, Deserializer, Serialize}; +use std::vec::Vec; -use super::lightspark_node_with_o_s_k::LightsparkNodeWithOSK; use super::lightspark_node_with_remote_signing::LightsparkNodeWithRemoteSigning; use crate::objects::balances::Balances; +use crate::objects::blockchain_balance::BlockchainBalance; use crate::objects::currency_amount::CurrencyAmount; +use crate::objects::lightspark_node_status::LightsparkNodeStatus; use crate::types::entity_wrapper::EntityWrapper; -use serde::{Deserialize, Deserializer, Serialize}; use serde_json::Value; -use std::vec::Vec; pub trait LightsparkNode: Node + Entity { /// The owner of this LightsparkNode. diff --git a/lightspark/src/objects/lightspark_node_to_daily_liquidity_forecasts_connection.rs b/lightspark/src/objects/lightspark_node_to_daily_liquidity_forecasts_connection.rs new file mode 100644 index 0000000..ea31b6e --- /dev/null +++ b/lightspark/src/objects/lightspark_node_to_daily_liquidity_forecasts_connection.rs @@ -0,0 +1,51 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use crate::objects::daily_liquidity_forecast::DailyLiquidityForecast; +use crate::objects::lightning_payment_direction::LightningPaymentDirection; +use crate::types::custom_date_formats::custom_date_only_format; +use chrono::NaiveDate; +use serde::{Deserialize, Serialize}; +use std::vec::Vec; + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct LightsparkNodeToDailyLiquidityForecastsConnection { + #[serde( + with = "custom_date_only_format", + rename = "lightspark_node_to_daily_liquidity_forecasts_connection_from_date" + )] + pub from_date: NaiveDate, + + #[serde( + with = "custom_date_only_format", + rename = "lightspark_node_to_daily_liquidity_forecasts_connection_to_date" + )] + pub to_date: NaiveDate, + + #[serde(rename = "lightspark_node_to_daily_liquidity_forecasts_connection_direction")] + pub direction: LightningPaymentDirection, + + /// The daily liquidity forecasts for the current page of this connection. + #[serde(rename = "lightspark_node_to_daily_liquidity_forecasts_connection_entities")] + pub entities: Vec, +} + +pub const FRAGMENT: &str = " +fragment LightsparkNodeToDailyLiquidityForecastsConnectionFragment on LightsparkNodeToDailyLiquidityForecastsConnection { + __typename + lightspark_node_to_daily_liquidity_forecasts_connection_from_date: from_date + lightspark_node_to_daily_liquidity_forecasts_connection_to_date: to_date + lightspark_node_to_daily_liquidity_forecasts_connection_direction: direction + lightspark_node_to_daily_liquidity_forecasts_connection_entities: entities { + __typename + daily_liquidity_forecast_date: date + daily_liquidity_forecast_direction: direction + daily_liquidity_forecast_amount: amount { + __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 + } + } +} +"; diff --git a/lightspark/src/objects/lightspark_node_with_o_s_k.rs b/lightspark/src/objects/lightspark_node_with_o_s_k.rs index 2b33c84..042a59a 100644 --- a/lightspark/src/objects/lightspark_node_with_o_s_k.rs +++ b/lightspark/src/objects/lightspark_node_with_o_s_k.rs @@ -1,26 +1,29 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use crate::error::Error; +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::node_address_type::NodeAddressType; +use crate::objects::node::Node; +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::{Deserialize, Serialize}; use std::collections::HashMap; -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::entity::Entity; +use crate::objects::lightning_payment_direction::LightningPaymentDirection; +use crate::objects::lightspark_node::LightsparkNode; use crate::objects::lightspark_node_status::LightsparkNodeStatus; use crate::objects::lightspark_node_to_channels_connection::LightsparkNodeToChannelsConnection; -use crate::objects::node::Node; +use crate::objects::lightspark_node_to_daily_liquidity_forecasts_connection::LightsparkNodeToDailyLiquidityForecastsConnection; +use crate::objects::node_address_type::NodeAddressType; use crate::objects::node_to_addresses_connection::NodeToAddressesConnection; use crate::objects::secret::Secret; -use crate::types::custom_date_formats::custom_date_format; -use crate::types::get_entity::GetEntity; -use crate::types::graphql_requester::GraphQLRequester; -use chrono::{DateTime, Utc}; +use chrono::NaiveDate; use serde_json::Value; use std::vec::Vec; @@ -539,4 +542,49 @@ impl LightsparkNodeWithOSK { let result = serde_json::from_value(json).map_err(Error::JsonError)?; Ok(result) } + + pub async fn get_daily_liquidity_forecasts( + &self, + requester: &impl GraphQLRequester, + from_date: NaiveDate, + to_date: NaiveDate, + direction: LightningPaymentDirection, + ) -> Result { + let query = "query FetchLightsparkNodeToDailyLiquidityForecastsConnection($entity_id: ID!, $from_date: Date!, $to_date: Date!, $direction: LightningPaymentDirection!) { + entity(id: $entity_id) { + ... on LightsparkNodeWithOSK { + daily_liquidity_forecasts(, from_date: $from_date, to_date: $to_date, direction: $direction) { + __typename + lightspark_node_to_daily_liquidity_forecasts_connection_from_date: from_date + lightspark_node_to_daily_liquidity_forecasts_connection_to_date: to_date + lightspark_node_to_daily_liquidity_forecasts_connection_direction: direction + lightspark_node_to_daily_liquidity_forecasts_connection_entities: entities { + __typename + daily_liquidity_forecast_date: date + daily_liquidity_forecast_direction: direction + daily_liquidity_forecast_amount: amount { + __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 + } + } + } + } + } +}"; + let mut variables: HashMap<&str, Value> = HashMap::new(); + variables.insert("entity_id", self.id.clone().into()); + variables.insert("from_date", from_date.format("%Y-%m-%d").to_string().into()); + variables.insert("to_date", to_date.format("%Y-%m-%d").to_string().into()); + variables.insert("direction", direction.into()); + + let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; + let result = requester.execute_graphql(query, Some(value)).await?; + let json = result["entity"]["daily_liquidity_forecasts"].clone(); + let result = serde_json::from_value(json).map_err(Error::JsonError)?; + Ok(result) + } } diff --git a/lightspark/src/objects/lightspark_node_with_remote_signing.rs b/lightspark/src/objects/lightspark_node_with_remote_signing.rs index a163d8c..71789e6 100644 --- a/lightspark/src/objects/lightspark_node_with_remote_signing.rs +++ b/lightspark/src/objects/lightspark_node_with_remote_signing.rs @@ -1,25 +1,28 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use crate::error::Error; +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::node_address_type::NodeAddressType; +use crate::objects::node::Node; +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::{Deserialize, Serialize}; use std::collections::HashMap; -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::entity::Entity; +use crate::objects::lightning_payment_direction::LightningPaymentDirection; +use crate::objects::lightspark_node::LightsparkNode; use crate::objects::lightspark_node_status::LightsparkNodeStatus; use crate::objects::lightspark_node_to_channels_connection::LightsparkNodeToChannelsConnection; -use crate::objects::node::Node; +use crate::objects::lightspark_node_to_daily_liquidity_forecasts_connection::LightsparkNodeToDailyLiquidityForecastsConnection; +use crate::objects::node_address_type::NodeAddressType; use crate::objects::node_to_addresses_connection::NodeToAddressesConnection; -use crate::types::custom_date_formats::custom_date_format; -use crate::types::get_entity::GetEntity; -use crate::types::graphql_requester::GraphQLRequester; -use chrono::{DateTime, Utc}; +use chrono::NaiveDate; use serde_json::Value; use std::vec::Vec; @@ -529,4 +532,49 @@ impl LightsparkNodeWithRemoteSigning { let result = serde_json::from_value(json).map_err(Error::JsonError)?; Ok(result) } + + pub async fn get_daily_liquidity_forecasts( + &self, + requester: &impl GraphQLRequester, + from_date: NaiveDate, + to_date: NaiveDate, + direction: LightningPaymentDirection, + ) -> Result { + let query = "query FetchLightsparkNodeToDailyLiquidityForecastsConnection($entity_id: ID!, $from_date: Date!, $to_date: Date!, $direction: LightningPaymentDirection!) { + entity(id: $entity_id) { + ... on LightsparkNodeWithRemoteSigning { + daily_liquidity_forecasts(, from_date: $from_date, to_date: $to_date, direction: $direction) { + __typename + lightspark_node_to_daily_liquidity_forecasts_connection_from_date: from_date + lightspark_node_to_daily_liquidity_forecasts_connection_to_date: to_date + lightspark_node_to_daily_liquidity_forecasts_connection_direction: direction + lightspark_node_to_daily_liquidity_forecasts_connection_entities: entities { + __typename + daily_liquidity_forecast_date: date + daily_liquidity_forecast_direction: direction + daily_liquidity_forecast_amount: amount { + __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 + } + } + } + } + } +}"; + let mut variables: HashMap<&str, Value> = HashMap::new(); + variables.insert("entity_id", self.id.clone().into()); + variables.insert("from_date", from_date.format("%Y-%m-%d").to_string().into()); + variables.insert("to_date", to_date.format("%Y-%m-%d").to_string().into()); + variables.insert("direction", direction.into()); + + let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; + let result = requester.execute_graphql(query, Some(value)).await?; + let json = result["entity"]["daily_liquidity_forecasts"].clone(); + let result = serde_json::from_value(json).map_err(Error::JsonError)?; + Ok(result) + } } diff --git a/lightspark/src/objects/mod.rs b/lightspark/src/objects/mod.rs index e20af64..a57837c 100644 --- a/lightspark/src/objects/mod.rs +++ b/lightspark/src/objects/mod.rs @@ -45,6 +45,7 @@ pub mod create_uma_invitation_output; pub mod create_uma_invoice_input; pub mod currency_amount; pub mod currency_unit; +pub mod daily_liquidity_forecast; pub mod decline_to_sign_messages_input; pub mod decline_to_sign_messages_output; pub mod delete_api_token_input; @@ -70,11 +71,13 @@ pub mod invoice_type; pub mod lightning_fee_estimate_for_invoice_input; pub mod lightning_fee_estimate_for_node_input; pub mod lightning_fee_estimate_output; +pub mod lightning_payment_direction; pub mod lightning_transaction; pub mod lightspark_node; pub mod lightspark_node_owner; pub mod lightspark_node_status; pub mod lightspark_node_to_channels_connection; +pub mod lightspark_node_to_daily_liquidity_forecasts_connection; pub mod lightspark_node_with_o_s_k; pub mod lightspark_node_with_remote_signing; pub mod node; @@ -144,6 +147,8 @@ pub mod wallet_to_transactions_connection; pub mod wallet_to_withdrawal_requests_connection; pub mod webhook_event_type; pub mod withdrawal; +pub mod withdrawal_fee_estimate_input; +pub mod withdrawal_fee_estimate_output; pub mod withdrawal_mode; pub mod withdrawal_request; pub mod withdrawal_request_status; diff --git a/lightspark/src/objects/outgoing_payment.rs b/lightspark/src/objects/outgoing_payment.rs index 2f366ae..d38bc13 100644 --- a/lightspark/src/objects/outgoing_payment.rs +++ b/lightspark/src/objects/outgoing_payment.rs @@ -1,25 +1,25 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use crate::error::Error; use crate::objects::currency_amount::CurrencyAmount; -use crate::objects::entity::Entity; use crate::objects::outgoing_payment_to_attempts_connection::OutgoingPaymentToAttemptsConnection; -use crate::objects::payment_request_data::PaymentRequestDataEnum; -use crate::objects::post_transaction_data::PostTransactionData; -use crate::objects::transaction_status::TransactionStatus; +use crate::objects::payment_failure_reason::PaymentFailureReason; +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::{Deserialize, Serialize}; -use serde_json::Value; use std::collections::HashMap; -use crate::error::Error; +use crate::objects::entity::Entity; use crate::objects::lightning_transaction::LightningTransaction; -use crate::objects::payment_failure_reason::PaymentFailureReason; +use crate::objects::payment_request_data::PaymentRequestDataEnum; +use crate::objects::post_transaction_data::PostTransactionData; use crate::objects::rich_text::RichText; use crate::objects::transaction::Transaction; -use crate::types::custom_date_formats::custom_date_format; +use crate::objects::transaction_status::TransactionStatus; use crate::types::custom_date_formats::custom_date_format_option; -use crate::types::get_entity::GetEntity; -use crate::types::graphql_requester::GraphQLRequester; -use chrono::{DateTime, Utc}; +use serde_json::Value; use std::vec::Vec; /// This object represents a Lightning Network payment sent from a Lightspark Node. You can retrieve this object to receive payment related information about any payment sent from your Lightspark Node on the Lightning Network. diff --git a/lightspark/src/objects/wallet_to_payment_requests_connection.rs b/lightspark/src/objects/wallet_to_payment_requests_connection.rs index 19aba9c..3936fba 100644 --- a/lightspark/src/objects/wallet_to_payment_requests_connection.rs +++ b/lightspark/src/objects/wallet_to_payment_requests_connection.rs @@ -1,10 +1,10 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use serde::{Deserialize, Serialize}; +use std::vec::Vec; + use crate::objects::connection::Connection; use crate::objects::page_info::PageInfo; use crate::objects::payment_request::PaymentRequestEnum; -use serde::{Deserialize, Serialize}; - -use std::vec::Vec; #[derive(Debug, Clone, Deserialize, Serialize)] pub struct WalletToPaymentRequestsConnection { diff --git a/lightspark/src/objects/wallet_to_transactions_connection.rs b/lightspark/src/objects/wallet_to_transactions_connection.rs index 04f04c9..e5f1893 100644 --- a/lightspark/src/objects/wallet_to_transactions_connection.rs +++ b/lightspark/src/objects/wallet_to_transactions_connection.rs @@ -1,10 +1,10 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved -use crate::objects::connection::Connection; +use crate::objects::transaction::TransactionEnum; use serde::{Deserialize, Serialize}; +use std::vec::Vec; +use crate::objects::connection::Connection; use crate::objects::page_info::PageInfo; -use crate::objects::transaction::TransactionEnum; -use std::vec::Vec; #[derive(Debug, Clone, Deserialize, Serialize)] pub struct WalletToTransactionsConnection { diff --git a/lightspark/src/objects/withdrawal_fee_estimate_input.rs b/lightspark/src/objects/withdrawal_fee_estimate_input.rs new file mode 100644 index 0000000..301031d --- /dev/null +++ b/lightspark/src/objects/withdrawal_fee_estimate_input.rs @@ -0,0 +1,15 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use crate::objects::withdrawal_mode::WithdrawalMode; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct WithdrawalFeeEstimateInput { + /// The node from which you'd like to make the withdrawal. + pub node_id: String, + + /// The amount you want to withdraw from this node in Satoshis. Use the special value -1 to withdrawal all funds from this node. + pub amount_sats: i64, + + /// The strategy that should be used to withdraw the funds from this node. + pub withdrawal_mode: WithdrawalMode, +} diff --git a/lightspark/src/objects/withdrawal_fee_estimate_output.rs b/lightspark/src/objects/withdrawal_fee_estimate_output.rs new file mode 100644 index 0000000..07fb839 --- /dev/null +++ b/lightspark/src/objects/withdrawal_fee_estimate_output.rs @@ -0,0 +1,24 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use crate::objects::currency_amount::CurrencyAmount; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct WithdrawalFeeEstimateOutput { + /// The estimated fee for the withdrawal. + #[serde(rename = "withdrawal_fee_estimate_output_fee_estimate")] + pub fee_estimate: CurrencyAmount, +} + +pub const FRAGMENT: &str = " +fragment WithdrawalFeeEstimateOutputFragment on WithdrawalFeeEstimateOutput { + __typename + withdrawal_fee_estimate_output_fee_estimate: fee_estimate { + __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 + } +} +";