From a9b4f6eec90ad9cd850da9fa812fa5f85e6b30a4 Mon Sep 17 00:00:00 2001 From: Arjan Zijderveld <5286904+arjanz@users.noreply.github.com> Date: Tue, 11 Jun 2024 17:04:57 +0200 Subject: [PATCH] CheckMetadataHash signed extension support (#392) Only allow mode is `Disabled` for now, but ensures compatibility with upcoming Kusama/Polkadot release. --- requirements.txt | 2 +- setup.py | 2 +- substrateinterface/base.py | 17 +++++++++++++++-- test/test_create_extrinsics.py | 4 ++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index 48ae6ea..9e9e112 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,7 +11,7 @@ eth_utils>=1.3.0,<5 pycryptodome>=3.11.0,<4 PyNaCl>=1.0.1,<2 -scalecodec>=1.2.8,<1.3 +scalecodec>=1.2.10,<1.3 py-sr25519-bindings>=0.2.0,<1 py-ed25519-zebra-bindings>=1.0,<2 py-bip39-bindings>=0.1.9,<1 diff --git a/setup.py b/setup.py index 6bd879b..8e87194 100644 --- a/setup.py +++ b/setup.py @@ -188,7 +188,7 @@ 'eth_utils>=1.3.0,<3', 'pycryptodome>=3.11.0,<4', 'PyNaCl>=1.0.1,<2', - 'scalecodec>=1.2.8,<1.3', + 'scalecodec>=1.2.10,<1.3', 'py-sr25519-bindings>=0.2.0,<1', 'py-ed25519-zebra-bindings>=1.0,<2', 'py-bip39-bindings>=0.1.9,<1' diff --git a/substrateinterface/base.py b/substrateinterface/base.py index 7e9316d..ae4d497 100644 --- a/substrateinterface/base.py +++ b/substrateinterface/base.py @@ -1490,6 +1490,11 @@ def generate_signature_payload(self, call: GenericCall, era=None, nonce: int = 0 ['asset_id', signed_extensions['ChargeAssetTxPayment']['extrinsic']] ) + if 'CheckMetadataHash' in signed_extensions: + signature_payload.type_mapping.append( + ['mode', signed_extensions['CheckMetadataHash']['extrinsic']] + ) + if 'CheckSpecVersion' in signed_extensions: signature_payload.type_mapping.append( ['spec_version', signed_extensions['CheckSpecVersion']['additional_signed']] @@ -1515,6 +1520,11 @@ def generate_signature_payload(self, call: GenericCall, era=None, nonce: int = 0 ['block_hash', signed_extensions['CheckEra']['additional_signed']] ) + if 'CheckMetadataHash' in signed_extensions: + signature_payload.type_mapping.append( + ['metadata_hash', signed_extensions['CheckMetadataHash']['additional_signed']] + ) + if include_call_length: length_obj = self.runtime_config.create_scale_object('Bytes') @@ -1532,7 +1542,9 @@ def generate_signature_payload(self, call: GenericCall, era=None, nonce: int = 0 'genesis_hash': genesis_hash, 'block_hash': block_hash, 'transaction_version': self.transaction_version, - 'asset_id': {'tip': tip, 'asset_id': tip_asset_id} + 'asset_id': {'tip': tip, 'asset_id': tip_asset_id}, + 'metadata_hash': None, + 'mode': 'Disabled' } signature_payload.encode(payload_dict) @@ -1624,7 +1636,8 @@ def create_signed_extrinsic( 'nonce': nonce, 'era': era, 'tip': tip, - 'asset_id': {'tip': tip, 'asset_id': tip_asset_id} + 'asset_id': {'tip': tip, 'asset_id': tip_asset_id}, + 'mode': 'Disabled' } # Check if ExtrinsicSignature is MultiSignature, otherwise omit signature_version diff --git a/test/test_create_extrinsics.py b/test/test_create_extrinsics.py index 7bf026b..3630399 100644 --- a/test/test_create_extrinsics.py +++ b/test/test_create_extrinsics.py @@ -192,7 +192,7 @@ def test_generate_signature_payload_lte_256_bytes(self): call_module='System', call_function='remark', call_params={ - 'remark': '0x' + ('01' * 177) + 'remark': '0x' + ('01' * 175) } ) @@ -206,7 +206,7 @@ def test_generate_signature_payload_gt_256_bytes(self): call_module='System', call_function='remark', call_params={ - 'remark': '0x' + ('01' * 178) + 'remark': '0x' + ('01' * 176) } )