Skip to content

Commit

Permalink
Regenerate SDK. (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenlu authored Jan 5, 2024
1 parent 7ffaaf6 commit fb05230
Show file tree
Hide file tree
Showing 19 changed files with 370 additions and 57 deletions.
14 changes: 12 additions & 2 deletions lightspark/src/objects/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ impl Account {
Ok(result)
}

#[allow(clippy::too_many_arguments)]
pub async fn get_channels(
&self,
requester: &impl GraphQLRequester,
Expand All @@ -663,13 +664,21 @@ impl Account {
after_date: Option<DateTime<Utc>>,
before_date: Option<DateTime<Utc>>,
first: Option<i64>,
after: Option<String>,
) -> Result<AccountToChannelsConnection, Error> {
let query = "query FetchAccountToChannelsConnection($entity_id: ID!, $bitcoin_network: BitcoinNetwork!, $lightning_node_id: ID, $after_date: DateTime, $before_date: DateTime, $first: Int) {
let query = "query FetchAccountToChannelsConnection($entity_id: ID!, $bitcoin_network: BitcoinNetwork!, $lightning_node_id: ID, $after_date: DateTime, $before_date: DateTime, $first: Int, $after: String) {
entity(id: $entity_id) {
... on Account {
channels(, bitcoin_network: $bitcoin_network, lightning_node_id: $lightning_node_id, after_date: $after_date, before_date: $before_date, first: $first) {
channels(, bitcoin_network: $bitcoin_network, lightning_node_id: $lightning_node_id, after_date: $after_date, before_date: $before_date, first: $first, after: $after) {
__typename
account_to_channels_connection_count: count
account_to_channels_connection_page_info: page_info {
__typename
page_info_has_next_page: has_next_page
page_info_has_previous_page: has_previous_page
page_info_start_cursor: start_cursor
page_info_end_cursor: end_cursor
}
account_to_channels_connection_entities: entities {
__typename
channel_id: id
Expand Down Expand Up @@ -775,6 +784,7 @@ impl Account {
variables.insert("after_date", after_date.map(|dt| dt.to_rfc3339()).into());
variables.insert("before_date", before_date.map(|dt| dt.to_rfc3339()).into());
variables.insert("first", first.into());
variables.insert("after", after.into());

let value = serde_json::to_value(variables).map_err(Error::ConversionError)?;
let result = requester.execute_graphql(query, Some(value)).await?;
Expand Down
33 changes: 33 additions & 0 deletions lightspark/src/objects/account_to_channels_connection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use crate::objects::channel::Channel;
use crate::objects::connection::Connection;
use crate::objects::page_info::PageInfo;
use serde::{Deserialize, Serialize};
use std::vec::Vec;

Expand All @@ -9,15 +11,46 @@ pub struct AccountToChannelsConnection {
#[serde(rename = "account_to_channels_connection_count")]
pub count: i64,

/// An object that holds pagination information about the objects in this connection.
#[serde(rename = "account_to_channels_connection_page_info")]
pub page_info: PageInfo,

/// The channels for the current page of this connection.
#[serde(rename = "account_to_channels_connection_entities")]
pub entities: Vec<Channel>,

/// The typename of the object
#[serde(rename = "__typename")]
pub typename: String,
}

impl Connection for AccountToChannelsConnection {
/// The total count of objects in this connection, using the current filters. It is different from the number of objects returned in the current page (in the `entities` field).
fn get_count(&self) -> i64 {
self.count
}

/// An object that holds pagination information about the objects in this connection.
fn get_page_info(&self) -> PageInfo {
self.page_info.clone()
}

fn type_name(&self) -> &'static str {
"AccountToChannelsConnection"
}
}

pub const FRAGMENT: &str = "
fragment AccountToChannelsConnectionFragment on AccountToChannelsConnection {
__typename
account_to_channels_connection_count: count
account_to_channels_connection_page_info: page_info {
__typename
page_info_has_next_page: has_next_page
page_info_has_previous_page: has_previous_page
page_info_start_cursor: start_cursor
page_info_end_cursor: end_cursor
}
account_to_channels_connection_entities: entities {
id
}
Expand Down
3 changes: 1 addition & 2 deletions lightspark/src/objects/account_to_nodes_connection.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use serde::{Deserialize, Serialize};

use crate::objects::connection::Connection;
use crate::objects::lightspark_node::LightsparkNodeEnum;
use crate::objects::page_info::PageInfo;
use serde::{Deserialize, Serialize};
use std::vec::Vec;

/// A connection between an account and the nodes it manages.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use serde::{Deserialize, Serialize};
use std::vec::Vec;

use crate::objects::connection::Connection;
use crate::objects::page_info::PageInfo;
use crate::objects::payment_request::PaymentRequestEnum;
use serde::{Deserialize, Serialize};

use std::vec::Vec;

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct AccountToPaymentRequestsConnection {
Expand Down
6 changes: 3 additions & 3 deletions lightspark/src/objects/account_to_transactions_connection.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use crate::objects::connection::Connection;
use crate::objects::transaction::TransactionEnum;
use serde::{Deserialize, Serialize};
use std::vec::Vec;

use crate::objects::connection::Connection;
use crate::objects::currency_amount::CurrencyAmount;
use crate::objects::page_info::PageInfo;
use crate::objects::transaction::TransactionEnum;
use std::vec::Vec;

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct AccountToTransactionsConnection {
Expand Down
8 changes: 8 additions & 0 deletions lightspark/src/objects/connection.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved

use super::account_to_api_tokens_connection::AccountToApiTokensConnection;
use super::account_to_channels_connection::AccountToChannelsConnection;
use super::account_to_nodes_connection::AccountToNodesConnection;
use super::account_to_payment_requests_connection::AccountToPaymentRequestsConnection;
use super::account_to_transactions_connection::AccountToTransactionsConnection;
Expand Down Expand Up @@ -31,6 +32,7 @@ pub trait Connection {
#[derive(Debug, Clone, Serialize)]
pub enum ConnectionEnum {
AccountToApiTokensConnection(AccountToApiTokensConnection),
AccountToChannelsConnection(AccountToChannelsConnection),
AccountToNodesConnection(AccountToNodesConnection),
AccountToPaymentRequestsConnection(AccountToPaymentRequestsConnection),
AccountToTransactionsConnection(AccountToTransactionsConnection),
Expand Down Expand Up @@ -59,6 +61,12 @@ impl<'de> Deserialize<'de> for ConnectionEnum {
})?;
Ok(ConnectionEnum::AccountToApiTokensConnection(obj))
}
"AccountToChannelsConnection" => {
let obj = AccountToChannelsConnection::deserialize(value).map_err(|err| {
serde::de::Error::custom(format!("Serde JSON Error {}", err))
})?;
Ok(ConnectionEnum::AccountToChannelsConnection(obj))
}
"AccountToNodesConnection" => {
let obj = AccountToNodesConnection::deserialize(value).map_err(|err| {
serde::de::Error::custom(format!("Serde JSON Error {}", err))
Expand Down
40 changes: 40 additions & 0 deletions lightspark/src/objects/daily_liquidity_forecast.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use crate::objects::currency_amount::CurrencyAmount;
use crate::objects::lightning_payment_direction::LightningPaymentDirection;
use crate::types::custom_date_formats::custom_date_only_format;
use chrono::NaiveDate;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct DailyLiquidityForecast {
/// The date for which this forecast was generated.
#[serde(
with = "custom_date_only_format",
rename = "daily_liquidity_forecast_date"
)]
pub date: NaiveDate,

/// The direction for which this forecast was generated.
#[serde(rename = "daily_liquidity_forecast_direction")]
pub direction: LightningPaymentDirection,

/// The value of the forecast. It represents the amount of msats that we think will be moved for that specified direction, for that node, on that date.
#[serde(rename = "daily_liquidity_forecast_amount")]
pub amount: CurrencyAmount,
}

pub const FRAGMENT: &str = "
fragment DailyLiquidityForecastFragment on DailyLiquidityForecast {
__typename
daily_liquidity_forecast_date: date
daily_liquidity_forecast_direction: direction
daily_liquidity_forecast_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
}
}
";
6 changes: 3 additions & 3 deletions lightspark/src/objects/invoice_data.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use crate::objects::bitcoin_network::BitcoinNetwork;
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};

use crate::objects::bitcoin_network::BitcoinNetwork;
use crate::objects::currency_amount::CurrencyAmount;
use crate::objects::payment_request_data::PaymentRequestData;
use chrono::{DateTime, Utc};

/// This object represents the data associated with a BOLT #11 invoice. You can retrieve this object to receive the relevant data associated with a specific invoice.
#[derive(Debug, Clone, Deserialize, Serialize)]
Expand Down
32 changes: 32 additions & 0 deletions lightspark/src/objects/lightning_payment_direction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::fmt;

/// This is an enum identifying the payment direction.
#[derive(Debug, Clone, Deserialize, Serialize)]
pub enum LightningPaymentDirection {
/// A payment that is received by the node.
#[serde(rename = "INCOMING")]
Incoming,
/// A payment that is sent by the node.
#[serde(rename = "OUTGOING")]
Outgoing,
}

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

impl fmt::Display for LightningPaymentDirection {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Incoming => write!(f, "INCOMING"),
Self::Outgoing => write!(f, "OUTGOING"),
}
}
}
10 changes: 5 additions & 5 deletions lightspark/src/objects/lightspark_node.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use crate::objects::blockchain_balance::BlockchainBalance;
use super::lightspark_node_with_o_s_k::LightsparkNodeWithOSK;
use crate::objects::entity::Entity;
use crate::objects::lightspark_node_status::LightsparkNodeStatus;
use crate::objects::node::Node;
use serde::{Deserialize, Deserializer, Serialize};
use std::vec::Vec;

use super::lightspark_node_with_o_s_k::LightsparkNodeWithOSK;
use super::lightspark_node_with_remote_signing::LightsparkNodeWithRemoteSigning;
use crate::objects::balances::Balances;
use crate::objects::blockchain_balance::BlockchainBalance;
use crate::objects::currency_amount::CurrencyAmount;
use crate::objects::lightspark_node_status::LightsparkNodeStatus;
use crate::types::entity_wrapper::EntityWrapper;
use serde::{Deserialize, Deserializer, Serialize};
use serde_json::Value;
use std::vec::Vec;

pub trait LightsparkNode: Node + Entity {
/// The owner of this LightsparkNode.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
use crate::objects::daily_liquidity_forecast::DailyLiquidityForecast;
use crate::objects::lightning_payment_direction::LightningPaymentDirection;
use crate::types::custom_date_formats::custom_date_only_format;
use chrono::NaiveDate;
use serde::{Deserialize, Serialize};
use std::vec::Vec;

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct LightsparkNodeToDailyLiquidityForecastsConnection {
#[serde(
with = "custom_date_only_format",
rename = "lightspark_node_to_daily_liquidity_forecasts_connection_from_date"
)]
pub from_date: NaiveDate,

#[serde(
with = "custom_date_only_format",
rename = "lightspark_node_to_daily_liquidity_forecasts_connection_to_date"
)]
pub to_date: NaiveDate,

#[serde(rename = "lightspark_node_to_daily_liquidity_forecasts_connection_direction")]
pub direction: LightningPaymentDirection,

/// The daily liquidity forecasts for the current page of this connection.
#[serde(rename = "lightspark_node_to_daily_liquidity_forecasts_connection_entities")]
pub entities: Vec<DailyLiquidityForecast>,
}

pub const FRAGMENT: &str = "
fragment LightsparkNodeToDailyLiquidityForecastsConnectionFragment on LightsparkNodeToDailyLiquidityForecastsConnection {
__typename
lightspark_node_to_daily_liquidity_forecasts_connection_from_date: from_date
lightspark_node_to_daily_liquidity_forecasts_connection_to_date: to_date
lightspark_node_to_daily_liquidity_forecasts_connection_direction: direction
lightspark_node_to_daily_liquidity_forecasts_connection_entities: entities {
__typename
daily_liquidity_forecast_date: date
daily_liquidity_forecast_direction: direction
daily_liquidity_forecast_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
}
}
}
";
Loading

0 comments on commit fb05230

Please sign in to comment.