Skip to content

Commit

Permalink
Upgrade scalecodec to 1.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
ravi-ojha committed Oct 14, 2021
1 parent 288cc0c commit bcf45e0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ py-sr25519-bindings==0.1.1
pytest==5.4.1
pytest-mock==3.1.0
python-dotenv==0.13.0
scalecodec==0.11.23
scalecodec==1.0.9
#-e git+https://github.com/CodeForcer/py-scale-codec.git@patch#egg=scalecodec
websockets==8.1
xxhash==1.4.3
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
EMAIL = "[email protected]"
AUTHOR = "Nathan Worsley"
REQUIRES_PYTHON = ">=3.7.0"
VERSION = "0.2.43"
VERSION = "1.0.0"

REQUIRED = [
"websockets==8.1",
"scalecodec==0.11.23",
"scalecodec==1.0.9",
"base58==2.0.1",
"py-bip39-bindings==0.1.6",
"py-sr25519-bindings==0.1.1",
Expand Down
28 changes: 18 additions & 10 deletions substrateutils/cores.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
from scalecodec import ScaleBytes
from scalecodec.base import RuntimeConfigurationObject
from scalecodec.base import ScaleDecoder
from scalecodec.block import ExtrinsicsDecoder
from scalecodec.metadata import MetadataDecoder
from scalecodec.type_registry import load_type_registry_preset
from scalecodec.types import Extrinsic
from scalecodec.updater import update_type_registries
from scalecodec.utils.ss58 import ss58_decode
from scalecodec.utils.ss58 import ss58_encode
Expand All @@ -29,8 +28,10 @@ def __init__(

def load_type_registry(self):
runtime_config = RuntimeConfigurationObject()
runtime_config.update_type_registry(load_type_registry_preset("metadata_types"))
runtime_config.update_type_registry(load_type_registry_preset("default"))
runtime_config.update_type_registry(load_type_registry_preset(self.chain))
runtime_config.set_active_spec_version_id(self.spec_version)
self.runtime_config = runtime_config

def connect(self, *, node_url: str = "", network: "Network" = None):
Expand Down Expand Up @@ -64,23 +65,27 @@ def runtime_info(self) -> int:
transaction version
"""
result = self.network.node_rpc_call("state_getRuntimeVersion", [])
self.spec_version = result["result"]["specVersion"]
self.transaction_version = result["result"]["transactionVersion"]
return result["result"]

def get_metadata(self) -> "MetadataDecoder":
def get_metadata(self):
"""
Returns decoded chain metadata
"""
raw_metadata = self.network.node_rpc_call("state_getMetadata", [None])["result"]
self.raw_metadata = raw_metadata
metadata = MetadataDecoder(ScaleBytes(raw_metadata))
metadata = self.runtime_config.create_scale_object(
"MetadataVersioned", data=ScaleBytes(raw_metadata)
)
metadata.decode()
return metadata

def get_json_metadata(self) -> dict:
raw_metadata = self.network.node_rpc_call("state_getMetadata", [None])["result"]
return MetadataDecoder(ScaleBytes(raw_metadata)).decode()
metadata = self.runtime_config.create_scale_object(
"MetadataVersioned", data=ScaleBytes(raw_metadata)
)
return metadata.decode()[1]

def get_failure_reason(self, module: int, error: int) -> str:
"""
Expand Down Expand Up @@ -171,13 +176,14 @@ def get_block(self, block_hash: str) -> dict:
)

for idx, data in enumerate(response["block"]["extrinsics"]):
extrinsic_decoder = ExtrinsicsDecoder(
extrinsics_decoder = Extrinsic(
data=ScaleBytes(data),
metadata=self.metadata,
runtime_config=self.runtime_config,
)
extrinsic_decoder.decode()
response["block"]["extrinsics"][idx] = extrinsic_decoder.value

extrinsic = extrinsics_decoder.decode()
response["block"]["extrinsics"][idx] = extrinsic.value

return response

Expand Down Expand Up @@ -265,7 +271,7 @@ def get_pending_extrinsics(self) -> list:
]

for idx, extrinsic in enumerate(extrinsics):
extrinsic_decoder = ExtrinsicsDecoder(
extrinsic_decoder = Extrinsic(
data=ScaleBytes(extrinsic),
metadata=self.metadata,
runtime_config=self.runtime_config,
Expand Down Expand Up @@ -585,6 +591,7 @@ def __init__(
arbitrator_key: str = None,
):
self.chain = "kusama"
self.spec_version = 9111
self.address_type = 2
self.max_weight = 190949000
self.welfare_value = 4000000000 # 0.004 KSM
Expand All @@ -596,6 +603,7 @@ def __init__(
self, *, node_url: str = "wss://rpc.polkadot.io/", arbitrator_key: str = None,
):
self.chain = "polkadot"
self.spec_version = 9110
self.address_type = 0
self.max_weight = 648378000
self.welfare_value = 400000000 # 0.04 DOT
Expand Down
11 changes: 5 additions & 6 deletions substrateutils/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import xxhash
from scalecodec.base import RuntimeConfigurationObject
from scalecodec.base import ScaleDecoder
from scalecodec.metadata import MetadataDecoder
from scalecodec.utils.ss58 import ss58_decode
from scalecodec.utils.ss58 import ss58_encode

Expand Down Expand Up @@ -45,7 +44,7 @@ def hash_call(call: "scalecodec.types.Call") -> str:


def transfer_signature_payload(
metadata: "MetadataDecoder",
metadata,
address: str,
value: int,
nonce: int,
Expand Down Expand Up @@ -86,7 +85,7 @@ def transfer_signature_payload(


def as_multi_signature_payload(
metadata: "MetadataDecoder",
metadata,
spec_version: int,
genesis_hash: str,
nonce: int,
Expand Down Expand Up @@ -159,7 +158,7 @@ def as_multi_signature_payload(


def _extrinsic_construction(
metadata: "MetadataDecoder",
metadata,
account_id: str,
signature: str,
call_function: str,
Expand Down Expand Up @@ -193,7 +192,7 @@ def _extrinsic_construction(


def unsigned_transfer_construction(
metadata: "MetadataDecoder",
metadata,
account_id: str,
signature: str,
nonce: int,
Expand Down Expand Up @@ -222,7 +221,7 @@ def unsigned_transfer_construction(


def unsigned_as_multi_construction(
metadata: "MetadataDecoder",
metadata,
account_id: str,
signature: str,
nonce: int,
Expand Down

0 comments on commit bcf45e0

Please sign in to comment.