Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #346 from humanprotocol/gas-limit-adjustment
Browse files Browse the repository at this point in the history
Assign gas inside function bodies if falsy value was provided explicitly
  • Loading branch information
Vlad Komodey authored Jul 28, 2022
2 parents 1f052c5 + abc98d8 commit 5474121
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
11 changes: 9 additions & 2 deletions hmt_escrow/eth_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ def deploy_factory(
str: returns the contract address of the newly deployed factory.
"""
if gas is None:
gas = GAS_LIMIT
gas_payer = credentials["gas_payer"]
gas_payer_priv = credentials["gas_payer_priv"]
hmtoken_address = HMTOKEN_ADDR if hmtoken_addr is None else hmtoken_addr
Expand Down Expand Up @@ -385,7 +387,9 @@ def get_pub_key_from_addr(wallet_addr: str, hmt_server_addr: str = None) -> byte
return bytes(addr_pub_key, encoding="utf-8")


def set_pub_key_at_addr(pub_key: str, hmt_server_addr: str = None) -> TxReceipt:
def set_pub_key_at_addr(
pub_key: str, hmt_server_addr: str = None, gas: int = GAS_LIMIT
) -> TxReceipt:
"""
Given a public key, this function will use the eth-kvstore to reach out to the blockchain
and set the key `hmt_pub_key` on the callers kvstore collection of values, equivalent to the
Expand Down Expand Up @@ -414,6 +418,9 @@ def set_pub_key_at_addr(pub_key: str, hmt_server_addr: str = None) -> TxReceipt:
GAS_PAYER = os.getenv("GAS_PAYER")
GAS_PAYER_PRIV = os.getenv("GAS_PAYER_PRIV")

if gas is None:
gas = GAS_LIMIT

if not (GAS_PAYER or GAS_PAYER_PRIV):
raise ValueError("environment variable GAS_PAYER AND GAS_PAYER_PRIV required")

Expand All @@ -425,7 +432,7 @@ def set_pub_key_at_addr(pub_key: str, hmt_server_addr: str = None) -> TxReceipt:
txn_info = {
"gas_payer": GAS_PAYER,
"gas_payer_priv": GAS_PAYER_PRIV,
"gas": GAS_LIMIT,
"gas": gas,
"hmt_server_addr": hmt_server_addr,
}

Expand Down
18 changes: 17 additions & 1 deletion hmt_escrow/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def status(escrow_contract: Contract, gas_payer: str, gas: int = GAS_LIMIT) -> E
Enum: returns the status as an enumeration.
"""
if gas is None:
gas = GAS_LIMIT

status_ = escrow_contract.functions.status().call(
{"from": gas_payer, "gas": Wei(gas)}
)
Expand All @@ -66,6 +69,10 @@ def manifest_url(
str: returns the manifest url of Job's escrow contract.
"""

if gas is None:
gas = GAS_LIMIT

return escrow_contract.functions.manifestUrl().call(
{"from": gas_payer, "gas": Wei(gas)}
)
Expand All @@ -85,6 +92,9 @@ def manifest_hash(
str: returns the manifest hash of Job's escrow contract.
"""
if gas is None:
gas = GAS_LIMIT

return escrow_contract.functions.manifestHash().call(
{"from": gas_payer, "gas": Wei(gas)}
)
Expand All @@ -93,6 +103,9 @@ def manifest_hash(
def is_trusted_handler(
escrow_contract: Contract, handler_addr: str, gas_payer: str, gas: int = GAS_LIMIT
) -> bool:
if gas is None:
gas = GAS_LIMIT

return escrow_contract.functions.areTrustedHandlers(handler_addr).call(
{"from": gas_payer, "gas": Wei(gas)}
)
Expand All @@ -110,6 +123,9 @@ def launcher(escrow_contract: Contract, gas_payer: str, gas: int = GAS_LIMIT) ->
str: returns the address of who launched the job.
"""
if gas is None:
gas = GAS_LIMIT

return escrow_contract.functions.launcher().call(
{"from": gas_payer, "gas": Wei(gas)}
)
Expand Down Expand Up @@ -243,7 +259,7 @@ def __init__(
self.multi_credentials = self._validate_multi_credentials(multi_credentials)
self.hmt_server_addr = hmt_server_addr
self.hmtoken_addr = HMTOKEN_ADDR if hmtoken_addr is None else hmtoken_addr
self.gas = gas_limit
self.gas = gas_limit or GAS_LIMIT

# Initialize a new Job.
if not escrow_addr and escrow_manifest:
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hmt-escrow",
"version": "0.12.0",
"version": "0.13.0",
"description": "Launch escrow contracts to the HUMAN network",
"main": "truffle.js",
"directories": {
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name="hmt-escrow",
version="0.12.0",
version="0.13.0",
author="HUMAN Protocol",
description="A python library to launch escrow contracts to the HUMAN network.",
url="https://github.com/humanprotocol/hmt-escrow",
Expand Down

0 comments on commit 5474121

Please sign in to comment.