diff --git a/objects/account.go b/objects/account.go index 33422d5..c7423f0 100644 --- a/objects/account.go +++ b/objects/account.go @@ -599,13 +599,20 @@ func (obj Account) GetUptimePercentage(requester *requester.Requester, afterDate return result, nil } -func (obj Account) GetChannels(requester *requester.Requester, bitcoinNetwork BitcoinNetwork, lightningNodeId *string, afterDate *time.Time, beforeDate *time.Time, first *int64) (*AccountToChannelsConnection, error) { - query := `query FetchAccountToChannelsConnection($entity_id: ID!, $bitcoin_network: BitcoinNetwork!, $lightning_node_id: ID, $after_date: DateTime, $before_date: DateTime, $first: Int) { +func (obj Account) GetChannels(requester *requester.Requester, bitcoinNetwork BitcoinNetwork, lightningNodeId *string, afterDate *time.Time, beforeDate *time.Time, first *int64, after *string) (*AccountToChannelsConnection, error) { + 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 @@ -711,6 +718,7 @@ func (obj Account) GetChannels(requester *requester.Requester, bitcoinNetwork Bi "after_date": afterDate, "before_date": beforeDate, "first": first, + "after": after, } response, err := requester.ExecuteGraphql(query, variables, nil) diff --git a/objects/account_to_channels_connection.go b/objects/account_to_channels_connection.go index 8cc01f1..a2d476a 100644 --- a/objects/account_to_channels_connection.go +++ b/objects/account_to_channels_connection.go @@ -6,8 +6,14 @@ type AccountToChannelsConnection struct { // Count 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). Count int64 `json:"account_to_channels_connection_count"` + // PageInfo An object that holds pagination information about the objects in this connection. + PageInfo PageInfo `json:"account_to_channels_connection_page_info"` + // Entities The channels for the current page of this connection. Entities []Channel `json:"account_to_channels_connection_entities"` + + // Typename The typename of the object + Typename string `json:"__typename"` } const ( @@ -15,9 +21,30 @@ const ( 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 } } ` ) + +// GetCount 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). +func (obj AccountToChannelsConnection) GetCount() int64 { + return obj.Count +} + +// GetPageInfo An object that holds pagination information about the objects in this connection. +func (obj AccountToChannelsConnection) GetPageInfo() PageInfo { + return obj.PageInfo +} + +func (obj AccountToChannelsConnection) GetTypename() string { + return obj.Typename +} diff --git a/objects/connection.go b/objects/connection.go index 9e6b2de..63ac691 100644 --- a/objects/connection.go +++ b/objects/connection.go @@ -35,6 +35,12 @@ func ConnectionUnmarshal(data map[string]interface{}) (Connection, error) { return nil, err } return accountToApiTokensConnection, nil + case "AccountToChannelsConnection": + var accountToChannelsConnection AccountToChannelsConnection + if err := json.Unmarshal(dataJSON, &accountToChannelsConnection); err != nil { + return nil, err + } + return accountToChannelsConnection, nil case "AccountToNodesConnection": var accountToNodesConnection AccountToNodesConnection if err := json.Unmarshal(dataJSON, &accountToNodesConnection); err != nil { diff --git a/objects/daily_liquidity_forecast.go b/objects/daily_liquidity_forecast.go new file mode 100644 index 0000000..cc03611 --- /dev/null +++ b/objects/daily_liquidity_forecast.go @@ -0,0 +1,34 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +package objects + +import "github.com/lightsparkdev/go-sdk/types" + +type DailyLiquidityForecast struct { + + // Date The date for which this forecast was generated. + Date types.Date `json:"daily_liquidity_forecast_date"` + + // Direction The direction for which this forecast was generated. + Direction LightningPaymentDirection `json:"daily_liquidity_forecast_direction"` + + // Amount 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. + Amount CurrencyAmount `json:"daily_liquidity_forecast_amount"` +} + +const ( + DailyLiquidityForecastFragment = ` +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 + } +} +` +) diff --git a/objects/lightning_payment_direction.go b/objects/lightning_payment_direction.go new file mode 100644 index 0000000..e6bba5f --- /dev/null +++ b/objects/lightning_payment_direction.go @@ -0,0 +1,54 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +package objects + +import ( + "encoding/json" +) + +// LightningPaymentDirection This is an enum identifying the payment direction. +type LightningPaymentDirection int + +const ( + LightningPaymentDirectionUndefined LightningPaymentDirection = iota + + // LightningPaymentDirectionIncoming A payment that is received by the node. + LightningPaymentDirectionIncoming + // LightningPaymentDirectionOutgoing A payment that is sent by the node. + LightningPaymentDirectionOutgoing +) + +func (a *LightningPaymentDirection) UnmarshalJSON(b []byte) error { + var s string + if err := json.Unmarshal(b, &s); err != nil { + return err + } + switch s { + default: + *a = LightningPaymentDirectionUndefined + case "INCOMING": + *a = LightningPaymentDirectionIncoming + case "OUTGOING": + *a = LightningPaymentDirectionOutgoing + + } + return nil +} + +func (a LightningPaymentDirection) StringValue() string { + var s string + switch a { + default: + s = "undefined" + case LightningPaymentDirectionIncoming: + s = "INCOMING" + case LightningPaymentDirectionOutgoing: + s = "OUTGOING" + + } + return s +} + +func (a LightningPaymentDirection) MarshalJSON() ([]byte, error) { + s := a.StringValue() + return json.Marshal(s) +} diff --git a/objects/lightspark_node_to_daily_liquidity_forecasts_connection.go b/objects/lightspark_node_to_daily_liquidity_forecasts_connection.go new file mode 100644 index 0000000..4c85c52 --- /dev/null +++ b/objects/lightspark_node_to_daily_liquidity_forecasts_connection.go @@ -0,0 +1,39 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +package objects + +import "github.com/lightsparkdev/go-sdk/types" + +type LightsparkNodeToDailyLiquidityForecastsConnection struct { + FromDate types.Date `json:"lightspark_node_to_daily_liquidity_forecasts_connection_from_date"` + + ToDate types.Date `json:"lightspark_node_to_daily_liquidity_forecasts_connection_to_date"` + + Direction LightningPaymentDirection `json:"lightspark_node_to_daily_liquidity_forecasts_connection_direction"` + + // Entities The daily liquidity forecasts for the current page of this connection. + Entities []DailyLiquidityForecast `json:"lightspark_node_to_daily_liquidity_forecasts_connection_entities"` +} + +const ( + LightsparkNodeToDailyLiquidityForecastsConnectionFragment = ` +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 + } + } +} +` +) diff --git a/objects/lightspark_node_with_o_s_k.go b/objects/lightspark_node_with_o_s_k.go index 9bf108d..c4cb608 100644 --- a/objects/lightspark_node_with_o_s_k.go +++ b/objects/lightspark_node_with_o_s_k.go @@ -478,3 +478,48 @@ func (obj LightsparkNodeWithOSK) GetChannels(requester *requester.Requester, fir json.Unmarshal(jsonString, &result) return result, nil } + +func (obj LightsparkNodeWithOSK) GetDailyLiquidityForecasts(requester *requester.Requester, fromDate types.Date, toDate types.Date, direction LightningPaymentDirection) (*LightsparkNodeToDailyLiquidityForecastsConnection, error) { + query := `query FetchLightsparkNodeToDailyLiquidityForecastsConnection($entity_id: ID!, $from_date: Date!, $to_date: Date!, $direction: LightningPaymentDirection!) { + entity(id: $entity_id) { + ... on LightsparkNodeWithOSK { + daily_liquidity_forecasts(, from_date: $from_date, to_date: $to_date, direction: $direction) { + __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 + } + } + } + } + } +}` + variables := map[string]interface{}{ + "entity_id": obj.Id, + "from_date": fromDate, + "to_date": toDate, + "direction": direction, + } + + response, err := requester.ExecuteGraphql(query, variables, nil) + if err != nil { + return nil, err + } + + output := response["entity"].(map[string]interface{})["daily_liquidity_forecasts"].(map[string]interface{}) + var result *LightsparkNodeToDailyLiquidityForecastsConnection + jsonString, err := json.Marshal(output) + json.Unmarshal(jsonString, &result) + return result, nil +} diff --git a/objects/lightspark_node_with_remote_signing.go b/objects/lightspark_node_with_remote_signing.go index 62708f3..d6f27a0 100644 --- a/objects/lightspark_node_with_remote_signing.go +++ b/objects/lightspark_node_with_remote_signing.go @@ -470,3 +470,48 @@ func (obj LightsparkNodeWithRemoteSigning) GetChannels(requester *requester.Requ json.Unmarshal(jsonString, &result) return result, nil } + +func (obj LightsparkNodeWithRemoteSigning) GetDailyLiquidityForecasts(requester *requester.Requester, fromDate types.Date, toDate types.Date, direction LightningPaymentDirection) (*LightsparkNodeToDailyLiquidityForecastsConnection, error) { + query := `query FetchLightsparkNodeToDailyLiquidityForecastsConnection($entity_id: ID!, $from_date: Date!, $to_date: Date!, $direction: LightningPaymentDirection!) { + entity(id: $entity_id) { + ... on LightsparkNodeWithRemoteSigning { + daily_liquidity_forecasts(, from_date: $from_date, to_date: $to_date, direction: $direction) { + __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 + } + } + } + } + } +}` + variables := map[string]interface{}{ + "entity_id": obj.Id, + "from_date": fromDate, + "to_date": toDate, + "direction": direction, + } + + response, err := requester.ExecuteGraphql(query, variables, nil) + if err != nil { + return nil, err + } + + output := response["entity"].(map[string]interface{})["daily_liquidity_forecasts"].(map[string]interface{}) + var result *LightsparkNodeToDailyLiquidityForecastsConnection + jsonString, err := json.Marshal(output) + json.Unmarshal(jsonString, &result) + return result, nil +} diff --git a/objects/withdrawal_fee_estimate_input.go b/objects/withdrawal_fee_estimate_input.go new file mode 100644 index 0000000..d3a3206 --- /dev/null +++ b/objects/withdrawal_fee_estimate_input.go @@ -0,0 +1,14 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +package objects + +type WithdrawalFeeEstimateInput struct { + + // NodeId The node from which you'd like to make the withdrawal. + NodeId string `json:"withdrawal_fee_estimate_input_node_id"` + + // AmountSats The amount you want to withdraw from this node in Satoshis. Use the special value -1 to withdrawal all funds from this node. + AmountSats int64 `json:"withdrawal_fee_estimate_input_amount_sats"` + + // WithdrawalMode The strategy that should be used to withdraw the funds from this node. + WithdrawalMode WithdrawalMode `json:"withdrawal_fee_estimate_input_withdrawal_mode"` +} diff --git a/objects/withdrawal_fee_estimate_output.go b/objects/withdrawal_fee_estimate_output.go new file mode 100644 index 0000000..ddd83b9 --- /dev/null +++ b/objects/withdrawal_fee_estimate_output.go @@ -0,0 +1,24 @@ +// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved +package objects + +type WithdrawalFeeEstimateOutput struct { + + // FeeEstimate The estimated fee for the withdrawal. + FeeEstimate CurrencyAmount `json:"withdrawal_fee_estimate_output_fee_estimate"` +} + +const ( + WithdrawalFeeEstimateOutputFragment = ` +fragment WithdrawalFeeEstimateOutputFragment on WithdrawalFeeEstimateOutput { + __typename + withdrawal_fee_estimate_output_fee_estimate: fee_estimate { + __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 + } +} +` +) diff --git a/types/date.go b/types/date.go new file mode 100644 index 0000000..8313ad7 --- /dev/null +++ b/types/date.go @@ -0,0 +1,18 @@ +package types + +import "time" + +type Date time.Time + +func (d *Date) UnmarshalJSON(b []byte) error { + t, err := time.Parse("\"2006-01-02\"", string(b)) + if err != nil { + return err + } + *d = Date(t) + return nil +} + +func (d Date) MarshalJSON() ([]byte, error) { + return []byte(time.Time(d).Format("\"2006-01-02\"")), nil +}