Exemple #1
0
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)
Exemple #3
0
    def test_parse_validator_pem_default_index(self):
        pem_file = self.multiple_bls_keys_file
        seed, bls_key = pem.parse_validator_pem(pem_file)

        key_hex = bytes.hex(seed)

        self.assertEqual(
            "f8910e47cf9464777c912e6390758bb39715fffcb861b184017920e4a807b42553f2f21e7f3914b81bcf58b66a72ab16d97013ae1cff807cefc977ef8cbf116258534b9e46d19528042d16ef8374404a89b184e0a4ee18c77c49e454d04eae8d",
            bls_key)
        self.assertEqual(
            "37633139626633613063353763646431666230386534363037636562616133363437643662393236316234363933663631653936653534623231386434343261",
            key_hex)
Exemple #4
0
    def test_parse_validator_pem_n_index(self):
        pem_file = self.multiple_bls_keys_file
        seed, bls_key = pem.parse_validator_pem(pem_file, 3)

        key_hex = bytes.hex(seed)

        self.assertEqual(
            "12773304cb718250edd89770cedcbf675ccdb7fe2b30bd3185ca65ffa0d516879768ed03f92e41a6e5bc5340b78a9d02655e3b727c79730ead791fb68eaa02b84e1be92a816a9604a1ab9a6d3874b638487e2145239438a4bafac3889348d405",
            bls_key)
        self.assertEqual(
            "38656265623037643239366164323532393430306234303638376137343161313335663833353766373966333966636232383934613666393730336135383136",
            key_hex)
Exemple #5
0
def get_validators(num_validators: int) -> Dict[str, Tuple[str, Account]]:
    result = {}

    for i in range(0, num_validators):
        validator_pem_file = get_validator_key_file(i)
        _, pubkey = pem.parse_validator_pem(validator_pem_file)

        pem_file = get_validator_wallet_file(i)
        nickname = "validator{:02}".format(i)
        account = Account(pem_file=pem_file)
        result[nickname] = [pubkey, account]

    return result
Exemple #6
0
def parse_args_for_stake(args: Any):
    validators_file = args.validators_file
    validators_data = _read_json_file(validators_file)

    reward_address = args.reward_address

    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 = len(validators_data.get("validators", []))
    stake_data = 'stake@' + binascii.hexlify(
        num_of_nodes.to_bytes(1, byteorder="little")).decode()
    for validator in validators_data.get("validators", []):
        # get validator
        validator_pem = validator.get("pemFile")
        validator_pem = path.join(path.dirname(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 = _STAKE_SMART_CONTRACT_ADDRESS
    args.data = stake_data

    if args.estimate_gas:
        args.gas_limit = estimate_system_sc_call(args,
                                                 MetaChainSystemSCsCost.STAKE,
                                                 num_of_nodes)

    return args