Skip to content

Commit

Permalink
Update graphql schema. (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenlu authored Dec 20, 2023
2 parents d95662e + 8236359 commit 0b31f48
Show file tree
Hide file tree
Showing 11 changed files with 317 additions and 3 deletions.
14 changes: 11 additions & 3 deletions objects/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions objects/account_to_channels_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,45 @@ 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 (
AccountToChannelsConnectionFragment = `
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
}
6 changes: 6 additions & 0 deletions objects/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
34 changes: 34 additions & 0 deletions objects/daily_liquidity_forecast.go
Original file line number Diff line number Diff line change
@@ -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
}
}
`
)
54 changes: 54 additions & 0 deletions objects/lightning_payment_direction.go
Original file line number Diff line number Diff line change
@@ -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)
}
39 changes: 39 additions & 0 deletions objects/lightspark_node_to_daily_liquidity_forecasts_connection.go
Original file line number Diff line number Diff line change
@@ -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
}
}
}
`
)
45 changes: 45 additions & 0 deletions objects/lightspark_node_with_o_s_k.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
45 changes: 45 additions & 0 deletions objects/lightspark_node_with_remote_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
14 changes: 14 additions & 0 deletions objects/withdrawal_fee_estimate_input.go
Original file line number Diff line number Diff line change
@@ -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"`
}
24 changes: 24 additions & 0 deletions objects/withdrawal_fee_estimate_output.go
Original file line number Diff line number Diff line change
@@ -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
}
}
`
)
18 changes: 18 additions & 0 deletions types/date.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 0b31f48

Please sign in to comment.