Skip to content

Commit

Permalink
Deal with non-sandwitch-encoding raiden-contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
pirapira committed Jul 2, 2019
1 parent 5cb5d04 commit 36c09a8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
5 changes: 4 additions & 1 deletion raiden/network/proxies/secret_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
encode_hex,
event_abi_to_log_topic,
is_binary_address,
to_bytes,
to_checksum_address,
to_normalized_address,
)
Expand Down Expand Up @@ -53,7 +54,9 @@ def __init__(self, jsonrpc_client, secret_registry_address, contract_manager: Co
jsonrpc_client,
secret_registry_address,
CONTRACT_SECRET_REGISTRY,
expected_code=contract_manager.get_runtime_hexcode(CONTRACT_SECRET_REGISTRY),
expected_code=to_bytes(
hexstr=contract_manager.get_runtime_hexcode(CONTRACT_SECRET_REGISTRY)
),
)

proxy = jsonrpc_client.new_contract_proxy(
Expand Down
6 changes: 4 additions & 2 deletions raiden/network/proxies/service_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import structlog
import web3
from eth_utils import is_binary_address, to_canonical_address, to_checksum_address
from eth_utils import is_binary_address, to_bytes, to_canonical_address, to_checksum_address

from raiden.exceptions import BrokenPreconditionError, InvalidAddress, RaidenUnrecoverableError
from raiden.network.proxies.utils import log_transaction
Expand Down Expand Up @@ -30,7 +30,9 @@ def __init__(
jsonrpc_client,
service_registry_address,
CONTRACT_SERVICE_REGISTRY,
expected_code=contract_manager.get_runtime_hexcode(CONTRACT_SERVICE_REGISTRY),
expected_code=to_bytes(
hexstr=contract_manager.get_runtime_hexcode(CONTRACT_SERVICE_REGISTRY)
),
)

proxy = jsonrpc_client.new_contract_proxy(
Expand Down
5 changes: 4 additions & 1 deletion raiden/network/proxies/token_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from eth_utils import (
encode_hex,
is_binary_address,
to_bytes,
to_canonical_address,
to_checksum_address,
to_hex,
Expand Down Expand Up @@ -157,7 +158,9 @@ def __init__(
jsonrpc_client,
Address(token_network_address),
CONTRACT_TOKEN_NETWORK,
expected_code=contract_manager.get_runtime_hexcode(CONTRACT_TOKEN_NETWORK),
expected_code=to_bytes(
hexstr=contract_manager.get_runtime_hexcode(CONTRACT_TOKEN_NETWORK)
),
)

self.contract_manager = contract_manager
Expand Down
5 changes: 4 additions & 1 deletion raiden/network/proxies/token_network_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
event_abi_to_log_topic,
is_binary_address,
is_same_address,
to_bytes,
to_canonical_address,
to_checksum_address,
to_normalized_address,
Expand Down Expand Up @@ -59,7 +60,9 @@ def __init__(
client=jsonrpc_client,
address=Address(registry_address),
contract_name=CONTRACT_TOKEN_NETWORK_REGISTRY,
expected_code=contract_manager.get_runtime_hexcode(CONTRACT_TOKEN_NETWORK_REGISTRY),
expected_code=to_bytes(
hexstr=contract_manager.get_runtime_hexcode(CONTRACT_TOKEN_NETWORK_REGISTRY)
),
)

self.contract_manager = contract_manager
Expand Down
5 changes: 4 additions & 1 deletion raiden/network/proxies/user_deposit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import structlog
from eth_utils import (
is_binary_address,
to_bytes,
to_canonical_address,
to_checksum_address,
to_normalized_address,
Expand Down Expand Up @@ -50,7 +51,9 @@ def __init__(
jsonrpc_client,
Address(user_deposit_address),
CONTRACT_USER_DEPOSIT,
expected_code=contract_manager.get_runtime_hexcode(CONTRACT_USER_DEPOSIT),
expected_code=to_bytes(
hexstr=contract_manager.get_runtime_hexcode(CONTRACT_USER_DEPOSIT)
),
)

self.client = jsonrpc_client
Expand Down
13 changes: 7 additions & 6 deletions raiden/network/rpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,26 +168,27 @@ def geth_discover_next_available_nonce(web3: Web3, address: AddressHex) -> Nonce


def check_address_has_code(
client: "JSONRPCClient", address: Address, contract_name: str = "", expected_code: str = None
client: "JSONRPCClient", address: Address, contract_name: str = "", expected_code: bytes = None
):
""" Checks that the given address contains code. """
result = client.web3.eth.getCode(to_checksum_address(address), "latest")

if not result:
def formatted_contract_name():
if contract_name:
formated_contract_name = f"[{contract_name}]: "
return f"[{contract_name}]: "
else:
formated_contract_name = ""
return ""

if not result:
raise AddressWithoutCode(
"{}Address {} does not contain code".format(
formated_contract_name, to_checksum_address(address)
formatted_contract_name(), to_checksum_address(address)
)
)

if expected_code is not None and result != expected_code:
raise ContractCodeMismatch(
f"{formated_contract_name}Address {to_checksum_address(address)} has wrong code."
f"{formatted_contract_name()}Address {to_checksum_address(address)} has wrong code."
)


Expand Down

0 comments on commit 36c09a8

Please sign in to comment.