chipi-stack 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- chipi_sdk/__init__.py +342 -0
- chipi_sdk/client.py +505 -0
- chipi_sdk/constants.py +171 -0
- chipi_sdk/encryption.py +179 -0
- chipi_sdk/errors.py +130 -0
- chipi_sdk/execute_paymaster.py +434 -0
- chipi_sdk/formatters.py +154 -0
- chipi_sdk/models/__init__.py +145 -0
- chipi_sdk/models/core.py +96 -0
- chipi_sdk/models/session.py +119 -0
- chipi_sdk/models/sku.py +28 -0
- chipi_sdk/models/sku_transaction.py +30 -0
- chipi_sdk/models/transaction.py +192 -0
- chipi_sdk/models/user.py +31 -0
- chipi_sdk/models/wallet.py +178 -0
- chipi_sdk/models/x402.py +117 -0
- chipi_sdk/py.typed +1 -0
- chipi_sdk/sdk.py +1021 -0
- chipi_sdk/sessions.py +836 -0
- chipi_sdk/sku_transactions.py +58 -0
- chipi_sdk/skus.py +93 -0
- chipi_sdk/transactions.py +447 -0
- chipi_sdk/users.py +92 -0
- chipi_sdk/validators.py +75 -0
- chipi_sdk/wallets.py +465 -0
- chipi_sdk/x402_client.py +207 -0
- chipi_sdk/x402_facilitator.py +200 -0
- chipi_sdk/x402_middleware.py +280 -0
- chipi_stack-2.0.0.dist-info/METADATA +366 -0
- chipi_stack-2.0.0.dist-info/RECORD +33 -0
- chipi_stack-2.0.0.dist-info/WHEEL +5 -0
- chipi_stack-2.0.0.dist-info/licenses/LICENSE +21 -0
- chipi_stack-2.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""SKU transaction management."""
|
|
2
|
+
|
|
3
|
+
from .models.sku_transaction import CreateSkuTransactionParams, SkuTransaction
|
|
4
|
+
from .constants import API_ENDPOINTS
|
|
5
|
+
from .client import ChipiClient
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ChipiSkuTransactions:
|
|
9
|
+
"""SKU transaction management class."""
|
|
10
|
+
|
|
11
|
+
def __init__(self, client: ChipiClient):
|
|
12
|
+
"""
|
|
13
|
+
Initialize SKU transaction manager.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
client: Chipi HTTP client
|
|
17
|
+
"""
|
|
18
|
+
self.client = client
|
|
19
|
+
|
|
20
|
+
async def acreate_sku_transaction(
|
|
21
|
+
self, params: CreateSkuTransactionParams, bearer_token: str
|
|
22
|
+
) -> SkuTransaction:
|
|
23
|
+
"""
|
|
24
|
+
Create a new SKU transaction (async).
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
params: SKU transaction creation parameters
|
|
28
|
+
bearer_token: Authentication token
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
Created SKU transaction
|
|
32
|
+
"""
|
|
33
|
+
response = await self.client.apost(
|
|
34
|
+
endpoint=API_ENDPOINTS["SKU_TRANSACTIONS"],
|
|
35
|
+
bearer_token=bearer_token,
|
|
36
|
+
body=params.model_dump(),
|
|
37
|
+
)
|
|
38
|
+
return SkuTransaction(**response)
|
|
39
|
+
|
|
40
|
+
def create_sku_transaction(
|
|
41
|
+
self, params: CreateSkuTransactionParams, bearer_token: str
|
|
42
|
+
) -> SkuTransaction:
|
|
43
|
+
"""
|
|
44
|
+
Create a new SKU transaction (sync).
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
params: SKU transaction creation parameters
|
|
48
|
+
bearer_token: Authentication token
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
Created SKU transaction
|
|
52
|
+
"""
|
|
53
|
+
response = self.client.post(
|
|
54
|
+
endpoint=API_ENDPOINTS["SKU_TRANSACTIONS"],
|
|
55
|
+
bearer_token=bearer_token,
|
|
56
|
+
body=params.model_dump(),
|
|
57
|
+
)
|
|
58
|
+
return SkuTransaction(**response)
|
chipi_sdk/skus.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""SKU (Stock Keeping Unit) management."""
|
|
2
|
+
|
|
3
|
+
from .models.sku import Sku, GetSkuListQuery
|
|
4
|
+
from .models.core import PaginatedResponse
|
|
5
|
+
from .constants import API_ENDPOINTS
|
|
6
|
+
from .client import ChipiClient
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ChipiSkus:
|
|
10
|
+
"""SKU management class."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, client: ChipiClient):
|
|
13
|
+
"""
|
|
14
|
+
Initialize SKU manager.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
client: Chipi HTTP client
|
|
18
|
+
"""
|
|
19
|
+
self.client = client
|
|
20
|
+
|
|
21
|
+
async def aget_sku_list(
|
|
22
|
+
self, params: GetSkuListQuery, bearer_token: str
|
|
23
|
+
) -> PaginatedResponse[Sku]:
|
|
24
|
+
"""
|
|
25
|
+
Get paginated list of SKUs (async).
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
params: Query parameters for filtering SKUs
|
|
29
|
+
bearer_token: Authentication token
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
Paginated SKU list
|
|
33
|
+
"""
|
|
34
|
+
response = await self.client.aget(
|
|
35
|
+
endpoint=API_ENDPOINTS["SKUS"],
|
|
36
|
+
params=params.model_dump(exclude_none=True),
|
|
37
|
+
bearer_token=bearer_token,
|
|
38
|
+
)
|
|
39
|
+
return PaginatedResponse[Sku](**response)
|
|
40
|
+
|
|
41
|
+
def get_sku_list(
|
|
42
|
+
self, params: GetSkuListQuery, bearer_token: str
|
|
43
|
+
) -> PaginatedResponse[Sku]:
|
|
44
|
+
"""
|
|
45
|
+
Get paginated list of SKUs (sync).
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
params: Query parameters for filtering SKUs
|
|
49
|
+
bearer_token: Authentication token
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
Paginated SKU list
|
|
53
|
+
"""
|
|
54
|
+
response = self.client.get(
|
|
55
|
+
endpoint=API_ENDPOINTS["SKUS"],
|
|
56
|
+
params=params.model_dump(exclude_none=True),
|
|
57
|
+
bearer_token=bearer_token,
|
|
58
|
+
)
|
|
59
|
+
return PaginatedResponse[Sku](**response)
|
|
60
|
+
|
|
61
|
+
async def aget_sku(self, sku_id: str, bearer_token: str) -> Sku:
|
|
62
|
+
"""
|
|
63
|
+
Get a specific SKU by ID (async).
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
sku_id: SKU identifier
|
|
67
|
+
bearer_token: Authentication token
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
SKU data
|
|
71
|
+
"""
|
|
72
|
+
response = await self.client.aget(
|
|
73
|
+
endpoint=f"{API_ENDPOINTS['SKUS']}/{sku_id}",
|
|
74
|
+
bearer_token=bearer_token,
|
|
75
|
+
)
|
|
76
|
+
return Sku(**response)
|
|
77
|
+
|
|
78
|
+
def get_sku(self, sku_id: str, bearer_token: str) -> Sku:
|
|
79
|
+
"""
|
|
80
|
+
Get a specific SKU by ID (sync).
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
sku_id: SKU identifier
|
|
84
|
+
bearer_token: Authentication token
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
SKU data
|
|
88
|
+
"""
|
|
89
|
+
response = self.client.get(
|
|
90
|
+
endpoint=f"{API_ENDPOINTS['SKUS']}/{sku_id}",
|
|
91
|
+
bearer_token=bearer_token,
|
|
92
|
+
)
|
|
93
|
+
return Sku(**response)
|
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
"""Transaction management utilities."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
from .models.transaction import (
|
|
5
|
+
ExecuteTransactionParams,
|
|
6
|
+
TransferParams,
|
|
7
|
+
ApproveParams,
|
|
8
|
+
CallAnyContractParams,
|
|
9
|
+
RecordSendTransactionParams,
|
|
10
|
+
Transaction,
|
|
11
|
+
GetTransactionListQuery,
|
|
12
|
+
TransactionStatusResponse,
|
|
13
|
+
)
|
|
14
|
+
from .models.core import PaginatedResponse, STARKNET_CONTRACTS
|
|
15
|
+
from .models.wallet import WalletData
|
|
16
|
+
from .formatters import format_amount
|
|
17
|
+
from .constants import API_ENDPOINTS
|
|
18
|
+
from .client import ChipiClient
|
|
19
|
+
from .execute_paymaster import (
|
|
20
|
+
execute_paymaster_transaction,
|
|
21
|
+
execute_paymaster_transaction_sync,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ChipiTransactions:
|
|
26
|
+
"""Transaction management class."""
|
|
27
|
+
|
|
28
|
+
def __init__(self, client: ChipiClient):
|
|
29
|
+
"""
|
|
30
|
+
Initialize transaction manager.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
client: Chipi HTTP client
|
|
34
|
+
"""
|
|
35
|
+
self.client = client
|
|
36
|
+
|
|
37
|
+
async def aexecute_transaction(
|
|
38
|
+
self,
|
|
39
|
+
params: ExecuteTransactionParams,
|
|
40
|
+
bearer_token: str,
|
|
41
|
+
save_to_database: bool = True,
|
|
42
|
+
) -> str:
|
|
43
|
+
"""
|
|
44
|
+
Execute a gasless transaction using paymaster (async).
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
params: Transaction execution parameters
|
|
48
|
+
bearer_token: Authentication token
|
|
49
|
+
save_to_database: Whether to save transaction to database (internal)
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
Transaction hash
|
|
53
|
+
"""
|
|
54
|
+
return await execute_paymaster_transaction(
|
|
55
|
+
params={
|
|
56
|
+
"encryptKey": params.encrypt_key,
|
|
57
|
+
"wallet": params.wallet.model_dump(),
|
|
58
|
+
"calls": [call.model_dump(by_alias=True) for call in params.calls],
|
|
59
|
+
"saveToDatabase": save_to_database,
|
|
60
|
+
"usePasskey": params.use_passkey,
|
|
61
|
+
},
|
|
62
|
+
bearer_token=bearer_token,
|
|
63
|
+
client=self.client,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
def execute_transaction(
|
|
67
|
+
self,
|
|
68
|
+
params: ExecuteTransactionParams,
|
|
69
|
+
bearer_token: str,
|
|
70
|
+
save_to_database: bool = True,
|
|
71
|
+
) -> str:
|
|
72
|
+
"""
|
|
73
|
+
Execute a gasless transaction using paymaster (sync).
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
params: Transaction execution parameters
|
|
77
|
+
bearer_token: Authentication token
|
|
78
|
+
save_to_database: Whether to save transaction to database (internal)
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
Transaction hash
|
|
82
|
+
"""
|
|
83
|
+
return execute_paymaster_transaction_sync(
|
|
84
|
+
params={
|
|
85
|
+
"encryptKey": params.encrypt_key,
|
|
86
|
+
"wallet": params.wallet.model_dump(),
|
|
87
|
+
"calls": [call.model_dump(by_alias=True) for call in params.calls],
|
|
88
|
+
"saveToDatabase": save_to_database,
|
|
89
|
+
"usePasskey": params.use_passkey,
|
|
90
|
+
},
|
|
91
|
+
bearer_token=bearer_token,
|
|
92
|
+
client=self.client,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
async def atransfer(
|
|
96
|
+
self, params: TransferParams, bearer_token: str
|
|
97
|
+
) -> str:
|
|
98
|
+
"""
|
|
99
|
+
Transfer tokens (async).
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
params: Transfer parameters
|
|
103
|
+
bearer_token: Authentication token
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
Transaction hash
|
|
107
|
+
"""
|
|
108
|
+
contract = STARKNET_CONTRACTS[params.token]
|
|
109
|
+
contract_address = contract.contract_address
|
|
110
|
+
decimals = contract.decimals
|
|
111
|
+
|
|
112
|
+
if params.token.value == "OTHER":
|
|
113
|
+
if not params.other_token:
|
|
114
|
+
raise ValueError("other_token is required when token is OTHER")
|
|
115
|
+
contract_address = params.other_token["contractAddress"]
|
|
116
|
+
decimals = params.other_token["decimals"]
|
|
117
|
+
|
|
118
|
+
formatted_amount = format_amount(params.amount, decimals)
|
|
119
|
+
|
|
120
|
+
from .models.transaction import Call, ExecuteTransactionParams
|
|
121
|
+
|
|
122
|
+
return await self.aexecute_transaction(
|
|
123
|
+
params=ExecuteTransactionParams(
|
|
124
|
+
encrypt_key=params.encrypt_key,
|
|
125
|
+
wallet=params.wallet,
|
|
126
|
+
calls=[
|
|
127
|
+
Call(
|
|
128
|
+
contractAddress=contract_address,
|
|
129
|
+
entrypoint="transfer",
|
|
130
|
+
calldata=[params.recipient, formatted_amount, "0x0"],
|
|
131
|
+
)
|
|
132
|
+
],
|
|
133
|
+
use_passkey=params.use_passkey,
|
|
134
|
+
),
|
|
135
|
+
bearer_token=bearer_token,
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
def transfer(self, params: TransferParams, bearer_token: str) -> str:
|
|
139
|
+
"""
|
|
140
|
+
Transfer tokens (sync).
|
|
141
|
+
|
|
142
|
+
Args:
|
|
143
|
+
params: Transfer parameters
|
|
144
|
+
bearer_token: Authentication token
|
|
145
|
+
|
|
146
|
+
Returns:
|
|
147
|
+
Transaction hash
|
|
148
|
+
"""
|
|
149
|
+
contract = STARKNET_CONTRACTS[params.token]
|
|
150
|
+
contract_address = contract.contract_address
|
|
151
|
+
decimals = contract.decimals
|
|
152
|
+
|
|
153
|
+
if params.token.value == "OTHER":
|
|
154
|
+
if not params.other_token:
|
|
155
|
+
raise ValueError("other_token is required when token is OTHER")
|
|
156
|
+
contract_address = params.other_token["contractAddress"]
|
|
157
|
+
decimals = params.other_token["decimals"]
|
|
158
|
+
|
|
159
|
+
formatted_amount = format_amount(params.amount, decimals)
|
|
160
|
+
|
|
161
|
+
from .models.transaction import Call, ExecuteTransactionParams
|
|
162
|
+
|
|
163
|
+
return self.execute_transaction(
|
|
164
|
+
params=ExecuteTransactionParams(
|
|
165
|
+
encrypt_key=params.encrypt_key,
|
|
166
|
+
wallet=params.wallet,
|
|
167
|
+
calls=[
|
|
168
|
+
Call(
|
|
169
|
+
contractAddress=contract_address,
|
|
170
|
+
entrypoint="transfer",
|
|
171
|
+
calldata=[params.recipient, formatted_amount, "0x0"],
|
|
172
|
+
)
|
|
173
|
+
],
|
|
174
|
+
use_passkey=params.use_passkey,
|
|
175
|
+
),
|
|
176
|
+
bearer_token=bearer_token,
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
async def aapprove(
|
|
180
|
+
self, params: ApproveParams, bearer_token: str
|
|
181
|
+
) -> str:
|
|
182
|
+
"""
|
|
183
|
+
Approve token spending (async).
|
|
184
|
+
|
|
185
|
+
Args:
|
|
186
|
+
params: Approval parameters
|
|
187
|
+
bearer_token: Authentication token
|
|
188
|
+
|
|
189
|
+
Returns:
|
|
190
|
+
Transaction hash
|
|
191
|
+
"""
|
|
192
|
+
formatted_amount = format_amount(params.amount, params.decimals or 18)
|
|
193
|
+
|
|
194
|
+
from .models.transaction import Call, ExecuteTransactionParams
|
|
195
|
+
|
|
196
|
+
return await self.aexecute_transaction(
|
|
197
|
+
params=ExecuteTransactionParams(
|
|
198
|
+
encrypt_key=params.encrypt_key,
|
|
199
|
+
wallet=params.wallet,
|
|
200
|
+
calls=[
|
|
201
|
+
Call(
|
|
202
|
+
contractAddress=params.contract_address,
|
|
203
|
+
entrypoint="approve",
|
|
204
|
+
calldata=[params.spender, formatted_amount, "0x0"],
|
|
205
|
+
)
|
|
206
|
+
],
|
|
207
|
+
use_passkey=params.use_passkey,
|
|
208
|
+
),
|
|
209
|
+
bearer_token=bearer_token,
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
def approve(self, params: ApproveParams, bearer_token: str) -> str:
|
|
213
|
+
"""
|
|
214
|
+
Approve token spending (sync).
|
|
215
|
+
|
|
216
|
+
Args:
|
|
217
|
+
params: Approval parameters
|
|
218
|
+
bearer_token: Authentication token
|
|
219
|
+
|
|
220
|
+
Returns:
|
|
221
|
+
Transaction hash
|
|
222
|
+
"""
|
|
223
|
+
formatted_amount = format_amount(params.amount, params.decimals or 18)
|
|
224
|
+
|
|
225
|
+
from .models.transaction import Call, ExecuteTransactionParams
|
|
226
|
+
|
|
227
|
+
return self.execute_transaction(
|
|
228
|
+
params=ExecuteTransactionParams(
|
|
229
|
+
encrypt_key=params.encrypt_key,
|
|
230
|
+
wallet=params.wallet,
|
|
231
|
+
calls=[
|
|
232
|
+
Call(
|
|
233
|
+
contractAddress=params.contract_address,
|
|
234
|
+
entrypoint="approve",
|
|
235
|
+
calldata=[params.spender, formatted_amount, "0x0"],
|
|
236
|
+
)
|
|
237
|
+
],
|
|
238
|
+
use_passkey=params.use_passkey,
|
|
239
|
+
),
|
|
240
|
+
bearer_token=bearer_token,
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
async def acall_any_contract(
|
|
244
|
+
self, params: CallAnyContractParams, bearer_token: str
|
|
245
|
+
) -> str:
|
|
246
|
+
"""
|
|
247
|
+
Call any contract method (async).
|
|
248
|
+
|
|
249
|
+
Args:
|
|
250
|
+
params: Contract call parameters
|
|
251
|
+
bearer_token: Authentication token
|
|
252
|
+
|
|
253
|
+
Returns:
|
|
254
|
+
Transaction hash
|
|
255
|
+
"""
|
|
256
|
+
from .models.transaction import ExecuteTransactionParams
|
|
257
|
+
|
|
258
|
+
return await self.aexecute_transaction(
|
|
259
|
+
params=ExecuteTransactionParams(
|
|
260
|
+
encrypt_key=params.encrypt_key,
|
|
261
|
+
wallet=params.wallet,
|
|
262
|
+
calls=params.calls,
|
|
263
|
+
use_passkey=params.use_passkey,
|
|
264
|
+
),
|
|
265
|
+
bearer_token=bearer_token,
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
def call_any_contract(
|
|
269
|
+
self, params: CallAnyContractParams, bearer_token: str
|
|
270
|
+
) -> str:
|
|
271
|
+
"""
|
|
272
|
+
Call any contract method (sync).
|
|
273
|
+
|
|
274
|
+
Args:
|
|
275
|
+
params: Contract call parameters
|
|
276
|
+
bearer_token: Authentication token
|
|
277
|
+
|
|
278
|
+
Returns:
|
|
279
|
+
Transaction hash
|
|
280
|
+
"""
|
|
281
|
+
from .models.transaction import ExecuteTransactionParams
|
|
282
|
+
|
|
283
|
+
return self.execute_transaction(
|
|
284
|
+
params=ExecuteTransactionParams(
|
|
285
|
+
encrypt_key=params.encrypt_key,
|
|
286
|
+
wallet=params.wallet,
|
|
287
|
+
calls=params.calls,
|
|
288
|
+
use_passkey=params.use_passkey,
|
|
289
|
+
),
|
|
290
|
+
bearer_token=bearer_token,
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
async def arecord_send_transaction(
|
|
294
|
+
self, params: RecordSendTransactionParams, bearer_token: str
|
|
295
|
+
) -> Transaction:
|
|
296
|
+
"""
|
|
297
|
+
Record a send transaction (async).
|
|
298
|
+
|
|
299
|
+
Args:
|
|
300
|
+
params: Transaction recording parameters
|
|
301
|
+
bearer_token: Authentication token
|
|
302
|
+
|
|
303
|
+
Returns:
|
|
304
|
+
Transaction record
|
|
305
|
+
"""
|
|
306
|
+
response = await self.client.apost(
|
|
307
|
+
endpoint=f"{API_ENDPOINTS['TRANSACTIONS']}/record-send",
|
|
308
|
+
bearer_token=bearer_token,
|
|
309
|
+
body=params.model_dump(),
|
|
310
|
+
)
|
|
311
|
+
return Transaction(**response)
|
|
312
|
+
|
|
313
|
+
def record_send_transaction(
|
|
314
|
+
self, params: RecordSendTransactionParams, bearer_token: str
|
|
315
|
+
) -> Transaction:
|
|
316
|
+
"""
|
|
317
|
+
Record a send transaction (sync).
|
|
318
|
+
|
|
319
|
+
Args:
|
|
320
|
+
params: Transaction recording parameters
|
|
321
|
+
bearer_token: Authentication token
|
|
322
|
+
|
|
323
|
+
Returns:
|
|
324
|
+
Transaction record
|
|
325
|
+
"""
|
|
326
|
+
response = self.client.post(
|
|
327
|
+
endpoint=f"{API_ENDPOINTS['TRANSACTIONS']}/record-send",
|
|
328
|
+
bearer_token=bearer_token,
|
|
329
|
+
body=params.model_dump(),
|
|
330
|
+
)
|
|
331
|
+
return Transaction(**response)
|
|
332
|
+
|
|
333
|
+
async def aget_transaction_list(
|
|
334
|
+
self, query: GetTransactionListQuery, bearer_token: str
|
|
335
|
+
) -> PaginatedResponse[Transaction]:
|
|
336
|
+
"""
|
|
337
|
+
Get paginated transaction history (async).
|
|
338
|
+
|
|
339
|
+
Args:
|
|
340
|
+
query: Query parameters for filtering transactions
|
|
341
|
+
bearer_token: Authentication token
|
|
342
|
+
|
|
343
|
+
Returns:
|
|
344
|
+
Paginated transaction list
|
|
345
|
+
"""
|
|
346
|
+
response = await self.client.aget(
|
|
347
|
+
endpoint=f"{API_ENDPOINTS['TRANSACTIONS']}/transaction-list",
|
|
348
|
+
params=query.model_dump(by_alias=True, exclude_none=True),
|
|
349
|
+
bearer_token=bearer_token,
|
|
350
|
+
)
|
|
351
|
+
return PaginatedResponse[Transaction](**response)
|
|
352
|
+
|
|
353
|
+
def get_transaction_list(
|
|
354
|
+
self, query: GetTransactionListQuery, bearer_token: str
|
|
355
|
+
) -> PaginatedResponse[Transaction]:
|
|
356
|
+
"""
|
|
357
|
+
Get paginated transaction history (sync).
|
|
358
|
+
|
|
359
|
+
Args:
|
|
360
|
+
query: Query parameters for filtering transactions
|
|
361
|
+
bearer_token: Authentication token
|
|
362
|
+
|
|
363
|
+
Returns:
|
|
364
|
+
Paginated transaction list
|
|
365
|
+
"""
|
|
366
|
+
response = self.client.get(
|
|
367
|
+
endpoint=f"{API_ENDPOINTS['TRANSACTIONS']}/transaction-list",
|
|
368
|
+
params=query.model_dump(by_alias=True, exclude_none=True),
|
|
369
|
+
bearer_token=bearer_token,
|
|
370
|
+
)
|
|
371
|
+
return PaginatedResponse[Transaction](**response)
|
|
372
|
+
|
|
373
|
+
async def aget_transaction(
|
|
374
|
+
self, hash_or_id: str, bearer_token: str
|
|
375
|
+
) -> Transaction:
|
|
376
|
+
"""
|
|
377
|
+
Get a single transaction by hash or ID (async).
|
|
378
|
+
|
|
379
|
+
Args:
|
|
380
|
+
hash_or_id: Transaction hash (0x...) or internal database ID
|
|
381
|
+
bearer_token: Authentication token
|
|
382
|
+
|
|
383
|
+
Returns:
|
|
384
|
+
Transaction record
|
|
385
|
+
"""
|
|
386
|
+
response = await self.client.aget(
|
|
387
|
+
endpoint=f"{API_ENDPOINTS['TRANSACTIONS']}/{hash_or_id}",
|
|
388
|
+
bearer_token=bearer_token,
|
|
389
|
+
)
|
|
390
|
+
return Transaction(**response)
|
|
391
|
+
|
|
392
|
+
def get_transaction(
|
|
393
|
+
self, hash_or_id: str, bearer_token: str
|
|
394
|
+
) -> Transaction:
|
|
395
|
+
"""
|
|
396
|
+
Get a single transaction by hash or ID (sync).
|
|
397
|
+
|
|
398
|
+
Args:
|
|
399
|
+
hash_or_id: Transaction hash (0x...) or internal database ID
|
|
400
|
+
bearer_token: Authentication token
|
|
401
|
+
|
|
402
|
+
Returns:
|
|
403
|
+
Transaction record
|
|
404
|
+
"""
|
|
405
|
+
response = self.client.get(
|
|
406
|
+
endpoint=f"{API_ENDPOINTS['TRANSACTIONS']}/{hash_or_id}",
|
|
407
|
+
bearer_token=bearer_token,
|
|
408
|
+
)
|
|
409
|
+
return Transaction(**response)
|
|
410
|
+
|
|
411
|
+
async def aget_transaction_status(
|
|
412
|
+
self, hash: str, bearer_token: str
|
|
413
|
+
) -> TransactionStatusResponse:
|
|
414
|
+
"""
|
|
415
|
+
Get on-chain transaction status (async).
|
|
416
|
+
|
|
417
|
+
Args:
|
|
418
|
+
hash: Transaction hash (0x...)
|
|
419
|
+
bearer_token: Authentication token
|
|
420
|
+
|
|
421
|
+
Returns:
|
|
422
|
+
Transaction status response
|
|
423
|
+
"""
|
|
424
|
+
response = await self.client.aget(
|
|
425
|
+
endpoint=f"{API_ENDPOINTS['TRANSACTIONS']}/{hash}/status",
|
|
426
|
+
bearer_token=bearer_token,
|
|
427
|
+
)
|
|
428
|
+
return TransactionStatusResponse(**response)
|
|
429
|
+
|
|
430
|
+
def get_transaction_status(
|
|
431
|
+
self, hash: str, bearer_token: str
|
|
432
|
+
) -> TransactionStatusResponse:
|
|
433
|
+
"""
|
|
434
|
+
Get on-chain transaction status (sync).
|
|
435
|
+
|
|
436
|
+
Args:
|
|
437
|
+
hash: Transaction hash (0x...)
|
|
438
|
+
bearer_token: Authentication token
|
|
439
|
+
|
|
440
|
+
Returns:
|
|
441
|
+
Transaction status response
|
|
442
|
+
"""
|
|
443
|
+
response = self.client.get(
|
|
444
|
+
endpoint=f"{API_ENDPOINTS['TRANSACTIONS']}/{hash}/status",
|
|
445
|
+
bearer_token=bearer_token,
|
|
446
|
+
)
|
|
447
|
+
return TransactionStatusResponse(**response)
|
chipi_sdk/users.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""User management."""
|
|
2
|
+
|
|
3
|
+
from .models.user import User, CreateUserParams, GetUserParams
|
|
4
|
+
from .constants import API_ENDPOINTS
|
|
5
|
+
from .client import ChipiClient
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ChipiUsers:
|
|
9
|
+
"""User management class."""
|
|
10
|
+
|
|
11
|
+
def __init__(self, client: ChipiClient):
|
|
12
|
+
"""
|
|
13
|
+
Initialize user manager.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
client: Chipi HTTP client
|
|
17
|
+
"""
|
|
18
|
+
self.client = client
|
|
19
|
+
|
|
20
|
+
async def aget_user(self, params: GetUserParams, bearer_token: str) -> User:
|
|
21
|
+
"""
|
|
22
|
+
Get user by external user ID (async).
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
params: User query parameters
|
|
26
|
+
bearer_token: Authentication token
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
User data
|
|
30
|
+
"""
|
|
31
|
+
response = await self.client.aget(
|
|
32
|
+
endpoint=f"{API_ENDPOINTS['USERS']}/by-external-id",
|
|
33
|
+
params={"externalUserId": params.external_user_id},
|
|
34
|
+
bearer_token=bearer_token,
|
|
35
|
+
)
|
|
36
|
+
return User(**response)
|
|
37
|
+
|
|
38
|
+
def get_user(self, params: GetUserParams, bearer_token: str) -> User:
|
|
39
|
+
"""
|
|
40
|
+
Get user by external user ID (sync).
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
params: User query parameters
|
|
44
|
+
bearer_token: Authentication token
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
User data
|
|
48
|
+
"""
|
|
49
|
+
response = self.client.get(
|
|
50
|
+
endpoint=f"{API_ENDPOINTS['USERS']}/by-external-id",
|
|
51
|
+
params={"externalUserId": params.external_user_id},
|
|
52
|
+
bearer_token=bearer_token,
|
|
53
|
+
)
|
|
54
|
+
return User(**response)
|
|
55
|
+
|
|
56
|
+
async def acreate_user(
|
|
57
|
+
self, params: CreateUserParams, bearer_token: str
|
|
58
|
+
) -> User:
|
|
59
|
+
"""
|
|
60
|
+
Create a new user (async).
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
params: User creation parameters
|
|
64
|
+
bearer_token: Authentication token
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
Created user data
|
|
68
|
+
"""
|
|
69
|
+
response = await self.client.apost(
|
|
70
|
+
endpoint=API_ENDPOINTS["USERS"],
|
|
71
|
+
bearer_token=bearer_token,
|
|
72
|
+
body=params.model_dump(),
|
|
73
|
+
)
|
|
74
|
+
return User(**response)
|
|
75
|
+
|
|
76
|
+
def create_user(self, params: CreateUserParams, bearer_token: str) -> User:
|
|
77
|
+
"""
|
|
78
|
+
Create a new user (sync).
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
params: User creation parameters
|
|
82
|
+
bearer_token: Authentication token
|
|
83
|
+
|
|
84
|
+
Returns:
|
|
85
|
+
Created user data
|
|
86
|
+
"""
|
|
87
|
+
response = self.client.post(
|
|
88
|
+
endpoint=API_ENDPOINTS["USERS"],
|
|
89
|
+
bearer_token=bearer_token,
|
|
90
|
+
body=params.model_dump(),
|
|
91
|
+
)
|
|
92
|
+
return User(**response)
|