shadowPaySDK 0.2.1__py3-none-any.whl → 1.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.
- shadowPaySDK/__init__.py +1 -3
- shadowPaySDK/const.py +221 -128
- shadowPaySDK/interface/__init__.py +2 -2
- shadowPaySDK/interface/erc20.py +30 -24
- shadowPaySDK/interface/sol.py +100 -38
- shadowPaySDK/types/EVMcheque.py +281 -102
- shadowPaySDK/types/SOLcheque.py +467 -8
- {shadowpaysdk-0.2.1.dist-info → shadowpaysdk-1.0.0.dist-info}/METADATA +21 -8
- shadowpaysdk-1.0.0.dist-info/RECORD +16 -0
- shadowPaySDK/api.py +0 -48
- shadowpaysdk-0.2.1.dist-info/RECORD +0 -17
- {shadowpaysdk-0.2.1.dist-info → shadowpaysdk-1.0.0.dist-info}/WHEEL +0 -0
- {shadowpaysdk-0.2.1.dist-info → shadowpaysdk-1.0.0.dist-info}/licenses/LICENSE +0 -0
- {shadowpaysdk-0.2.1.dist-info → shadowpaysdk-1.0.0.dist-info}/top_level.txt +0 -0
shadowPaySDK/types/EVMcheque.py
CHANGED
@@ -1,26 +1,32 @@
|
|
1
1
|
import shadowPaySDK
|
2
2
|
from shadowPaySDK.const import __SHADOWPAY_ABI__ERC20__, __ALLOW_CHAINS__, __SHADOWPAY_CONTRACT_ADDRESS__ERC20__
|
3
|
-
from shadowPaySDK.api import __CREATE__CHEQUE__
|
4
3
|
from web3 import Web3
|
5
4
|
from typing import Optional
|
6
5
|
import httpx
|
7
6
|
|
8
7
|
|
9
8
|
class Cheque:
|
10
|
-
def __init__(self, w3:Web3,private_key:str, ABI = __SHADOWPAY_ABI__ERC20__, allowed_chains = __ALLOW_CHAINS__):
|
9
|
+
def __init__(self, w3:Optional[Web3] = None,private_key:Optional[str] = None, ABI = __SHADOWPAY_ABI__ERC20__, allowed_chains = __ALLOW_CHAINS__, retunrn_build_tx:bool = False,address:Optional[str] = None):
|
11
10
|
self.w3 = w3
|
12
|
-
|
13
|
-
print(f"allowed chains", allowed_chains)
|
11
|
+
|
14
12
|
self.amount = None
|
15
13
|
self.token = None
|
16
14
|
self.private_key = private_key
|
17
15
|
self.ABI = ABI
|
18
|
-
|
16
|
+
self.address = address
|
17
|
+
self.return_build_tx = retunrn_build_tx
|
19
18
|
self.allowed_chains = allowed_chains
|
20
|
-
if self.
|
21
|
-
|
19
|
+
if self.w3 != None:
|
20
|
+
self.__allow__()
|
21
|
+
|
22
|
+
def get_id(self, tx):
|
23
|
+
if isinstance(tx, str):
|
24
|
+
try:
|
25
|
+
tx = self.w3.eth.wait_for_transaction_receipt(tx)
|
26
|
+
except Exception as e:
|
27
|
+
print(f"Failed to get transaction receipt: {str(e)}")
|
28
|
+
return False
|
22
29
|
|
23
|
-
def __get__id(self, tx):
|
24
30
|
try:
|
25
31
|
logs = self.contract.events.ChequeCreated().process_receipt(tx)
|
26
32
|
cheque_id = logs[0]["args"]["id"]
|
@@ -29,6 +35,7 @@ class Cheque:
|
|
29
35
|
print(f"Failed to get cheque ID from transaction receipt: {str(e)}")
|
30
36
|
return False
|
31
37
|
def __allow__(self):
|
38
|
+
print("Checking if chain is allowed", self.w3.eth.chain_id)
|
32
39
|
for chain in self.allowed_chains:
|
33
40
|
|
34
41
|
if chain == self.w3.eth.chain_id:
|
@@ -39,18 +46,26 @@ class Cheque:
|
|
39
46
|
raise ValueError(f"Chain {str(self.w3.eth.chain_id)} is not allowed. Allowed chains are: {self.allowed_chains}")
|
40
47
|
def get_contract_for_chain(self,chain_id: str):
|
41
48
|
c = None
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
chain_id = int(chain_id)
|
50
|
+
|
51
|
+
for key,value in __SHADOWPAY_CONTRACT_ADDRESS__ERC20__.items():
|
52
|
+
print("Checking address", value, "for chain_id", chain_id)
|
53
|
+
if key == chain_id:
|
54
|
+
c = value
|
55
|
+
contract_address = Web3.to_checksum_address(c)
|
56
|
+
contract = self.w3.eth.contract(address=contract_address, abi=__SHADOWPAY_ABI__ERC20__)
|
57
|
+
self.contract = contract
|
58
|
+
return contract
|
51
59
|
raise ValueError(f"Chain {chain_id} is not supported. Supported chains are: {list(__SHADOWPAY_CONTRACT_ADDRESS__ERC20__.keys())}")
|
52
|
-
|
53
|
-
|
60
|
+
async def get_address(self):
|
61
|
+
if self.address:
|
62
|
+
return self.address
|
63
|
+
elif self.w3:
|
64
|
+
return self.w3.eth.default_account
|
65
|
+
else:
|
66
|
+
raise ValueError("No address provided or Web3 instance is not set")
|
67
|
+
|
68
|
+
def set_parameters(self,chain_id: Optional[str] = None, w3:Optional[Web3] = None, amount:Optional[int] = None, private_key:Optional[str] = None, token:Optional[str] = None,address:Optional[str] = None):
|
54
69
|
if w3:
|
55
70
|
self.w3 = w3
|
56
71
|
self.get_contract_for_chain(chain_id=chain_id or self.w3.eth.chain_id)
|
@@ -58,40 +73,66 @@ class Cheque:
|
|
58
73
|
self.amount = amount
|
59
74
|
if private_key:
|
60
75
|
self.private_key = private_key
|
76
|
+
self.address = Web3.to_checksum_address(self.w3.eth.account.from_key(private_key).address)
|
61
77
|
if token:
|
62
78
|
self.token = token
|
79
|
+
if address:
|
80
|
+
self.address = address
|
81
|
+
|
63
82
|
def __convert__(self):
|
64
83
|
return self.w3.to_wei(self.amount, 'ether')
|
65
|
-
|
84
|
+
|
66
85
|
async def InitCheque(self, amount, receiver:list, private_key:Optional[str] = None):
|
67
86
|
if not isinstance(receiver,list):
|
68
87
|
raise ValueError("Receiver must be a list of addresses, [""0x1234...5678", "0x2345...6789""]")
|
88
|
+
|
89
|
+
key = private_key or self.private_key
|
90
|
+
|
91
|
+
if key:
|
92
|
+
address = Web3.to_checksum_address(self.w3.eth.account.from_key(key).address)
|
93
|
+
print("InitCheque", amount, receiver, key)
|
69
94
|
|
95
|
+
elif self.address:
|
96
|
+
address = Web3.to_checksum_address(self.address)
|
97
|
+
else:
|
98
|
+
raise ValueError("No private key or address provided")
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
70
104
|
receiver = [Web3.to_checksum_address(addr) for addr in receiver]
|
71
105
|
estimated_gas = self.contract.functions.InitCheque(receiver).estimate_gas({
|
72
|
-
'from':
|
106
|
+
'from': address,
|
73
107
|
'value': self.w3.to_wei(amount, 'ether'),
|
74
108
|
'gasPrice': self.w3.eth.gas_price
|
75
109
|
})
|
76
110
|
txn = self.contract.functions.InitCheque(receiver).build_transaction({
|
77
|
-
'from':
|
111
|
+
'from': address,
|
78
112
|
'value': self.w3.to_wei(amount, 'ether'),
|
79
113
|
'nonce': self.w3.eth.get_transaction_count(
|
80
|
-
|
114
|
+
address
|
81
115
|
),
|
82
116
|
'gas': estimated_gas,
|
83
117
|
'gasPrice': self.w3.eth.gas_price,
|
84
118
|
'chainId': self.w3.eth.chain_id
|
85
119
|
})
|
86
|
-
|
120
|
+
if self.return_build_tx:
|
121
|
+
return {
|
122
|
+
"build_tx": txn
|
123
|
+
}
|
124
|
+
|
125
|
+
signed_txn = self.w3.eth.account.sign_transaction(txn, key)
|
87
126
|
txn_hash = self.w3.eth.send_raw_transaction(signed_txn.raw_transaction)
|
88
127
|
txn_receipt = self.w3.eth.wait_for_transaction_receipt(txn_hash)
|
89
128
|
insert_to_dn = None
|
90
|
-
logs = self.
|
129
|
+
logs = self.get_id(txn_receipt)
|
91
130
|
if logs:
|
92
131
|
cheque_id = logs
|
93
132
|
else:
|
94
133
|
cheque_id = None
|
134
|
+
if txn_receipt.status != 1:
|
135
|
+
return False
|
95
136
|
return {
|
96
137
|
"hash": txn_hash.hex(),
|
97
138
|
"chequeId": cheque_id,
|
@@ -103,78 +144,110 @@ class Cheque:
|
|
103
144
|
async def CashOutCheque(
|
104
145
|
self,
|
105
146
|
private_key: str,
|
106
|
-
cheque_id: str
|
147
|
+
cheque_id: str
|
107
148
|
):
|
108
149
|
if not private_key:
|
109
150
|
private_key = self.private_key
|
110
151
|
|
111
|
-
|
112
152
|
account = self.w3.eth.account.from_key(private_key)
|
113
|
-
sender_address = account.address
|
153
|
+
sender_address = account.address or self.address
|
154
|
+
nonce = self.w3.eth.get_transaction_count(sender_address)
|
114
155
|
|
156
|
+
latest_block = self.w3.eth.get_block('latest')
|
157
|
+
supports_eip1559 = 'baseFeePerGas' in latest_block
|
115
158
|
|
116
|
-
|
117
|
-
nonce = self.eth.get_transaction_count(sender_address)
|
118
|
-
|
119
|
-
txn = self.contract.functions.CashOutCheque(
|
120
|
-
Web3.to_bytes(hexstr=cheque_id)).build_transaction({
|
159
|
+
tx_common = {
|
121
160
|
'from': sender_address,
|
122
161
|
'nonce': nonce,
|
123
|
-
'gas': 300_000,
|
124
|
-
|
125
|
-
})
|
162
|
+
'gas': 300_000,
|
163
|
+
}
|
126
164
|
|
127
|
-
|
128
|
-
|
165
|
+
if supports_eip1559:
|
166
|
+
# EIP-1559 style
|
167
|
+
base_fee = latest_block['baseFeePerGas']
|
168
|
+
priority_fee = self.w3.to_wei(2, 'gwei') # можно поднять до 5
|
169
|
+
max_fee = base_fee + priority_fee * 2
|
129
170
|
|
130
|
-
|
131
|
-
|
171
|
+
tx_common.update({
|
172
|
+
'maxFeePerGas': max_fee,
|
173
|
+
'maxPriorityFeePerGas': priority_fee
|
174
|
+
})
|
175
|
+
else:
|
176
|
+
# Legacy gas price style
|
177
|
+
tx_common.update({
|
178
|
+
'gasPrice': self.w3.to_wei('5', 'gwei')
|
179
|
+
})
|
132
180
|
|
133
|
-
|
181
|
+
txn = self.contract.functions.CashOutCheque(
|
182
|
+
Web3.to_bytes(hexstr=cheque_id)
|
183
|
+
).build_transaction(tx_common)
|
184
|
+
|
185
|
+
if self.return_build_tx:
|
186
|
+
return {"build_tx": txn}
|
187
|
+
|
188
|
+
signed_txn = self.w3.eth.account.sign_transaction(txn, private_key=private_key)
|
189
|
+
tx_hash = self.w3.eth.send_raw_transaction(signed_txn.raw_transaction)
|
134
190
|
receipt = self.w3.eth.wait_for_transaction_receipt(tx_hash)
|
135
|
-
print(f"✅ Transaction confirmed in block {receipt.blockNumber}")
|
136
|
-
return receipt
|
137
191
|
|
192
|
+
if receipt.status != 1:
|
193
|
+
return False
|
194
|
+
return {"hash": tx_hash.hex()}
|
195
|
+
|
138
196
|
async def InitTokenCheque(self, token_address:str, amount, reciver:str, private_key:Optional[str] = None):
|
139
|
-
|
197
|
+
key = private_key or self.private_key
|
198
|
+
|
199
|
+
if key:
|
200
|
+
address = Web3.to_checksum_address(self.w3.eth.account.from_key(key).address)
|
201
|
+
|
202
|
+
elif self.address:
|
203
|
+
address = Web3.to_checksum_address(self.address)
|
204
|
+
else:
|
205
|
+
raise ValueError("No private key or address provided")
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
140
210
|
|
141
211
|
erc20 = shadowPaySDK.ERC20Token(w3=self.w3)
|
142
212
|
erc20.set_params(token_address=token_address)
|
143
|
-
|
144
|
-
|
213
|
+
decimals = erc20.get_decimals()
|
214
|
+
erc20.allowance(
|
145
215
|
spender=self.contract.address,
|
146
|
-
|
216
|
+
owner=address,
|
147
217
|
)
|
148
|
-
print(f"Ensure allowance: {ensure_allowance}")
|
149
|
-
decimals = erc20.get_decimals()
|
150
218
|
estimated_gas = self.contract.functions.InitTokenCheque(
|
151
219
|
Web3.to_checksum_address(token_address),
|
152
|
-
|
220
|
+
amount,
|
153
221
|
Web3.to_checksum_address(reciver)
|
154
222
|
).estimate_gas({
|
155
|
-
'from':
|
223
|
+
'from': address,
|
156
224
|
'gasPrice': self.w3.eth.gas_price
|
157
225
|
})
|
158
226
|
txn = self.contract.functions.InitTokenCheque(
|
159
227
|
Web3.to_checksum_address(token_address),
|
160
|
-
|
228
|
+
amount,
|
161
229
|
Web3.to_checksum_address(reciver)
|
162
230
|
).build_transaction({
|
163
|
-
'from':
|
164
|
-
'nonce': self.w3.eth.get_transaction_count(
|
231
|
+
'from': address,
|
232
|
+
'nonce': self.w3.eth.get_transaction_count(address),
|
165
233
|
'gas': estimated_gas,
|
166
234
|
'gasPrice': self.w3.eth.gas_price
|
167
235
|
})
|
168
|
-
|
236
|
+
if self.return_build_tx:
|
237
|
+
return {
|
238
|
+
"build_tx": txn
|
239
|
+
}
|
240
|
+
signed_txn = self.w3.eth.account.sign_transaction(txn, key)
|
169
241
|
txn_hash = self.w3.eth.send_raw_transaction(signed_txn.raw_transaction)
|
170
242
|
txn_receipt = self.w3.eth.wait_for_transaction_receipt(txn_hash)
|
171
243
|
|
172
|
-
logs = self.
|
244
|
+
logs = self.get_id(txn_receipt)
|
173
245
|
if logs:
|
174
246
|
cheque_id = logs
|
175
247
|
else:
|
176
248
|
cheque_id = None
|
177
|
-
|
249
|
+
if txn_receipt.status != 1:
|
250
|
+
return False
|
178
251
|
return {
|
179
252
|
"hash": txn_hash.hex(),
|
180
253
|
"chequeId": cheque_id,
|
@@ -188,93 +261,216 @@ class Cheque:
|
|
188
261
|
|
189
262
|
|
190
263
|
|
191
|
-
# Строим транзакцию
|
192
264
|
estimated_gas = self.contract.functions.CashOutTokenCheque(
|
193
|
-
Web3.to_bytes(hexstr=cheque_id)
|
265
|
+
Web3.to_bytes(hexstr=cheque_id)
|
194
266
|
).estimate_gas({
|
195
|
-
'from': account.address,
|
267
|
+
'from': account.address or self.address,
|
196
268
|
'gasPrice': self.w3.eth.gas_price
|
197
269
|
})
|
198
270
|
txn = self.contract.functions.CashOutTokenCheque(
|
199
271
|
Web3.to_bytes(hexstr=cheque_id)
|
200
272
|
).build_transaction({
|
201
|
-
'from': account.address,
|
202
|
-
'nonce': self.w3.eth.get_transaction_count(account.address),
|
273
|
+
'from': account.address or self.address,
|
274
|
+
'nonce': self.w3.eth.get_transaction_count(account.address or self.address),
|
203
275
|
'gas': estimated_gas,
|
204
276
|
'gasPrice': self.w3.eth.gas_price,
|
205
277
|
})
|
278
|
+
if self.return_build_tx:
|
279
|
+
return {
|
280
|
+
"build_tx": txn
|
281
|
+
}
|
206
282
|
|
207
|
-
# Подписываем и отправляем транзакцию
|
208
283
|
signed_txn = self.w3.eth.account.sign_transaction(txn, private_key=private_key)
|
209
284
|
tx_hash = self.w3.eth.send_raw_transaction(signed_txn.raw_transaction)
|
210
285
|
|
211
|
-
# Получаем подтверждение
|
212
286
|
receipt = self.w3.eth.wait_for_transaction_receipt(tx_hash)
|
213
287
|
|
288
|
+
if receipt.status != 1:
|
289
|
+
return False
|
214
290
|
return {
|
215
291
|
"hash": tx_hash.hex(),
|
216
292
|
"status": receipt.status # 1 = success, 0 = fail
|
217
293
|
}
|
218
294
|
async def InitTokenChequeSwap(self, token_in:str, amount_in,token_out:str, amount_out, reciver:str, private_key:Optional[str] = None):
|
219
|
-
|
295
|
+
key = private_key or self.private_key
|
296
|
+
if key:
|
297
|
+
address = Web3.to_checksum_address(self.w3.eth.account.from_key(key).address)
|
298
|
+
elif self.address:
|
299
|
+
address = Web3.to_checksum_address(self.address)
|
220
300
|
erc20 = shadowPaySDK.ERC20Token(w3=self.w3)
|
221
301
|
erc20.set_params(token_address=token_in)
|
222
|
-
|
223
|
-
private_key=self.private_key,
|
302
|
+
approve = erc20.allowance(
|
224
303
|
spender=self.contract.address,
|
225
|
-
|
226
|
-
token=token_in
|
304
|
+
owner=address,
|
227
305
|
)
|
228
|
-
|
229
|
-
|
230
|
-
token_out_decinals = erc20.get_decimals(
|
306
|
+
decimals = erc20.get_decimals()
|
307
|
+
erc20.set_params(token_address=token_out)
|
308
|
+
token_out_decinals = erc20.get_decimals()
|
231
309
|
estimated_gas = self.contract.functions.InitSwapCheque(
|
232
310
|
Web3.to_checksum_address(reciver),
|
233
311
|
Web3.to_checksum_address(token_in),
|
234
|
-
|
312
|
+
amount_in,
|
235
313
|
Web3.to_checksum_address(token_out),
|
236
|
-
|
314
|
+
amount_out,
|
237
315
|
).estimate_gas({
|
238
|
-
'from':
|
316
|
+
'from': address,
|
239
317
|
'gasPrice': self.w3.eth.gas_price
|
240
318
|
})
|
241
319
|
txn = self.contract.functions.InitSwapCheque(
|
242
320
|
Web3.to_checksum_address(reciver),
|
243
321
|
Web3.to_checksum_address(token_in),
|
244
|
-
|
322
|
+
amount_in,
|
245
323
|
Web3.to_checksum_address(token_out),
|
246
|
-
|
324
|
+
amount_out
|
247
325
|
).build_transaction({
|
248
|
-
'from':
|
249
|
-
'nonce': self.w3.eth.get_transaction_count(
|
326
|
+
'from': address,
|
327
|
+
'nonce': self.w3.eth.get_transaction_count(address),
|
250
328
|
'gas': estimated_gas,
|
251
329
|
'gasPrice': self.w3.eth.gas_price
|
252
330
|
})
|
253
|
-
|
331
|
+
if self.return_build_tx:
|
332
|
+
return {
|
333
|
+
"build_tx": txn
|
334
|
+
}
|
335
|
+
signed_txn = self.w3.eth.account.sign_transaction(txn, key)
|
254
336
|
txn_hash = self.w3.eth.send_raw_transaction(signed_txn.raw_transaction)
|
255
337
|
txn_receipt = self.w3.eth.wait_for_transaction_receipt(txn_hash)
|
256
338
|
|
257
|
-
logs = self.
|
339
|
+
logs = self.get_id(txn_receipt)
|
258
340
|
if logs:
|
259
341
|
cheque_id = logs
|
260
342
|
else:
|
261
343
|
cheque_id = None
|
344
|
+
if txn_receipt.status != 1:
|
345
|
+
return False
|
262
346
|
return {
|
263
347
|
"hash": txn_hash.hex(),
|
264
348
|
"chequeId": cheque_id
|
265
349
|
}
|
350
|
+
|
351
|
+
async def CashOutSwapCheque(self, cheque_id: str, private_key: Optional[str] = None):
|
352
|
+
swapDetail = await self.getSwaoDetail(cheque_id)
|
353
|
+
print(swapDetail)
|
354
|
+
if private_key is None:
|
355
|
+
private_key = self.private_key
|
356
|
+
token_out = swapDetail["tokenOut"]
|
357
|
+
amount_out = swapDetail["amountOut"]
|
358
|
+
erc20 = shadowPaySDK.ERC20Token(w3=self.w3)
|
359
|
+
erc20.set_params(token_address=token_out)
|
360
|
+
encure_allowance = erc20.allowance(
|
361
|
+
spender=self.contract.address,
|
362
|
+
owner=self.address,
|
363
|
+
)
|
364
|
+
if encure_allowance < amount_out:
|
365
|
+
approve = erc20.approve(
|
366
|
+
spender=self.contract.address,
|
367
|
+
amount=amount_out,
|
368
|
+
private_key=private_key,
|
369
|
+
conveted_amount=False
|
370
|
+
)
|
371
|
+
if not approve:
|
372
|
+
return False
|
373
|
+
print(f"contract balance: {erc20.get_balance(wallet_address=self.contract.address)}")
|
374
|
+
estimated_gas = self.contract.functions.CashOutSwapCheque(
|
375
|
+
Web3.to_bytes(hexstr=cheque_id)
|
376
|
+
).estimate_gas({
|
377
|
+
'from': self.w3.eth.account.from_key(private_key).address,
|
378
|
+
'gasPrice': self.w3.eth.gas_price
|
379
|
+
})
|
380
|
+
swa = self.contract.functions.CashOutSwapCheque(
|
381
|
+
Web3.to_bytes(hexstr=cheque_id)
|
382
|
+
).build_transaction({
|
383
|
+
'from': self.w3.eth.account.from_key(private_key).address,
|
384
|
+
'nonce': self.w3.eth.get_transaction_count(self.w3.eth.account.from_key(private_key).address),
|
385
|
+
'gas': 300_000,
|
386
|
+
'gasPrice': self.w3.eth.gas_price
|
387
|
+
})
|
388
|
+
if self.return_build_tx:
|
389
|
+
return {
|
390
|
+
"build_tx": swa
|
391
|
+
}
|
392
|
+
signed_txn = self.w3.eth.account.sign_transaction(swa, private_key=private_key)
|
393
|
+
tx_hash = self.w3.eth.send_raw_transaction(signed_txn.raw_transaction)
|
394
|
+
receipt = self.w3.eth.wait_for_transaction_receipt(tx_hash)
|
395
|
+
if receipt.status != 1:
|
396
|
+
return False
|
397
|
+
return {
|
398
|
+
"hash": tx_hash.hex(),
|
399
|
+
}
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
|
266
404
|
async def getComunityPool(self):
|
267
|
-
|
268
|
-
fee = 50000000000000
|
405
|
+
fee = self.contract.functions.getCollectedFee().call()
|
269
406
|
half_fee_eth = self.w3.from_wei(fee // 2, 'ether')
|
270
407
|
return half_fee_eth
|
271
408
|
async def getOwner(self):
|
272
409
|
return self.contract.functions.getOwner().call()
|
273
410
|
async def getTreasery(self):
|
274
411
|
return self.contract.functions.getTreasery().call()
|
412
|
+
def getChequeInfo(self, cheque_id: str, address: Optional[str] = None):
|
413
|
+
###returns cheque info###
|
414
|
+
# s = EVMcheque.getChequeInfo(
|
415
|
+
# cheque_id=chequeId,
|
416
|
+
# address=address
|
417
|
+
# )
|
418
|
+
### cheque_amount = s[0] - amount of cheque in wei
|
419
|
+
### cheque_sender = s[1] - list of sender addresses
|
420
|
+
### cheque_status = s[2] - status of cheque (True - claimed, False - not claimed)
|
421
|
+
if not cheque_id:
|
422
|
+
raise ValueError("Cheque ID is required")
|
423
|
+
if address:
|
424
|
+
address = Web3.to_checksum_address(address)
|
425
|
+
|
426
|
+
cheque_id_bytes32 = Web3.to_bytes(hexstr=cheque_id).rjust(32, b'\x00')
|
427
|
+
cheque_info = self.contract.functions.getChequeInfo(
|
428
|
+
cheque_id_bytes32,
|
429
|
+
address or self.address
|
430
|
+
).call()
|
431
|
+
|
432
|
+
return {
|
433
|
+
"sender": cheque_info[0],
|
434
|
+
"receiver": cheque_info[1],
|
435
|
+
"status": "claimed" if cheque_info[2] else "unclaimed",
|
436
|
+
}
|
437
|
+
def getTokenChequeInfo(self, cheque_id: str):
|
438
|
+
# f = EVMcheque.getTokenChequeInfo(
|
439
|
+
# cheque_id=chequeId,
|
440
|
+
# )
|
441
|
+
### cheque_sender = s[0] - sender address
|
442
|
+
### cheque_amount = s[1] - receiver address
|
443
|
+
### cheque_status = s[2] - status of cheque (True - claimed, False - not claimed
|
444
|
+
|
445
|
+
if not cheque_id:
|
446
|
+
raise ValueError("Cheque ID is required")
|
447
|
+
|
448
|
+
cheque_id_bytes32 = Web3.to_bytes(hexstr=cheque_id).rjust(32, b'\x00')
|
449
|
+
cheque_info = self.contract.functions.getTokenChequeDetail(cheque_id_bytes32).call()
|
450
|
+
return {
|
451
|
+
"sender": cheque_info[0],
|
452
|
+
"receivers": cheque_info[1],
|
453
|
+
"status": "claimed" if cheque_info[2] else "unclaimed",
|
454
|
+
}
|
275
455
|
async def getSwaoDetail(self, cheque_id: str):
|
276
|
-
|
277
|
-
|
456
|
+
# f = EVMcheque.getSwaoDetail(
|
457
|
+
# cheque_id=chequeId,
|
458
|
+
# )
|
459
|
+
# f[0] - tokenOut address,
|
460
|
+
# f[1] - amountOut in wei,
|
461
|
+
# f[2] - spender,
|
462
|
+
# f[3] - receiver,
|
463
|
+
# f[4] - claimed
|
464
|
+
cheque_id_bytes32 = Web3.to_bytes(hexstr=cheque_id).rjust(32, b'\x00')
|
465
|
+
s = self.contract.functions.getSwapDetail(cheque_id_bytes32).call()
|
466
|
+
return {
|
467
|
+
"tokenOut": s[0],
|
468
|
+
"amountOut": s[1],
|
469
|
+
"spender": s[2],
|
470
|
+
"receiver": s[3],
|
471
|
+
"status": "claimed" if s[4] else "unclaimed"
|
472
|
+
}
|
473
|
+
|
278
474
|
class NFTcheque:
|
279
475
|
def __init__(self, w3:Web3, token:str, amount:int, spender:str):
|
280
476
|
self.w3 = w3
|
@@ -306,20 +502,3 @@ class NFTcheque:
|
|
306
502
|
|
307
503
|
|
308
504
|
|
309
|
-
async def create_cheque(id, type, chain_id, receiver, sender):
|
310
|
-
async with httpx.AsyncClient() as client:
|
311
|
-
response = await client.post(
|
312
|
-
__CREATE__CHEQUE__,
|
313
|
-
json={
|
314
|
-
"cheque_id": id,
|
315
|
-
"chain_id":chain_id,
|
316
|
-
"receiver": receiver,
|
317
|
-
"type": type,
|
318
|
-
"sender":sender
|
319
|
-
}
|
320
|
-
)
|
321
|
-
if response.status_code == 200:
|
322
|
-
return response.json()
|
323
|
-
else:
|
324
|
-
print(f"Failed to create cheque: {response.text}")
|
325
|
-
return False
|