-
Notifications
You must be signed in to change notification settings - Fork 2
/
confchain.py
284 lines (234 loc) · 6.74 KB
/
confchain.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# -*- coding: utf-8 -*-
import sys
import click
import time
import json
from grapheneapi.grapheneapi import GrapheneAPI
from bitshares.utils import formatTimeFromNow
from bitshares.genesisbalance import GenesisBalances
from bitshares.account import Account
from bitshares.amount import Amount
from bitshares.asset import Asset
from bitshares.proposal import Proposals
from bitshares.witness import Witness
from bitshares.blockchain import Blockchain
from bitshares import BitShares
from getpass import getpass
from pprint import pprint
from bitshares.instance import set_shared_blockchain_instance
from bitsharesbase.account import PasswordKey
from bitsharesbase import operations
connection = {
"blocking": True,
"nobroadcast": False,
"num_retries": 1,
#"node": ["wss://node.mvsdna.com"],
"node": ["ws://localhost:8090"],
"keys": [
# udrur
"5JEVg45P9ySbo4ZVuqfCBjydEi11C7n7z9PhqZAwwL8effcfEvU", # initial balance
"5JBtkKThCStcYZwBJhQEys1nc7e44F4giZCdLj3FyQWWAxESteB", # foundation active
"5JxNuvALBwigV29bnGd969sCsTwiuExs6pgdrnvvzs6PTvCiB9n", # foundation owner
"5JyhVvLVBo7ujoce5wHpCEWsnjVsmrmBHP8UK4Qy8pEYqXK6ptD", # faucet
"5KWNLXftSvmUaxmtfHPrwpD39654H3TwwaUkenpBNoLJsSvHPtW", # init0 owner
]
}
blockchain = BitShares(
**connection
)
set_shared_blockchain_instance(blockchain)
def sleep(t: int) -> None:
click.echo(" - Going to sleep for {}s".format(t))
time.sleep(int(t))
@click.group()
def main():
pass
@main.command()
def info():
click.echo(dict(Account("1.2.6")))
@main.command()
def listaccounts():
click.echo(blockchain.wallet.getAccounts())
@main.command()
@click.argument("ids", required=False, nargs=-1)
def claim(ids):
""" 2 - Claim genesis stake
"""
_claim(ids)
def _claim(ids):
# Claim genesis stake
click.echo(" - Claiming Genesis Stake")
p = GenesisBalances()
if not ids:
[click.echo(x) for x in p]
return
try:
for x in p:
if x["id"] in ids:
click.echo(x.claim(account="foundation"))
click.echo("Claimed!")
except Exception as e:
click.echo(click.style(str(e), fg="red"))
@main.command()
def keys():
password = "RYzJFo7uXPPoRtew" # P5JNdP5NtnuaispDGX4gUdx6WkEXYLCrkvKYm6dH7mbXgX76VzLz
keys = dict(
active_key=str(PasswordKey("faucet", password, role="active").get_private_key()),
owner_key=str(PasswordKey("faucet", password, role="owner").get_private_key()),
memo_key=str(PasswordKey("faucet", password, role="memo").get_private_key())
)
click.echo(keys)
@main.command()
@click.argument("accounts", nargs=-1)
def accounts(accounts):
""" 3 - create accounts
"""
_accounts = [
{
"name": "faucet",
"password": "RYzJFo7uXPPoRtew",
"registrar": "foundation"
},
{
"name": "debug",
"password": "P5JNdP5NtnuaispDGX4gUdx6WkEXYLCrkvKYm6dH7mbXgX76VzLz"
}
]
for account in _accounts:
if accounts is not None and account["name"] not in accounts:
continue
click.echo(" - Creating account {}".format(account["name"]))
try:
click.echo(
blockchain.create_account(
account["name"], registrar=account.get("registrar", "faucet"), password=account["password"]
)
)
except Exception as e:
click.echo(click.style(str(e), fg="red"))
@main.command()
def upgrade():
""" Upgrade accounts
"""
accounts = ["faucet"]
for account in accounts:
click.echo(" - Upgrading account {}".format(account))
try:
click.echo(Account(account).upgrade())
except Exception as e:
click.echo(click.style(str(e), fg="red"))
@main.command()
@click.argument("account")
@click.argument("reward_percent")
def createwitness(
account,
reward_percent
):
""" Upgrade accounts
"""
click.echo(" - Creating witness for {}".format(account))
try:
click.echo("")
except Exception as e:
click.echo(click.style(str(e), fg="red"))
@main.command()
@click.argument("account")
@click.argument("reward_percent")
def updatewitness(
account,
reward_percent
):
GRAPHENE_1_PERCENT = 100
witness = Witness(account)
account = witness.account
op = operations.Witness_update(
**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"prefix": blockchain.prefix,
"witness": witness["id"],
"witness_account": account["id"],
"block_producer_reward_pct": int(reward_percent) * GRAPHENE_1_PERCENT
}
)
return blockchain.finalizeOp(op, account["name"], "active")
@main.command()
def fund():
""" Fund accounts
"""
accounts = [
"init0",
"init1",
"init2",
"init3",
"init4",
"init5",
"init6",
"init7",
"init8",
"init9",
"init10",
"witness-account",
"faucet"
]
for account in accounts:
click.echo(" - Transferring core token to account {}".format(account))
try:
click.echo(blockchain.transfer(account, 1000000, "DNA", account="foundation"))
except Exception as e:
click.echo(click.style(str(e), fg="red"))
@main.command()
@click.argument("accounts", nargs=-1)
def vote(accounts):
""" 6 - Vote
"""
_vote(accounts)
def _vote(accounts=None):
if not accounts:
accounts = [
"init0",
"init1",
"init2",
"init3",
"init4",
"init5",
"init6",
"init7",
"init8",
"init9",
"init10",
]
try:
click.echo(blockchain.approvewitness(accounts, account="foundation"))
click.echo("Voted!")
except Exception as e:
click.echo(click.style(str(e), fg="red"))
@main.command()
def setupvesting():
_setupvesting()
def _setupvesting():
creator = Account("foundation")
owner = Account("init0")
amount = Amount("10000000 DNA")
op = operations.Vesting_balance_create(
**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"creator": creator["id"],
"owner": owner["id"],
"amount": amount.json(),
"policy": [3, {"duration": 60 * 60 * 24 * 365}],
"extensions": [],
}
)
try:
click.echo(blockchain.finalizeOp(op, creator, "active"))
click.echo("Vested!")
except Exception as e:
click.echo(click.style(str(e), fg="red"))
@main.command()
def fixer():
# claim
_claim("1.15.0")
_setupvesting()
_vote()
if __name__ == "__main__":
main()