Skip to content

Commit

Permalink
Merge pull request #19 from levonyak/PAN-1998-upgrade-to-hexbytes-1x
Browse files Browse the repository at this point in the history
[PAN-1998] Upgrade to hexbytes 1.x and versioned contract ABIs
  • Loading branch information
markuslevonyak authored Jul 8, 2024
2 parents 57ef826 + 619c741 commit 5caad61
Show file tree
Hide file tree
Showing 4 changed files with 592 additions and 427 deletions.
10 changes: 10 additions & 0 deletions pantos/client/library/blockchains/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import dataclasses
import typing

import semantic_version # type: ignore
from pantos.common.blockchains.base import Blockchain
from pantos.common.blockchains.base import BlockchainHandler
from pantos.common.blockchains.base import BlockchainUtilities
from pantos.common.blockchains.base import BlockchainUtilitiesError
from pantos.common.blockchains.base import VersionedContractAbi
from pantos.common.blockchains.enums import ContractAbi
from pantos.common.blockchains.factory import get_blockchain_utilities
from pantos.common.blockchains.factory import initialize_blockchain_utilities
from pantos.common.entities import ServiceNodeBid
Expand All @@ -20,6 +23,13 @@
from pantos.client.library.configuration import get_blockchain_config
from pantos.client.library.exceptions import ClientLibraryError

_CONTRACTS_VERSION = semantic_version.Version('1.0.0')

VERSIONED_CONTRACT_ABIS = {
contract_abi: VersionedContractAbi(contract_abi, _CONTRACTS_VERSION)
for contract_abi in ContractAbi
}


class BlockchainClientError(ClientLibraryError):
"""Base exception class for all blockchain client errors.
Expand Down
10 changes: 7 additions & 3 deletions pantos/client/library/blockchains/ethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pantos.common.types import BlockchainAddress
from pantos.common.types import PrivateKey

from pantos.client.library.blockchains.base import VERSIONED_CONTRACT_ABIS
from pantos.client.library.blockchains.base import BlockchainClient
from pantos.client.library.blockchains.base import BlockchainClientError
from pantos.client.library.constants import TOKEN_SYMBOL_PAN
Expand Down Expand Up @@ -208,7 +209,8 @@ def _create_hub_contract(
-> NodeConnections.Wrapper[web3.contract.Contract]:
try:
return self._get_utilities().create_contract(
self._get_config()['hub'], ContractAbi.PANTOS_HUB,
self._get_config()['hub'],
VERSIONED_CONTRACT_ABIS[ContractAbi.PANTOS_HUB],
node_connections)
except Exception:
raise self._create_error(
Expand All @@ -219,7 +221,9 @@ def _create_token_contract(
token_address: BlockchainAddress) -> Web3Contract:
try:
return self._get_utilities().create_contract(
token_address, ContractAbi.PANTOS_TOKEN, node_connections)
token_address,
VERSIONED_CONTRACT_ABIS[ContractAbi.PANTOS_TOKEN],
node_connections)
except Exception:
raise self._create_error(
'unable to create a token contract instance')
Expand All @@ -241,4 +245,4 @@ def __sign_message(self, private_key: PrivateKey,
message = eth_account.messages.encode_defunct(base_message)
signed_message = web3.Account.sign_message(message,
private_key=private_key)
return signed_message.signature.hex()
return signed_message.signature.to_0x_hex()
Loading

0 comments on commit 5caad61

Please sign in to comment.