-
Notifications
You must be signed in to change notification settings - Fork 1
/
reactor.py
78 lines (51 loc) · 1.97 KB
/
reactor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import sys
from substrateinterface import SubstrateInterface, Keypair
from substrateinterface.exceptions import SubstrateRequestException
NODE_WSS = "wss://governance2-testnet.litentry.io"
# NODE_WSS = "wss://kusama-rpc.polkadot.io"
g_keypair = ""
g_substrate = ""
def vote():
global g_keypair
global g_substrate
try:
call = g_substrate.compose_call(
call_module='System',
call_function='remark',
call_params={
'remark': '0x1234'
}
)
print("generating extrinsic...")
extrinsic = g_substrate.create_signed_extrinsic(call=call, keypair=g_keypair, era={'period': 64})
print("done!")
print("submitting extrinsic...")
receipt = g_substrate.submit_extrinsic(extrinsic, wait_for_inclusion=True)
print("done!")
print("Extrinsic '{}' sent and included in block '{}'".format(receipt.extrinsic_hash, receipt.block_hash))
except SubstrateRequestException as e:
print("Failed to send: {}".format(e))
def subscription_handler(events_obj, update_nr, subscription_id):
for event in events_obj:
if event.value["module_id"] == "System" and event.value["event_id"] == "Remarked":
print('System.Remarked event found with attributes:', event.value['attributes'])
vote()
##########################################
# EXECUTION STARTS HERE
##########################################
# Check that a seed phrase is entered
if len(sys.argv) != 2:
print("Arguments: seed_phrase_in_quotes")
sys.exit("Could not read arguments")
print(sys.argv)
seed = sys.argv[1]
# Connect to node.
print("Connecting to node...", end='')
g_substrate = SubstrateInterface(
url=NODE_WSS
)
# Generate keypair
print("Generating keypair...", end='')
g_keypair = Keypair.create_from_mnemonic(seed)
print(" done!")
result = g_substrate.query("System", "Events", [], subscription_handler=subscription_handler)