Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 72 additions & 41 deletions lightspark/src/objects/account.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lightspark/src/objects/account_to_nodes_connection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use crate::objects::connection::Connection;
use crate::objects::lightspark_node::LightsparkNode;

Check failure on line 3 in lightspark/src/objects/account_to_nodes_connection.rs

View workflow job for this annotation

GitHub Actions / test

unused import: `crate::objects::lightspark_node::LightsparkNode`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this unused import for LightsparkNode. It's not being used in this file and is causing a compiler warning.

Spotted by Diamond (based on CI logs)

Is this helpful? React 👍 or 👎 to let us know.

use crate::objects::lightspark_node::LightsparkNodeEnum;
use crate::objects::page_info::PageInfo;
use serde::{Deserialize, Serialize};
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

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

View workflow job for this annotation

GitHub Actions / test

unused import: `crate::objects::payment_request::PaymentRequest`
use crate::objects::payment_request::PaymentRequestEnum;
use serde::{Deserialize, Serialize};
use std::vec::Vec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check failure on line 5 in lightspark/src/objects/account_to_transactions_connection.rs

View workflow job for this annotation

GitHub Actions / test

unused import: `crate::objects::transaction::Transaction`
use crate::objects::transaction::TransactionEnum;
use serde::{Deserialize, Serialize};
use std::vec::Vec;
Expand Down
6 changes: 3 additions & 3 deletions lightspark/src/objects/bitcoin_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ pub enum BitcoinNetwork {
Testnet,
}

impl From<BitcoinNetwork> for Value {
fn from(val: BitcoinNetwork) -> Self {
Value::from(val.to_string())
impl Into<Value> for BitcoinNetwork {
fn into(self) -> Value {
Value::from(self.to_string())
}
}

Expand Down
10 changes: 5 additions & 5 deletions lightspark/src/objects/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
6 changes: 3 additions & 3 deletions lightspark/src/objects/channel_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ pub enum ChannelStatus {
Error,
}

impl From<ChannelStatus> for Value {
fn from(val: ChannelStatus) -> Self {
Value::from(val.to_string())
impl Into<Value> for ChannelStatus {
fn into(self) -> Value {
Value::from(self.to_string())
}
}

Expand Down
6 changes: 3 additions & 3 deletions lightspark/src/objects/compliance_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ pub enum ComplianceProvider {
Chainalysis,
}

impl From<ComplianceProvider> for Value {
fn from(val: ComplianceProvider) -> Self {
Value::from(val.to_string())
impl Into<Value> for ComplianceProvider {
fn into(self) -> Value {
Value::from(self.to_string())
}
}

Expand Down
6 changes: 6 additions & 0 deletions lightspark/src/objects/create_invoice_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ pub struct CreateInvoiceInput {

/// The expiry of the invoice in seconds. Default value is 86400 (1 day).
pub expiry_secs: Option<i64>,

/// 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<String>,

/// 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<String>,
}
14 changes: 14 additions & 0 deletions lightspark/src/objects/create_offer_input.rs
Original file line number Diff line number Diff line change
@@ -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<i64>,

/// A short description of the offer.
pub description: Option<String>,
}
18 changes: 18 additions & 0 deletions lightspark/src/objects/create_offer_output.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
";
4 changes: 4 additions & 0 deletions lightspark/src/objects/create_test_mode_invoice_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

/// The type of invoice to create.
pub invoice_type: Option<InvoiceType>,
}
10 changes: 10 additions & 0 deletions lightspark/src/objects/currency_amount_input.rs
Original file line number Diff line number Diff line change
@@ -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,
}
16 changes: 13 additions & 3 deletions lightspark/src/objects/currency_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -40,9 +48,9 @@ pub enum CurrencyUnit {
Millibitcoin,
}

impl From<CurrencyUnit> for Value {
fn from(val: CurrencyUnit) -> Self {
Value::from(val.to_string())
impl Into<Value> for CurrencyUnit {
fn into(self) -> Value {
Value::from(self.to_string())
}
}

Expand All @@ -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"),
Expand Down
16 changes: 16 additions & 0 deletions lightspark/src/objects/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,6 +59,8 @@ pub enum EntityEnum {
Invoice(Invoice),
LightsparkNodeWithOSK(LightsparkNodeWithOSK),
LightsparkNodeWithRemoteSigning(LightsparkNodeWithRemoteSigning),
Offer(Offer),
OfferData(OfferData),
OutgoingPayment(OutgoingPayment),
OutgoingPaymentAttempt(OutgoingPaymentAttempt),
RoutingTransaction(RoutingTransaction),
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions lightspark/src/objects/graph_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
6 changes: 3 additions & 3 deletions lightspark/src/objects/htlc_attempt_failure_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ pub enum HtlcAttemptFailureCode {
UnreadableFailure,
}

impl From<HtlcAttemptFailureCode> for Value {
fn from(val: HtlcAttemptFailureCode) -> Self {
Value::from(val.to_string())
impl Into<Value> for HtlcAttemptFailureCode {
fn into(self) -> Value {
Value::from(self.to_string())
}
}

Expand Down
6 changes: 3 additions & 3 deletions lightspark/src/objects/incentives_ineligibility_reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ pub enum IncentivesIneligibilityReason {
NotCrossBorder,
}

impl From<IncentivesIneligibilityReason> for Value {
fn from(val: IncentivesIneligibilityReason) -> Self {
Value::from(val.to_string())
impl Into<Value> for IncentivesIneligibilityReason {
fn into(self) -> Value {
Value::from(self.to_string())
}
}

Expand Down
6 changes: 3 additions & 3 deletions lightspark/src/objects/incentives_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ pub enum IncentivesStatus {
Ineligible,
}

impl From<IncentivesStatus> for Value {
fn from(val: IncentivesStatus) -> Self {
Value::from(val.to_string())
impl Into<Value> for IncentivesStatus {
fn into(self) -> Value {
Value::from(self.to_string())
}
}

Expand Down
6 changes: 3 additions & 3 deletions lightspark/src/objects/incoming_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
6 changes: 3 additions & 3 deletions lightspark/src/objects/incoming_payment_attempt_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ pub enum IncomingPaymentAttemptStatus {
Unknown,
}

impl From<IncomingPaymentAttemptStatus> for Value {
fn from(val: IncomingPaymentAttemptStatus) -> Self {
Value::from(val.to_string())
impl Into<Value> for IncomingPaymentAttemptStatus {
fn into(self) -> Value {
Value::from(self.to_string())
}
}

Expand Down
2 changes: 1 addition & 1 deletion lightspark/src/objects/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion lightspark/src/objects/invoice_data.rs
Original file line number Diff line number Diff line change
@@ -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;

Check failure on line 4 in lightspark/src/objects/invoice_data.rs

View workflow job for this annotation

GitHub Actions / test

unused import: `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")]
Expand Down
6 changes: 3 additions & 3 deletions lightspark/src/objects/invoice_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ pub enum InvoiceType {
Amp,
}

impl From<InvoiceType> for Value {
fn from(val: InvoiceType) -> Self {
Value::from(val.to_string())
impl Into<Value> for InvoiceType {
fn into(self) -> Value {
Value::from(self.to_string())
}
}

Expand Down
6 changes: 3 additions & 3 deletions lightspark/src/objects/lightning_payment_direction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ pub enum LightningPaymentDirection {
Outgoing,
}

impl From<LightningPaymentDirection> for Value {
fn from(val: LightningPaymentDirection) -> Self {
Value::from(val.to_string())
impl Into<Value> for LightningPaymentDirection {
fn into(self) -> Value {
Value::from(self.to_string())
}
}

Expand Down
1 change: 1 addition & 0 deletions lightspark/src/objects/lightspark_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use crate::objects::blockchain_balance::BlockchainBalance;
use crate::objects::currency_amount::CurrencyAmount;
use crate::objects::entity::Entity;
use crate::objects::lightspark_node_owner::LightsparkNodeOwner;

Check failure on line 8 in lightspark/src/objects/lightspark_node.rs

View workflow job for this annotation

GitHub Actions / test

unused import: `crate::objects::lightspark_node_owner::LightsparkNodeOwner`
use crate::objects::lightspark_node_status::LightsparkNodeStatus;
use crate::objects::node::Node;
use crate::types::entity_wrapper::EntityWrapper;
Expand Down
6 changes: 3 additions & 3 deletions lightspark/src/objects/lightspark_node_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ pub enum LightsparkNodeStatus {
FailedToDeploy,
}

impl From<LightsparkNodeStatus> for Value {
fn from(val: LightsparkNodeStatus) -> Self {
Value::from(val.to_string())
impl Into<Value> for LightsparkNodeStatus {
fn into(self) -> Value {
Value::from(self.to_string())
}
}

Expand Down
Loading