substrate-interface 1.7.10__tar.gz → 1.8.0__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.
- substrate_interface-1.8.0/PKG-INFO +125 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/README.md +13 -7
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/setup.py +6 -2
- substrate_interface-1.8.0/substrate_interface.egg-info/PKG-INFO +125 -0
- substrate_interface-1.8.0/substrate_interface.egg-info/SOURCES.txt +71 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrate_interface.egg-info/requires.txt +2 -1
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrateinterface/base.py +53 -121
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/ksmcc3.json +62 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/ksmcc3_asset_hub.json +44 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/ksmcc3_bridge_hub.json +46 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/ksmcc3_coretime.json +26 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/ksmcc3_encointer.json +43 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/ksmcc3_people.json +46 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/kusama.json +3494 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/paseo.json +42 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/paseo_asset_hub.json +24 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/paseo_coretime.json +22 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/paseo_people.json +32 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/polkadot.json +60 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/polkadot_asset_hub.json +42 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/polkadot_bridge_hub.json +44 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/polkadot_collectives.json +43 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/polkadot_coretime.json +29 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/polkadot_people.json +26 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/rococo_v2_2.json +30 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/rococo_v2_2_asset_hub.json +25 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/rococo_v2_2_bridge_hub.json +24 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/rococo_v2_2_people.json +26 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/westend2.json +54 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/westend2_asset_hub.json +42 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/westend2_bridge_hub.json +42 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/westend2_collectives.json +42 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/westend2_coretime.json +47 -0
- substrate_interface-1.8.0/substrateinterface/data/chainspecs/westend2_people.json +45 -0
- substrate_interface-1.8.0/substrateinterface/transport/__init__.py +11 -0
- substrate_interface-1.8.0/substrateinterface/transport/base.py +34 -0
- substrate_interface-1.8.0/substrateinterface/transport/http.py +34 -0
- substrate_interface-1.8.0/substrateinterface/transport/smoldot.py +121 -0
- substrate_interface-1.8.0/substrateinterface/transport/websocket.py +85 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/test/test_helper_functions.py +3 -4
- substrate_interface-1.8.0/test/test_light_client.py +46 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/test/test_query.py +1 -2
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/test/test_query_map.py +9 -13
- substrate-interface-1.7.10/PKG-INFO +0 -90
- substrate-interface-1.7.10/substrate_interface.egg-info/PKG-INFO +0 -90
- substrate-interface-1.7.10/substrate_interface.egg-info/SOURCES.txt +0 -38
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/LICENSE +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/setup.cfg +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrate_interface.egg-info/dependency_links.txt +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrate_interface.egg-info/top_level.txt +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrateinterface/__init__.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrateinterface/constants.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrateinterface/contracts.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrateinterface/exceptions.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrateinterface/extensions.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrateinterface/interfaces.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrateinterface/key.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrateinterface/keypair.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrateinterface/storage.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrateinterface/utils/__init__.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrateinterface/utils/caching.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrateinterface/utils/ecdsa_helpers.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrateinterface/utils/encrypted_json.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrateinterface/utils/hasher.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrateinterface/utils/ss58.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/test/test_block.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/test/test_contracts.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/test/test_create_extrinsics.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/test/test_extension_interface.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/test/test_init.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/test/test_keypair.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/test/test_rpc_compatibility.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/test/test_runtime_call.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/test/test_ss58.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/test/test_subscriptions.py +0 -0
- {substrate-interface-1.7.10 → substrate_interface-1.8.0}/test/test_type_registry.py +0 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: substrate-interface
|
|
3
|
+
Version: 1.8.0
|
|
4
|
+
Summary: Library for interfacing with a Substrate node
|
|
5
|
+
Home-page: https://github.com/polkascan/py-substrate-interface
|
|
6
|
+
Author: Stichting Polkascan (Polkascan Foundation)
|
|
7
|
+
Author-email: info@polkascan.org
|
|
8
|
+
Keywords: interface polkascan polkadot substrate blockchain rpc kusama
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Requires-Python: >=3.7, <4
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: websocket-client<2,>=0.57.0
|
|
22
|
+
Requires-Dist: base58<3,>=1.0.3
|
|
23
|
+
Requires-Dist: certifi>=2019.3.9
|
|
24
|
+
Requires-Dist: idna<4,>=2.1.0
|
|
25
|
+
Requires-Dist: requests<3,>=2.21.0
|
|
26
|
+
Requires-Dist: xxhash<4,>=1.3.0
|
|
27
|
+
Requires-Dist: ecdsa<1,>=0.17.0
|
|
28
|
+
Requires-Dist: eth-keys<1,>=0.2.1
|
|
29
|
+
Requires-Dist: eth_utils<6,>=1.3.0
|
|
30
|
+
Requires-Dist: pycryptodome<4,>=3.11.0
|
|
31
|
+
Requires-Dist: PyNaCl<2,>=1.0.1
|
|
32
|
+
Requires-Dist: scalecodec<1.3,>=1.2.10
|
|
33
|
+
Requires-Dist: py-sr25519-bindings<1,>=0.2.0
|
|
34
|
+
Requires-Dist: py-ed25519-zebra-bindings<2,>=1.0
|
|
35
|
+
Requires-Dist: py-bip39-bindings<1,>=0.1.9
|
|
36
|
+
Requires-Dist: smoldot-light<1,>=0.1.0
|
|
37
|
+
Provides-Extra: test
|
|
38
|
+
Requires-Dist: coverage; extra == "test"
|
|
39
|
+
Requires-Dist: pytest; extra == "test"
|
|
40
|
+
Dynamic: author
|
|
41
|
+
Dynamic: author-email
|
|
42
|
+
Dynamic: classifier
|
|
43
|
+
Dynamic: description
|
|
44
|
+
Dynamic: description-content-type
|
|
45
|
+
Dynamic: home-page
|
|
46
|
+
Dynamic: keywords
|
|
47
|
+
Dynamic: license-file
|
|
48
|
+
Dynamic: provides-extra
|
|
49
|
+
Dynamic: requires-dist
|
|
50
|
+
Dynamic: requires-python
|
|
51
|
+
Dynamic: summary
|
|
52
|
+
|
|
53
|
+
# Python Substrate Interface
|
|
54
|
+
|
|
55
|
+
[](https://github.com/JAMdotTech/py-polkadot-sdk/actions?query=workflow%3A%22Run+unit+tests%22)
|
|
56
|
+
[](https://pypi.org/project/substrate-interface/)
|
|
57
|
+
[](https://pypi.org/project/substrate-interface/)
|
|
58
|
+
[](https://github.com/JAMdotTech/py-polkadot-sdk/blob/master/LICENSE)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
## Description
|
|
62
|
+
This library specializes in interfacing with a [Substrate](https://substrate.io/) node; querying storage, composing extrinsics,
|
|
63
|
+
SCALE encoding/decoding and providing additional convenience methods to deal with the features and metadata of
|
|
64
|
+
the Substrate runtime.
|
|
65
|
+
|
|
66
|
+
## Documentation
|
|
67
|
+
|
|
68
|
+
* [Library documentation](https://jamdottech.github.io/py-polkadot-sdk/)
|
|
69
|
+
* [Metadata documentation for Polkadot and Kusama ecosystem runtimes](https://jamdottech.github.io/py-polkadot-metadata-docs/)
|
|
70
|
+
|
|
71
|
+
## Installation
|
|
72
|
+
```bash
|
|
73
|
+
pip install substrate-interface
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Initialization
|
|
77
|
+
|
|
78
|
+
Using embedded light client
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
substrate = SubstrateInterface(chainspec="polkadot_asset_hub", relay_chainspecs=["polkadot"])
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Using node RPC endpoint
|
|
85
|
+
```python
|
|
86
|
+
substrate = SubstrateInterface(url="ws://127.0.0.1:9944")
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
After connecting certain properties like `ss58_format` will be determined automatically by querying the RPC node. At
|
|
90
|
+
the moment this will work for most `MetadataV14` and above runtimes like Polkadot, Kusama, Acala, Moonbeam. For
|
|
91
|
+
older or runtimes under development the `ss58_format` (default 42) and other properties should be set manually.
|
|
92
|
+
|
|
93
|
+
## Quick usage
|
|
94
|
+
|
|
95
|
+
### Balance information of an account
|
|
96
|
+
```python
|
|
97
|
+
result = substrate.query('System', 'Account', ['F4xQKRUagnSGjFqafyhajLs94e7Vvzvr8ebwYJceKpr8R7T'])
|
|
98
|
+
print(result.value['data']['free']) # 635278638077956496
|
|
99
|
+
```
|
|
100
|
+
### Create balance transfer extrinsic
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
call = substrate.compose_call(
|
|
104
|
+
call_module='Balances',
|
|
105
|
+
call_function='transfer',
|
|
106
|
+
call_params={
|
|
107
|
+
'dest': '5E9oDs9PjpsBbxXxRE9uMaZZhnBAV38n2ouLB28oecBDdeQo',
|
|
108
|
+
'value': 1 * 10**12
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
keypair = Keypair.create_from_uri('//Alice')
|
|
113
|
+
extrinsic = substrate.create_signed_extrinsic(call=call, keypair=keypair)
|
|
114
|
+
|
|
115
|
+
receipt = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=True)
|
|
116
|
+
|
|
117
|
+
print(f"Extrinsic '{receipt.extrinsic_hash}' sent and included in block '{receipt.block_hash}'")
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Contact and Support
|
|
121
|
+
|
|
122
|
+
For questions, please see the [Substrate StackExchange](https://substrate.stackexchange.com/questions/tagged/python) or [Github Discussions](https://github.com/JAMdotTech/py-polkadot-sdk/discussions).
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
https://github.com/JAMdotTech/py-polkadot-sdk/blob/master/LICENSE
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# Python Substrate Interface
|
|
2
2
|
|
|
3
|
-
[](https://github.com/
|
|
3
|
+
[](https://github.com/JAMdotTech/py-polkadot-sdk/actions?query=workflow%3A%22Run+unit+tests%22)
|
|
4
4
|
[](https://pypi.org/project/substrate-interface/)
|
|
5
5
|
[](https://pypi.org/project/substrate-interface/)
|
|
6
|
-
[](https://github.com/
|
|
6
|
+
[](https://github.com/JAMdotTech/py-polkadot-sdk/blob/master/LICENSE)
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
## Description
|
|
@@ -13,8 +13,8 @@ the Substrate runtime.
|
|
|
13
13
|
|
|
14
14
|
## Documentation
|
|
15
15
|
|
|
16
|
-
* [Library documentation](https://
|
|
17
|
-
* [Metadata documentation for Polkadot and Kusama ecosystem runtimes](https://
|
|
16
|
+
* [Library documentation](https://jamdottech.github.io/py-polkadot-sdk/)
|
|
17
|
+
* [Metadata documentation for Polkadot and Kusama ecosystem runtimes](https://jamdottech.github.io/py-polkadot-metadata-docs/)
|
|
18
18
|
|
|
19
19
|
## Installation
|
|
20
20
|
```bash
|
|
@@ -23,6 +23,13 @@ pip install substrate-interface
|
|
|
23
23
|
|
|
24
24
|
## Initialization
|
|
25
25
|
|
|
26
|
+
Using embedded light client
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
substrate = SubstrateInterface(chainspec="polkadot_asset_hub", relay_chainspecs=["polkadot"])
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Using node RPC endpoint
|
|
26
33
|
```python
|
|
27
34
|
substrate = SubstrateInterface(url="ws://127.0.0.1:9944")
|
|
28
35
|
```
|
|
@@ -60,8 +67,7 @@ print(f"Extrinsic '{receipt.extrinsic_hash}' sent and included in block '{receip
|
|
|
60
67
|
|
|
61
68
|
## Contact and Support
|
|
62
69
|
|
|
63
|
-
For questions, please see the [Substrate StackExchange](https://substrate.stackexchange.com/questions/tagged/python)
|
|
64
|
-
reach out to us on our [matrix](http://matrix.org) chat group: [Polkascan Technical](https://matrix.to/#/#polkascan:matrix.org).
|
|
70
|
+
For questions, please see the [Substrate StackExchange](https://substrate.stackexchange.com/questions/tagged/python) or [Github Discussions](https://github.com/JAMdotTech/py-polkadot-sdk/discussions).
|
|
65
71
|
|
|
66
72
|
## License
|
|
67
|
-
https://github.com/
|
|
73
|
+
https://github.com/JAMdotTech/py-polkadot-sdk/blob/master/LICENSE
|
|
@@ -185,13 +185,14 @@ setup(
|
|
|
185
185
|
'xxhash>=1.3.0,<4',
|
|
186
186
|
'ecdsa>=0.17.0,<1',
|
|
187
187
|
'eth-keys>=0.2.1,<1',
|
|
188
|
-
'eth_utils>=1.3.0,<
|
|
188
|
+
'eth_utils>=1.3.0,<6',
|
|
189
189
|
'pycryptodome>=3.11.0,<4',
|
|
190
190
|
'PyNaCl>=1.0.1,<2',
|
|
191
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
|
-
'py-bip39-bindings>=0.1.9,<1'
|
|
194
|
+
'py-bip39-bindings>=0.1.9,<1',
|
|
195
|
+
'smoldot-light>=0.1.0,<1'
|
|
195
196
|
],
|
|
196
197
|
|
|
197
198
|
# List additional groups of dependencies here (e.g. development
|
|
@@ -216,6 +217,9 @@ setup(
|
|
|
216
217
|
# package_data={ # Optional
|
|
217
218
|
# 'sample': ['package_data.dat'],
|
|
218
219
|
# },
|
|
220
|
+
package_data={
|
|
221
|
+
'substrateinterface': ['data/chainspecs/*.json'],
|
|
222
|
+
},
|
|
219
223
|
|
|
220
224
|
# Although 'package_data' is the preferred approach, in some case you may
|
|
221
225
|
# need to place data files outside of your packages. See:
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: substrate-interface
|
|
3
|
+
Version: 1.8.0
|
|
4
|
+
Summary: Library for interfacing with a Substrate node
|
|
5
|
+
Home-page: https://github.com/polkascan/py-substrate-interface
|
|
6
|
+
Author: Stichting Polkascan (Polkascan Foundation)
|
|
7
|
+
Author-email: info@polkascan.org
|
|
8
|
+
Keywords: interface polkascan polkadot substrate blockchain rpc kusama
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Requires-Python: >=3.7, <4
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: websocket-client<2,>=0.57.0
|
|
22
|
+
Requires-Dist: base58<3,>=1.0.3
|
|
23
|
+
Requires-Dist: certifi>=2019.3.9
|
|
24
|
+
Requires-Dist: idna<4,>=2.1.0
|
|
25
|
+
Requires-Dist: requests<3,>=2.21.0
|
|
26
|
+
Requires-Dist: xxhash<4,>=1.3.0
|
|
27
|
+
Requires-Dist: ecdsa<1,>=0.17.0
|
|
28
|
+
Requires-Dist: eth-keys<1,>=0.2.1
|
|
29
|
+
Requires-Dist: eth_utils<6,>=1.3.0
|
|
30
|
+
Requires-Dist: pycryptodome<4,>=3.11.0
|
|
31
|
+
Requires-Dist: PyNaCl<2,>=1.0.1
|
|
32
|
+
Requires-Dist: scalecodec<1.3,>=1.2.10
|
|
33
|
+
Requires-Dist: py-sr25519-bindings<1,>=0.2.0
|
|
34
|
+
Requires-Dist: py-ed25519-zebra-bindings<2,>=1.0
|
|
35
|
+
Requires-Dist: py-bip39-bindings<1,>=0.1.9
|
|
36
|
+
Requires-Dist: smoldot-light<1,>=0.1.0
|
|
37
|
+
Provides-Extra: test
|
|
38
|
+
Requires-Dist: coverage; extra == "test"
|
|
39
|
+
Requires-Dist: pytest; extra == "test"
|
|
40
|
+
Dynamic: author
|
|
41
|
+
Dynamic: author-email
|
|
42
|
+
Dynamic: classifier
|
|
43
|
+
Dynamic: description
|
|
44
|
+
Dynamic: description-content-type
|
|
45
|
+
Dynamic: home-page
|
|
46
|
+
Dynamic: keywords
|
|
47
|
+
Dynamic: license-file
|
|
48
|
+
Dynamic: provides-extra
|
|
49
|
+
Dynamic: requires-dist
|
|
50
|
+
Dynamic: requires-python
|
|
51
|
+
Dynamic: summary
|
|
52
|
+
|
|
53
|
+
# Python Substrate Interface
|
|
54
|
+
|
|
55
|
+
[](https://github.com/JAMdotTech/py-polkadot-sdk/actions?query=workflow%3A%22Run+unit+tests%22)
|
|
56
|
+
[](https://pypi.org/project/substrate-interface/)
|
|
57
|
+
[](https://pypi.org/project/substrate-interface/)
|
|
58
|
+
[](https://github.com/JAMdotTech/py-polkadot-sdk/blob/master/LICENSE)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
## Description
|
|
62
|
+
This library specializes in interfacing with a [Substrate](https://substrate.io/) node; querying storage, composing extrinsics,
|
|
63
|
+
SCALE encoding/decoding and providing additional convenience methods to deal with the features and metadata of
|
|
64
|
+
the Substrate runtime.
|
|
65
|
+
|
|
66
|
+
## Documentation
|
|
67
|
+
|
|
68
|
+
* [Library documentation](https://jamdottech.github.io/py-polkadot-sdk/)
|
|
69
|
+
* [Metadata documentation for Polkadot and Kusama ecosystem runtimes](https://jamdottech.github.io/py-polkadot-metadata-docs/)
|
|
70
|
+
|
|
71
|
+
## Installation
|
|
72
|
+
```bash
|
|
73
|
+
pip install substrate-interface
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Initialization
|
|
77
|
+
|
|
78
|
+
Using embedded light client
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
substrate = SubstrateInterface(chainspec="polkadot_asset_hub", relay_chainspecs=["polkadot"])
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Using node RPC endpoint
|
|
85
|
+
```python
|
|
86
|
+
substrate = SubstrateInterface(url="ws://127.0.0.1:9944")
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
After connecting certain properties like `ss58_format` will be determined automatically by querying the RPC node. At
|
|
90
|
+
the moment this will work for most `MetadataV14` and above runtimes like Polkadot, Kusama, Acala, Moonbeam. For
|
|
91
|
+
older or runtimes under development the `ss58_format` (default 42) and other properties should be set manually.
|
|
92
|
+
|
|
93
|
+
## Quick usage
|
|
94
|
+
|
|
95
|
+
### Balance information of an account
|
|
96
|
+
```python
|
|
97
|
+
result = substrate.query('System', 'Account', ['F4xQKRUagnSGjFqafyhajLs94e7Vvzvr8ebwYJceKpr8R7T'])
|
|
98
|
+
print(result.value['data']['free']) # 635278638077956496
|
|
99
|
+
```
|
|
100
|
+
### Create balance transfer extrinsic
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
call = substrate.compose_call(
|
|
104
|
+
call_module='Balances',
|
|
105
|
+
call_function='transfer',
|
|
106
|
+
call_params={
|
|
107
|
+
'dest': '5E9oDs9PjpsBbxXxRE9uMaZZhnBAV38n2ouLB28oecBDdeQo',
|
|
108
|
+
'value': 1 * 10**12
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
keypair = Keypair.create_from_uri('//Alice')
|
|
113
|
+
extrinsic = substrate.create_signed_extrinsic(call=call, keypair=keypair)
|
|
114
|
+
|
|
115
|
+
receipt = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=True)
|
|
116
|
+
|
|
117
|
+
print(f"Extrinsic '{receipt.extrinsic_hash}' sent and included in block '{receipt.block_hash}'")
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Contact and Support
|
|
121
|
+
|
|
122
|
+
For questions, please see the [Substrate StackExchange](https://substrate.stackexchange.com/questions/tagged/python) or [Github Discussions](https://github.com/JAMdotTech/py-polkadot-sdk/discussions).
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
https://github.com/JAMdotTech/py-polkadot-sdk/blob/master/LICENSE
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
substrate_interface.egg-info/PKG-INFO
|
|
5
|
+
substrate_interface.egg-info/SOURCES.txt
|
|
6
|
+
substrate_interface.egg-info/dependency_links.txt
|
|
7
|
+
substrate_interface.egg-info/requires.txt
|
|
8
|
+
substrate_interface.egg-info/top_level.txt
|
|
9
|
+
substrateinterface/__init__.py
|
|
10
|
+
substrateinterface/base.py
|
|
11
|
+
substrateinterface/constants.py
|
|
12
|
+
substrateinterface/contracts.py
|
|
13
|
+
substrateinterface/exceptions.py
|
|
14
|
+
substrateinterface/extensions.py
|
|
15
|
+
substrateinterface/interfaces.py
|
|
16
|
+
substrateinterface/key.py
|
|
17
|
+
substrateinterface/keypair.py
|
|
18
|
+
substrateinterface/storage.py
|
|
19
|
+
substrateinterface/data/chainspecs/ksmcc3.json
|
|
20
|
+
substrateinterface/data/chainspecs/ksmcc3_asset_hub.json
|
|
21
|
+
substrateinterface/data/chainspecs/ksmcc3_bridge_hub.json
|
|
22
|
+
substrateinterface/data/chainspecs/ksmcc3_coretime.json
|
|
23
|
+
substrateinterface/data/chainspecs/ksmcc3_encointer.json
|
|
24
|
+
substrateinterface/data/chainspecs/ksmcc3_people.json
|
|
25
|
+
substrateinterface/data/chainspecs/kusama.json
|
|
26
|
+
substrateinterface/data/chainspecs/paseo.json
|
|
27
|
+
substrateinterface/data/chainspecs/paseo_asset_hub.json
|
|
28
|
+
substrateinterface/data/chainspecs/paseo_coretime.json
|
|
29
|
+
substrateinterface/data/chainspecs/paseo_people.json
|
|
30
|
+
substrateinterface/data/chainspecs/polkadot.json
|
|
31
|
+
substrateinterface/data/chainspecs/polkadot_asset_hub.json
|
|
32
|
+
substrateinterface/data/chainspecs/polkadot_bridge_hub.json
|
|
33
|
+
substrateinterface/data/chainspecs/polkadot_collectives.json
|
|
34
|
+
substrateinterface/data/chainspecs/polkadot_coretime.json
|
|
35
|
+
substrateinterface/data/chainspecs/polkadot_people.json
|
|
36
|
+
substrateinterface/data/chainspecs/rococo_v2_2.json
|
|
37
|
+
substrateinterface/data/chainspecs/rococo_v2_2_asset_hub.json
|
|
38
|
+
substrateinterface/data/chainspecs/rococo_v2_2_bridge_hub.json
|
|
39
|
+
substrateinterface/data/chainspecs/rococo_v2_2_people.json
|
|
40
|
+
substrateinterface/data/chainspecs/westend2.json
|
|
41
|
+
substrateinterface/data/chainspecs/westend2_asset_hub.json
|
|
42
|
+
substrateinterface/data/chainspecs/westend2_bridge_hub.json
|
|
43
|
+
substrateinterface/data/chainspecs/westend2_collectives.json
|
|
44
|
+
substrateinterface/data/chainspecs/westend2_coretime.json
|
|
45
|
+
substrateinterface/data/chainspecs/westend2_people.json
|
|
46
|
+
substrateinterface/transport/__init__.py
|
|
47
|
+
substrateinterface/transport/base.py
|
|
48
|
+
substrateinterface/transport/http.py
|
|
49
|
+
substrateinterface/transport/smoldot.py
|
|
50
|
+
substrateinterface/transport/websocket.py
|
|
51
|
+
substrateinterface/utils/__init__.py
|
|
52
|
+
substrateinterface/utils/caching.py
|
|
53
|
+
substrateinterface/utils/ecdsa_helpers.py
|
|
54
|
+
substrateinterface/utils/encrypted_json.py
|
|
55
|
+
substrateinterface/utils/hasher.py
|
|
56
|
+
substrateinterface/utils/ss58.py
|
|
57
|
+
test/test_block.py
|
|
58
|
+
test/test_contracts.py
|
|
59
|
+
test/test_create_extrinsics.py
|
|
60
|
+
test/test_extension_interface.py
|
|
61
|
+
test/test_helper_functions.py
|
|
62
|
+
test/test_init.py
|
|
63
|
+
test/test_keypair.py
|
|
64
|
+
test/test_light_client.py
|
|
65
|
+
test/test_query.py
|
|
66
|
+
test/test_query_map.py
|
|
67
|
+
test/test_rpc_compatibility.py
|
|
68
|
+
test/test_runtime_call.py
|
|
69
|
+
test/test_ss58.py
|
|
70
|
+
test/test_subscriptions.py
|
|
71
|
+
test/test_type_registry.py
|
{substrate-interface-1.7.10 → substrate_interface-1.8.0}/substrate_interface.egg-info/requires.txt
RENAMED
|
@@ -6,13 +6,14 @@ requests<3,>=2.21.0
|
|
|
6
6
|
xxhash<4,>=1.3.0
|
|
7
7
|
ecdsa<1,>=0.17.0
|
|
8
8
|
eth-keys<1,>=0.2.1
|
|
9
|
-
eth_utils<
|
|
9
|
+
eth_utils<6,>=1.3.0
|
|
10
10
|
pycryptodome<4,>=3.11.0
|
|
11
11
|
PyNaCl<2,>=1.0.1
|
|
12
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
|
|
16
|
+
smoldot-light<1,>=0.1.0
|
|
16
17
|
|
|
17
18
|
[test]
|
|
18
19
|
coverage
|
|
@@ -20,14 +20,10 @@ import warnings
|
|
|
20
20
|
from datetime import datetime
|
|
21
21
|
from hashlib import blake2b
|
|
22
22
|
|
|
23
|
-
import json
|
|
24
23
|
import logging
|
|
25
24
|
|
|
26
|
-
import requests
|
|
27
25
|
from typing import Optional, Union, List
|
|
28
26
|
|
|
29
|
-
from websocket import create_connection, WebSocketConnectionClosedException
|
|
30
|
-
|
|
31
27
|
from scalecodec.base import ScaleBytes, RuntimeConfigurationObject, ScaleType
|
|
32
28
|
from scalecodec.types import GenericCall, GenericExtrinsic, Extrinsic, MultiAccountId, GenericRuntimeCallDefinition
|
|
33
29
|
from scalecodec.type_registry import load_type_registry_preset
|
|
@@ -42,6 +38,7 @@ from .exceptions import SubstrateRequestException, ConfigurationError, StorageFu
|
|
|
42
38
|
from .constants import *
|
|
43
39
|
from .keypair import Keypair, KeypairType, MnemonicLanguageCode
|
|
44
40
|
from .utils.ss58 import ss58_decode, ss58_encode, is_valid_ss58_address, get_ss58_format
|
|
41
|
+
from .transport import HttpTransport, WebsocketTransport, SmoldotTransport
|
|
45
42
|
|
|
46
43
|
|
|
47
44
|
__all__ = ['SubstrateInterface', 'ExtrinsicReceipt', 'logger']
|
|
@@ -49,33 +46,21 @@ __all__ = ['SubstrateInterface', 'ExtrinsicReceipt', 'logger']
|
|
|
49
46
|
logger = logging.getLogger(__name__)
|
|
50
47
|
|
|
51
48
|
|
|
52
|
-
def list_remove_iter(xs: list):
|
|
53
|
-
removed = False
|
|
54
|
-
def remove():
|
|
55
|
-
nonlocal removed
|
|
56
|
-
removed = True
|
|
57
|
-
|
|
58
|
-
i = 0
|
|
59
|
-
while i < len(xs):
|
|
60
|
-
removed = False
|
|
61
|
-
yield xs[i], remove
|
|
62
|
-
if removed:
|
|
63
|
-
xs.pop(i)
|
|
64
|
-
else:
|
|
65
|
-
i += 1
|
|
66
|
-
|
|
67
|
-
|
|
68
49
|
class SubstrateInterface:
|
|
69
50
|
|
|
70
51
|
def __init__(self, url=None, websocket=None, ss58_format=None, type_registry=None, type_registry_preset=None,
|
|
71
52
|
cache_region=None, runtime_config=None, use_remote_preset=False, ws_options=None,
|
|
72
|
-
auto_discover=True, auto_reconnect=True, config=None
|
|
53
|
+
auto_discover=True, auto_reconnect=True, config=None, chainspec=None,
|
|
54
|
+
relay_chainspecs=None, relay_chain_ids=None):
|
|
73
55
|
"""
|
|
74
56
|
A specialized class in interfacing with a Substrate node.
|
|
75
57
|
|
|
76
58
|
Parameters
|
|
77
59
|
----------
|
|
78
60
|
url: the URL to the substrate node, either in format https://127.0.0.1:9933 or wss://127.0.0.1:9944
|
|
61
|
+
chainspec: path or preset name string for a Substrate chain spec (Smoldot light client)
|
|
62
|
+
relay_chainspecs: list of relay chain specs (paths or preset names) for Smoldot parachain usage
|
|
63
|
+
relay_chain_ids: list of relay chain IDs for Smoldot parachain usage
|
|
79
64
|
ss58_format: The address type which account IDs will be SS58-encoded to Substrate addresses. Defaults to 42, for Kusama the address type is 2
|
|
80
65
|
type_registry: A dict containing the custom type registry in format: {'types': {'customType': 'u32'},..}
|
|
81
66
|
type_registry_preset: The name of the predefined type registry shipped with the SCALE-codec, e.g. kusama
|
|
@@ -85,8 +70,14 @@ class SubstrateInterface:
|
|
|
85
70
|
config: dict of config flags to overwrite default configuration
|
|
86
71
|
"""
|
|
87
72
|
|
|
88
|
-
if
|
|
73
|
+
if chainspec and (url or websocket):
|
|
74
|
+
raise ValueError("Either 'chainspec' or 'url'/'websocket' must be provided")
|
|
75
|
+
if not chainspec and ((not url and not websocket) or (url and websocket)):
|
|
89
76
|
raise ValueError("Either 'url' or 'websocket' must be provided")
|
|
77
|
+
if chainspec is None and (relay_chainspecs or relay_chain_ids):
|
|
78
|
+
raise ValueError("'relay_chainspecs' and 'relay_chain_ids' are only valid with 'chainspec'")
|
|
79
|
+
if relay_chainspecs and relay_chain_ids:
|
|
80
|
+
raise ValueError("Specify either 'relay_chainspecs' or 'relay_chain_ids', not both")
|
|
90
81
|
|
|
91
82
|
# Initialize lazy loading variables
|
|
92
83
|
self.__version = None
|
|
@@ -113,7 +104,11 @@ class SubstrateInterface:
|
|
|
113
104
|
|
|
114
105
|
self.request_id = 1
|
|
115
106
|
self.url = url
|
|
107
|
+
self.chainspec = chainspec
|
|
108
|
+
self.relay_chainspecs = relay_chainspecs
|
|
109
|
+
self.relay_chain_ids = relay_chain_ids
|
|
116
110
|
self.websocket = None
|
|
111
|
+
self.transport = None
|
|
117
112
|
|
|
118
113
|
# Websocket connection options
|
|
119
114
|
self.ws_options = ws_options or {}
|
|
@@ -127,14 +122,6 @@ class SubstrateInterface:
|
|
|
127
122
|
if 'write_limit' not in self.ws_options:
|
|
128
123
|
self.ws_options['write_limit'] = 2 ** 32
|
|
129
124
|
|
|
130
|
-
self.__rpc_message_queue = []
|
|
131
|
-
|
|
132
|
-
if self.url and (self.url[0:6] == 'wss://' or self.url[0:5] == 'ws://'):
|
|
133
|
-
self.connect_websocket()
|
|
134
|
-
|
|
135
|
-
elif websocket:
|
|
136
|
-
self.websocket = websocket
|
|
137
|
-
|
|
138
125
|
self.mock_extrinsics = None
|
|
139
126
|
self.default_headers = {
|
|
140
127
|
'content-type': "application/json",
|
|
@@ -162,12 +149,33 @@ class SubstrateInterface:
|
|
|
162
149
|
if type(config) is dict:
|
|
163
150
|
self.config.update(config)
|
|
164
151
|
|
|
152
|
+
if self.chainspec:
|
|
153
|
+
self.transport = SmoldotTransport(
|
|
154
|
+
chainspec=self.chainspec,
|
|
155
|
+
relay_chainspecs=self.relay_chainspecs,
|
|
156
|
+
relay_chain_ids=self.relay_chain_ids,
|
|
157
|
+
debug_fn=self.debug_message
|
|
158
|
+
)
|
|
159
|
+
elif websocket or (self.url and (self.url[0:6] == 'wss://' or self.url[0:5] == 'ws://')):
|
|
160
|
+
self.transport = WebsocketTransport(
|
|
161
|
+
url=self.url,
|
|
162
|
+
websocket=websocket,
|
|
163
|
+
ws_options=self.ws_options,
|
|
164
|
+
auto_reconnect=self.config.get('auto_reconnect', True),
|
|
165
|
+
debug_fn=self.debug_message,
|
|
166
|
+
on_connect=self._set_websocket
|
|
167
|
+
)
|
|
168
|
+
else:
|
|
169
|
+
self.transport = HttpTransport(
|
|
170
|
+
url=self.url,
|
|
171
|
+
headers=self.default_headers,
|
|
172
|
+
debug_fn=self.debug_message
|
|
173
|
+
)
|
|
174
|
+
|
|
165
175
|
|
|
166
176
|
# Initialize extension interface
|
|
167
177
|
self.extensions = ExtensionInterface(self)
|
|
168
178
|
|
|
169
|
-
self.session = requests.Session()
|
|
170
|
-
|
|
171
179
|
self.reload_type_registry(use_remote_preset=use_remote_preset, auto_discover=auto_discover)
|
|
172
180
|
|
|
173
181
|
def connect_websocket(self):
|
|
@@ -178,12 +186,13 @@ class SubstrateInterface:
|
|
|
178
186
|
-------
|
|
179
187
|
|
|
180
188
|
"""
|
|
181
|
-
if
|
|
182
|
-
self.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
189
|
+
if isinstance(self.transport, WebsocketTransport):
|
|
190
|
+
self.transport.connect()
|
|
191
|
+
else:
|
|
192
|
+
raise ConfigurationError("Websocket transport not configured for this interface")
|
|
193
|
+
|
|
194
|
+
def _set_websocket(self, websocket):
|
|
195
|
+
self.websocket = websocket
|
|
187
196
|
|
|
188
197
|
def close(self):
|
|
189
198
|
"""
|
|
@@ -193,9 +202,8 @@ class SubstrateInterface:
|
|
|
193
202
|
-------
|
|
194
203
|
|
|
195
204
|
"""
|
|
196
|
-
if self.
|
|
197
|
-
self.
|
|
198
|
-
self.websocket.close()
|
|
205
|
+
if self.transport:
|
|
206
|
+
self.transport.close()
|
|
199
207
|
|
|
200
208
|
self.extensions.unregister_all()
|
|
201
209
|
|
|
@@ -266,86 +274,8 @@ class SubstrateInterface:
|
|
|
266
274
|
}
|
|
267
275
|
|
|
268
276
|
self.debug_message('RPC request #{}: "{}"'.format(request_id, method))
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
try:
|
|
272
|
-
self.websocket.send(json.dumps(payload))
|
|
273
|
-
except WebSocketConnectionClosedException:
|
|
274
|
-
if self.config.get('auto_reconnect') and self.url:
|
|
275
|
-
# Try to reconnect websocket and retry rpc_request
|
|
276
|
-
self.debug_message("Connection Closed; Trying to reconnecting...")
|
|
277
|
-
self.connect_websocket()
|
|
278
|
-
|
|
279
|
-
return self.rpc_request(method=method, params=params, result_handler=result_handler)
|
|
280
|
-
else:
|
|
281
|
-
# websocket connection is externally created, re-raise exception
|
|
282
|
-
raise
|
|
283
|
-
|
|
284
|
-
update_nr = 0
|
|
285
|
-
json_body = None
|
|
286
|
-
subscription_id = None
|
|
287
|
-
|
|
288
|
-
while json_body is None:
|
|
289
|
-
# Search for subscriptions
|
|
290
|
-
for message, remove_message in list_remove_iter(self.__rpc_message_queue):
|
|
291
|
-
|
|
292
|
-
# Check if result message is matching request ID
|
|
293
|
-
if 'id' in message and message['id'] == request_id:
|
|
294
|
-
|
|
295
|
-
remove_message()
|
|
296
|
-
|
|
297
|
-
# Check if response has error
|
|
298
|
-
if 'error' in message:
|
|
299
|
-
raise SubstrateRequestException(message['error'])
|
|
300
|
-
|
|
301
|
-
# If result handler is set, pass result through and loop until handler return value is set
|
|
302
|
-
if callable(result_handler):
|
|
303
|
-
|
|
304
|
-
# Set subscription ID and only listen to messages containing this ID
|
|
305
|
-
subscription_id = message['result']
|
|
306
|
-
self.debug_message(f"Websocket subscription [{subscription_id}] created")
|
|
307
|
-
|
|
308
|
-
else:
|
|
309
|
-
json_body = message
|
|
310
|
-
|
|
311
|
-
# Process subscription updates
|
|
312
|
-
for message, remove_message in list_remove_iter(self.__rpc_message_queue):
|
|
313
|
-
# Check if message is meant for this subscription
|
|
314
|
-
if 'params' in message and message['params']['subscription'] == subscription_id:
|
|
315
|
-
|
|
316
|
-
remove_message()
|
|
317
|
-
|
|
318
|
-
self.debug_message(f"Websocket result [{subscription_id} #{update_nr}]: {message}")
|
|
319
|
-
|
|
320
|
-
# Call result_handler with message for processing
|
|
321
|
-
callback_result = result_handler(message, update_nr, subscription_id)
|
|
322
|
-
if callback_result is not None:
|
|
323
|
-
json_body = callback_result
|
|
324
|
-
|
|
325
|
-
update_nr += 1
|
|
326
|
-
|
|
327
|
-
# Read one more message to queue
|
|
328
|
-
if json_body is None:
|
|
329
|
-
self.__rpc_message_queue.append(json.loads(self.websocket.recv()))
|
|
330
|
-
|
|
331
|
-
else:
|
|
332
|
-
|
|
333
|
-
if result_handler:
|
|
334
|
-
raise ConfigurationError("Result handlers only available for websockets (ws://) connections")
|
|
335
|
-
|
|
336
|
-
response = self.session.request("POST", self.url, data=json.dumps(payload), headers=self.default_headers)
|
|
337
|
-
|
|
338
|
-
if response.status_code != 200:
|
|
339
|
-
raise SubstrateRequestException(
|
|
340
|
-
"RPC request failed with HTTP status code {}".format(response.status_code))
|
|
341
|
-
|
|
342
|
-
json_body = response.json()
|
|
343
|
-
|
|
344
|
-
# Check if response has error
|
|
345
|
-
if 'error' in json_body:
|
|
346
|
-
raise SubstrateRequestException(json_body['error'])
|
|
347
|
-
|
|
348
|
-
return json_body
|
|
277
|
+
logging.debug(payload)
|
|
278
|
+
return self.transport.rpc_request(payload, result_handler=result_handler)
|
|
349
279
|
|
|
350
280
|
@property
|
|
351
281
|
def name(self):
|
|
@@ -1796,6 +1726,8 @@ class SubstrateInterface:
|
|
|
1796
1726
|
'extrinsic_hash': '0x{}'.format(extrinsic.extrinsic_hash.hex()),
|
|
1797
1727
|
'finalized': False
|
|
1798
1728
|
}
|
|
1729
|
+
elif message['params']['result'] in ['dropped']:
|
|
1730
|
+
raise ValueError(f'Submit extrinsic failed: {message['params']['result']}')
|
|
1799
1731
|
|
|
1800
1732
|
if wait_for_inclusion or wait_for_finalization:
|
|
1801
1733
|
response = self.rpc_request(
|