lightspark/objects/
account.rs

1// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2use crate::error::Error;
3use crate::objects::account_to_api_tokens_connection::AccountToApiTokensConnection;
4use crate::objects::account_to_channels_connection::AccountToChannelsConnection;
5use crate::objects::account_to_nodes_connection::AccountToNodesConnection;
6use crate::objects::account_to_payment_requests_connection::AccountToPaymentRequestsConnection;
7use crate::objects::account_to_transactions_connection::AccountToTransactionsConnection;
8use crate::objects::account_to_wallets_connection::AccountToWalletsConnection;
9use crate::objects::account_to_withdrawal_requests_connection::AccountToWithdrawalRequestsConnection;
10use crate::objects::bitcoin_network::BitcoinNetwork;
11use crate::objects::blockchain_balance::BlockchainBalance;
12use crate::objects::currency_amount::CurrencyAmount;
13use crate::objects::entity::Entity;
14use crate::objects::lightspark_node_owner::LightsparkNodeOwner;
15use crate::objects::transaction_failures::TransactionFailures;
16use crate::objects::transaction_status::TransactionStatus;
17use crate::objects::transaction_type::TransactionType;
18use crate::objects::withdrawal_request_status::WithdrawalRequestStatus;
19use crate::types::custom_date_formats::custom_date_format;
20use crate::types::get_entity::GetEntity;
21use crate::types::graphql_requester::GraphQLRequester;
22use chrono::{DateTime, Utc};
23use serde::{Deserialize, Serialize};
24use serde_json::Value;
25use std::collections::HashMap;
26use std::vec::Vec;
27
28/// This is an object representing the connected Lightspark account. You can retrieve this object to see your account information and objects tied to your account.
29#[derive(Debug, Clone, Deserialize, Serialize)]
30pub struct Account {
31    /// The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque string.
32    #[serde(rename = "account_id")]
33    pub id: String,
34
35    /// The date and time when the entity was first created.
36    #[serde(with = "custom_date_format", rename = "account_created_at")]
37    pub created_at: DateTime<Utc>,
38
39    /// The date and time when the entity was last updated.
40    #[serde(with = "custom_date_format", rename = "account_updated_at")]
41    pub updated_at: DateTime<Utc>,
42
43    /// The name of this account.
44    #[serde(rename = "account_name")]
45    pub name: Option<String>,
46
47    /// The typename of the object
48    #[serde(rename = "__typename")]
49    pub typename: String,
50}
51
52impl LightsparkNodeOwner for Account {
53    fn type_name(&self) -> &'static str {
54        "Account"
55    }
56}
57
58impl Entity for Account {
59    /// The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque string.
60    fn get_id(&self) -> String {
61        self.id.clone()
62    }
63
64    /// The date and time when the entity was first created.
65    fn get_created_at(&self) -> DateTime<Utc> {
66        self.created_at
67    }
68
69    /// The date and time when the entity was last updated.
70    fn get_updated_at(&self) -> DateTime<Utc> {
71        self.updated_at
72    }
73
74    fn type_name(&self) -> &'static str {
75        "Account"
76    }
77}
78
79impl GetEntity for Account {
80    fn get_entity_query() -> String {
81        format!(
82            "
83        query GetEntity($id: ID!) {{
84            entity(id: $id) {{
85                ... on Account {{
86                    ... AccountFragment
87                }}
88            }}
89        }}
90
91        {}",
92            FRAGMENT
93        )
94    }
95}
96
97pub const FRAGMENT: &str = "
98fragment AccountFragment on Account {
99    __typename
100    account_id: id
101    account_created_at: created_at
102    account_updated_at: updated_at
103    account_name: name
104}
105";
106
107impl Account {
108    pub async fn get_api_tokens(
109        &self,
110        requester: &impl GraphQLRequester,
111        first: Option<i64>,
112        after: Option<String>,
113    ) -> Result<AccountToApiTokensConnection, Error> {
114        let query = "query FetchAccountToApiTokensConnection($entity_id: ID!, $first: Int, $after: String) {
115    entity(id: $entity_id) {
116        ... on Account {
117            api_tokens(, first: $first, after: $after) {
118                __typename
119                account_to_api_tokens_connection_count: count
120                account_to_api_tokens_connection_page_info: page_info {
121                    __typename
122                    page_info_has_next_page: has_next_page
123                    page_info_has_previous_page: has_previous_page
124                    page_info_start_cursor: start_cursor
125                    page_info_end_cursor: end_cursor
126                }
127                account_to_api_tokens_connection_entities: entities {
128                    __typename
129                    api_token_id: id
130                    api_token_created_at: created_at
131                    api_token_updated_at: updated_at
132                    api_token_client_id: client_id
133                    api_token_name: name
134                    api_token_permissions: permissions
135                    api_token_is_deleted: is_deleted
136                }
137            }
138        }
139    }
140}";
141        let mut variables: HashMap<&str, Value> = HashMap::new();
142        variables.insert("entity_id", self.id.clone().into());
143        variables.insert("first", first.into());
144        variables.insert("after", after.into());
145
146        let value = serde_json::to_value(variables).map_err(Error::ConversionError)?;
147        let result = requester.execute_graphql(query, Some(value)).await?;
148        let json = result["entity"]["api_tokens"].clone();
149        let result = serde_json::from_value(json).map_err(Error::JsonError)?;
150        Ok(result)
151    }
152
153    pub async fn get_blockchain_balance(
154        &self,
155        requester: &impl GraphQLRequester,
156        bitcoin_networks: Option<Vec<BitcoinNetwork>>,
157        node_ids: Option<Vec<String>>,
158    ) -> Result<Option<BlockchainBalance>, Error> {
159        let query = "query FetchAccountBlockchainBalance($entity_id: ID!, $bitcoin_networks: [BitcoinNetwork!], $node_ids: [ID!]) {
160    entity(id: $entity_id) {
161        ... on Account {
162            blockchain_balance(, bitcoin_networks: $bitcoin_networks, node_ids: $node_ids) {
163                __typename
164                blockchain_balance_total_balance: total_balance {
165                    __typename
166                    currency_amount_original_value: original_value
167                    currency_amount_original_unit: original_unit
168                    currency_amount_preferred_currency_unit: preferred_currency_unit
169                    currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
170                    currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
171                }
172                blockchain_balance_confirmed_balance: confirmed_balance {
173                    __typename
174                    currency_amount_original_value: original_value
175                    currency_amount_original_unit: original_unit
176                    currency_amount_preferred_currency_unit: preferred_currency_unit
177                    currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
178                    currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
179                }
180                blockchain_balance_unconfirmed_balance: unconfirmed_balance {
181                    __typename
182                    currency_amount_original_value: original_value
183                    currency_amount_original_unit: original_unit
184                    currency_amount_preferred_currency_unit: preferred_currency_unit
185                    currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
186                    currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
187                }
188                blockchain_balance_locked_balance: locked_balance {
189                    __typename
190                    currency_amount_original_value: original_value
191                    currency_amount_original_unit: original_unit
192                    currency_amount_preferred_currency_unit: preferred_currency_unit
193                    currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
194                    currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
195                }
196                blockchain_balance_required_reserve: required_reserve {
197                    __typename
198                    currency_amount_original_value: original_value
199                    currency_amount_original_unit: original_unit
200                    currency_amount_preferred_currency_unit: preferred_currency_unit
201                    currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
202                    currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
203                }
204                blockchain_balance_available_balance: available_balance {
205                    __typename
206                    currency_amount_original_value: original_value
207                    currency_amount_original_unit: original_unit
208                    currency_amount_preferred_currency_unit: preferred_currency_unit
209                    currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
210                    currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
211                }
212            }
213        }
214    }
215}";
216        let mut variables: HashMap<&str, Value> = HashMap::new();
217        variables.insert("entity_id", self.id.clone().into());
218        variables.insert("bitcoin_networks", bitcoin_networks.into());
219        variables.insert("node_ids", node_ids.into());
220
221        let value = serde_json::to_value(variables).map_err(Error::ConversionError)?;
222        let result = requester.execute_graphql(query, Some(value)).await?;
223        let json = result["entity"]["blockchain_balance"].clone();
224        let result = if json.is_null() {
225            None
226        } else {
227            Some(serde_json::from_value(json).map_err(Error::JsonError)?)
228        };
229        Ok(result)
230    }
231
232    pub async fn get_conductivity(
233        &self,
234        requester: &impl GraphQLRequester,
235        bitcoin_networks: Option<Vec<BitcoinNetwork>>,
236        node_ids: Option<Vec<String>>,
237    ) -> Result<Option<i64>, Error> {
238        let query = "query FetchAccountConductivity($entity_id: ID!, $bitcoin_networks: [BitcoinNetwork!], $node_ids: [ID!]) {
239    entity(id: $entity_id) {
240        ... on Account {
241            conductivity(, bitcoin_networks: $bitcoin_networks, node_ids: $node_ids)
242        }
243    }
244}";
245        let mut variables: HashMap<&str, Value> = HashMap::new();
246        variables.insert("entity_id", self.id.clone().into());
247        variables.insert("bitcoin_networks", bitcoin_networks.into());
248        variables.insert("node_ids", node_ids.into());
249
250        let value = serde_json::to_value(variables).map_err(Error::ConversionError)?;
251        let result = requester.execute_graphql(query, Some(value)).await?;
252        let json = result["entity"]["conductivity"].clone();
253        let result = json.as_i64();
254        Ok(result)
255    }
256
257    pub async fn get_local_balance(
258        &self,
259        requester: &impl GraphQLRequester,
260        bitcoin_networks: Option<Vec<BitcoinNetwork>>,
261        node_ids: Option<Vec<String>>,
262    ) -> Result<Option<CurrencyAmount>, Error> {
263        let query = "query FetchAccountLocalBalance($entity_id: ID!, $bitcoin_networks: [BitcoinNetwork!], $node_ids: [ID!]) {
264    entity(id: $entity_id) {
265        ... on Account {
266            local_balance(, bitcoin_networks: $bitcoin_networks, node_ids: $node_ids) {
267                __typename
268                currency_amount_original_value: original_value
269                currency_amount_original_unit: original_unit
270                currency_amount_preferred_currency_unit: preferred_currency_unit
271                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
272                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
273            }
274        }
275    }
276}";
277        let mut variables: HashMap<&str, Value> = HashMap::new();
278        variables.insert("entity_id", self.id.clone().into());
279        variables.insert("bitcoin_networks", bitcoin_networks.into());
280        variables.insert("node_ids", node_ids.into());
281
282        let value = serde_json::to_value(variables).map_err(Error::ConversionError)?;
283        let result = requester.execute_graphql(query, Some(value)).await?;
284        let json = result["entity"]["local_balance"].clone();
285        let result = if json.is_null() {
286            None
287        } else {
288            Some(serde_json::from_value(json).map_err(Error::JsonError)?)
289        };
290        Ok(result)
291    }
292
293    pub async fn get_nodes(
294        &self,
295        requester: &impl GraphQLRequester,
296        first: Option<i64>,
297        bitcoin_networks: Option<Vec<BitcoinNetwork>>,
298        node_ids: Option<Vec<String>>,
299        after: Option<String>,
300    ) -> Result<AccountToNodesConnection, Error> {
301        let query = "query FetchAccountToNodesConnection($entity_id: ID!, $first: Int, $bitcoin_networks: [BitcoinNetwork!], $node_ids: [ID!], $after: String) {
302    entity(id: $entity_id) {
303        ... on Account {
304            nodes(, first: $first, bitcoin_networks: $bitcoin_networks, node_ids: $node_ids, after: $after) {
305                __typename
306                account_to_nodes_connection_count: count
307                account_to_nodes_connection_page_info: page_info {
308                    __typename
309                    page_info_has_next_page: has_next_page
310                    page_info_has_previous_page: has_previous_page
311                    page_info_start_cursor: start_cursor
312                    page_info_end_cursor: end_cursor
313                }
314                account_to_nodes_connection_entities: entities {
315                    __typename
316                    ... on LightsparkNodeWithOSK {
317                        __typename
318                        lightspark_node_with_o_s_k_id: id
319                        lightspark_node_with_o_s_k_created_at: created_at
320                        lightspark_node_with_o_s_k_updated_at: updated_at
321                        lightspark_node_with_o_s_k_alias: alias
322                        lightspark_node_with_o_s_k_bitcoin_network: bitcoin_network
323                        lightspark_node_with_o_s_k_color: color
324                        lightspark_node_with_o_s_k_conductivity: conductivity
325                        lightspark_node_with_o_s_k_display_name: display_name
326                        lightspark_node_with_o_s_k_public_key: public_key
327                        lightspark_node_with_o_s_k_owner: owner {
328                            id
329                        }
330                        lightspark_node_with_o_s_k_status: status
331                        lightspark_node_with_o_s_k_total_balance: total_balance {
332                            __typename
333                            currency_amount_original_value: original_value
334                            currency_amount_original_unit: original_unit
335                            currency_amount_preferred_currency_unit: preferred_currency_unit
336                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
337                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
338                        }
339                        lightspark_node_with_o_s_k_total_local_balance: total_local_balance {
340                            __typename
341                            currency_amount_original_value: original_value
342                            currency_amount_original_unit: original_unit
343                            currency_amount_preferred_currency_unit: preferred_currency_unit
344                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
345                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
346                        }
347                        lightspark_node_with_o_s_k_local_balance: local_balance {
348                            __typename
349                            currency_amount_original_value: original_value
350                            currency_amount_original_unit: original_unit
351                            currency_amount_preferred_currency_unit: preferred_currency_unit
352                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
353                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
354                        }
355                        lightspark_node_with_o_s_k_remote_balance: remote_balance {
356                            __typename
357                            currency_amount_original_value: original_value
358                            currency_amount_original_unit: original_unit
359                            currency_amount_preferred_currency_unit: preferred_currency_unit
360                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
361                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
362                        }
363                        lightspark_node_with_o_s_k_blockchain_balance: blockchain_balance {
364                            __typename
365                            blockchain_balance_total_balance: total_balance {
366                                __typename
367                                currency_amount_original_value: original_value
368                                currency_amount_original_unit: original_unit
369                                currency_amount_preferred_currency_unit: preferred_currency_unit
370                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
371                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
372                            }
373                            blockchain_balance_confirmed_balance: confirmed_balance {
374                                __typename
375                                currency_amount_original_value: original_value
376                                currency_amount_original_unit: original_unit
377                                currency_amount_preferred_currency_unit: preferred_currency_unit
378                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
379                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
380                            }
381                            blockchain_balance_unconfirmed_balance: unconfirmed_balance {
382                                __typename
383                                currency_amount_original_value: original_value
384                                currency_amount_original_unit: original_unit
385                                currency_amount_preferred_currency_unit: preferred_currency_unit
386                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
387                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
388                            }
389                            blockchain_balance_locked_balance: locked_balance {
390                                __typename
391                                currency_amount_original_value: original_value
392                                currency_amount_original_unit: original_unit
393                                currency_amount_preferred_currency_unit: preferred_currency_unit
394                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
395                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
396                            }
397                            blockchain_balance_required_reserve: required_reserve {
398                                __typename
399                                currency_amount_original_value: original_value
400                                currency_amount_original_unit: original_unit
401                                currency_amount_preferred_currency_unit: preferred_currency_unit
402                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
403                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
404                            }
405                            blockchain_balance_available_balance: available_balance {
406                                __typename
407                                currency_amount_original_value: original_value
408                                currency_amount_original_unit: original_unit
409                                currency_amount_preferred_currency_unit: preferred_currency_unit
410                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
411                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
412                            }
413                        }
414                        lightspark_node_with_o_s_k_uma_prescreening_utxos: uma_prescreening_utxos
415                        lightspark_node_with_o_s_k_balances: balances {
416                            __typename
417                            balances_owned_balance: owned_balance {
418                                __typename
419                                currency_amount_original_value: original_value
420                                currency_amount_original_unit: original_unit
421                                currency_amount_preferred_currency_unit: preferred_currency_unit
422                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
423                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
424                            }
425                            balances_available_to_send_balance: available_to_send_balance {
426                                __typename
427                                currency_amount_original_value: original_value
428                                currency_amount_original_unit: original_unit
429                                currency_amount_preferred_currency_unit: preferred_currency_unit
430                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
431                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
432                            }
433                            balances_available_to_withdraw_balance: available_to_withdraw_balance {
434                                __typename
435                                currency_amount_original_value: original_value
436                                currency_amount_original_unit: original_unit
437                                currency_amount_preferred_currency_unit: preferred_currency_unit
438                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
439                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
440                            }
441                        }
442                        lightspark_node_with_o_s_k_encrypted_signing_private_key: encrypted_signing_private_key {
443                            __typename
444                            secret_encrypted_value: encrypted_value
445                            secret_cipher: cipher
446                        }
447                    }
448                    ... on LightsparkNodeWithRemoteSigning {
449                        __typename
450                        lightspark_node_with_remote_signing_id: id
451                        lightspark_node_with_remote_signing_created_at: created_at
452                        lightspark_node_with_remote_signing_updated_at: updated_at
453                        lightspark_node_with_remote_signing_alias: alias
454                        lightspark_node_with_remote_signing_bitcoin_network: bitcoin_network
455                        lightspark_node_with_remote_signing_color: color
456                        lightspark_node_with_remote_signing_conductivity: conductivity
457                        lightspark_node_with_remote_signing_display_name: display_name
458                        lightspark_node_with_remote_signing_public_key: public_key
459                        lightspark_node_with_remote_signing_owner: owner {
460                            id
461                        }
462                        lightspark_node_with_remote_signing_status: status
463                        lightspark_node_with_remote_signing_total_balance: total_balance {
464                            __typename
465                            currency_amount_original_value: original_value
466                            currency_amount_original_unit: original_unit
467                            currency_amount_preferred_currency_unit: preferred_currency_unit
468                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
469                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
470                        }
471                        lightspark_node_with_remote_signing_total_local_balance: total_local_balance {
472                            __typename
473                            currency_amount_original_value: original_value
474                            currency_amount_original_unit: original_unit
475                            currency_amount_preferred_currency_unit: preferred_currency_unit
476                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
477                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
478                        }
479                        lightspark_node_with_remote_signing_local_balance: local_balance {
480                            __typename
481                            currency_amount_original_value: original_value
482                            currency_amount_original_unit: original_unit
483                            currency_amount_preferred_currency_unit: preferred_currency_unit
484                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
485                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
486                        }
487                        lightspark_node_with_remote_signing_remote_balance: remote_balance {
488                            __typename
489                            currency_amount_original_value: original_value
490                            currency_amount_original_unit: original_unit
491                            currency_amount_preferred_currency_unit: preferred_currency_unit
492                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
493                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
494                        }
495                        lightspark_node_with_remote_signing_blockchain_balance: blockchain_balance {
496                            __typename
497                            blockchain_balance_total_balance: total_balance {
498                                __typename
499                                currency_amount_original_value: original_value
500                                currency_amount_original_unit: original_unit
501                                currency_amount_preferred_currency_unit: preferred_currency_unit
502                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
503                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
504                            }
505                            blockchain_balance_confirmed_balance: confirmed_balance {
506                                __typename
507                                currency_amount_original_value: original_value
508                                currency_amount_original_unit: original_unit
509                                currency_amount_preferred_currency_unit: preferred_currency_unit
510                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
511                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
512                            }
513                            blockchain_balance_unconfirmed_balance: unconfirmed_balance {
514                                __typename
515                                currency_amount_original_value: original_value
516                                currency_amount_original_unit: original_unit
517                                currency_amount_preferred_currency_unit: preferred_currency_unit
518                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
519                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
520                            }
521                            blockchain_balance_locked_balance: locked_balance {
522                                __typename
523                                currency_amount_original_value: original_value
524                                currency_amount_original_unit: original_unit
525                                currency_amount_preferred_currency_unit: preferred_currency_unit
526                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
527                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
528                            }
529                            blockchain_balance_required_reserve: required_reserve {
530                                __typename
531                                currency_amount_original_value: original_value
532                                currency_amount_original_unit: original_unit
533                                currency_amount_preferred_currency_unit: preferred_currency_unit
534                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
535                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
536                            }
537                            blockchain_balance_available_balance: available_balance {
538                                __typename
539                                currency_amount_original_value: original_value
540                                currency_amount_original_unit: original_unit
541                                currency_amount_preferred_currency_unit: preferred_currency_unit
542                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
543                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
544                            }
545                        }
546                        lightspark_node_with_remote_signing_uma_prescreening_utxos: uma_prescreening_utxos
547                        lightspark_node_with_remote_signing_balances: balances {
548                            __typename
549                            balances_owned_balance: owned_balance {
550                                __typename
551                                currency_amount_original_value: original_value
552                                currency_amount_original_unit: original_unit
553                                currency_amount_preferred_currency_unit: preferred_currency_unit
554                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
555                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
556                            }
557                            balances_available_to_send_balance: available_to_send_balance {
558                                __typename
559                                currency_amount_original_value: original_value
560                                currency_amount_original_unit: original_unit
561                                currency_amount_preferred_currency_unit: preferred_currency_unit
562                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
563                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
564                            }
565                            balances_available_to_withdraw_balance: available_to_withdraw_balance {
566                                __typename
567                                currency_amount_original_value: original_value
568                                currency_amount_original_unit: original_unit
569                                currency_amount_preferred_currency_unit: preferred_currency_unit
570                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
571                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
572                            }
573                        }
574                    }
575                }
576            }
577        }
578    }
579}";
580        let mut variables: HashMap<&str, Value> = HashMap::new();
581        variables.insert("entity_id", self.id.clone().into());
582        variables.insert("first", first.into());
583        variables.insert("bitcoin_networks", bitcoin_networks.into());
584        variables.insert("node_ids", node_ids.into());
585        variables.insert("after", after.into());
586
587        let value = serde_json::to_value(variables).map_err(Error::ConversionError)?;
588        let result = requester.execute_graphql(query, Some(value)).await?;
589        let json = result["entity"]["nodes"].clone();
590        let result = serde_json::from_value(json).map_err(Error::JsonError)?;
591        Ok(result)
592    }
593
594    pub async fn get_remote_balance(
595        &self,
596        requester: &impl GraphQLRequester,
597        bitcoin_networks: Option<Vec<BitcoinNetwork>>,
598        node_ids: Option<Vec<String>>,
599    ) -> Result<Option<CurrencyAmount>, Error> {
600        let query = "query FetchAccountRemoteBalance($entity_id: ID!, $bitcoin_networks: [BitcoinNetwork!], $node_ids: [ID!]) {
601    entity(id: $entity_id) {
602        ... on Account {
603            remote_balance(, bitcoin_networks: $bitcoin_networks, node_ids: $node_ids) {
604                __typename
605                currency_amount_original_value: original_value
606                currency_amount_original_unit: original_unit
607                currency_amount_preferred_currency_unit: preferred_currency_unit
608                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
609                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
610            }
611        }
612    }
613}";
614        let mut variables: HashMap<&str, Value> = HashMap::new();
615        variables.insert("entity_id", self.id.clone().into());
616        variables.insert("bitcoin_networks", bitcoin_networks.into());
617        variables.insert("node_ids", node_ids.into());
618
619        let value = serde_json::to_value(variables).map_err(Error::ConversionError)?;
620        let result = requester.execute_graphql(query, Some(value)).await?;
621        let json = result["entity"]["remote_balance"].clone();
622        let result = if json.is_null() {
623            None
624        } else {
625            Some(serde_json::from_value(json).map_err(Error::JsonError)?)
626        };
627        Ok(result)
628    }
629
630    pub async fn get_uptime_percentage(
631        &self,
632        requester: &impl GraphQLRequester,
633        after_date: Option<DateTime<Utc>>,
634        before_date: Option<DateTime<Utc>>,
635        bitcoin_networks: Option<Vec<BitcoinNetwork>>,
636        node_ids: Option<Vec<String>>,
637    ) -> Result<Option<i64>, Error> {
638        let query = "query FetchAccountUptimePercentage($entity_id: ID!, $after_date: DateTime, $before_date: DateTime, $bitcoin_networks: [BitcoinNetwork!], $node_ids: [ID!]) {
639    entity(id: $entity_id) {
640        ... on Account {
641            uptime_percentage(, after_date: $after_date, before_date: $before_date, bitcoin_networks: $bitcoin_networks, node_ids: $node_ids)
642        }
643    }
644}";
645        let mut variables: HashMap<&str, Value> = HashMap::new();
646        variables.insert("entity_id", self.id.clone().into());
647        variables.insert("after_date", after_date.map(|dt| dt.to_rfc3339()).into());
648        variables.insert("before_date", before_date.map(|dt| dt.to_rfc3339()).into());
649        variables.insert("bitcoin_networks", bitcoin_networks.into());
650        variables.insert("node_ids", node_ids.into());
651
652        let value = serde_json::to_value(variables).map_err(Error::ConversionError)?;
653        let result = requester.execute_graphql(query, Some(value)).await?;
654        let json = result["entity"]["uptime_percentage"].clone();
655        let result = json.as_i64();
656        Ok(result)
657    }
658
659    #[allow(clippy::too_many_arguments)]
660    pub async fn get_channels(
661        &self,
662        requester: &impl GraphQLRequester,
663        bitcoin_network: BitcoinNetwork,
664        lightning_node_id: Option<String>,
665        after_date: Option<DateTime<Utc>>,
666        before_date: Option<DateTime<Utc>>,
667        first: Option<i64>,
668        after: Option<String>,
669    ) -> Result<AccountToChannelsConnection, Error> {
670        let query = "query FetchAccountToChannelsConnection($entity_id: ID!, $bitcoin_network: BitcoinNetwork!, $lightning_node_id: ID, $after_date: DateTime, $before_date: DateTime, $first: Int, $after: String) {
671    entity(id: $entity_id) {
672        ... on Account {
673            channels(, bitcoin_network: $bitcoin_network, lightning_node_id: $lightning_node_id, after_date: $after_date, before_date: $before_date, first: $first, after: $after) {
674                __typename
675                account_to_channels_connection_count: count
676                account_to_channels_connection_page_info: page_info {
677                    __typename
678                    page_info_has_next_page: has_next_page
679                    page_info_has_previous_page: has_previous_page
680                    page_info_start_cursor: start_cursor
681                    page_info_end_cursor: end_cursor
682                }
683                account_to_channels_connection_entities: entities {
684                    __typename
685                    channel_id: id
686                    channel_created_at: created_at
687                    channel_updated_at: updated_at
688                    channel_funding_transaction: funding_transaction {
689                        id
690                    }
691                    channel_capacity: capacity {
692                        __typename
693                        currency_amount_original_value: original_value
694                        currency_amount_original_unit: original_unit
695                        currency_amount_preferred_currency_unit: preferred_currency_unit
696                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
697                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
698                    }
699                    channel_local_balance: local_balance {
700                        __typename
701                        currency_amount_original_value: original_value
702                        currency_amount_original_unit: original_unit
703                        currency_amount_preferred_currency_unit: preferred_currency_unit
704                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
705                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
706                    }
707                    channel_local_unsettled_balance: local_unsettled_balance {
708                        __typename
709                        currency_amount_original_value: original_value
710                        currency_amount_original_unit: original_unit
711                        currency_amount_preferred_currency_unit: preferred_currency_unit
712                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
713                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
714                    }
715                    channel_remote_balance: remote_balance {
716                        __typename
717                        currency_amount_original_value: original_value
718                        currency_amount_original_unit: original_unit
719                        currency_amount_preferred_currency_unit: preferred_currency_unit
720                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
721                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
722                    }
723                    channel_remote_unsettled_balance: remote_unsettled_balance {
724                        __typename
725                        currency_amount_original_value: original_value
726                        currency_amount_original_unit: original_unit
727                        currency_amount_preferred_currency_unit: preferred_currency_unit
728                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
729                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
730                    }
731                    channel_unsettled_balance: unsettled_balance {
732                        __typename
733                        currency_amount_original_value: original_value
734                        currency_amount_original_unit: original_unit
735                        currency_amount_preferred_currency_unit: preferred_currency_unit
736                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
737                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
738                    }
739                    channel_total_balance: total_balance {
740                        __typename
741                        currency_amount_original_value: original_value
742                        currency_amount_original_unit: original_unit
743                        currency_amount_preferred_currency_unit: preferred_currency_unit
744                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
745                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
746                    }
747                    channel_status: status
748                    channel_estimated_force_closure_wait_minutes: estimated_force_closure_wait_minutes
749                    channel_commit_fee: commit_fee {
750                        __typename
751                        currency_amount_original_value: original_value
752                        currency_amount_original_unit: original_unit
753                        currency_amount_preferred_currency_unit: preferred_currency_unit
754                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
755                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
756                    }
757                    channel_fees: fees {
758                        __typename
759                        channel_fees_base_fee: base_fee {
760                            __typename
761                            currency_amount_original_value: original_value
762                            currency_amount_original_unit: original_unit
763                            currency_amount_preferred_currency_unit: preferred_currency_unit
764                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
765                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
766                        }
767                        channel_fees_fee_rate_per_mil: fee_rate_per_mil
768                    }
769                    channel_remote_node: remote_node {
770                        id
771                    }
772                    channel_local_node: local_node {
773                        id
774                    }
775                    channel_short_channel_id: short_channel_id
776                }
777            }
778        }
779    }
780}";
781        let mut variables: HashMap<&str, Value> = HashMap::new();
782        variables.insert("entity_id", self.id.clone().into());
783        variables.insert("bitcoin_network", bitcoin_network.into());
784        variables.insert("lightning_node_id", lightning_node_id.into());
785        variables.insert("after_date", after_date.map(|dt| dt.to_rfc3339()).into());
786        variables.insert("before_date", before_date.map(|dt| dt.to_rfc3339()).into());
787        variables.insert("first", first.into());
788        variables.insert("after", after.into());
789
790        let value = serde_json::to_value(variables).map_err(Error::ConversionError)?;
791        let result = requester.execute_graphql(query, Some(value)).await?;
792        let json = result["entity"]["channels"].clone();
793        let result = serde_json::from_value(json).map_err(Error::JsonError)?;
794        Ok(result)
795    }
796
797    #[allow(clippy::too_many_arguments)]
798    pub async fn get_transactions(
799        &self,
800        requester: &impl GraphQLRequester,
801        first: Option<i64>,
802        after: Option<String>,
803        types: Option<Vec<TransactionType>>,
804        after_date: Option<DateTime<Utc>>,
805        before_date: Option<DateTime<Utc>>,
806        bitcoin_network: Option<BitcoinNetwork>,
807        lightning_node_id: Option<String>,
808        statuses: Option<Vec<TransactionStatus>>,
809        exclude_failures: Option<TransactionFailures>,
810    ) -> Result<AccountToTransactionsConnection, Error> {
811        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) {
812    entity(id: $entity_id) {
813        ... on Account {
814            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) {
815                __typename
816                account_to_transactions_connection_count: count
817                account_to_transactions_connection_page_info: page_info {
818                    __typename
819                    page_info_has_next_page: has_next_page
820                    page_info_has_previous_page: has_previous_page
821                    page_info_start_cursor: start_cursor
822                    page_info_end_cursor: end_cursor
823                }
824                account_to_transactions_connection_profit_loss: profit_loss {
825                    __typename
826                    currency_amount_original_value: original_value
827                    currency_amount_original_unit: original_unit
828                    currency_amount_preferred_currency_unit: preferred_currency_unit
829                    currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
830                    currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
831                }
832                account_to_transactions_connection_average_fee_earned: average_fee_earned {
833                    __typename
834                    currency_amount_original_value: original_value
835                    currency_amount_original_unit: original_unit
836                    currency_amount_preferred_currency_unit: preferred_currency_unit
837                    currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
838                    currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
839                }
840                account_to_transactions_connection_total_amount_transacted: total_amount_transacted {
841                    __typename
842                    currency_amount_original_value: original_value
843                    currency_amount_original_unit: original_unit
844                    currency_amount_preferred_currency_unit: preferred_currency_unit
845                    currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
846                    currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
847                }
848                account_to_transactions_connection_entities: entities {
849                    __typename
850                    ... on ChannelClosingTransaction {
851                        __typename
852                        channel_closing_transaction_id: id
853                        channel_closing_transaction_created_at: created_at
854                        channel_closing_transaction_updated_at: updated_at
855                        channel_closing_transaction_status: status
856                        channel_closing_transaction_resolved_at: resolved_at
857                        channel_closing_transaction_amount: amount {
858                            __typename
859                            currency_amount_original_value: original_value
860                            currency_amount_original_unit: original_unit
861                            currency_amount_preferred_currency_unit: preferred_currency_unit
862                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
863                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
864                        }
865                        channel_closing_transaction_transaction_hash: transaction_hash
866                        channel_closing_transaction_fees: fees {
867                            __typename
868                            currency_amount_original_value: original_value
869                            currency_amount_original_unit: original_unit
870                            currency_amount_preferred_currency_unit: preferred_currency_unit
871                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
872                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
873                        }
874                        channel_closing_transaction_block_hash: block_hash
875                        channel_closing_transaction_block_height: block_height
876                        channel_closing_transaction_destination_addresses: destination_addresses
877                        channel_closing_transaction_num_confirmations: num_confirmations
878                        channel_closing_transaction_channel: channel {
879                            id
880                        }
881                    }
882                    ... on ChannelOpeningTransaction {
883                        __typename
884                        channel_opening_transaction_id: id
885                        channel_opening_transaction_created_at: created_at
886                        channel_opening_transaction_updated_at: updated_at
887                        channel_opening_transaction_status: status
888                        channel_opening_transaction_resolved_at: resolved_at
889                        channel_opening_transaction_amount: amount {
890                            __typename
891                            currency_amount_original_value: original_value
892                            currency_amount_original_unit: original_unit
893                            currency_amount_preferred_currency_unit: preferred_currency_unit
894                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
895                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
896                        }
897                        channel_opening_transaction_transaction_hash: transaction_hash
898                        channel_opening_transaction_fees: fees {
899                            __typename
900                            currency_amount_original_value: original_value
901                            currency_amount_original_unit: original_unit
902                            currency_amount_preferred_currency_unit: preferred_currency_unit
903                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
904                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
905                        }
906                        channel_opening_transaction_block_hash: block_hash
907                        channel_opening_transaction_block_height: block_height
908                        channel_opening_transaction_destination_addresses: destination_addresses
909                        channel_opening_transaction_num_confirmations: num_confirmations
910                        channel_opening_transaction_channel: channel {
911                            id
912                        }
913                    }
914                    ... on Deposit {
915                        __typename
916                        deposit_id: id
917                        deposit_created_at: created_at
918                        deposit_updated_at: updated_at
919                        deposit_status: status
920                        deposit_resolved_at: resolved_at
921                        deposit_amount: amount {
922                            __typename
923                            currency_amount_original_value: original_value
924                            currency_amount_original_unit: original_unit
925                            currency_amount_preferred_currency_unit: preferred_currency_unit
926                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
927                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
928                        }
929                        deposit_transaction_hash: transaction_hash
930                        deposit_fees: fees {
931                            __typename
932                            currency_amount_original_value: original_value
933                            currency_amount_original_unit: original_unit
934                            currency_amount_preferred_currency_unit: preferred_currency_unit
935                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
936                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
937                        }
938                        deposit_block_hash: block_hash
939                        deposit_block_height: block_height
940                        deposit_destination_addresses: destination_addresses
941                        deposit_num_confirmations: num_confirmations
942                        deposit_destination: destination {
943                            id
944                        }
945                    }
946                    ... on IncomingPayment {
947                        __typename
948                        incoming_payment_id: id
949                        incoming_payment_created_at: created_at
950                        incoming_payment_updated_at: updated_at
951                        incoming_payment_status: status
952                        incoming_payment_resolved_at: resolved_at
953                        incoming_payment_amount: amount {
954                            __typename
955                            currency_amount_original_value: original_value
956                            currency_amount_original_unit: original_unit
957                            currency_amount_preferred_currency_unit: preferred_currency_unit
958                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
959                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
960                        }
961                        incoming_payment_transaction_hash: transaction_hash
962                        incoming_payment_is_uma: is_uma
963                        incoming_payment_destination: destination {
964                            id
965                        }
966                        incoming_payment_payment_request: payment_request {
967                            id
968                        }
969                        incoming_payment_uma_post_transaction_data: uma_post_transaction_data {
970                            __typename
971                            post_transaction_data_utxo: utxo
972                            post_transaction_data_amount: amount {
973                                __typename
974                                currency_amount_original_value: original_value
975                                currency_amount_original_unit: original_unit
976                                currency_amount_preferred_currency_unit: preferred_currency_unit
977                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
978                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
979                            }
980                        }
981                        incoming_payment_is_internal_payment: is_internal_payment
982                    }
983                    ... on OutgoingPayment {
984                        __typename
985                        outgoing_payment_id: id
986                        outgoing_payment_created_at: created_at
987                        outgoing_payment_updated_at: updated_at
988                        outgoing_payment_status: status
989                        outgoing_payment_resolved_at: resolved_at
990                        outgoing_payment_amount: amount {
991                            __typename
992                            currency_amount_original_value: original_value
993                            currency_amount_original_unit: original_unit
994                            currency_amount_preferred_currency_unit: preferred_currency_unit
995                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
996                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
997                        }
998                        outgoing_payment_transaction_hash: transaction_hash
999                        outgoing_payment_is_uma: is_uma
1000                        outgoing_payment_origin: origin {
1001                            id
1002                        }
1003                        outgoing_payment_destination: destination {
1004                            id
1005                        }
1006                        outgoing_payment_fees: fees {
1007                            __typename
1008                            currency_amount_original_value: original_value
1009                            currency_amount_original_unit: original_unit
1010                            currency_amount_preferred_currency_unit: preferred_currency_unit
1011                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1012                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1013                        }
1014                        outgoing_payment_payment_request_data: payment_request_data {
1015                            __typename
1016                            ... on InvoiceData {
1017                                __typename
1018                                invoice_data_encoded_payment_request: encoded_payment_request
1019                                invoice_data_bitcoin_network: bitcoin_network
1020                                invoice_data_payment_hash: payment_hash
1021                                invoice_data_amount: amount {
1022                                    __typename
1023                                    currency_amount_original_value: original_value
1024                                    currency_amount_original_unit: original_unit
1025                                    currency_amount_preferred_currency_unit: preferred_currency_unit
1026                                    currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1027                                    currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1028                                }
1029                                invoice_data_created_at: created_at
1030                                invoice_data_expires_at: expires_at
1031                                invoice_data_memo: memo
1032                                invoice_data_destination: destination {
1033                                    __typename
1034                                    ... on GraphNode {
1035                                        __typename
1036                                        graph_node_id: id
1037                                        graph_node_created_at: created_at
1038                                        graph_node_updated_at: updated_at
1039                                        graph_node_alias: alias
1040                                        graph_node_bitcoin_network: bitcoin_network
1041                                        graph_node_color: color
1042                                        graph_node_conductivity: conductivity
1043                                        graph_node_display_name: display_name
1044                                        graph_node_public_key: public_key
1045                                    }
1046                                    ... on LightsparkNodeWithOSK {
1047                                        __typename
1048                                        lightspark_node_with_o_s_k_id: id
1049                                        lightspark_node_with_o_s_k_created_at: created_at
1050                                        lightspark_node_with_o_s_k_updated_at: updated_at
1051                                        lightspark_node_with_o_s_k_alias: alias
1052                                        lightspark_node_with_o_s_k_bitcoin_network: bitcoin_network
1053                                        lightspark_node_with_o_s_k_color: color
1054                                        lightspark_node_with_o_s_k_conductivity: conductivity
1055                                        lightspark_node_with_o_s_k_display_name: display_name
1056                                        lightspark_node_with_o_s_k_public_key: public_key
1057                                        lightspark_node_with_o_s_k_owner: owner {
1058                                            id
1059                                        }
1060                                        lightspark_node_with_o_s_k_status: status
1061                                        lightspark_node_with_o_s_k_total_balance: total_balance {
1062                                            __typename
1063                                            currency_amount_original_value: original_value
1064                                            currency_amount_original_unit: original_unit
1065                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1066                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1067                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1068                                        }
1069                                        lightspark_node_with_o_s_k_total_local_balance: total_local_balance {
1070                                            __typename
1071                                            currency_amount_original_value: original_value
1072                                            currency_amount_original_unit: original_unit
1073                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1074                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1075                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1076                                        }
1077                                        lightspark_node_with_o_s_k_local_balance: local_balance {
1078                                            __typename
1079                                            currency_amount_original_value: original_value
1080                                            currency_amount_original_unit: original_unit
1081                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1082                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1083                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1084                                        }
1085                                        lightspark_node_with_o_s_k_remote_balance: remote_balance {
1086                                            __typename
1087                                            currency_amount_original_value: original_value
1088                                            currency_amount_original_unit: original_unit
1089                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1090                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1091                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1092                                        }
1093                                        lightspark_node_with_o_s_k_blockchain_balance: blockchain_balance {
1094                                            __typename
1095                                            blockchain_balance_total_balance: total_balance {
1096                                                __typename
1097                                                currency_amount_original_value: original_value
1098                                                currency_amount_original_unit: original_unit
1099                                                currency_amount_preferred_currency_unit: preferred_currency_unit
1100                                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1101                                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1102                                            }
1103                                            blockchain_balance_confirmed_balance: confirmed_balance {
1104                                                __typename
1105                                                currency_amount_original_value: original_value
1106                                                currency_amount_original_unit: original_unit
1107                                                currency_amount_preferred_currency_unit: preferred_currency_unit
1108                                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1109                                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1110                                            }
1111                                            blockchain_balance_unconfirmed_balance: unconfirmed_balance {
1112                                                __typename
1113                                                currency_amount_original_value: original_value
1114                                                currency_amount_original_unit: original_unit
1115                                                currency_amount_preferred_currency_unit: preferred_currency_unit
1116                                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1117                                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1118                                            }
1119                                            blockchain_balance_locked_balance: locked_balance {
1120                                                __typename
1121                                                currency_amount_original_value: original_value
1122                                                currency_amount_original_unit: original_unit
1123                                                currency_amount_preferred_currency_unit: preferred_currency_unit
1124                                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1125                                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1126                                            }
1127                                            blockchain_balance_required_reserve: required_reserve {
1128                                                __typename
1129                                                currency_amount_original_value: original_value
1130                                                currency_amount_original_unit: original_unit
1131                                                currency_amount_preferred_currency_unit: preferred_currency_unit
1132                                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1133                                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1134                                            }
1135                                            blockchain_balance_available_balance: available_balance {
1136                                                __typename
1137                                                currency_amount_original_value: original_value
1138                                                currency_amount_original_unit: original_unit
1139                                                currency_amount_preferred_currency_unit: preferred_currency_unit
1140                                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1141                                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1142                                            }
1143                                        }
1144                                        lightspark_node_with_o_s_k_uma_prescreening_utxos: uma_prescreening_utxos
1145                                        lightspark_node_with_o_s_k_balances: balances {
1146                                            __typename
1147                                            balances_owned_balance: owned_balance {
1148                                                __typename
1149                                                currency_amount_original_value: original_value
1150                                                currency_amount_original_unit: original_unit
1151                                                currency_amount_preferred_currency_unit: preferred_currency_unit
1152                                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1153                                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1154                                            }
1155                                            balances_available_to_send_balance: available_to_send_balance {
1156                                                __typename
1157                                                currency_amount_original_value: original_value
1158                                                currency_amount_original_unit: original_unit
1159                                                currency_amount_preferred_currency_unit: preferred_currency_unit
1160                                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1161                                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1162                                            }
1163                                            balances_available_to_withdraw_balance: available_to_withdraw_balance {
1164                                                __typename
1165                                                currency_amount_original_value: original_value
1166                                                currency_amount_original_unit: original_unit
1167                                                currency_amount_preferred_currency_unit: preferred_currency_unit
1168                                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1169                                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1170                                            }
1171                                        }
1172                                        lightspark_node_with_o_s_k_encrypted_signing_private_key: encrypted_signing_private_key {
1173                                            __typename
1174                                            secret_encrypted_value: encrypted_value
1175                                            secret_cipher: cipher
1176                                        }
1177                                    }
1178                                    ... on LightsparkNodeWithRemoteSigning {
1179                                        __typename
1180                                        lightspark_node_with_remote_signing_id: id
1181                                        lightspark_node_with_remote_signing_created_at: created_at
1182                                        lightspark_node_with_remote_signing_updated_at: updated_at
1183                                        lightspark_node_with_remote_signing_alias: alias
1184                                        lightspark_node_with_remote_signing_bitcoin_network: bitcoin_network
1185                                        lightspark_node_with_remote_signing_color: color
1186                                        lightspark_node_with_remote_signing_conductivity: conductivity
1187                                        lightspark_node_with_remote_signing_display_name: display_name
1188                                        lightspark_node_with_remote_signing_public_key: public_key
1189                                        lightspark_node_with_remote_signing_owner: owner {
1190                                            id
1191                                        }
1192                                        lightspark_node_with_remote_signing_status: status
1193                                        lightspark_node_with_remote_signing_total_balance: total_balance {
1194                                            __typename
1195                                            currency_amount_original_value: original_value
1196                                            currency_amount_original_unit: original_unit
1197                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1198                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1199                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1200                                        }
1201                                        lightspark_node_with_remote_signing_total_local_balance: total_local_balance {
1202                                            __typename
1203                                            currency_amount_original_value: original_value
1204                                            currency_amount_original_unit: original_unit
1205                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1206                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1207                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1208                                        }
1209                                        lightspark_node_with_remote_signing_local_balance: local_balance {
1210                                            __typename
1211                                            currency_amount_original_value: original_value
1212                                            currency_amount_original_unit: original_unit
1213                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1214                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1215                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1216                                        }
1217                                        lightspark_node_with_remote_signing_remote_balance: remote_balance {
1218                                            __typename
1219                                            currency_amount_original_value: original_value
1220                                            currency_amount_original_unit: original_unit
1221                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1222                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1223                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1224                                        }
1225                                        lightspark_node_with_remote_signing_blockchain_balance: blockchain_balance {
1226                                            __typename
1227                                            blockchain_balance_total_balance: total_balance {
1228                                                __typename
1229                                                currency_amount_original_value: original_value
1230                                                currency_amount_original_unit: original_unit
1231                                                currency_amount_preferred_currency_unit: preferred_currency_unit
1232                                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1233                                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1234                                            }
1235                                            blockchain_balance_confirmed_balance: confirmed_balance {
1236                                                __typename
1237                                                currency_amount_original_value: original_value
1238                                                currency_amount_original_unit: original_unit
1239                                                currency_amount_preferred_currency_unit: preferred_currency_unit
1240                                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1241                                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1242                                            }
1243                                            blockchain_balance_unconfirmed_balance: unconfirmed_balance {
1244                                                __typename
1245                                                currency_amount_original_value: original_value
1246                                                currency_amount_original_unit: original_unit
1247                                                currency_amount_preferred_currency_unit: preferred_currency_unit
1248                                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1249                                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1250                                            }
1251                                            blockchain_balance_locked_balance: locked_balance {
1252                                                __typename
1253                                                currency_amount_original_value: original_value
1254                                                currency_amount_original_unit: original_unit
1255                                                currency_amount_preferred_currency_unit: preferred_currency_unit
1256                                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1257                                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1258                                            }
1259                                            blockchain_balance_required_reserve: required_reserve {
1260                                                __typename
1261                                                currency_amount_original_value: original_value
1262                                                currency_amount_original_unit: original_unit
1263                                                currency_amount_preferred_currency_unit: preferred_currency_unit
1264                                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1265                                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1266                                            }
1267                                            blockchain_balance_available_balance: available_balance {
1268                                                __typename
1269                                                currency_amount_original_value: original_value
1270                                                currency_amount_original_unit: original_unit
1271                                                currency_amount_preferred_currency_unit: preferred_currency_unit
1272                                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1273                                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1274                                            }
1275                                        }
1276                                        lightspark_node_with_remote_signing_uma_prescreening_utxos: uma_prescreening_utxos
1277                                        lightspark_node_with_remote_signing_balances: balances {
1278                                            __typename
1279                                            balances_owned_balance: owned_balance {
1280                                                __typename
1281                                                currency_amount_original_value: original_value
1282                                                currency_amount_original_unit: original_unit
1283                                                currency_amount_preferred_currency_unit: preferred_currency_unit
1284                                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1285                                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1286                                            }
1287                                            balances_available_to_send_balance: available_to_send_balance {
1288                                                __typename
1289                                                currency_amount_original_value: original_value
1290                                                currency_amount_original_unit: original_unit
1291                                                currency_amount_preferred_currency_unit: preferred_currency_unit
1292                                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1293                                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1294                                            }
1295                                            balances_available_to_withdraw_balance: available_to_withdraw_balance {
1296                                                __typename
1297                                                currency_amount_original_value: original_value
1298                                                currency_amount_original_unit: original_unit
1299                                                currency_amount_preferred_currency_unit: preferred_currency_unit
1300                                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1301                                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1302                                            }
1303                                        }
1304                                    }
1305                                }
1306                            }
1307                        }
1308                        outgoing_payment_failure_reason: failure_reason
1309                        outgoing_payment_failure_message: failure_message {
1310                            __typename
1311                            rich_text_text: text
1312                        }
1313                        outgoing_payment_uma_post_transaction_data: uma_post_transaction_data {
1314                            __typename
1315                            post_transaction_data_utxo: utxo
1316                            post_transaction_data_amount: amount {
1317                                __typename
1318                                currency_amount_original_value: original_value
1319                                currency_amount_original_unit: original_unit
1320                                currency_amount_preferred_currency_unit: preferred_currency_unit
1321                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1322                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1323                            }
1324                        }
1325                        outgoing_payment_payment_preimage: payment_preimage
1326                        outgoing_payment_is_internal_payment: is_internal_payment
1327                        outgoing_payment_idempotency_key: idempotency_key
1328                    }
1329                    ... on RoutingTransaction {
1330                        __typename
1331                        routing_transaction_id: id
1332                        routing_transaction_created_at: created_at
1333                        routing_transaction_updated_at: updated_at
1334                        routing_transaction_status: status
1335                        routing_transaction_resolved_at: resolved_at
1336                        routing_transaction_amount: amount {
1337                            __typename
1338                            currency_amount_original_value: original_value
1339                            currency_amount_original_unit: original_unit
1340                            currency_amount_preferred_currency_unit: preferred_currency_unit
1341                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1342                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1343                        }
1344                        routing_transaction_transaction_hash: transaction_hash
1345                        routing_transaction_incoming_channel: incoming_channel {
1346                            id
1347                        }
1348                        routing_transaction_outgoing_channel: outgoing_channel {
1349                            id
1350                        }
1351                        routing_transaction_fees: fees {
1352                            __typename
1353                            currency_amount_original_value: original_value
1354                            currency_amount_original_unit: original_unit
1355                            currency_amount_preferred_currency_unit: preferred_currency_unit
1356                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1357                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1358                        }
1359                        routing_transaction_failure_message: failure_message {
1360                            __typename
1361                            rich_text_text: text
1362                        }
1363                        routing_transaction_failure_reason: failure_reason
1364                    }
1365                    ... on Withdrawal {
1366                        __typename
1367                        withdrawal_id: id
1368                        withdrawal_created_at: created_at
1369                        withdrawal_updated_at: updated_at
1370                        withdrawal_status: status
1371                        withdrawal_resolved_at: resolved_at
1372                        withdrawal_amount: amount {
1373                            __typename
1374                            currency_amount_original_value: original_value
1375                            currency_amount_original_unit: original_unit
1376                            currency_amount_preferred_currency_unit: preferred_currency_unit
1377                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1378                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1379                        }
1380                        withdrawal_transaction_hash: transaction_hash
1381                        withdrawal_fees: fees {
1382                            __typename
1383                            currency_amount_original_value: original_value
1384                            currency_amount_original_unit: original_unit
1385                            currency_amount_preferred_currency_unit: preferred_currency_unit
1386                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1387                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1388                        }
1389                        withdrawal_block_hash: block_hash
1390                        withdrawal_block_height: block_height
1391                        withdrawal_destination_addresses: destination_addresses
1392                        withdrawal_num_confirmations: num_confirmations
1393                        withdrawal_origin: origin {
1394                            id
1395                        }
1396                    }
1397                }
1398            }
1399        }
1400    }
1401}";
1402        let mut variables: HashMap<&str, Value> = HashMap::new();
1403        variables.insert("entity_id", self.id.clone().into());
1404        variables.insert("first", first.into());
1405        variables.insert("after", after.into());
1406        variables.insert("types", types.into());
1407        variables.insert("after_date", after_date.map(|dt| dt.to_rfc3339()).into());
1408        variables.insert("before_date", before_date.map(|dt| dt.to_rfc3339()).into());
1409        variables.insert("bitcoin_network", bitcoin_network.into());
1410        variables.insert("lightning_node_id", lightning_node_id.into());
1411        variables.insert("statuses", statuses.into());
1412        variables.insert(
1413            "exclude_failures",
1414            serde_json::to_value(&exclude_failures).map_err(Error::ConversionError)?,
1415        );
1416
1417        let value = serde_json::to_value(variables).map_err(Error::ConversionError)?;
1418        let result = requester.execute_graphql(query, Some(value)).await?;
1419        let json = result["entity"]["transactions"].clone();
1420        let result = serde_json::from_value(json).map_err(Error::JsonError)?;
1421        Ok(result)
1422    }
1423
1424    #[allow(clippy::too_many_arguments)]
1425    pub async fn get_payment_requests(
1426        &self,
1427        requester: &impl GraphQLRequester,
1428        first: Option<i64>,
1429        after: Option<String>,
1430        after_date: Option<DateTime<Utc>>,
1431        before_date: Option<DateTime<Utc>>,
1432        bitcoin_network: Option<BitcoinNetwork>,
1433        lightning_node_id: Option<String>,
1434    ) -> Result<AccountToPaymentRequestsConnection, Error> {
1435        let query = "query FetchAccountToPaymentRequestsConnection($entity_id: ID!, $first: Int, $after: String, $after_date: DateTime, $before_date: DateTime, $bitcoin_network: BitcoinNetwork, $lightning_node_id: ID) {
1436    entity(id: $entity_id) {
1437        ... on Account {
1438            payment_requests(, first: $first, after: $after, after_date: $after_date, before_date: $before_date, bitcoin_network: $bitcoin_network, lightning_node_id: $lightning_node_id) {
1439                __typename
1440                account_to_payment_requests_connection_count: count
1441                account_to_payment_requests_connection_page_info: page_info {
1442                    __typename
1443                    page_info_has_next_page: has_next_page
1444                    page_info_has_previous_page: has_previous_page
1445                    page_info_start_cursor: start_cursor
1446                    page_info_end_cursor: end_cursor
1447                }
1448                account_to_payment_requests_connection_entities: entities {
1449                    __typename
1450                    ... on Invoice {
1451                        __typename
1452                        invoice_id: id
1453                        invoice_created_at: created_at
1454                        invoice_updated_at: updated_at
1455                        invoice_data: data {
1456                            __typename
1457                            invoice_data_encoded_payment_request: encoded_payment_request
1458                            invoice_data_bitcoin_network: bitcoin_network
1459                            invoice_data_payment_hash: payment_hash
1460                            invoice_data_amount: amount {
1461                                __typename
1462                                currency_amount_original_value: original_value
1463                                currency_amount_original_unit: original_unit
1464                                currency_amount_preferred_currency_unit: preferred_currency_unit
1465                                currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1466                                currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1467                            }
1468                            invoice_data_created_at: created_at
1469                            invoice_data_expires_at: expires_at
1470                            invoice_data_memo: memo
1471                            invoice_data_destination: destination {
1472                                __typename
1473                                ... on GraphNode {
1474                                    __typename
1475                                    graph_node_id: id
1476                                    graph_node_created_at: created_at
1477                                    graph_node_updated_at: updated_at
1478                                    graph_node_alias: alias
1479                                    graph_node_bitcoin_network: bitcoin_network
1480                                    graph_node_color: color
1481                                    graph_node_conductivity: conductivity
1482                                    graph_node_display_name: display_name
1483                                    graph_node_public_key: public_key
1484                                }
1485                                ... on LightsparkNodeWithOSK {
1486                                    __typename
1487                                    lightspark_node_with_o_s_k_id: id
1488                                    lightspark_node_with_o_s_k_created_at: created_at
1489                                    lightspark_node_with_o_s_k_updated_at: updated_at
1490                                    lightspark_node_with_o_s_k_alias: alias
1491                                    lightspark_node_with_o_s_k_bitcoin_network: bitcoin_network
1492                                    lightspark_node_with_o_s_k_color: color
1493                                    lightspark_node_with_o_s_k_conductivity: conductivity
1494                                    lightspark_node_with_o_s_k_display_name: display_name
1495                                    lightspark_node_with_o_s_k_public_key: public_key
1496                                    lightspark_node_with_o_s_k_owner: owner {
1497                                        id
1498                                    }
1499                                    lightspark_node_with_o_s_k_status: status
1500                                    lightspark_node_with_o_s_k_total_balance: total_balance {
1501                                        __typename
1502                                        currency_amount_original_value: original_value
1503                                        currency_amount_original_unit: original_unit
1504                                        currency_amount_preferred_currency_unit: preferred_currency_unit
1505                                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1506                                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1507                                    }
1508                                    lightspark_node_with_o_s_k_total_local_balance: total_local_balance {
1509                                        __typename
1510                                        currency_amount_original_value: original_value
1511                                        currency_amount_original_unit: original_unit
1512                                        currency_amount_preferred_currency_unit: preferred_currency_unit
1513                                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1514                                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1515                                    }
1516                                    lightspark_node_with_o_s_k_local_balance: local_balance {
1517                                        __typename
1518                                        currency_amount_original_value: original_value
1519                                        currency_amount_original_unit: original_unit
1520                                        currency_amount_preferred_currency_unit: preferred_currency_unit
1521                                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1522                                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1523                                    }
1524                                    lightspark_node_with_o_s_k_remote_balance: remote_balance {
1525                                        __typename
1526                                        currency_amount_original_value: original_value
1527                                        currency_amount_original_unit: original_unit
1528                                        currency_amount_preferred_currency_unit: preferred_currency_unit
1529                                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1530                                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1531                                    }
1532                                    lightspark_node_with_o_s_k_blockchain_balance: blockchain_balance {
1533                                        __typename
1534                                        blockchain_balance_total_balance: total_balance {
1535                                            __typename
1536                                            currency_amount_original_value: original_value
1537                                            currency_amount_original_unit: original_unit
1538                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1539                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1540                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1541                                        }
1542                                        blockchain_balance_confirmed_balance: confirmed_balance {
1543                                            __typename
1544                                            currency_amount_original_value: original_value
1545                                            currency_amount_original_unit: original_unit
1546                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1547                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1548                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1549                                        }
1550                                        blockchain_balance_unconfirmed_balance: unconfirmed_balance {
1551                                            __typename
1552                                            currency_amount_original_value: original_value
1553                                            currency_amount_original_unit: original_unit
1554                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1555                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1556                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1557                                        }
1558                                        blockchain_balance_locked_balance: locked_balance {
1559                                            __typename
1560                                            currency_amount_original_value: original_value
1561                                            currency_amount_original_unit: original_unit
1562                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1563                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1564                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1565                                        }
1566                                        blockchain_balance_required_reserve: required_reserve {
1567                                            __typename
1568                                            currency_amount_original_value: original_value
1569                                            currency_amount_original_unit: original_unit
1570                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1571                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1572                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1573                                        }
1574                                        blockchain_balance_available_balance: available_balance {
1575                                            __typename
1576                                            currency_amount_original_value: original_value
1577                                            currency_amount_original_unit: original_unit
1578                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1579                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1580                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1581                                        }
1582                                    }
1583                                    lightspark_node_with_o_s_k_uma_prescreening_utxos: uma_prescreening_utxos
1584                                    lightspark_node_with_o_s_k_balances: balances {
1585                                        __typename
1586                                        balances_owned_balance: owned_balance {
1587                                            __typename
1588                                            currency_amount_original_value: original_value
1589                                            currency_amount_original_unit: original_unit
1590                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1591                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1592                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1593                                        }
1594                                        balances_available_to_send_balance: available_to_send_balance {
1595                                            __typename
1596                                            currency_amount_original_value: original_value
1597                                            currency_amount_original_unit: original_unit
1598                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1599                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1600                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1601                                        }
1602                                        balances_available_to_withdraw_balance: available_to_withdraw_balance {
1603                                            __typename
1604                                            currency_amount_original_value: original_value
1605                                            currency_amount_original_unit: original_unit
1606                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1607                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1608                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1609                                        }
1610                                    }
1611                                    lightspark_node_with_o_s_k_encrypted_signing_private_key: encrypted_signing_private_key {
1612                                        __typename
1613                                        secret_encrypted_value: encrypted_value
1614                                        secret_cipher: cipher
1615                                    }
1616                                }
1617                                ... on LightsparkNodeWithRemoteSigning {
1618                                    __typename
1619                                    lightspark_node_with_remote_signing_id: id
1620                                    lightspark_node_with_remote_signing_created_at: created_at
1621                                    lightspark_node_with_remote_signing_updated_at: updated_at
1622                                    lightspark_node_with_remote_signing_alias: alias
1623                                    lightspark_node_with_remote_signing_bitcoin_network: bitcoin_network
1624                                    lightspark_node_with_remote_signing_color: color
1625                                    lightspark_node_with_remote_signing_conductivity: conductivity
1626                                    lightspark_node_with_remote_signing_display_name: display_name
1627                                    lightspark_node_with_remote_signing_public_key: public_key
1628                                    lightspark_node_with_remote_signing_owner: owner {
1629                                        id
1630                                    }
1631                                    lightspark_node_with_remote_signing_status: status
1632                                    lightspark_node_with_remote_signing_total_balance: total_balance {
1633                                        __typename
1634                                        currency_amount_original_value: original_value
1635                                        currency_amount_original_unit: original_unit
1636                                        currency_amount_preferred_currency_unit: preferred_currency_unit
1637                                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1638                                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1639                                    }
1640                                    lightspark_node_with_remote_signing_total_local_balance: total_local_balance {
1641                                        __typename
1642                                        currency_amount_original_value: original_value
1643                                        currency_amount_original_unit: original_unit
1644                                        currency_amount_preferred_currency_unit: preferred_currency_unit
1645                                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1646                                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1647                                    }
1648                                    lightspark_node_with_remote_signing_local_balance: local_balance {
1649                                        __typename
1650                                        currency_amount_original_value: original_value
1651                                        currency_amount_original_unit: original_unit
1652                                        currency_amount_preferred_currency_unit: preferred_currency_unit
1653                                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1654                                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1655                                    }
1656                                    lightspark_node_with_remote_signing_remote_balance: remote_balance {
1657                                        __typename
1658                                        currency_amount_original_value: original_value
1659                                        currency_amount_original_unit: original_unit
1660                                        currency_amount_preferred_currency_unit: preferred_currency_unit
1661                                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1662                                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1663                                    }
1664                                    lightspark_node_with_remote_signing_blockchain_balance: blockchain_balance {
1665                                        __typename
1666                                        blockchain_balance_total_balance: total_balance {
1667                                            __typename
1668                                            currency_amount_original_value: original_value
1669                                            currency_amount_original_unit: original_unit
1670                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1671                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1672                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1673                                        }
1674                                        blockchain_balance_confirmed_balance: confirmed_balance {
1675                                            __typename
1676                                            currency_amount_original_value: original_value
1677                                            currency_amount_original_unit: original_unit
1678                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1679                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1680                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1681                                        }
1682                                        blockchain_balance_unconfirmed_balance: unconfirmed_balance {
1683                                            __typename
1684                                            currency_amount_original_value: original_value
1685                                            currency_amount_original_unit: original_unit
1686                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1687                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1688                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1689                                        }
1690                                        blockchain_balance_locked_balance: locked_balance {
1691                                            __typename
1692                                            currency_amount_original_value: original_value
1693                                            currency_amount_original_unit: original_unit
1694                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1695                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1696                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1697                                        }
1698                                        blockchain_balance_required_reserve: required_reserve {
1699                                            __typename
1700                                            currency_amount_original_value: original_value
1701                                            currency_amount_original_unit: original_unit
1702                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1703                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1704                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1705                                        }
1706                                        blockchain_balance_available_balance: available_balance {
1707                                            __typename
1708                                            currency_amount_original_value: original_value
1709                                            currency_amount_original_unit: original_unit
1710                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1711                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1712                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1713                                        }
1714                                    }
1715                                    lightspark_node_with_remote_signing_uma_prescreening_utxos: uma_prescreening_utxos
1716                                    lightspark_node_with_remote_signing_balances: balances {
1717                                        __typename
1718                                        balances_owned_balance: owned_balance {
1719                                            __typename
1720                                            currency_amount_original_value: original_value
1721                                            currency_amount_original_unit: original_unit
1722                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1723                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1724                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1725                                        }
1726                                        balances_available_to_send_balance: available_to_send_balance {
1727                                            __typename
1728                                            currency_amount_original_value: original_value
1729                                            currency_amount_original_unit: original_unit
1730                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1731                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1732                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1733                                        }
1734                                        balances_available_to_withdraw_balance: available_to_withdraw_balance {
1735                                            __typename
1736                                            currency_amount_original_value: original_value
1737                                            currency_amount_original_unit: original_unit
1738                                            currency_amount_preferred_currency_unit: preferred_currency_unit
1739                                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1740                                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1741                                        }
1742                                    }
1743                                }
1744                            }
1745                        }
1746                        invoice_status: status
1747                        invoice_amount_paid: amount_paid {
1748                            __typename
1749                            currency_amount_original_value: original_value
1750                            currency_amount_original_unit: original_unit
1751                            currency_amount_preferred_currency_unit: preferred_currency_unit
1752                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1753                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1754                        }
1755                        invoice_is_uma: is_uma
1756                        invoice_is_lnurl: is_lnurl
1757                    }
1758                }
1759            }
1760        }
1761    }
1762}";
1763        let mut variables: HashMap<&str, Value> = HashMap::new();
1764        variables.insert("entity_id", self.id.clone().into());
1765        variables.insert("first", first.into());
1766        variables.insert("after", after.into());
1767        variables.insert("after_date", after_date.map(|dt| dt.to_rfc3339()).into());
1768        variables.insert("before_date", before_date.map(|dt| dt.to_rfc3339()).into());
1769        variables.insert("bitcoin_network", bitcoin_network.into());
1770        variables.insert("lightning_node_id", lightning_node_id.into());
1771
1772        let value = serde_json::to_value(variables).map_err(Error::ConversionError)?;
1773        let result = requester.execute_graphql(query, Some(value)).await?;
1774        let json = result["entity"]["payment_requests"].clone();
1775        let result = serde_json::from_value(json).map_err(Error::JsonError)?;
1776        Ok(result)
1777    }
1778
1779    #[allow(clippy::too_many_arguments)]
1780    pub async fn get_withdrawal_requests(
1781        &self,
1782        requester: &impl GraphQLRequester,
1783        first: Option<i64>,
1784        after: Option<String>,
1785        bitcoin_networks: Option<Vec<BitcoinNetwork>>,
1786        statuses: Option<Vec<WithdrawalRequestStatus>>,
1787        node_ids: Option<Vec<String>>,
1788        idempotency_keys: Option<Vec<String>>,
1789        after_date: Option<DateTime<Utc>>,
1790        before_date: Option<DateTime<Utc>>,
1791    ) -> Result<AccountToWithdrawalRequestsConnection, Error> {
1792        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) {
1793    entity(id: $entity_id) {
1794        ... on Account {
1795            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) {
1796                __typename
1797                account_to_withdrawal_requests_connection_count: count
1798                account_to_withdrawal_requests_connection_page_info: page_info {
1799                    __typename
1800                    page_info_has_next_page: has_next_page
1801                    page_info_has_previous_page: has_previous_page
1802                    page_info_start_cursor: start_cursor
1803                    page_info_end_cursor: end_cursor
1804                }
1805                account_to_withdrawal_requests_connection_entities: entities {
1806                    __typename
1807                    withdrawal_request_id: id
1808                    withdrawal_request_created_at: created_at
1809                    withdrawal_request_updated_at: updated_at
1810                    withdrawal_request_requested_amount: requested_amount {
1811                        __typename
1812                        currency_amount_original_value: original_value
1813                        currency_amount_original_unit: original_unit
1814                        currency_amount_preferred_currency_unit: preferred_currency_unit
1815                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1816                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1817                    }
1818                    withdrawal_request_amount: amount {
1819                        __typename
1820                        currency_amount_original_value: original_value
1821                        currency_amount_original_unit: original_unit
1822                        currency_amount_preferred_currency_unit: preferred_currency_unit
1823                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1824                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1825                    }
1826                    withdrawal_request_estimated_amount: estimated_amount {
1827                        __typename
1828                        currency_amount_original_value: original_value
1829                        currency_amount_original_unit: original_unit
1830                        currency_amount_preferred_currency_unit: preferred_currency_unit
1831                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1832                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1833                    }
1834                    withdrawal_request_amount_withdrawn: amount_withdrawn {
1835                        __typename
1836                        currency_amount_original_value: original_value
1837                        currency_amount_original_unit: original_unit
1838                        currency_amount_preferred_currency_unit: preferred_currency_unit
1839                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1840                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1841                    }
1842                    withdrawal_request_total_fees: total_fees {
1843                        __typename
1844                        currency_amount_original_value: original_value
1845                        currency_amount_original_unit: original_unit
1846                        currency_amount_preferred_currency_unit: preferred_currency_unit
1847                        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1848                        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1849                    }
1850                    withdrawal_request_bitcoin_address: bitcoin_address
1851                    withdrawal_request_withdrawal_mode: withdrawal_mode
1852                    withdrawal_request_status: status
1853                    withdrawal_request_completed_at: completed_at
1854                    withdrawal_request_withdrawal: withdrawal {
1855                        id
1856                    }
1857                    withdrawal_request_idempotency_key: idempotency_key
1858                    withdrawal_request_initiator: initiator
1859                }
1860            }
1861        }
1862    }
1863}";
1864        let mut variables: HashMap<&str, Value> = HashMap::new();
1865        variables.insert("entity_id", self.id.clone().into());
1866        variables.insert("first", first.into());
1867        variables.insert("after", after.into());
1868        variables.insert("bitcoin_networks", bitcoin_networks.into());
1869        variables.insert("statuses", statuses.into());
1870        variables.insert("node_ids", node_ids.into());
1871        variables.insert("idempotency_keys", idempotency_keys.into());
1872        variables.insert("after_date", after_date.map(|dt| dt.to_rfc3339()).into());
1873        variables.insert("before_date", before_date.map(|dt| dt.to_rfc3339()).into());
1874
1875        let value = serde_json::to_value(variables).map_err(Error::ConversionError)?;
1876        let result = requester.execute_graphql(query, Some(value)).await?;
1877        let json = result["entity"]["withdrawal_requests"].clone();
1878        let result = serde_json::from_value(json).map_err(Error::JsonError)?;
1879        Ok(result)
1880    }
1881
1882    pub async fn get_wallets(
1883        &self,
1884        requester: &impl GraphQLRequester,
1885        first: Option<i64>,
1886        after: Option<String>,
1887        third_party_ids: Option<Vec<String>>,
1888    ) -> Result<AccountToWalletsConnection, Error> {
1889        let query = "query FetchAccountToWalletsConnection($entity_id: ID!, $first: Int, $after: String, $third_party_ids: [String!]) {
1890    entity(id: $entity_id) {
1891        ... on Account {
1892            wallets(, first: $first, after: $after, third_party_ids: $third_party_ids) {
1893                __typename
1894                account_to_wallets_connection_count: count
1895                account_to_wallets_connection_page_info: page_info {
1896                    __typename
1897                    page_info_has_next_page: has_next_page
1898                    page_info_has_previous_page: has_previous_page
1899                    page_info_start_cursor: start_cursor
1900                    page_info_end_cursor: end_cursor
1901                }
1902                account_to_wallets_connection_entities: entities {
1903                    __typename
1904                    wallet_id: id
1905                    wallet_created_at: created_at
1906                    wallet_updated_at: updated_at
1907                    wallet_last_login_at: last_login_at
1908                    wallet_balances: balances {
1909                        __typename
1910                        balances_owned_balance: owned_balance {
1911                            __typename
1912                            currency_amount_original_value: original_value
1913                            currency_amount_original_unit: original_unit
1914                            currency_amount_preferred_currency_unit: preferred_currency_unit
1915                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1916                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1917                        }
1918                        balances_available_to_send_balance: available_to_send_balance {
1919                            __typename
1920                            currency_amount_original_value: original_value
1921                            currency_amount_original_unit: original_unit
1922                            currency_amount_preferred_currency_unit: preferred_currency_unit
1923                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1924                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1925                        }
1926                        balances_available_to_withdraw_balance: available_to_withdraw_balance {
1927                            __typename
1928                            currency_amount_original_value: original_value
1929                            currency_amount_original_unit: original_unit
1930                            currency_amount_preferred_currency_unit: preferred_currency_unit
1931                            currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1932                            currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1933                        }
1934                    }
1935                    wallet_third_party_identifier: third_party_identifier
1936                    wallet_account: account {
1937                        id
1938                    }
1939                    wallet_status: status
1940                }
1941            }
1942        }
1943    }
1944}";
1945        let mut variables: HashMap<&str, Value> = HashMap::new();
1946        variables.insert("entity_id", self.id.clone().into());
1947        variables.insert("first", first.into());
1948        variables.insert("after", after.into());
1949        variables.insert("third_party_ids", third_party_ids.into());
1950
1951        let value = serde_json::to_value(variables).map_err(Error::ConversionError)?;
1952        let result = requester.execute_graphql(query, Some(value)).await?;
1953        let json = result["entity"]["wallets"].clone();
1954        let result = serde_json::from_value(json).map_err(Error::JsonError)?;
1955        Ok(result)
1956    }
1957}