-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathblock_create.py
executable file
·110 lines (79 loc) · 2.96 KB
/
block_create.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python3
# Script for RPC "block_create" command
import requests
import json
import argparse
import sys
import common
def parse_args():
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group()
group.add_argument('-b', '--beta', action='store_true', default=False,
help='use beta network')
group.add_argument('-t', '--test', action='store_true', default=False,
help='use test network')
parser.add_argument('--rpc',
help='RPC URL to contact')
parser.add_argument('--process', action='store_true', default=False,
help='process the block after creating it')
parser.add_argument('--work',
help='optional work value to use')
parser.add_argument('-w', '--wallet',
help='wallet ID holding account')
parser.add_argument('-a', '--account',
help='account that signs the block')
parser.add_argument('-p', '--prvkey',
help='private key to sign the block (instead of wallet/account)')
parser.add_argument('previous',
help='previous block hash')
parser.add_argument('representative',
help='representative to set in block')
parser.add_argument('balance', type=int,
help='final balance for account after block creation')
parser.add_argument('link',
help='link field in hex, send block hash or receive public key')
return parser.parse_args()
def process_block(session, rpc_url, blk, blkhash):
print('Processing block with hash: %s' % blkhash)
params = {
"action": "process",
"json_block": "true",
"block": blk,
}
print(json.dumps(params, indent=4))
result = common.post(session, params, rpc_url, timeout=360)
print(json.dumps(result, indent=4))
args = parse_args()
if args.prvkey:
if args.wallet or args.account:
print('Private key given, wallet/account should not be set.')
sys.exit(1)
else:
if not args.wallet or not args.account:
print('Wallet and account must be set, if private key is not used.')
sys.exit(1)
rpc_url = common.get_rpc_url(args)
print('RPC URL = %s' % rpc_url)
params = {
'action': 'block_create',
'json_block': 'true',
'type': 'state',
'previous': args.previous,
'representative': args.representative,
'balance': str(args.balance),
'link': args.link,
}
if args.wallet or args.account:
params['wallet'] = args.wallet
params['account'] = args.account
else:
params['key'] = args.prvkey
if args.work != None:
params['work'] = args.work
print(json.dumps(params, indent=4))
session = requests.Session()
result = common.post(session, params, rpc_url, timeout=360)
print(json.dumps(result, indent=4))
if args.process:
print()
process_block(session, rpc_url, result['block'], result['hash'])