def prepare_args_for_stake(args: Any): validators_file = ValidatorsFile(args.validators_file) reward_address = args.reward_address # TODO: Refactor, so that only address is received here. if args.pem: account = Account(pem_file=args.pem) elif args.keyfile and args.passfile: account = Account(key_file=args.keyfile, pass_file=args.passfile) num_of_nodes = validators_file.get_num_of_nodes() stake_data = 'stake@' + binascii.hexlify(num_of_nodes.to_bytes(1, byteorder="little")).decode() validators_list = validators_file.get_validators_list() for validator in validators_list: # get validator validator_pem = validator.get("pemFile") validator_pem = path.join(path.dirname(args.validators_file), validator_pem) seed, bls_key = parse_validator_pem(validator_pem) signed_message = sign_message_with_bls_key(account.address.pubkey().hex(), seed.hex()) stake_data += f"@{bls_key}@{signed_message}" if reward_address: reward_address = Address(args.reward_address) stake_data += '@' + reward_address.hex() args.receiver = AUCTION_SMART_CONTRACT_ADDRESS args.data = stake_data if args.estimate_gas: args.gas_limit = estimate_system_sc_call(args, MetaChainSystemSCsCost.STAKE, num_of_nodes)
def prepare_args_for_add_nodes(args: Any): validators_file = ValidatorsFile(args.validators_file) # TODO: Refactor, so that only address is received here. if args.using_delegation_manager: account = Account(address=args.delegation_contract) elif args.pem: account = Account(pem_file=args.pem) elif args.keyfile and args.passfile: account = Account(key_file=args.keyfile, pass_file=args.passfile) add_nodes_data = "addNodes" num_of_nodes = validators_file.get_num_of_nodes() for validator in validators_file.get_validators_list(): # get validator validator_pem = validator.get("pemFile") validator_pem = path.join(path.dirname(args.validators_file), validator_pem) seed, bls_key = parse_validator_pem(validator_pem) signed_message = sign_message_with_bls_key(account.address.pubkey().hex(), seed.decode('ascii')) add_nodes_data += f"@{bls_key}@{signed_message}" args.receiver = args.delegation_contract args.data = add_nodes_data if args.estimate_gas: args.gas_limit = estimate_system_sc_call(args, MetaChainSystemSCsCost.DELEGATION_OPS, num_of_nodes + 1)
def test_read_validators_files_get_validators_list(self): validators_file = ValidatorsFile(self.validators_file_path) validators_list = validators_file.get_validators_list() self.assertEqual(3, len(validators_list))
def test_read_validators_files_num_of_nodes(self): validators_file = ValidatorsFile(self.validators_file_path) num_of_nodes = validators_file.get_num_of_nodes() self.assertEqual(3, num_of_nodes)