Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add withdrawalRequests info for wallets and accounts. #23

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions lightspark/src/objects/account_to_nodes_connection.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use crate::objects::connection::Connection;
use serde::{Deserialize, Serialize};
use std::vec::Vec;

use crate::objects::connection::Connection;
use crate::objects::lightspark_node::LightsparkNodeEnum;
use crate::objects::page_info::PageInfo;
use std::vec::Vec;

/// A connection between an account and the nodes it manages.
#[derive(Debug, Clone, Deserialize, Serialize)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use serde::{Deserialize, Serialize};

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)]
Expand Down
4 changes: 2 additions & 2 deletions lightspark/src/objects/account_to_transactions_connection.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use crate::objects::transaction::TransactionEnum;
use crate::objects::connection::Connection;
use serde::{Deserialize, Serialize};

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)]
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
4 changes: 2 additions & 2 deletions lightspark/src/objects/invoice_data.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::payment_request_data::PaymentRequestData;
use crate::objects::node::NodeEnum;
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::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.
Expand Down
4 changes: 2 additions & 2 deletions lightspark/src/objects/lightspark_node.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use crate::objects::blockchain_balance::BlockchainBalance;
use crate::objects::entity::Entity;
use crate::objects::lightspark_node_status::LightsparkNodeStatus;
use crate::objects::node::Node;

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;
Expand Down
22 changes: 11 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,27 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
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::types::entity_wrapper::EntityWrapper;
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::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 std::collections::HashMap;

use crate::objects::bitcoin_network::BitcoinNetwork;
use crate::objects::lightspark_node_status::LightsparkNodeStatus;
use crate::objects::node_address_type::NodeAddressType;
use crate::objects::secret::Secret;
use std::vec::Vec;

/// This is a Lightspark node with OSK.
Expand Down
20 changes: 10 additions & 10 deletions lightspark/src/objects/lightspark_node_with_remote_signing.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
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::types::entity_wrapper::EntityWrapper;
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::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::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::objects::lightspark_node_status::LightsparkNodeStatus;
use crate::objects::node_address_type::NodeAddressType;
use crate::objects::node_to_addresses_connection::NodeToAddressesConnection;
use std::vec::Vec;

/// This is a Lightspark node with remote signing.
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
Loading