コード例 #1
0
ファイル: chain.py プロジェクト: hardice501/hardice
    def forks(self, head):
        (vec_ptr, vec_len,
         vec_cap) = ffi.prepare_vec_result(pointer_type=_BlockPayload)

        head = ctypes.c_char_p(head.encode())

        _libexec('chain_controller_forks', self.pointer, head,
                 ctypes.byref(vec_ptr), ctypes.byref(vec_len),
                 ctypes.byref(vec_cap))

        # Check if NULL
        if not vec_ptr:
            return None

        blocks = []
        for i in range(vec_len.value):
            block_payload = vec_ptr[i]
            payload = ffi.from_rust_vec(
                block_payload.block_ptr,
                ctypes.c_size_t(block_payload.block_len),
                ctypes.c_size_t(block_payload.block_cap),
            )
            block = Block()
            block.ParseFromString(payload)
            blocks.append(BlockWrapper(block))

        LIBRARY.call("chain_controller_reclaim_block_payload_vec", vec_ptr,
                     vec_len, vec_cap)

        return blocks
コード例 #2
0
ファイル: publisher.py プロジェクト: vrogojin/sawtooth-core
    def has_batch(self, batch_id):
        has = ctypes.c_bool(False)
        c_batch_id = ctypes.c_char_p(batch_id.encode())

        LIBRARY.call('incoming_batch_sender_has_batch', self.pointer,
                     c_batch_id, ctypes.byref(has))

        return has
コード例 #3
0
ファイル: publisher.py プロジェクト: cianx/sawtooth-core
    def has_batch(self, batch_id):
        has = ctypes.c_bool(False)
        c_batch_id = ctypes.c_char_p(batch_id.encode())

        LIBRARY.call(
            'incoming_batch_sender_has_batch',
            self.pointer,
            c_batch_id,
            ctypes.byref(has))

        return has
コード例 #4
0
    def __init__(self, path, indexes=None, _size=1024**4):
        super(NativeLmdbDatabase, self).__init__('lmdb_database_drop')

        if indexes is None:
            indexes = []

        c_path = ctypes.c_char_p(path.encode())

        c_indexes = (ctypes.c_char_p * len(indexes))()
        for (i, index) in enumerate(indexes):
            c_indexes[i] = ctypes.c_char_p(index.encode())

        c_size = ctypes.c_size_t(_size)
        res = LIBRARY.call('lmdb_database_new', c_path, c_size, c_indexes,
                           ctypes.c_size_t(len(indexes)),
                           ctypes.byref(self.pointer))
        if res == ErrorCode.Success:
            return
        elif res == ErrorCode.NullPointerProvided:
            raise TypeError("Path cannot be null")
        elif res == ErrorCode.InvalidFilePath:
            raise TypeError("Invalid file path {}".format(path))
        elif res == ErrorCode.InvalidIndexString:
            raise TypeError("Invalid index string {}".format(indexes))
        elif res == ErrorCode.InitializeContextError:
            raise TypeError("Unable to initialize LMDB Context")
        elif res == ErrorCode.InitializeDatabaseError:
            raise TypeError("Unable to initialize LMDB Database")
        else:
            raise TypeError("Unknown error occurred: {}".format(res.error))
コード例 #5
0
ファイル: publisher.py プロジェクト: manojgop/sawtooth-core
    def release(self):
        res = LIBRARY.call("chain_head_guard_drop", self._guard.pointer)

        if res == ChainHeadLockErrorCode.Success:
            return
        if res == ChainHeadLockErrorCode.NullPointerProvided:
            raise TypeError("Provided null pointer(s)")

        raise ValueError("An unknown error occurred: {}".format(res))
コード例 #6
0
ファイル: notifier.py プロジェクト: gluwa/sawtooth-core
    def _notify(self, fn_name, *args):
        return_code = LIBRARY.call(fn_name, self.pointer, *args)

        if return_code == ErrorCode.Success:
            return
        if return_code == ErrorCode.NullPointerProvided:
            raise TypeError("Provided null pointer(s)")
        if return_code == ErrorCode.InvalidArgument:
            raise ValueError("Input was not valid ")
コード例 #7
0
ファイル: publisher.py プロジェクト: Whiteblock/sawtooth-core
    def release(self):
        res = LIBRARY.call(
            "chain_head_guard_drop",
            self._guard.pointer)

        if res == ChainHeadLockErrorCode.Success:
            return
        elif res == ChainHeadLockErrorCode.NullPointerProvided:
            raise TypeError("Provided null pointer(s)")
        else:
            raise ValueError("An unknown error occurred: {}".format(res))
コード例 #8
0
ファイル: publisher.py プロジェクト: manojgop/sawtooth-core
    def acquire(self):
        guard_ptr = ctypes.c_void_p()
        res = LIBRARY.call("chain_head_lock_acquire", self._ptr,
                           ctypes.byref(guard_ptr))

        if res == ChainHeadLockErrorCode.Success:
            self._guard = ChainHeadGuard(guard_ptr)
            return self._guard
        if res == ChainHeadLockErrorCode.NullPointerProvided:
            raise TypeError("Provided null pointer(s)")

        raise ValueError("An unknown error occurred: {}".format(res))
コード例 #9
0
ファイル: notifier.py プロジェクト: hyperledger/sawtooth-core
    def _notify(self, fn_name, *args):
        return_code = LIBRARY.call(
            fn_name,
            self.pointer,
            *args)

        if return_code == ErrorCode.Success:
            return
        if return_code == ErrorCode.NullPointerProvided:
            raise TypeError("Provided null pointer(s)")
        if return_code == ErrorCode.InvalidArgument:
            raise ValueError("Input was not valid ")
コード例 #10
0
ファイル: publisher.py プロジェクト: Whiteblock/sawtooth-core
    def acquire(self):
        guard_ptr = ctypes.c_void_p()
        res = LIBRARY.call(
            "chain_head_lock_acquire",
            self._ptr,
            ctypes.byref(guard_ptr))

        if res == ChainHeadLockErrorCode.Success:
            self._guard = ChainHeadGuard(guard_ptr)
            return self._guard
        elif res == ChainHeadLockErrorCode.NullPointerProvided:
            raise TypeError("Provided null pointer(s)")
        else:
            raise ValueError("An unknown error occurred: {}".format(res))
コード例 #11
0
ファイル: chain.py プロジェクト: cianx/sawtooth-core
    def forks(self, head):
        (vec_ptr, vec_len, vec_cap) = ffi.prepare_vec_result(
            pointer_type=_BlockPayload)

        head = ctypes.c_char_p(head.encode())

        _libexec(
            'chain_controller_forks',
            self.pointer,
            head,
            ctypes.byref(vec_ptr),
            ctypes.byref(vec_len),
            ctypes.byref(vec_cap))

        # Check if NULL
        if not vec_ptr:
            return None

        blocks = []
        for i in range(vec_len.value):
            block_payload = vec_ptr[i]
            payload = ffi.from_rust_vec(
                block_payload.block_ptr,
                ctypes.c_size_t(block_payload.block_len),
                ctypes.c_size_t(block_payload.block_cap),
            )
            block = Block()
            block.ParseFromString(payload)
            blocks.append(block)

        LIBRARY.call(
            "chain_controller_reclaim_block_payload_vec",
            vec_ptr,
            vec_len,
            vec_cap)

        return blocks
コード例 #12
0
ファイル: publisher.py プロジェクト: manojgop/sawtooth-core
    def notify_on_chain_updated(self,
                                chain_head,
                                committed_batches=None,
                                uncommitted_batches=None):
        res = LIBRARY.call("chain_head_guard_on_chain_updated", self.pointer,
                           ctypes.py_object(chain_head),
                           ctypes.py_object(committed_batches),
                           ctypes.py_object(uncommitted_batches))

        if res == ChainHeadLockErrorCode.Success:
            return
        if res == ChainHeadLockErrorCode.NullPointerProvided:
            raise TypeError("Provided null pointer(s)")

        raise ValueError("An unknown error occurred: {}".format(res))
コード例 #13
0
    def send(self, item):
        res = LIBRARY.call("incoming_batch_sender_send", self._ptr,
                           ctypes.py_object(item))

        if res == IncomingBatchSenderErrorCode.Success:
            return

        if res == IncomingBatchSenderErrorCode.NullPointerProvided:
            raise TypeError("Provided null pointer(s)")
        if res == IncomingBatchSenderErrorCode.InvalidInput:
            raise ValueError("Input was not valid ")
        if res == IncomingBatchSenderErrorCode.Disconnected:
            raise Disconnected()

        raise ValueError("An unknown error occurred: {}".format(res))
コード例 #14
0
ファイル: publisher.py プロジェクト: Whiteblock/sawtooth-core
    def notify_on_chain_updated(self,
                                chain_head,
                                committed_batches=None,
                                uncommitted_batches=None):
        res = LIBRARY.call(
            "chain_head_guard_on_chain_updated",
            self.pointer,
            ctypes.py_object(chain_head),
            ctypes.py_object(committed_batches),
            ctypes.py_object(uncommitted_batches))

        if res == ChainHeadLockErrorCode.Success:
            return
        elif res == ChainHeadLockErrorCode.NullPointerProvided:
            raise TypeError("Provided null pointer(s)")
        else:
            raise ValueError("An unknown error occurred: {}".format(res))
コード例 #15
0
    def __init__(self, path, _size=1024**4):
        self._db_ptr = ctypes.c_void_p()

        c_path = ctypes.c_char_p(path.encode())
        c_size = ctypes.c_size_t(_size)
        res = LIBRARY.call('lmdb_database_new', c_path, c_size,
                           ctypes.byref(self._db_ptr))
        if res == ErrorCode.Success:
            return
        elif res == ErrorCode.NullPointerProvided:
            raise TypeError("Path cannot be null")
        elif res == ErrorCode.InvalidFilePath:
            raise TypeError("Invalid file path {}".format(path))
        elif res == ErrorCode.InitializeContextError:
            raise TypeError("Unable to initialize LMDB Context")
        elif res == ErrorCode.InitializeDatabaseError:
            raise TypeError("Unable to initialize LMDB Database")
        else:
            raise TypeError("Unknown error occurred: {}".format(res.error))
コード例 #16
0
    def __init__(self):
        super().__init__("block_status_store_drop")

        _to_exception(
            LIBRARY.call("block_status_store_new", ctypes.byref(self.pointer)))
コード例 #17
0
 def stop(self):
     _to_exception(LIBRARY.call("block_validator_stop", self.pointer))
コード例 #18
0
 def __del__(self):
     if self._db_ptr:
         LIBRARY.call('lmdb_database_drop', self._db_ptr)
         self._db_ptr = None
コード例 #19
0
    def __init__(self):
        super(BlockValidationResultStore, self).__init__(
            "block_status_store_drop")

        _to_exception(LIBRARY.call("block_status_store_new",
                                   ctypes.byref(self.pointer)))
コード例 #20
0
 def stop(self):
     _to_exception(LIBRARY.call("block_validator_stop", self.pointer))