def __init__(self, ledger_id: int, state_root_hash: str, pool_state_root_hash: str, txn_root_hash: str, timestamp: int): ''' :param ledger_id: id of the ledger multisig is created over :param state_root_hash: root hash (base58) of the state associated with ledger_id and multisig is created over :param pool_state_root_hash: root hash (base58) of pool state needed to anchor the state of Nodes participated in multisig :param txn_root_hash: root hash (base58) of the ledger associated with ledger_id and multisig is created over :param timestamp: timestamp of the state the multisig is created over ''' if not isinstance(ledger_id, int): raise PlenumTypeError('ledger_id', ledger_id, int) if not isinstance(state_root_hash, str): raise PlenumTypeError('state_root_hash', state_root_hash, str) if not isinstance(pool_state_root_hash, str): raise PlenumTypeError('pool_state_root_hash', pool_state_root_hash, str) if not isinstance(txn_root_hash, str): raise PlenumTypeError('txn_root_hash', txn_root_hash, str) if not isinstance(timestamp, int): raise PlenumTypeError('timestamp', timestamp, int) self.ledger_id = ledger_id self.state_root_hash = state_root_hash self.pool_state_root_hash = pool_state_root_hash self.txn_root_hash = txn_root_hash self.timestamp = timestamp
def save_keys(self, sk: str, pk: str): if not isinstance(sk, str): raise PlenumTypeError('sk', sk, str) if not isinstance(pk, str): raise PlenumTypeError('pk', pk, str) self._save_secret_key(sk) self._save_public_key(pk) return sk, pk
def __init__(self, name, encoder, decoder): if not isinstance(name, str): raise PlenumTypeError('name', name, str) if not name: raise PlenumValueError('name', name, 'a non-empty string') if not callable(encoder): raise PlenumTypeError('encoder', encoder, 'callable') if not callable(decoder): raise PlenumTypeError('decoder', decoder, 'callable') self.name = name self.encoder = encoder self.decoder = decoder
def __init__(self, sk: str, pk: str, params: GroupParams): if not isinstance(sk, str): raise PlenumTypeError('sk', sk, str) if not sk: raise ValueError("'sk' should be a non-empty string") if not isinstance(pk, str): raise PlenumTypeError('pk', pk, str) if not pk: raise ValueError("'pk' should be a non-empty string") self._sk = sk self.pk = pk self._group_params = params
def __init__(self, max_size=None, **kwargs): if max_size is not None: if not isinstance(max_size, int): raise PlenumTypeError('max_size', max_size, int) if not max_size > 0: raise PlenumValueError('max_size', max_size, '> 0') self.max_size = max_size super().__init__(**kwargs)
def randomStr(size): if not isinstance(size, int): raise PlenumTypeError('size', size, int) if not size > 0: raise PlenumValueError('size', size, '> 0') # Approach 1 rv = randombytes(size // 2).hex() return rv if size % 2 == 0 else rv + hex(randombytes_uniform(15))[-1]
def __init__(self, signature: str, participants: list, value: MultiSignatureValue): """ :param signature: Multi signature itself :param participants: List of signers :param value: the value multi-signature was created over """ if not isinstance(signature, str): raise PlenumTypeError('signature', signature, str) if not isinstance(participants, list): raise PlenumTypeError('participants', participants, list) if not participants: raise ValueError("'participants' list shouldn't be empty") if not isinstance(value, MultiSignatureValue): raise PlenumTypeError('value', value, MultiSignatureValue) self.signature = signature self.participants = participants self.value = value
def __init__(self, inner_field_type: FieldValidator, min_length=None, max_length=None, **kwargs): if not isinstance(inner_field_type, FieldValidator): raise PlenumTypeError( 'inner_field_type', inner_field_type, FieldValidator) for k in ('min_length', 'max_length'): m = locals()[k] if m is not None: if not isinstance(m, int): raise PlenumTypeError(k, m, int) if not m > 0: raise PlenumValueError(k, m, '> 0') self.inner_field_type = inner_field_type self.min_length = min_length self.max_length = max_length super().__init__(**kwargs)
def test_PlenumTypeError(): aaa = 1 exc = PlenumTypeError('aaa', aaa, str, prefix="PREFIX") assert isinstance(exc, PlenumError) assert isinstance(exc, TypeError) exc_str = str(exc) assert exc_str.startswith("PREFIX: ") assert "variable 'aaa'" in exc_str assert "type {}".format(type(aaa)) in exc_str assert "expected: {}".format(str) in exc_str
def set_root_hash(self, root_hash): if not is_string(root_hash): raise PlenumTypeError('root_hash', root_hash, bytes) if not (len(root_hash) in [0, 32]): raise PlenumValueError('root_hash', root_hash, 'length in range [0, 32]') if self.transient: self.transient_root_hash = root_hash return if root_hash == BLANK_ROOT: self.root_node = BLANK_NODE return # print(repr(root_hash)) self.root_node = self._decode_to_node(root_hash)
def __init__(self, windowSize, delayFunction=None): """ Limits rate of actions performed in a unit of time (window) :param windowSize: size (in seconds) of the time window events counted in :param delayFunction: function from **number of actions** to **time to wait after the last one** """ if not isinstance(windowSize, int): raise PlenumTypeError('windowSize', windowSize, int) if not windowSize > 0: raise PlenumValueError('windowSize', windowSize, '> 0') self.windowSize = windowSize self.delayFunction = delayFunction if delayFunction else self._defaultDelayFunction self.actionsLog = []
def reconnectRemote(self, remote): """ Disconnect remote and connect to it again :param remote: instance of Remote from self.remotes :param remoteName: name of remote :return: """ if not isinstance(remote, Remote): raise PlenumTypeError('remote', remote, Remote) logger.info('{} reconnecting to {}'.format(self, remote)) public, secret = self.selfEncKeys remote.disconnect() remote.connect(self.ctx, public, secret) self.sendPingPong(remote, is_ping=True)
def __getitem__(self, item): if not isinstance(item, int): raise PlenumTypeError('item', item, int) return self._replicas[item]
def validate_field(field): if not isinstance(field, IterableField): # This exception will be caught up on the top level of static validation phase and # Reply with this message will be sent to client. raise PlenumTypeError("Field {} should be a variable of type {}".format(field, IterableField))