substrate-interface 1.7.8__tar.gz → 1.7.10__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. {substrate-interface-1.7.8/substrate_interface.egg-info → substrate-interface-1.7.10}/PKG-INFO +1 -1
  2. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/setup.py +1 -1
  3. {substrate-interface-1.7.8 → substrate-interface-1.7.10/substrate_interface.egg-info}/PKG-INFO +1 -1
  4. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrate_interface.egg-info/requires.txt +1 -1
  5. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrateinterface/base.py +15 -2
  6. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrateinterface/contracts.py +27 -2
  7. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/test/test_contracts.py +54 -0
  8. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/test/test_create_extrinsics.py +2 -2
  9. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/LICENSE +0 -0
  10. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/README.md +0 -0
  11. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/setup.cfg +0 -0
  12. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrate_interface.egg-info/SOURCES.txt +0 -0
  13. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrate_interface.egg-info/dependency_links.txt +0 -0
  14. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrate_interface.egg-info/top_level.txt +0 -0
  15. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrateinterface/__init__.py +0 -0
  16. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrateinterface/constants.py +0 -0
  17. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrateinterface/exceptions.py +0 -0
  18. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrateinterface/extensions.py +0 -0
  19. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrateinterface/interfaces.py +0 -0
  20. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrateinterface/key.py +0 -0
  21. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrateinterface/keypair.py +0 -0
  22. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrateinterface/storage.py +0 -0
  23. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrateinterface/utils/__init__.py +0 -0
  24. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrateinterface/utils/caching.py +0 -0
  25. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrateinterface/utils/ecdsa_helpers.py +0 -0
  26. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrateinterface/utils/encrypted_json.py +0 -0
  27. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrateinterface/utils/hasher.py +0 -0
  28. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/substrateinterface/utils/ss58.py +0 -0
  29. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/test/test_block.py +0 -0
  30. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/test/test_extension_interface.py +0 -0
  31. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/test/test_helper_functions.py +0 -0
  32. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/test/test_init.py +0 -0
  33. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/test/test_keypair.py +0 -0
  34. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/test/test_query.py +0 -0
  35. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/test/test_query_map.py +0 -0
  36. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/test/test_rpc_compatibility.py +0 -0
  37. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/test/test_runtime_call.py +0 -0
  38. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/test/test_ss58.py +0 -0
  39. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/test/test_subscriptions.py +0 -0
  40. {substrate-interface-1.7.8 → substrate-interface-1.7.10}/test/test_type_registry.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: substrate-interface
3
- Version: 1.7.8
3
+ Version: 1.7.10
4
4
  Summary: Library for interfacing with a Substrate node
5
5
  Home-page: https://github.com/polkascan/py-substrate-interface
6
6
  Author: Stichting Polkascan (Polkascan Foundation)
@@ -188,7 +188,7 @@ setup(
188
188
  'eth_utils>=1.3.0,<3',
189
189
  'pycryptodome>=3.11.0,<4',
190
190
  'PyNaCl>=1.0.1,<2',
191
- 'scalecodec>=1.2.8,<1.3',
191
+ 'scalecodec>=1.2.10,<1.3',
192
192
  'py-sr25519-bindings>=0.2.0,<1',
193
193
  'py-ed25519-zebra-bindings>=1.0,<2',
194
194
  'py-bip39-bindings>=0.1.9,<1'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: substrate-interface
3
- Version: 1.7.8
3
+ Version: 1.7.10
4
4
  Summary: Library for interfacing with a Substrate node
5
5
  Home-page: https://github.com/polkascan/py-substrate-interface
6
6
  Author: Stichting Polkascan (Polkascan Foundation)
@@ -9,7 +9,7 @@ eth-keys<1,>=0.2.1
9
9
  eth_utils<3,>=1.3.0
10
10
  pycryptodome<4,>=3.11.0
11
11
  PyNaCl<2,>=1.0.1
12
- scalecodec<1.3,>=1.2.8
12
+ scalecodec<1.3,>=1.2.10
13
13
  py-sr25519-bindings<1,>=0.2.0
14
14
  py-ed25519-zebra-bindings<2,>=1.0
15
15
  py-bip39-bindings<1,>=0.1.9
@@ -1490,6 +1490,11 @@ class SubstrateInterface:
1490
1490
  ['asset_id', signed_extensions['ChargeAssetTxPayment']['extrinsic']]
1491
1491
  )
1492
1492
 
1493
+ if 'CheckMetadataHash' in signed_extensions:
1494
+ signature_payload.type_mapping.append(
1495
+ ['mode', signed_extensions['CheckMetadataHash']['extrinsic']]
1496
+ )
1497
+
1493
1498
  if 'CheckSpecVersion' in signed_extensions:
1494
1499
  signature_payload.type_mapping.append(
1495
1500
  ['spec_version', signed_extensions['CheckSpecVersion']['additional_signed']]
@@ -1515,6 +1520,11 @@ class SubstrateInterface:
1515
1520
  ['block_hash', signed_extensions['CheckEra']['additional_signed']]
1516
1521
  )
1517
1522
 
1523
+ if 'CheckMetadataHash' in signed_extensions:
1524
+ signature_payload.type_mapping.append(
1525
+ ['metadata_hash', signed_extensions['CheckMetadataHash']['additional_signed']]
1526
+ )
1527
+
1518
1528
  if include_call_length:
1519
1529
 
1520
1530
  length_obj = self.runtime_config.create_scale_object('Bytes')
@@ -1532,7 +1542,9 @@ class SubstrateInterface:
1532
1542
  'genesis_hash': genesis_hash,
1533
1543
  'block_hash': block_hash,
1534
1544
  'transaction_version': self.transaction_version,
1535
- 'asset_id': {'tip': tip, 'asset_id': tip_asset_id}
1545
+ 'asset_id': {'tip': tip, 'asset_id': tip_asset_id},
1546
+ 'metadata_hash': None,
1547
+ 'mode': 'Disabled'
1536
1548
  }
1537
1549
 
1538
1550
  signature_payload.encode(payload_dict)
@@ -1624,7 +1636,8 @@ class SubstrateInterface:
1624
1636
  'nonce': nonce,
1625
1637
  'era': era,
1626
1638
  'tip': tip,
1627
- 'asset_id': {'tip': tip, 'asset_id': tip_asset_id}
1639
+ 'asset_id': {'tip': tip, 'asset_id': tip_asset_id},
1640
+ 'mode': 'Disabled'
1628
1641
  }
1629
1642
 
1630
1643
  # Check if ExtrinsicSignature is MultiSignature, otherwise omit signature_version
@@ -90,7 +90,7 @@ class ContractMetadata:
90
90
  elif 'version' in self.metadata_dict:
91
91
  self.metadata_version = int(self.metadata_dict['version'])
92
92
 
93
- if self.metadata_version is None or self.metadata_version > 4:
93
+ if self.metadata_version is None or self.metadata_version > 5:
94
94
  raise ContractMetadataParseException("Unsupported metadata version")
95
95
 
96
96
  if 1 <= self.metadata_version <= 3:
@@ -126,6 +126,13 @@ class ContractMetadata:
126
126
  for idx, c in enumerate(self.metadata_dict['spec']['constructors']):
127
127
  c["payable"] = True
128
128
 
129
+ # V4 -> V5: new event fields: module_path and signature_topic
130
+ if self.metadata_version <= 4:
131
+ for idx, c in enumerate(self.metadata_dict['spec']['events']):
132
+ c["module_path"] = None
133
+ c["signature_topic"] = None
134
+
135
+
129
136
  def __parse_metadata(self):
130
137
 
131
138
  self.__convert_to_latest_metadata()
@@ -392,6 +399,13 @@ class ContractMetadata:
392
399
 
393
400
  return self.metadata_dict['spec']['events'][event_id]
394
401
 
402
+ def get_event_id_by_topic(self, topic: str) -> Optional[int]:
403
+ for event_id, event in enumerate(self.metadata_dict['spec']['events']):
404
+ if topic == event['signature_topic']:
405
+ return event_id
406
+
407
+ # raise ValueError(f'Contract event for topic "{topic}" not found')
408
+
395
409
 
396
410
  class ContractEvent(ScaleType):
397
411
 
@@ -485,9 +499,20 @@ class ContractExecutionReceipt(ExtrinsicReceipt):
485
499
 
486
500
  if self.substrate.implements_scaleinfo():
487
501
  if event.value['module_id'] == 'Contracts' and event.value['event_id'] == 'ContractEmitted' and event.value['attributes']['contract'] == self.contract_address:
502
+
503
+ contract_data = event['event'][1][1]['data'].value_object
504
+
505
+ if self.contract_metadata.metadata_version >= 5:
506
+ # Find corresponding contract event by event topic
507
+ for topic in event.value['topics']:
508
+ event_id = self.contract_metadata.get_event_id_by_topic(topic)
509
+ if event_id is not None:
510
+ event_bytes = self.substrate.create_scale_object("U8").encode(event_id).data
511
+ contract_data = event_bytes + contract_data
512
+
488
513
  # Create contract event
489
514
  contract_event_obj = ContractEvent(
490
- data=ScaleBytes(event['event'][1][1]['data'].value_object),
515
+ data=ScaleBytes(contract_data),
491
516
  runtime_config=self.substrate.runtime_config,
492
517
  contract_metadata=self.contract_metadata
493
518
  )
@@ -409,5 +409,59 @@ class FlipperInstanceV4TestCase(FlipperInstanceTestCase):
409
409
  )
410
410
 
411
411
 
412
+ class FlipperInstanceV5TestCase(FlipperInstanceTestCase):
413
+
414
+ @classmethod
415
+ def setUpClass(cls):
416
+
417
+ class MockedSubstrateInterface(SubstrateInterface):
418
+
419
+ def rpc_request(self, method, params, result_handler=None):
420
+ if method == 'state_call':
421
+ return {
422
+ 'jsonrpc': '2.0',
423
+ 'result': '0x1a987a663dbd8e5cf16786bc0100010000000000000000000000000000000000000000000008000000',
424
+ 'id': 16
425
+ }
426
+ if method == 'contracts_call':
427
+ return {
428
+ 'jsonrpc': '2.0',
429
+ 'result': {
430
+ 'gasConsumed': 7419127834,
431
+ 'gasRequired': 74999922688,
432
+ 'storageDeposit': {'charge': '0x0'},
433
+ 'debugMessage': '',
434
+ 'result': {'Ok': {'flags': 0, 'data': '0x0000'}}
435
+ },
436
+ 'id': self.request_id}
437
+
438
+ return super().rpc_request(method, params, result_handler)
439
+
440
+ cls.substrate = MockedSubstrateInterface(
441
+ url=settings.KUSAMA_NODE_URL, type_registry_preset='canvas', type_registry={'types': {"ContractExecResult": "ContractExecResultTo269"}}
442
+ )
443
+
444
+ cls.keypair = Keypair.create_from_uri('//Alice')
445
+
446
+ def setUp(self) -> None:
447
+ self.contract = ContractInstance.create_from_address(
448
+ contract_address="5DaohteAvvR9PZEhynqWvbFT8HEaHNuiiPTZV61VEUHnqsfU",
449
+ metadata_file=os.path.join(os.path.dirname(__file__), 'fixtures', 'flipper-v5.json'),
450
+ substrate=self.substrate
451
+ )
452
+
453
+ def test_instance_read(self):
454
+
455
+ result = self.contract.read(self.keypair, 'get')
456
+
457
+ self.assertEqual({'Ok': False}, result.contract_result_data.value)
458
+
459
+ def test_instance_read_at_not_best_block(self):
460
+ parent_hash = self.substrate.get_block_header()['header']['parentHash']
461
+ result = self.contract.read(self.keypair, 'get', block_hash=parent_hash)
462
+
463
+ self.assertEqual({'Ok': False}, result.contract_result_data.value)
464
+
465
+
412
466
  if __name__ == '__main__':
413
467
  unittest.main()
@@ -192,7 +192,7 @@ class CreateExtrinsicsTestCase(unittest.TestCase):
192
192
  call_module='System',
193
193
  call_function='remark',
194
194
  call_params={
195
- 'remark': '0x' + ('01' * 177)
195
+ 'remark': '0x' + ('01' * 175)
196
196
  }
197
197
  )
198
198
 
@@ -206,7 +206,7 @@ class CreateExtrinsicsTestCase(unittest.TestCase):
206
206
  call_module='System',
207
207
  call_function='remark',
208
208
  call_params={
209
- 'remark': '0x' + ('01' * 178)
209
+ 'remark': '0x' + ('01' * 176)
210
210
  }
211
211
  )
212
212