Skip to content

Commit

Permalink
Add withdrawalRequests info for wallets and accounts.
Browse files Browse the repository at this point in the history
  • Loading branch information
jklein24 committed Dec 2, 2023
1 parent 51c11fd commit 9e1f44a
Show file tree
Hide file tree
Showing 16 changed files with 403 additions and 6 deletions.
93 changes: 93 additions & 0 deletions lightspark/src/objects/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<i64>,
after: Option<String>,
bitcoin_networks: Option<Vec<BitcoinNetwork>>,
statuses: Option<Vec<WithdrawalRequestStatus>>,
node_ids: Option<Vec<String>>,
after_date: Option<DateTime<Utc>>,
before_date: Option<DateTime<Utc>>,
) -> Result<AccountToWithdrawalRequestsConnection, Error> {
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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
<<<<<<< Updated upstream

Check failure on line 2 in lightspark/src/objects/account_to_payment_requests_connection.rs

View workflow job for this annotation

GitHub Actions / test

encountered diff marker
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)]
Expand Down
3 changes: 3 additions & 0 deletions lightspark/src/objects/account_to_transactions_connection.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
Original file line number Diff line number Diff line change
@@ -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<WithdrawalRequest>,

/// 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
}
}
";
16 changes: 16 additions & 0 deletions lightspark/src/objects/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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")),
}
Expand Down
10 changes: 10 additions & 0 deletions lightspark/src/objects/invoice_data.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
// 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};

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.
Expand Down
9 changes: 8 additions & 1 deletion lightspark/src/objects/lightspark_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 10 additions & 2 deletions lightspark/src/objects/lightspark_node_with_o_s_k.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
7 changes: 5 additions & 2 deletions lightspark/src/objects/lightspark_node_with_remote_signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions lightspark/src/objects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion lightspark/src/objects/outgoing_payment.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading

0 comments on commit 9e1f44a

Please sign in to comment.