From 06ddcda443b15b9e46ffa2e9b412c07e46e2fcfe Mon Sep 17 00:00:00 2001 From: Jeremy Klein Date: Thu, 9 Nov 2023 09:11:11 -0800 Subject: [PATCH 1/2] Add a to_json() object function that's consistent with from_json() --- lightspark/__tests__/test_serialization.py | 25 +++++++++++ lightspark/objects/Account.py | 9 ++++ .../objects/AccountToApiTokensConnection.py | 10 +++++ .../objects/AccountToChannelsConnection.py | 8 ++++ .../objects/AccountToNodesConnection.py | 10 +++++ .../AccountToPaymentRequestsConnection.py | 10 +++++ .../AccountToTransactionsConnection.py | 19 +++++++++ .../objects/AccountToWalletsConnection.py | 10 +++++ lightspark/objects/ApiToken.py | 11 +++++ lightspark/objects/Balances.py | 7 ++++ lightspark/objects/BlockchainBalance.py | 22 ++++++++++ lightspark/objects/Channel.py | 41 +++++++++++++++++++ .../objects/ChannelClosingTransaction.py | 22 ++++++++++ lightspark/objects/ChannelFees.py | 6 +++ .../objects/ChannelOpeningTransaction.py | 22 ++++++++++ lightspark/objects/ChannelSnapshot.py | 21 ++++++++++ .../ChannelToTransactionsConnection.py | 14 +++++++ lightspark/objects/CreateApiTokenInput.py | 8 ++++ lightspark/objects/CreateApiTokenOutput.py | 6 +++ lightspark/objects/CreateInvoiceInput.py | 9 ++++ lightspark/objects/CreateInvoiceOutput.py | 5 +++ lightspark/objects/CreateLnurlInvoiceInput.py | 8 ++++ .../objects/CreateNodeWalletAddressInput.py | 5 +++ .../objects/CreateNodeWalletAddressOutput.py | 6 +++ .../objects/CreateTestModeInvoiceInput.py | 8 ++++ .../objects/CreateTestModeInvoiceOutput.py | 5 +++ .../objects/CreateTestModePaymentInput.py | 7 ++++ .../objects/CreateTestModePaymentoutput.py | 8 ++++ lightspark/objects/CreateUmaInvoiceInput.py | 8 ++++ lightspark/objects/CurrencyAmount.py | 9 ++++ .../objects/DeclineToSignMessagesInput.py | 5 +++ .../objects/DeclineToSignMessagesOutput.py | 7 ++++ lightspark/objects/DeleteApiTokenInput.py | 5 +++ lightspark/objects/DeleteApiTokenOutput.py | 5 +++ lightspark/objects/Deposit.py | 18 ++++++++ lightspark/objects/FeeEstimate.py | 6 +++ lightspark/objects/FundNodeInput.py | 6 +++ lightspark/objects/FundNodeOutput.py | 5 +++ lightspark/objects/GraphNode.py | 14 +++++++ lightspark/objects/Hop.py | 18 ++++++++ lightspark/objects/IdAndSignature.py | 6 +++ lightspark/objects/IncomingPayment.py | 21 ++++++++++ lightspark/objects/IncomingPaymentAttempt.py | 12 ++++++ .../IncomingPaymentToAttemptsConnection.py | 10 +++++ lightspark/objects/Invoice.py | 13 ++++++ lightspark/objects/InvoiceData.py | 13 ++++++ .../LightningFeeEstimateForInvoiceInput.py | 7 ++++ .../LightningFeeEstimateForNodeInput.py | 7 ++++ .../objects/LightningFeeEstimateOutput.py | 5 +++ lightspark/objects/LightningTransaction.py | 12 ++++++ lightspark/objects/LightsparkNode.py | 35 ++++++++++++++++ lightspark/objects/LightsparkNodeOwner.py | 8 ++++ .../LightsparkNodeToChannelsConnection.py | 10 +++++ lightspark/objects/LightsparkNodeWithOSK.py | 38 +++++++++++++++++ .../LightsparkNodeWithRemoteSigning.py | 35 ++++++++++++++++ lightspark/objects/Node.py | 14 +++++++ lightspark/objects/NodeAddress.py | 6 +++ .../objects/NodeToAddressesConnection.py | 8 ++++ lightspark/objects/OnChainTransaction.py | 17 ++++++++ lightspark/objects/OutgoingPayment.py | 30 ++++++++++++++ lightspark/objects/OutgoingPaymentAttempt.py | 22 ++++++++++ .../OutgoingPaymentAttemptToHopsConnection.py | 10 +++++ .../OutgoingPaymentToAttemptsConnection.py | 10 +++++ .../OutgoingPaymentsForInvoiceQueryInput.py | 10 +++++ .../OutgoingPaymentsForInvoiceQueryOutput.py | 7 ++++ lightspark/objects/PageInfo.py | 8 ++++ lightspark/objects/PayInvoiceInput.py | 9 ++++ lightspark/objects/PayInvoiceOutput.py | 5 +++ lightspark/objects/PayUmaInvoiceInput.py | 9 ++++ lightspark/objects/PaymentRequest.py | 10 +++++ lightspark/objects/PaymentRequestData.py | 7 ++++ lightspark/objects/PostTransactionData.py | 6 +++ lightspark/objects/RegisterPaymentInput.py | 8 ++++ lightspark/objects/RegisterPaymentOutput.py | 5 +++ .../ReleaseChannelPerCommitmentSecretInput.py | 7 ++++ ...ReleaseChannelPerCommitmentSecretOutput.py | 7 ++++ .../objects/ReleasePaymentPreimageInput.py | 6 +++ .../objects/ReleasePaymentPreimageOutput.py | 5 +++ lightspark/objects/RequestWithdrawalInput.py | 8 ++++ lightspark/objects/RequestWithdrawalOutput.py | 5 +++ lightspark/objects/RichText.py | 5 +++ lightspark/objects/RoutingTransaction.py | 23 +++++++++++ lightspark/objects/ScreenNodeInput.py | 6 +++ lightspark/objects/ScreenNodeOutput.py | 5 +++ lightspark/objects/Secret.py | 6 +++ lightspark/objects/SendPaymentInput.py | 9 ++++ lightspark/objects/SendPaymentOutput.py | 5 +++ .../objects/SetInvoicePaymentHashInput.py | 7 ++++ .../objects/SetInvoicePaymentHashOutput.py | 5 +++ lightspark/objects/SignInvoiceInput.py | 7 ++++ lightspark/objects/SignInvoiceOutput.py | 5 +++ lightspark/objects/SignMessagesInput.py | 5 +++ lightspark/objects/SignMessagesOutput.py | 7 ++++ lightspark/objects/Signable.py | 8 ++++ lightspark/objects/SignablePayload.py | 14 +++++++ lightspark/objects/Transaction.py | 12 ++++++ lightspark/objects/TransactionFailures.py | 14 +++++++ .../UpdateChannelPerCommitmentPointInput.py | 7 ++++ .../UpdateChannelPerCommitmentPointOutput.py | 7 ++++ .../objects/UpdateNodeSharedSecretInput.py | 6 +++ .../objects/UpdateNodeSharedSecretOutput.py | 5 +++ lightspark/objects/Wallet.py | 13 ++++++ .../WalletToPaymentRequestsConnection.py | 10 +++++ .../objects/WalletToTransactionsConnection.py | 10 +++++ lightspark/objects/Withdrawal.py | 18 ++++++++ lightspark/objects/WithdrawalRequest.py | 19 +++++++++ ...tToChannelClosingTransactionsConnection.py | 9 ++++ ...tToChannelOpeningTransactionsConnection.py | 9 ++++ 108 files changed, 1175 insertions(+) create mode 100644 lightspark/__tests__/test_serialization.py diff --git a/lightspark/__tests__/test_serialization.py b/lightspark/__tests__/test_serialization.py new file mode 100644 index 0000000..8c22aa7 --- /dev/null +++ b/lightspark/__tests__/test_serialization.py @@ -0,0 +1,25 @@ +import json +from lightspark.objects.InvoiceData import from_json as InvoiceData_from_json +from lightspark.objects.Node import from_json as Node_from_json + + +class TestSerialization: + def test_serialize_deserialize_invoice_data(self): + serialized = '{"__typename": "InvoiceData", "invoice_data_encoded_payment_request":"lnbcrt34170n1pj5vdn4pp56jhw0672v566u4rvl333v8hwwuvavvu9gx4a2mqag4pkrvm0hwkqhp5xaz278y6cejcvpqnndl4wfq3slgthjduwlfksg778aevn23v2pdscqzpgxqyz5vqsp5ee5jezfvjqvvz7hfwta3ekk8hs6dq36szkgp40qh7twa8upquxlq9qyyssqjg2slc95falxf2t67y0wu2w43qwfcvfflwl8tn4ppqw9tumwqxk36qkfct9p2w8c3yy2ld7c6nacy4ssv2gl6qyqfpmhl4jmarnjf8cpvjlxek","invoice_data_bitcoin_network":"REGTEST","invoice_data_payment_hash":"d4aee7ebca6535ae546cfc63161eee7719d6338541abd56c1d454361b36fbbac","invoice_data_amount":{"currency_amount_original_value":3417,"currency_amount_original_unit":"SATOSHI","currency_amount_preferred_currency_unit":"USD","currency_amount_preferred_currency_value_rounded":118,"currency_amount_preferred_currency_value_approx":118.89352818371607},"invoice_data_created_at":"2023-11-04T12:17:57Z","invoice_data_expires_at":"2023-11-05T12:17:57Z","invoice_data_memo":null,"invoice_data_destination":{"graph_node_id":"GraphNode:0189a572-6dba-cf00-0000-ac0908d34ea6","graph_node_created_at":"2023-07-30T06:18:07.162759Z","graph_node_updated_at":"2023-11-04T12:01:04.015414Z","graph_node_alias":"ls_test_vSViIQitob_SE","graph_node_bitcoin_network":"REGTEST","graph_node_color":"#3399ff","graph_node_conductivity":null,"graph_node_display_name":"ls_test_vSViIQitob_SE","graph_node_public_key":"02253935a5703a6f0429081e08d2defce0faa15f4d75305302284751d53a4e0608", "__typename":"GraphNode"}}' + deserialized = InvoiceData_from_json(None, json.loads(serialized)) + reserialized = deserialized.to_json() + # TODO(Jeremy): Fix this assertion by making iso format consistent w.r.t. trailing Z. + # assert reserialized == json.loads(serialized) + + deserialized_again = InvoiceData_from_json(None, reserialized) + assert deserialized_again == deserialized + + def test_serialize_deserialize_graph_node(self): + serialized = '{"graph_node_id":"GraphNode:0189a572-6dba-cf00-0000-ac0908d34ea6","graph_node_created_at":"2023-07-30T06:18:07.162759Z","graph_node_updated_at":"2023-11-04T12:01:04.015414Z","graph_node_alias":"ls_test_vSViIQitob_SE","graph_node_bitcoin_network":"REGTEST","graph_node_color":"#3399ff","graph_node_conductivity":null,"graph_node_display_name":"ls_test_vSViIQitob_SE","graph_node_public_key":"02253935a5703a6f0429081e08d2defce0faa15f4d75305302284751d53a4e0608", "__typename":"GraphNode"}' + deserialized = Node_from_json(None, json.loads(serialized)) + reserialized = deserialized.to_json() + # TODO(Jeremy): Fix this assertion by making iso format consistent w.r.t. trailing Z. + # assert reserialized == json.loads(serialized) + + deserialized_again = Node_from_json(None, reserialized) + assert deserialized_again == deserialized diff --git a/lightspark/objects/Account.py b/lightspark/objects/Account.py index 72f29ee..125ac65 100644 --- a/lightspark/objects/Account.py +++ b/lightspark/objects/Account.py @@ -1762,6 +1762,15 @@ def get_wallets( connection = json["entity"]["wallets"] return AccountToWalletsConnection_from_json(self.requester, connection) + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "Account", + "account_id": self.id, + "account_created_at": self.created_at.isoformat(), + "account_updated_at": self.updated_at.isoformat(), + "account_name": self.name, + } + FRAGMENT = """ fragment AccountFragment on Account { diff --git a/lightspark/objects/AccountToApiTokensConnection.py b/lightspark/objects/AccountToApiTokensConnection.py index 4644245..35682e0 100644 --- a/lightspark/objects/AccountToApiTokensConnection.py +++ b/lightspark/objects/AccountToApiTokensConnection.py @@ -26,6 +26,16 @@ class AccountToApiTokensConnection(Connection): """The API tokens for the current page of this connection.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "AccountToApiTokensConnection", + "account_to_api_tokens_connection_count": self.count, + "account_to_api_tokens_connection_page_info": self.page_info.to_json(), + "account_to_api_tokens_connection_entities": [ + e.to_json() for e in self.entities + ], + } + FRAGMENT = """ fragment AccountToApiTokensConnectionFragment on AccountToApiTokensConnection { diff --git a/lightspark/objects/AccountToChannelsConnection.py b/lightspark/objects/AccountToChannelsConnection.py index 6e07553..fa8fb71 100644 --- a/lightspark/objects/AccountToChannelsConnection.py +++ b/lightspark/objects/AccountToChannelsConnection.py @@ -19,6 +19,14 @@ class AccountToChannelsConnection: entities: List[Channel] """The channels for the current page of this connection.""" + def to_json(self) -> Mapping[str, Any]: + return { + "account_to_channels_connection_count": self.count, + "account_to_channels_connection_entities": [ + e.to_json() for e in self.entities + ], + } + FRAGMENT = """ fragment AccountToChannelsConnectionFragment on AccountToChannelsConnection { diff --git a/lightspark/objects/AccountToNodesConnection.py b/lightspark/objects/AccountToNodesConnection.py index 249f348..b896548 100644 --- a/lightspark/objects/AccountToNodesConnection.py +++ b/lightspark/objects/AccountToNodesConnection.py @@ -28,6 +28,16 @@ class AccountToNodesConnection(Connection): """The nodes for the current page of this connection.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "AccountToNodesConnection", + "account_to_nodes_connection_count": self.count, + "account_to_nodes_connection_page_info": self.page_info.to_json(), + "account_to_nodes_connection_entities": [ + e.to_json() for e in self.entities + ], + } + FRAGMENT = """ fragment AccountToNodesConnectionFragment on AccountToNodesConnection { diff --git a/lightspark/objects/AccountToPaymentRequestsConnection.py b/lightspark/objects/AccountToPaymentRequestsConnection.py index da17ca3..723a53d 100644 --- a/lightspark/objects/AccountToPaymentRequestsConnection.py +++ b/lightspark/objects/AccountToPaymentRequestsConnection.py @@ -26,6 +26,16 @@ class AccountToPaymentRequestsConnection(Connection): """The payment requests for the current page of this connection.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "AccountToPaymentRequestsConnection", + "account_to_payment_requests_connection_count": self.count, + "account_to_payment_requests_connection_page_info": self.page_info.to_json(), + "account_to_payment_requests_connection_entities": [ + e.to_json() for e in self.entities + ], + } + FRAGMENT = """ fragment AccountToPaymentRequestsConnectionFragment on AccountToPaymentRequestsConnection { diff --git a/lightspark/objects/AccountToTransactionsConnection.py b/lightspark/objects/AccountToTransactionsConnection.py index fdc0f37..b3f7aef 100644 --- a/lightspark/objects/AccountToTransactionsConnection.py +++ b/lightspark/objects/AccountToTransactionsConnection.py @@ -37,6 +37,25 @@ class AccountToTransactionsConnection(Connection): """The transactions for the current page of this connection.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "AccountToTransactionsConnection", + "account_to_transactions_connection_count": self.count, + "account_to_transactions_connection_page_info": self.page_info.to_json(), + "account_to_transactions_connection_profit_loss": self.profit_loss.to_json() + if self.profit_loss + else None, + "account_to_transactions_connection_average_fee_earned": self.average_fee_earned.to_json() + if self.average_fee_earned + else None, + "account_to_transactions_connection_total_amount_transacted": self.total_amount_transacted.to_json() + if self.total_amount_transacted + else None, + "account_to_transactions_connection_entities": [ + e.to_json() for e in self.entities + ], + } + FRAGMENT = """ fragment AccountToTransactionsConnectionFragment on AccountToTransactionsConnection { diff --git a/lightspark/objects/AccountToWalletsConnection.py b/lightspark/objects/AccountToWalletsConnection.py index bea1453..73a7b45 100644 --- a/lightspark/objects/AccountToWalletsConnection.py +++ b/lightspark/objects/AccountToWalletsConnection.py @@ -26,6 +26,16 @@ class AccountToWalletsConnection(Connection): """The wallets for the current page of this connection.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "AccountToWalletsConnection", + "account_to_wallets_connection_count": self.count, + "account_to_wallets_connection_page_info": self.page_info.to_json(), + "account_to_wallets_connection_entities": [ + e.to_json() for e in self.entities + ], + } + FRAGMENT = """ fragment AccountToWalletsConnectionFragment on AccountToWalletsConnection { diff --git a/lightspark/objects/ApiToken.py b/lightspark/objects/ApiToken.py index f58f94b..0f3298f 100644 --- a/lightspark/objects/ApiToken.py +++ b/lightspark/objects/ApiToken.py @@ -36,6 +36,17 @@ class ApiToken(Entity): """A list of permissions granted to the token.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "ApiToken", + "api_token_id": self.id, + "api_token_created_at": self.created_at.isoformat(), + "api_token_updated_at": self.updated_at.isoformat(), + "api_token_client_id": self.client_id, + "api_token_name": self.name, + "api_token_permissions": [e.to_json() for e in self.permissions], + } + FRAGMENT = """ fragment ApiTokenFragment on ApiToken { diff --git a/lightspark/objects/Balances.py b/lightspark/objects/Balances.py index 3379294..b2c4bfc 100644 --- a/lightspark/objects/Balances.py +++ b/lightspark/objects/Balances.py @@ -30,6 +30,13 @@ class Balances: It represents the amount currently available to withdraw and is usually equal to the `owned_balance` but it does not include in-flight operations (which would likely succeed and therefore likely make your withdrawal fail).""" + def to_json(self) -> Mapping[str, Any]: + return { + "balances_owned_balance": self.owned_balance.to_json(), + "balances_available_to_send_balance": self.available_to_send_balance.to_json(), + "balances_available_to_withdraw_balance": self.available_to_withdraw_balance.to_json(), + } + FRAGMENT = """ fragment BalancesFragment on Balances { diff --git a/lightspark/objects/BlockchainBalance.py b/lightspark/objects/BlockchainBalance.py index 30f6895..8f928b1 100644 --- a/lightspark/objects/BlockchainBalance.py +++ b/lightspark/objects/BlockchainBalance.py @@ -33,6 +33,28 @@ class BlockchainBalance: available_balance: Optional[CurrencyAmount] """Funds available for creating channels or withdrawing.""" + def to_json(self) -> Mapping[str, Any]: + return { + "blockchain_balance_total_balance": self.total_balance.to_json() + if self.total_balance + else None, + "blockchain_balance_confirmed_balance": self.confirmed_balance.to_json() + if self.confirmed_balance + else None, + "blockchain_balance_unconfirmed_balance": self.unconfirmed_balance.to_json() + if self.unconfirmed_balance + else None, + "blockchain_balance_locked_balance": self.locked_balance.to_json() + if self.locked_balance + else None, + "blockchain_balance_required_reserve": self.required_reserve.to_json() + if self.required_reserve + else None, + "blockchain_balance_available_balance": self.available_balance.to_json() + if self.available_balance + else None, + } + FRAGMENT = """ fragment BlockchainBalanceFragment on BlockchainBalance { diff --git a/lightspark/objects/Channel.py b/lightspark/objects/Channel.py index c362da4..a57cde0 100644 --- a/lightspark/objects/Channel.py +++ b/lightspark/objects/Channel.py @@ -159,6 +159,47 @@ def get_transactions( connection = json["entity"]["transactions"] return ChannelToTransactionsConnection_from_json(self.requester, connection) + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "Channel", + "channel_id": self.id, + "channel_created_at": self.created_at.isoformat(), + "channel_updated_at": self.updated_at.isoformat(), + "channel_funding_transaction": {"id": self.funding_transaction_id} + if self.funding_transaction_id + else None, + "channel_capacity": self.capacity.to_json() if self.capacity else None, + "channel_local_balance": self.local_balance.to_json() + if self.local_balance + else None, + "channel_local_unsettled_balance": self.local_unsettled_balance.to_json() + if self.local_unsettled_balance + else None, + "channel_remote_balance": self.remote_balance.to_json() + if self.remote_balance + else None, + "channel_remote_unsettled_balance": self.remote_unsettled_balance.to_json() + if self.remote_unsettled_balance + else None, + "channel_unsettled_balance": self.unsettled_balance.to_json() + if self.unsettled_balance + else None, + "channel_total_balance": self.total_balance.to_json() + if self.total_balance + else None, + "channel_status": self.status.value, + "channel_estimated_force_closure_wait_minutes": self.estimated_force_closure_wait_minutes, + "channel_commit_fee": self.commit_fee.to_json() + if self.commit_fee + else None, + "channel_fees": self.fees.to_json() if self.fees else None, + "channel_remote_node": {"id": self.remote_node_id} + if self.remote_node_id + else None, + "channel_local_node": {"id": self.local_node_id}, + "channel_short_channel_id": self.short_channel_id, + } + FRAGMENT = """ fragment ChannelFragment on Channel { diff --git a/lightspark/objects/ChannelClosingTransaction.py b/lightspark/objects/ChannelClosingTransaction.py index abbeef0..138a0b1 100644 --- a/lightspark/objects/ChannelClosingTransaction.py +++ b/lightspark/objects/ChannelClosingTransaction.py @@ -62,6 +62,28 @@ class ChannelClosingTransaction(OnChainTransaction, Transaction, Entity): """If known, the channel this transaction is closing.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "ChannelClosingTransaction", + "channel_closing_transaction_id": self.id, + "channel_closing_transaction_created_at": self.created_at.isoformat(), + "channel_closing_transaction_updated_at": self.updated_at.isoformat(), + "channel_closing_transaction_status": self.status.value, + "channel_closing_transaction_resolved_at": self.resolved_at.isoformat(), + "channel_closing_transaction_amount": self.amount.to_json(), + "channel_closing_transaction_transaction_hash": self.transaction_hash, + "channel_closing_transaction_fees": self.fees.to_json() + if self.fees + else None, + "channel_closing_transaction_block_hash": self.block_hash, + "channel_closing_transaction_block_height": self.block_height, + "channel_closing_transaction_destination_addresses": self.destination_addresses, + "channel_closing_transaction_num_confirmations": self.num_confirmations, + "channel_closing_transaction_channel": {"id": self.channel_id} + if self.channel_id + else None, + } + FRAGMENT = """ fragment ChannelClosingTransactionFragment on ChannelClosingTransaction { diff --git a/lightspark/objects/ChannelFees.py b/lightspark/objects/ChannelFees.py index 62f6918..4f27597 100644 --- a/lightspark/objects/ChannelFees.py +++ b/lightspark/objects/ChannelFees.py @@ -19,6 +19,12 @@ class ChannelFees: fee_rate_per_mil: Optional[int] + def to_json(self) -> Mapping[str, Any]: + return { + "channel_fees_base_fee": self.base_fee.to_json() if self.base_fee else None, + "channel_fees_fee_rate_per_mil": self.fee_rate_per_mil, + } + FRAGMENT = """ fragment ChannelFeesFragment on ChannelFees { diff --git a/lightspark/objects/ChannelOpeningTransaction.py b/lightspark/objects/ChannelOpeningTransaction.py index 6113680..9612a1e 100644 --- a/lightspark/objects/ChannelOpeningTransaction.py +++ b/lightspark/objects/ChannelOpeningTransaction.py @@ -62,6 +62,28 @@ class ChannelOpeningTransaction(OnChainTransaction, Transaction, Entity): """If known, the channel this transaction is opening.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "ChannelOpeningTransaction", + "channel_opening_transaction_id": self.id, + "channel_opening_transaction_created_at": self.created_at.isoformat(), + "channel_opening_transaction_updated_at": self.updated_at.isoformat(), + "channel_opening_transaction_status": self.status.value, + "channel_opening_transaction_resolved_at": self.resolved_at.isoformat(), + "channel_opening_transaction_amount": self.amount.to_json(), + "channel_opening_transaction_transaction_hash": self.transaction_hash, + "channel_opening_transaction_fees": self.fees.to_json() + if self.fees + else None, + "channel_opening_transaction_block_hash": self.block_hash, + "channel_opening_transaction_block_height": self.block_height, + "channel_opening_transaction_destination_addresses": self.destination_addresses, + "channel_opening_transaction_num_confirmations": self.num_confirmations, + "channel_opening_transaction_channel": {"id": self.channel_id} + if self.channel_id + else None, + } + FRAGMENT = """ fragment ChannelOpeningTransactionFragment on ChannelOpeningTransaction { diff --git a/lightspark/objects/ChannelSnapshot.py b/lightspark/objects/ChannelSnapshot.py index 8e0c169..185b6c1 100644 --- a/lightspark/objects/ChannelSnapshot.py +++ b/lightspark/objects/ChannelSnapshot.py @@ -28,6 +28,27 @@ class ChannelSnapshot: remote_unsettled_balance: Optional[CurrencyAmount] + def to_json(self) -> Mapping[str, Any]: + return { + "channel_snapshot_channel": {"id": self.channel_id}, + "channel_snapshot_timestamp": self.timestamp.isoformat(), + "channel_snapshot_local_balance": self.local_balance.to_json() + if self.local_balance + else None, + "channel_snapshot_local_unsettled_balance": self.local_unsettled_balance.to_json() + if self.local_unsettled_balance + else None, + "channel_snapshot_local_channel_reserve": self.local_channel_reserve.to_json() + if self.local_channel_reserve + else None, + "channel_snapshot_remote_balance": self.remote_balance.to_json() + if self.remote_balance + else None, + "channel_snapshot_remote_unsettled_balance": self.remote_unsettled_balance.to_json() + if self.remote_unsettled_balance + else None, + } + FRAGMENT = """ fragment ChannelSnapshotFragment on ChannelSnapshot { diff --git a/lightspark/objects/ChannelToTransactionsConnection.py b/lightspark/objects/ChannelToTransactionsConnection.py index cf1a51b..4da3c3b 100644 --- a/lightspark/objects/ChannelToTransactionsConnection.py +++ b/lightspark/objects/ChannelToTransactionsConnection.py @@ -25,6 +25,20 @@ class ChannelToTransactionsConnection: total_fees: Optional[CurrencyAmount] """The total amount of fees for the transactions that transited through this channel, according to the filters and constraints of the connection.""" + def to_json(self) -> Mapping[str, Any]: + return { + "channel_to_transactions_connection_count": self.count, + "channel_to_transactions_connection_average_fee": self.average_fee.to_json() + if self.average_fee + else None, + "channel_to_transactions_connection_total_amount_transacted": self.total_amount_transacted.to_json() + if self.total_amount_transacted + else None, + "channel_to_transactions_connection_total_fees": self.total_fees.to_json() + if self.total_fees + else None, + } + FRAGMENT = """ fragment ChannelToTransactionsConnectionFragment on ChannelToTransactionsConnection { diff --git a/lightspark/objects/CreateApiTokenInput.py b/lightspark/objects/CreateApiTokenInput.py index 1dda0d3..66d89b7 100644 --- a/lightspark/objects/CreateApiTokenInput.py +++ b/lightspark/objects/CreateApiTokenInput.py @@ -16,6 +16,14 @@ class CreateApiTokenInput: permissions: List[Permission] """List of permissions to grant to the API token""" + def to_json(self) -> Mapping[str, Any]: + return { + "create_api_token_input_name": self.name, + "create_api_token_input_permissions": [ + e.to_json() for e in self.permissions + ], + } + def from_json(obj: Mapping[str, Any]) -> CreateApiTokenInput: return CreateApiTokenInput( diff --git a/lightspark/objects/CreateApiTokenOutput.py b/lightspark/objects/CreateApiTokenOutput.py index 5343e99..0edf990 100644 --- a/lightspark/objects/CreateApiTokenOutput.py +++ b/lightspark/objects/CreateApiTokenOutput.py @@ -20,6 +20,12 @@ class CreateApiTokenOutput: """The secret that should be used to authenticate against our API. This secret is not stored and will never be available again after this. You must keep this secret secure as it grants access to your account.""" + def to_json(self) -> Mapping[str, Any]: + return { + "create_api_token_output_api_token": self.api_token.to_json(), + "create_api_token_output_client_secret": self.client_secret, + } + FRAGMENT = """ fragment CreateApiTokenOutputFragment on CreateApiTokenOutput { diff --git a/lightspark/objects/CreateInvoiceInput.py b/lightspark/objects/CreateInvoiceInput.py index 1b737fb..229e2cf 100644 --- a/lightspark/objects/CreateInvoiceInput.py +++ b/lightspark/objects/CreateInvoiceInput.py @@ -24,6 +24,15 @@ class CreateInvoiceInput: expiry_secs: Optional[int] """The expiry of the invoice in seconds. Default value is 86400 (1 day).""" + def to_json(self) -> Mapping[str, Any]: + return { + "create_invoice_input_node_id": self.node_id, + "create_invoice_input_amount_msats": self.amount_msats, + "create_invoice_input_memo": self.memo, + "create_invoice_input_invoice_type": self.invoice_type.value, + "create_invoice_input_expiry_secs": self.expiry_secs, + } + def from_json(obj: Mapping[str, Any]) -> CreateInvoiceInput: return CreateInvoiceInput( diff --git a/lightspark/objects/CreateInvoiceOutput.py b/lightspark/objects/CreateInvoiceOutput.py index e390b44..2601f45 100644 --- a/lightspark/objects/CreateInvoiceOutput.py +++ b/lightspark/objects/CreateInvoiceOutput.py @@ -12,6 +12,11 @@ class CreateInvoiceOutput: invoice_id: str + def to_json(self) -> Mapping[str, Any]: + return { + "create_invoice_output_invoice": {"id": self.invoice_id}, + } + FRAGMENT = """ fragment CreateInvoiceOutputFragment on CreateInvoiceOutput { diff --git a/lightspark/objects/CreateLnurlInvoiceInput.py b/lightspark/objects/CreateLnurlInvoiceInput.py index 33948d9..ab0d2ce 100644 --- a/lightspark/objects/CreateLnurlInvoiceInput.py +++ b/lightspark/objects/CreateLnurlInvoiceInput.py @@ -18,6 +18,14 @@ class CreateLnurlInvoiceInput: expiry_secs: Optional[int] """The expiry of the invoice in seconds. Default value is 86400 (1 day).""" + def to_json(self) -> Mapping[str, Any]: + return { + "create_lnurl_invoice_input_node_id": self.node_id, + "create_lnurl_invoice_input_amount_msats": self.amount_msats, + "create_lnurl_invoice_input_metadata_hash": self.metadata_hash, + "create_lnurl_invoice_input_expiry_secs": self.expiry_secs, + } + def from_json(obj: Mapping[str, Any]) -> CreateLnurlInvoiceInput: return CreateLnurlInvoiceInput( diff --git a/lightspark/objects/CreateNodeWalletAddressInput.py b/lightspark/objects/CreateNodeWalletAddressInput.py index 3b71283..9425e2e 100644 --- a/lightspark/objects/CreateNodeWalletAddressInput.py +++ b/lightspark/objects/CreateNodeWalletAddressInput.py @@ -8,6 +8,11 @@ class CreateNodeWalletAddressInput: node_id: str + def to_json(self) -> Mapping[str, Any]: + return { + "create_node_wallet_address_input_node_id": self.node_id, + } + def from_json(obj: Mapping[str, Any]) -> CreateNodeWalletAddressInput: return CreateNodeWalletAddressInput( diff --git a/lightspark/objects/CreateNodeWalletAddressOutput.py b/lightspark/objects/CreateNodeWalletAddressOutput.py index f5d25f1..32fdcd6 100644 --- a/lightspark/objects/CreateNodeWalletAddressOutput.py +++ b/lightspark/objects/CreateNodeWalletAddressOutput.py @@ -14,6 +14,12 @@ class CreateNodeWalletAddressOutput: wallet_address: str + def to_json(self) -> Mapping[str, Any]: + return { + "create_node_wallet_address_output_node": {"id": self.node_id}, + "create_node_wallet_address_output_wallet_address": self.wallet_address, + } + FRAGMENT = """ fragment CreateNodeWalletAddressOutputFragment on CreateNodeWalletAddressOutput { diff --git a/lightspark/objects/CreateTestModeInvoiceInput.py b/lightspark/objects/CreateTestModeInvoiceInput.py index e4c867e..3fe5323 100644 --- a/lightspark/objects/CreateTestModeInvoiceInput.py +++ b/lightspark/objects/CreateTestModeInvoiceInput.py @@ -19,6 +19,14 @@ class CreateTestModeInvoiceInput: invoice_type: Optional[InvoiceType] + def to_json(self) -> Mapping[str, Any]: + return { + "create_test_mode_invoice_input_local_node_id": self.local_node_id, + "create_test_mode_invoice_input_amount_msats": self.amount_msats, + "create_test_mode_invoice_input_memo": self.memo, + "create_test_mode_invoice_input_invoice_type": self.invoice_type.value, + } + def from_json(obj: Mapping[str, Any]) -> CreateTestModeInvoiceInput: return CreateTestModeInvoiceInput( diff --git a/lightspark/objects/CreateTestModeInvoiceOutput.py b/lightspark/objects/CreateTestModeInvoiceOutput.py index 8d62c23..ac3e96d 100644 --- a/lightspark/objects/CreateTestModeInvoiceOutput.py +++ b/lightspark/objects/CreateTestModeInvoiceOutput.py @@ -12,6 +12,11 @@ class CreateTestModeInvoiceOutput: encoded_payment_request: str + def to_json(self) -> Mapping[str, Any]: + return { + "create_test_mode_invoice_output_encoded_payment_request": self.encoded_payment_request, + } + FRAGMENT = """ fragment CreateTestModeInvoiceOutputFragment on CreateTestModeInvoiceOutput { diff --git a/lightspark/objects/CreateTestModePaymentInput.py b/lightspark/objects/CreateTestModePaymentInput.py index 63702a3..0c71eb6 100644 --- a/lightspark/objects/CreateTestModePaymentInput.py +++ b/lightspark/objects/CreateTestModePaymentInput.py @@ -15,6 +15,13 @@ class CreateTestModePaymentInput: amount_msats: Optional[int] """The amount you will be paid for this invoice, expressed in msats. It should ONLY be set when the invoice amount is zero.""" + def to_json(self) -> Mapping[str, Any]: + return { + "create_test_mode_payment_input_local_node_id": self.local_node_id, + "create_test_mode_payment_input_encoded_invoice": self.encoded_invoice, + "create_test_mode_payment_input_amount_msats": self.amount_msats, + } + def from_json(obj: Mapping[str, Any]) -> CreateTestModePaymentInput: return CreateTestModePaymentInput( diff --git a/lightspark/objects/CreateTestModePaymentoutput.py b/lightspark/objects/CreateTestModePaymentoutput.py index 976d9b8..26b0bf9 100644 --- a/lightspark/objects/CreateTestModePaymentoutput.py +++ b/lightspark/objects/CreateTestModePaymentoutput.py @@ -18,6 +18,14 @@ class CreateTestModePaymentoutput: incoming_payment_id: str """The payment that has been received.""" + def to_json(self) -> Mapping[str, Any]: + return { + "create_test_mode_paymentoutput_payment": {"id": self.payment_id}, + "create_test_mode_paymentoutput_incoming_payment": { + "id": self.incoming_payment_id + }, + } + FRAGMENT = """ fragment CreateTestModePaymentoutputFragment on CreateTestModePaymentoutput { diff --git a/lightspark/objects/CreateUmaInvoiceInput.py b/lightspark/objects/CreateUmaInvoiceInput.py index af9a274..8e55cc6 100644 --- a/lightspark/objects/CreateUmaInvoiceInput.py +++ b/lightspark/objects/CreateUmaInvoiceInput.py @@ -14,6 +14,14 @@ class CreateUmaInvoiceInput: expiry_secs: Optional[int] + def to_json(self) -> Mapping[str, Any]: + return { + "create_uma_invoice_input_node_id": self.node_id, + "create_uma_invoice_input_amount_msats": self.amount_msats, + "create_uma_invoice_input_metadata_hash": self.metadata_hash, + "create_uma_invoice_input_expiry_secs": self.expiry_secs, + } + def from_json(obj: Mapping[str, Any]) -> CreateUmaInvoiceInput: return CreateUmaInvoiceInput( diff --git a/lightspark/objects/CurrencyAmount.py b/lightspark/objects/CurrencyAmount.py index 192b9bf..e9bb092 100644 --- a/lightspark/objects/CurrencyAmount.py +++ b/lightspark/objects/CurrencyAmount.py @@ -32,6 +32,15 @@ class CurrencyAmount: preferred_currency_value_approx: float """The approximate float value for this CurrencyAmount in the very base level of user's preferred currency. For example, for USD, the value will be in cents.""" + def to_json(self) -> Mapping[str, Any]: + return { + "currency_amount_original_value": self.original_value, + "currency_amount_original_unit": self.original_unit.value, + "currency_amount_preferred_currency_unit": self.preferred_currency_unit.value, + "currency_amount_preferred_currency_value_rounded": self.preferred_currency_value_rounded, + "currency_amount_preferred_currency_value_approx": self.preferred_currency_value_approx, + } + _CONVERSION_MAP = { CurrencyUnit.BITCOIN: { CurrencyUnit.BITCOIN: lambda v: v, diff --git a/lightspark/objects/DeclineToSignMessagesInput.py b/lightspark/objects/DeclineToSignMessagesInput.py index 230ee79..9ac7c7f 100644 --- a/lightspark/objects/DeclineToSignMessagesInput.py +++ b/lightspark/objects/DeclineToSignMessagesInput.py @@ -9,6 +9,11 @@ class DeclineToSignMessagesInput: payload_ids: List[str] """List of payload ids to decline to sign because validation failed.""" + def to_json(self) -> Mapping[str, Any]: + return { + "decline_to_sign_messages_input_payload_ids": self.payload_ids, + } + def from_json(obj: Mapping[str, Any]) -> DeclineToSignMessagesInput: return DeclineToSignMessagesInput( diff --git a/lightspark/objects/DeclineToSignMessagesOutput.py b/lightspark/objects/DeclineToSignMessagesOutput.py index c8a8eaa..7de917f 100644 --- a/lightspark/objects/DeclineToSignMessagesOutput.py +++ b/lightspark/objects/DeclineToSignMessagesOutput.py @@ -15,6 +15,13 @@ class DeclineToSignMessagesOutput: declined_payloads: List[SignablePayload] + def to_json(self) -> Mapping[str, Any]: + return { + "decline_to_sign_messages_output_declined_payloads": [ + e.to_json() for e in self.declined_payloads + ], + } + FRAGMENT = """ fragment DeclineToSignMessagesOutputFragment on DeclineToSignMessagesOutput { diff --git a/lightspark/objects/DeleteApiTokenInput.py b/lightspark/objects/DeleteApiTokenInput.py index 3fd3de7..620618b 100644 --- a/lightspark/objects/DeleteApiTokenInput.py +++ b/lightspark/objects/DeleteApiTokenInput.py @@ -8,6 +8,11 @@ class DeleteApiTokenInput: api_token_id: str + def to_json(self) -> Mapping[str, Any]: + return { + "delete_api_token_input_api_token_id": self.api_token_id, + } + def from_json(obj: Mapping[str, Any]) -> DeleteApiTokenInput: return DeleteApiTokenInput( diff --git a/lightspark/objects/DeleteApiTokenOutput.py b/lightspark/objects/DeleteApiTokenOutput.py index 67be3b9..94eb18e 100644 --- a/lightspark/objects/DeleteApiTokenOutput.py +++ b/lightspark/objects/DeleteApiTokenOutput.py @@ -12,6 +12,11 @@ class DeleteApiTokenOutput: account_id: str + def to_json(self) -> Mapping[str, Any]: + return { + "delete_api_token_output_account": {"id": self.account_id}, + } + FRAGMENT = """ fragment DeleteApiTokenOutputFragment on DeleteApiTokenOutput { diff --git a/lightspark/objects/Deposit.py b/lightspark/objects/Deposit.py index 127db74..062e8e4 100644 --- a/lightspark/objects/Deposit.py +++ b/lightspark/objects/Deposit.py @@ -62,6 +62,24 @@ class Deposit(OnChainTransaction, Transaction, Entity): """The recipient Lightspark node this deposit was sent to.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "Deposit", + "deposit_id": self.id, + "deposit_created_at": self.created_at.isoformat(), + "deposit_updated_at": self.updated_at.isoformat(), + "deposit_status": self.status.value, + "deposit_resolved_at": self.resolved_at.isoformat(), + "deposit_amount": self.amount.to_json(), + "deposit_transaction_hash": self.transaction_hash, + "deposit_fees": self.fees.to_json() if self.fees else None, + "deposit_block_hash": self.block_hash, + "deposit_block_height": self.block_height, + "deposit_destination_addresses": self.destination_addresses, + "deposit_num_confirmations": self.num_confirmations, + "deposit_destination": {"id": self.destination_id}, + } + FRAGMENT = """ fragment DepositFragment on Deposit { diff --git a/lightspark/objects/FeeEstimate.py b/lightspark/objects/FeeEstimate.py index 513d41a..8779146 100644 --- a/lightspark/objects/FeeEstimate.py +++ b/lightspark/objects/FeeEstimate.py @@ -19,6 +19,12 @@ class FeeEstimate: fee_min: CurrencyAmount + def to_json(self) -> Mapping[str, Any]: + return { + "fee_estimate_fee_fast": self.fee_fast.to_json(), + "fee_estimate_fee_min": self.fee_min.to_json(), + } + FRAGMENT = """ fragment FeeEstimateFragment on FeeEstimate { diff --git a/lightspark/objects/FundNodeInput.py b/lightspark/objects/FundNodeInput.py index f386c18..b11b731 100644 --- a/lightspark/objects/FundNodeInput.py +++ b/lightspark/objects/FundNodeInput.py @@ -10,6 +10,12 @@ class FundNodeInput: amount_sats: Optional[int] + def to_json(self) -> Mapping[str, Any]: + return { + "fund_node_input_node_id": self.node_id, + "fund_node_input_amount_sats": self.amount_sats, + } + def from_json(obj: Mapping[str, Any]) -> FundNodeInput: return FundNodeInput( diff --git a/lightspark/objects/FundNodeOutput.py b/lightspark/objects/FundNodeOutput.py index 1d6ebab..1ef782f 100644 --- a/lightspark/objects/FundNodeOutput.py +++ b/lightspark/objects/FundNodeOutput.py @@ -15,6 +15,11 @@ class FundNodeOutput: amount: CurrencyAmount + def to_json(self) -> Mapping[str, Any]: + return { + "fund_node_output_amount": self.amount.to_json(), + } + FRAGMENT = """ fragment FundNodeOutputFragment on FundNodeOutput { diff --git a/lightspark/objects/GraphNode.py b/lightspark/objects/GraphNode.py index 2306c40..6e823ef 100644 --- a/lightspark/objects/GraphNode.py +++ b/lightspark/objects/GraphNode.py @@ -76,6 +76,20 @@ def get_addresses( connection = json["entity"]["addresses"] return NodeToAddressesConnection_from_json(self.requester, connection) + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "GraphNode", + "graph_node_id": self.id, + "graph_node_created_at": self.created_at.isoformat(), + "graph_node_updated_at": self.updated_at.isoformat(), + "graph_node_alias": self.alias, + "graph_node_bitcoin_network": self.bitcoin_network.value, + "graph_node_color": self.color, + "graph_node_conductivity": self.conductivity, + "graph_node_display_name": self.display_name, + "graph_node_public_key": self.public_key, + } + FRAGMENT = """ fragment GraphNodeFragment on GraphNode { diff --git a/lightspark/objects/Hop.py b/lightspark/objects/Hop.py index f857930..dbacc7f 100644 --- a/lightspark/objects/Hop.py +++ b/lightspark/objects/Hop.py @@ -45,6 +45,24 @@ class Hop(Entity): """The block height at which an unsettled HTLC is considered expired.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "Hop", + "hop_id": self.id, + "hop_created_at": self.created_at.isoformat(), + "hop_updated_at": self.updated_at.isoformat(), + "hop_destination": {"id": self.destination_id} + if self.destination_id + else None, + "hop_index": self.index, + "hop_public_key": self.public_key, + "hop_amount_to_forward": self.amount_to_forward.to_json() + if self.amount_to_forward + else None, + "hop_fee": self.fee.to_json() if self.fee else None, + "hop_expiry_block_height": self.expiry_block_height, + } + FRAGMENT = """ fragment HopFragment on Hop { diff --git a/lightspark/objects/IdAndSignature.py b/lightspark/objects/IdAndSignature.py index bde38ec..a5e7339 100644 --- a/lightspark/objects/IdAndSignature.py +++ b/lightspark/objects/IdAndSignature.py @@ -12,6 +12,12 @@ class IdAndSignature: signature: str """The signature of the message.""" + def to_json(self) -> Mapping[str, Any]: + return { + "id_and_signature_id": self.id, + "id_and_signature_signature": self.signature, + } + def from_json(obj: Mapping[str, Any]) -> IdAndSignature: return IdAndSignature( diff --git a/lightspark/objects/IncomingPayment.py b/lightspark/objects/IncomingPayment.py index ea1f85c..925e6ad 100644 --- a/lightspark/objects/IncomingPayment.py +++ b/lightspark/objects/IncomingPayment.py @@ -115,6 +115,27 @@ def get_attempts( connection = json["entity"]["attempts"] return IncomingPaymentToAttemptsConnection_from_json(self.requester, connection) + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "IncomingPayment", + "incoming_payment_id": self.id, + "incoming_payment_created_at": self.created_at.isoformat(), + "incoming_payment_updated_at": self.updated_at.isoformat(), + "incoming_payment_status": self.status.value, + "incoming_payment_resolved_at": self.resolved_at.isoformat(), + "incoming_payment_amount": self.amount.to_json(), + "incoming_payment_transaction_hash": self.transaction_hash, + "incoming_payment_destination": {"id": self.destination_id}, + "incoming_payment_payment_request": {"id": self.payment_request_id} + if self.payment_request_id + else None, + "incoming_payment_uma_post_transaction_data": [ + e.to_json() for e in self.uma_post_transaction_data + ] + if self.uma_post_transaction_data + else None, + } + FRAGMENT = """ fragment IncomingPaymentFragment on IncomingPayment { diff --git a/lightspark/objects/IncomingPaymentAttempt.py b/lightspark/objects/IncomingPaymentAttempt.py index 6d27f6c..e7440f8 100644 --- a/lightspark/objects/IncomingPaymentAttempt.py +++ b/lightspark/objects/IncomingPaymentAttempt.py @@ -42,6 +42,18 @@ class IncomingPaymentAttempt(Entity): """The channel this attempt was made on.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "IncomingPaymentAttempt", + "incoming_payment_attempt_id": self.id, + "incoming_payment_attempt_created_at": self.created_at.isoformat(), + "incoming_payment_attempt_updated_at": self.updated_at.isoformat(), + "incoming_payment_attempt_status": self.status.value, + "incoming_payment_attempt_resolved_at": self.resolved_at.isoformat(), + "incoming_payment_attempt_amount": self.amount.to_json(), + "incoming_payment_attempt_channel": {"id": self.channel_id}, + } + FRAGMENT = """ fragment IncomingPaymentAttemptFragment on IncomingPaymentAttempt { diff --git a/lightspark/objects/IncomingPaymentToAttemptsConnection.py b/lightspark/objects/IncomingPaymentToAttemptsConnection.py index fc36c08..e29e66c 100644 --- a/lightspark/objects/IncomingPaymentToAttemptsConnection.py +++ b/lightspark/objects/IncomingPaymentToAttemptsConnection.py @@ -28,6 +28,16 @@ class IncomingPaymentToAttemptsConnection(Connection): """The incoming payment attempts for the current page of this connection.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "IncomingPaymentToAttemptsConnection", + "incoming_payment_to_attempts_connection_count": self.count, + "incoming_payment_to_attempts_connection_page_info": self.page_info.to_json(), + "incoming_payment_to_attempts_connection_entities": [ + e.to_json() for e in self.entities + ], + } + FRAGMENT = """ fragment IncomingPaymentToAttemptsConnectionFragment on IncomingPaymentToAttemptsConnection { diff --git a/lightspark/objects/Invoice.py b/lightspark/objects/Invoice.py index 2f42abc..87cb225 100644 --- a/lightspark/objects/Invoice.py +++ b/lightspark/objects/Invoice.py @@ -42,6 +42,19 @@ class Invoice(PaymentRequest, Entity): """The total amount that has been paid to this invoice.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "Invoice", + "invoice_id": self.id, + "invoice_created_at": self.created_at.isoformat(), + "invoice_updated_at": self.updated_at.isoformat(), + "invoice_data": self.data.to_json(), + "invoice_status": self.status.value, + "invoice_amount_paid": self.amount_paid.to_json() + if self.amount_paid + else None, + } + FRAGMENT = """ fragment InvoiceFragment on Invoice { diff --git a/lightspark/objects/InvoiceData.py b/lightspark/objects/InvoiceData.py index 0c22934..ac89e25 100644 --- a/lightspark/objects/InvoiceData.py +++ b/lightspark/objects/InvoiceData.py @@ -45,6 +45,19 @@ class InvoiceData(PaymentRequestData): """The lightning node that will be paid when fulfilling this invoice.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "InvoiceData", + "invoice_data_encoded_payment_request": self.encoded_payment_request, + "invoice_data_bitcoin_network": self.bitcoin_network.value, + "invoice_data_payment_hash": self.payment_hash, + "invoice_data_amount": self.amount.to_json(), + "invoice_data_created_at": self.created_at.isoformat(), + "invoice_data_expires_at": self.expires_at.isoformat(), + "invoice_data_memo": self.memo, + "invoice_data_destination": self.destination.to_json(), + } + FRAGMENT = """ fragment InvoiceDataFragment on InvoiceData { diff --git a/lightspark/objects/LightningFeeEstimateForInvoiceInput.py b/lightspark/objects/LightningFeeEstimateForInvoiceInput.py index 91b078d..04391b0 100644 --- a/lightspark/objects/LightningFeeEstimateForInvoiceInput.py +++ b/lightspark/objects/LightningFeeEstimateForInvoiceInput.py @@ -15,6 +15,13 @@ class LightningFeeEstimateForInvoiceInput: amount_msats: Optional[int] """If the invoice does not specify a payment amount, then the amount that you wish to pay, expressed in msats.""" + def to_json(self) -> Mapping[str, Any]: + return { + "lightning_fee_estimate_for_invoice_input_node_id": self.node_id, + "lightning_fee_estimate_for_invoice_input_encoded_payment_request": self.encoded_payment_request, + "lightning_fee_estimate_for_invoice_input_amount_msats": self.amount_msats, + } + def from_json(obj: Mapping[str, Any]) -> LightningFeeEstimateForInvoiceInput: return LightningFeeEstimateForInvoiceInput( diff --git a/lightspark/objects/LightningFeeEstimateForNodeInput.py b/lightspark/objects/LightningFeeEstimateForNodeInput.py index 8183887..e0c80d0 100644 --- a/lightspark/objects/LightningFeeEstimateForNodeInput.py +++ b/lightspark/objects/LightningFeeEstimateForNodeInput.py @@ -15,6 +15,13 @@ class LightningFeeEstimateForNodeInput: amount_msats: int """The payment amount expressed in msats.""" + def to_json(self) -> Mapping[str, Any]: + return { + "lightning_fee_estimate_for_node_input_node_id": self.node_id, + "lightning_fee_estimate_for_node_input_destination_node_public_key": self.destination_node_public_key, + "lightning_fee_estimate_for_node_input_amount_msats": self.amount_msats, + } + def from_json(obj: Mapping[str, Any]) -> LightningFeeEstimateForNodeInput: return LightningFeeEstimateForNodeInput( diff --git a/lightspark/objects/LightningFeeEstimateOutput.py b/lightspark/objects/LightningFeeEstimateOutput.py index 82872c5..3a6bcd0 100644 --- a/lightspark/objects/LightningFeeEstimateOutput.py +++ b/lightspark/objects/LightningFeeEstimateOutput.py @@ -16,6 +16,11 @@ class LightningFeeEstimateOutput: fee_estimate: CurrencyAmount """The estimated fees for the payment.""" + def to_json(self) -> Mapping[str, Any]: + return { + "lightning_fee_estimate_output_fee_estimate": self.fee_estimate.to_json(), + } + FRAGMENT = """ fragment LightningFeeEstimateOutputFragment on LightningFeeEstimateOutput { diff --git a/lightspark/objects/LightningTransaction.py b/lightspark/objects/LightningTransaction.py index b116cd7..fa6947c 100644 --- a/lightspark/objects/LightningTransaction.py +++ b/lightspark/objects/LightningTransaction.py @@ -51,6 +51,18 @@ class LightningTransaction(Transaction, Entity): """The hash of this transaction, so it can be uniquely identified on the Lightning Network.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": self.typename, + "lightning_transaction_id": self.id, + "lightning_transaction_created_at": self.created_at.isoformat(), + "lightning_transaction_updated_at": self.updated_at.isoformat(), + "lightning_transaction_status": self.status.value, + "lightning_transaction_resolved_at": self.resolved_at.isoformat(), + "lightning_transaction_amount": self.amount.to_json(), + "lightning_transaction_transaction_hash": self.transaction_hash, + } + FRAGMENT = """ fragment LightningTransactionFragment on LightningTransaction { diff --git a/lightspark/objects/LightsparkNode.py b/lightspark/objects/LightsparkNode.py index 9932fd4..c1db178 100644 --- a/lightspark/objects/LightsparkNode.py +++ b/lightspark/objects/LightsparkNode.py @@ -248,6 +248,41 @@ def get_channels( connection = json["entity"]["channels"] return LightsparkNodeToChannelsConnection_from_json(self.requester, connection) + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": self.typename, + "lightspark_node_id": self.id, + "lightspark_node_created_at": self.created_at.isoformat(), + "lightspark_node_updated_at": self.updated_at.isoformat(), + "lightspark_node_alias": self.alias, + "lightspark_node_bitcoin_network": self.bitcoin_network.value, + "lightspark_node_color": self.color, + "lightspark_node_conductivity": self.conductivity, + "lightspark_node_display_name": self.display_name, + "lightspark_node_public_key": self.public_key, + "lightspark_node_owner": {"id": self.owner_id}, + "lightspark_node_status": self.status.value, + "lightspark_node_total_balance": self.total_balance.to_json() + if self.total_balance + else None, + "lightspark_node_total_local_balance": self.total_local_balance.to_json() + if self.total_local_balance + else None, + "lightspark_node_local_balance": self.local_balance.to_json() + if self.local_balance + else None, + "lightspark_node_remote_balance": self.remote_balance.to_json() + if self.remote_balance + else None, + "lightspark_node_blockchain_balance": self.blockchain_balance.to_json() + if self.blockchain_balance + else None, + "lightspark_node_uma_prescreening_utxos": self.uma_prescreening_utxos, + "lightspark_node_balances": self.balances.to_json() + if self.balances + else None, + } + FRAGMENT = """ fragment LightsparkNodeFragment on LightsparkNode { diff --git a/lightspark/objects/LightsparkNodeOwner.py b/lightspark/objects/LightsparkNodeOwner.py index 7f43ca3..8930933 100644 --- a/lightspark/objects/LightsparkNodeOwner.py +++ b/lightspark/objects/LightsparkNodeOwner.py @@ -29,6 +29,14 @@ class LightsparkNodeOwner(Entity): """The date and time when the entity was last updated.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": self.typename, + "lightspark_node_owner_id": self.id, + "lightspark_node_owner_created_at": self.created_at.isoformat(), + "lightspark_node_owner_updated_at": self.updated_at.isoformat(), + } + FRAGMENT = """ fragment LightsparkNodeOwnerFragment on LightsparkNodeOwner { diff --git a/lightspark/objects/LightsparkNodeToChannelsConnection.py b/lightspark/objects/LightsparkNodeToChannelsConnection.py index cc62343..5460d96 100644 --- a/lightspark/objects/LightsparkNodeToChannelsConnection.py +++ b/lightspark/objects/LightsparkNodeToChannelsConnection.py @@ -26,6 +26,16 @@ class LightsparkNodeToChannelsConnection(Connection): """The channels for the current page of this connection.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "LightsparkNodeToChannelsConnection", + "lightspark_node_to_channels_connection_count": self.count, + "lightspark_node_to_channels_connection_page_info": self.page_info.to_json(), + "lightspark_node_to_channels_connection_entities": [ + e.to_json() for e in self.entities + ], + } + FRAGMENT = """ fragment LightsparkNodeToChannelsConnectionFragment on LightsparkNodeToChannelsConnection { diff --git a/lightspark/objects/LightsparkNodeWithOSK.py b/lightspark/objects/LightsparkNodeWithOSK.py index dd46ed4..f688c22 100644 --- a/lightspark/objects/LightsparkNodeWithOSK.py +++ b/lightspark/objects/LightsparkNodeWithOSK.py @@ -252,6 +252,44 @@ def get_channels( connection = json["entity"]["channels"] return LightsparkNodeToChannelsConnection_from_json(self.requester, connection) + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "LightsparkNodeWithOSK", + "lightspark_node_with_o_s_k_id": self.id, + "lightspark_node_with_o_s_k_created_at": self.created_at.isoformat(), + "lightspark_node_with_o_s_k_updated_at": self.updated_at.isoformat(), + "lightspark_node_with_o_s_k_alias": self.alias, + "lightspark_node_with_o_s_k_bitcoin_network": self.bitcoin_network.value, + "lightspark_node_with_o_s_k_color": self.color, + "lightspark_node_with_o_s_k_conductivity": self.conductivity, + "lightspark_node_with_o_s_k_display_name": self.display_name, + "lightspark_node_with_o_s_k_public_key": self.public_key, + "lightspark_node_with_o_s_k_owner": {"id": self.owner_id}, + "lightspark_node_with_o_s_k_status": self.status.value, + "lightspark_node_with_o_s_k_total_balance": self.total_balance.to_json() + if self.total_balance + else None, + "lightspark_node_with_o_s_k_total_local_balance": self.total_local_balance.to_json() + if self.total_local_balance + else None, + "lightspark_node_with_o_s_k_local_balance": self.local_balance.to_json() + if self.local_balance + else None, + "lightspark_node_with_o_s_k_remote_balance": self.remote_balance.to_json() + if self.remote_balance + else None, + "lightspark_node_with_o_s_k_blockchain_balance": self.blockchain_balance.to_json() + if self.blockchain_balance + else None, + "lightspark_node_with_o_s_k_uma_prescreening_utxos": self.uma_prescreening_utxos, + "lightspark_node_with_o_s_k_balances": self.balances.to_json() + if self.balances + else None, + "lightspark_node_with_o_s_k_encrypted_signing_private_key": self.encrypted_signing_private_key.to_json() + if self.encrypted_signing_private_key + else None, + } + FRAGMENT = """ fragment LightsparkNodeWithOSKFragment on LightsparkNodeWithOSK { diff --git a/lightspark/objects/LightsparkNodeWithRemoteSigning.py b/lightspark/objects/LightsparkNodeWithRemoteSigning.py index 121702c..b53d801 100644 --- a/lightspark/objects/LightsparkNodeWithRemoteSigning.py +++ b/lightspark/objects/LightsparkNodeWithRemoteSigning.py @@ -247,6 +247,41 @@ def get_channels( connection = json["entity"]["channels"] return LightsparkNodeToChannelsConnection_from_json(self.requester, connection) + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "LightsparkNodeWithRemoteSigning", + "lightspark_node_with_remote_signing_id": self.id, + "lightspark_node_with_remote_signing_created_at": self.created_at.isoformat(), + "lightspark_node_with_remote_signing_updated_at": self.updated_at.isoformat(), + "lightspark_node_with_remote_signing_alias": self.alias, + "lightspark_node_with_remote_signing_bitcoin_network": self.bitcoin_network.value, + "lightspark_node_with_remote_signing_color": self.color, + "lightspark_node_with_remote_signing_conductivity": self.conductivity, + "lightspark_node_with_remote_signing_display_name": self.display_name, + "lightspark_node_with_remote_signing_public_key": self.public_key, + "lightspark_node_with_remote_signing_owner": {"id": self.owner_id}, + "lightspark_node_with_remote_signing_status": self.status.value, + "lightspark_node_with_remote_signing_total_balance": self.total_balance.to_json() + if self.total_balance + else None, + "lightspark_node_with_remote_signing_total_local_balance": self.total_local_balance.to_json() + if self.total_local_balance + else None, + "lightspark_node_with_remote_signing_local_balance": self.local_balance.to_json() + if self.local_balance + else None, + "lightspark_node_with_remote_signing_remote_balance": self.remote_balance.to_json() + if self.remote_balance + else None, + "lightspark_node_with_remote_signing_blockchain_balance": self.blockchain_balance.to_json() + if self.blockchain_balance + else None, + "lightspark_node_with_remote_signing_uma_prescreening_utxos": self.uma_prescreening_utxos, + "lightspark_node_with_remote_signing_balances": self.balances.to_json() + if self.balances + else None, + } + FRAGMENT = """ fragment LightsparkNodeWithRemoteSigningFragment on LightsparkNodeWithRemoteSigning { diff --git a/lightspark/objects/Node.py b/lightspark/objects/Node.py index 6f1de1e..75d29b5 100644 --- a/lightspark/objects/Node.py +++ b/lightspark/objects/Node.py @@ -81,6 +81,20 @@ def get_addresses( connection = json["entity"]["addresses"] return NodeToAddressesConnection_from_json(self.requester, connection) + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": self.typename, + "node_id": self.id, + "node_created_at": self.created_at.isoformat(), + "node_updated_at": self.updated_at.isoformat(), + "node_alias": self.alias, + "node_bitcoin_network": self.bitcoin_network.value, + "node_color": self.color, + "node_conductivity": self.conductivity, + "node_display_name": self.display_name, + "node_public_key": self.public_key, + } + FRAGMENT = """ fragment NodeFragment on Node { diff --git a/lightspark/objects/NodeAddress.py b/lightspark/objects/NodeAddress.py index 7855101..cc37f59 100644 --- a/lightspark/objects/NodeAddress.py +++ b/lightspark/objects/NodeAddress.py @@ -22,6 +22,12 @@ class NodeAddress: type: NodeAddressType """The type, or protocol, of this address.""" + def to_json(self) -> Mapping[str, Any]: + return { + "node_address_address": self.address, + "node_address_type": self.type.value, + } + FRAGMENT = """ fragment NodeAddressFragment on NodeAddress { diff --git a/lightspark/objects/NodeToAddressesConnection.py b/lightspark/objects/NodeToAddressesConnection.py index f89651d..8093dd1 100644 --- a/lightspark/objects/NodeToAddressesConnection.py +++ b/lightspark/objects/NodeToAddressesConnection.py @@ -21,6 +21,14 @@ class NodeToAddressesConnection: entities: List[NodeAddress] """The addresses for the current page of this connection.""" + def to_json(self) -> Mapping[str, Any]: + return { + "node_to_addresses_connection_count": self.count, + "node_to_addresses_connection_entities": [ + e.to_json() for e in self.entities + ], + } + FRAGMENT = """ fragment NodeToAddressesConnectionFragment on NodeToAddressesConnection { diff --git a/lightspark/objects/OnChainTransaction.py b/lightspark/objects/OnChainTransaction.py index b7a6356..5629cff 100644 --- a/lightspark/objects/OnChainTransaction.py +++ b/lightspark/objects/OnChainTransaction.py @@ -59,6 +59,23 @@ class OnChainTransaction(Transaction, Entity): """The number of blockchain confirmations for this transaction in real time.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": self.typename, + "on_chain_transaction_id": self.id, + "on_chain_transaction_created_at": self.created_at.isoformat(), + "on_chain_transaction_updated_at": self.updated_at.isoformat(), + "on_chain_transaction_status": self.status.value, + "on_chain_transaction_resolved_at": self.resolved_at.isoformat(), + "on_chain_transaction_amount": self.amount.to_json(), + "on_chain_transaction_transaction_hash": self.transaction_hash, + "on_chain_transaction_fees": self.fees.to_json() if self.fees else None, + "on_chain_transaction_block_hash": self.block_hash, + "on_chain_transaction_block_height": self.block_height, + "on_chain_transaction_destination_addresses": self.destination_addresses, + "on_chain_transaction_num_confirmations": self.num_confirmations, + } + FRAGMENT = """ fragment OnChainTransactionFragment on OnChainTransaction { diff --git a/lightspark/objects/OutgoingPayment.py b/lightspark/objects/OutgoingPayment.py index b987312..67176e4 100644 --- a/lightspark/objects/OutgoingPayment.py +++ b/lightspark/objects/OutgoingPayment.py @@ -184,6 +184,36 @@ def get_attempts( connection = json["entity"]["attempts"] return OutgoingPaymentToAttemptsConnection_from_json(self.requester, connection) + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "OutgoingPayment", + "outgoing_payment_id": self.id, + "outgoing_payment_created_at": self.created_at.isoformat(), + "outgoing_payment_updated_at": self.updated_at.isoformat(), + "outgoing_payment_status": self.status.value, + "outgoing_payment_resolved_at": self.resolved_at.isoformat(), + "outgoing_payment_amount": self.amount.to_json(), + "outgoing_payment_transaction_hash": self.transaction_hash, + "outgoing_payment_origin": {"id": self.origin_id}, + "outgoing_payment_destination": {"id": self.destination_id} + if self.destination_id + else None, + "outgoing_payment_fees": self.fees.to_json() if self.fees else None, + "outgoing_payment_payment_request_data": self.payment_request_data.to_json() + if self.payment_request_data + else None, + "outgoing_payment_failure_reason": self.failure_reason.value, + "outgoing_payment_failure_message": self.failure_message.to_json() + if self.failure_message + else None, + "outgoing_payment_uma_post_transaction_data": [ + e.to_json() for e in self.uma_post_transaction_data + ] + if self.uma_post_transaction_data + else None, + "outgoing_payment_payment_preimage": self.payment_preimage, + } + FRAGMENT = """ fragment OutgoingPaymentFragment on OutgoingPayment { diff --git a/lightspark/objects/OutgoingPaymentAttempt.py b/lightspark/objects/OutgoingPaymentAttempt.py index e71444f..0ee7e02 100644 --- a/lightspark/objects/OutgoingPaymentAttempt.py +++ b/lightspark/objects/OutgoingPaymentAttempt.py @@ -122,6 +122,28 @@ def get_hops( self.requester, connection ) + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "OutgoingPaymentAttempt", + "outgoing_payment_attempt_id": self.id, + "outgoing_payment_attempt_created_at": self.created_at.isoformat(), + "outgoing_payment_attempt_updated_at": self.updated_at.isoformat(), + "outgoing_payment_attempt_status": self.status.value, + "outgoing_payment_attempt_failure_code": self.failure_code.value, + "outgoing_payment_attempt_failure_source_index": self.failure_source_index, + "outgoing_payment_attempt_resolved_at": self.resolved_at.isoformat(), + "outgoing_payment_attempt_amount": self.amount.to_json() + if self.amount + else None, + "outgoing_payment_attempt_fees": self.fees.to_json() if self.fees else None, + "outgoing_payment_attempt_outgoing_payment": { + "id": self.outgoing_payment_id + }, + "outgoing_payment_attempt_channel_snapshot": self.channel_snapshot.to_json() + if self.channel_snapshot + else None, + } + FRAGMENT = """ fragment OutgoingPaymentAttemptFragment on OutgoingPaymentAttempt { diff --git a/lightspark/objects/OutgoingPaymentAttemptToHopsConnection.py b/lightspark/objects/OutgoingPaymentAttemptToHopsConnection.py index c095492..b7bb0cb 100644 --- a/lightspark/objects/OutgoingPaymentAttemptToHopsConnection.py +++ b/lightspark/objects/OutgoingPaymentAttemptToHopsConnection.py @@ -28,6 +28,16 @@ class OutgoingPaymentAttemptToHopsConnection(Connection): """The hops for the current page of this connection.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "OutgoingPaymentAttemptToHopsConnection", + "outgoing_payment_attempt_to_hops_connection_count": self.count, + "outgoing_payment_attempt_to_hops_connection_page_info": self.page_info.to_json(), + "outgoing_payment_attempt_to_hops_connection_entities": [ + e.to_json() for e in self.entities + ], + } + FRAGMENT = """ fragment OutgoingPaymentAttemptToHopsConnectionFragment on OutgoingPaymentAttemptToHopsConnection { diff --git a/lightspark/objects/OutgoingPaymentToAttemptsConnection.py b/lightspark/objects/OutgoingPaymentToAttemptsConnection.py index 6a1ba5f..36f8242 100644 --- a/lightspark/objects/OutgoingPaymentToAttemptsConnection.py +++ b/lightspark/objects/OutgoingPaymentToAttemptsConnection.py @@ -28,6 +28,16 @@ class OutgoingPaymentToAttemptsConnection(Connection): """The attempts for the current page of this connection.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "OutgoingPaymentToAttemptsConnection", + "outgoing_payment_to_attempts_connection_count": self.count, + "outgoing_payment_to_attempts_connection_page_info": self.page_info.to_json(), + "outgoing_payment_to_attempts_connection_entities": [ + e.to_json() for e in self.entities + ], + } + FRAGMENT = """ fragment OutgoingPaymentToAttemptsConnectionFragment on OutgoingPaymentToAttemptsConnection { diff --git a/lightspark/objects/OutgoingPaymentsForInvoiceQueryInput.py b/lightspark/objects/OutgoingPaymentsForInvoiceQueryInput.py index 8a6083a..ca69637 100644 --- a/lightspark/objects/OutgoingPaymentsForInvoiceQueryInput.py +++ b/lightspark/objects/OutgoingPaymentsForInvoiceQueryInput.py @@ -16,6 +16,16 @@ class OutgoingPaymentsForInvoiceQueryInput: statuses: Optional[List[TransactionStatus]] """An optional filter to only query outgoing payments of given statuses.""" + def to_json(self) -> Mapping[str, Any]: + return { + "outgoing_payments_for_invoice_query_input_encoded_invoice": self.encoded_invoice, + "outgoing_payments_for_invoice_query_input_statuses": [ + e.to_json() for e in self.statuses + ] + if self.statuses + else None, + } + def from_json(obj: Mapping[str, Any]) -> OutgoingPaymentsForInvoiceQueryInput: return OutgoingPaymentsForInvoiceQueryInput( diff --git a/lightspark/objects/OutgoingPaymentsForInvoiceQueryOutput.py b/lightspark/objects/OutgoingPaymentsForInvoiceQueryOutput.py index 7dcfd4a..cc04623 100644 --- a/lightspark/objects/OutgoingPaymentsForInvoiceQueryOutput.py +++ b/lightspark/objects/OutgoingPaymentsForInvoiceQueryOutput.py @@ -15,6 +15,13 @@ class OutgoingPaymentsForInvoiceQueryOutput: payments: List[OutgoingPayment] + def to_json(self) -> Mapping[str, Any]: + return { + "outgoing_payments_for_invoice_query_output_payments": [ + e.to_json() for e in self.payments + ], + } + FRAGMENT = """ fragment OutgoingPaymentsForInvoiceQueryOutputFragment on OutgoingPaymentsForInvoiceQueryOutput { diff --git a/lightspark/objects/PageInfo.py b/lightspark/objects/PageInfo.py index e34b86b..3b56c5b 100644 --- a/lightspark/objects/PageInfo.py +++ b/lightspark/objects/PageInfo.py @@ -20,6 +20,14 @@ class PageInfo: end_cursor: Optional[str] + def to_json(self) -> Mapping[str, Any]: + return { + "page_info_has_next_page": self.has_next_page, + "page_info_has_previous_page": self.has_previous_page, + "page_info_start_cursor": self.start_cursor, + "page_info_end_cursor": self.end_cursor, + } + FRAGMENT = """ fragment PageInfoFragment on PageInfo { diff --git a/lightspark/objects/PayInvoiceInput.py b/lightspark/objects/PayInvoiceInput.py index caeeb42..1f8f2d5 100644 --- a/lightspark/objects/PayInvoiceInput.py +++ b/lightspark/objects/PayInvoiceInput.py @@ -21,6 +21,15 @@ class PayInvoiceInput: amount_msats: Optional[int] """The amount you will pay for this invoice, expressed in msats. It should ONLY be set when the invoice amount is zero.""" + def to_json(self) -> Mapping[str, Any]: + return { + "pay_invoice_input_node_id": self.node_id, + "pay_invoice_input_encoded_invoice": self.encoded_invoice, + "pay_invoice_input_timeout_secs": self.timeout_secs, + "pay_invoice_input_maximum_fees_msats": self.maximum_fees_msats, + "pay_invoice_input_amount_msats": self.amount_msats, + } + def from_json(obj: Mapping[str, Any]) -> PayInvoiceInput: return PayInvoiceInput( diff --git a/lightspark/objects/PayInvoiceOutput.py b/lightspark/objects/PayInvoiceOutput.py index 9661f3e..4b33fb7 100644 --- a/lightspark/objects/PayInvoiceOutput.py +++ b/lightspark/objects/PayInvoiceOutput.py @@ -13,6 +13,11 @@ class PayInvoiceOutput: payment_id: str """The payment that has been sent.""" + def to_json(self) -> Mapping[str, Any]: + return { + "pay_invoice_output_payment": {"id": self.payment_id}, + } + FRAGMENT = """ fragment PayInvoiceOutputFragment on PayInvoiceOutput { diff --git a/lightspark/objects/PayUmaInvoiceInput.py b/lightspark/objects/PayUmaInvoiceInput.py index 6337049..7efeda5 100644 --- a/lightspark/objects/PayUmaInvoiceInput.py +++ b/lightspark/objects/PayUmaInvoiceInput.py @@ -16,6 +16,15 @@ class PayUmaInvoiceInput: amount_msats: Optional[int] + def to_json(self) -> Mapping[str, Any]: + return { + "pay_uma_invoice_input_node_id": self.node_id, + "pay_uma_invoice_input_encoded_invoice": self.encoded_invoice, + "pay_uma_invoice_input_timeout_secs": self.timeout_secs, + "pay_uma_invoice_input_maximum_fees_msats": self.maximum_fees_msats, + "pay_uma_invoice_input_amount_msats": self.amount_msats, + } + def from_json(obj: Mapping[str, Any]) -> PayUmaInvoiceInput: return PayUmaInvoiceInput( diff --git a/lightspark/objects/PaymentRequest.py b/lightspark/objects/PaymentRequest.py index 8373e42..dc0a9f6 100644 --- a/lightspark/objects/PaymentRequest.py +++ b/lightspark/objects/PaymentRequest.py @@ -38,6 +38,16 @@ class PaymentRequest(Entity): """The status of the payment request.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": self.typename, + "payment_request_id": self.id, + "payment_request_created_at": self.created_at.isoformat(), + "payment_request_updated_at": self.updated_at.isoformat(), + "payment_request_data": self.data.to_json(), + "payment_request_status": self.status.value, + } + FRAGMENT = """ fragment PaymentRequestFragment on PaymentRequest { diff --git a/lightspark/objects/PaymentRequestData.py b/lightspark/objects/PaymentRequestData.py index 7c57332..f407348 100644 --- a/lightspark/objects/PaymentRequestData.py +++ b/lightspark/objects/PaymentRequestData.py @@ -26,6 +26,13 @@ class PaymentRequestData: typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": self.typename, + "payment_request_data_encoded_payment_request": self.encoded_payment_request, + "payment_request_data_bitcoin_network": self.bitcoin_network.value, + } + FRAGMENT = """ fragment PaymentRequestDataFragment on PaymentRequestData { diff --git a/lightspark/objects/PostTransactionData.py b/lightspark/objects/PostTransactionData.py index 9e36701..f0a13bf 100644 --- a/lightspark/objects/PostTransactionData.py +++ b/lightspark/objects/PostTransactionData.py @@ -21,6 +21,12 @@ class PostTransactionData: amount: CurrencyAmount """The amount of funds transferred in the payment.""" + def to_json(self) -> Mapping[str, Any]: + return { + "post_transaction_data_utxo": self.utxo, + "post_transaction_data_amount": self.amount.to_json(), + } + FRAGMENT = """ fragment PostTransactionDataFragment on PostTransactionData { diff --git a/lightspark/objects/RegisterPaymentInput.py b/lightspark/objects/RegisterPaymentInput.py index 1e7244a..bb51676 100644 --- a/lightspark/objects/RegisterPaymentInput.py +++ b/lightspark/objects/RegisterPaymentInput.py @@ -25,6 +25,14 @@ class RegisterPaymentInput: direction: PaymentDirection """Indicates whether this payment is an OutgoingPayment or an IncomingPayment.""" + def to_json(self) -> Mapping[str, Any]: + return { + "register_payment_input_provider": self.provider.value, + "register_payment_input_payment_id": self.payment_id, + "register_payment_input_node_pubkey": self.node_pubkey, + "register_payment_input_direction": self.direction.value, + } + def from_json(obj: Mapping[str, Any]) -> RegisterPaymentInput: return RegisterPaymentInput( diff --git a/lightspark/objects/RegisterPaymentOutput.py b/lightspark/objects/RegisterPaymentOutput.py index 783ccb3..c2da6fc 100644 --- a/lightspark/objects/RegisterPaymentOutput.py +++ b/lightspark/objects/RegisterPaymentOutput.py @@ -12,6 +12,11 @@ class RegisterPaymentOutput: payment_id: str + def to_json(self) -> Mapping[str, Any]: + return { + "register_payment_output_payment": {"id": self.payment_id}, + } + FRAGMENT = """ fragment RegisterPaymentOutputFragment on RegisterPaymentOutput { diff --git a/lightspark/objects/ReleaseChannelPerCommitmentSecretInput.py b/lightspark/objects/ReleaseChannelPerCommitmentSecretInput.py index bf27849..15e9c1f 100644 --- a/lightspark/objects/ReleaseChannelPerCommitmentSecretInput.py +++ b/lightspark/objects/ReleaseChannelPerCommitmentSecretInput.py @@ -15,6 +15,13 @@ class ReleaseChannelPerCommitmentSecretInput: per_commitment_index: int """The index associated with the per-commitment secret.""" + def to_json(self) -> Mapping[str, Any]: + return { + "release_channel_per_commitment_secret_input_channel_id": self.channel_id, + "release_channel_per_commitment_secret_input_per_commitment_secret": self.per_commitment_secret, + "release_channel_per_commitment_secret_input_per_commitment_index": self.per_commitment_index, + } + def from_json(obj: Mapping[str, Any]) -> ReleaseChannelPerCommitmentSecretInput: return ReleaseChannelPerCommitmentSecretInput( diff --git a/lightspark/objects/ReleaseChannelPerCommitmentSecretOutput.py b/lightspark/objects/ReleaseChannelPerCommitmentSecretOutput.py index 83bb66b..75bb1bb 100644 --- a/lightspark/objects/ReleaseChannelPerCommitmentSecretOutput.py +++ b/lightspark/objects/ReleaseChannelPerCommitmentSecretOutput.py @@ -13,6 +13,13 @@ class ReleaseChannelPerCommitmentSecretOutput: channel_id: str """The channel object after the per-commitment secret release operation.""" + def to_json(self) -> Mapping[str, Any]: + return { + "release_channel_per_commitment_secret_output_channel": { + "id": self.channel_id + }, + } + FRAGMENT = """ fragment ReleaseChannelPerCommitmentSecretOutputFragment on ReleaseChannelPerCommitmentSecretOutput { diff --git a/lightspark/objects/ReleasePaymentPreimageInput.py b/lightspark/objects/ReleasePaymentPreimageInput.py index 6df4304..9967f4c 100644 --- a/lightspark/objects/ReleasePaymentPreimageInput.py +++ b/lightspark/objects/ReleasePaymentPreimageInput.py @@ -12,6 +12,12 @@ class ReleasePaymentPreimageInput: payment_preimage: str """The preimage to release.""" + def to_json(self) -> Mapping[str, Any]: + return { + "release_payment_preimage_input_invoice_id": self.invoice_id, + "release_payment_preimage_input_payment_preimage": self.payment_preimage, + } + def from_json(obj: Mapping[str, Any]) -> ReleasePaymentPreimageInput: return ReleasePaymentPreimageInput( diff --git a/lightspark/objects/ReleasePaymentPreimageOutput.py b/lightspark/objects/ReleasePaymentPreimageOutput.py index d153036..88811e5 100644 --- a/lightspark/objects/ReleasePaymentPreimageOutput.py +++ b/lightspark/objects/ReleasePaymentPreimageOutput.py @@ -13,6 +13,11 @@ class ReleasePaymentPreimageOutput: invoice_id: str """The invoice of the transaction.""" + def to_json(self) -> Mapping[str, Any]: + return { + "release_payment_preimage_output_invoice": {"id": self.invoice_id}, + } + FRAGMENT = """ fragment ReleasePaymentPreimageOutputFragment on ReleasePaymentPreimageOutput { diff --git a/lightspark/objects/RequestWithdrawalInput.py b/lightspark/objects/RequestWithdrawalInput.py index 37b18d7..21583cf 100644 --- a/lightspark/objects/RequestWithdrawalInput.py +++ b/lightspark/objects/RequestWithdrawalInput.py @@ -23,6 +23,14 @@ class RequestWithdrawalInput: withdrawal_mode: WithdrawalMode """The strategy that should be used to withdraw the funds from this node.""" + def to_json(self) -> Mapping[str, Any]: + return { + "request_withdrawal_input_node_id": self.node_id, + "request_withdrawal_input_bitcoin_address": self.bitcoin_address, + "request_withdrawal_input_amount_sats": self.amount_sats, + "request_withdrawal_input_withdrawal_mode": self.withdrawal_mode.value, + } + def from_json(obj: Mapping[str, Any]) -> RequestWithdrawalInput: return RequestWithdrawalInput( diff --git a/lightspark/objects/RequestWithdrawalOutput.py b/lightspark/objects/RequestWithdrawalOutput.py index 95a4b33..9ad37d4 100644 --- a/lightspark/objects/RequestWithdrawalOutput.py +++ b/lightspark/objects/RequestWithdrawalOutput.py @@ -13,6 +13,11 @@ class RequestWithdrawalOutput: request_id: str """The request that is created for this withdrawal.""" + def to_json(self) -> Mapping[str, Any]: + return { + "request_withdrawal_output_request": {"id": self.request_id}, + } + FRAGMENT = """ fragment RequestWithdrawalOutputFragment on RequestWithdrawalOutput { diff --git a/lightspark/objects/RichText.py b/lightspark/objects/RichText.py index ba94e54..8cf3473 100644 --- a/lightspark/objects/RichText.py +++ b/lightspark/objects/RichText.py @@ -12,6 +12,11 @@ class RichText: text: str + def to_json(self) -> Mapping[str, Any]: + return { + "rich_text_text": self.text, + } + FRAGMENT = """ fragment RichTextFragment on RichText { diff --git a/lightspark/objects/RoutingTransaction.py b/lightspark/objects/RoutingTransaction.py index 25f43ac..984ad13 100644 --- a/lightspark/objects/RoutingTransaction.py +++ b/lightspark/objects/RoutingTransaction.py @@ -65,6 +65,29 @@ class RoutingTransaction(LightningTransaction, Transaction, Entity): """If applicable, the reason why the routing failed.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "RoutingTransaction", + "routing_transaction_id": self.id, + "routing_transaction_created_at": self.created_at.isoformat(), + "routing_transaction_updated_at": self.updated_at.isoformat(), + "routing_transaction_status": self.status.value, + "routing_transaction_resolved_at": self.resolved_at.isoformat(), + "routing_transaction_amount": self.amount.to_json(), + "routing_transaction_transaction_hash": self.transaction_hash, + "routing_transaction_incoming_channel": {"id": self.incoming_channel_id} + if self.incoming_channel_id + else None, + "routing_transaction_outgoing_channel": {"id": self.outgoing_channel_id} + if self.outgoing_channel_id + else None, + "routing_transaction_fees": self.fees.to_json() if self.fees else None, + "routing_transaction_failure_message": self.failure_message.to_json() + if self.failure_message + else None, + "routing_transaction_failure_reason": self.failure_reason.value, + } + FRAGMENT = """ fragment RoutingTransactionFragment on RoutingTransaction { diff --git a/lightspark/objects/ScreenNodeInput.py b/lightspark/objects/ScreenNodeInput.py index f2be0c2..f78621a 100644 --- a/lightspark/objects/ScreenNodeInput.py +++ b/lightspark/objects/ScreenNodeInput.py @@ -17,6 +17,12 @@ class ScreenNodeInput: node_pubkey: str """The public key of the lightning node that needs to be screened.""" + def to_json(self) -> Mapping[str, Any]: + return { + "screen_node_input_provider": self.provider.value, + "screen_node_input_node_pubkey": self.node_pubkey, + } + def from_json(obj: Mapping[str, Any]) -> ScreenNodeInput: return ScreenNodeInput( diff --git a/lightspark/objects/ScreenNodeOutput.py b/lightspark/objects/ScreenNodeOutput.py index 6827792..d167e41 100644 --- a/lightspark/objects/ScreenNodeOutput.py +++ b/lightspark/objects/ScreenNodeOutput.py @@ -16,6 +16,11 @@ class ScreenNodeOutput: rating: RiskRating + def to_json(self) -> Mapping[str, Any]: + return { + "screen_node_output_rating": self.rating.value, + } + FRAGMENT = """ fragment ScreenNodeOutputFragment on ScreenNodeOutput { diff --git a/lightspark/objects/Secret.py b/lightspark/objects/Secret.py index 346025f..9384dca 100644 --- a/lightspark/objects/Secret.py +++ b/lightspark/objects/Secret.py @@ -14,6 +14,12 @@ class Secret: cipher: str + def to_json(self) -> Mapping[str, Any]: + return { + "secret_encrypted_value": self.encrypted_value, + "secret_cipher": self.cipher, + } + FRAGMENT = """ fragment SecretFragment on Secret { diff --git a/lightspark/objects/SendPaymentInput.py b/lightspark/objects/SendPaymentInput.py index 96123d9..fa1e9d0 100644 --- a/lightspark/objects/SendPaymentInput.py +++ b/lightspark/objects/SendPaymentInput.py @@ -21,6 +21,15 @@ class SendPaymentInput: maximum_fees_msats: int """The maximum amount of fees that you want to pay for this payment to be sent, expressed in msats.""" + def to_json(self) -> Mapping[str, Any]: + return { + "send_payment_input_node_id": self.node_id, + "send_payment_input_destination_public_key": self.destination_public_key, + "send_payment_input_timeout_secs": self.timeout_secs, + "send_payment_input_amount_msats": self.amount_msats, + "send_payment_input_maximum_fees_msats": self.maximum_fees_msats, + } + def from_json(obj: Mapping[str, Any]) -> SendPaymentInput: return SendPaymentInput( diff --git a/lightspark/objects/SendPaymentOutput.py b/lightspark/objects/SendPaymentOutput.py index b008efd..ee52b72 100644 --- a/lightspark/objects/SendPaymentOutput.py +++ b/lightspark/objects/SendPaymentOutput.py @@ -13,6 +13,11 @@ class SendPaymentOutput: payment_id: str """The payment that has been sent.""" + def to_json(self) -> Mapping[str, Any]: + return { + "send_payment_output_payment": {"id": self.payment_id}, + } + FRAGMENT = """ fragment SendPaymentOutputFragment on SendPaymentOutput { diff --git a/lightspark/objects/SetInvoicePaymentHashInput.py b/lightspark/objects/SetInvoicePaymentHashInput.py index a216aac..9e130ac 100644 --- a/lightspark/objects/SetInvoicePaymentHashInput.py +++ b/lightspark/objects/SetInvoicePaymentHashInput.py @@ -15,6 +15,13 @@ class SetInvoicePaymentHashInput: preimage_nonce: Optional[str] """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.""" + def to_json(self) -> Mapping[str, Any]: + return { + "set_invoice_payment_hash_input_invoice_id": self.invoice_id, + "set_invoice_payment_hash_input_payment_hash": self.payment_hash, + "set_invoice_payment_hash_input_preimage_nonce": self.preimage_nonce, + } + def from_json(obj: Mapping[str, Any]) -> SetInvoicePaymentHashInput: return SetInvoicePaymentHashInput( diff --git a/lightspark/objects/SetInvoicePaymentHashOutput.py b/lightspark/objects/SetInvoicePaymentHashOutput.py index 5c3dd88..f2b8768 100644 --- a/lightspark/objects/SetInvoicePaymentHashOutput.py +++ b/lightspark/objects/SetInvoicePaymentHashOutput.py @@ -12,6 +12,11 @@ class SetInvoicePaymentHashOutput: invoice_id: str + def to_json(self) -> Mapping[str, Any]: + return { + "set_invoice_payment_hash_output_invoice": {"id": self.invoice_id}, + } + FRAGMENT = """ fragment SetInvoicePaymentHashOutputFragment on SetInvoicePaymentHashOutput { diff --git a/lightspark/objects/SignInvoiceInput.py b/lightspark/objects/SignInvoiceInput.py index b47e97a..f946a21 100644 --- a/lightspark/objects/SignInvoiceInput.py +++ b/lightspark/objects/SignInvoiceInput.py @@ -15,6 +15,13 @@ class SignInvoiceInput: recovery_id: int """The recovery identifier for the signature.""" + def to_json(self) -> Mapping[str, Any]: + return { + "sign_invoice_input_invoice_id": self.invoice_id, + "sign_invoice_input_signature": self.signature, + "sign_invoice_input_recovery_id": self.recovery_id, + } + def from_json(obj: Mapping[str, Any]) -> SignInvoiceInput: return SignInvoiceInput( diff --git a/lightspark/objects/SignInvoiceOutput.py b/lightspark/objects/SignInvoiceOutput.py index 19869ff..df2b868 100644 --- a/lightspark/objects/SignInvoiceOutput.py +++ b/lightspark/objects/SignInvoiceOutput.py @@ -13,6 +13,11 @@ class SignInvoiceOutput: invoice_id: str """ The signed invoice object.""" + def to_json(self) -> Mapping[str, Any]: + return { + "sign_invoice_output_invoice": {"id": self.invoice_id}, + } + FRAGMENT = """ fragment SignInvoiceOutputFragment on SignInvoiceOutput { diff --git a/lightspark/objects/SignMessagesInput.py b/lightspark/objects/SignMessagesInput.py index de68ded..bf79191 100644 --- a/lightspark/objects/SignMessagesInput.py +++ b/lightspark/objects/SignMessagesInput.py @@ -12,6 +12,11 @@ class SignMessagesInput: signatures: List[IdAndSignature] """The list of the message ids and signatures.""" + def to_json(self) -> Mapping[str, Any]: + return { + "sign_messages_input_signatures": [e.to_json() for e in self.signatures], + } + def from_json(obj: Mapping[str, Any]) -> SignMessagesInput: return SignMessagesInput( diff --git a/lightspark/objects/SignMessagesOutput.py b/lightspark/objects/SignMessagesOutput.py index c170c17..382e144 100644 --- a/lightspark/objects/SignMessagesOutput.py +++ b/lightspark/objects/SignMessagesOutput.py @@ -16,6 +16,13 @@ class SignMessagesOutput: signed_payloads: List[SignablePayload] """The list of signed payloads.""" + def to_json(self) -> Mapping[str, Any]: + return { + "sign_messages_output_signed_payloads": [ + e.to_json() for e in self.signed_payloads + ], + } + FRAGMENT = """ fragment SignMessagesOutputFragment on SignMessagesOutput { diff --git a/lightspark/objects/Signable.py b/lightspark/objects/Signable.py index 77e7072..b0cc213 100644 --- a/lightspark/objects/Signable.py +++ b/lightspark/objects/Signable.py @@ -23,6 +23,14 @@ class Signable(Entity): """The date and time when the entity was last updated.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "Signable", + "signable_id": self.id, + "signable_created_at": self.created_at.isoformat(), + "signable_updated_at": self.updated_at.isoformat(), + } + FRAGMENT = """ fragment SignableFragment on Signable { diff --git a/lightspark/objects/SignablePayload.py b/lightspark/objects/SignablePayload.py index eea22de..b7acbee 100644 --- a/lightspark/objects/SignablePayload.py +++ b/lightspark/objects/SignablePayload.py @@ -44,6 +44,20 @@ class SignablePayload(Entity): """The signable this payload belongs to.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "SignablePayload", + "signable_payload_id": self.id, + "signable_payload_created_at": self.created_at.isoformat(), + "signable_payload_updated_at": self.updated_at.isoformat(), + "signable_payload_payload": self.payload, + "signable_payload_derivation_path": self.derivation_path, + "signable_payload_status": self.status.value, + "signable_payload_add_tweak": self.add_tweak, + "signable_payload_mul_tweak": self.mul_tweak, + "signable_payload_signable": {"id": self.signable_id}, + } + FRAGMENT = """ fragment SignablePayloadFragment on SignablePayload { diff --git a/lightspark/objects/Transaction.py b/lightspark/objects/Transaction.py index ce9030e..4a9c6ac 100644 --- a/lightspark/objects/Transaction.py +++ b/lightspark/objects/Transaction.py @@ -50,6 +50,18 @@ class Transaction(Entity): """The hash of this transaction, so it can be uniquely identified on the Lightning Network.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": self.typename, + "transaction_id": self.id, + "transaction_created_at": self.created_at.isoformat(), + "transaction_updated_at": self.updated_at.isoformat(), + "transaction_status": self.status.value, + "transaction_resolved_at": self.resolved_at.isoformat(), + "transaction_amount": self.amount.to_json(), + "transaction_transaction_hash": self.transaction_hash, + } + FRAGMENT = """ fragment TransactionFragment on Transaction { diff --git a/lightspark/objects/TransactionFailures.py b/lightspark/objects/TransactionFailures.py index d7b19de..852c588 100644 --- a/lightspark/objects/TransactionFailures.py +++ b/lightspark/objects/TransactionFailures.py @@ -17,6 +17,20 @@ class TransactionFailures: routing_transaction_failures: Optional[List[RoutingTransactionFailureReason]] + def to_json(self) -> Mapping[str, Any]: + return { + "transaction_failures_payment_failures": [ + e.to_json() for e in self.payment_failures + ] + if self.payment_failures + else None, + "transaction_failures_routing_transaction_failures": [ + e.to_json() for e in self.routing_transaction_failures + ] + if self.routing_transaction_failures + else None, + } + def from_json(obj: Mapping[str, Any]) -> TransactionFailures: return TransactionFailures( diff --git a/lightspark/objects/UpdateChannelPerCommitmentPointInput.py b/lightspark/objects/UpdateChannelPerCommitmentPointInput.py index 182eeea..3903dda 100644 --- a/lightspark/objects/UpdateChannelPerCommitmentPointInput.py +++ b/lightspark/objects/UpdateChannelPerCommitmentPointInput.py @@ -12,6 +12,13 @@ class UpdateChannelPerCommitmentPointInput: per_commitment_point_index: int + def to_json(self) -> Mapping[str, Any]: + return { + "update_channel_per_commitment_point_input_channel_id": self.channel_id, + "update_channel_per_commitment_point_input_per_commitment_point": self.per_commitment_point, + "update_channel_per_commitment_point_input_per_commitment_point_index": self.per_commitment_point_index, + } + def from_json(obj: Mapping[str, Any]) -> UpdateChannelPerCommitmentPointInput: return UpdateChannelPerCommitmentPointInput( diff --git a/lightspark/objects/UpdateChannelPerCommitmentPointOutput.py b/lightspark/objects/UpdateChannelPerCommitmentPointOutput.py index 3a1416f..4836a06 100644 --- a/lightspark/objects/UpdateChannelPerCommitmentPointOutput.py +++ b/lightspark/objects/UpdateChannelPerCommitmentPointOutput.py @@ -12,6 +12,13 @@ class UpdateChannelPerCommitmentPointOutput: channel_id: str + def to_json(self) -> Mapping[str, Any]: + return { + "update_channel_per_commitment_point_output_channel": { + "id": self.channel_id + }, + } + FRAGMENT = """ fragment UpdateChannelPerCommitmentPointOutputFragment on UpdateChannelPerCommitmentPointOutput { diff --git a/lightspark/objects/UpdateNodeSharedSecretInput.py b/lightspark/objects/UpdateNodeSharedSecretInput.py index b231253..b070987 100644 --- a/lightspark/objects/UpdateNodeSharedSecretInput.py +++ b/lightspark/objects/UpdateNodeSharedSecretInput.py @@ -10,6 +10,12 @@ class UpdateNodeSharedSecretInput: shared_secret: str + def to_json(self) -> Mapping[str, Any]: + return { + "update_node_shared_secret_input_node_id": self.node_id, + "update_node_shared_secret_input_shared_secret": self.shared_secret, + } + def from_json(obj: Mapping[str, Any]) -> UpdateNodeSharedSecretInput: return UpdateNodeSharedSecretInput( diff --git a/lightspark/objects/UpdateNodeSharedSecretOutput.py b/lightspark/objects/UpdateNodeSharedSecretOutput.py index f8115d9..86415fd 100644 --- a/lightspark/objects/UpdateNodeSharedSecretOutput.py +++ b/lightspark/objects/UpdateNodeSharedSecretOutput.py @@ -12,6 +12,11 @@ class UpdateNodeSharedSecretOutput: node_id: str + def to_json(self) -> Mapping[str, Any]: + return { + "update_node_shared_secret_output_node": {"id": self.node_id}, + } + FRAGMENT = """ fragment UpdateNodeSharedSecretOutputFragment on UpdateNodeSharedSecretOutput { diff --git a/lightspark/objects/Wallet.py b/lightspark/objects/Wallet.py index 4e92247..3ee019d 100644 --- a/lightspark/objects/Wallet.py +++ b/lightspark/objects/Wallet.py @@ -1054,6 +1054,19 @@ def get_total_amount_sent( connection = json["entity"]["total_amount_sent"] return CurrencyAmount_from_json(self.requester, connection) + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "Wallet", + "wallet_id": self.id, + "wallet_created_at": self.created_at.isoformat(), + "wallet_updated_at": self.updated_at.isoformat(), + "wallet_last_login_at": self.last_login_at.isoformat(), + "wallet_balances": self.balances.to_json() if self.balances else None, + "wallet_third_party_identifier": self.third_party_identifier, + "wallet_account": {"id": self.account_id} if self.account_id else None, + "wallet_status": self.status.value, + } + FRAGMENT = """ fragment WalletFragment on Wallet { diff --git a/lightspark/objects/WalletToPaymentRequestsConnection.py b/lightspark/objects/WalletToPaymentRequestsConnection.py index 6950bf1..3ce6f8d 100644 --- a/lightspark/objects/WalletToPaymentRequestsConnection.py +++ b/lightspark/objects/WalletToPaymentRequestsConnection.py @@ -26,6 +26,16 @@ class WalletToPaymentRequestsConnection(Connection): """The payment requests for the current page of this connection.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "WalletToPaymentRequestsConnection", + "wallet_to_payment_requests_connection_count": self.count, + "wallet_to_payment_requests_connection_page_info": self.page_info.to_json(), + "wallet_to_payment_requests_connection_entities": [ + e.to_json() for e in self.entities + ], + } + FRAGMENT = """ fragment WalletToPaymentRequestsConnectionFragment on WalletToPaymentRequestsConnection { diff --git a/lightspark/objects/WalletToTransactionsConnection.py b/lightspark/objects/WalletToTransactionsConnection.py index f07f20d..da95d27 100644 --- a/lightspark/objects/WalletToTransactionsConnection.py +++ b/lightspark/objects/WalletToTransactionsConnection.py @@ -26,6 +26,16 @@ class WalletToTransactionsConnection(Connection): """The transactions for the current page of this connection.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "WalletToTransactionsConnection", + "wallet_to_transactions_connection_count": self.count, + "wallet_to_transactions_connection_page_info": self.page_info.to_json(), + "wallet_to_transactions_connection_entities": [ + e.to_json() for e in self.entities + ], + } + FRAGMENT = """ fragment WalletToTransactionsConnectionFragment on WalletToTransactionsConnection { diff --git a/lightspark/objects/Withdrawal.py b/lightspark/objects/Withdrawal.py index 55d0d5a..efd7748 100644 --- a/lightspark/objects/Withdrawal.py +++ b/lightspark/objects/Withdrawal.py @@ -62,6 +62,24 @@ class Withdrawal(OnChainTransaction, Transaction, Entity): """The Lightspark node this withdrawal originated from.""" typename: str + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "Withdrawal", + "withdrawal_id": self.id, + "withdrawal_created_at": self.created_at.isoformat(), + "withdrawal_updated_at": self.updated_at.isoformat(), + "withdrawal_status": self.status.value, + "withdrawal_resolved_at": self.resolved_at.isoformat(), + "withdrawal_amount": self.amount.to_json(), + "withdrawal_transaction_hash": self.transaction_hash, + "withdrawal_fees": self.fees.to_json() if self.fees else None, + "withdrawal_block_hash": self.block_hash, + "withdrawal_block_height": self.block_height, + "withdrawal_destination_addresses": self.destination_addresses, + "withdrawal_num_confirmations": self.num_confirmations, + "withdrawal_origin": {"id": self.origin_id}, + } + FRAGMENT = """ fragment WithdrawalFragment on Withdrawal { diff --git a/lightspark/objects/WithdrawalRequest.py b/lightspark/objects/WithdrawalRequest.py index 1b2b48f..2006110 100644 --- a/lightspark/objects/WithdrawalRequest.py +++ b/lightspark/objects/WithdrawalRequest.py @@ -189,6 +189,25 @@ def get_channel_opening_transactions( self.requester, connection ) + def to_json(self) -> Mapping[str, Any]: + return { + "__typename": "WithdrawalRequest", + "withdrawal_request_id": self.id, + "withdrawal_request_created_at": self.created_at.isoformat(), + "withdrawal_request_updated_at": self.updated_at.isoformat(), + "withdrawal_request_amount": self.amount.to_json(), + "withdrawal_request_estimated_amount": self.estimated_amount.to_json() + if self.estimated_amount + else None, + "withdrawal_request_bitcoin_address": self.bitcoin_address, + "withdrawal_request_withdrawal_mode": self.withdrawal_mode.value, + "withdrawal_request_status": self.status.value, + "withdrawal_request_completed_at": self.completed_at.isoformat(), + "withdrawal_request_withdrawal": {"id": self.withdrawal_id} + if self.withdrawal_id + else None, + } + FRAGMENT = """ fragment WithdrawalRequestFragment on WithdrawalRequest { diff --git a/lightspark/objects/WithdrawalRequestToChannelClosingTransactionsConnection.py b/lightspark/objects/WithdrawalRequestToChannelClosingTransactionsConnection.py index e47cd57..367b7e8 100644 --- a/lightspark/objects/WithdrawalRequestToChannelClosingTransactionsConnection.py +++ b/lightspark/objects/WithdrawalRequestToChannelClosingTransactionsConnection.py @@ -24,6 +24,15 @@ class WithdrawalRequestToChannelClosingTransactionsConnection: entities: List[ChannelClosingTransaction] """The channel closing transactions for the current page of this connection.""" + def to_json(self) -> Mapping[str, Any]: + return { + "withdrawal_request_to_channel_closing_transactions_connection_page_info": self.page_info.to_json(), + "withdrawal_request_to_channel_closing_transactions_connection_count": self.count, + "withdrawal_request_to_channel_closing_transactions_connection_entities": [ + e.to_json() for e in self.entities + ], + } + FRAGMENT = """ fragment WithdrawalRequestToChannelClosingTransactionsConnectionFragment on WithdrawalRequestToChannelClosingTransactionsConnection { diff --git a/lightspark/objects/WithdrawalRequestToChannelOpeningTransactionsConnection.py b/lightspark/objects/WithdrawalRequestToChannelOpeningTransactionsConnection.py index a0207d5..8d01078 100644 --- a/lightspark/objects/WithdrawalRequestToChannelOpeningTransactionsConnection.py +++ b/lightspark/objects/WithdrawalRequestToChannelOpeningTransactionsConnection.py @@ -24,6 +24,15 @@ class WithdrawalRequestToChannelOpeningTransactionsConnection: entities: List[ChannelOpeningTransaction] """The channel opening transactions for the current page of this connection.""" + def to_json(self) -> Mapping[str, Any]: + return { + "withdrawal_request_to_channel_opening_transactions_connection_page_info": self.page_info.to_json(), + "withdrawal_request_to_channel_opening_transactions_connection_count": self.count, + "withdrawal_request_to_channel_opening_transactions_connection_entities": [ + e.to_json() for e in self.entities + ], + } + FRAGMENT = """ fragment WithdrawalRequestToChannelOpeningTransactionsConnectionFragment on WithdrawalRequestToChannelOpeningTransactionsConnection { From 26eb908b7409fa9e445666f826ab33f48caeecff Mon Sep 17 00:00:00 2001 From: Jeremy Klein Date: Thu, 9 Nov 2023 10:53:50 -0800 Subject: [PATCH 2/2] Fix tests and null checks --- lightspark/__tests__/test_serialization.py | 10 ++++------ lightspark/objects/ApiToken.py | 2 +- lightspark/objects/Channel.py | 2 +- lightspark/objects/ChannelClosingTransaction.py | 4 +++- lightspark/objects/ChannelOpeningTransaction.py | 4 +++- lightspark/objects/CreateApiTokenInput.py | 4 +--- lightspark/objects/CreateInvoiceInput.py | 4 +++- lightspark/objects/CreateTestModeInvoiceInput.py | 4 +++- lightspark/objects/Deposit.py | 4 +++- lightspark/objects/IncomingPayment.py | 4 +++- lightspark/objects/IncomingPaymentAttempt.py | 4 +++- lightspark/objects/LightningTransaction.py | 4 +++- lightspark/objects/LightsparkNode.py | 2 +- lightspark/objects/LightsparkNodeWithOSK.py | 4 +++- lightspark/objects/LightsparkNodeWithRemoteSigning.py | 4 +++- lightspark/objects/OnChainTransaction.py | 4 +++- lightspark/objects/OutgoingPayment.py | 8 ++++++-- lightspark/objects/OutgoingPaymentAttempt.py | 8 ++++++-- .../objects/OutgoingPaymentsForInvoiceQueryInput.py | 2 +- lightspark/objects/RoutingTransaction.py | 8 ++++++-- lightspark/objects/Transaction.py | 4 +++- lightspark/objects/TransactionFailures.py | 4 ++-- lightspark/objects/Wallet.py | 4 +++- lightspark/objects/Withdrawal.py | 4 +++- lightspark/objects/WithdrawalRequest.py | 4 +++- 25 files changed, 74 insertions(+), 36 deletions(-) diff --git a/lightspark/__tests__/test_serialization.py b/lightspark/__tests__/test_serialization.py index 8c22aa7..b77bc39 100644 --- a/lightspark/__tests__/test_serialization.py +++ b/lightspark/__tests__/test_serialization.py @@ -5,21 +5,19 @@ class TestSerialization: def test_serialize_deserialize_invoice_data(self): - serialized = '{"__typename": "InvoiceData", "invoice_data_encoded_payment_request":"lnbcrt34170n1pj5vdn4pp56jhw0672v566u4rvl333v8hwwuvavvu9gx4a2mqag4pkrvm0hwkqhp5xaz278y6cejcvpqnndl4wfq3slgthjduwlfksg778aevn23v2pdscqzpgxqyz5vqsp5ee5jezfvjqvvz7hfwta3ekk8hs6dq36szkgp40qh7twa8upquxlq9qyyssqjg2slc95falxf2t67y0wu2w43qwfcvfflwl8tn4ppqw9tumwqxk36qkfct9p2w8c3yy2ld7c6nacy4ssv2gl6qyqfpmhl4jmarnjf8cpvjlxek","invoice_data_bitcoin_network":"REGTEST","invoice_data_payment_hash":"d4aee7ebca6535ae546cfc63161eee7719d6338541abd56c1d454361b36fbbac","invoice_data_amount":{"currency_amount_original_value":3417,"currency_amount_original_unit":"SATOSHI","currency_amount_preferred_currency_unit":"USD","currency_amount_preferred_currency_value_rounded":118,"currency_amount_preferred_currency_value_approx":118.89352818371607},"invoice_data_created_at":"2023-11-04T12:17:57Z","invoice_data_expires_at":"2023-11-05T12:17:57Z","invoice_data_memo":null,"invoice_data_destination":{"graph_node_id":"GraphNode:0189a572-6dba-cf00-0000-ac0908d34ea6","graph_node_created_at":"2023-07-30T06:18:07.162759Z","graph_node_updated_at":"2023-11-04T12:01:04.015414Z","graph_node_alias":"ls_test_vSViIQitob_SE","graph_node_bitcoin_network":"REGTEST","graph_node_color":"#3399ff","graph_node_conductivity":null,"graph_node_display_name":"ls_test_vSViIQitob_SE","graph_node_public_key":"02253935a5703a6f0429081e08d2defce0faa15f4d75305302284751d53a4e0608", "__typename":"GraphNode"}}' + serialized = '{"__typename": "InvoiceData", "invoice_data_encoded_payment_request":"lnbcrt34170n1pj5vdn4pp56jhw0672v566u4rvl333v8hwwuvavvu9gx4a2mqag4pkrvm0hwkqhp5xaz278y6cejcvpqnndl4wfq3slgthjduwlfksg778aevn23v2pdscqzpgxqyz5vqsp5ee5jezfvjqvvz7hfwta3ekk8hs6dq36szkgp40qh7twa8upquxlq9qyyssqjg2slc95falxf2t67y0wu2w43qwfcvfflwl8tn4ppqw9tumwqxk36qkfct9p2w8c3yy2ld7c6nacy4ssv2gl6qyqfpmhl4jmarnjf8cpvjlxek","invoice_data_bitcoin_network":"REGTEST","invoice_data_payment_hash":"d4aee7ebca6535ae546cfc63161eee7719d6338541abd56c1d454361b36fbbac","invoice_data_amount":{"currency_amount_original_value":3417,"currency_amount_original_unit":"SATOSHI","currency_amount_preferred_currency_unit":"USD","currency_amount_preferred_currency_value_rounded":118,"currency_amount_preferred_currency_value_approx":118.89352818371607},"invoice_data_created_at":"2023-11-04T12:17:57+00:00","invoice_data_expires_at":"2023-11-05T12:17:57+00:00","invoice_data_memo":null,"invoice_data_destination":{"graph_node_id":"GraphNode:0189a572-6dba-cf00-0000-ac0908d34ea6","graph_node_created_at":"2023-07-30T06:18:07.162759+00:00","graph_node_updated_at":"2023-11-04T12:01:04.015414+00:00","graph_node_alias":"ls_test_vSViIQitob_SE","graph_node_bitcoin_network":"REGTEST","graph_node_color":"#3399ff","graph_node_conductivity":null,"graph_node_display_name":"ls_test_vSViIQitob_SE","graph_node_public_key":"02253935a5703a6f0429081e08d2defce0faa15f4d75305302284751d53a4e0608", "__typename":"GraphNode"}}' deserialized = InvoiceData_from_json(None, json.loads(serialized)) reserialized = deserialized.to_json() - # TODO(Jeremy): Fix this assertion by making iso format consistent w.r.t. trailing Z. - # assert reserialized == json.loads(serialized) + assert reserialized == json.loads(serialized) deserialized_again = InvoiceData_from_json(None, reserialized) assert deserialized_again == deserialized def test_serialize_deserialize_graph_node(self): - serialized = '{"graph_node_id":"GraphNode:0189a572-6dba-cf00-0000-ac0908d34ea6","graph_node_created_at":"2023-07-30T06:18:07.162759Z","graph_node_updated_at":"2023-11-04T12:01:04.015414Z","graph_node_alias":"ls_test_vSViIQitob_SE","graph_node_bitcoin_network":"REGTEST","graph_node_color":"#3399ff","graph_node_conductivity":null,"graph_node_display_name":"ls_test_vSViIQitob_SE","graph_node_public_key":"02253935a5703a6f0429081e08d2defce0faa15f4d75305302284751d53a4e0608", "__typename":"GraphNode"}' + serialized = '{"graph_node_id":"GraphNode:0189a572-6dba-cf00-0000-ac0908d34ea6","graph_node_created_at":"2023-07-30T06:18:07.162759+00:00","graph_node_updated_at":"2023-11-04T12:01:04.015414+00:00","graph_node_alias":"ls_test_vSViIQitob_SE","graph_node_bitcoin_network":"REGTEST","graph_node_color":"#3399ff","graph_node_conductivity":null,"graph_node_display_name":"ls_test_vSViIQitob_SE","graph_node_public_key":"02253935a5703a6f0429081e08d2defce0faa15f4d75305302284751d53a4e0608", "__typename":"GraphNode"}' deserialized = Node_from_json(None, json.loads(serialized)) reserialized = deserialized.to_json() - # TODO(Jeremy): Fix this assertion by making iso format consistent w.r.t. trailing Z. - # assert reserialized == json.loads(serialized) + assert reserialized == json.loads(serialized) deserialized_again = Node_from_json(None, reserialized) assert deserialized_again == deserialized diff --git a/lightspark/objects/ApiToken.py b/lightspark/objects/ApiToken.py index 0f3298f..4071b81 100644 --- a/lightspark/objects/ApiToken.py +++ b/lightspark/objects/ApiToken.py @@ -44,7 +44,7 @@ def to_json(self) -> Mapping[str, Any]: "api_token_updated_at": self.updated_at.isoformat(), "api_token_client_id": self.client_id, "api_token_name": self.name, - "api_token_permissions": [e.to_json() for e in self.permissions], + "api_token_permissions": [e.value for e in self.permissions], } diff --git a/lightspark/objects/Channel.py b/lightspark/objects/Channel.py index a57cde0..ecf0adc 100644 --- a/lightspark/objects/Channel.py +++ b/lightspark/objects/Channel.py @@ -187,7 +187,7 @@ def to_json(self) -> Mapping[str, Any]: "channel_total_balance": self.total_balance.to_json() if self.total_balance else None, - "channel_status": self.status.value, + "channel_status": self.status.value if self.status else None, "channel_estimated_force_closure_wait_minutes": self.estimated_force_closure_wait_minutes, "channel_commit_fee": self.commit_fee.to_json() if self.commit_fee diff --git a/lightspark/objects/ChannelClosingTransaction.py b/lightspark/objects/ChannelClosingTransaction.py index 138a0b1..cc141a9 100644 --- a/lightspark/objects/ChannelClosingTransaction.py +++ b/lightspark/objects/ChannelClosingTransaction.py @@ -69,7 +69,9 @@ def to_json(self) -> Mapping[str, Any]: "channel_closing_transaction_created_at": self.created_at.isoformat(), "channel_closing_transaction_updated_at": self.updated_at.isoformat(), "channel_closing_transaction_status": self.status.value, - "channel_closing_transaction_resolved_at": self.resolved_at.isoformat(), + "channel_closing_transaction_resolved_at": self.resolved_at.isoformat() + if self.resolved_at + else None, "channel_closing_transaction_amount": self.amount.to_json(), "channel_closing_transaction_transaction_hash": self.transaction_hash, "channel_closing_transaction_fees": self.fees.to_json() diff --git a/lightspark/objects/ChannelOpeningTransaction.py b/lightspark/objects/ChannelOpeningTransaction.py index 9612a1e..8ce5cb5 100644 --- a/lightspark/objects/ChannelOpeningTransaction.py +++ b/lightspark/objects/ChannelOpeningTransaction.py @@ -69,7 +69,9 @@ def to_json(self) -> Mapping[str, Any]: "channel_opening_transaction_created_at": self.created_at.isoformat(), "channel_opening_transaction_updated_at": self.updated_at.isoformat(), "channel_opening_transaction_status": self.status.value, - "channel_opening_transaction_resolved_at": self.resolved_at.isoformat(), + "channel_opening_transaction_resolved_at": self.resolved_at.isoformat() + if self.resolved_at + else None, "channel_opening_transaction_amount": self.amount.to_json(), "channel_opening_transaction_transaction_hash": self.transaction_hash, "channel_opening_transaction_fees": self.fees.to_json() diff --git a/lightspark/objects/CreateApiTokenInput.py b/lightspark/objects/CreateApiTokenInput.py index 66d89b7..e8d2603 100644 --- a/lightspark/objects/CreateApiTokenInput.py +++ b/lightspark/objects/CreateApiTokenInput.py @@ -19,9 +19,7 @@ class CreateApiTokenInput: def to_json(self) -> Mapping[str, Any]: return { "create_api_token_input_name": self.name, - "create_api_token_input_permissions": [ - e.to_json() for e in self.permissions - ], + "create_api_token_input_permissions": [e.value for e in self.permissions], } diff --git a/lightspark/objects/CreateInvoiceInput.py b/lightspark/objects/CreateInvoiceInput.py index 229e2cf..00a7e36 100644 --- a/lightspark/objects/CreateInvoiceInput.py +++ b/lightspark/objects/CreateInvoiceInput.py @@ -29,7 +29,9 @@ def to_json(self) -> Mapping[str, Any]: "create_invoice_input_node_id": self.node_id, "create_invoice_input_amount_msats": self.amount_msats, "create_invoice_input_memo": self.memo, - "create_invoice_input_invoice_type": self.invoice_type.value, + "create_invoice_input_invoice_type": self.invoice_type.value + if self.invoice_type + else None, "create_invoice_input_expiry_secs": self.expiry_secs, } diff --git a/lightspark/objects/CreateTestModeInvoiceInput.py b/lightspark/objects/CreateTestModeInvoiceInput.py index 3fe5323..546669d 100644 --- a/lightspark/objects/CreateTestModeInvoiceInput.py +++ b/lightspark/objects/CreateTestModeInvoiceInput.py @@ -24,7 +24,9 @@ def to_json(self) -> Mapping[str, Any]: "create_test_mode_invoice_input_local_node_id": self.local_node_id, "create_test_mode_invoice_input_amount_msats": self.amount_msats, "create_test_mode_invoice_input_memo": self.memo, - "create_test_mode_invoice_input_invoice_type": self.invoice_type.value, + "create_test_mode_invoice_input_invoice_type": self.invoice_type.value + if self.invoice_type + else None, } diff --git a/lightspark/objects/Deposit.py b/lightspark/objects/Deposit.py index 062e8e4..1df9426 100644 --- a/lightspark/objects/Deposit.py +++ b/lightspark/objects/Deposit.py @@ -69,7 +69,9 @@ def to_json(self) -> Mapping[str, Any]: "deposit_created_at": self.created_at.isoformat(), "deposit_updated_at": self.updated_at.isoformat(), "deposit_status": self.status.value, - "deposit_resolved_at": self.resolved_at.isoformat(), + "deposit_resolved_at": self.resolved_at.isoformat() + if self.resolved_at + else None, "deposit_amount": self.amount.to_json(), "deposit_transaction_hash": self.transaction_hash, "deposit_fees": self.fees.to_json() if self.fees else None, diff --git a/lightspark/objects/IncomingPayment.py b/lightspark/objects/IncomingPayment.py index 925e6ad..dbca905 100644 --- a/lightspark/objects/IncomingPayment.py +++ b/lightspark/objects/IncomingPayment.py @@ -122,7 +122,9 @@ def to_json(self) -> Mapping[str, Any]: "incoming_payment_created_at": self.created_at.isoformat(), "incoming_payment_updated_at": self.updated_at.isoformat(), "incoming_payment_status": self.status.value, - "incoming_payment_resolved_at": self.resolved_at.isoformat(), + "incoming_payment_resolved_at": self.resolved_at.isoformat() + if self.resolved_at + else None, "incoming_payment_amount": self.amount.to_json(), "incoming_payment_transaction_hash": self.transaction_hash, "incoming_payment_destination": {"id": self.destination_id}, diff --git a/lightspark/objects/IncomingPaymentAttempt.py b/lightspark/objects/IncomingPaymentAttempt.py index e7440f8..650aa0b 100644 --- a/lightspark/objects/IncomingPaymentAttempt.py +++ b/lightspark/objects/IncomingPaymentAttempt.py @@ -49,7 +49,9 @@ def to_json(self) -> Mapping[str, Any]: "incoming_payment_attempt_created_at": self.created_at.isoformat(), "incoming_payment_attempt_updated_at": self.updated_at.isoformat(), "incoming_payment_attempt_status": self.status.value, - "incoming_payment_attempt_resolved_at": self.resolved_at.isoformat(), + "incoming_payment_attempt_resolved_at": self.resolved_at.isoformat() + if self.resolved_at + else None, "incoming_payment_attempt_amount": self.amount.to_json(), "incoming_payment_attempt_channel": {"id": self.channel_id}, } diff --git a/lightspark/objects/LightningTransaction.py b/lightspark/objects/LightningTransaction.py index fa6947c..b0c26cb 100644 --- a/lightspark/objects/LightningTransaction.py +++ b/lightspark/objects/LightningTransaction.py @@ -58,7 +58,9 @@ def to_json(self) -> Mapping[str, Any]: "lightning_transaction_created_at": self.created_at.isoformat(), "lightning_transaction_updated_at": self.updated_at.isoformat(), "lightning_transaction_status": self.status.value, - "lightning_transaction_resolved_at": self.resolved_at.isoformat(), + "lightning_transaction_resolved_at": self.resolved_at.isoformat() + if self.resolved_at + else None, "lightning_transaction_amount": self.amount.to_json(), "lightning_transaction_transaction_hash": self.transaction_hash, } diff --git a/lightspark/objects/LightsparkNode.py b/lightspark/objects/LightsparkNode.py index c1db178..d726393 100644 --- a/lightspark/objects/LightsparkNode.py +++ b/lightspark/objects/LightsparkNode.py @@ -261,7 +261,7 @@ def to_json(self) -> Mapping[str, Any]: "lightspark_node_display_name": self.display_name, "lightspark_node_public_key": self.public_key, "lightspark_node_owner": {"id": self.owner_id}, - "lightspark_node_status": self.status.value, + "lightspark_node_status": self.status.value if self.status else None, "lightspark_node_total_balance": self.total_balance.to_json() if self.total_balance else None, diff --git a/lightspark/objects/LightsparkNodeWithOSK.py b/lightspark/objects/LightsparkNodeWithOSK.py index f688c22..4f1b366 100644 --- a/lightspark/objects/LightsparkNodeWithOSK.py +++ b/lightspark/objects/LightsparkNodeWithOSK.py @@ -265,7 +265,9 @@ def to_json(self) -> Mapping[str, Any]: "lightspark_node_with_o_s_k_display_name": self.display_name, "lightspark_node_with_o_s_k_public_key": self.public_key, "lightspark_node_with_o_s_k_owner": {"id": self.owner_id}, - "lightspark_node_with_o_s_k_status": self.status.value, + "lightspark_node_with_o_s_k_status": self.status.value + if self.status + else None, "lightspark_node_with_o_s_k_total_balance": self.total_balance.to_json() if self.total_balance else None, diff --git a/lightspark/objects/LightsparkNodeWithRemoteSigning.py b/lightspark/objects/LightsparkNodeWithRemoteSigning.py index b53d801..493de76 100644 --- a/lightspark/objects/LightsparkNodeWithRemoteSigning.py +++ b/lightspark/objects/LightsparkNodeWithRemoteSigning.py @@ -260,7 +260,9 @@ def to_json(self) -> Mapping[str, Any]: "lightspark_node_with_remote_signing_display_name": self.display_name, "lightspark_node_with_remote_signing_public_key": self.public_key, "lightspark_node_with_remote_signing_owner": {"id": self.owner_id}, - "lightspark_node_with_remote_signing_status": self.status.value, + "lightspark_node_with_remote_signing_status": self.status.value + if self.status + else None, "lightspark_node_with_remote_signing_total_balance": self.total_balance.to_json() if self.total_balance else None, diff --git a/lightspark/objects/OnChainTransaction.py b/lightspark/objects/OnChainTransaction.py index 5629cff..b302f1a 100644 --- a/lightspark/objects/OnChainTransaction.py +++ b/lightspark/objects/OnChainTransaction.py @@ -66,7 +66,9 @@ def to_json(self) -> Mapping[str, Any]: "on_chain_transaction_created_at": self.created_at.isoformat(), "on_chain_transaction_updated_at": self.updated_at.isoformat(), "on_chain_transaction_status": self.status.value, - "on_chain_transaction_resolved_at": self.resolved_at.isoformat(), + "on_chain_transaction_resolved_at": self.resolved_at.isoformat() + if self.resolved_at + else None, "on_chain_transaction_amount": self.amount.to_json(), "on_chain_transaction_transaction_hash": self.transaction_hash, "on_chain_transaction_fees": self.fees.to_json() if self.fees else None, diff --git a/lightspark/objects/OutgoingPayment.py b/lightspark/objects/OutgoingPayment.py index 67176e4..9062be7 100644 --- a/lightspark/objects/OutgoingPayment.py +++ b/lightspark/objects/OutgoingPayment.py @@ -191,7 +191,9 @@ def to_json(self) -> Mapping[str, Any]: "outgoing_payment_created_at": self.created_at.isoformat(), "outgoing_payment_updated_at": self.updated_at.isoformat(), "outgoing_payment_status": self.status.value, - "outgoing_payment_resolved_at": self.resolved_at.isoformat(), + "outgoing_payment_resolved_at": self.resolved_at.isoformat() + if self.resolved_at + else None, "outgoing_payment_amount": self.amount.to_json(), "outgoing_payment_transaction_hash": self.transaction_hash, "outgoing_payment_origin": {"id": self.origin_id}, @@ -202,7 +204,9 @@ def to_json(self) -> Mapping[str, Any]: "outgoing_payment_payment_request_data": self.payment_request_data.to_json() if self.payment_request_data else None, - "outgoing_payment_failure_reason": self.failure_reason.value, + "outgoing_payment_failure_reason": self.failure_reason.value + if self.failure_reason + else None, "outgoing_payment_failure_message": self.failure_message.to_json() if self.failure_message else None, diff --git a/lightspark/objects/OutgoingPaymentAttempt.py b/lightspark/objects/OutgoingPaymentAttempt.py index 0ee7e02..18e359d 100644 --- a/lightspark/objects/OutgoingPaymentAttempt.py +++ b/lightspark/objects/OutgoingPaymentAttempt.py @@ -129,9 +129,13 @@ def to_json(self) -> Mapping[str, Any]: "outgoing_payment_attempt_created_at": self.created_at.isoformat(), "outgoing_payment_attempt_updated_at": self.updated_at.isoformat(), "outgoing_payment_attempt_status": self.status.value, - "outgoing_payment_attempt_failure_code": self.failure_code.value, + "outgoing_payment_attempt_failure_code": self.failure_code.value + if self.failure_code + else None, "outgoing_payment_attempt_failure_source_index": self.failure_source_index, - "outgoing_payment_attempt_resolved_at": self.resolved_at.isoformat(), + "outgoing_payment_attempt_resolved_at": self.resolved_at.isoformat() + if self.resolved_at + else None, "outgoing_payment_attempt_amount": self.amount.to_json() if self.amount else None, diff --git a/lightspark/objects/OutgoingPaymentsForInvoiceQueryInput.py b/lightspark/objects/OutgoingPaymentsForInvoiceQueryInput.py index ca69637..98e8749 100644 --- a/lightspark/objects/OutgoingPaymentsForInvoiceQueryInput.py +++ b/lightspark/objects/OutgoingPaymentsForInvoiceQueryInput.py @@ -20,7 +20,7 @@ def to_json(self) -> Mapping[str, Any]: return { "outgoing_payments_for_invoice_query_input_encoded_invoice": self.encoded_invoice, "outgoing_payments_for_invoice_query_input_statuses": [ - e.to_json() for e in self.statuses + e.value for e in self.statuses ] if self.statuses else None, diff --git a/lightspark/objects/RoutingTransaction.py b/lightspark/objects/RoutingTransaction.py index 984ad13..f6dd390 100644 --- a/lightspark/objects/RoutingTransaction.py +++ b/lightspark/objects/RoutingTransaction.py @@ -72,7 +72,9 @@ def to_json(self) -> Mapping[str, Any]: "routing_transaction_created_at": self.created_at.isoformat(), "routing_transaction_updated_at": self.updated_at.isoformat(), "routing_transaction_status": self.status.value, - "routing_transaction_resolved_at": self.resolved_at.isoformat(), + "routing_transaction_resolved_at": self.resolved_at.isoformat() + if self.resolved_at + else None, "routing_transaction_amount": self.amount.to_json(), "routing_transaction_transaction_hash": self.transaction_hash, "routing_transaction_incoming_channel": {"id": self.incoming_channel_id} @@ -85,7 +87,9 @@ def to_json(self) -> Mapping[str, Any]: "routing_transaction_failure_message": self.failure_message.to_json() if self.failure_message else None, - "routing_transaction_failure_reason": self.failure_reason.value, + "routing_transaction_failure_reason": self.failure_reason.value + if self.failure_reason + else None, } diff --git a/lightspark/objects/Transaction.py b/lightspark/objects/Transaction.py index 4a9c6ac..c112ac9 100644 --- a/lightspark/objects/Transaction.py +++ b/lightspark/objects/Transaction.py @@ -57,7 +57,9 @@ def to_json(self) -> Mapping[str, Any]: "transaction_created_at": self.created_at.isoformat(), "transaction_updated_at": self.updated_at.isoformat(), "transaction_status": self.status.value, - "transaction_resolved_at": self.resolved_at.isoformat(), + "transaction_resolved_at": self.resolved_at.isoformat() + if self.resolved_at + else None, "transaction_amount": self.amount.to_json(), "transaction_transaction_hash": self.transaction_hash, } diff --git a/lightspark/objects/TransactionFailures.py b/lightspark/objects/TransactionFailures.py index 852c588..48b53e9 100644 --- a/lightspark/objects/TransactionFailures.py +++ b/lightspark/objects/TransactionFailures.py @@ -20,12 +20,12 @@ class TransactionFailures: def to_json(self) -> Mapping[str, Any]: return { "transaction_failures_payment_failures": [ - e.to_json() for e in self.payment_failures + e.value for e in self.payment_failures ] if self.payment_failures else None, "transaction_failures_routing_transaction_failures": [ - e.to_json() for e in self.routing_transaction_failures + e.value for e in self.routing_transaction_failures ] if self.routing_transaction_failures else None, diff --git a/lightspark/objects/Wallet.py b/lightspark/objects/Wallet.py index 3ee019d..a87319a 100644 --- a/lightspark/objects/Wallet.py +++ b/lightspark/objects/Wallet.py @@ -1060,7 +1060,9 @@ def to_json(self) -> Mapping[str, Any]: "wallet_id": self.id, "wallet_created_at": self.created_at.isoformat(), "wallet_updated_at": self.updated_at.isoformat(), - "wallet_last_login_at": self.last_login_at.isoformat(), + "wallet_last_login_at": self.last_login_at.isoformat() + if self.last_login_at + else None, "wallet_balances": self.balances.to_json() if self.balances else None, "wallet_third_party_identifier": self.third_party_identifier, "wallet_account": {"id": self.account_id} if self.account_id else None, diff --git a/lightspark/objects/Withdrawal.py b/lightspark/objects/Withdrawal.py index efd7748..f783a26 100644 --- a/lightspark/objects/Withdrawal.py +++ b/lightspark/objects/Withdrawal.py @@ -69,7 +69,9 @@ def to_json(self) -> Mapping[str, Any]: "withdrawal_created_at": self.created_at.isoformat(), "withdrawal_updated_at": self.updated_at.isoformat(), "withdrawal_status": self.status.value, - "withdrawal_resolved_at": self.resolved_at.isoformat(), + "withdrawal_resolved_at": self.resolved_at.isoformat() + if self.resolved_at + else None, "withdrawal_amount": self.amount.to_json(), "withdrawal_transaction_hash": self.transaction_hash, "withdrawal_fees": self.fees.to_json() if self.fees else None, diff --git a/lightspark/objects/WithdrawalRequest.py b/lightspark/objects/WithdrawalRequest.py index 2006110..07b12b0 100644 --- a/lightspark/objects/WithdrawalRequest.py +++ b/lightspark/objects/WithdrawalRequest.py @@ -202,7 +202,9 @@ def to_json(self) -> Mapping[str, Any]: "withdrawal_request_bitcoin_address": self.bitcoin_address, "withdrawal_request_withdrawal_mode": self.withdrawal_mode.value, "withdrawal_request_status": self.status.value, - "withdrawal_request_completed_at": self.completed_at.isoformat(), + "withdrawal_request_completed_at": self.completed_at.isoformat() + if self.completed_at + else None, "withdrawal_request_withdrawal": {"id": self.withdrawal_id} if self.withdrawal_id else None,