def withdrawDelegateReward(address, offline, config, style): """ this is delegate submodule withdrawDelegateReward command. """ wallet_dir = g_dict_dir_config["wallet_dir"] wallet_file_path, private_key, hrp, _ = verify_password(address, wallet_dir) ppos = get_eth_obj(config, 'ppos') _params = {'pri_key': private_key[2:], 'transaction_cfg': None} try: if offline: data = rlp.encode([rlp.encode(int(5000))]) _params['to_type'] = 'delegateReward' transaction_dict = un_sign_data(data, _params, ppos, _params['pri_key']) unsigned_tx_dir = g_dict_dir_config["unsigned_tx_dir"] check_dir_exits(unsigned_tx_dir) unsigned_file_csv_name = "unsigned_delegate_withdrawDelegateReward_{}.csv".format(get_time_stamp()) unsigned_file_path = os.path.join(unsigned_tx_dir, unsigned_file_csv_name) if style == '': write_csv(unsigned_file_path, [transaction_dict]) else: unsigned_file_path = unsigned_file_path.replace('csv', 'jpg') write_QRCode(transaction_dict, unsigned_file_path) else: tx_hash = ppos.withdrawDelegateReward(*_params.values()) cust_print('delegate withdrawDelegateReward send transfer transaction successful, tx hash:{}.'.format(tx_hash),fg='g') except ValueError as e: cust_print('delegate withdrawDelegateReward send transfer transaction fail,error info:{}'.format(e), fg='r') sys.exit(1)
def reportDoubleSign(param, address, offline, config, style): """ this is government submodule reportDoubleSign command. """ if not os.path.isfile(param): cust_print('file {} not exits! please check!'.format(param), fg='r') sys.exit(1) params = read_json_file(param) wallet_dir = g_dict_dir_config["wallet_dir"] _, private_key, _, _ = verify_password(address, wallet_dir) ppos = get_eth_obj(config, 'ppos') try: _params = {'typ': params['type'], 'data': params['data']} except KeyError as e: cust_print( 'reportDoubleSign need params {},but it does not exist,please check!' .format(e), fg='r') sys.exit(1) try: if offline: data = rlp.encode([ rlp.encode(int(3000)), rlp.encode(params['type']), rlp.encode(params['data']) ]) _params['transaction_cfg'] = params.get('transaction_cfg', None) _params['to_type'] = 'penalty' transaction_dict = un_sign_data(data, _params, ppos, private_key[2:]) unsigned_tx_dir = g_dict_dir_config["unsigned_tx_dir"] check_dir_exits(unsigned_tx_dir) unsigned_file_csv_name = "unsigned_government_reportDoubleSign_{}.csv".format( get_time_stamp()) unsigned_file_path = os.path.join(unsigned_tx_dir, unsigned_file_csv_name) if style == '': write_csv(unsigned_file_path, [transaction_dict]) else: unsigned_file_path = unsigned_file_path.replace('csv', 'jpg') write_QRCode(transaction_dict, unsigned_file_path) cust_print('unsigned_file save to:{}'.format(unsigned_file_path), fg='g') else: _params['pri_key'] = private_key[2:] _params['transaction_cfg'] = params.get('transaction_cfg', None) txhash = ppos.reportDuplicateSign(*_params.values()) cust_print( 'send raw transfer transaction successful, tx hash:{}.'.format( txhash), fg='g') except Exception as e: cust_print( 'government send transfer transaction fail,error info:{}'.format( e), fg='r') sys.exit(1)
def vote(param, address, offline, config, style): """ this is government submodule vote command. """ if not os.path.isfile(param): cust_print('file {} not exits! please check!'.format(param), fg='r') sys.exit(1) params = read_json_file(param) try: _params = {'verifier': params['verifier'], 'proposalId': params['proposalId'], 'option': int(params['option'])} except KeyError as e: cust_print('vote need params {},but it does not exist,please check!'.format(e), fg='r') sys.exit(1) wallet_dir = g_dict_dir_config["wallet_dir"] _, private_key, _, _ = verify_password(address, wallet_dir) ppos = get_eth_obj(config, 'ppos') pip = get_eth_obj(config, 'pip') msg = ppos.admin.getProgramVersion() program_version = msg['Version'] version_sign = msg['Sign'] try: if offline: data = rlp.encode( [rlp.encode(int(2003)), rlp.encode(bytes.fromhex(params['verifier'])), rlp.encode(bytes.fromhex(params['proposalId'])), rlp.encode(params['option']), rlp.encode(int(program_version)), rlp.encode(bytes.fromhex(version_sign))]) _params['transaction_cfg'] = params.get('transaction_cfg', None) _params['to_type'] = 'pip' transaction_dict = un_sign_data(data, _params, pip, private_key[2:]) unsigned_tx_dir = g_dict_dir_config["unsigned_tx_dir"] check_dir_exits(unsigned_tx_dir) unsigned_file_csv_name = "unsigned_government_vote_{}.csv".format(get_time_stamp()) unsigned_file_path = os.path.join(unsigned_tx_dir, unsigned_file_csv_name) if style == '': write_csv(unsigned_file_path, [transaction_dict]) else: unsigned_file_path = unsigned_file_path.replace('csv', 'jpg') write_QRCode(transaction_dict, unsigned_file_path) cust_print('unsigned_file save to:{}'.format(unsigned_file_path), fg='g') else: _params['program_version'] = program_version _params['version_sign'] = version_sign _params['pri_key'] = private_key[2:] _params['transaction_cfg'] = params.get('transaction_cfg', None) txhash = pip.vote(*_params.values()) cust_print('send raw transfer transaction successful, tx hash:{}.'.format(txhash), fg='g') except Exception as e: cust_print('vote send transfer transaction fail,error info:{}'.format(e), fg='r') sys.exit(1)
def unStaking(address, file, config, offline, style): """ this is staking submodule unStaking command. """ params = read_json_file(file) node_id = params['node_id'] transaction_cfg = params['transaction_cfg'] check_node_id(node_id) wallet_dir = g_dict_dir_config["wallet_dir"] _, private_key, _, _ = verify_password(address, wallet_dir) private_key = private_key[2:] ppos = get_eth_obj(config, 'ppos') try: if offline: unsigned_tx_dir = g_dict_dir_config["unsigned_tx_dir"] check_dir_exits(unsigned_tx_dir) unsigned_file_csv_name = "unsigned_staking_unStaking_{}.csv".format( get_time_stamp()) unsigned_file_path = os.path.join(unsigned_tx_dir, unsigned_file_csv_name) data = rlp.encode( [rlp.encode(int(1003)), rlp.encode(bytes.fromhex(node_id))]) params['to_type'] = 'staking' transaction_dict = un_sign_data(data, params, ppos, private_key) if style == '': write_csv(unsigned_file_path, [transaction_dict]) else: unsigned_file_path = unsigned_file_path.replace('csv', 'jpg') write_QRCode(transaction_dict, unsigned_file_path) cust_print('unsigned_file save to:{}'.format(unsigned_file_path), fg='g') else: tx_hash = ppos.withdrewStaking(node_id, private_key, transaction_cfg) cust_print( 'withdrewStaking send transfer transaction successful, tx hash:{}.' .format(tx_hash), fg='g') except ValueError as e: cust_print( 'unStaking send transfer transaction fail,error info:{}'.format(e), fg='r') sys.exit(1)
def create(file, address, template, config, offline, style): """ this is staking submodule create command. """ if template: show_params() return if not os.path.isfile(file): cust_print('file {} not exits! please check!'.format(file), fg='r') sys.exit(1) params = read_json_file(file) wallet_dir = g_dict_dir_config["wallet_dir"] wallet_file_path, private_key, hrp, _ = verify_password(address, wallet_dir) ppos = get_eth_obj(config, 'ppos') msg = ppos.admin.getProgramVersion() bls_pubkey = ppos.admin.nodeInfo.blsPubKey bls_proof = ppos.admin.getSchnorrNIZKProve() program_version = msg['Version'] program_version_sign = msg['Sign'] _params = {} try: _params['typ'] = params['typ'] _params['benifit_address'] = params['benifit_address'] _params['node_id'] = params['node_id'] or ppos.admin.nodeInfo.id _params['external_id'] = params['external_id'] _params['node_name'] = params['node_name'] _params['website'] = params['website'] _params['details'] = params['details'] _params['amount'] = ppos.w3.toWei(str(params['amount']), "ether") _params['program_version'] = params['program_version'] or program_version _params['program_version_sign'] = params['program_version_sign'] or program_version_sign _params['bls_pubkey'] = params['bls_pubkey'] or bls_pubkey _params['bls_proof'] = params['bls_proof'] or bls_proof _params['pri_key'] = private_key[2:] _params['reward_per'] = params['reward_per'] if isinstance(params['transaction_cfg'], dict): _params['transaction_cfg'] = params['transaction_cfg'] except KeyError as e: cust_print('Key {} does not exist in file {},please check!'.format(e, file), fg='r') sys.exit(1) try: if offline: data = rlp_params(tuple(_params.values()), hrp) params['to_type'] = 'staking' transaction_dict = un_sign_data(data, params, ppos, _params['pri_key']) unsigned_tx_dir = g_dict_dir_config["unsigned_tx_dir"] check_dir_exits(unsigned_tx_dir) unsigned_file_csv_name = "unsigned_staking_create_{}.csv".format(get_time_stamp()) unsigned_file_path = os.path.join(unsigned_tx_dir, unsigned_file_csv_name) if style == '': write_csv(unsigned_file_path, [transaction_dict]) else: unsigned_file_path = unsigned_file_path.replace('csv', 'jpg') write_QRCode(transaction_dict, unsigned_file_path) cust_print('unsigned_file save to:{}'.format(unsigned_file_path), fg='g') else: tx_hash = ppos.createStaking(*_params.values()) cust_print('createStaking send transfer transaction successful, tx hash:{}.'.format(tx_hash), fg='g') except ValueError as e: cust_print('createStaking send transfer transaction fail,error info:{}'.format(e)) sys.exit(1)
def increase(file, address, template, config, offline, style): """ this is staking submodule increase command. """ if template: show_params() return if not os.path.isfile(file): cust_print('file {} not exits! please check!'.format(file), fg='r') sys.exit(1) params = read_json_file(file) wallet_dir = g_dict_dir_config["wallet_dir"] wallet_file_path, private_key, hrp, _ = verify_password( address, wallet_dir) ppos = get_eth_obj(config, 'ppos') _params = {} try: _params['typ'] = params['typ'] _params['node_id'] = params['node_id'] or ppos.admin.nodeInfo.id _params['amount'] = ppos.w3.toWei(str(params['amount']), "ether") _params['pri_key'] = private_key[2:] if isinstance(params['transaction_cfg'], dict): _params['transaction_cfg'] = params['transaction_cfg'] except KeyError as e: cust_print('Key {} does not exist in file {},please check!'.format( e, file), fg='r') sys.exit(1) try: if offline: data = HexBytes( rlp.encode([ rlp.encode(int(1002)), rlp.encode(bytes.fromhex(_params['node_id'])), rlp.encode(_params['typ']), rlp.encode(_params['amount']) ])).hex() params['to_type'] = 'staking' transaction_dict = un_sign_data(data, params, ppos, _params['pri_key']) unsigned_tx_dir = g_dict_dir_config["unsigned_tx_dir"] check_dir_exits(unsigned_tx_dir) unsigned_file_csv_name = "unsigned_staking_increase_{}.csv".format( get_time_stamp()) unsigned_file_path = os.path.join(unsigned_tx_dir, unsigned_file_csv_name) if style == '': write_csv(unsigned_file_path, [transaction_dict]) else: unsigned_file_path = unsigned_file_path.replace('csv', 'jpg') write_QRCode(transaction_dict, unsigned_file_path) cust_print('unsigned_file save to:{}'.format(unsigned_file_path), fg='g') else: tx_hash = ppos.increaseStaking(*_params.values()) cust_print( 'increase staking send transfer transaction successful, tx hash:{}.' .format(tx_hash), fg='g') except ValueError as e: cust_print( 'increase staking send transfer transaction fail,error info:{}'. format(e), fg='r') sys.exit(1)
def createRestrictingPlan(param, address, offline, config, style): """ this is government submodule vote command. """ if not os.path.isfile(param): cust_print('file {} not exits! please check!'.format(param), fg='r') sys.exit(1) params = read_json_file(param) ppos = get_eth_obj(config, 'ppos') try: params['plans'] = [{ 'epoch': plan['epoch'], 'amount': ppos.web3.toWei(str(plan['amount']), "ether") } for plan in params['plans']] _params = {'account': params['account'], 'plans': params['plans']} except KeyError as e: cust_print( 'createRestrictingPlan need params {},but it does not exist,please check!' .format(e), fg='r') sys.exit(1) wallet_dir = g_dict_dir_config["wallet_dir"] _, private_key, hrp, _ = verify_password(address, wallet_dir) try: if offline: account = bech32_address_bytes(hrp)(params['account']) plan_list = [[plan[k] for k in plan] for plan in params['plans']] data = rlp.encode([ rlp.encode(int(4000)), rlp.encode(account), rlp.encode(plan_list) ]) _params['transaction_cfg'] = params.get('transaction_cfg', None) _params['to_type'] = 'restricting' transaction_dict = un_sign_data(data, _params, ppos, private_key[2:]) unsigned_tx_dir = g_dict_dir_config["unsigned_tx_dir"] check_dir_exits(unsigned_tx_dir) unsigned_file_csv_name = "unsigned_hedge_createRestrictingPlan_{}.csv".format( get_time_stamp()) unsigned_file_path = os.path.join(unsigned_tx_dir, unsigned_file_csv_name) if style == '': write_csv(unsigned_file_path, [transaction_dict]) else: unsigned_file_path = unsigned_file_path.replace('csv', 'jpg') write_QRCode(transaction_dict, unsigned_file_path) cust_print('unsigned_file save to:{}'.format(unsigned_file_path), fg='g') else: _params['pri_key'] = private_key[2:] _params['transaction_cfg'] = params.get('transaction_cfg', None) txhash = ppos.createRestrictingPlan(*_params.values()) cust_print( 'send raw transfer transaction successful, tx hash:{}.'.format( txhash), fg='g') except Exception as e: cust_print( 'createRestrictingPlan send transfer transaction fail,error info:{}' .format(e), fg='r') sys.exit(1)
def submitProposal(param, address, offline, module, config, style): """ this is government submodule submitProposal command. """ if not os.path.isfile(param): cust_print('file {} not exits! please check!'.format(param), fg='r') sys.exit(1) params = read_json_file(param) check_params(params) _params = {'verifier': params['verifier'], 'pip_id': params['pIDID']} _module, func = method_module[module] try: if _module == 'submitVersion': _params['new_version'] = params['newVersion'] _params['end_voting_rounds'] = params['endVotingRound'] if _module == 'submitCancel': _params['end_voting_rounds'] = params['endVotingRound'] _params['tobe_canceled_proposal_id'] = params['canceledProposalID'] if _module == 'submitParam': _params['module'] = params['module'] _params['name'] = params['name'] _params['new_value'] = params['newValue'] except KeyError as e: cust_print( '{} need params {},but it does not exist,please check!'.format( module, e), fg='r') sys.exit(1) wallet_dir = g_dict_dir_config["wallet_dir"] _, private_key, _, _ = verify_password(address, wallet_dir) pip = get_eth_obj(config, 'pip') module, func = method_module[module] try: if offline: data = rlp_params(func, *_params.values()) _params['transaction_cfg'] = params.get('transaction_cfg', None) _params['to_type'] = 'pip' transaction_dict = un_sign_data(data, _params, pip, private_key[2:]) unsigned_tx_dir = g_dict_dir_config["unsigned_tx_dir"] check_dir_exits(unsigned_tx_dir) unsigned_file_csv_name = "unsigned_submitProposal_{}_{}.csv".format( module, get_time_stamp()) unsigned_file_path = os.path.join(unsigned_tx_dir, unsigned_file_csv_name) if style == '': write_csv(unsigned_file_path, [transaction_dict]) else: unsigned_file_path = unsigned_file_path.replace('csv', 'jpg') write_QRCode(transaction_dict, unsigned_file_path) cust_print('unsigned_file save to:{}'.format(unsigned_file_path), fg='g') else: _params['pri_key'] = private_key[2:] _params['transaction_cfg'] = params.get('transaction_cfg', None) txhash = getattr(pip, module)(*_params.values()) cust_print( 'send raw transfer transaction successful, tx hash:{}.'.format( txhash), fg='g') except Exception as e: cust_print( 'submitProposal {} send transfer transaction fail,error info:{}'. format(module, e), fg='r') sys.exit(1)