Esempio n. 1
0
    def _get_setting(self, key, default_value=None, value_type=str):
        """Get the setting stored at the given key.

        Args:
            key (str): the setting key
            default_value (str, optional): The default value, if none is
                found. Defaults to None.
            value_type (function, optional): The type of a setting value.
                Defaults to `str`.

        Returns:
            str: The value of the setting if found, default_value
            otherwise.
        """
        try:
            state_entry = self._state_view.get(
                SettingsView.setting_address(key))
        except KeyError:
            return default_value

        if state_entry is not None:
            setting = Setting()
            setting.ParseFromString(state_entry)
            for setting_entry in setting.entries:
                if setting_entry.key == key:
                    return value_type(setting_entry.value)

        return default_value
Esempio n. 2
0
def _get_setting_entry(context, address):
    setting = Setting()

    try:
        entries_list = context.get_state([address], timeout=STATE_TIMEOUT_SEC)
    except FutureTimeoutError:
        LOGGER.warning('Timeout occured on context.get_state([%s])', address)
        raise InternalError('Unable to get {}'.format(address))

    if entries_list:
        setting.ParseFromString(entries_list[0].data)

    return setting
Esempio n. 3
0
def _check_allowed_minter(minting_key, context):
    entries_list = _get_data(ALLOWED_SIGNER_ADDRESS, context)
    if not entries_list:
        raise InvalidTransaction(
            "The transaction signer is not authorized to submit transactions: "
            "{}".format(minting_key))

    setting = Setting()
    setting.ParseFromString(entries_list[0].data)
    for entry in setting.entries:
        if entry.key == "sawtooth.stake.allowed_keys":
            allowed_signer = entry.value.split(",")
            LOGGER.info('minting key: {}'.format(allowed_signer))
            if minting_key == allowed_signer[0]:
                return

    raise InvalidTransaction(
        "The transction signer is not authorized mint stake tokens: "
        "{}".format(minting_key))
Esempio n. 4
0
def _check_allowed_transactor(transaction, context):
    header = transaction.header

    entries_list = _get_data(ALLOWED_SIGNER_ADDRESS, context)
    if not entries_list:
        raise InvalidTransaction(
            "The transaction signer is not authorized to submit transactions: "
            "{}".format(header.signer_public_key))

    setting = Setting()
    setting.ParseFromString(entries_list[0].data)
    for entry in setting.entries:
        if entry.key == "sawtooth.identity.allowed_keys":
            allowed_signer = entry.value.split(",")
            if header.signer_public_key in allowed_signer:
                return

    raise InvalidTransaction(
        "The transction signer is not authorized to submit transactions: "
        "{}".format(header.signer_public_key))
    async def get_initial_stake(self):
        """
        Get initial stake of node.

        To use:
            .. code-block:: python

                initial_stake = await remme.node_management.get_initial_stake()
        """
        data = await self._remme_api.send_request(
            method=RemmeMethods.FETCH_STATE,
            params={
                'address': self._stake_settings_address,
            },
        )

        setting = Setting()
        setting.ParseFromString(base64.b64decode(data.get('data')))

        value = setting.entries[0].value

        return int(value, 10)
Esempio n. 6
0
 def get_setting_value(self, key):
     setting = Setting()
     value = self.get_value(_make_settings_key(key))
     setting.ParseFromString(value)
     return setting.entries[0].value
Esempio n. 7
0
 def get_pub_key_encryption(self):
     setting = Setting()
     setting.ParseFromString(self.get_value(_make_settings_key(SETTINGS_PUB_KEY_ENCRYPTION)))
     return setting.entries[0].value
Esempio n. 8
0
 async def get_pub_key_encryption(self):
     setting = Setting()
     pub_key_enc = _make_settings_key(SETTINGS_PUB_KEY_ENCRYPTION)
     raw_pub_key = await self.get_value(pub_key_enc)
     setting.ParseFromString(raw_pub_key)
     return setting.entries[0].value