shadowPaySDK 0.2.0.3__tar.gz → 0.2.0.5__tar.gz
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-0.2.0.3 → shadowpaysdk-0.2.0.5}/PKG-INFO +1 -1
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/setup.py +1 -1
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/shadowPaySDK/interface/erc20.py +9 -8
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/shadowPaySDK/types/EVMcheque.py +4 -7
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/shadowPaySDK.egg-info/PKG-INFO +1 -1
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/LICENSE +0 -0
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/README.md +0 -0
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/setup.cfg +0 -0
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/shadowPaySDK/__init__.py +0 -0
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/shadowPaySDK/api.py +0 -0
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/shadowPaySDK/const.py +0 -0
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/shadowPaySDK/interface/__init__.py +0 -0
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/shadowPaySDK/interface/erc721.py +0 -0
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/shadowPaySDK/interface/sol.py +0 -0
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/shadowPaySDK/types/SOLcheque.py +0 -0
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/shadowPaySDK/types/__init__.py +0 -0
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/shadowPaySDK/utils/__init__.py +0 -0
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/shadowPaySDK/utils/utils.py +0 -0
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/shadowPaySDK.egg-info/SOURCES.txt +0 -0
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/shadowPaySDK.egg-info/dependency_links.txt +0 -0
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/shadowPaySDK.egg-info/requires.txt +0 -0
- {shadowpaysdk-0.2.0.3 → shadowpaysdk-0.2.0.5}/shadowPaySDK.egg-info/top_level.txt +0 -0
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
2
2
|
|
3
3
|
setup(
|
4
4
|
name='shadowPaySDK',
|
5
|
-
version='0.2.0.
|
5
|
+
version='0.2.0.5',
|
6
6
|
description='ShadowPay SDK for ERC20/ERC721 and P2P smart contract interaction',
|
7
7
|
long_description=open('README.md').read(),
|
8
8
|
long_description_content_type='text/markdown',
|
@@ -9,6 +9,7 @@ class ERC20Token:
|
|
9
9
|
def __init__(self, w3:Web3, explorer: Optional[str] = None):
|
10
10
|
self.web3 = w3
|
11
11
|
self.explorer = explorer
|
12
|
+
|
12
13
|
self.address = None
|
13
14
|
self.contract = None
|
14
15
|
|
@@ -21,7 +22,7 @@ class ERC20Token:
|
|
21
22
|
|
22
23
|
def _ensure_contract(self):
|
23
24
|
if not self.contract:
|
24
|
-
raise ValueError("Token address is not set. Use
|
25
|
+
raise ValueError("Token address is not set. Use set_params first.")
|
25
26
|
|
26
27
|
def _format_tx(self, tx_hash: str) -> str:
|
27
28
|
if self.explorer:
|
@@ -44,7 +45,7 @@ class ERC20Token:
|
|
44
45
|
raw = self.contract.functions.balanceOf(Web3.to_checksum_address(wallet_address)).call()
|
45
46
|
return raw / (10 ** self.get_decimals())
|
46
47
|
|
47
|
-
def allowance(self, owner: str, spender: str
|
48
|
+
def allowance(self, owner: str, spender: str) -> float:
|
48
49
|
self._ensure_contract()
|
49
50
|
raw = self.contract.functions.allowance(
|
50
51
|
Web3.to_checksum_address(owner),
|
@@ -52,13 +53,13 @@ class ERC20Token:
|
|
52
53
|
).call()
|
53
54
|
return raw / (10 ** self.get_decimals())
|
54
55
|
|
55
|
-
def ensure_allowance(self, private_key: str, spender: str, amount
|
56
|
+
def ensure_allowance(self, private_key: str, spender: str, amount) -> Union[bool, str]:
|
56
57
|
self._ensure_contract()
|
57
58
|
account = self.web3.eth.account.from_key(private_key)
|
58
|
-
current = self.allowance(account.address, spender
|
59
|
+
current = self.allowance(account.address, spender)
|
59
60
|
if current == amount:
|
60
61
|
return True
|
61
|
-
return self.approve(private_key, spender, amount
|
62
|
+
return self.approve(private_key, spender, amount)
|
62
63
|
|
63
64
|
def transfer(self, private_key: str, to: str, amount: float) -> str:
|
64
65
|
self._ensure_contract()
|
@@ -86,10 +87,10 @@ class ERC20Token:
|
|
86
87
|
tx_hash = self.web3.eth.send_raw_transaction(signed.raw_transaction)
|
87
88
|
return self._format_tx(self.web3.to_hex(tx_hash))
|
88
89
|
|
89
|
-
def approve(self, private_key: str, spender: str, amount: float
|
90
|
+
def approve(self, private_key: str, spender: str, amount: float) -> str:
|
90
91
|
self._ensure_contract()
|
91
92
|
account = self.web3.eth.account.from_key(private_key)
|
92
|
-
decimals = self.get_decimals(
|
93
|
+
decimals = self.get_decimals()
|
93
94
|
amount = int(amount * (10 ** decimals))
|
94
95
|
|
95
96
|
txn = self.contract.functions.approve(
|
@@ -108,5 +109,5 @@ class ERC20Token:
|
|
108
109
|
tx_receipt = self.web3.eth.wait_for_transaction_receipt(tx_hash)
|
109
110
|
if tx_receipt.status != 1:
|
110
111
|
raise ValueError(f"aaprove fail.\n {self._format_tx(self.web3.to_hex(tx_hash))}")
|
111
|
-
return f"
|
112
|
+
return f"{self._format_tx(self.web3.to_hex(tx_hash))}"
|
112
113
|
|
@@ -139,14 +139,11 @@ class Cheque:
|
|
139
139
|
|
140
140
|
erc20 = shadowPaySDK.ERC20Token(w3=self.w3)
|
141
141
|
erc20.set_params(token_address=token_address)
|
142
|
-
decimals = erc20.get_decimals(
|
143
|
-
token_address
|
144
|
-
)
|
142
|
+
decimals = erc20.get_decimals()
|
145
143
|
erc20.ensure_allowance(
|
146
144
|
private_key=self.private_key,
|
147
145
|
spender=self.contract.address,
|
148
146
|
amount=amount,
|
149
|
-
token=token_address
|
150
147
|
)
|
151
148
|
estimated_gas = self.contract.functions.InitTokenCheque(
|
152
149
|
Web3.to_checksum_address(token_address),
|
@@ -224,10 +221,10 @@ class Cheque:
|
|
224
221
|
private_key=self.private_key,
|
225
222
|
spender=self.contract.address,
|
226
223
|
amount=amount_in,
|
227
|
-
token=token_in
|
228
224
|
)
|
229
|
-
decimals = erc20.get_decimals(
|
230
|
-
|
225
|
+
decimals = erc20.get_decimals()
|
226
|
+
erc20.set_params(token_address=token_out)
|
227
|
+
token_out_decinals = erc20.get_decimals()
|
231
228
|
estimated_gas = self.contract.functions.InitSwapCheque(
|
232
229
|
Web3.to_checksum_address(reciver),
|
233
230
|
Web3.to_checksum_address(token_in),
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|