Skip to content
This repository was archived by the owner on Jul 6, 2022. It is now read-only.

Commit 1de45d8

Browse files
committed
Merge branch 'develop' into substrate3.0
2 parents 96d498b + 4328fbe commit 1de45d8

File tree

8 files changed

+128
-116
lines changed

8 files changed

+128
-116
lines changed

.github/workflows/deploy.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Test and Deploy
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Set up Python
13+
uses: actions/setup-python@v1
14+
with:
15+
python-version: '3.8'
16+
- name: Install project dependencies
17+
run: |
18+
python -m pip install --upgrade pip
19+
pip install -r requirements.txt
20+
- name: Lint with flake8
21+
run: |
22+
pip install flake8
23+
# stop the build if there are Python syntax errors or undefined names
24+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
25+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
26+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
27+
- name: Test with pytest
28+
run: |
29+
pip install pytest
30+
pytest
31+
- name: Install deploy dependencies
32+
run: |
33+
pip install setuptools wheel twine
34+
- name: Build and publish
35+
env:
36+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
37+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
38+
run: |
39+
python setup.py sdist bdist_wheel
40+
twine upload dist/*

.github/workflows/deploypypi.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

.github/workflows/unittests.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
name: Run unit tests
22

3-
on:
4-
push:
5-
branches: [master, develop]
6-
pull_request:
7-
# The branches below must be a subset of the branches above
8-
branches: [master, develop]
9-
schedule:
10-
- cron: '0 7 * * *'
3+
on: [push]
114

125
jobs:
136
build:

README.md

Lines changed: 24 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# Python Substrate Interface
1+
#### This project is forked from https://github.com/polkascan/py-substrate-interface
22

3-
[![Build Status](https://img.shields.io/github/workflow/status/polkascan/py-substrate-interface/Run%20unit%20tests)](https://github.com/polkascan/py-substrate-interface/actions?query=workflow%3A%22Run+unit+tests%22)
4-
[![Latest Version](https://img.shields.io/pypi/v/substrate-interface.svg)](https://pypi.org/project/substrate-interface/)
5-
[![Supported Python versions](https://img.shields.io/pypi/pyversions/substrate-interface.svg)](https://pypi.org/project/substrate-interface/)
6-
[![License](https://img.shields.io/pypi/l/substrate-interface.svg)](https://github.com/polkascan/py-substrate-interface/blob/master/LICENSE)
3+
# Python Polymath Substrate Interface
74

8-
Python Substrate Interface Library
5+
[![Latest Version](https://img.shields.io/pypi/v/polymath-substrate-interface.svg)](https://pypi.org/project/polymath-substrate-interface/)
6+
[![Supported Python versions](https://img.shields.io/pypi/pyversions/polymath-substrate-interface.svg)](https://pypi.org/project/polymath-substrate-interface/)
7+
8+
Python Polymath Substrate Interface Library
99

1010
## Description
11-
This library specializes in interfacing with a Substrate node, providing additional convenience methods to deal with
11+
This library specializes in interfacing with a Polymesh node, providing additional convenience methods to deal with
1212
SCALE encoding/decoding (the default output and input format of the Substrate JSONRPC), metadata parsing, type registry
1313
management and versioning of types.
1414

@@ -40,62 +40,18 @@ management and versioning of types.
4040
* [License](#license)
4141

4242
## Documentation
43+
4344
https://polkascan.github.io/py-substrate-interface/
4445

4546
## Installation
47+
4648
```bash
47-
pip install substrate-interface
49+
pip install polymath-substrate-interface
4850
```
4951

5052
## Initialization
5153

52-
The following examples show how to initialize for supported chains:
53-
54-
### Autodiscover mode
55-
56-
```python
57-
substrate = SubstrateInterface(
58-
url="wss://rpc.polkadot.io"
59-
)
60-
```
61-
62-
When only an `url` is provided, it tries to determine certain properties like `ss58_format` and
63-
`type_registry_preset` automatically by calling the RPC method `system_properties`.
64-
65-
At the moment this will work for Polkadot, Kusama, Kulupu and Westend nodes, for other chains the `ss58_format`
66-
(default 42) and `type_registry` (defaults to latest vanilla Substrate types) should be set manually.
67-
68-
### Manually set required properties
69-
70-
Polkadot
71-
72-
```python
73-
substrate = SubstrateInterface(
74-
url="wss://rpc.polkadot.io",
75-
ss58_format=0,
76-
type_registry_preset='polkadot'
77-
)
78-
```
79-
80-
Kusama
81-
82-
```python
83-
substrate = SubstrateInterface(
84-
url="wss://kusama-rpc.polkadot.io/",
85-
ss58_format=2,
86-
type_registry_preset='kusama'
87-
)
88-
```
89-
90-
Rococo
91-
92-
```python
93-
substrate = SubstrateInterface(
94-
url="wss://rococo-rpc.polkadot.io",
95-
ss58_format=42,
96-
type_registry_preset='rococo'
97-
)
98-
```
54+
The following examples show how to initialize for Polymesh chain:
9955

10056
Westend
10157

@@ -152,9 +108,18 @@ substrate = SubstrateInterface(
152108

153109
```
154110

155-
## Features
111+
## Keeping type registry presets up to date
112+
113+
When on-chain runtime upgrades occur, types used in call- or storage functions can be added or modified. Therefor it is
114+
important to keep the type registry presets up to date. At the moment the type registry for Polymesh is being actively maintained for this library and an check and update procedure can be triggered with:
115+
116+
```python
117+
substrate.update_type_registry_presets()
118+
```
156119

157-
### Retrieve extrinsics for a certain block
120+
## Examples
121+
122+
### Get extrinsics for a certain block
158123

159124
```python
160125
# Set block_hash to None for chaintip
@@ -611,4 +576,5 @@ To check for updates after instantiating the `substrate` object, using `substrat
611576
the most recent type registry preset from Github and apply changes to current object.
612577

613578
## License
614-
https://github.com/polkascan/py-substrate-interface/blob/master/LICENSE
579+
580+
https://github.com/PolymathNetwork/py-substrate-interface/blob/master/LICENSE

setup.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
# There are some restrictions on what makes a valid project name
6565
# specification here:
6666
# https://packaging.python.org/specifications/core-metadata/#name
67-
name='substrate-interface', # Required
67+
name='polymath-substrate-interface', # Required
6868

6969
# Versions should comply with PEP 440:
7070
# https://www.python.org/dev/peps/pep-0440/
@@ -77,7 +77,7 @@
7777
# This is a one-line description or tagline of what your project does. This
7878
# corresponds to the "Summary" metadata field:
7979
# https://packaging.python.org/specifications/core-metadata/#summary
80-
description='Library for interfacing with a Substrate node', # Optional
80+
description='Library for interfacing with a Polymesh node', # Optional
8181

8282
# This is an optional longer description of your project that represents
8383
# the body of text which users will see when they visit PyPI.
@@ -109,11 +109,11 @@
109109

110110
# This should be your name or the name of the organization which owns the
111111
# project.
112-
author='Stichting Polkascan (Polkascan Foundation)', # Optional
112+
author='Polymath', # Optional
113113

114114
# This should be a valid email address corresponding to the author listed
115115
# above.
116-
author_email='[email protected]', # Optional
116+
# author_email='', # Optional
117117

118118
# Classifiers help users find your project by categorizing it.
119119
#
@@ -136,7 +136,6 @@
136136
# These classifiers are *not* checked by 'pip install'. See instead
137137
# 'python_requires' below.
138138
'Programming Language :: Python :: 3',
139-
'Programming Language :: Python :: 3.6',
140139
'Programming Language :: Python :: 3.7',
141140
'Programming Language :: Python :: 3.8',
142141
'Programming Language :: Python :: 3.9',
@@ -146,7 +145,7 @@
146145
# project page. What does your project relate to?
147146
#
148147
# Note that this is a string of words separated by whitespace, not a list.
149-
keywords='interface polkascan polkadot substrate blockchain rpc kusama', # Optional
148+
keywords='interface polkascan polkadot substrate blockchain rpc polymesh', # Optional
150149

151150
# You can just specify package directories manually here if your project is
152151
# simple. Or you can use find_packages().
@@ -167,7 +166,7 @@
167166
# https://packaging.python.org/guides/distributing-packages-using-setuptools/#python-requires
168167

169168
#python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4',
170-
python_requires='>=3.6, <4',
169+
python_requires='>=3.7, <4',
171170

172171
# This field lists other packages that your project depends on to run.
173172
# Any package you put here will be installed by pip when your project is
@@ -182,7 +181,7 @@
182181
'idna>=2.8',
183182
'requests~=2.25.1',
184183
'xxhash>=1.3.0',
185-
'scalecodec~=0.11.11',
184+
'polymath-scalecodec~=4.0.0',
186185
'py-sr25519-bindings~=0.1.2',
187186
'py-ed25519-bindings~=0.1.2',
188187
'py-bip39-bindings~=0.1.6'

test.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from substrateinterface import SubstrateInterface
2+
from substrateinterface.utils.ss58 import ss58_encode
3+
4+
substrate = SubstrateInterface(
5+
# url="http://78.47.58.121:9933/",
6+
url="wss://pme.polymath.network/",
7+
address_type=2,
8+
type_registry_preset='polymesh'
9+
)
10+
11+
# Set block_hash to None for chaintip
12+
block_hash = "0x0a432dd8441621bc2985caa36d10c241170a2d43e764845438069b1caf1eae77"
13+
block_hash = "0xe23e1d389d453935dfe6ee532e06c0930ab51b3e1beaf948d8529f74e68c985b"
14+
15+
metadata_decoder = substrate.get_block_metadata(block_hash=block_hash, decode=True)
16+
# Retrieve extrinsics in block
17+
result = substrate.get_block_events(block_hash=block_hash, metadata_decoder=metadata_decoder)
18+
19+
print(result)
20+
21+
# for extrinsic in result['block']['extrinsics']:
22+
23+
# if 'account_id' in extrinsic:
24+
# signed_by_address = ss58_encode(address=extrinsic['account_id'], address_type=2)
25+
# else:
26+
# signed_by_address = None
27+
28+
# print('\nModule: {}\nCall: {}\nSigned by: {}'.format(
29+
# extrinsic['call_module'],
30+
# extrinsic['call_function'],
31+
# signed_by_address
32+
# ))
33+
34+
# # Loop through params
35+
# for param in extrinsic['params']:
36+
37+
# if param['type'] == 'Address':
38+
# param['value'] = ss58_encode(address=param['value'], address_type=2)
39+
40+
# if param['type'] == 'Compact<Balance>':
41+
# param['value'] = '{} DOT'.format(param['value'] / 10**12)
42+
43+
# print("Param '{}': {}".format(param['name'], param['value']))

test/test_create_extrinsics.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def setUpClass(cls):
3838
type_registry_preset='polkadot'
3939
)
4040

41+
"""
4142
def test_compatibility_polkadot_runtime(self):
4243
type_reg = load_type_registry_preset("polkadot")
4344
@@ -117,6 +118,9 @@ def test_create_mortal_extrinsic(self):
117118
# Extrinsic should be successful if account had balance, eitherwise 'Bad proof' error should be raised
118119
pass
119120
121+
"""
122+
"""
123+
120124
def test_create_unsigned_extrinsic(self):
121125
122126
call = self.kusama_substrate.compose_call(
@@ -130,6 +134,8 @@ def test_create_unsigned_extrinsic(self):
130134
extrinsic = self.kusama_substrate.create_unsigned_extrinsic(call)
131135
self.assertEqual(str(extrinsic.data), '0x280402000ba09cc0317501')
132136
137+
"""
138+
"""
133139
def test_payment_info(self):
134140
keypair = Keypair(ss58_address="EaG2CRhJWPb7qmdcJvy3LiWdh26Jreu9Dx6R1rXxPmYXoDk")
135141
@@ -148,7 +154,9 @@ def test_payment_info(self):
148154
self.assertIn('weight', payment_info)
149155
150156
self.assertGreater(payment_info['partialFee'], 0)
157+
"""
151158

159+
"""
152160
def test_generate_signature_payload_lte_256_bytes(self):
153161
154162
call = self.kusama_substrate.compose_call(
@@ -176,6 +184,7 @@ def test_generate_signature_payload_gt_256_bytes(self):
176184
signature_payload = self.kusama_substrate.generate_signature_payload(call=call)
177185
178186
self.assertEqual(signature_payload.length, 32)
187+
"""
179188

180189
def test_check_extrinsic_receipt(self):
181190
result = ExtrinsicReceipt(

0 commit comments

Comments
 (0)