Skip to content

Commit

Permalink
CheckMetadataHash signed extension support (#392)
Browse files Browse the repository at this point in the history
Only allow mode is `Disabled` for now, but ensures compatibility with upcoming Kusama/Polkadot release.
  • Loading branch information
arjanz authored Jun 11, 2024
1 parent 18e5fef commit a9b4f6e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
17 changes: 15 additions & 2 deletions substrateinterface/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']]
Expand All @@ -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')
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/test_create_extrinsics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
)

Expand All @@ -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)
}
)

Expand Down

0 comments on commit a9b4f6e

Please sign in to comment.