Skip to content

Commit 4d8b7cd

Browse files
committed
Add threshold gas value to Wallet and other minor changes
1 parent 059283f commit 4d8b7cd

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

sdk/contracts/AccountsWrapper.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ def authorize_vote_signer(self, signer: str, proof_of_signing_key_possession: Si
216216
signer, proof_of_signing_key_possession.v, proof_of_signing_key_possession.r, proof_of_signing_key_possession.s)
217217
return self.__wallet.send_transaction(func_call)
218218

219-
# TODO need to implement Validators smart contract to try to test this method
220219
def authorize_validator_signer(self, signer: str, proof_of_signing_key_possession: SignedMessage) -> str:
221220
"""
222221
Authorizes an address to sign consensus messages on behalf of the account

sdk/contracts/AttestationsWrapper.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def __init__(self, web3: Web3, registry: Registry, address: str, abi: list, wall
4444
'valid': 'Valid'
4545
}
4646

47-
# TODO: test this method
4847
def parse_get_completable_attestations(self, response: list) -> list:
4948
metadata_urls = attestations_utils.parse_solidity_string_array(
5049
response[2], response[3]) # TODO: check response[3] data type
@@ -102,10 +101,6 @@ def is_attestation_expired(self, attestation_request_block_number: int) -> bool:
102101
current_block = self.web3.eth.getBlock().number
103102
return current_block >= attestation_request_block_number + attestation_expity_block
104103

105-
def wait_for_selecting_issuers(self):
106-
# TODO: think whether we need to implement it such as it will not work the same as in JS
107-
pass
108-
109104
def get_attestation_issuers(self, identifier: str, account: str) -> list:
110105
"""
111106
Returns the issuers of attestations for a phoneNumber/account combo

sdk/contracts/GovernanceWrapper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,21 +532,21 @@ def sorted_queue(self, queue: List[dict]) -> List[dict]:
532532
def _with_upvote_revoked(self, upvoter: str, queue_p: List[dict] = []) -> dict:
533533
upvoter_record = self.get_upvote_record(upvoter)
534534
index, queue = self._get_queue_index(
535-
upvoter_record['proposal_id'], queue_p)
535+
upvoter_record['proposal_id'], queue_p).values()
536536
queue[index]['upvotes'] = queue[index]['upvotes'] - \
537537
upvoter_record['upvotes']
538538

539539
return {'queue': self.sorted_queue(queue), 'upvote_record': upvoter_record}
540540

541541
def _with_upvote_applied(self, upvoter: str, proposal_id: int, queue_p: List[dict] = []) -> list:
542-
index, queue = self._get_queue_index(proposal_id, queue_p)
542+
index, queue = self._get_queue_index(proposal_id, queue_p).values()
543543
weight = self.get_vote_weight(upvoter)
544544
queue[index]['upvotes'] = queue[index]['upvotes'] + weight
545545

546546
return self.sorted_queue(queue)
547547

548548
def _lesser_and_greater_after_revoke(self, upvoter: str) -> dict:
549-
queue, upvote_record = self._with_upvote_revoked(upvoter)
549+
queue, upvote_record = self._with_upvote_revoked(upvoter).values()
550550

551551
return self._lesser_and_greater(upvote_record['proposal_id'], queue)
552552

sdk/contracts/base_wrapper.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ def create_contract_by_name(self, contract_name: str):
6969
contract_obj = self.contracts.get(contract_name)
7070
if contract_obj:
7171
return
72-
# raise Exception("Such a contract already created")
7372
contract_data = self.registry.load_contract_by_name(contract_name)
7473

7574
self.create_contract(

sdk/wallet.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(self, web3: Web3, priv_key: bytes, gas_price_contract: "GasPriceCon
3535
self._gas_price = None
3636
self._gas = 10000000
3737
self.gas_increase_step = 1000000
38+
self._threshold_gas_value = 100000000
3839

3940
@property
4041
def fee_currency(self) -> str:
@@ -55,6 +56,10 @@ def gas_price(self) -> int:
5556
@property
5657
def gas(self) -> int:
5758
return self._gas
59+
60+
@property
61+
def threshold_gas_value(self) -> int:
62+
return self._threshold_gas_value
5863

5964
@property
6065
def accounts(self) -> dict:
@@ -93,6 +98,12 @@ def gas(self, new_gas: int):
9398
if type(new_gas) != int:
9499
raise TypeError("Incorrect new gas type data")
95100
self._gas = new_gas
101+
102+
@threshold_gas_value.setter
103+
def threshold_gas_value(self, new_threshold_gas_value: int):
104+
if type(new_threshold_gas_value) != int:
105+
raise TypeError("Incorrect new threshold gas value type data")
106+
self._threshold_gas_value = new_threshold_gas_value
96107

97108
@accounts.setter
98109
def accounts(self, new_acc: Account):
@@ -208,9 +219,9 @@ def send_transaction(self, contract_method: web3._utils.datatypes, parameters: d
208219
except ValueError as e:
209220
error_message = ast.literal_eval(str(e))['message']
210221
if error_message == 'intrinsic gas too low':
211-
print(
212-
"Got error about too low gas value. Increase gas value and try to send it again.")
213222
gas = gas + self.gas_increase_step if gas else self._gas + self.gas_increase_step
223+
if gas > self.threshold_gas_value:
224+
raise Exception(f"Transaction requires a lot of gas use({gas}), if you want to send transaction set higher gas value and increase threshold gas value")
214225
self.send_transaction(contract_method, parameters={'gas': gas})
215226
else:
216227
raise ValueError(error_message)
@@ -229,7 +240,7 @@ def push_tx_to_blockchain(self, signed_raw_tx: HexBytes) -> str:
229240
hash of sent transaction
230241
"""
231242
tx_hash = self.web3.eth.sendRawTransaction(signed_raw_tx)
232-
return tx_hash.hex()
243+
return tx_hash
233244

234245
def get_network_gas_price(self) -> int:
235246
"""

0 commit comments

Comments
 (0)