From 7c4465d97623be786ae66a42c70d7a1c24209161 Mon Sep 17 00:00:00 2001 From: olegkubrakov Date: Mon, 17 Mar 2025 18:18:42 -0700 Subject: [PATCH] Enable Signet --- lightspark/src/objects/account.rs | 113 +++++++++++------- .../objects/account_to_nodes_connection.rs | 1 + .../account_to_payment_requests_connection.rs | 1 + .../account_to_transactions_connection.rs | 1 + lightspark/src/objects/bitcoin_network.rs | 6 +- lightspark/src/objects/channel.rs | 10 +- lightspark/src/objects/channel_status.rs | 6 +- lightspark/src/objects/compliance_provider.rs | 6 +- .../src/objects/create_invoice_input.rs | 6 + lightspark/src/objects/create_offer_input.rs | 14 +++ lightspark/src/objects/create_offer_output.rs | 18 +++ .../objects/create_test_mode_invoice_input.rs | 4 + .../src/objects/currency_amount_input.rs | 10 ++ lightspark/src/objects/currency_unit.rs | 16 ++- lightspark/src/objects/entity.rs | 16 +++ lightspark/src/objects/graph_node.rs | 6 +- .../src/objects/htlc_attempt_failure_code.rs | 6 +- .../incentives_ineligibility_reason.rs | 6 +- lightspark/src/objects/incentives_status.rs | 6 +- lightspark/src/objects/incoming_payment.rs | 6 +- .../incoming_payment_attempt_status.rs | 6 +- lightspark/src/objects/invoice.rs | 2 +- lightspark/src/objects/invoice_data.rs | 3 +- lightspark/src/objects/invoice_type.rs | 6 +- .../objects/lightning_payment_direction.rs | 6 +- lightspark/src/objects/lightspark_node.rs | 1 + .../src/objects/lightspark_node_status.rs | 6 +- .../src/objects/lightspark_node_with_o_s_k.rs | 19 +-- .../lightspark_node_with_remote_signing.rs | 19 +-- lightspark/src/objects/mod.rs | 8 ++ lightspark/src/objects/node_address_type.rs | 6 +- lightspark/src/objects/offer.rs | 105 ++++++++++++++++ lightspark/src/objects/offer_data.rs | 105 ++++++++++++++++ lightspark/src/objects/on_chain_fee_target.rs | 6 +- lightspark/src/objects/outgoing_payment.rs | 7 +- .../src/objects/outgoing_payment_attempt.rs | 6 +- .../outgoing_payment_attempt_status.rs | 6 +- lightspark/src/objects/pay_offer_input.rs | 23 ++++ lightspark/src/objects/pay_offer_output.rs | 19 +++ .../objects/pay_test_mode_invoice_input.rs | 27 +++++ lightspark/src/objects/payment_direction.rs | 6 +- .../src/objects/payment_failure_reason.rs | 6 +- .../src/objects/payment_request_status.rs | 6 +- lightspark/src/objects/permission.rs | 6 +- lightspark/src/objects/region_code.rs | 6 +- .../objects/remote_signing_sub_event_type.rs | 6 +- lightspark/src/objects/request_initiator.rs | 6 +- lightspark/src/objects/risk_rating.rs | 6 +- .../routing_transaction_failure_reason.rs | 6 +- .../src/objects/signable_payload_status.rs | 6 +- lightspark/src/objects/transaction_status.rs | 6 +- lightspark/src/objects/transaction_type.rs | 6 +- lightspark/src/objects/wallet.rs | 30 ++--- lightspark/src/objects/wallet_status.rs | 6 +- .../wallet_to_payment_requests_connection.rs | 1 + .../wallet_to_transactions_connection.rs | 1 + lightspark/src/objects/webhook_event_type.rs | 6 +- lightspark/src/objects/withdrawal_mode.rs | 6 +- lightspark/src/objects/withdrawal_request.rs | 18 +-- .../src/objects/withdrawal_request_status.rs | 6 +- 60 files changed, 598 insertions(+), 192 deletions(-) create mode 100644 lightspark/src/objects/create_offer_input.rs create mode 100644 lightspark/src/objects/create_offer_output.rs create mode 100644 lightspark/src/objects/currency_amount_input.rs create mode 100644 lightspark/src/objects/offer.rs create mode 100644 lightspark/src/objects/offer_data.rs create mode 100644 lightspark/src/objects/pay_offer_input.rs create mode 100644 lightspark/src/objects/pay_offer_output.rs create mode 100644 lightspark/src/objects/pay_test_mode_invoice_input.rs diff --git a/lightspark/src/objects/account.rs b/lightspark/src/objects/account.rs index 163b841..5d2c4d6 100644 --- a/lightspark/src/objects/account.rs +++ b/lightspark/src/objects/account.rs @@ -10,6 +10,7 @@ use crate::objects::account_to_withdrawal_requests_connection::AccountToWithdraw use crate::objects::bitcoin_network::BitcoinNetwork; use crate::objects::blockchain_balance::BlockchainBalance; use crate::objects::currency_amount::CurrencyAmount; +use crate::objects::currency_amount_input::CurrencyAmountInput; use crate::objects::entity::Entity; use crate::objects::lightspark_node_owner::LightsparkNodeOwner; use crate::objects::transaction_failures::TransactionFailures; @@ -143,10 +144,10 @@ impl Account { variables.insert("first", first.into()); variables.insert("after", after.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["api_tokens"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } @@ -218,13 +219,13 @@ impl Account { variables.insert("bitcoin_networks", bitcoin_networks.into()); variables.insert("node_ids", node_ids.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["blockchain_balance"].clone(); let result = if json.is_null() { None } else { - Some(serde_json::from_value(json).map_err(Error::JsonError)?) + Some(serde_json::from_value(json).map_err(|err| Error::JsonError(err))?) }; Ok(result) } @@ -247,8 +248,8 @@ impl Account { variables.insert("bitcoin_networks", bitcoin_networks.into()); variables.insert("node_ids", node_ids.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["conductivity"].clone(); let result = json.as_i64(); Ok(result) @@ -279,13 +280,13 @@ impl Account { variables.insert("bitcoin_networks", bitcoin_networks.into()); variables.insert("node_ids", node_ids.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["local_balance"].clone(); let result = if json.is_null() { None } else { - Some(serde_json::from_value(json).map_err(Error::JsonError)?) + Some(serde_json::from_value(json).map_err(|err| Error::JsonError(err))?) }; Ok(result) } @@ -584,10 +585,10 @@ impl Account { variables.insert("node_ids", node_ids.into()); variables.insert("after", after.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["nodes"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } @@ -616,13 +617,13 @@ impl Account { variables.insert("bitcoin_networks", bitcoin_networks.into()); variables.insert("node_ids", node_ids.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["remote_balance"].clone(); let result = if json.is_null() { None } else { - Some(serde_json::from_value(json).map_err(Error::JsonError)?) + Some(serde_json::from_value(json).map_err(|err| Error::JsonError(err))?) }; Ok(result) } @@ -649,8 +650,8 @@ impl Account { variables.insert("bitcoin_networks", bitcoin_networks.into()); variables.insert("node_ids", node_ids.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["uptime_percentage"].clone(); let result = json.as_i64(); Ok(result) @@ -787,10 +788,10 @@ impl Account { variables.insert("first", first.into()); variables.insert("after", after.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["channels"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } @@ -807,11 +808,13 @@ impl Account { lightning_node_id: Option, statuses: Option>, exclude_failures: Option, + max_amount: Option, + min_amount: Option, ) -> Result { - 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) { + 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, $max_amount: CurrencyAmountInput, $min_amount: CurrencyAmountInput) { entity(id: $entity_id) { ... on Account { - transactions(, first: $first, after: $after, types: $types, after_date: $after_date, before_date: $before_date, bitcoin_network: $bitcoin_network, lightning_node_id: $lightning_node_id, statuses: $statuses, exclude_failures: $exclude_failures) { + 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, max_amount: $max_amount, min_amount: $min_amount) { __typename account_to_transactions_connection_count: count account_to_transactions_connection_page_info: page_info { @@ -1411,13 +1414,21 @@ impl Account { variables.insert("statuses", statuses.into()); variables.insert( "exclude_failures", - serde_json::to_value(&exclude_failures).map_err(Error::ConversionError)?, + serde_json::to_value(&exclude_failures).map_err(|err| Error::ConversionError(err))?, + ); + variables.insert( + "max_amount", + serde_json::to_value(&max_amount).map_err(|err| Error::ConversionError(err))?, + ); + variables.insert( + "min_amount", + serde_json::to_value(&min_amount).map_err(|err| Error::ConversionError(err))?, ); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["transactions"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } @@ -1431,11 +1442,13 @@ impl Account { before_date: Option>, bitcoin_network: Option, lightning_node_id: Option, + max_amount: Option, + min_amount: Option, ) -> Result { - let query = "query FetchAccountToPaymentRequestsConnection($entity_id: ID!, $first: Int, $after: String, $after_date: DateTime, $before_date: DateTime, $bitcoin_network: BitcoinNetwork, $lightning_node_id: ID) { + let query = "query FetchAccountToPaymentRequestsConnection($entity_id: ID!, $first: Int, $after: String, $after_date: DateTime, $before_date: DateTime, $bitcoin_network: BitcoinNetwork, $lightning_node_id: ID, $max_amount: CurrencyAmountInput, $min_amount: CurrencyAmountInput) { entity(id: $entity_id) { ... on Account { - payment_requests(, first: $first, after: $after, after_date: $after_date, before_date: $before_date, bitcoin_network: $bitcoin_network, lightning_node_id: $lightning_node_id) { + payment_requests(, first: $first, after: $after, after_date: $after_date, before_date: $before_date, bitcoin_network: $bitcoin_network, lightning_node_id: $lightning_node_id, max_amount: $max_amount, min_amount: $min_amount) { __typename account_to_payment_requests_connection_count: count account_to_payment_requests_connection_page_info: page_info { @@ -1768,11 +1781,19 @@ impl Account { variables.insert("before_date", before_date.map(|dt| dt.to_rfc3339()).into()); variables.insert("bitcoin_network", bitcoin_network.into()); variables.insert("lightning_node_id", lightning_node_id.into()); + variables.insert( + "max_amount", + serde_json::to_value(&max_amount).map_err(|err| Error::ConversionError(err))?, + ); + variables.insert( + "min_amount", + serde_json::to_value(&min_amount).map_err(|err| Error::ConversionError(err))?, + ); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["payment_requests"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } @@ -1788,11 +1809,13 @@ impl Account { idempotency_keys: Option>, after_date: Option>, before_date: Option>, + max_amount: Option, + min_amount: Option, ) -> Result { - 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) { + 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, $max_amount: CurrencyAmountInput, $min_amount: CurrencyAmountInput) { entity(id: $entity_id) { ... on Account { - withdrawal_requests(, first: $first, after: $after, bitcoin_networks: $bitcoin_networks, statuses: $statuses, node_ids: $node_ids, idempotency_keys: $idempotency_keys, after_date: $after_date, before_date: $before_date) { + 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, max_amount: $max_amount, min_amount: $min_amount) { __typename account_to_withdrawal_requests_connection_count: count account_to_withdrawal_requests_connection_page_info: page_info { @@ -1871,11 +1894,19 @@ impl Account { variables.insert("idempotency_keys", idempotency_keys.into()); variables.insert("after_date", after_date.map(|dt| dt.to_rfc3339()).into()); variables.insert("before_date", before_date.map(|dt| dt.to_rfc3339()).into()); + variables.insert( + "max_amount", + serde_json::to_value(&max_amount).map_err(|err| Error::ConversionError(err))?, + ); + variables.insert( + "min_amount", + serde_json::to_value(&min_amount).map_err(|err| Error::ConversionError(err))?, + ); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["withdrawal_requests"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } @@ -1948,10 +1979,10 @@ impl Account { variables.insert("after", after.into()); variables.insert("third_party_ids", third_party_ids.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["wallets"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } } diff --git a/lightspark/src/objects/account_to_nodes_connection.rs b/lightspark/src/objects/account_to_nodes_connection.rs index f627e8a..8bc9f09 100644 --- a/lightspark/src/objects/account_to_nodes_connection.rs +++ b/lightspark/src/objects/account_to_nodes_connection.rs @@ -1,5 +1,6 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved use crate::objects::connection::Connection; +use crate::objects::lightspark_node::LightsparkNode; use crate::objects::lightspark_node::LightsparkNodeEnum; use crate::objects::page_info::PageInfo; use serde::{Deserialize, Serialize}; diff --git a/lightspark/src/objects/account_to_payment_requests_connection.rs b/lightspark/src/objects/account_to_payment_requests_connection.rs index d43c3c9..02a1103 100644 --- a/lightspark/src/objects/account_to_payment_requests_connection.rs +++ b/lightspark/src/objects/account_to_payment_requests_connection.rs @@ -1,6 +1,7 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved use crate::objects::connection::Connection; use crate::objects::page_info::PageInfo; +use crate::objects::payment_request::PaymentRequest; use crate::objects::payment_request::PaymentRequestEnum; use serde::{Deserialize, Serialize}; use std::vec::Vec; diff --git a/lightspark/src/objects/account_to_transactions_connection.rs b/lightspark/src/objects/account_to_transactions_connection.rs index 3e1416d..217466b 100644 --- a/lightspark/src/objects/account_to_transactions_connection.rs +++ b/lightspark/src/objects/account_to_transactions_connection.rs @@ -2,6 +2,7 @@ use crate::objects::connection::Connection; use crate::objects::currency_amount::CurrencyAmount; use crate::objects::page_info::PageInfo; +use crate::objects::transaction::Transaction; use crate::objects::transaction::TransactionEnum; use serde::{Deserialize, Serialize}; use std::vec::Vec; diff --git a/lightspark/src/objects/bitcoin_network.rs b/lightspark/src/objects/bitcoin_network.rs index 90ccd6d..eb46bc6 100644 --- a/lightspark/src/objects/bitcoin_network.rs +++ b/lightspark/src/objects/bitcoin_network.rs @@ -24,9 +24,9 @@ pub enum BitcoinNetwork { Testnet, } -impl From for Value { - fn from(val: BitcoinNetwork) -> Self { - Value::from(val.to_string()) +impl Into for BitcoinNetwork { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/channel.rs b/lightspark/src/objects/channel.rs index 1270acb..d5a5dea 100644 --- a/lightspark/src/objects/channel.rs +++ b/lightspark/src/objects/channel.rs @@ -251,8 +251,8 @@ impl Channel { variables.insert("after_date", after_date.map(|dt| dt.to_rfc3339()).into()); variables.insert("before_date", before_date.map(|dt| dt.to_rfc3339()).into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["uptime_percentage"].clone(); let result = json.as_i64(); Ok(result) @@ -305,10 +305,10 @@ impl Channel { variables.insert("after_date", after_date.map(|dt| dt.to_rfc3339()).into()); variables.insert("before_date", before_date.map(|dt| dt.to_rfc3339()).into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["transactions"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } } diff --git a/lightspark/src/objects/channel_status.rs b/lightspark/src/objects/channel_status.rs index fa55356..a92768e 100644 --- a/lightspark/src/objects/channel_status.rs +++ b/lightspark/src/objects/channel_status.rs @@ -36,9 +36,9 @@ pub enum ChannelStatus { Error, } -impl From for Value { - fn from(val: ChannelStatus) -> Self { - Value::from(val.to_string()) +impl Into for ChannelStatus { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/compliance_provider.rs b/lightspark/src/objects/compliance_provider.rs index 08eb806..6b3d687 100644 --- a/lightspark/src/objects/compliance_provider.rs +++ b/lightspark/src/objects/compliance_provider.rs @@ -10,9 +10,9 @@ pub enum ComplianceProvider { Chainalysis, } -impl From for Value { - fn from(val: ComplianceProvider) -> Self { - Value::from(val.to_string()) +impl Into for ComplianceProvider { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/create_invoice_input.rs b/lightspark/src/objects/create_invoice_input.rs index 7287726..25dbe2d 100644 --- a/lightspark/src/objects/create_invoice_input.rs +++ b/lightspark/src/objects/create_invoice_input.rs @@ -16,4 +16,10 @@ pub struct CreateInvoiceInput { /// The expiry of the invoice in seconds. Default value is 86400 (1 day). pub expiry_secs: Option, + + /// The payment hash of the invoice. It should only be set if your node is a remote signing node. If not set, it will be requested through REMOTE_SIGNING webhooks with sub event type REQUEST_INVOICE_PAYMENT_HASH. + pub payment_hash: Option, + + /// The 32-byte nonce used to generate the invoice preimage if applicable. It will later be included in RELEASE_PAYMENT_PREIMAGE webhook to help recover the raw preimage. This can only be specified when `payment_hash` is specified. + pub preimage_nonce: Option, } diff --git a/lightspark/src/objects/create_offer_input.rs b/lightspark/src/objects/create_offer_input.rs new file mode 100644 index 0000000..3c25c96 --- /dev/null +++ b/lightspark/src/objects/create_offer_input.rs @@ -0,0 +1,14 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct CreateOfferInput { + /// The node from which to create the offer. + pub node_id: String, + + /// The amount for which the offer should be created, in millisatoshis. Setting the amount to 0 will allow the payer to specify an amount. + pub amount_msats: Option, + + /// A short description of the offer. + pub description: Option, +} diff --git a/lightspark/src/objects/create_offer_output.rs b/lightspark/src/objects/create_offer_output.rs new file mode 100644 index 0000000..5c4e201 --- /dev/null +++ b/lightspark/src/objects/create_offer_output.rs @@ -0,0 +1,18 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use crate::types::entity_wrapper::EntityWrapper; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct CreateOfferOutput { + #[serde(rename = "create_offer_output_offer")] + pub offer: EntityWrapper, +} + +pub const FRAGMENT: &str = " +fragment CreateOfferOutputFragment on CreateOfferOutput { + __typename + create_offer_output_offer: offer { + id + } +} +"; diff --git a/lightspark/src/objects/create_test_mode_invoice_input.rs b/lightspark/src/objects/create_test_mode_invoice_input.rs index 4f6cbdb..7563235 100644 --- a/lightspark/src/objects/create_test_mode_invoice_input.rs +++ b/lightspark/src/objects/create_test_mode_invoice_input.rs @@ -4,11 +4,15 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Deserialize, Serialize)] pub struct CreateTestModeInvoiceInput { + /// The local node from which to create the invoice. pub local_node_id: String, + /// The amount for which the invoice should be created, in millisatoshis. Setting the amount to 0 will allow the payer to specify an amount. pub amount_msats: i64, + /// An optional memo to include in the invoice. pub memo: Option, + /// The type of invoice to create. pub invoice_type: Option, } diff --git a/lightspark/src/objects/currency_amount_input.rs b/lightspark/src/objects/currency_amount_input.rs new file mode 100644 index 0000000..7bcd025 --- /dev/null +++ b/lightspark/src/objects/currency_amount_input.rs @@ -0,0 +1,10 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use crate::objects::currency_unit::CurrencyUnit; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct CurrencyAmountInput { + pub value: i64, + + pub unit: CurrencyUnit, +} diff --git a/lightspark/src/objects/currency_unit.rs b/lightspark/src/objects/currency_unit.rs index 5c96fd5..13fceb4 100644 --- a/lightspark/src/objects/currency_unit.rs +++ b/lightspark/src/objects/currency_unit.rs @@ -26,6 +26,14 @@ pub enum CurrencyUnit { #[serde(rename = "MXN")] Mxn, + /// Philippine Peso. + + #[serde(rename = "PHP")] + Php, + /// Euro. + + #[serde(rename = "EUR")] + Eur, /// 0.000000001 (10e-9) Bitcoin or a billionth of a Bitcoin. We recommend using the Satoshi unit instead when possible. #[serde(rename = "NANOBITCOIN")] @@ -40,9 +48,9 @@ pub enum CurrencyUnit { Millibitcoin, } -impl From for Value { - fn from(val: CurrencyUnit) -> Self { - Value::from(val.to_string()) +impl Into for CurrencyUnit { + fn into(self) -> Value { + Value::from(self.to_string()) } } @@ -54,6 +62,8 @@ impl fmt::Display for CurrencyUnit { Self::Millisatoshi => write!(f, "MILLISATOSHI"), Self::Usd => write!(f, "USD"), Self::Mxn => write!(f, "MXN"), + Self::Php => write!(f, "PHP"), + Self::Eur => write!(f, "EUR"), Self::Nanobitcoin => write!(f, "NANOBITCOIN"), Self::Microbitcoin => write!(f, "MICROBITCOIN"), Self::Millibitcoin => write!(f, "MILLIBITCOIN"), diff --git a/lightspark/src/objects/entity.rs b/lightspark/src/objects/entity.rs index b00c3ef..eee1453 100644 --- a/lightspark/src/objects/entity.rs +++ b/lightspark/src/objects/entity.rs @@ -14,6 +14,8 @@ use super::incoming_payment_attempt::IncomingPaymentAttempt; use super::invoice::Invoice; use super::lightspark_node_with_o_s_k::LightsparkNodeWithOSK; use super::lightspark_node_with_remote_signing::LightsparkNodeWithRemoteSigning; +use super::offer::Offer; +use super::offer_data::OfferData; use super::outgoing_payment::OutgoingPayment; use super::outgoing_payment_attempt::OutgoingPaymentAttempt; use super::routing_transaction::RoutingTransaction; @@ -57,6 +59,8 @@ pub enum EntityEnum { Invoice(Invoice), LightsparkNodeWithOSK(LightsparkNodeWithOSK), LightsparkNodeWithRemoteSigning(LightsparkNodeWithRemoteSigning), + Offer(Offer), + OfferData(OfferData), OutgoingPayment(OutgoingPayment), OutgoingPaymentAttempt(OutgoingPaymentAttempt), RoutingTransaction(RoutingTransaction), @@ -161,6 +165,18 @@ impl<'de> Deserialize<'de> for EntityEnum { })?; Ok(EntityEnum::LightsparkNodeWithRemoteSigning(obj)) } + "Offer" => { + let obj = Offer::deserialize(value).map_err(|err| { + serde::de::Error::custom(format!("Serde JSON Error {}", err)) + })?; + Ok(EntityEnum::Offer(obj)) + } + "OfferData" => { + let obj = OfferData::deserialize(value).map_err(|err| { + serde::de::Error::custom(format!("Serde JSON Error {}", err)) + })?; + Ok(EntityEnum::OfferData(obj)) + } "OutgoingPayment" => { let obj = OutgoingPayment::deserialize(value).map_err(|err| { serde::de::Error::custom(format!("Serde JSON Error {}", err)) diff --git a/lightspark/src/objects/graph_node.rs b/lightspark/src/objects/graph_node.rs index 96ceabf..297200d 100644 --- a/lightspark/src/objects/graph_node.rs +++ b/lightspark/src/objects/graph_node.rs @@ -175,10 +175,10 @@ impl GraphNode { variables.insert("first", first.into()); variables.insert("types", types.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["addresses"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } } diff --git a/lightspark/src/objects/htlc_attempt_failure_code.rs b/lightspark/src/objects/htlc_attempt_failure_code.rs index 4d64600..2c96122 100644 --- a/lightspark/src/objects/htlc_attempt_failure_code.rs +++ b/lightspark/src/objects/htlc_attempt_failure_code.rs @@ -91,9 +91,9 @@ pub enum HtlcAttemptFailureCode { UnreadableFailure, } -impl From for Value { - fn from(val: HtlcAttemptFailureCode) -> Self { - Value::from(val.to_string()) +impl Into for HtlcAttemptFailureCode { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/incentives_ineligibility_reason.rs b/lightspark/src/objects/incentives_ineligibility_reason.rs index 65de36d..216bada 100644 --- a/lightspark/src/objects/incentives_ineligibility_reason.rs +++ b/lightspark/src/objects/incentives_ineligibility_reason.rs @@ -32,9 +32,9 @@ pub enum IncentivesIneligibilityReason { NotCrossBorder, } -impl From for Value { - fn from(val: IncentivesIneligibilityReason) -> Self { - Value::from(val.to_string()) +impl Into for IncentivesIneligibilityReason { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/incentives_status.rs b/lightspark/src/objects/incentives_status.rs index 17dbac3..874317d 100644 --- a/lightspark/src/objects/incentives_status.rs +++ b/lightspark/src/objects/incentives_status.rs @@ -20,9 +20,9 @@ pub enum IncentivesStatus { Ineligible, } -impl From for Value { - fn from(val: IncentivesStatus) -> Self { - Value::from(val.to_string()) +impl Into for IncentivesStatus { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/incoming_payment.rs b/lightspark/src/objects/incoming_payment.rs index df01baf..330ae00 100644 --- a/lightspark/src/objects/incoming_payment.rs +++ b/lightspark/src/objects/incoming_payment.rs @@ -239,10 +239,10 @@ impl IncomingPayment { variables.insert("statuses", statuses.into()); variables.insert("after", after.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["attempts"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } } diff --git a/lightspark/src/objects/incoming_payment_attempt_status.rs b/lightspark/src/objects/incoming_payment_attempt_status.rs index cbbbd81..7134229 100644 --- a/lightspark/src/objects/incoming_payment_attempt_status.rs +++ b/lightspark/src/objects/incoming_payment_attempt_status.rs @@ -19,9 +19,9 @@ pub enum IncomingPaymentAttemptStatus { Unknown, } -impl From for Value { - fn from(val: IncomingPaymentAttemptStatus) -> Self { - Value::from(val.to_string()) +impl Into for IncomingPaymentAttemptStatus { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/invoice.rs b/lightspark/src/objects/invoice.rs index fd80bef..1d6fce8 100644 --- a/lightspark/src/objects/invoice.rs +++ b/lightspark/src/objects/invoice.rs @@ -10,7 +10,7 @@ use crate::types::get_entity::GetEntity; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; -/// This object represents a BOLT #11 invoice (https://github.com/lightning/bolts/blob/master/11-payment-encoding.md) created by a Lightspark Node. You can retrieve this object to receive relevant payment information for a specific invoice generated by a Lightspark node. +/// This object represents a Bolt #11 or Bolt #12 invoice created by a Lightspark Node. You can retrieve this object to receive relevant payment information for a specific invoice generated by a Lightspark node. #[derive(Debug, Clone, Deserialize, Serialize)] pub struct Invoice { /// The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque string. diff --git a/lightspark/src/objects/invoice_data.rs b/lightspark/src/objects/invoice_data.rs index d906ccf..25106ec 100644 --- a/lightspark/src/objects/invoice_data.rs +++ b/lightspark/src/objects/invoice_data.rs @@ -1,13 +1,14 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved use crate::objects::bitcoin_network::BitcoinNetwork; use crate::objects::currency_amount::CurrencyAmount; +use crate::objects::node::Node; use crate::objects::node::NodeEnum; use crate::objects::payment_request_data::PaymentRequestData; use crate::types::custom_date_formats::custom_date_format; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; -/// This object represents the data associated with a BOLT #11 invoice. You can retrieve this object to receive the relevant data associated with a specific invoice. +/// This object represents the data associated with a Bolt #11 or Bolt #12 invoice. You can retrieve this object to receive the relevant data associated with a specific invoice. #[derive(Debug, Clone, Deserialize, Serialize)] pub struct InvoiceData { #[serde(rename = "invoice_data_encoded_payment_request")] diff --git a/lightspark/src/objects/invoice_type.rs b/lightspark/src/objects/invoice_type.rs index d8d429b..6432f93 100644 --- a/lightspark/src/objects/invoice_type.rs +++ b/lightspark/src/objects/invoice_type.rs @@ -16,9 +16,9 @@ pub enum InvoiceType { Amp, } -impl From for Value { - fn from(val: InvoiceType) -> Self { - Value::from(val.to_string()) +impl Into for InvoiceType { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/lightning_payment_direction.rs b/lightspark/src/objects/lightning_payment_direction.rs index fffeea4..79fb3fb 100644 --- a/lightspark/src/objects/lightning_payment_direction.rs +++ b/lightspark/src/objects/lightning_payment_direction.rs @@ -16,9 +16,9 @@ pub enum LightningPaymentDirection { Outgoing, } -impl From for Value { - fn from(val: LightningPaymentDirection) -> Self { - Value::from(val.to_string()) +impl Into for LightningPaymentDirection { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/lightspark_node.rs b/lightspark/src/objects/lightspark_node.rs index 5721546..59549a5 100644 --- a/lightspark/src/objects/lightspark_node.rs +++ b/lightspark/src/objects/lightspark_node.rs @@ -5,6 +5,7 @@ use crate::objects::balances::Balances; use crate::objects::blockchain_balance::BlockchainBalance; use crate::objects::currency_amount::CurrencyAmount; use crate::objects::entity::Entity; +use crate::objects::lightspark_node_owner::LightsparkNodeOwner; use crate::objects::lightspark_node_status::LightsparkNodeStatus; use crate::objects::node::Node; use crate::types::entity_wrapper::EntityWrapper; diff --git a/lightspark/src/objects/lightspark_node_status.rs b/lightspark/src/objects/lightspark_node_status.rs index 3a9ab2d..e3b9af5 100644 --- a/lightspark/src/objects/lightspark_node_status.rs +++ b/lightspark/src/objects/lightspark_node_status.rs @@ -36,9 +36,9 @@ pub enum LightsparkNodeStatus { FailedToDeploy, } -impl From for Value { - fn from(val: LightsparkNodeStatus) -> Self { - Value::from(val.to_string()) +impl Into for LightsparkNodeStatus { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/lightspark_node_with_o_s_k.rs b/lightspark/src/objects/lightspark_node_with_o_s_k.rs index 19e51b2..87cd002 100644 --- a/lightspark/src/objects/lightspark_node_with_o_s_k.rs +++ b/lightspark/src/objects/lightspark_node_with_o_s_k.rs @@ -8,6 +8,7 @@ use crate::objects::currency_amount::CurrencyAmount; use crate::objects::entity::Entity; use crate::objects::lightning_payment_direction::LightningPaymentDirection; use crate::objects::lightspark_node::LightsparkNode; +use crate::objects::lightspark_node_owner::LightsparkNodeOwner; use crate::objects::lightspark_node_status::LightsparkNodeStatus; use crate::objects::lightspark_node_to_channels_connection::LightsparkNodeToChannelsConnection; use crate::objects::lightspark_node_to_daily_liquidity_forecasts_connection::LightsparkNodeToDailyLiquidityForecastsConnection; @@ -404,10 +405,10 @@ impl LightsparkNodeWithOSK { variables.insert("first", first.into()); variables.insert("types", types.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["addresses"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } @@ -539,10 +540,10 @@ impl LightsparkNodeWithOSK { variables.insert("after_date", after_date.map(|dt| dt.to_rfc3339()).into()); variables.insert("statuses", statuses.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["channels"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } @@ -584,10 +585,10 @@ impl LightsparkNodeWithOSK { variables.insert("to_date", to_date.format("%Y-%m-%d").to_string().into()); variables.insert("direction", direction.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["daily_liquidity_forecasts"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } } diff --git a/lightspark/src/objects/lightspark_node_with_remote_signing.rs b/lightspark/src/objects/lightspark_node_with_remote_signing.rs index 346440b..eaa8e25 100644 --- a/lightspark/src/objects/lightspark_node_with_remote_signing.rs +++ b/lightspark/src/objects/lightspark_node_with_remote_signing.rs @@ -8,6 +8,7 @@ use crate::objects::currency_amount::CurrencyAmount; use crate::objects::entity::Entity; use crate::objects::lightning_payment_direction::LightningPaymentDirection; use crate::objects::lightspark_node::LightsparkNode; +use crate::objects::lightspark_node_owner::LightsparkNodeOwner; use crate::objects::lightspark_node_status::LightsparkNodeStatus; use crate::objects::lightspark_node_to_channels_connection::LightsparkNodeToChannelsConnection; use crate::objects::lightspark_node_to_daily_liquidity_forecasts_connection::LightsparkNodeToDailyLiquidityForecastsConnection; @@ -394,10 +395,10 @@ impl LightsparkNodeWithRemoteSigning { variables.insert("first", first.into()); variables.insert("types", types.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["addresses"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } @@ -529,10 +530,10 @@ impl LightsparkNodeWithRemoteSigning { variables.insert("after_date", after_date.map(|dt| dt.to_rfc3339()).into()); variables.insert("statuses", statuses.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["channels"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } @@ -574,10 +575,10 @@ impl LightsparkNodeWithRemoteSigning { variables.insert("to_date", to_date.format("%Y-%m-%d").to_string().into()); variables.insert("direction", direction.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["daily_liquidity_forecasts"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } } diff --git a/lightspark/src/objects/mod.rs b/lightspark/src/objects/mod.rs index c8e4320..f966bcb 100644 --- a/lightspark/src/objects/mod.rs +++ b/lightspark/src/objects/mod.rs @@ -37,6 +37,8 @@ pub mod create_invoice_output; pub mod create_lnurl_invoice_input; pub mod create_node_wallet_address_input; pub mod create_node_wallet_address_output; +pub mod create_offer_input; +pub mod create_offer_output; pub mod create_test_mode_invoice_input; pub mod create_test_mode_invoice_output; pub mod create_test_mode_payment_input; @@ -45,6 +47,7 @@ pub mod create_uma_invitation_input; pub mod create_uma_invitation_output; pub mod create_uma_invoice_input; pub mod currency_amount; +pub mod currency_amount_input; pub mod currency_unit; pub mod daily_liquidity_forecast; pub mod decline_to_sign_messages_input; @@ -94,6 +97,8 @@ pub mod node; pub mod node_address; pub mod node_address_type; pub mod node_to_addresses_connection; +pub mod offer; +pub mod offer_data; pub mod on_chain_fee_target; pub mod on_chain_transaction; pub mod outgoing_payment; @@ -110,6 +115,9 @@ pub mod outgoing_payments_for_payment_hash_query_output; pub mod page_info; pub mod pay_invoice_input; pub mod pay_invoice_output; +pub mod pay_offer_input; +pub mod pay_offer_output; +pub mod pay_test_mode_invoice_input; pub mod pay_uma_invoice_input; pub mod payment_direction; pub mod payment_failure_reason; diff --git a/lightspark/src/objects/node_address_type.rs b/lightspark/src/objects/node_address_type.rs index 716982b..2f7e2dd 100644 --- a/lightspark/src/objects/node_address_type.rs +++ b/lightspark/src/objects/node_address_type.rs @@ -16,9 +16,9 @@ pub enum NodeAddressType { Tor, } -impl From for Value { - fn from(val: NodeAddressType) -> Self { - Value::from(val.to_string()) +impl Into for NodeAddressType { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/offer.rs b/lightspark/src/objects/offer.rs new file mode 100644 index 0000000..9a4f7ff --- /dev/null +++ b/lightspark/src/objects/offer.rs @@ -0,0 +1,105 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use crate::objects::currency_amount::CurrencyAmount; +use crate::objects::entity::Entity; +use crate::types::custom_date_formats::custom_date_format; +use crate::types::entity_wrapper::EntityWrapper; +use crate::types::get_entity::GetEntity; +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; + +/// This object represents a BOLT #12 offer (https://github.com/lightning/bolts/blob/master/12-offer-encoding.md) created by a Lightspark Node. +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct Offer { + /// The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque string. + #[serde(rename = "offer_id")] + pub id: String, + + /// The date and time when the entity was first created. + #[serde(with = "custom_date_format", rename = "offer_created_at")] + pub created_at: DateTime, + + /// The date and time when the entity was last updated. + #[serde(with = "custom_date_format", rename = "offer_updated_at")] + pub updated_at: DateTime, + + /// The details of the offer. + #[serde(rename = "offer_data")] + pub data: EntityWrapper, + + /// The BOLT12 encoded offer. Starts with 'lno'. + #[serde(rename = "offer_encoded_offer")] + pub encoded_offer: String, + + /// The amount of the offer. If null, the payer chooses the amount. + #[serde(rename = "offer_amount")] + pub amount: Option, + + /// The description of the offer. + #[serde(rename = "offer_description")] + pub description: Option, + + /// The typename of the object + #[serde(rename = "__typename")] + pub typename: String, +} + +impl Entity for Offer { + /// The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque string. + fn get_id(&self) -> String { + self.id.clone() + } + + /// The date and time when the entity was first created. + fn get_created_at(&self) -> DateTime { + self.created_at + } + + /// The date and time when the entity was last updated. + fn get_updated_at(&self) -> DateTime { + self.updated_at + } + + fn type_name(&self) -> &'static str { + "Offer" + } +} + +impl GetEntity for Offer { + fn get_entity_query() -> String { + format!( + " + query GetEntity($id: ID!) {{ + entity(id: $id) {{ + ... on Offer {{ + ... OfferFragment + }} + }} + }} + + {}", + FRAGMENT + ) + } +} + +pub const FRAGMENT: &str = " +fragment OfferFragment on Offer { + __typename + offer_id: id + offer_created_at: created_at + offer_updated_at: updated_at + offer_data: data { + id + } + offer_encoded_offer: encoded_offer + offer_amount: amount { + __typename + currency_amount_original_value: original_value + currency_amount_original_unit: original_unit + currency_amount_preferred_currency_unit: preferred_currency_unit + currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded + currency_amount_preferred_currency_value_approx: preferred_currency_value_approx + } + offer_description: description +} +"; diff --git a/lightspark/src/objects/offer_data.rs b/lightspark/src/objects/offer_data.rs new file mode 100644 index 0000000..319784b --- /dev/null +++ b/lightspark/src/objects/offer_data.rs @@ -0,0 +1,105 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use crate::objects::bitcoin_network::BitcoinNetwork; +use crate::objects::currency_amount::CurrencyAmount; +use crate::objects::entity::Entity; +use crate::types::custom_date_formats::custom_date_format; +use crate::types::custom_date_formats::custom_date_format_option; +use crate::types::get_entity::GetEntity; +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; +use std::vec::Vec; + +/// This object represents the data associated with a BOLT #12 offer. You can retrieve this object to receive the relevant data associated with a specific offer. +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct OfferData { + /// The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque string. + #[serde(rename = "offer_data_id")] + pub id: String, + + /// The date and time when the entity was first created. + #[serde(with = "custom_date_format", rename = "offer_data_created_at")] + pub created_at: DateTime, + + /// The date and time when the entity was last updated. + #[serde(with = "custom_date_format", rename = "offer_data_updated_at")] + pub updated_at: DateTime, + + /// The requested amount in this invoice. If it is equal to 0, the sender should choose the amount to send. + #[serde(rename = "offer_data_amount")] + pub amount: Option, + + /// The Bech32 encoded offer. + #[serde(rename = "offer_data_encoded_offer")] + pub encoded_offer: String, + + /// The bitcoin networks supported by the offer. + #[serde(rename = "offer_data_bitcoin_networks")] + pub bitcoin_networks: Vec, + + /// The date and time when this invoice will expire. + #[serde(with = "custom_date_format_option", rename = "offer_data_expires_at")] + pub expires_at: Option>, + + /// The typename of the object + #[serde(rename = "__typename")] + pub typename: String, +} + +impl Entity for OfferData { + /// The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque string. + fn get_id(&self) -> String { + self.id.clone() + } + + /// The date and time when the entity was first created. + fn get_created_at(&self) -> DateTime { + self.created_at + } + + /// The date and time when the entity was last updated. + fn get_updated_at(&self) -> DateTime { + self.updated_at + } + + fn type_name(&self) -> &'static str { + "OfferData" + } +} + +impl GetEntity for OfferData { + fn get_entity_query() -> String { + format!( + " + query GetEntity($id: ID!) {{ + entity(id: $id) {{ + ... on OfferData {{ + ... OfferDataFragment + }} + }} + }} + + {}", + FRAGMENT + ) + } +} + +pub const FRAGMENT: &str = " +fragment OfferDataFragment on OfferData { + __typename + offer_data_id: id + offer_data_created_at: created_at + offer_data_updated_at: updated_at + offer_data_amount: amount { + __typename + currency_amount_original_value: original_value + currency_amount_original_unit: original_unit + currency_amount_preferred_currency_unit: preferred_currency_unit + currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded + currency_amount_preferred_currency_value_approx: preferred_currency_value_approx + } + offer_data_encoded_offer: encoded_offer + offer_data_bitcoin_networks: bitcoin_networks + offer_data_expires_at: expires_at +} +"; diff --git a/lightspark/src/objects/on_chain_fee_target.rs b/lightspark/src/objects/on_chain_fee_target.rs index 70239ae..43871b5 100644 --- a/lightspark/src/objects/on_chain_fee_target.rs +++ b/lightspark/src/objects/on_chain_fee_target.rs @@ -23,9 +23,9 @@ pub enum OnChainFeeTarget { Background, } -impl From for Value { - fn from(val: OnChainFeeTarget) -> Self { - Value::from(val.to_string()) +impl Into for OnChainFeeTarget { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/outgoing_payment.rs b/lightspark/src/objects/outgoing_payment.rs index a8d187a..fd21451 100644 --- a/lightspark/src/objects/outgoing_payment.rs +++ b/lightspark/src/objects/outgoing_payment.rs @@ -5,6 +5,7 @@ use crate::objects::entity::Entity; use crate::objects::lightning_transaction::LightningTransaction; use crate::objects::outgoing_payment_to_attempts_connection::OutgoingPaymentToAttemptsConnection; use crate::objects::payment_failure_reason::PaymentFailureReason; +use crate::objects::payment_request_data::PaymentRequestData; use crate::objects::payment_request_data::PaymentRequestDataEnum; use crate::objects::post_transaction_data::PostTransactionData; use crate::objects::rich_text::RichText; @@ -586,10 +587,10 @@ impl OutgoingPayment { variables.insert("first", first.into()); variables.insert("after", after.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["attempts"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } } diff --git a/lightspark/src/objects/outgoing_payment_attempt.rs b/lightspark/src/objects/outgoing_payment_attempt.rs index 450a2d4..ba7995d 100644 --- a/lightspark/src/objects/outgoing_payment_attempt.rs +++ b/lightspark/src/objects/outgoing_payment_attempt.rs @@ -215,10 +215,10 @@ impl OutgoingPaymentAttempt { variables.insert("first", first.into()); variables.insert("after", after.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["hops"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } } diff --git a/lightspark/src/objects/outgoing_payment_attempt_status.rs b/lightspark/src/objects/outgoing_payment_attempt_status.rs index 61e9f9e..9ffae68 100644 --- a/lightspark/src/objects/outgoing_payment_attempt_status.rs +++ b/lightspark/src/objects/outgoing_payment_attempt_status.rs @@ -16,9 +16,9 @@ pub enum OutgoingPaymentAttemptStatus { Failed, } -impl From for Value { - fn from(val: OutgoingPaymentAttemptStatus) -> Self { - Value::from(val.to_string()) +impl Into for OutgoingPaymentAttemptStatus { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/pay_offer_input.rs b/lightspark/src/objects/pay_offer_input.rs new file mode 100644 index 0000000..f42656e --- /dev/null +++ b/lightspark/src/objects/pay_offer_input.rs @@ -0,0 +1,23 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct PayOfferInput { + /// The ID of the node that will be sending the payment. + pub node_id: String, + + /// The Bech32 offer you want to pay (as defined by the BOLT12 standard). + pub encoded_offer: String, + + /// The timeout in seconds that we will try to make the payment. + pub timeout_secs: i64, + + /// The maximum amount of fees that you want to pay for this payment to be sent, expressed in msats. + pub maximum_fees_msats: i64, + + /// The amount you will pay for this offer, expressed in msats. It should ONLY be set when the offer amount is zero. + pub amount_msats: Option, + + /// An idempotency key for this payment. If provided, it will be used to create a payment with the same idempotency key. If not provided, a new idempotency key will be generated. + pub idempotency_key: Option, +} diff --git a/lightspark/src/objects/pay_offer_output.rs b/lightspark/src/objects/pay_offer_output.rs new file mode 100644 index 0000000..62bc131 --- /dev/null +++ b/lightspark/src/objects/pay_offer_output.rs @@ -0,0 +1,19 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use crate::types::entity_wrapper::EntityWrapper; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct PayOfferOutput { + /// The payment that has been sent. + #[serde(rename = "pay_offer_output_payment")] + pub payment: EntityWrapper, +} + +pub const FRAGMENT: &str = " +fragment PayOfferOutputFragment on PayOfferOutput { + __typename + pay_offer_output_payment: payment { + id + } +} +"; diff --git a/lightspark/src/objects/pay_test_mode_invoice_input.rs b/lightspark/src/objects/pay_test_mode_invoice_input.rs new file mode 100644 index 0000000..8192587 --- /dev/null +++ b/lightspark/src/objects/pay_test_mode_invoice_input.rs @@ -0,0 +1,27 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +use crate::objects::payment_failure_reason::PaymentFailureReason; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct PayTestModeInvoiceInput { + /// The node from where you want to send the payment. + pub node_id: String, + + /// The invoice you want to pay (as defined by the BOLT11 standard). + pub encoded_invoice: String, + + /// The timeout in seconds that we will try to make the payment. + pub timeout_secs: i64, + + /// The maximum amount of fees that you want to pay for this payment to be sent, expressed in msats. + pub maximum_fees_msats: i64, + + /// The failure reason to trigger for the payment. If not set, pay_invoice will be called. + pub failure_reason: Option, + + /// The amount you will pay for this invoice, expressed in msats. It should ONLY be set when the invoice amount is zero. + pub amount_msats: Option, + + /// The idempotency key of the request. The same result will be returned for the same idempotency key. + pub idempotency_key: Option, +} diff --git a/lightspark/src/objects/payment_direction.rs b/lightspark/src/objects/payment_direction.rs index b433fc3..2a13ede 100644 --- a/lightspark/src/objects/payment_direction.rs +++ b/lightspark/src/objects/payment_direction.rs @@ -13,9 +13,9 @@ pub enum PaymentDirection { Received, } -impl From for Value { - fn from(val: PaymentDirection) -> Self { - Value::from(val.to_string()) +impl Into for PaymentDirection { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/payment_failure_reason.rs b/lightspark/src/objects/payment_failure_reason.rs index 585e8c6..1811015 100644 --- a/lightspark/src/objects/payment_failure_reason.rs +++ b/lightspark/src/objects/payment_failure_reason.rs @@ -43,9 +43,9 @@ pub enum PaymentFailureReason { InsufficientBalanceOnSinglePathInvoice, } -impl From for Value { - fn from(val: PaymentFailureReason) -> Self { - Value::from(val.to_string()) +impl Into for PaymentFailureReason { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/payment_request_status.rs b/lightspark/src/objects/payment_request_status.rs index 8fdb2cf..20d9e43 100644 --- a/lightspark/src/objects/payment_request_status.rs +++ b/lightspark/src/objects/payment_request_status.rs @@ -13,9 +13,9 @@ pub enum PaymentRequestStatus { Closed, } -impl From for Value { - fn from(val: PaymentRequestStatus) -> Self { - Value::from(val.to_string()) +impl Into for PaymentRequestStatus { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/permission.rs b/lightspark/src/objects/permission.rs index 0acd69f..0594586 100644 --- a/lightspark/src/objects/permission.rs +++ b/lightspark/src/objects/permission.rs @@ -58,9 +58,9 @@ pub enum Permission { AccountManage, } -impl From for Value { - fn from(val: Permission) -> Self { - Value::from(val.to_string()) +impl Into for Permission { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/region_code.rs b/lightspark/src/objects/region_code.rs index 4a34761..998f3ac 100644 --- a/lightspark/src/objects/region_code.rs +++ b/lightspark/src/objects/region_code.rs @@ -1008,9 +1008,9 @@ pub enum RegionCode { Nn, } -impl From for Value { - fn from(val: RegionCode) -> Self { - Value::from(val.to_string()) +impl Into for RegionCode { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/remote_signing_sub_event_type.rs b/lightspark/src/objects/remote_signing_sub_event_type.rs index 061735c..ad21f9d 100644 --- a/lightspark/src/objects/remote_signing_sub_event_type.rs +++ b/lightspark/src/objects/remote_signing_sub_event_type.rs @@ -34,9 +34,9 @@ pub enum RemoteSigningSubEventType { VlsMessage, } -impl From for Value { - fn from(val: RemoteSigningSubEventType) -> Self { - Value::from(val.to_string()) +impl Into for RemoteSigningSubEventType { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/request_initiator.rs b/lightspark/src/objects/request_initiator.rs index 9aca961..cb8785f 100644 --- a/lightspark/src/objects/request_initiator.rs +++ b/lightspark/src/objects/request_initiator.rs @@ -12,9 +12,9 @@ pub enum RequestInitiator { Lightspark, } -impl From for Value { - fn from(val: RequestInitiator) -> Self { - Value::from(val.to_string()) +impl Into for RequestInitiator { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/risk_rating.rs b/lightspark/src/objects/risk_rating.rs index a41c5fe..3e044a9 100644 --- a/lightspark/src/objects/risk_rating.rs +++ b/lightspark/src/objects/risk_rating.rs @@ -16,9 +16,9 @@ pub enum RiskRating { Unknown, } -impl From for Value { - fn from(val: RiskRating) -> Self { - Value::from(val.to_string()) +impl Into for RiskRating { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/routing_transaction_failure_reason.rs b/lightspark/src/objects/routing_transaction_failure_reason.rs index a253a44..ea4ae75 100644 --- a/lightspark/src/objects/routing_transaction_failure_reason.rs +++ b/lightspark/src/objects/routing_transaction_failure_reason.rs @@ -16,9 +16,9 @@ pub enum RoutingTransactionFailureReason { ForwardingFailure, } -impl From for Value { - fn from(val: RoutingTransactionFailureReason) -> Self { - Value::from(val.to_string()) +impl Into for RoutingTransactionFailureReason { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/signable_payload_status.rs b/lightspark/src/objects/signable_payload_status.rs index c987b4e..85fedf3 100644 --- a/lightspark/src/objects/signable_payload_status.rs +++ b/lightspark/src/objects/signable_payload_status.rs @@ -18,9 +18,9 @@ pub enum SignablePayloadStatus { InvalidSignature, } -impl From for Value { - fn from(val: SignablePayloadStatus) -> Self { - Value::from(val.to_string()) +impl Into for SignablePayloadStatus { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/transaction_status.rs b/lightspark/src/objects/transaction_status.rs index 30b863d..bf0e73b 100644 --- a/lightspark/src/objects/transaction_status.rs +++ b/lightspark/src/objects/transaction_status.rs @@ -32,9 +32,9 @@ pub enum TransactionStatus { Cancelled, } -impl From for Value { - fn from(val: TransactionStatus) -> Self { - Value::from(val.to_string()) +impl Into for TransactionStatus { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/transaction_type.rs b/lightspark/src/objects/transaction_type.rs index ace525c..0097539 100644 --- a/lightspark/src/objects/transaction_type.rs +++ b/lightspark/src/objects/transaction_type.rs @@ -48,9 +48,9 @@ pub enum TransactionType { Route, } -impl From for Value { - fn from(val: TransactionType) -> Self { - Value::from(val.to_string()) +impl Into for TransactionType { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/wallet.rs b/lightspark/src/objects/wallet.rs index 35bee3d..eea23d0 100644 --- a/lightspark/src/objects/wallet.rs +++ b/lightspark/src/objects/wallet.rs @@ -743,10 +743,10 @@ impl Wallet { variables.insert("statuses", statuses.into()); variables.insert("types", types.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["transactions"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } @@ -1099,10 +1099,10 @@ impl Wallet { created_before_date.map(|dt| dt.to_rfc3339()).into(), ); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["payment_requests"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } @@ -1137,10 +1137,10 @@ impl Wallet { created_before_date.map(|dt| dt.to_rfc3339()).into(), ); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["total_amount_received"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } @@ -1239,10 +1239,10 @@ impl Wallet { created_before_date.map(|dt| dt.to_rfc3339()).into(), ); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["withdrawal_requests"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } @@ -1277,10 +1277,10 @@ impl Wallet { created_before_date.map(|dt| dt.to_rfc3339()).into(), ); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["total_amount_sent"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } } diff --git a/lightspark/src/objects/wallet_status.rs b/lightspark/src/objects/wallet_status.rs index 64bddcb..8559be2 100644 --- a/lightspark/src/objects/wallet_status.rs +++ b/lightspark/src/objects/wallet_status.rs @@ -44,9 +44,9 @@ pub enum WalletStatus { Terminated, } -impl From for Value { - fn from(val: WalletStatus) -> Self { - Value::from(val.to_string()) +impl Into for WalletStatus { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/wallet_to_payment_requests_connection.rs b/lightspark/src/objects/wallet_to_payment_requests_connection.rs index 2ed09ed..a6424e0 100644 --- a/lightspark/src/objects/wallet_to_payment_requests_connection.rs +++ b/lightspark/src/objects/wallet_to_payment_requests_connection.rs @@ -1,6 +1,7 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved use crate::objects::connection::Connection; use crate::objects::page_info::PageInfo; +use crate::objects::payment_request::PaymentRequest; use crate::objects::payment_request::PaymentRequestEnum; use serde::{Deserialize, Serialize}; use std::vec::Vec; diff --git a/lightspark/src/objects/wallet_to_transactions_connection.rs b/lightspark/src/objects/wallet_to_transactions_connection.rs index 483e78b..fa99461 100644 --- a/lightspark/src/objects/wallet_to_transactions_connection.rs +++ b/lightspark/src/objects/wallet_to_transactions_connection.rs @@ -1,6 +1,7 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved use crate::objects::connection::Connection; use crate::objects::page_info::PageInfo; +use crate::objects::transaction::Transaction; use crate::objects::transaction::TransactionEnum; use serde::{Deserialize, Serialize}; use std::vec::Vec; diff --git a/lightspark/src/objects/webhook_event_type.rs b/lightspark/src/objects/webhook_event_type.rs index ba1dedb..fc0630a 100644 --- a/lightspark/src/objects/webhook_event_type.rs +++ b/lightspark/src/objects/webhook_event_type.rs @@ -52,9 +52,9 @@ pub enum WebhookEventType { ChannelOpeningFees, } -impl From for Value { - fn from(val: WebhookEventType) -> Self { - Value::from(val.to_string()) +impl Into for WebhookEventType { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/withdrawal_mode.rs b/lightspark/src/objects/withdrawal_mode.rs index dda0f5a..7203766 100644 --- a/lightspark/src/objects/withdrawal_mode.rs +++ b/lightspark/src/objects/withdrawal_mode.rs @@ -13,9 +13,9 @@ pub enum WithdrawalMode { WalletThenChannels, } -impl From for Value { - fn from(val: WithdrawalMode) -> Self { - Value::from(val.to_string()) +impl Into for WithdrawalMode { + fn into(self) -> Value { + Value::from(self.to_string()) } } diff --git a/lightspark/src/objects/withdrawal_request.rs b/lightspark/src/objects/withdrawal_request.rs index 0687677..6e4f48c 100644 --- a/lightspark/src/objects/withdrawal_request.rs +++ b/lightspark/src/objects/withdrawal_request.rs @@ -247,10 +247,10 @@ impl WithdrawalRequest { variables.insert("first", first.into()); variables.insert("after", after.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["channel_closing_transactions"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } @@ -314,10 +314,10 @@ impl WithdrawalRequest { variables.insert("first", first.into()); variables.insert("after", after.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["channel_opening_transactions"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } @@ -372,10 +372,10 @@ impl WithdrawalRequest { variables.insert("entity_id", self.id.clone().into()); variables.insert("first", first.into()); - let value = serde_json::to_value(variables).map_err(Error::ConversionError)?; - let result = requester.execute_graphql(query, Some(value)).await?; + let value = serde_json::to_value(variables).map_err(|err| Error::ConversionError(err))?; + let result = requester.execute_graphql(&query, Some(value)).await?; let json = result["entity"]["withdrawals"].clone(); - let result = serde_json::from_value(json).map_err(Error::JsonError)?; + let result = serde_json::from_value(json).map_err(|err| Error::JsonError(err))?; Ok(result) } } diff --git a/lightspark/src/objects/withdrawal_request_status.rs b/lightspark/src/objects/withdrawal_request_status.rs index 70c4cf9..b81a601 100644 --- a/lightspark/src/objects/withdrawal_request_status.rs +++ b/lightspark/src/objects/withdrawal_request_status.rs @@ -25,9 +25,9 @@ pub enum WithdrawalRequestStatus { PartiallySuccessful, } -impl From for Value { - fn from(val: WithdrawalRequestStatus) -> Self { - Value::from(val.to_string()) +impl Into for WithdrawalRequestStatus { + fn into(self) -> Value { + Value::from(self.to_string()) } }