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
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
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
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))
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))
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 ")
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))
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))
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 ")
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))
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
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))
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))
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))
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))
def __init__(self): super().__init__("block_status_store_drop") _to_exception( LIBRARY.call("block_status_store_new", ctypes.byref(self.pointer)))
def stop(self): _to_exception(LIBRARY.call("block_validator_stop", self.pointer))
def __del__(self): if self._db_ptr: LIBRARY.call('lmdb_database_drop', self._db_ptr) self._db_ptr = None
def __init__(self): super(BlockValidationResultStore, self).__init__( "block_status_store_drop") _to_exception(LIBRARY.call("block_status_store_new", ctypes.byref(self.pointer)))
def stop(self): _to_exception(LIBRARY.call("block_validator_stop", self.pointer))