use crate::error::Error;
use crate::objects::account_to_api_tokens_connection::AccountToApiTokensConnection;
use crate::objects::account_to_channels_connection::AccountToChannelsConnection;
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;
use crate::objects::entity::Entity;
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;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;
use std::vec::Vec;
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Account {
#[serde(rename = "account_id")]
pub id: String,
#[serde(with = "custom_date_format", rename = "account_created_at")]
pub created_at: DateTime<Utc>,
#[serde(with = "custom_date_format", rename = "account_updated_at")]
pub updated_at: DateTime<Utc>,
#[serde(rename = "account_name")]
pub name: Option<String>,
#[serde(rename = "__typename")]
pub typename: String,
}
impl LightsparkNodeOwner for Account {
fn type_name(&self) -> &'static str {
"Account"
}
}
impl Entity for Account {
fn get_id(&self) -> String {
self.id.clone()
}
fn get_created_at(&self) -> DateTime<Utc> {
self.created_at
}
fn get_updated_at(&self) -> DateTime<Utc> {
self.updated_at
}
fn type_name(&self) -> &'static str {
"Account"
}
}
impl GetEntity for Account {
fn get_entity_query() -> String {
format!(
"
query GetEntity($id: ID!) {{
entity(id: $id) {{
... on Account {{
... AccountFragment
}}
}}
}}
{}",
FRAGMENT
)
}
}
pub const FRAGMENT: &str = "
fragment AccountFragment on Account {
__typename
account_id: id
account_created_at: created_at
account_updated_at: updated_at
account_name: name
}
";
impl Account {
pub async fn get_api_tokens(
&self,
requester: &impl GraphQLRequester,
first: Option<i64>,
after: Option<String>,
) -> Result<AccountToApiTokensConnection, Error> {
let query = "query FetchAccountToApiTokensConnection($entity_id: ID!, $first: Int, $after: String) {
entity(id: $entity_id) {
... on Account {
api_tokens(, first: $first, after: $after) {
__typename
account_to_api_tokens_connection_count: count
account_to_api_tokens_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_api_tokens_connection_entities: entities {
__typename
api_token_id: id
api_token_created_at: created_at
api_token_updated_at: updated_at
api_token_client_id: client_id
api_token_name: name
api_token_permissions: permissions
api_token_is_deleted: is_deleted
}
}
}
}
}";
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());
let value = serde_json::to_value(variables).map_err(Error::ConversionError)?;
let result = requester.execute_graphql(query, Some(value)).await?;
let json = result["entity"]["api_tokens"].clone();
let result = serde_json::from_value(json).map_err(Error::JsonError)?;
Ok(result)
}
pub async fn get_blockchain_balance(
&self,
requester: &impl GraphQLRequester,
bitcoin_networks: Option<Vec<BitcoinNetwork>>,
node_ids: Option<Vec<String>>,
) -> Result<Option<BlockchainBalance>, Error> {
let query = "query FetchAccountBlockchainBalance($entity_id: ID!, $bitcoin_networks: [BitcoinNetwork!], $node_ids: [ID!]) {
entity(id: $entity_id) {
... on Account {
blockchain_balance(, bitcoin_networks: $bitcoin_networks, node_ids: $node_ids) {
__typename
blockchain_balance_total_balance: total_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_confirmed_balance: confirmed_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_unconfirmed_balance: unconfirmed_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_locked_balance: locked_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_required_reserve: required_reserve {
__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
}
blockchain_balance_available_balance: available_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
}
}
}";
let mut variables: HashMap<&str, Value> = HashMap::new();
variables.insert("entity_id", self.id.clone().into());
variables.insert("bitcoin_networks", bitcoin_networks.into());
variables.insert("node_ids", node_ids.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"]["blockchain_balance"].clone();
let result = if json.is_null() {
None
} else {
Some(serde_json::from_value(json).map_err(Error::JsonError)?)
};
Ok(result)
}
pub async fn get_conductivity(
&self,
requester: &impl GraphQLRequester,
bitcoin_networks: Option<Vec<BitcoinNetwork>>,
node_ids: Option<Vec<String>>,
) -> Result<Option<i64>, Error> {
let query = "query FetchAccountConductivity($entity_id: ID!, $bitcoin_networks: [BitcoinNetwork!], $node_ids: [ID!]) {
entity(id: $entity_id) {
... on Account {
conductivity(, bitcoin_networks: $bitcoin_networks, node_ids: $node_ids)
}
}
}";
let mut variables: HashMap<&str, Value> = HashMap::new();
variables.insert("entity_id", self.id.clone().into());
variables.insert("bitcoin_networks", bitcoin_networks.into());
variables.insert("node_ids", node_ids.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"]["conductivity"].clone();
let result = json.as_i64();
Ok(result)
}
pub async fn get_local_balance(
&self,
requester: &impl GraphQLRequester,
bitcoin_networks: Option<Vec<BitcoinNetwork>>,
node_ids: Option<Vec<String>>,
) -> Result<Option<CurrencyAmount>, Error> {
let query = "query FetchAccountLocalBalance($entity_id: ID!, $bitcoin_networks: [BitcoinNetwork!], $node_ids: [ID!]) {
entity(id: $entity_id) {
... on Account {
local_balance(, bitcoin_networks: $bitcoin_networks, node_ids: $node_ids) {
__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("bitcoin_networks", bitcoin_networks.into());
variables.insert("node_ids", node_ids.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"]["local_balance"].clone();
let result = if json.is_null() {
None
} else {
Some(serde_json::from_value(json).map_err(Error::JsonError)?)
};
Ok(result)
}
pub async fn get_nodes(
&self,
requester: &impl GraphQLRequester,
first: Option<i64>,
bitcoin_networks: Option<Vec<BitcoinNetwork>>,
node_ids: Option<Vec<String>>,
after: Option<String>,
) -> Result<AccountToNodesConnection, Error> {
let query = "query FetchAccountToNodesConnection($entity_id: ID!, $first: Int, $bitcoin_networks: [BitcoinNetwork!], $node_ids: [ID!], $after: String) {
entity(id: $entity_id) {
... on Account {
nodes(, first: $first, bitcoin_networks: $bitcoin_networks, node_ids: $node_ids, after: $after) {
__typename
account_to_nodes_connection_count: count
account_to_nodes_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_nodes_connection_entities: entities {
__typename
... on LightsparkNodeWithOSK {
__typename
lightspark_node_with_o_s_k_id: id
lightspark_node_with_o_s_k_created_at: created_at
lightspark_node_with_o_s_k_updated_at: updated_at
lightspark_node_with_o_s_k_alias: alias
lightspark_node_with_o_s_k_bitcoin_network: bitcoin_network
lightspark_node_with_o_s_k_color: color
lightspark_node_with_o_s_k_conductivity: conductivity
lightspark_node_with_o_s_k_display_name: display_name
lightspark_node_with_o_s_k_public_key: public_key
lightspark_node_with_o_s_k_owner: owner {
id
}
lightspark_node_with_o_s_k_status: status
lightspark_node_with_o_s_k_total_balance: total_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_o_s_k_total_local_balance: total_local_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_o_s_k_local_balance: local_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_o_s_k_remote_balance: remote_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_o_s_k_blockchain_balance: blockchain_balance {
__typename
blockchain_balance_total_balance: total_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_confirmed_balance: confirmed_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_unconfirmed_balance: unconfirmed_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_locked_balance: locked_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_required_reserve: required_reserve {
__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
}
blockchain_balance_available_balance: available_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
lightspark_node_with_o_s_k_uma_prescreening_utxos: uma_prescreening_utxos
lightspark_node_with_o_s_k_balances: balances {
__typename
balances_owned_balance: owned_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_send_balance: available_to_send_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_withdraw_balance: available_to_withdraw_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
lightspark_node_with_o_s_k_encrypted_signing_private_key: encrypted_signing_private_key {
__typename
secret_encrypted_value: encrypted_value
secret_cipher: cipher
}
}
... on LightsparkNodeWithRemoteSigning {
__typename
lightspark_node_with_remote_signing_id: id
lightspark_node_with_remote_signing_created_at: created_at
lightspark_node_with_remote_signing_updated_at: updated_at
lightspark_node_with_remote_signing_alias: alias
lightspark_node_with_remote_signing_bitcoin_network: bitcoin_network
lightspark_node_with_remote_signing_color: color
lightspark_node_with_remote_signing_conductivity: conductivity
lightspark_node_with_remote_signing_display_name: display_name
lightspark_node_with_remote_signing_public_key: public_key
lightspark_node_with_remote_signing_owner: owner {
id
}
lightspark_node_with_remote_signing_status: status
lightspark_node_with_remote_signing_total_balance: total_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_remote_signing_total_local_balance: total_local_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_remote_signing_local_balance: local_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_remote_signing_remote_balance: remote_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_remote_signing_blockchain_balance: blockchain_balance {
__typename
blockchain_balance_total_balance: total_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_confirmed_balance: confirmed_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_unconfirmed_balance: unconfirmed_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_locked_balance: locked_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_required_reserve: required_reserve {
__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
}
blockchain_balance_available_balance: available_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
lightspark_node_with_remote_signing_uma_prescreening_utxos: uma_prescreening_utxos
lightspark_node_with_remote_signing_balances: balances {
__typename
balances_owned_balance: owned_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_send_balance: available_to_send_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_withdraw_balance: available_to_withdraw_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
}
}
}
}
}
}";
let mut variables: HashMap<&str, Value> = HashMap::new();
variables.insert("entity_id", self.id.clone().into());
variables.insert("first", first.into());
variables.insert("bitcoin_networks", bitcoin_networks.into());
variables.insert("node_ids", node_ids.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?;
let json = result["entity"]["nodes"].clone();
let result = serde_json::from_value(json).map_err(Error::JsonError)?;
Ok(result)
}
pub async fn get_remote_balance(
&self,
requester: &impl GraphQLRequester,
bitcoin_networks: Option<Vec<BitcoinNetwork>>,
node_ids: Option<Vec<String>>,
) -> Result<Option<CurrencyAmount>, Error> {
let query = "query FetchAccountRemoteBalance($entity_id: ID!, $bitcoin_networks: [BitcoinNetwork!], $node_ids: [ID!]) {
entity(id: $entity_id) {
... on Account {
remote_balance(, bitcoin_networks: $bitcoin_networks, node_ids: $node_ids) {
__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("bitcoin_networks", bitcoin_networks.into());
variables.insert("node_ids", node_ids.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"]["remote_balance"].clone();
let result = if json.is_null() {
None
} else {
Some(serde_json::from_value(json).map_err(Error::JsonError)?)
};
Ok(result)
}
pub async fn get_uptime_percentage(
&self,
requester: &impl GraphQLRequester,
after_date: Option<DateTime<Utc>>,
before_date: Option<DateTime<Utc>>,
bitcoin_networks: Option<Vec<BitcoinNetwork>>,
node_ids: Option<Vec<String>>,
) -> Result<Option<i64>, Error> {
let query = "query FetchAccountUptimePercentage($entity_id: ID!, $after_date: DateTime, $before_date: DateTime, $bitcoin_networks: [BitcoinNetwork!], $node_ids: [ID!]) {
entity(id: $entity_id) {
... on Account {
uptime_percentage(, after_date: $after_date, before_date: $before_date, bitcoin_networks: $bitcoin_networks, node_ids: $node_ids)
}
}
}";
let mut variables: HashMap<&str, Value> = HashMap::new();
variables.insert("entity_id", self.id.clone().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());
variables.insert("bitcoin_networks", bitcoin_networks.into());
variables.insert("node_ids", node_ids.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"]["uptime_percentage"].clone();
let result = json.as_i64();
Ok(result)
}
#[allow(clippy::too_many_arguments)]
pub async fn get_channels(
&self,
requester: &impl GraphQLRequester,
bitcoin_network: BitcoinNetwork,
lightning_node_id: Option<String>,
after_date: Option<DateTime<Utc>>,
before_date: Option<DateTime<Utc>>,
first: Option<i64>,
after: Option<String>,
) -> Result<AccountToChannelsConnection, Error> {
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, 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
channel_created_at: created_at
channel_updated_at: updated_at
channel_funding_transaction: funding_transaction {
id
}
channel_capacity: capacity {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_local_balance: local_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_local_unsettled_balance: local_unsettled_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_remote_balance: remote_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_remote_unsettled_balance: remote_unsettled_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_unsettled_balance: unsettled_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_total_balance: total_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_status: status
channel_estimated_force_closure_wait_minutes: estimated_force_closure_wait_minutes
channel_commit_fee: commit_fee {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_fees: fees {
__typename
channel_fees_base_fee: base_fee {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_fees_fee_rate_per_mil: fee_rate_per_mil
}
channel_remote_node: remote_node {
id
}
channel_local_node: local_node {
id
}
channel_short_channel_id: short_channel_id
}
}
}
}
}";
let mut variables: HashMap<&str, Value> = HashMap::new();
variables.insert("entity_id", self.id.clone().into());
variables.insert("bitcoin_network", bitcoin_network.into());
variables.insert("lightning_node_id", lightning_node_id.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());
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?;
let json = result["entity"]["channels"].clone();
let result = serde_json::from_value(json).map_err(Error::JsonError)?;
Ok(result)
}
#[allow(clippy::too_many_arguments)]
pub async fn get_transactions(
&self,
requester: &impl GraphQLRequester,
first: Option<i64>,
after: Option<String>,
types: Option<Vec<TransactionType>>,
after_date: Option<DateTime<Utc>>,
before_date: Option<DateTime<Utc>>,
bitcoin_network: Option<BitcoinNetwork>,
lightning_node_id: Option<String>,
statuses: Option<Vec<TransactionStatus>>,
exclude_failures: Option<TransactionFailures>,
) -> Result<AccountToTransactionsConnection, Error> {
let query = "query FetchAccountToTransactionsConnection($entity_id: ID!, $first: Int, $after: String, $types: [TransactionType!], $after_date: DateTime, $before_date: DateTime, $bitcoin_network: BitcoinNetwork, $lightning_node_id: ID, $statuses: [TransactionStatus!], $exclude_failures: TransactionFailures) {
entity(id: $entity_id) {
... on Account {
transactions(, first: $first, after: $after, types: $types, after_date: $after_date, before_date: $before_date, bitcoin_network: $bitcoin_network, lightning_node_id: $lightning_node_id, statuses: $statuses, exclude_failures: $exclude_failures) {
__typename
account_to_transactions_connection_count: count
account_to_transactions_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_transactions_connection_profit_loss: profit_loss {
__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
}
account_to_transactions_connection_average_fee_earned: average_fee_earned {
__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
}
account_to_transactions_connection_total_amount_transacted: total_amount_transacted {
__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
}
account_to_transactions_connection_entities: entities {
__typename
... on ChannelClosingTransaction {
__typename
channel_closing_transaction_id: id
channel_closing_transaction_created_at: created_at
channel_closing_transaction_updated_at: updated_at
channel_closing_transaction_status: status
channel_closing_transaction_resolved_at: resolved_at
channel_closing_transaction_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
}
channel_closing_transaction_transaction_hash: transaction_hash
channel_closing_transaction_fees: fees {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_closing_transaction_block_hash: block_hash
channel_closing_transaction_block_height: block_height
channel_closing_transaction_destination_addresses: destination_addresses
channel_closing_transaction_num_confirmations: num_confirmations
channel_closing_transaction_channel: channel {
id
}
}
... on ChannelOpeningTransaction {
__typename
channel_opening_transaction_id: id
channel_opening_transaction_created_at: created_at
channel_opening_transaction_updated_at: updated_at
channel_opening_transaction_status: status
channel_opening_transaction_resolved_at: resolved_at
channel_opening_transaction_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
}
channel_opening_transaction_transaction_hash: transaction_hash
channel_opening_transaction_fees: fees {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_opening_transaction_block_hash: block_hash
channel_opening_transaction_block_height: block_height
channel_opening_transaction_destination_addresses: destination_addresses
channel_opening_transaction_num_confirmations: num_confirmations
channel_opening_transaction_channel: channel {
id
}
}
... on Deposit {
__typename
deposit_id: id
deposit_created_at: created_at
deposit_updated_at: updated_at
deposit_status: status
deposit_resolved_at: resolved_at
deposit_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
}
deposit_transaction_hash: transaction_hash
deposit_fees: fees {
__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
}
deposit_block_hash: block_hash
deposit_block_height: block_height
deposit_destination_addresses: destination_addresses
deposit_num_confirmations: num_confirmations
deposit_destination: destination {
id
}
}
... on IncomingPayment {
__typename
incoming_payment_id: id
incoming_payment_created_at: created_at
incoming_payment_updated_at: updated_at
incoming_payment_status: status
incoming_payment_resolved_at: resolved_at
incoming_payment_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
}
incoming_payment_transaction_hash: transaction_hash
incoming_payment_is_uma: is_uma
incoming_payment_destination: destination {
id
}
incoming_payment_payment_request: payment_request {
id
}
incoming_payment_uma_post_transaction_data: uma_post_transaction_data {
__typename
post_transaction_data_utxo: utxo
post_transaction_data_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
}
}
incoming_payment_is_internal_payment: is_internal_payment
}
... on OutgoingPayment {
__typename
outgoing_payment_id: id
outgoing_payment_created_at: created_at
outgoing_payment_updated_at: updated_at
outgoing_payment_status: status
outgoing_payment_resolved_at: resolved_at
outgoing_payment_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
}
outgoing_payment_transaction_hash: transaction_hash
outgoing_payment_is_uma: is_uma
outgoing_payment_origin: origin {
id
}
outgoing_payment_destination: destination {
id
}
outgoing_payment_fees: fees {
__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
}
outgoing_payment_payment_request_data: payment_request_data {
__typename
... on InvoiceData {
__typename
invoice_data_encoded_payment_request: encoded_payment_request
invoice_data_bitcoin_network: bitcoin_network
invoice_data_payment_hash: payment_hash
invoice_data_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
}
invoice_data_created_at: created_at
invoice_data_expires_at: expires_at
invoice_data_memo: memo
invoice_data_destination: destination {
__typename
... on GraphNode {
__typename
graph_node_id: id
graph_node_created_at: created_at
graph_node_updated_at: updated_at
graph_node_alias: alias
graph_node_bitcoin_network: bitcoin_network
graph_node_color: color
graph_node_conductivity: conductivity
graph_node_display_name: display_name
graph_node_public_key: public_key
}
... on LightsparkNodeWithOSK {
__typename
lightspark_node_with_o_s_k_id: id
lightspark_node_with_o_s_k_created_at: created_at
lightspark_node_with_o_s_k_updated_at: updated_at
lightspark_node_with_o_s_k_alias: alias
lightspark_node_with_o_s_k_bitcoin_network: bitcoin_network
lightspark_node_with_o_s_k_color: color
lightspark_node_with_o_s_k_conductivity: conductivity
lightspark_node_with_o_s_k_display_name: display_name
lightspark_node_with_o_s_k_public_key: public_key
lightspark_node_with_o_s_k_owner: owner {
id
}
lightspark_node_with_o_s_k_status: status
lightspark_node_with_o_s_k_total_balance: total_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_o_s_k_total_local_balance: total_local_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_o_s_k_local_balance: local_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_o_s_k_remote_balance: remote_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_o_s_k_blockchain_balance: blockchain_balance {
__typename
blockchain_balance_total_balance: total_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_confirmed_balance: confirmed_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_unconfirmed_balance: unconfirmed_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_locked_balance: locked_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_required_reserve: required_reserve {
__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
}
blockchain_balance_available_balance: available_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
lightspark_node_with_o_s_k_uma_prescreening_utxos: uma_prescreening_utxos
lightspark_node_with_o_s_k_balances: balances {
__typename
balances_owned_balance: owned_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_send_balance: available_to_send_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_withdraw_balance: available_to_withdraw_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
lightspark_node_with_o_s_k_encrypted_signing_private_key: encrypted_signing_private_key {
__typename
secret_encrypted_value: encrypted_value
secret_cipher: cipher
}
}
... on LightsparkNodeWithRemoteSigning {
__typename
lightspark_node_with_remote_signing_id: id
lightspark_node_with_remote_signing_created_at: created_at
lightspark_node_with_remote_signing_updated_at: updated_at
lightspark_node_with_remote_signing_alias: alias
lightspark_node_with_remote_signing_bitcoin_network: bitcoin_network
lightspark_node_with_remote_signing_color: color
lightspark_node_with_remote_signing_conductivity: conductivity
lightspark_node_with_remote_signing_display_name: display_name
lightspark_node_with_remote_signing_public_key: public_key
lightspark_node_with_remote_signing_owner: owner {
id
}
lightspark_node_with_remote_signing_status: status
lightspark_node_with_remote_signing_total_balance: total_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_remote_signing_total_local_balance: total_local_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_remote_signing_local_balance: local_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_remote_signing_remote_balance: remote_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_remote_signing_blockchain_balance: blockchain_balance {
__typename
blockchain_balance_total_balance: total_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_confirmed_balance: confirmed_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_unconfirmed_balance: unconfirmed_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_locked_balance: locked_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_required_reserve: required_reserve {
__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
}
blockchain_balance_available_balance: available_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
lightspark_node_with_remote_signing_uma_prescreening_utxos: uma_prescreening_utxos
lightspark_node_with_remote_signing_balances: balances {
__typename
balances_owned_balance: owned_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_send_balance: available_to_send_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_withdraw_balance: available_to_withdraw_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
}
}
}
}
outgoing_payment_failure_reason: failure_reason
outgoing_payment_failure_message: failure_message {
__typename
rich_text_text: text
}
outgoing_payment_uma_post_transaction_data: uma_post_transaction_data {
__typename
post_transaction_data_utxo: utxo
post_transaction_data_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
}
}
outgoing_payment_payment_preimage: payment_preimage
outgoing_payment_is_internal_payment: is_internal_payment
outgoing_payment_idempotency_key: idempotency_key
}
... on RoutingTransaction {
__typename
routing_transaction_id: id
routing_transaction_created_at: created_at
routing_transaction_updated_at: updated_at
routing_transaction_status: status
routing_transaction_resolved_at: resolved_at
routing_transaction_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
}
routing_transaction_transaction_hash: transaction_hash
routing_transaction_incoming_channel: incoming_channel {
id
}
routing_transaction_outgoing_channel: outgoing_channel {
id
}
routing_transaction_fees: fees {
__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
}
routing_transaction_failure_message: failure_message {
__typename
rich_text_text: text
}
routing_transaction_failure_reason: failure_reason
}
... on Withdrawal {
__typename
withdrawal_id: id
withdrawal_created_at: created_at
withdrawal_updated_at: updated_at
withdrawal_status: status
withdrawal_resolved_at: resolved_at
withdrawal_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_transaction_hash: transaction_hash
withdrawal_fees: fees {
__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_block_hash: block_hash
withdrawal_block_height: block_height
withdrawal_destination_addresses: destination_addresses
withdrawal_num_confirmations: num_confirmations
withdrawal_origin: origin {
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("types", types.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());
variables.insert("bitcoin_network", bitcoin_network.into());
variables.insert("lightning_node_id", lightning_node_id.into());
variables.insert("statuses", statuses.into());
variables.insert(
"exclude_failures",
serde_json::to_value(&exclude_failures).map_err(Error::ConversionError)?,
);
let value = serde_json::to_value(variables).map_err(Error::ConversionError)?;
let result = requester.execute_graphql(query, Some(value)).await?;
let json = result["entity"]["transactions"].clone();
let result = serde_json::from_value(json).map_err(Error::JsonError)?;
Ok(result)
}
#[allow(clippy::too_many_arguments)]
pub async fn get_payment_requests(
&self,
requester: &impl GraphQLRequester,
first: Option<i64>,
after: Option<String>,
after_date: Option<DateTime<Utc>>,
before_date: Option<DateTime<Utc>>,
bitcoin_network: Option<BitcoinNetwork>,
lightning_node_id: Option<String>,
) -> Result<AccountToPaymentRequestsConnection, Error> {
let query = "query FetchAccountToPaymentRequestsConnection($entity_id: ID!, $first: Int, $after: String, $after_date: DateTime, $before_date: DateTime, $bitcoin_network: BitcoinNetwork, $lightning_node_id: ID) {
entity(id: $entity_id) {
... on Account {
payment_requests(, first: $first, after: $after, after_date: $after_date, before_date: $before_date, bitcoin_network: $bitcoin_network, lightning_node_id: $lightning_node_id) {
__typename
account_to_payment_requests_connection_count: count
account_to_payment_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_payment_requests_connection_entities: entities {
__typename
... on Invoice {
__typename
invoice_id: id
invoice_created_at: created_at
invoice_updated_at: updated_at
invoice_data: data {
__typename
invoice_data_encoded_payment_request: encoded_payment_request
invoice_data_bitcoin_network: bitcoin_network
invoice_data_payment_hash: payment_hash
invoice_data_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
}
invoice_data_created_at: created_at
invoice_data_expires_at: expires_at
invoice_data_memo: memo
invoice_data_destination: destination {
__typename
... on GraphNode {
__typename
graph_node_id: id
graph_node_created_at: created_at
graph_node_updated_at: updated_at
graph_node_alias: alias
graph_node_bitcoin_network: bitcoin_network
graph_node_color: color
graph_node_conductivity: conductivity
graph_node_display_name: display_name
graph_node_public_key: public_key
}
... on LightsparkNodeWithOSK {
__typename
lightspark_node_with_o_s_k_id: id
lightspark_node_with_o_s_k_created_at: created_at
lightspark_node_with_o_s_k_updated_at: updated_at
lightspark_node_with_o_s_k_alias: alias
lightspark_node_with_o_s_k_bitcoin_network: bitcoin_network
lightspark_node_with_o_s_k_color: color
lightspark_node_with_o_s_k_conductivity: conductivity
lightspark_node_with_o_s_k_display_name: display_name
lightspark_node_with_o_s_k_public_key: public_key
lightspark_node_with_o_s_k_owner: owner {
id
}
lightspark_node_with_o_s_k_status: status
lightspark_node_with_o_s_k_total_balance: total_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_o_s_k_total_local_balance: total_local_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_o_s_k_local_balance: local_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_o_s_k_remote_balance: remote_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_o_s_k_blockchain_balance: blockchain_balance {
__typename
blockchain_balance_total_balance: total_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_confirmed_balance: confirmed_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_unconfirmed_balance: unconfirmed_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_locked_balance: locked_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_required_reserve: required_reserve {
__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
}
blockchain_balance_available_balance: available_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
lightspark_node_with_o_s_k_uma_prescreening_utxos: uma_prescreening_utxos
lightspark_node_with_o_s_k_balances: balances {
__typename
balances_owned_balance: owned_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_send_balance: available_to_send_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_withdraw_balance: available_to_withdraw_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
lightspark_node_with_o_s_k_encrypted_signing_private_key: encrypted_signing_private_key {
__typename
secret_encrypted_value: encrypted_value
secret_cipher: cipher
}
}
... on LightsparkNodeWithRemoteSigning {
__typename
lightspark_node_with_remote_signing_id: id
lightspark_node_with_remote_signing_created_at: created_at
lightspark_node_with_remote_signing_updated_at: updated_at
lightspark_node_with_remote_signing_alias: alias
lightspark_node_with_remote_signing_bitcoin_network: bitcoin_network
lightspark_node_with_remote_signing_color: color
lightspark_node_with_remote_signing_conductivity: conductivity
lightspark_node_with_remote_signing_display_name: display_name
lightspark_node_with_remote_signing_public_key: public_key
lightspark_node_with_remote_signing_owner: owner {
id
}
lightspark_node_with_remote_signing_status: status
lightspark_node_with_remote_signing_total_balance: total_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_remote_signing_total_local_balance: total_local_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_remote_signing_local_balance: local_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_remote_signing_remote_balance: remote_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
lightspark_node_with_remote_signing_blockchain_balance: blockchain_balance {
__typename
blockchain_balance_total_balance: total_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_confirmed_balance: confirmed_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_unconfirmed_balance: unconfirmed_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_locked_balance: locked_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
blockchain_balance_required_reserve: required_reserve {
__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
}
blockchain_balance_available_balance: available_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
lightspark_node_with_remote_signing_uma_prescreening_utxos: uma_prescreening_utxos
lightspark_node_with_remote_signing_balances: balances {
__typename
balances_owned_balance: owned_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_send_balance: available_to_send_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_withdraw_balance: available_to_withdraw_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
}
}
}
invoice_status: status
invoice_amount_paid: amount_paid {
__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
}
invoice_is_uma: is_uma
invoice_is_lnurl: is_lnurl
}
}
}
}
}
}";
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("after_date", after_date.map(|dt| dt.to_rfc3339()).into());
variables.insert("before_date", before_date.map(|dt| dt.to_rfc3339()).into());
variables.insert("bitcoin_network", bitcoin_network.into());
variables.insert("lightning_node_id", lightning_node_id.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"]["payment_requests"].clone();
let result = serde_json::from_value(json).map_err(Error::JsonError)?;
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>>,
idempotency_keys: 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!], $idempotency_keys: [String!], $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, idempotency_keys: $idempotency_keys, 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_total_fees: total_fees {
__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
}
withdrawal_request_idempotency_key: idempotency_key
withdrawal_request_initiator: initiator
}
}
}
}
}";
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("idempotency_keys", idempotency_keys.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,
first: Option<i64>,
after: Option<String>,
third_party_ids: Option<Vec<String>>,
) -> Result<AccountToWalletsConnection, Error> {
let query = "query FetchAccountToWalletsConnection($entity_id: ID!, $first: Int, $after: String, $third_party_ids: [String!]) {
entity(id: $entity_id) {
... on Account {
wallets(, first: $first, after: $after, third_party_ids: $third_party_ids) {
__typename
account_to_wallets_connection_count: count
account_to_wallets_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_wallets_connection_entities: entities {
__typename
wallet_id: id
wallet_created_at: created_at
wallet_updated_at: updated_at
wallet_last_login_at: last_login_at
wallet_balances: balances {
__typename
balances_owned_balance: owned_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_send_balance: available_to_send_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
balances_available_to_withdraw_balance: available_to_withdraw_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
}
wallet_third_party_identifier: third_party_identifier
wallet_account: account {
id
}
wallet_status: status
}
}
}
}
}";
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("third_party_ids", third_party_ids.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"]["wallets"].clone();
let result = serde_json::from_value(json).map_err(Error::JsonError)?;
Ok(result)
}
}