def validate_payment_address(self, conf_obj): if PAYMENT_ADDRESS not in conf_obj or not conf_obj[PAYMENT_ADDRESS]: raise ConfigurationException("Payment address must be set") pymnt_addr = conf_obj[(PAYMENT_ADDRESS)] if not pymnt_addr: raise ConfigurationException("Payment address must be set") if pymnt_addr.startswith("KT"): raise ConfigurationException( "KT addresses cannot be used for payments. Only tz addresses are allowed" ) if len(pymnt_addr) == PKH_LENGHT and pymnt_addr.startswith("tz"): self.clnt_mngr.check_pkh_known_by_signer(pymnt_addr) conf_obj[("__%s_type" % PAYMENT_ADDRESS)] = AddrType.TZ conf_obj[("__%s_pkh" % PAYMENT_ADDRESS)] = pymnt_addr conf_obj[("__%s_manager" % PAYMENT_ADDRESS)] = pymnt_addr else: raise ConfigurationException( "Payment Address ({}) cannot be translated into a PKH. " "Make sure it is a tz1 address and to first import " "its corresponding secret key to the signer. ".format( pymnt_addr))
def __validate_share_map(self, conf_obj, map_name): """ all shares in the map must sum up to 1 :param conf_obj: configuration object :param map_name: name of the map to validate :return: None """ if map_name not in conf_obj: conf_obj[map_name] = dict() return if isinstance(conf_obj[map_name], str) and conf_obj[map_name].lower() == 'none': conf_obj[map_name] = dict() return if not conf_obj[map_name]: return share_map = conf_obj[map_name] validator = AddressValidator(map_name) for key, value in share_map.items(): validator.validate(key) if len(share_map) > 0: try: if abs(1 - sum(share_map.values()) > 1e-4): # a zero check actually raise ConfigurationException("Map '{}' shares does not sum up to 1!".format(map_name)) except TypeError: raise ConfigurationException("Map '{}' values must be number!".format(map_name))
def validate_rewards_type(self, conf_obj): if REWARDS_TYPE not in conf_obj or conf_obj[REWARDS_TYPE] is None: conf_obj[REWARDS_TYPE] = RewardsType.ACTUAL logger.warning( "[config_parser] Parameter '{:s}' is missing or incorrectly configured. " "Defaults to 'actual' rewards payout type.".format( REWARDS_TYPE)) if conf_obj[REWARDS_TYPE] == RewardsType.ESTIMATED: raise ConfigurationException( "Setting 'rewards_type' to 'estimated' is no longer supported.\n" "Please see https://tezos-reward-distributor-organization.github.io/tezos-reward-distributor/payouttiming.html\n" "for details on how to configure a improved method.") # Validate correct value try: v = conf_obj[REWARDS_TYPE] r_type = RewardsType(v) except ValueError: raise ConfigurationException( "'{:s}' is not a valid option for parameter '{:s}'. " "Please consult the documentation.".format(v, REWARDS_TYPE)) # Reset conf object to be the enum conf_obj[REWARDS_TYPE] = r_type
def validate_payment_address(self, conf_obj): if PAYMENT_ADDRESS not in conf_obj or not conf_obj[PAYMENT_ADDRESS]: raise ConfigurationException("Payment address must be set") pymnt_addr = conf_obj[(PAYMENT_ADDRESS)] if not pymnt_addr: raise ConfigurationException("Payment address must be set") if pymnt_addr.startswith("KT"): raise ConfigurationException( "KT addresses cannot be used for payments. Only tz addresses are allowed" ) if len(pymnt_addr) == PKH_LENGHT and pymnt_addr.startswith("tz"): addr_obj = self.wllt_clnt_mngr.get_addr_dict_by_pkh(pymnt_addr) self.check_sk(addr_obj, pymnt_addr) conf_obj[('__%s_type' % PAYMENT_ADDRESS)] = AddrType.TZ conf_obj[('__%s_pkh' % PAYMENT_ADDRESS)] = pymnt_addr conf_obj[('__%s_manager' % PAYMENT_ADDRESS)] = pymnt_addr else: if pymnt_addr in self.wllt_clnt_mngr.get_known_contracts_by_alias( ): pkh = self.wllt_clnt_mngr.get_known_contract_by_alias( pymnt_addr) if pkh.startswith("KT"): raise ConfigurationException( "KT addresses cannot be used for payments. Only tz addresses are allowed" ) addr_obj = self.wllt_clnt_mngr.get_addr_dict_by_pkh(pkh) self.check_sk(addr_obj, pkh) conf_obj[('__%s_type' % PAYMENT_ADDRESS)] = AddrType.KTALS if pkh.startswith( "KT") else AddrType.TZALS conf_obj[('__%s_pkh' % PAYMENT_ADDRESS)] = pkh conf_obj[( '__%s_manager' % PAYMENT_ADDRESS )] = self.wllt_clnt_mngr.get_manager_for_contract(pkh) else: raise ConfigurationException( "Payment Address ({}) cannot be translated into a PKH or alias. " "If it is an alias import it first. ".format(pymnt_addr)) # if reveal information is present, do not ask if 'revealed' in addr_obj: revealed = addr_obj['revealed']
def __validate_payment_address(self, conf_obj): if PAYMENT_ADDRESS not in conf_obj or not conf_obj[PAYMENT_ADDRESS]: raise ConfigurationException("Payment address must be set") pymnt_addr = conf_obj[(PAYMENT_ADDRESS)] if not pymnt_addr: raise ConfigurationException("Payment address must be set") if len(pymnt_addr) == PKH_LENGHT and (pymnt_addr.startswith("KT") or pymnt_addr.startswith("tz")): addr_obj = self.wllt_clnt_mngr.get_addr_dict_by_pkh(pymnt_addr) self.check_sk(addr_obj, pymnt_addr) conf_obj[('%s_type' % PAYMENT_ADDRESS)] = AddrType.KT if pymnt_addr.startswith( "KT") else AddrType.TZ conf_obj[('%s_pkh' % PAYMENT_ADDRESS)] = pymnt_addr conf_obj[( '%s_manager' % PAYMENT_ADDRESS )] = self.wllt_clnt_mngr.get_manager_for_contract(pymnt_addr) else: if pymnt_addr in self.wllt_clnt_mngr.get_known_contracts_by_alias( ): pkh = self.wllt_clnt_mngr.get_known_contract_by_alias( pymnt_addr) addr_obj = self.wllt_clnt_mngr.get_addr_dict_by_pkh(pkh) self.check_sk(addr_obj, pkh) conf_obj[('%s_type' % PAYMENT_ADDRESS)] = AddrType.KTALS if pkh.startswith( "KT") else AddrType.TZALS conf_obj[('%s_pkh' % PAYMENT_ADDRESS)] = pkh conf_obj[( '%s_manager' % PAYMENT_ADDRESS )] = self.wllt_clnt_mngr.get_manager_for_contract(pkh) else: raise ConfigurationException( "Payment Address ({}) cannot be translated into a PKH or alias. " "If it is an alias import it first. ".format(pymnt_addr)) if not self.block_api.get_revelation( conf_obj[('%s_pkh' % PAYMENT_ADDRESS)]): raise ConfigurationException( "Payment Address ({}) is not eligible for payments. \n" "Public key is not revealed.\n" "Use command 'reveal key for <src>' to reveal your public key. \n" "For implicit accounts, setting your account as delegate is enough.\n" "For more information please refer to tezos command line interface." .format(pymnt_addr))
def validate_plugins(self, conf_obj): if PLUGINS_CONF not in conf_obj: raise ConfigurationException( "Parameter '{:s}' is not present in config file. " "Please consult the documentation and add this parameter.". format(PLUGINS_CONF)) if conf_obj[PLUGINS_CONF] is None or "enabled" not in conf_obj[ PLUGINS_CONF]: raise ConfigurationException( "Plugins config missing 'enabled' parameter. " "Please consult the documentation and add this parameter.")
def __validate_baking_address(self, conf_obj): if BAKING_ADDRESS not in conf_obj or not conf_obj[BAKING_ADDRESS]: raise ConfigurationException("Baking address must be set") baking_address = conf_obj[BAKING_ADDRESS] # key_name must has a length of 36 and starts with tz or KT, an alias is not expected if len(baking_address) == PKH_LENGHT: if not baking_address.startswith("tz"): raise ConfigurationException("Baking address must be a valid tz address") else: raise ConfigurationException("Baking address length must be {}".format(PKH_LENGHT)) pass
def __validate_min_delegation_amt(self, conf_obj): if MIN_DELEGATION_AMT not in conf_obj: conf_obj[MIN_DELEGATION_AMT] = 0 return if not self.__validate_non_negative_int(conf_obj[MIN_DELEGATION_AMT]): raise ConfigurationException("Invalid value:'{}'. {} parameter value must be an non negative integer". format(conf_obj[MIN_DELEGATION_AMT], MIN_DELEGATION_AMT))
def validate_baking_address(self, conf_obj): if BAKING_ADDRESS not in conf_obj or not conf_obj[BAKING_ADDRESS]: raise ConfigurationException("Baking address must be set") baking_address = conf_obj[BAKING_ADDRESS] if baking_address.startswith("KT"): raise ConfigurationException( "KT addresses cannot act as bakers. Only tz addresses can be registered to bake." ) # key_name must has a length of 36 and starts with tz an alias is not expected if len(baking_address) == PKH_LENGHT: if not baking_address.startswith("tz"): raise ConfigurationException( "Baking address must be a valid tz address.") else: if not self.block_api.get_revelation(baking_address): raise ConfigurationException( "Baking address {} did not reveal key.".format( baking_address)) if not self.block_api.get_delegatable(baking_address): raise ConfigurationException( "Baking address {} is not enabled for delegation". format(baking_address)) else: raise ConfigurationException( "Baking address length must be {}".format(PKH_LENGHT))
def __validate_scale(self, conf_obj, scale_name): if scale_name not in conf_obj: conf_obj[scale_name] = None return if isinstance(conf_obj[scale_name], str) and conf_obj[scale_name].lower() == 'none': conf_obj[scale_name] = None return if conf_obj[scale_name] is None: return if not self.__validate_non_negative_int(conf_obj[scale_name]): raise ConfigurationException( "Invalid value:'{}'. {} parameter value must be an non negative integer or None. ". format(conf_obj[scale_name], scale_name))
def validate_rewards_type(self, conf_obj): if REWARDS_TYPE not in conf_obj or conf_obj[REWARDS_TYPE] is None: conf_obj[REWARDS_TYPE] = "actual" logger.warning( "[config_parser] Parameter '{:s}' is missing or incorrectly configured. " "Defaults to 'actual' rewards payout type.".format( REWARDS_TYPE)) # Validate correct value try: v = conf_obj[REWARDS_TYPE] r_type = RewardsType(v) except ValueError: raise ConfigurationException( "'{:s}' is not a valid option for parameter '{:s}'. " "Please consult the documentation.".format(v, REWARDS_TYPE)) # Reset conf object to be the enum conf_obj[REWARDS_TYPE] = r_type
def parse_bool(self, conf_obj, param_name, default): if param_name not in conf_obj: # If required param (ie: no default), raise exception if not defined if default is None: raise ConfigurationException( "Parameter '{}' is not present in config file. Please consult the documentation and add this parameter." .format(param_name)) else: conf_obj[param_name] = default return # already a bool value if type(conf_obj[param_name]) == type(False): return if isinstance(conf_obj[param_name], str) and "true" == conf_obj[param_name].lower(): conf_obj[param_name] = True else: conf_obj[param_name] = False
def check_sk(self, addr_obj, pkh): if not addr_obj['sk']: raise ConfigurationException( "No secret key for Address Obj {} with PKH {}".format( addr_obj, pkh))
def validate_service_fee(self, conf_obj): if SERVICE_FEE not in conf_obj: raise ConfigurationException("Service fee is not set") FeeValidator(SERVICE_FEE).validate(conf_obj[(SERVICE_FEE)])