Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions packages/snet_cli/snet/snet_cli/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
from pathlib import Path, PurePath

import web3
import pkg_resources

import importlib.resources
from importlib.metadata import distribution

import grpc
from grpc_tools.protoc import main as protoc

Expand Down Expand Up @@ -72,7 +75,7 @@ def serializable(o):


def safe_address_converter(a):
if not web3.eth.is_checksum_address(a):
if not web3.is_checksum_address(a):
raise Exception("%s is not is not a valid Ethereum checksum address" % a)
return a

Expand All @@ -82,12 +85,12 @@ def type_converter(t):
return lambda x: list(map(type_converter(t.replace("[]", "")), json.loads(x)))
else:
if "int" in t:
return lambda x: web3.Web3.toInt(text=x)
return lambda x: web3.Web3.to_int(text=x)
elif "bytes32" in t:
return lambda x: web3.Web3.toBytes(text=x).ljust(32, b"\0") if not x.startswith(
"0x") else web3.Web3.toBytes(hexstr=x).ljust(32, b"\0")
return lambda x: web3.Web3.to_bytes(text=x).ljust(32, b"\0") if not x.startswith(
"0x") else web3.Web3.to_bytes(hexstr=x).ljust(32, b"\0")
elif "byte" in t:
return lambda x: web3.Web3.toBytes(text=x) if not x.startswith("0x") else web3.Web3.toBytes(hexstr=x)
return lambda x: web3.Web3.to_bytes(text=x) if not x.startswith("0x") else web3.Web3.toBytes(hexstr=x)
elif "address" in t:
return safe_address_converter
else:
Expand Down Expand Up @@ -150,14 +153,14 @@ def read_temp_tar(f):


def get_cli_version():
return pkg_resources.get_distribution("snet-cli").version
return distribution("snet-cli").version


def compile_proto(entry_path, codegen_dir, proto_file=None, target_language="python"):
try:
if not os.path.exists(codegen_dir):
os.makedirs(codegen_dir)
proto_include = pkg_resources.resource_filename('grpc_tools', '_proto')
proto_include = importlib.resources.files('grpc_tools') / '_proto'

compiler_args = [
"-I{}".format(entry_path),
Expand Down Expand Up @@ -310,7 +313,7 @@ def normalize_private_key(private_key):


def get_address_from_private(private_key):
return web3.eth.Account.privateKeyToAccount(private_key).address
return web3.eth.Account.from_key(private_key).address


class add_to_path():
Expand Down
7 changes: 3 additions & 4 deletions packages/snet_cli/snet_cli/commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
LedgerIdentityProvider, KeyIdentityProvider, KeyStoreIdentityProvider
from snet_cli.identity import get_kws_for_identity_type
from snet_cli.utils.config import get_contract_address, get_field_from_args_or_session, read_default_contract_address
from web3.eth import is_checksum_address
from web3.gas_strategies.time_based import fast_gas_price_strategy, medium_gas_price_strategy, slow_gas_price_strategy
import web3


class Command(object):
Expand Down Expand Up @@ -501,7 +500,7 @@ def get_members_from_args(self):
members = [m.replace("[", "").replace("]", "")
for m in self.args.members.split(',')]
for m in members:
if not is_checksum_address(m):
if not web3.Web3.is_checksum_address(m):
raise Exception(
"Member account %s is not a valid Ethereum checksum address" % m)
return members
Expand Down Expand Up @@ -652,7 +651,7 @@ def change_owner(self):
self.error_organization_not_found(org_id, found)

new_owner = self.args.owner
if not is_checksum_address(new_owner):
if not web3.Web3.is_checksum_address(new_owner):
raise Exception(
"New owner account %s is not a valid Ethereum checksum address" % new_owner)

Expand Down
5 changes: 2 additions & 3 deletions packages/snet_cli/snet_cli/commands/mpe_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
type_converter
from snet_cli.commands.commands import OrganizationCommand
from snet_cli.utils.agi2cogs import cogs2stragi
from web3.utils.encoding import pad_hex
from web3.utils.events import get_event_data

from web3._utils.encoding import pad_hex
from web3._utils.events import get_event_data

# we inherit MPEServiceCommand because we need _get_service_metadata_from_registry
class MPEChannelCommand(OrganizationCommand):
Expand Down
14 changes: 10 additions & 4 deletions packages/snet_cli/snet_cli/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@
import time
import getpass

import web3
from pycoin.key.BIP32Node import BIP32Node
import rlp
from eth_account.internal.transactions import serializable_unsigned_transaction_from_dict, encode_transaction, \

from eth_account._utils.legacy_transactions import (
serializable_unsigned_transaction_from_dict,
encode_transaction,
UnsignedTransaction
)

from eth_account.messages import defunct_hash_message
from mnemonic import Mnemonic
from trezorlib.client import TrezorClient, proto
from trezorlib.transport_hid import HidTransport

from trezorlib.client import TrezorClient
from trezorlib import messages as proto
from trezorlib.transport.hid import HidTransport

from ledgerblue.comm import getDongle
from ledgerblue.commException import CommException
Expand Down