From 9e1f44a2a58c78439d8e3bae82a120d66ea77019 Mon Sep 17 00:00:00 2001 From: Jeremy Klein Date: Fri, 1 Dec 2023 16:08:00 -0800 Subject: [PATCH] Add withdrawalRequests info for wallets and accounts. --- lightspark/src/objects/account.rs | 93 ++++++++++++++++++ .../account_to_payment_requests_connection.rs | 7 ++ .../account_to_transactions_connection.rs | 3 + ...count_to_withdrawal_requests_connection.rs | 59 ++++++++++++ lightspark/src/objects/connection.rs | 16 ++++ lightspark/src/objects/invoice_data.rs | 10 ++ lightspark/src/objects/lightspark_node.rs | 9 +- .../src/objects/lightspark_node_with_o_s_k.rs | 12 ++- .../lightspark_node_with_remote_signing.rs | 7 +- lightspark/src/objects/mod.rs | 2 + lightspark/src/objects/outgoing_payment.rs | 5 +- lightspark/src/objects/wallet.rs | 94 +++++++++++++++++++ .../wallet_to_payment_requests_connection.rs | 7 ++ .../wallet_to_transactions_connection.rs | 3 + ...allet_to_withdrawal_requests_connection.rs | 58 ++++++++++++ lightspark/src/objects/withdrawal_request.rs | 24 +++++ 16 files changed, 403 insertions(+), 6 deletions(-) create mode 100644 lightspark/src/objects/account_to_withdrawal_requests_connection.rs create mode 100644 lightspark/src/objects/wallet_to_withdrawal_requests_connection.rs diff --git a/lightspark/src/objects/account.rs b/lightspark/src/objects/account.rs index 94818aa..a24b266 100644 --- a/lightspark/src/objects/account.rs +++ b/lightspark/src/objects/account.rs @@ -6,6 +6,7 @@ use crate::objects::account_to_nodes_connection::AccountToNodesConnection; use crate::objects::account_to_payment_requests_connection::AccountToPaymentRequestsConnection; use crate::objects::account_to_transactions_connection::AccountToTransactionsConnection; use crate::objects::account_to_wallets_connection::AccountToWalletsConnection; +use crate::objects::account_to_withdrawal_requests_connection::AccountToWithdrawalRequestsConnection; use crate::objects::bitcoin_network::BitcoinNetwork; use crate::objects::blockchain_balance::BlockchainBalance; use crate::objects::currency_amount::CurrencyAmount; @@ -14,6 +15,7 @@ use crate::objects::lightspark_node_owner::LightsparkNodeOwner; use crate::objects::transaction_failures::TransactionFailures; use crate::objects::transaction_status::TransactionStatus; use crate::objects::transaction_type::TransactionType; +use crate::objects::withdrawal_request_status::WithdrawalRequestStatus; use crate::types::custom_date_formats::custom_date_format; use crate::types::get_entity::GetEntity; use crate::types::graphql_requester::GraphQLRequester; @@ -1756,6 +1758,97 @@ impl Account { Ok(result) } + #[allow(clippy::too_many_arguments)] + pub async fn get_withdrawal_requests( + &self, + requester: &impl GraphQLRequester, + first: Option, + after: Option, + bitcoin_networks: Option>, + statuses: Option>, + node_ids: Option>, + after_date: Option>, + before_date: Option>, + ) -> Result { + let query = "query FetchAccountToWithdrawalRequestsConnection($entity_id: ID!, $first: Int, $after: String, $bitcoin_networks: [BitcoinNetwork!], $statuses: [WithdrawalRequestStatus!], $node_ids: [ID!], $after_date: DateTime, $before_date: DateTime) { + entity(id: $entity_id) { + ... on Account { + withdrawal_requests(, first: $first, after: $after, bitcoin_networks: $bitcoin_networks, statuses: $statuses, node_ids: $node_ids, after_date: $after_date, before_date: $before_date) { + __typename + account_to_withdrawal_requests_connection_count: count + account_to_withdrawal_requests_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_withdrawal_requests_connection_entities: entities { + __typename + withdrawal_request_id: id + withdrawal_request_created_at: created_at + withdrawal_request_updated_at: updated_at + withdrawal_request_requested_amount: requested_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 + } + withdrawal_request_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 + } + withdrawal_request_estimated_amount: estimated_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 + } + withdrawal_request_amount_withdrawn: amount_withdrawn { + __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 + } + withdrawal_request_bitcoin_address: bitcoin_address + withdrawal_request_withdrawal_mode: withdrawal_mode + withdrawal_request_status: status + withdrawal_request_completed_at: completed_at + withdrawal_request_withdrawal: withdrawal { + id + } + } + } + } + } +}"; + let mut variables: HashMap<&str, Value> = HashMap::new(); + variables.insert("entity_id", self.id.clone().into()); + variables.insert("first", first.into()); + variables.insert("after", after.into()); + variables.insert("bitcoin_networks", bitcoin_networks.into()); + variables.insert("statuses", statuses.into()); + variables.insert("node_ids", node_ids.into()); + variables.insert("after_date", after_date.map(|dt| dt.to_rfc3339()).into()); + variables.insert("before_date", before_date.map(|dt| dt.to_rfc3339()).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"]["withdrawal_requests"].clone(); + let result = serde_json::from_value(json).map_err(Error::JsonError)?; + Ok(result) + } + pub async fn get_wallets( &self, requester: &impl GraphQLRequester, diff --git a/lightspark/src/objects/account_to_payment_requests_connection.rs b/lightspark/src/objects/account_to_payment_requests_connection.rs index 7d7e614..ce6fcea 100644 --- a/lightspark/src/objects/account_to_payment_requests_connection.rs +++ b/lightspark/src/objects/account_to_payment_requests_connection.rs @@ -1,9 +1,16 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +<<<<<<< Updated upstream use serde::{Deserialize, Serialize}; use crate::objects::connection::Connection; use crate::objects::page_info::PageInfo; use crate::objects::payment_request::PaymentRequestEnum; +======= +use crate::objects::connection::Connection; +use crate::objects::page_info::PageInfo; +use crate::objects::payment_request::PaymentRequestEnum; +use serde::{Deserialize, Serialize}; +>>>>>>> Stashed changes use std::vec::Vec; #[derive(Debug, Clone, Deserialize, Serialize)] diff --git a/lightspark/src/objects/account_to_transactions_connection.rs b/lightspark/src/objects/account_to_transactions_connection.rs index defc558..d366bb5 100644 --- a/lightspark/src/objects/account_to_transactions_connection.rs +++ b/lightspark/src/objects/account_to_transactions_connection.rs @@ -1,10 +1,13 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved use crate::objects::transaction::TransactionEnum; use serde::{Deserialize, Serialize}; +<<<<<<< Updated upstream use crate::objects::connection::Connection; use crate::objects::currency_amount::CurrencyAmount; use crate::objects::page_info::PageInfo; +======= +>>>>>>> Stashed changes use std::vec::Vec; #[derive(Debug, Clone, Deserialize, Serialize)] diff --git a/lightspark/src/objects/account_to_withdrawal_requests_connection.rs b/lightspark/src/objects/account_to_withdrawal_requests_connection.rs new file mode 100644 index 0000000..1c0b10c --- /dev/null +++ b/lightspark/src/objects/account_to_withdrawal_requests_connection.rs @@ -0,0 +1,59 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use crate::objects::connection::Connection; +use crate::objects::page_info::PageInfo; +use crate::objects::withdrawal_request::WithdrawalRequest; +use serde::{Deserialize, Serialize}; +use std::vec::Vec; + +/// A connection between an account and its past and present withdrawal requests. +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct AccountToWithdrawalRequestsConnection { + /// 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). + #[serde(rename = "account_to_withdrawal_requests_connection_count")] + pub count: i64, + + /// An object that holds pagination information about the objects in this connection. + #[serde(rename = "account_to_withdrawal_requests_connection_page_info")] + pub page_info: PageInfo, + + /// The withdrawal requests for the current page of this connection. + #[serde(rename = "account_to_withdrawal_requests_connection_entities")] + pub entities: Vec, + + /// The typename of the object + #[serde(rename = "__typename")] + pub typename: String, +} + +impl Connection for AccountToWithdrawalRequestsConnection { + /// 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 { + "AccountToWithdrawalRequestsConnection" + } +} + +pub const FRAGMENT: &str = " +fragment AccountToWithdrawalRequestsConnectionFragment on AccountToWithdrawalRequestsConnection { + __typename + account_to_withdrawal_requests_connection_count: count + account_to_withdrawal_requests_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_withdrawal_requests_connection_entities: entities { + id + } +} +"; diff --git a/lightspark/src/objects/connection.rs b/lightspark/src/objects/connection.rs index e85cffb..6660794 100644 --- a/lightspark/src/objects/connection.rs +++ b/lightspark/src/objects/connection.rs @@ -5,12 +5,14 @@ use super::account_to_nodes_connection::AccountToNodesConnection; use super::account_to_payment_requests_connection::AccountToPaymentRequestsConnection; use super::account_to_transactions_connection::AccountToTransactionsConnection; use super::account_to_wallets_connection::AccountToWalletsConnection; +use super::account_to_withdrawal_requests_connection::AccountToWithdrawalRequestsConnection; use super::incoming_payment_to_attempts_connection::IncomingPaymentToAttemptsConnection; use super::lightspark_node_to_channels_connection::LightsparkNodeToChannelsConnection; use super::outgoing_payment_attempt_to_hops_connection::OutgoingPaymentAttemptToHopsConnection; use super::outgoing_payment_to_attempts_connection::OutgoingPaymentToAttemptsConnection; use super::wallet_to_payment_requests_connection::WalletToPaymentRequestsConnection; use super::wallet_to_transactions_connection::WalletToTransactionsConnection; +use super::wallet_to_withdrawal_requests_connection::WalletToWithdrawalRequestsConnection; use crate::objects::page_info::PageInfo; use serde::{Deserialize, Deserializer, Serialize}; use serde_json::Value; @@ -33,12 +35,14 @@ pub enum ConnectionEnum { AccountToPaymentRequestsConnection(AccountToPaymentRequestsConnection), AccountToTransactionsConnection(AccountToTransactionsConnection), AccountToWalletsConnection(AccountToWalletsConnection), + AccountToWithdrawalRequestsConnection(AccountToWithdrawalRequestsConnection), IncomingPaymentToAttemptsConnection(IncomingPaymentToAttemptsConnection), LightsparkNodeToChannelsConnection(LightsparkNodeToChannelsConnection), OutgoingPaymentAttemptToHopsConnection(OutgoingPaymentAttemptToHopsConnection), OutgoingPaymentToAttemptsConnection(OutgoingPaymentToAttemptsConnection), WalletToPaymentRequestsConnection(WalletToPaymentRequestsConnection), WalletToTransactionsConnection(WalletToTransactionsConnection), + WalletToWithdrawalRequestsConnection(WalletToWithdrawalRequestsConnection), } impl<'de> Deserialize<'de> for ConnectionEnum { @@ -81,6 +85,12 @@ impl<'de> Deserialize<'de> for ConnectionEnum { })?; Ok(ConnectionEnum::AccountToWalletsConnection(obj)) } + "AccountToWithdrawalRequestsConnection" => { + let obj = AccountToWithdrawalRequestsConnection::deserialize(value).map_err( + |err| serde::de::Error::custom(format!("Serde JSON Error {}", err)), + )?; + Ok(ConnectionEnum::AccountToWithdrawalRequestsConnection(obj)) + } "IncomingPaymentToAttemptsConnection" => { let obj = IncomingPaymentToAttemptsConnection::deserialize(value).map_err(|err| { @@ -122,6 +132,12 @@ impl<'de> Deserialize<'de> for ConnectionEnum { })?; Ok(ConnectionEnum::WalletToTransactionsConnection(obj)) } + "WalletToWithdrawalRequestsConnection" => { + let obj = WalletToWithdrawalRequestsConnection::deserialize(value).map_err( + |err| serde::de::Error::custom(format!("Serde JSON Error {}", err)), + )?; + Ok(ConnectionEnum::WalletToWithdrawalRequestsConnection(obj)) + } _ => Err(serde::de::Error::custom("unknown typename")), } diff --git a/lightspark/src/objects/invoice_data.rs b/lightspark/src/objects/invoice_data.rs index 3fe5c9c..c80798b 100644 --- a/lightspark/src/objects/invoice_data.rs +++ b/lightspark/src/objects/invoice_data.rs @@ -1,4 +1,5 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +<<<<<<< Updated upstream use crate::objects::payment_request_data::PaymentRequestData; use crate::types::custom_date_formats::custom_date_format; use serde::{Deserialize, Serialize}; @@ -6,6 +7,15 @@ use serde::{Deserialize, Serialize}; use crate::objects::bitcoin_network::BitcoinNetwork; use crate::objects::currency_amount::CurrencyAmount; use crate::objects::node::NodeEnum; +======= +use crate::objects::bitcoin_network::BitcoinNetwork; +use crate::objects::currency_amount::CurrencyAmount; +use crate::types::custom_date_formats::custom_date_format; +use serde::{Deserialize, Serialize}; + +use crate::objects::node::NodeEnum; +use crate::objects::payment_request_data::PaymentRequestData; +>>>>>>> Stashed changes 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. diff --git a/lightspark/src/objects/lightspark_node.rs b/lightspark/src/objects/lightspark_node.rs index dffa629..9976f09 100644 --- a/lightspark/src/objects/lightspark_node.rs +++ b/lightspark/src/objects/lightspark_node.rs @@ -3,14 +3,21 @@ use crate::objects::entity::Entity; use crate::objects::node::Node; use super::lightspark_node_with_o_s_k::LightsparkNodeWithOSK; +use crate::objects::currency_amount::CurrencyAmount; +use crate::objects::entity::Entity; +use crate::objects::node::Node; +use serde_json::Value; + use super::lightspark_node_with_remote_signing::LightsparkNodeWithRemoteSigning; use crate::objects::balances::Balances; use crate::objects::blockchain_balance::BlockchainBalance; +<<<<<<< Updated upstream use crate::objects::currency_amount::CurrencyAmount; +======= +>>>>>>> Stashed changes 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 { 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 2b3c287..3ceae7f 100644 --- a/lightspark/src/objects/lightspark_node_with_o_s_k.rs +++ b/lightspark/src/objects/lightspark_node_with_o_s_k.rs @@ -1,22 +1,30 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved use crate::error::Error; use crate::objects::balances::Balances; +<<<<<<< Updated upstream +======= +use crate::objects::bitcoin_network::BitcoinNetwork; +>>>>>>> Stashed changes 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::lightspark_node_to_channels_connection::LightsparkNodeToChannelsConnection; use crate::objects::node::Node; 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::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 crate::objects::entity::Entity; +use crate::types::graphql_requester::GraphQLRequester; use std::collections::HashMap; +use std::vec::Vec; use crate::objects::bitcoin_network::BitcoinNetwork; use crate::objects::lightspark_node_status::LightsparkNodeStatus; diff --git a/lightspark/src/objects/lightspark_node_with_remote_signing.rs b/lightspark/src/objects/lightspark_node_with_remote_signing.rs index a100fa8..e889908 100644 --- a/lightspark/src/objects/lightspark_node_with_remote_signing.rs +++ b/lightspark/src/objects/lightspark_node_with_remote_signing.rs @@ -5,18 +5,21 @@ 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::lightspark_node_to_channels_connection::LightsparkNodeToChannelsConnection; 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 serde_json::Value; + +use crate::objects::entity::Entity; +use crate::types::graphql_requester::GraphQLRequester; use std::collections::HashMap; +use std::vec::Vec; use crate::objects::lightspark_node_status::LightsparkNodeStatus; use crate::objects::node_address_type::NodeAddressType; diff --git a/lightspark/src/objects/mod.rs b/lightspark/src/objects/mod.rs index 3b1bce0..e20af64 100644 --- a/lightspark/src/objects/mod.rs +++ b/lightspark/src/objects/mod.rs @@ -7,6 +7,7 @@ pub mod account_to_nodes_connection; pub mod account_to_payment_requests_connection; pub mod account_to_transactions_connection; pub mod account_to_wallets_connection; +pub mod account_to_withdrawal_requests_connection; pub mod api_token; pub mod balances; pub mod bitcoin_network; @@ -140,6 +141,7 @@ pub mod wallet; pub mod wallet_status; pub mod wallet_to_payment_requests_connection; pub mod wallet_to_transactions_connection; +pub mod wallet_to_withdrawal_requests_connection; pub mod webhook_event_type; pub mod withdrawal; pub mod withdrawal_mode; diff --git a/lightspark/src/objects/outgoing_payment.rs b/lightspark/src/objects/outgoing_payment.rs index 0805919..ed832c7 100644 --- a/lightspark/src/objects/outgoing_payment.rs +++ b/lightspark/src/objects/outgoing_payment.rs @@ -1,10 +1,13 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +<<<<<<< Updated upstream +======= +use crate::objects::lightning_transaction::LightningTransaction; +>>>>>>> Stashed changes use serde::{Deserialize, Serialize}; use crate::error::Error; use crate::objects::currency_amount::CurrencyAmount; use crate::objects::entity::Entity; -use crate::objects::lightning_transaction::LightningTransaction; use crate::objects::outgoing_payment_to_attempts_connection::OutgoingPaymentToAttemptsConnection; use crate::objects::payment_failure_reason::PaymentFailureReason; use crate::objects::payment_request_data::PaymentRequestDataEnum; diff --git a/lightspark/src/objects/wallet.rs b/lightspark/src/objects/wallet.rs index 56c03c6..8cf8424 100644 --- a/lightspark/src/objects/wallet.rs +++ b/lightspark/src/objects/wallet.rs @@ -9,6 +9,8 @@ use crate::objects::transaction_type::TransactionType; use crate::objects::wallet_status::WalletStatus; use crate::objects::wallet_to_payment_requests_connection::WalletToPaymentRequestsConnection; use crate::objects::wallet_to_transactions_connection::WalletToTransactionsConnection; +use crate::objects::wallet_to_withdrawal_requests_connection::WalletToWithdrawalRequestsConnection; +use crate::objects::withdrawal_request_status::WithdrawalRequestStatus; use crate::types::custom_date_formats::custom_date_format; use crate::types::custom_date_formats::custom_date_format_option; use crate::types::entity_wrapper::EntityWrapper; @@ -1135,6 +1137,98 @@ impl Wallet { Ok(result) } + pub async fn get_withdrawal_requests( + &self, + requester: &impl GraphQLRequester, + first: Option, + after: Option, + statuses: Option>, + created_after_date: Option>, + created_before_date: Option>, + ) -> Result { + let query = "query FetchWalletToWithdrawalRequestsConnection($entity_id: ID!, $first: Int, $after: ID, $statuses: [WithdrawalRequestStatus!], $created_after_date: DateTime, $created_before_date: DateTime) { + entity(id: $entity_id) { + ... on Wallet { + withdrawal_requests(, first: $first, after: $after, statuses: $statuses, created_after_date: $created_after_date, created_before_date: $created_before_date) { + __typename + wallet_to_withdrawal_requests_connection_count: count + wallet_to_withdrawal_requests_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 + } + wallet_to_withdrawal_requests_connection_entities: entities { + __typename + withdrawal_request_id: id + withdrawal_request_created_at: created_at + withdrawal_request_updated_at: updated_at + withdrawal_request_requested_amount: requested_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 + } + withdrawal_request_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 + } + withdrawal_request_estimated_amount: estimated_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 + } + withdrawal_request_amount_withdrawn: amount_withdrawn { + __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 + } + withdrawal_request_bitcoin_address: bitcoin_address + withdrawal_request_withdrawal_mode: withdrawal_mode + withdrawal_request_status: status + withdrawal_request_completed_at: completed_at + withdrawal_request_withdrawal: withdrawal { + id + } + } + } + } + } +}"; + let mut variables: HashMap<&str, Value> = HashMap::new(); + variables.insert("entity_id", self.id.clone().into()); + variables.insert("first", first.into()); + variables.insert("after", after.into()); + variables.insert("statuses", statuses.into()); + variables.insert( + "created_after_date", + created_after_date.map(|dt| dt.to_rfc3339()).into(), + ); + variables.insert( + "created_before_date", + created_before_date.map(|dt| dt.to_rfc3339()).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"]["withdrawal_requests"].clone(); + let result = serde_json::from_value(json).map_err(Error::JsonError)?; + Ok(result) + } + pub async fn get_total_amount_sent( &self, requester: &impl GraphQLRequester, diff --git a/lightspark/src/objects/wallet_to_payment_requests_connection.rs b/lightspark/src/objects/wallet_to_payment_requests_connection.rs index eeac2c5..502a982 100644 --- a/lightspark/src/objects/wallet_to_payment_requests_connection.rs +++ b/lightspark/src/objects/wallet_to_payment_requests_connection.rs @@ -1,9 +1,16 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +<<<<<<< Updated upstream use serde::{Deserialize, Serialize}; use crate::objects::connection::Connection; use crate::objects::page_info::PageInfo; use crate::objects::payment_request::PaymentRequestEnum; +======= +use crate::objects::connection::Connection; +use crate::objects::page_info::PageInfo; +use crate::objects::payment_request::PaymentRequestEnum; +use serde::{Deserialize, Serialize}; +>>>>>>> Stashed changes use std::vec::Vec; #[derive(Debug, Clone, Deserialize, Serialize)] diff --git a/lightspark/src/objects/wallet_to_transactions_connection.rs b/lightspark/src/objects/wallet_to_transactions_connection.rs index e7a7b7f..b96a2c0 100644 --- a/lightspark/src/objects/wallet_to_transactions_connection.rs +++ b/lightspark/src/objects/wallet_to_transactions_connection.rs @@ -2,8 +2,11 @@ use crate::objects::connection::Connection; use crate::objects::transaction::TransactionEnum; use serde::{Deserialize, Serialize}; +<<<<<<< Updated upstream use crate::objects::page_info::PageInfo; +======= +>>>>>>> Stashed changes use std::vec::Vec; #[derive(Debug, Clone, Deserialize, Serialize)] diff --git a/lightspark/src/objects/wallet_to_withdrawal_requests_connection.rs b/lightspark/src/objects/wallet_to_withdrawal_requests_connection.rs new file mode 100644 index 0000000..c897d1a --- /dev/null +++ b/lightspark/src/objects/wallet_to_withdrawal_requests_connection.rs @@ -0,0 +1,58 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use crate::objects::connection::Connection; +use crate::objects::page_info::PageInfo; +use crate::objects::withdrawal_request::WithdrawalRequest; +use serde::{Deserialize, Serialize}; +use std::vec::Vec; + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct WalletToWithdrawalRequestsConnection { + /// 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). + #[serde(rename = "wallet_to_withdrawal_requests_connection_count")] + pub count: i64, + + /// An object that holds pagination information about the objects in this connection. + #[serde(rename = "wallet_to_withdrawal_requests_connection_page_info")] + pub page_info: PageInfo, + + /// The withdrawal requests for the current page of this connection. + #[serde(rename = "wallet_to_withdrawal_requests_connection_entities")] + pub entities: Vec, + + /// The typename of the object + #[serde(rename = "__typename")] + pub typename: String, +} + +impl Connection for WalletToWithdrawalRequestsConnection { + /// 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 { + "WalletToWithdrawalRequestsConnection" + } +} + +pub const FRAGMENT: &str = " +fragment WalletToWithdrawalRequestsConnectionFragment on WalletToWithdrawalRequestsConnection { + __typename + wallet_to_withdrawal_requests_connection_count: count + wallet_to_withdrawal_requests_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 + } + wallet_to_withdrawal_requests_connection_entities: entities { + id + } +} +"; diff --git a/lightspark/src/objects/withdrawal_request.rs b/lightspark/src/objects/withdrawal_request.rs index 5410b1f..236b802 100644 --- a/lightspark/src/objects/withdrawal_request.rs +++ b/lightspark/src/objects/withdrawal_request.rs @@ -31,6 +31,10 @@ pub struct WithdrawalRequest { #[serde(with = "custom_date_format", rename = "withdrawal_request_updated_at")] pub updated_at: DateTime, + /// The requested amount of money to be withdrawn. If the requested amount is -1, it means to withdraw all. + #[serde(rename = "withdrawal_request_requested_amount")] + pub requested_amount: CurrencyAmount, + /// The amount of money that should be withdrawn in this request. #[serde(rename = "withdrawal_request_amount")] pub amount: CurrencyAmount, @@ -39,6 +43,10 @@ pub struct WithdrawalRequest { #[serde(rename = "withdrawal_request_estimated_amount")] pub estimated_amount: Option, + /// The actual amount that is withdrawn. It will be set once the request is completed. + #[serde(rename = "withdrawal_request_amount_withdrawn")] + pub amount_withdrawn: Option, + /// The bitcoin address where the funds should be sent. #[serde(rename = "withdrawal_request_bitcoin_address")] pub bitcoin_address: String, @@ -112,6 +120,14 @@ fragment WithdrawalRequestFragment on WithdrawalRequest { withdrawal_request_id: id withdrawal_request_created_at: created_at withdrawal_request_updated_at: updated_at + withdrawal_request_requested_amount: requested_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 + } withdrawal_request_amount: amount { __typename currency_amount_original_value: original_value @@ -128,6 +144,14 @@ fragment WithdrawalRequestFragment on WithdrawalRequest { currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded currency_amount_preferred_currency_value_approx: preferred_currency_value_approx } + withdrawal_request_amount_withdrawn: amount_withdrawn { + __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 + } withdrawal_request_bitcoin_address: bitcoin_address withdrawal_request_withdrawal_mode: withdrawal_mode withdrawal_request_status: status