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

Commit 9531373

Browse files
Merge pull request #22 from PolymathNetwork/alpha
Merge alpha into beta
2 parents 9b960c6 + 8604a79 commit 9531373

File tree

12 files changed

+498
-200
lines changed

12 files changed

+498
-200
lines changed

.github/workflows/unittests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
python-version: [3.7, 3.8]
11+
python-version: [3.6, 3.7, 3.8]
1212

1313
steps:
1414
- uses: actions/checkout@v2

README.md

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,23 +221,91 @@ if keypair.verify("Test123", signature):
221221
By default a keypair is using SR25519 cryptography, alternatively ED25519 can be explictly specified:
222222

223223
```python
224-
keypair = Keypair.create_from_mnemonic(mnemonic, crypto_type=Keypair.ED25519)
224+
keypair = Keypair.create_from_mnemonic(mnemonic, crypto_type=KeypairType.ED25519)
225225
```
226226

227-
### Create keypair using Subkey wrapper (using local subkey binary)
227+
### Creating keypairs with soft and hard key derivation paths
228228

229229
```python
230-
sub_key = Subkey(subkey_path='/usr/local/bin/subkey')
231-
subkey_result = sub_key.inspect(network='kusama', suri="appear fortune produce assist volcano deal shoulder foot engine harvest pupil agent//Alice")
232-
keypair = Keypair.create_from_seed(subkey_result["secretSeed"], address_type=2)
230+
mnemonic = Keypair.generate_mnemonic()
231+
keypair = Keypair.create_from_uri(mnemonic + '//hard/soft')
232+
```
233+
234+
By omitting the mnemonic the default development mnemonic is used:
235+
236+
```python
237+
keypair = Keypair.create_from_uri('//Alice')
238+
```
239+
240+
### Getting estimate of network fees for extrinsic in advance
241+
242+
```python
243+
keypair = Keypair(ss58_address="EaG2CRhJWPb7qmdcJvy3LiWdh26Jreu9Dx6R1rXxPmYXoDk")
244+
245+
call = self.kusama_substrate.compose_call(
246+
call_module='Balances',
247+
call_function='transfer',
248+
call_params={
249+
'dest': 'EaG2CRhJWPb7qmdcJvy3LiWdh26Jreu9Dx6R1rXxPmYXoDk',
250+
'value': 2 * 10 ** 3
251+
}
252+
)
253+
payment_info = self.kusama_substrate.get_payment_info(call=call, keypair=keypair)
254+
```
255+
256+
### Offline signing of extrinsics
257+
258+
This example generates a signature payload which can be signed on another (offline) machine and later on sent to the
259+
network with the generated signature.
260+
261+
Generate signature payload on online machine:
262+
```python
263+
substrate = SubstrateInterface(
264+
url="http://127.0.0.1:9933",
265+
address_type=42,
266+
type_registry_preset='substrate-node-template',
267+
)
268+
269+
call = substrate.compose_call(
270+
call_module='Balances',
271+
call_function='transfer',
272+
call_params={
273+
'dest': '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
274+
'value': 2 * 10**8
275+
}
276+
)
277+
278+
era = {'period': 64, 'current': 22719}
279+
nonce = 0
280+
281+
signature_payload = substrate.generate_signature_payload(call=call, era=era, nonce=nonce)
282+
```
283+
284+
Then on another (offline) machine generate the signature with given `signature_payload`:
285+
286+
```python
287+
keypair = Keypair.create_from_mnemonic("nature exchange gasp toy result bacon coin broccoli rule oyster believe lyrics")
288+
signature = keypair.sign(signature_payload)
233289
```
234290

235-
### Create keypair using Subkey wrapper (using Docker image parity/subkey:latest)
291+
Finally on the online machine send the extrinsic with generated signature:
236292

237293
```python
238-
sub_key = Subkey(use_docker=True)
239-
subkey_result = sub_key.inspect(network='kusama', suri="appear fortune produce assist volcano deal shoulder foot engine harvest pupil agent//Alice")
240-
keypair = Keypair.create_from_seed(subkey_result["secretSeed"], address_type=2)
294+
keypair = Keypair(ss58_address="5EChUec3ZQhUvY1g52ZbfBVkqjUY9Kcr6mcEvQMbmd38shQL")
295+
296+
extrinsic = substrate.create_signed_extrinsic(
297+
call=call,
298+
keypair=keypair,
299+
era=era,
300+
nonce=nonce,
301+
signature=signature
302+
)
303+
304+
result = substrate.submit_extrinsic(
305+
extrinsic=extrinsic
306+
)
307+
308+
print(result['extrinsic_hash'])
241309
```
242310

243311
### Metadata and type versioning

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ urllib3>=1.25.11
99
xxhash>=1.3.0
1010
pytest>=6.1.1
1111

12-
polymath-scalecodec==0.5.1
12+
polymath-scalecodec==0.6.2a2
1313
py-sr25519-bindings>=0.1.2
1414
py-ed25519-bindings>=0.1.1
1515
py-bip39-bindings>=0.1.6

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
'requests>=2.24.0',
184184
'urllib3>=1.25.10',
185185
'xxhash>=1.3.0',
186-
'polymath-scalecodec==0.5.1',
186+
'polymath-scalecodec==0.6.2a2',
187187
'py-sr25519-bindings>=0.1.2',
188188
'py-ed25519-bindings>=0.1.1',
189189
'py-bip39-bindings>=0.1.6'

0 commit comments

Comments
 (0)