-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Usage python ./onboard-parachain.py wss://relay-chain-rpc.url wss://para-chain-rpc.url 0xrelay_sudo_seed | ||
# python ./onboard-parachain.py wss://westend-rpc.polkadot.io wss://westend-bridge-hub-rpc.polkadot.io 0x1111.... | ||
|
||
import sys | ||
|
||
import click | ||
# install with `pip install substrate-interface | ||
from substrateinterface import SubstrateInterface, Keypair | ||
from app.lib.parachain_manager import initialize_parachain, get_chain_wasm, get_parachain_head, \ | ||
get_permanent_slot_lease_period_length | ||
|
||
|
||
if len(sys.argv) > 2: | ||
relay_url = sys.argv[1] | ||
para_url = sys.argv[2] | ||
sudo_seed = sys.argv[3] | ||
relay_chain_client = SubstrateInterface(url=relay_url) | ||
para_chain_client = SubstrateInterface(url=para_url) | ||
|
||
key_from_chain = relay_chain_client.query('Sudo', 'Key', params=[]).value | ||
key_from_cli = Keypair.create_from_seed(sudo_seed).ss58_address | ||
if key_from_chain == key_from_cli: | ||
print("Sudo key: True") | ||
else: | ||
print("Provided wrong sudo key {}, expected {}".format(key_from_cli, key_from_chain)) | ||
exit(1) | ||
|
||
para_id = para_chain_client.query('ParachainInfo', 'ParachainId', params=[]).value | ||
state = get_parachain_head(para_chain_client) | ||
wasm = get_chain_wasm(para_chain_client) | ||
permanent_slot_lease_period_length = get_permanent_slot_lease_period_length(relay_chain_client) | ||
|
||
print('Scheduling parachain #{}, state:{}, wasm: {}...{}, lease: {}'.format( | ||
para_id, state, wasm[0:64], wasm[-64:], permanent_slot_lease_period_length)) | ||
|
||
if click.confirm('Do you want to continue?', default=True): | ||
print('Started...') | ||
print(initialize_parachain(relay_chain_client, sudo_seed, para_id, state, wasm, permanent_slot_lease_period_length)) | ||
print('Done, check here: https://polkadot.js.org/apps/?rpc={}#/parachains/parathreads '.format(relay_url)) | ||
else: | ||
print('Do nothing') | ||
else: | ||
print('No WS URL passed as arg') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python3 | ||
# Usage python ./send-xcm.py wss://relay-chain-rpc.url wss://parar-chain-rpc.url 0xrelay_sudo_seed 0xcall | ||
|
||
import sys | ||
from datetime import datetime | ||
|
||
import click | ||
import time | ||
|
||
from scalecodec import ScaleBytes | ||
from substrateinterface import SubstrateInterface, Keypair | ||
from substrateinterface.exceptions import SubstrateRequestException | ||
from substrateinterface.utils.hasher import blake2_256 | ||
from app.lib.substrate import substrate_xcm_sudo_transact_call, get_query_weight | ||
|
||
|
||
if len(sys.argv) > 3: | ||
relay_ws = sys.argv[1] | ||
parar_ws = sys.argv[2] | ||
sudo_key = sys.argv[3] | ||
xcm = sys.argv[4] | ||
|
||
relay_sudo_keypair = Keypair.create_from_seed(sudo_key) | ||
relay = SubstrateInterface(url=relay_ws) | ||
para = SubstrateInterface(url=parar_ws) | ||
|
||
sudo_pub = relay.query('Sudo', 'Key', params=[]).value | ||
para_id = para.query('ParachainInfo', 'ParachainId', params=[]).value | ||
call_obj = para.create_scale_object("Call") | ||
call_obj.decode(ScaleBytes(xcm)) | ||
weight = get_query_weight(para, call_obj) | ||
if sudo_pub == relay_sudo_keypair.ss58_address: | ||
print("Sudo key: True") | ||
else: | ||
print("Provided wrong sudo key {}, expected {}".format(relay_sudo_keypair.ss58_address, sudo_pub)) | ||
exit(1) | ||
|
||
print("relay_ws:", relay_ws) | ||
print("para_ws:", parar_ws) | ||
print("para_id:", para_id) | ||
print("weight:", weight) | ||
|
||
if click.confirm('Do you want to continue?', default=False): | ||
print('Do sudo.sudoUncheckedWeight(palletXcm.sendXcm(Transact(encodedAuthorizeUpgradeCall)))...') | ||
try: | ||
receipt = substrate_xcm_sudo_transact_call(relay, relay_sudo_keypair, para_id, xcm, weight) | ||
print('Relay: Extrinsic "{}" included in block "{}"'.format(receipt.extrinsic_hash, receipt.block_hash)) | ||
print('https://polkadot.js.org/apps/?rpc={}#/explorer/query/{}'.format(relay_ws, receipt.block_hash)) | ||
except SubstrateRequestException as e: | ||
print("Failed to send: {}".format(e)) | ||
exit(1) | ||
else: | ||
print('Do nothing') | ||
exit(0) | ||
|
||
else: | ||
print('No WS URL passed as arg') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python3 | ||
# Usage python ./upgrade-parachain.py wss://relay-chain-rpc.url wss://para-chain-rpc.url 0xrelay_sudo_seed /path/to/runtime | ||
# python ./upgrade-parachain.py wss://westend-rpc.polkadot.io wss://westend-bridge-hub-rpc.polkadot.io 0xrelay_sudo_seed.... /home/user/Downloads/... | ||
|
||
import sys | ||
|
||
import click | ||
from substrateinterface import SubstrateInterface, Keypair | ||
from substrateinterface.utils.hasher import blake2_256 | ||
from app.lib.parachain_manager import parachain_runtime_upgrade | ||
|
||
if len(sys.argv) > 3: | ||
relay_ws = sys.argv[1] | ||
parachain_ws = sys.argv[2] | ||
sudo_key = sys.argv[3] | ||
runtime_file = sys.argv[4] | ||
|
||
relay_sudo_keypair = Keypair.create_from_seed(sudo_key) | ||
relay = SubstrateInterface(url=relay_ws) | ||
parachain = SubstrateInterface(url=parachain_ws) | ||
para_id = parachain.query('ParachainInfo', 'ParachainId', params=[]).value | ||
sudo_pub = relay.query('Sudo', 'Key', params=[]).value | ||
print("Runtime file:", runtime_file) | ||
print("Parachain id:", para_id) | ||
if sudo_pub == relay_sudo_keypair.ss58_address: | ||
print("Sudo key: True") | ||
else: | ||
print("Provided wrong sudo key {}, expected {}".format(relay_sudo_keypair.ss58_address, sudo_pub)) | ||
exit(1) | ||
|
||
# Get the Blake-2_256 hash (you may also toggle “hash a file” in the Apps UI and the Blake2_256 code_hash will be | ||
# computed for you) | ||
with open(runtime_file, 'rb') as f: | ||
binarycontent = f.read(-1) | ||
code_hash = "0x" + blake2_256(binarycontent).hex() | ||
print("code_hash:", code_hash) | ||
|
||
|
||
if click.confirm('Do you want to continue?', default=False): | ||
parachain_runtime_upgrade("Runtime name", para_id, binarycontent, parachain, relay, relay_sudo_keypair, | ||
check_version=True) | ||
|
||
else: | ||
print('Do nothing') | ||
exit(0) | ||
|
||
else: | ||
print('No WS URL passed as arg') |