Skip to content

Commit b8cc256

Browse files
authored
Add withdrawalRequests info for wallets and accounts. (#14)
2 parents e1ce771 + 7870144 commit b8cc256

File tree

8 files changed

+424
-0
lines changed

8 files changed

+424
-0
lines changed

lightspark/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
AccountToTransactionsConnection,
1414
)
1515
from lightspark.objects.AccountToWalletsConnection import AccountToWalletsConnection
16+
from lightspark.objects.AccountToWithdrawalRequestsConnection import (
17+
AccountToWithdrawalRequestsConnection,
18+
)
1619
from lightspark.objects.ApiToken import ApiToken
1720
from lightspark.objects.Balances import Balances
1821
from lightspark.objects.BitcoinNetwork import BitcoinNetwork
@@ -192,6 +195,9 @@
192195
from lightspark.objects.WalletToTransactionsConnection import (
193196
WalletToTransactionsConnection,
194197
)
198+
from lightspark.objects.WalletToWithdrawalRequestsConnection import (
199+
WalletToWithdrawalRequestsConnection,
200+
)
195201
from lightspark.objects.WebhookEventType import WebhookEventType
196202
from lightspark.objects.Withdrawal import Withdrawal
197203
from lightspark.objects.WithdrawalMode import WithdrawalMode

lightspark/objects/Account.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
from .AccountToWalletsConnection import (
2929
from_json as AccountToWalletsConnection_from_json,
3030
)
31+
from .AccountToWithdrawalRequestsConnection import AccountToWithdrawalRequestsConnection
32+
from .AccountToWithdrawalRequestsConnection import (
33+
from_json as AccountToWithdrawalRequestsConnection_from_json,
34+
)
3135
from .BitcoinNetwork import BitcoinNetwork
3236
from .BlockchainBalance import BlockchainBalance
3337
from .BlockchainBalance import from_json as BlockchainBalance_from_json
@@ -38,6 +42,7 @@
3842
from .TransactionFailures import TransactionFailures
3943
from .TransactionStatus import TransactionStatus
4044
from .TransactionType import TransactionType
45+
from .WithdrawalRequestStatus import WithdrawalRequestStatus
4146

4247

4348
@dataclass
@@ -1687,6 +1692,97 @@ def get_payment_requests(
16871692
connection = json["entity"]["payment_requests"]
16881693
return AccountToPaymentRequestsConnection_from_json(self.requester, connection)
16891694

1695+
def get_withdrawal_requests(
1696+
self,
1697+
first: Optional[int] = None,
1698+
after: Optional[str] = None,
1699+
bitcoin_networks: Optional[List[BitcoinNetwork]] = None,
1700+
statuses: Optional[List[WithdrawalRequestStatus]] = None,
1701+
node_ids: Optional[List[str]] = None,
1702+
after_date: Optional[datetime] = None,
1703+
before_date: Optional[datetime] = None,
1704+
) -> AccountToWithdrawalRequestsConnection:
1705+
json = self.requester.execute_graphql(
1706+
"""
1707+
query FetchAccountToWithdrawalRequestsConnection($entity_id: ID!, $first: Int, $after: String, $bitcoin_networks: [BitcoinNetwork!], $statuses: [WithdrawalRequestStatus!], $node_ids: [ID!], $after_date: DateTime, $before_date: DateTime) {
1708+
entity(id: $entity_id) {
1709+
... on Account {
1710+
withdrawal_requests(, first: $first, after: $after, bitcoin_networks: $bitcoin_networks, statuses: $statuses, node_ids: $node_ids, after_date: $after_date, before_date: $before_date) {
1711+
__typename
1712+
account_to_withdrawal_requests_connection_count: count
1713+
account_to_withdrawal_requests_connection_page_info: page_info {
1714+
__typename
1715+
page_info_has_next_page: has_next_page
1716+
page_info_has_previous_page: has_previous_page
1717+
page_info_start_cursor: start_cursor
1718+
page_info_end_cursor: end_cursor
1719+
}
1720+
account_to_withdrawal_requests_connection_entities: entities {
1721+
__typename
1722+
withdrawal_request_id: id
1723+
withdrawal_request_created_at: created_at
1724+
withdrawal_request_updated_at: updated_at
1725+
withdrawal_request_requested_amount: requested_amount {
1726+
__typename
1727+
currency_amount_original_value: original_value
1728+
currency_amount_original_unit: original_unit
1729+
currency_amount_preferred_currency_unit: preferred_currency_unit
1730+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1731+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1732+
}
1733+
withdrawal_request_amount: amount {
1734+
__typename
1735+
currency_amount_original_value: original_value
1736+
currency_amount_original_unit: original_unit
1737+
currency_amount_preferred_currency_unit: preferred_currency_unit
1738+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1739+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1740+
}
1741+
withdrawal_request_estimated_amount: estimated_amount {
1742+
__typename
1743+
currency_amount_original_value: original_value
1744+
currency_amount_original_unit: original_unit
1745+
currency_amount_preferred_currency_unit: preferred_currency_unit
1746+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1747+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1748+
}
1749+
withdrawal_request_amount_withdrawn: amount_withdrawn {
1750+
__typename
1751+
currency_amount_original_value: original_value
1752+
currency_amount_original_unit: original_unit
1753+
currency_amount_preferred_currency_unit: preferred_currency_unit
1754+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1755+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1756+
}
1757+
withdrawal_request_bitcoin_address: bitcoin_address
1758+
withdrawal_request_withdrawal_mode: withdrawal_mode
1759+
withdrawal_request_status: status
1760+
withdrawal_request_completed_at: completed_at
1761+
withdrawal_request_withdrawal: withdrawal {
1762+
id
1763+
}
1764+
}
1765+
}
1766+
}
1767+
}
1768+
}
1769+
""",
1770+
{
1771+
"entity_id": self.id,
1772+
"first": first,
1773+
"after": after,
1774+
"bitcoin_networks": bitcoin_networks,
1775+
"statuses": statuses,
1776+
"node_ids": node_ids,
1777+
"after_date": after_date,
1778+
"before_date": before_date,
1779+
},
1780+
)
1781+
connection = json["entity"]["withdrawal_requests"]
1782+
return AccountToWithdrawalRequestsConnection_from_json(
1783+
self.requester, connection
1784+
)
1785+
16901786
def get_wallets(
16911787
self,
16921788
first: Optional[int] = None,
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved
2+
3+
from dataclasses import dataclass
4+
from typing import Any, List, Mapping
5+
6+
from lightspark.requests.requester import Requester
7+
8+
from .Connection import Connection
9+
from .PageInfo import PageInfo
10+
from .PageInfo import from_json as PageInfo_from_json
11+
from .WithdrawalRequest import WithdrawalRequest
12+
from .WithdrawalRequest import from_json as WithdrawalRequest_from_json
13+
14+
15+
@dataclass
16+
class AccountToWithdrawalRequestsConnection(Connection):
17+
"""A connection between an account and its past and present withdrawal requests."""
18+
19+
requester: Requester
20+
21+
count: int
22+
"""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)."""
23+
24+
page_info: PageInfo
25+
"""An object that holds pagination information about the objects in this connection."""
26+
27+
entities: List[WithdrawalRequest]
28+
"""The withdrawal requests for the current page of this connection."""
29+
typename: str
30+
31+
def to_json(self) -> Mapping[str, Any]:
32+
return {
33+
"__typename": "AccountToWithdrawalRequestsConnection",
34+
"account_to_withdrawal_requests_connection_count": self.count,
35+
"account_to_withdrawal_requests_connection_page_info": self.page_info.to_json(),
36+
"account_to_withdrawal_requests_connection_entities": [
37+
e.to_json() for e in self.entities
38+
],
39+
}
40+
41+
42+
FRAGMENT = """
43+
fragment AccountToWithdrawalRequestsConnectionFragment on AccountToWithdrawalRequestsConnection {
44+
__typename
45+
account_to_withdrawal_requests_connection_count: count
46+
account_to_withdrawal_requests_connection_page_info: page_info {
47+
__typename
48+
page_info_has_next_page: has_next_page
49+
page_info_has_previous_page: has_previous_page
50+
page_info_start_cursor: start_cursor
51+
page_info_end_cursor: end_cursor
52+
}
53+
account_to_withdrawal_requests_connection_entities: entities {
54+
id
55+
}
56+
}
57+
"""
58+
59+
60+
def from_json(
61+
requester: Requester, obj: Mapping[str, Any]
62+
) -> AccountToWithdrawalRequestsConnection:
63+
return AccountToWithdrawalRequestsConnection(
64+
requester=requester,
65+
typename="AccountToWithdrawalRequestsConnection",
66+
count=obj["account_to_withdrawal_requests_connection_count"],
67+
page_info=PageInfo_from_json(
68+
requester, obj["account_to_withdrawal_requests_connection_page_info"]
69+
),
70+
entities=list(
71+
map(
72+
# pylint: disable=unnecessary-lambda
73+
lambda e: WithdrawalRequest_from_json(requester, e),
74+
obj["account_to_withdrawal_requests_connection_entities"],
75+
)
76+
),
77+
)

lightspark/objects/Connection.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ class Connection:
116116
id
117117
}
118118
}
119+
... on AccountToWithdrawalRequestsConnection {
120+
__typename
121+
account_to_withdrawal_requests_connection_count: count
122+
account_to_withdrawal_requests_connection_page_info: page_info {
123+
__typename
124+
page_info_has_next_page: has_next_page
125+
page_info_has_previous_page: has_previous_page
126+
page_info_start_cursor: start_cursor
127+
page_info_end_cursor: end_cursor
128+
}
129+
account_to_withdrawal_requests_connection_entities: entities {
130+
id
131+
}
132+
}
119133
... on IncomingPaymentToAttemptsConnection {
120134
__typename
121135
incoming_payment_to_attempts_connection_count: count
@@ -200,5 +214,19 @@ class Connection:
200214
id
201215
}
202216
}
217+
... on WalletToWithdrawalRequestsConnection {
218+
__typename
219+
wallet_to_withdrawal_requests_connection_count: count
220+
wallet_to_withdrawal_requests_connection_page_info: page_info {
221+
__typename
222+
page_info_has_next_page: has_next_page
223+
page_info_has_previous_page: has_previous_page
224+
page_info_start_cursor: start_cursor
225+
page_info_end_cursor: end_cursor
226+
}
227+
wallet_to_withdrawal_requests_connection_entities: entities {
228+
id
229+
}
230+
}
203231
}
204232
"""

lightspark/objects/Entity.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,14 @@ class Entity:
14551455
withdrawal_request_id: id
14561456
withdrawal_request_created_at: created_at
14571457
withdrawal_request_updated_at: updated_at
1458+
withdrawal_request_requested_amount: requested_amount {
1459+
__typename
1460+
currency_amount_original_value: original_value
1461+
currency_amount_original_unit: original_unit
1462+
currency_amount_preferred_currency_unit: preferred_currency_unit
1463+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1464+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1465+
}
14581466
withdrawal_request_amount: amount {
14591467
__typename
14601468
currency_amount_original_value: original_value
@@ -1471,6 +1479,14 @@ class Entity:
14711479
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
14721480
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
14731481
}
1482+
withdrawal_request_amount_withdrawn: amount_withdrawn {
1483+
__typename
1484+
currency_amount_original_value: original_value
1485+
currency_amount_original_unit: original_unit
1486+
currency_amount_preferred_currency_unit: preferred_currency_unit
1487+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1488+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1489+
}
14741490
withdrawal_request_bitcoin_address: bitcoin_address
14751491
withdrawal_request_withdrawal_mode: withdrawal_mode
14761492
withdrawal_request_status: status

lightspark/objects/Wallet.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
from .WalletToTransactionsConnection import (
2626
from_json as WalletToTransactionsConnection_from_json,
2727
)
28+
from .WalletToWithdrawalRequestsConnection import WalletToWithdrawalRequestsConnection
29+
from .WalletToWithdrawalRequestsConnection import (
30+
from_json as WalletToWithdrawalRequestsConnection_from_json,
31+
)
32+
from .WithdrawalRequestStatus import WithdrawalRequestStatus
2833

2934

3035
@dataclass
@@ -1023,6 +1028,93 @@ def get_total_amount_received(
10231028
connection = json["entity"]["total_amount_received"]
10241029
return CurrencyAmount_from_json(self.requester, connection)
10251030

1031+
def get_withdrawal_requests(
1032+
self,
1033+
first: Optional[int] = None,
1034+
after: Optional[str] = None,
1035+
statuses: Optional[List[WithdrawalRequestStatus]] = None,
1036+
created_after_date: Optional[datetime] = None,
1037+
created_before_date: Optional[datetime] = None,
1038+
) -> WalletToWithdrawalRequestsConnection:
1039+
json = self.requester.execute_graphql(
1040+
"""
1041+
query FetchWalletToWithdrawalRequestsConnection($entity_id: ID!, $first: Int, $after: ID, $statuses: [WithdrawalRequestStatus!], $created_after_date: DateTime, $created_before_date: DateTime) {
1042+
entity(id: $entity_id) {
1043+
... on Wallet {
1044+
withdrawal_requests(, first: $first, after: $after, statuses: $statuses, created_after_date: $created_after_date, created_before_date: $created_before_date) {
1045+
__typename
1046+
wallet_to_withdrawal_requests_connection_count: count
1047+
wallet_to_withdrawal_requests_connection_page_info: page_info {
1048+
__typename
1049+
page_info_has_next_page: has_next_page
1050+
page_info_has_previous_page: has_previous_page
1051+
page_info_start_cursor: start_cursor
1052+
page_info_end_cursor: end_cursor
1053+
}
1054+
wallet_to_withdrawal_requests_connection_entities: entities {
1055+
__typename
1056+
withdrawal_request_id: id
1057+
withdrawal_request_created_at: created_at
1058+
withdrawal_request_updated_at: updated_at
1059+
withdrawal_request_requested_amount: requested_amount {
1060+
__typename
1061+
currency_amount_original_value: original_value
1062+
currency_amount_original_unit: original_unit
1063+
currency_amount_preferred_currency_unit: preferred_currency_unit
1064+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1065+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1066+
}
1067+
withdrawal_request_amount: amount {
1068+
__typename
1069+
currency_amount_original_value: original_value
1070+
currency_amount_original_unit: original_unit
1071+
currency_amount_preferred_currency_unit: preferred_currency_unit
1072+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1073+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1074+
}
1075+
withdrawal_request_estimated_amount: estimated_amount {
1076+
__typename
1077+
currency_amount_original_value: original_value
1078+
currency_amount_original_unit: original_unit
1079+
currency_amount_preferred_currency_unit: preferred_currency_unit
1080+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1081+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1082+
}
1083+
withdrawal_request_amount_withdrawn: amount_withdrawn {
1084+
__typename
1085+
currency_amount_original_value: original_value
1086+
currency_amount_original_unit: original_unit
1087+
currency_amount_preferred_currency_unit: preferred_currency_unit
1088+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1089+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1090+
}
1091+
withdrawal_request_bitcoin_address: bitcoin_address
1092+
withdrawal_request_withdrawal_mode: withdrawal_mode
1093+
withdrawal_request_status: status
1094+
withdrawal_request_completed_at: completed_at
1095+
withdrawal_request_withdrawal: withdrawal {
1096+
id
1097+
}
1098+
}
1099+
}
1100+
}
1101+
}
1102+
}
1103+
""",
1104+
{
1105+
"entity_id": self.id,
1106+
"first": first,
1107+
"after": after,
1108+
"statuses": statuses,
1109+
"created_after_date": created_after_date,
1110+
"created_before_date": created_before_date,
1111+
},
1112+
)
1113+
connection = json["entity"]["withdrawal_requests"]
1114+
return WalletToWithdrawalRequestsConnection_from_json(
1115+
self.requester, connection
1116+
)
1117+
10261118
def get_total_amount_sent(
10271119
self,
10281120
created_after_date: Optional[datetime] = None,

0 commit comments

Comments
 (0)