Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add withdrawalRequests info for wallets and accounts. #14

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lightspark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
AccountToTransactionsConnection,
)
from lightspark.objects.AccountToWalletsConnection import AccountToWalletsConnection
from lightspark.objects.AccountToWithdrawalRequestsConnection import (
AccountToWithdrawalRequestsConnection,
)
from lightspark.objects.ApiToken import ApiToken
from lightspark.objects.Balances import Balances
from lightspark.objects.BitcoinNetwork import BitcoinNetwork
Expand Down Expand Up @@ -192,6 +195,9 @@
from lightspark.objects.WalletToTransactionsConnection import (
WalletToTransactionsConnection,
)
from lightspark.objects.WalletToWithdrawalRequestsConnection import (
WalletToWithdrawalRequestsConnection,
)
from lightspark.objects.WebhookEventType import WebhookEventType
from lightspark.objects.Withdrawal import Withdrawal
from lightspark.objects.WithdrawalMode import WithdrawalMode
Expand Down
96 changes: 96 additions & 0 deletions lightspark/objects/Account.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
from .AccountToWalletsConnection import (
from_json as AccountToWalletsConnection_from_json,
)
from .AccountToWithdrawalRequestsConnection import AccountToWithdrawalRequestsConnection
from .AccountToWithdrawalRequestsConnection import (
from_json as AccountToWithdrawalRequestsConnection_from_json,
)
from .BitcoinNetwork import BitcoinNetwork
from .BlockchainBalance import BlockchainBalance
from .BlockchainBalance import from_json as BlockchainBalance_from_json
Expand All @@ -38,6 +42,7 @@
from .TransactionFailures import TransactionFailures
from .TransactionStatus import TransactionStatus
from .TransactionType import TransactionType
from .WithdrawalRequestStatus import WithdrawalRequestStatus


@dataclass
Expand Down Expand Up @@ -1687,6 +1692,97 @@ def get_payment_requests(
connection = json["entity"]["payment_requests"]
return AccountToPaymentRequestsConnection_from_json(self.requester, connection)

def get_withdrawal_requests(
self,
first: Optional[int] = None,
after: Optional[str] = None,
bitcoin_networks: Optional[List[BitcoinNetwork]] = None,
statuses: Optional[List[WithdrawalRequestStatus]] = None,
node_ids: Optional[List[str]] = None,
after_date: Optional[datetime] = None,
before_date: Optional[datetime] = None,
) -> AccountToWithdrawalRequestsConnection:
json = self.requester.execute_graphql(
"""
query FetchAccountToWithdrawalRequestsConnection($entity_id: ID!, $first: Int, $after: String, $bitcoin_networks: [BitcoinNetwork!], $statuses: [WithdrawalRequestStatus!], $node_ids: [ID!], $after_date: DateTime, $before_date: DateTime) {
entity(id: $entity_id) {
... on Account {
withdrawal_requests(, first: $first, after: $after, bitcoin_networks: $bitcoin_networks, statuses: $statuses, node_ids: $node_ids, after_date: $after_date, before_date: $before_date) {
__typename
account_to_withdrawal_requests_connection_count: count
account_to_withdrawal_requests_connection_page_info: page_info {
__typename
page_info_has_next_page: has_next_page
page_info_has_previous_page: has_previous_page
page_info_start_cursor: start_cursor
page_info_end_cursor: end_cursor
}
account_to_withdrawal_requests_connection_entities: entities {
__typename
withdrawal_request_id: id
withdrawal_request_created_at: created_at
withdrawal_request_updated_at: updated_at
withdrawal_request_requested_amount: requested_amount {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
withdrawal_request_amount: amount {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
withdrawal_request_estimated_amount: estimated_amount {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
withdrawal_request_amount_withdrawn: amount_withdrawn {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
withdrawal_request_bitcoin_address: bitcoin_address
withdrawal_request_withdrawal_mode: withdrawal_mode
withdrawal_request_status: status
withdrawal_request_completed_at: completed_at
withdrawal_request_withdrawal: withdrawal {
id
}
}
}
}
}
}
""",
{
"entity_id": self.id,
"first": first,
"after": after,
"bitcoin_networks": bitcoin_networks,
"statuses": statuses,
"node_ids": node_ids,
"after_date": after_date,
"before_date": before_date,
},
)
connection = json["entity"]["withdrawal_requests"]
return AccountToWithdrawalRequestsConnection_from_json(
self.requester, connection
)

def get_wallets(
self,
first: Optional[int] = None,
Expand Down
77 changes: 77 additions & 0 deletions lightspark/objects/AccountToWithdrawalRequestsConnection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved

from dataclasses import dataclass
from typing import Any, List, Mapping

from lightspark.requests.requester import Requester

from .Connection import Connection
from .PageInfo import PageInfo
from .PageInfo import from_json as PageInfo_from_json
from .WithdrawalRequest import WithdrawalRequest
from .WithdrawalRequest import from_json as WithdrawalRequest_from_json


@dataclass
class AccountToWithdrawalRequestsConnection(Connection):
"""A connection between an account and its past and present withdrawal requests."""

requester: Requester

count: int
"""The total count of objects in this connection, using the current filters. It is different from the number of objects returned in the current page (in the `entities` field)."""

page_info: PageInfo
"""An object that holds pagination information about the objects in this connection."""

entities: List[WithdrawalRequest]
"""The withdrawal requests for the current page of this connection."""
typename: str

def to_json(self) -> Mapping[str, Any]:
return {
"__typename": "AccountToWithdrawalRequestsConnection",
"account_to_withdrawal_requests_connection_count": self.count,
"account_to_withdrawal_requests_connection_page_info": self.page_info.to_json(),
"account_to_withdrawal_requests_connection_entities": [
e.to_json() for e in self.entities
],
}


FRAGMENT = """
fragment AccountToWithdrawalRequestsConnectionFragment on AccountToWithdrawalRequestsConnection {
__typename
account_to_withdrawal_requests_connection_count: count
account_to_withdrawal_requests_connection_page_info: page_info {
__typename
page_info_has_next_page: has_next_page
page_info_has_previous_page: has_previous_page
page_info_start_cursor: start_cursor
page_info_end_cursor: end_cursor
}
account_to_withdrawal_requests_connection_entities: entities {
id
}
}
"""


def from_json(
requester: Requester, obj: Mapping[str, Any]
) -> AccountToWithdrawalRequestsConnection:
return AccountToWithdrawalRequestsConnection(
requester=requester,
typename="AccountToWithdrawalRequestsConnection",
count=obj["account_to_withdrawal_requests_connection_count"],
page_info=PageInfo_from_json(
requester, obj["account_to_withdrawal_requests_connection_page_info"]
),
entities=list(
map(
# pylint: disable=unnecessary-lambda
lambda e: WithdrawalRequest_from_json(requester, e),
obj["account_to_withdrawal_requests_connection_entities"],
)
),
)
28 changes: 28 additions & 0 deletions lightspark/objects/Connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ class Connection:
id
}
}
... on AccountToWithdrawalRequestsConnection {
__typename
account_to_withdrawal_requests_connection_count: count
account_to_withdrawal_requests_connection_page_info: page_info {
__typename
page_info_has_next_page: has_next_page
page_info_has_previous_page: has_previous_page
page_info_start_cursor: start_cursor
page_info_end_cursor: end_cursor
}
account_to_withdrawal_requests_connection_entities: entities {
id
}
}
... on IncomingPaymentToAttemptsConnection {
__typename
incoming_payment_to_attempts_connection_count: count
Expand Down Expand Up @@ -200,5 +214,19 @@ class Connection:
id
}
}
... on WalletToWithdrawalRequestsConnection {
__typename
wallet_to_withdrawal_requests_connection_count: count
wallet_to_withdrawal_requests_connection_page_info: page_info {
__typename
page_info_has_next_page: has_next_page
page_info_has_previous_page: has_previous_page
page_info_start_cursor: start_cursor
page_info_end_cursor: end_cursor
}
wallet_to_withdrawal_requests_connection_entities: entities {
id
}
}
}
"""
16 changes: 16 additions & 0 deletions lightspark/objects/Entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,14 @@ class Entity:
withdrawal_request_id: id
withdrawal_request_created_at: created_at
withdrawal_request_updated_at: updated_at
withdrawal_request_requested_amount: requested_amount {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
withdrawal_request_amount: amount {
__typename
currency_amount_original_value: original_value
Expand All @@ -1471,6 +1479,14 @@ class Entity:
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
withdrawal_request_amount_withdrawn: amount_withdrawn {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
withdrawal_request_bitcoin_address: bitcoin_address
withdrawal_request_withdrawal_mode: withdrawal_mode
withdrawal_request_status: status
Expand Down
92 changes: 92 additions & 0 deletions lightspark/objects/Wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
from .WalletToTransactionsConnection import (
from_json as WalletToTransactionsConnection_from_json,
)
from .WalletToWithdrawalRequestsConnection import WalletToWithdrawalRequestsConnection
from .WalletToWithdrawalRequestsConnection import (
from_json as WalletToWithdrawalRequestsConnection_from_json,
)
from .WithdrawalRequestStatus import WithdrawalRequestStatus


@dataclass
Expand Down Expand Up @@ -1023,6 +1028,93 @@ def get_total_amount_received(
connection = json["entity"]["total_amount_received"]
return CurrencyAmount_from_json(self.requester, connection)

def get_withdrawal_requests(
self,
first: Optional[int] = None,
after: Optional[str] = None,
statuses: Optional[List[WithdrawalRequestStatus]] = None,
created_after_date: Optional[datetime] = None,
created_before_date: Optional[datetime] = None,
) -> WalletToWithdrawalRequestsConnection:
json = self.requester.execute_graphql(
"""
query FetchWalletToWithdrawalRequestsConnection($entity_id: ID!, $first: Int, $after: ID, $statuses: [WithdrawalRequestStatus!], $created_after_date: DateTime, $created_before_date: DateTime) {
entity(id: $entity_id) {
... on Wallet {
withdrawal_requests(, first: $first, after: $after, statuses: $statuses, created_after_date: $created_after_date, created_before_date: $created_before_date) {
__typename
wallet_to_withdrawal_requests_connection_count: count
wallet_to_withdrawal_requests_connection_page_info: page_info {
__typename
page_info_has_next_page: has_next_page
page_info_has_previous_page: has_previous_page
page_info_start_cursor: start_cursor
page_info_end_cursor: end_cursor
}
wallet_to_withdrawal_requests_connection_entities: entities {
__typename
withdrawal_request_id: id
withdrawal_request_created_at: created_at
withdrawal_request_updated_at: updated_at
withdrawal_request_requested_amount: requested_amount {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
withdrawal_request_amount: amount {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
withdrawal_request_estimated_amount: estimated_amount {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
withdrawal_request_amount_withdrawn: amount_withdrawn {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
withdrawal_request_bitcoin_address: bitcoin_address
withdrawal_request_withdrawal_mode: withdrawal_mode
withdrawal_request_status: status
withdrawal_request_completed_at: completed_at
withdrawal_request_withdrawal: withdrawal {
id
}
}
}
}
}
}
""",
{
"entity_id": self.id,
"first": first,
"after": after,
"statuses": statuses,
"created_after_date": created_after_date,
"created_before_date": created_before_date,
},
)
connection = json["entity"]["withdrawal_requests"]
return WalletToWithdrawalRequestsConnection_from_json(
self.requester, connection
)

def get_total_amount_sent(
self,
created_after_date: Optional[datetime] = None,
Expand Down
Loading