Skip to content

Commit

Permalink
Added usage of decorator for contract instances autoupdate (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
u-hubar authored Jan 10, 2024
2 parents 25092f5 + 9b4b134 commit 4b5d095
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions dkg/providers/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def make_json_rpc_request(self, endpoint: str, args: dict[str, Any] = {}) -> Any
def handle_updated_contract(func):
@wraps(func)
def wrapper(self, *args, **kwargs):
contract_name = kwargs.get("contract_name") or (args[0] if args else None)
contract_name = kwargs.get("contract") or (args[0] if args else None)

try:
return func(self, *args, **kwargs)
Expand All @@ -133,6 +133,7 @@ def wrapper(self, *args, **kwargs):

return wrapper

@handle_updated_contract
def call_function(
self,
contract: str,
Expand Down Expand Up @@ -240,14 +241,10 @@ def _update_contract_instance(self, contract: str):
self.contracts[contract] = self.w3.eth.contract(
address=(
self.contracts["Hub"]
.functions.getContractAddress(
contract if contract != "ERC20Token" else "Token"
)
.call()
.functions.getContractAddress(contract).call()
if not contract.endswith("AssetStorage")
else self.contracts["Hub"]
.functions.getAssetStorageAddress(contract)
.call()
.functions.getAssetStorageAddress(contract).call()
),
abi=self.abi[contract],
)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dkg"
version = "0.1.0-beta.3"
version = "0.1.0-beta.4"
description = "Python library for interacting with the OriginTrail Decentralized Knowledge Graph"
authors = ["Uladzislau Hubar <hubar.uladzislau@gmail.com>"]
license = "Apache-2.0"
Expand Down

0 comments on commit 4b5d095

Please sign in to comment.