From 05fa8548b097759b9f06742169275ce0ee1cb950 Mon Sep 17 00:00:00 2001 From: foefl Date: Mon, 15 Dec 2025 16:47:59 +0100 Subject: [PATCH] basic blockchain functionality incl. data hashing --- setup.py | 8 +- src/polluck_blockchain/placeholder_native.cpp | 5858 +++++++++-------- src/polluck_blockchain/placeholder_native.pyx | 435 +- 3 files changed, 3447 insertions(+), 2854 deletions(-) diff --git a/setup.py b/setup.py index 3770cec..49d96d1 100644 --- a/setup.py +++ b/setup.py @@ -12,6 +12,7 @@ Options.embed_pos_in_docstring = False Options.annotate = False Options.fast_fail = True +OPEN_MP = False DEBUG = bool(os.getenv("DOPT_DEBUG", None)) linetrace_opt: bool = False if DEBUG: @@ -60,8 +61,11 @@ linker_args: list[str] = [] if sys.platform.startswith("win") and not DEBUG: - c_args = ("/O2", "/GL", "/Gy", "/openmp:llvm") - l_args = ("/LTCG", "/OPT:REF", "/OPT:ICF", "/openmp:llvm") + c_args = ["/O2", "/GL", "/Gy"] + l_args = ["/LTCG", "/OPT:REF", "/OPT:ICF"] + if OPEN_MP: + c_args.extend(["/openmp:llvm"]) + l_args.extend(["/openmp:llvm"]) else: c_args = tuple() l_args = tuple() diff --git a/src/polluck_blockchain/placeholder_native.cpp b/src/polluck_blockchain/placeholder_native.cpp index 53e8036..da77328 100644 --- a/src/polluck_blockchain/placeholder_native.cpp +++ b/src/polluck_blockchain/placeholder_native.cpp @@ -1590,7 +1590,7 @@ static const char* const __pyx_f[] = { * * ctypedef unsigned long ULong # <<<<<<<<<<<<<< * ctypedef unordered_map[uint64_t, Block*] BcHashmap - * + * cdef const size_t NONCE_OFFSET = 16 */ typedef unsigned long __pyx_t_18polluck_blockchain_18placeholder_native_ULong; /* #### Code section: complex_type_declarations ### */ @@ -1600,18 +1600,18 @@ typedef unsigned long __pyx_t_18polluck_blockchain_18placeholder_native_ULong; struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock; struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain; struct __pyx_opt_args_18polluck_blockchain_18placeholder_native_7PyBlock_from_ptr; -struct __pyx_opt_args_18polluck_blockchain_18placeholder_native_7PyBlock_mine; +struct __pyx_opt_args_18polluck_blockchain_18placeholder_native_mine_block; /* "polluck_blockchain/placeholder_native.pyx":28 * * ctypedef unsigned long ULong * ctypedef unordered_map[uint64_t, Block*] BcHashmap # <<<<<<<<<<<<<< + * cdef const size_t NONCE_OFFSET = 16 * - * cdef timestamp_to_datetime(uint64_t ts): */ typedef std::unordered_map __pyx_t_18polluck_blockchain_18placeholder_native_BcHashmap; -/* "polluck_blockchain/placeholder_native.pyx":124 +/* "polluck_blockchain/placeholder_native.pyx":121 * * @staticmethod * cdef PyBlock from_ptr(Block *block, bint owner=False): # <<<<<<<<<<<<<< @@ -1623,19 +1623,19 @@ struct __pyx_opt_args_18polluck_blockchain_18placeholder_native_7PyBlock_from_pt int owner; }; -/* "polluck_blockchain/placeholder_native.pyx":264 - * free(serialize_res) +/* "polluck_blockchain/placeholder_native.pyx":276 * - * cpdef mine(self, unsigned int difficulty, unsigned int max_nonce=0xFFFFFFFF): # <<<<<<<<<<<<<< - * cdef: - * unsigned char *serial_buf + * + * cdef int mine_block(Block *block, unsigned int difficulty, uint64_t *nonce_solution, unsigned int max_nonce=0xFFFFFFFF) nogil: # <<<<<<<<<<<<<< + * cdef: + * unsigned char *serial_buf */ -struct __pyx_opt_args_18polluck_blockchain_18placeholder_native_7PyBlock_mine { +struct __pyx_opt_args_18polluck_blockchain_18placeholder_native_mine_block { int __pyx_n; unsigned int max_nonce; }; -/* "polluck_blockchain/placeholder_native.pyx":88 +/* "polluck_blockchain/placeholder_native.pyx":85 * * * cdef class PyBlock: # <<<<<<<<<<<<<< @@ -1650,17 +1650,17 @@ struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock { }; -/* "polluck_blockchain/placeholder_native.pyx":339 +/* "polluck_blockchain/placeholder_native.pyx":307 * * * cdef class Blockchain: # <<<<<<<<<<<<<< - * cdef int _difficulty + * cdef unsigned int _difficulty * cdef uint64_t _index */ struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain { PyObject_HEAD struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_vtab; - int _difficulty; + unsigned int _difficulty; uint64_t _index; __pyx_t_18polluck_blockchain_18placeholder_native_BcHashmap *_chain; int _genesis_done; @@ -1668,7 +1668,7 @@ struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain { -/* "polluck_blockchain/placeholder_native.pyx":88 +/* "polluck_blockchain/placeholder_native.pyx":85 * * * cdef class PyBlock: # <<<<<<<<<<<<<< @@ -1678,26 +1678,22 @@ struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain { struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_PyBlock { struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *(*from_ptr)(::Block *, struct __pyx_opt_args_18polluck_blockchain_18placeholder_native_7PyBlock_from_ptr *__pyx_optional_args); - unsigned char *(*bytes_serialize_c)(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *, size_t *); - unsigned char *(*digest)(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *, unsigned char *, size_t, size_t *); - PyObject *(*mine)(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *, unsigned int, int __pyx_skip_dispatch, struct __pyx_opt_args_18polluck_blockchain_18placeholder_native_7PyBlock_mine *__pyx_optional_args); - unsigned char *(*perform_hash_c)(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *, size_t *); - PyObject *(*perform_hash)(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *, int __pyx_skip_dispatch); }; static struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_vtabptr_18polluck_blockchain_18placeholder_native_PyBlock; -/* "polluck_blockchain/placeholder_native.pyx":339 +/* "polluck_blockchain/placeholder_native.pyx":307 * * * cdef class Blockchain: # <<<<<<<<<<<<<< - * cdef int _difficulty + * cdef unsigned int _difficulty * cdef uint64_t _index */ struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_Blockchain { ::Block *(*get_block_c)(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *, uint64_t); - void (*add_block)(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *, ::Block *); + int (*add_block)(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *, ::Block *); + std::string (*hash_data)(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *, PyObject *); }; static struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_vtabptr_18polluck_blockchain_18placeholder_native_Blockchain; /* #### Code section: utility_code_proto ### */ @@ -1910,6 +1906,31 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObj static PyObject *__Pyx_PyObject_FastCallMethod(PyObject *name, PyObject *const *args, size_t nargsf); #endif +/* PyObjectVectorCallKwBuilder.proto (used by PyObjectVectorCallMethodKwBuilder) */ +CYTHON_UNUSED static int __Pyx_VectorcallBuilder_AddArg_Check(PyObject *key, PyObject *value, PyObject *builder, PyObject **args, int n); +#if CYTHON_VECTORCALL +#if PY_VERSION_HEX >= 0x03090000 +#define __Pyx_Object_Vectorcall_CallFromBuilder PyObject_Vectorcall +#else +#define __Pyx_Object_Vectorcall_CallFromBuilder _PyObject_Vectorcall +#endif +#define __Pyx_MakeVectorcallBuilderKwds(n) PyTuple_New(n) +static int __Pyx_VectorcallBuilder_AddArg(PyObject *key, PyObject *value, PyObject *builder, PyObject **args, int n); +static int __Pyx_VectorcallBuilder_AddArgStr(const char *key, PyObject *value, PyObject *builder, PyObject **args, int n); +#else +#define __Pyx_Object_Vectorcall_CallFromBuilder __Pyx_PyObject_FastCallDict +#define __Pyx_MakeVectorcallBuilderKwds(n) __Pyx_PyDict_NewPresized(n) +#define __Pyx_VectorcallBuilder_AddArg(key, value, builder, args, n) PyDict_SetItem(builder, key, value) +#define __Pyx_VectorcallBuilder_AddArgStr(key, value, builder, args, n) PyDict_SetItemString(builder, key, value) +#endif + +/* PyObjectVectorCallMethodKwBuilder.proto */ +#if CYTHON_VECTORCALL && PY_VERSION_HEX >= 0x03090000 +#define __Pyx_Object_VectorcallMethod_CallFromBuilder PyObject_VectorcallMethod +#else +static PyObject *__Pyx_Object_VectorcallMethod_CallFromBuilder(PyObject *name, PyObject *const *args, size_t nargsf, PyObject *kwnames); +#endif + /* DivInt[long].proto */ static CYTHON_INLINE long __Pyx_div_long(long, long, int b_is_constant); @@ -2184,15 +2205,6 @@ static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject #define __Pyx_ExceptionReset(type, value, tb) PyErr_SetExcInfo(type, value, tb) #endif -/* ErrOccurredWithGIL.proto */ -static CYTHON_INLINE int __Pyx_ErrOccurredWithGIL(void); - -/* PyRuntimeError_Check.proto */ -#define __Pyx_PyExc_RuntimeError_Check(obj) __Pyx_TypeCheck(obj, PyExc_RuntimeError) - -/* RaiseException.export */ -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); - /* MoveIfSupported.proto */ #if CYTHON_USE_CPP_STD_MOVE #include @@ -2204,12 +2216,38 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject /* PyTypeError_Check.proto */ #define __Pyx_PyExc_TypeError_Check(obj) __Pyx_TypeCheck(obj, PyExc_TypeError) +/* RaiseException.export */ +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); + +/* ErrOccurredWithGIL.proto */ +static CYTHON_INLINE int __Pyx_ErrOccurredWithGIL(void); + +/* ReleaseUnknownGil.proto */ +#if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030d0000 +typedef struct { + PyThreadState* ts; + PyGILState_STATE gil_state; +} __Pyx_UnknownThreadState; +#else +#define __Pyx_UnknownThreadState PyThreadState* +#endif +static __Pyx_UnknownThreadState __Pyx_SaveUnknownThread(void); +static void __Pyx_RestoreUnknownThread(__Pyx_UnknownThreadState state); +static CYTHON_INLINE int __Pyx_UnknownThreadStateDefinitelyHadGil(__Pyx_UnknownThreadState state); +static CYTHON_INLINE int __Pyx_UnknownThreadStateMayHaveHadGil(__Pyx_UnknownThreadState state); + /* PyMemoryError_Check.proto */ #define __Pyx_PyExc_MemoryError_Check(obj) __Pyx_TypeCheck(obj, PyExc_MemoryError) +/* PyValueError_Check.proto */ +#define __Pyx_PyExc_ValueError_Check(obj) __Pyx_TypeCheck(obj, PyExc_ValueError) + /* PyIndexError_Check.proto */ #define __Pyx_PyExc_IndexError_Check(obj) __Pyx_TypeCheck(obj, PyExc_IndexError) +/* PyRuntimeError_Check.proto */ +#define __Pyx_PyExc_RuntimeError_Check(obj) __Pyx_TypeCheck(obj, PyExc_RuntimeError) + /* AllocateExtensionType.proto */ static PyObject *__Pyx_AllocateExtensionType(PyTypeObject *t, int is_final); @@ -2486,42 +2524,24 @@ static void __Pyx_CppExn2PyErr() { } #endif -/* CIntFromPy.proto */ -static CYTHON_INLINE unsigned int __Pyx_PyLong_As_unsigned_int(PyObject *); - -/* PyObjectVectorCallKwBuilder.proto (used by CIntToPy) */ -CYTHON_UNUSED static int __Pyx_VectorcallBuilder_AddArg_Check(PyObject *key, PyObject *value, PyObject *builder, PyObject **args, int n); -#if CYTHON_VECTORCALL -#if PY_VERSION_HEX >= 0x03090000 -#define __Pyx_Object_Vectorcall_CallFromBuilder PyObject_Vectorcall -#else -#define __Pyx_Object_Vectorcall_CallFromBuilder _PyObject_Vectorcall -#endif -#define __Pyx_MakeVectorcallBuilderKwds(n) PyTuple_New(n) -static int __Pyx_VectorcallBuilder_AddArg(PyObject *key, PyObject *value, PyObject *builder, PyObject **args, int n); -static int __Pyx_VectorcallBuilder_AddArgStr(const char *key, PyObject *value, PyObject *builder, PyObject **args, int n); -#else -#define __Pyx_Object_Vectorcall_CallFromBuilder __Pyx_PyObject_FastCallDict -#define __Pyx_MakeVectorcallBuilderKwds(n) __Pyx_PyDict_NewPresized(n) -#define __Pyx_VectorcallBuilder_AddArg(key, value, builder, args, n) PyDict_SetItem(builder, key, value) -#define __Pyx_VectorcallBuilder_AddArgStr(key, value, builder, args, n) PyDict_SetItemString(builder, key, value) -#endif - /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyLong_From_uint64_t(uint64_t value); +/* CIntFromPy.proto */ +static CYTHON_INLINE uint64_t __Pyx_PyLong_As_uint64_t(PyObject *); + /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyLong_From_int(int value); /* CIntFromPy.proto */ static CYTHON_INLINE int __Pyx_PyLong_As_int(PyObject *); -/* CIntFromPy.proto */ -static CYTHON_INLINE uint64_t __Pyx_PyLong_As_uint64_t(PyObject *); - /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyLong_From_unsigned_int(unsigned int value); +/* CIntFromPy.proto */ +static CYTHON_INLINE unsigned int __Pyx_PyLong_As_unsigned_int(PyObject *); + /* FormatTypeName.proto */ #if CYTHON_COMPILING_IN_LIMITED_API typedef PyObject *__Pyx_TypeName; @@ -2632,13 +2652,9 @@ static int __Pyx_State_RemoveModule(void*); #define __PYX_TYPE_MODULE_PREFIX __PYX_ABI_MODULE_NAME "." static struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_from_ptr(::Block *__pyx_v_block, struct __pyx_opt_args_18polluck_blockchain_18placeholder_native_7PyBlock_from_ptr *__pyx_optional_args); /* proto*/ -static unsigned char *__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_bytes_serialize_c(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self, size_t *__pyx_v_size); /* proto*/ -static unsigned char *__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_digest(CYTHON_UNUSED struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self, unsigned char *__pyx_v_data, size_t __pyx_v_data_size, size_t *__pyx_v_digest_size); /* proto*/ -static PyObject *__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_mine(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self, unsigned int __pyx_v_difficulty, int __pyx_skip_dispatch, struct __pyx_opt_args_18polluck_blockchain_18placeholder_native_7PyBlock_mine *__pyx_optional_args); /* proto*/ -static unsigned char *__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_perform_hash_c(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self, size_t *__pyx_v_digest_size); /* proto*/ -static PyObject *__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_perform_hash(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/ static ::Block *__pyx_f_18polluck_blockchain_18placeholder_native_10Blockchain_get_block_c(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self, uint64_t __pyx_v_idx); /* proto*/ -static void __pyx_f_18polluck_blockchain_18placeholder_native_10Blockchain_add_block(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self, ::Block *__pyx_v_block); /* proto*/ +static int __pyx_f_18polluck_blockchain_18placeholder_native_10Blockchain_add_block(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self, ::Block *__pyx_v_block); /* proto*/ +static std::string __pyx_f_18polluck_blockchain_18placeholder_native_10Blockchain_hash_data(CYTHON_UNUSED struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self, PyObject *__pyx_v_data); /* proto*/ /* Module declarations from "cython" */ @@ -2667,6 +2683,10 @@ static size_t const __pyx_v_18polluck_blockchain_18placeholder_native_NONCE_OFFS static PyObject *__pyx_f_18polluck_blockchain_18placeholder_native_timestamp_to_datetime(uint64_t); /*proto*/ static int __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint64(unsigned char *, unsigned PY_LONG_LONG); /*proto*/ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_leading_zero_bits(unsigned char const *, int); /*proto*/ +static unsigned char *__pyx_f_18polluck_blockchain_18placeholder_native_bytes_serialize_c(::Block *, size_t *); /*proto*/ +static unsigned char *__pyx_f_18polluck_blockchain_18placeholder_native_SHA256_digest(void const *, size_t, size_t *); /*proto*/ +static unsigned char *__pyx_f_18polluck_blockchain_18placeholder_native_perform_hash_c(::Block *, size_t *); /*proto*/ +static int __pyx_f_18polluck_blockchain_18placeholder_native_mine_block(::Block *, unsigned int, uint64_t *, struct __pyx_opt_args_18polluck_blockchain_18placeholder_native_mine_block *__pyx_optional_args); /*proto*/ static std::string __pyx_convert_string_from_py_6libcpp_6string_std__in_string(PyObject *); /*proto*/ static CYTHON_INLINE PyObject *__pyx_convert_PyObject_string_to_py_6libcpp_6string_std__in_string(std::string const &); /*proto*/ static CYTHON_INLINE PyObject *__pyx_convert_PyUnicode_string_to_py_6libcpp_6string_std__in_string(std::string const &); /*proto*/ @@ -2695,17 +2715,18 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_9pr static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_5nonce___get__(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_4hash___get__(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_10bytes_serialize(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_12mine(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self, unsigned int __pyx_v_difficulty, unsigned int __pyx_v_max_nonce); /* proto */ -static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_14perform_hash(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_16__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_18__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_12perform_hash(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_14__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_16__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain___cinit__(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self); /* proto */ static int __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_2__init__(CYTHON_UNUSED struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */ static void __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_4__dealloc__(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self); /* proto */ static Py_ssize_t __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_6__len__(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_8print_key_value_pair(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_10difficulty___get__(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self); /* proto */ +static int __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_10difficulty_2__set__(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_12genesis_done___get__(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_5index___get__(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_8print_key_value_pair(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_10get_block(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self, PyObject *__pyx_v_idx); /* proto */ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_12create_genesis_block(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_14new_block(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self, PyObject *__pyx_v_data); /* proto */ @@ -2740,10 +2761,10 @@ typedef struct { __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_items; __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_pop; __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_values; - PyObject *__pyx_tuple[2]; - PyObject *__pyx_codeobj_tab[11]; - PyObject *__pyx_string_tab[102]; - PyObject *__pyx_number_tab[5]; + PyObject *__pyx_tuple[1]; + PyObject *__pyx_codeobj_tab[10]; + PyObject *__pyx_string_tab[109]; + PyObject *__pyx_number_tab[4]; /* #### Code section: module_state_contents ### */ /* CommonTypesMetaclass.module_state_decls */ PyTypeObject *__pyx_CommonTypesMetaclassType; @@ -2785,112 +2806,118 @@ static __pyx_mstatetype * const __pyx_mstate_global = &__pyx_mstate_global_stati #endif /* #### Code section: constant_name_defines ### */ #define __pyx_kp_u_Could_not_allocate_hasmap __pyx_string_tab[0] -#define __pyx_kp_u_Create_a_genesis_block_first __pyx_string_tab[1] -#define __pyx_kp_u_Index_value_is_out_of_bounds __pyx_string_tab[2] -#define __pyx_kp_u_No_valid_nonce_found __pyx_string_tab[3] -#define __pyx_kp_u_PyBlock __pyx_string_tab[4] -#define __pyx_kp_u_UTF_8 __pyx_string_tab[5] -#define __pyx_kp_u__2 __pyx_string_tab[6] -#define __pyx_kp_u__3 __pyx_string_tab[7] -#define __pyx_kp_u_disable __pyx_string_tab[8] -#define __pyx_kp_u_enable __pyx_string_tab[9] -#define __pyx_kp_u_gc __pyx_string_tab[10] -#define __pyx_kp_u_isenabled __pyx_string_tab[11] -#define __pyx_kp_u_no_default___reduce___due_to_non __pyx_string_tab[12] -#define __pyx_kp_u_src_polluck_blockchain_placehold __pyx_string_tab[13] -#define __pyx_kp_u_stringsource __pyx_string_tab[14] -#define __pyx_n_u_Blockchain __pyx_string_tab[15] -#define __pyx_n_u_Blockchain___reduce_cython __pyx_string_tab[16] -#define __pyx_n_u_Blockchain___setstate_cython __pyx_string_tab[17] -#define __pyx_n_u_Blockchain_create_genesis_block __pyx_string_tab[18] -#define __pyx_n_u_Blockchain_get_block __pyx_string_tab[19] -#define __pyx_n_u_Blockchain_new_block __pyx_string_tab[20] -#define __pyx_n_u_Blockchain_print_key_value_pair __pyx_string_tab[21] -#define __pyx_n_u_PyBlock_2 __pyx_string_tab[22] -#define __pyx_n_u_PyBlock___reduce_cython __pyx_string_tab[23] -#define __pyx_n_u_PyBlock___setstate_cython __pyx_string_tab[24] -#define __pyx_n_u_PyBlock_bytes_serialize __pyx_string_tab[25] -#define __pyx_n_u_PyBlock_mine __pyx_string_tab[26] -#define __pyx_n_u_PyBlock_perform_hash __pyx_string_tab[27] -#define __pyx_n_u_Pyx_PyDict_NextRef __pyx_string_tab[28] -#define __pyx_n_u_TIMEZONE_UTC __pyx_string_tab[29] -#define __pyx_n_u_asyncio_coroutines __pyx_string_tab[30] -#define __pyx_n_u_block __pyx_string_tab[31] -#define __pyx_n_u_bytes_serialize __pyx_string_tab[32] -#define __pyx_n_u_cline_in_traceback __pyx_string_tab[33] -#define __pyx_n_u_create_genesis_block __pyx_string_tab[34] -#define __pyx_n_u_data __pyx_string_tab[35] -#define __pyx_n_u_datetime __pyx_string_tab[36] -#define __pyx_n_u_difficulty __pyx_string_tab[37] -#define __pyx_n_u_dopt_basics __pyx_string_tab[38] -#define __pyx_n_u_dopt_basics_datetime __pyx_string_tab[39] -#define __pyx_n_u_encode __pyx_string_tab[40] -#define __pyx_n_u_from_ptr __pyx_string_tab[41] -#define __pyx_n_u_fromtimestamp __pyx_string_tab[42] -#define __pyx_n_u_func __pyx_string_tab[43] -#define __pyx_n_u_get_block __pyx_string_tab[44] -#define __pyx_n_u_getstate __pyx_string_tab[45] -#define __pyx_n_u_hash __pyx_string_tab[46] -#define __pyx_n_u_hashlib __pyx_string_tab[47] -#define __pyx_n_u_hex __pyx_string_tab[48] -#define __pyx_n_u_idx __pyx_string_tab[49] -#define __pyx_n_u_index __pyx_string_tab[50] -#define __pyx_n_u_is_coroutine __pyx_string_tab[51] -#define __pyx_n_u_it __pyx_string_tab[52] -#define __pyx_n_u_items __pyx_string_tab[53] -#define __pyx_n_u_main __pyx_string_tab[54] -#define __pyx_n_u_max_nonce __pyx_string_tab[55] -#define __pyx_n_u_mine __pyx_string_tab[56] -#define __pyx_n_u_module __pyx_string_tab[57] -#define __pyx_n_u_name __pyx_string_tab[58] -#define __pyx_n_u_new_block __pyx_string_tab[59] -#define __pyx_n_u_new_idx __pyx_string_tab[60] -#define __pyx_n_u_nonce __pyx_string_tab[61] -#define __pyx_n_u_perform_hash __pyx_string_tab[62] -#define __pyx_n_u_polluck_blockchain_placeholder_n __pyx_string_tab[63] -#define __pyx_n_u_pop __pyx_string_tab[64] -#define __pyx_n_u_prev_block __pyx_string_tab[65] -#define __pyx_n_u_prev_hash __pyx_string_tab[66] -#define __pyx_n_u_previous_hash __pyx_string_tab[67] -#define __pyx_n_u_print __pyx_string_tab[68] -#define __pyx_n_u_print_key_value_pair __pyx_string_tab[69] -#define __pyx_n_u_py_block __pyx_string_tab[70] -#define __pyx_n_u_pyx_state __pyx_string_tab[71] -#define __pyx_n_u_pyx_vtable __pyx_string_tab[72] -#define __pyx_n_u_qualname __pyx_string_tab[73] -#define __pyx_n_u_reduce __pyx_string_tab[74] -#define __pyx_n_u_reduce_cython __pyx_string_tab[75] -#define __pyx_n_u_reduce_ex __pyx_string_tab[76] -#define __pyx_n_u_repr __pyx_string_tab[77] -#define __pyx_n_u_self __pyx_string_tab[78] -#define __pyx_n_u_serialize_res __pyx_string_tab[79] -#define __pyx_n_u_serialize_size __pyx_string_tab[80] -#define __pyx_n_u_set_name __pyx_string_tab[81] -#define __pyx_n_u_setdefault __pyx_string_tab[82] -#define __pyx_n_u_setstate __pyx_string_tab[83] -#define __pyx_n_u_setstate_cython __pyx_string_tab[84] -#define __pyx_n_u_struct __pyx_string_tab[85] -#define __pyx_n_u_test __pyx_string_tab[86] -#define __pyx_n_u_time __pyx_string_tab[87] -#define __pyx_n_u_timestamp __pyx_string_tab[88] -#define __pyx_n_u_values __pyx_string_tab[89] -#define __pyx_kp_b_ __pyx_string_tab[90] -#define __pyx_kp_b_0 __pyx_string_tab[91] -#define __pyx_kp_b_Genesis_Block __pyx_string_tab[92] -#define __pyx_kp_b_dummy_hash __pyx_string_tab[93] -#define __pyx_kp_b_iso88591_A_4r_3d_D_AQ_D_AQ_iq_Q __pyx_string_tab[94] -#define __pyx_kp_b_iso88591_A_4t1_aq_a_HBa_IQ_q_Ct3b_q_gQa_J __pyx_string_tab[95] -#define __pyx_kp_b_iso88591_A_D_2_1A __pyx_string_tab[96] -#define __pyx_kp_b_iso88591_A_IQ_q_Ct3b_7_1_waq_gQa_X_Jaq_Q __pyx_string_tab[97] -#define __pyx_kp_b_iso88591_A_T_a_c_D_t1_c_L_1_iq __pyx_string_tab[98] -#define __pyx_kp_b_iso88591_A_T_wc_xuAV2_b_q_t1 __pyx_string_tab[99] -#define __pyx_kp_b_iso88591_EQ_q_T_1AQ_aq_BnJa_WA_1A_Q_AQ_4 __pyx_string_tab[100] -#define __pyx_kp_b_iso88591_Q __pyx_string_tab[101] +#define __pyx_kp_u_Could_not_mine_block_No_nonce_fo __pyx_string_tab[1] +#define __pyx_kp_u_Create_a_genesis_block_first __pyx_string_tab[2] +#define __pyx_kp_u_Data_must_be_a_string __pyx_string_tab[3] +#define __pyx_kp_u_Difficulty_must_be_greater_than __pyx_string_tab[4] +#define __pyx_kp_u_Difficulty_must_be_integer_value __pyx_string_tab[5] +#define __pyx_kp_u_Failed_to_hash_data __pyx_string_tab[6] +#define __pyx_kp_u_Genesis_Block __pyx_string_tab[7] +#define __pyx_kp_u_Index_value_is_out_of_bounds __pyx_string_tab[8] +#define __pyx_kp_u_Provided_index_not_found __pyx_string_tab[9] +#define __pyx_kp_u_PyBlock __pyx_string_tab[10] +#define __pyx_kp_u_UTF_8 __pyx_string_tab[11] +#define __pyx_kp_u__2 __pyx_string_tab[12] +#define __pyx_kp_u__3 __pyx_string_tab[13] +#define __pyx_kp_u_disable __pyx_string_tab[14] +#define __pyx_kp_u_enable __pyx_string_tab[15] +#define __pyx_kp_u_gc __pyx_string_tab[16] +#define __pyx_kp_u_isenabled __pyx_string_tab[17] +#define __pyx_kp_u_no_default___reduce___due_to_non __pyx_string_tab[18] +#define __pyx_kp_u_src_polluck_blockchain_placehold __pyx_string_tab[19] +#define __pyx_kp_u_stringsource __pyx_string_tab[20] +#define __pyx_n_u_Blockchain __pyx_string_tab[21] +#define __pyx_n_u_Blockchain___reduce_cython __pyx_string_tab[22] +#define __pyx_n_u_Blockchain___setstate_cython __pyx_string_tab[23] +#define __pyx_n_u_Blockchain_create_genesis_block __pyx_string_tab[24] +#define __pyx_n_u_Blockchain_get_block __pyx_string_tab[25] +#define __pyx_n_u_Blockchain_new_block __pyx_string_tab[26] +#define __pyx_n_u_Blockchain_print_key_value_pair __pyx_string_tab[27] +#define __pyx_n_u_PyBlock_2 __pyx_string_tab[28] +#define __pyx_n_u_PyBlock___reduce_cython __pyx_string_tab[29] +#define __pyx_n_u_PyBlock___setstate_cython __pyx_string_tab[30] +#define __pyx_n_u_PyBlock_bytes_serialize __pyx_string_tab[31] +#define __pyx_n_u_PyBlock_perform_hash __pyx_string_tab[32] +#define __pyx_n_u_Pyx_PyDict_NextRef __pyx_string_tab[33] +#define __pyx_n_u_TIMEZONE_UTC __pyx_string_tab[34] +#define __pyx_n_u_asyncio_coroutines __pyx_string_tab[35] +#define __pyx_n_u_block __pyx_string_tab[36] +#define __pyx_n_u_bytes_serialize __pyx_string_tab[37] +#define __pyx_n_u_cline_in_traceback __pyx_string_tab[38] +#define __pyx_n_u_create_genesis_block __pyx_string_tab[39] +#define __pyx_n_u_current_time_tz __pyx_string_tab[40] +#define __pyx_n_u_cut_microseconds __pyx_string_tab[41] +#define __pyx_n_u_data __pyx_string_tab[42] +#define __pyx_n_u_data_digest __pyx_string_tab[43] +#define __pyx_n_u_data_str __pyx_string_tab[44] +#define __pyx_n_u_datetime __pyx_string_tab[45] +#define __pyx_n_u_digest __pyx_string_tab[46] +#define __pyx_n_u_digest_size __pyx_string_tab[47] +#define __pyx_n_u_dopt_basics __pyx_string_tab[48] +#define __pyx_n_u_dopt_basics_datetime __pyx_string_tab[49] +#define __pyx_n_u_encode __pyx_string_tab[50] +#define __pyx_n_u_from_ptr __pyx_string_tab[51] +#define __pyx_n_u_fromtimestamp __pyx_string_tab[52] +#define __pyx_n_u_func __pyx_string_tab[53] +#define __pyx_n_u_genesis_prev_hash __pyx_string_tab[54] +#define __pyx_n_u_get_block __pyx_string_tab[55] +#define __pyx_n_u_getstate __pyx_string_tab[56] +#define __pyx_n_u_hash __pyx_string_tab[57] +#define __pyx_n_u_hashlib __pyx_string_tab[58] +#define __pyx_n_u_hex __pyx_string_tab[59] +#define __pyx_n_u_idx __pyx_string_tab[60] +#define __pyx_n_u_index __pyx_string_tab[61] +#define __pyx_n_u_is_coroutine __pyx_string_tab[62] +#define __pyx_n_u_it __pyx_string_tab[63] +#define __pyx_n_u_items __pyx_string_tab[64] +#define __pyx_n_u_main __pyx_string_tab[65] +#define __pyx_n_u_module __pyx_string_tab[66] +#define __pyx_n_u_name __pyx_string_tab[67] +#define __pyx_n_u_new_block __pyx_string_tab[68] +#define __pyx_n_u_new_idx __pyx_string_tab[69] +#define __pyx_n_u_nonce __pyx_string_tab[70] +#define __pyx_n_u_perform_hash __pyx_string_tab[71] +#define __pyx_n_u_polluck_blockchain_placeholder_n __pyx_string_tab[72] +#define __pyx_n_u_pop __pyx_string_tab[73] +#define __pyx_n_u_prev_block __pyx_string_tab[74] +#define __pyx_n_u_prev_hash __pyx_string_tab[75] +#define __pyx_n_u_previous_hash __pyx_string_tab[76] +#define __pyx_n_u_print __pyx_string_tab[77] +#define __pyx_n_u_print_key_value_pair __pyx_string_tab[78] +#define __pyx_n_u_py_block __pyx_string_tab[79] +#define __pyx_n_u_pyx_state __pyx_string_tab[80] +#define __pyx_n_u_pyx_vtable __pyx_string_tab[81] +#define __pyx_n_u_qualname __pyx_string_tab[82] +#define __pyx_n_u_reduce __pyx_string_tab[83] +#define __pyx_n_u_reduce_cython __pyx_string_tab[84] +#define __pyx_n_u_reduce_ex __pyx_string_tab[85] +#define __pyx_n_u_repr __pyx_string_tab[86] +#define __pyx_n_u_res __pyx_string_tab[87] +#define __pyx_n_u_self __pyx_string_tab[88] +#define __pyx_n_u_serialize_res __pyx_string_tab[89] +#define __pyx_n_u_serialize_size __pyx_string_tab[90] +#define __pyx_n_u_set_name __pyx_string_tab[91] +#define __pyx_n_u_setdefault __pyx_string_tab[92] +#define __pyx_n_u_setstate __pyx_string_tab[93] +#define __pyx_n_u_setstate_cython __pyx_string_tab[94] +#define __pyx_n_u_struct __pyx_string_tab[95] +#define __pyx_n_u_test __pyx_string_tab[96] +#define __pyx_n_u_time __pyx_string_tab[97] +#define __pyx_n_u_timestamp __pyx_string_tab[98] +#define __pyx_n_u_values __pyx_string_tab[99] +#define __pyx_kp_b_ __pyx_string_tab[100] +#define __pyx_kp_b_00000000000000000000000000000000 __pyx_string_tab[101] +#define __pyx_kp_b_iso88591_A_1D_wc_xuAV2_b_q_t1 __pyx_string_tab[102] +#define __pyx_kp_b_iso88591_A_4r_3d_D_AQ_D_AQ_6_A_AQ_iq_Q __pyx_string_tab[103] +#define __pyx_kp_b_iso88591_A_4t1_aq_4z_1A_4z_T_Qd_Ja_hb_IQ __pyx_string_tab[104] +#define __pyx_kp_b_iso88591_A_Qd_1A __pyx_string_tab[105] +#define __pyx_kp_b_iso88591_A_T_a_c_D_t1_c_L_1_iq __pyx_string_tab[106] +#define __pyx_kp_b_iso88591_A_YgQa_t_Qa_IQ_q_Ct3b_gQa_t_Qa_4 __pyx_string_tab[107] +#define __pyx_kp_b_iso88591_Q __pyx_string_tab[108] #define __pyx_int_0 __pyx_number_tab[0] #define __pyx_int_1 __pyx_number_tab[1] #define __pyx_int_12 __pyx_number_tab[2] #define __pyx_int_2025 __pyx_number_tab[3] -#define __pyx_int_4294967295 __pyx_number_tab[4] /* #### Code section: module_state_clear ### */ #if CYTHON_USE_MODULE_STATE static CYTHON_SMALL_CODE int __pyx_m_clear(PyObject *m) { @@ -2909,10 +2936,10 @@ static CYTHON_SMALL_CODE int __pyx_m_clear(PyObject *m) { Py_CLEAR(clear_module_state->__pyx_type_18polluck_blockchain_18placeholder_native_PyBlock); Py_CLEAR(clear_module_state->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain); Py_CLEAR(clear_module_state->__pyx_type_18polluck_blockchain_18placeholder_native_Blockchain); - for (int i=0; i<2; ++i) { Py_CLEAR(clear_module_state->__pyx_tuple[i]); } - for (int i=0; i<11; ++i) { Py_CLEAR(clear_module_state->__pyx_codeobj_tab[i]); } - for (int i=0; i<102; ++i) { Py_CLEAR(clear_module_state->__pyx_string_tab[i]); } - for (int i=0; i<5; ++i) { Py_CLEAR(clear_module_state->__pyx_number_tab[i]); } + for (int i=0; i<1; ++i) { Py_CLEAR(clear_module_state->__pyx_tuple[i]); } + for (int i=0; i<10; ++i) { Py_CLEAR(clear_module_state->__pyx_codeobj_tab[i]); } + for (int i=0; i<109; ++i) { Py_CLEAR(clear_module_state->__pyx_string_tab[i]); } + for (int i=0; i<4; ++i) { Py_CLEAR(clear_module_state->__pyx_number_tab[i]); } /* #### Code section: module_state_clear_contents ### */ /* CommonTypesMetaclass.module_state_clear */ Py_CLEAR(clear_module_state->__pyx_CommonTypesMetaclassType); @@ -2939,10 +2966,10 @@ static CYTHON_SMALL_CODE int __pyx_m_traverse(PyObject *m, visitproc visit, void Py_VISIT(traverse_module_state->__pyx_type_18polluck_blockchain_18placeholder_native_PyBlock); Py_VISIT(traverse_module_state->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain); Py_VISIT(traverse_module_state->__pyx_type_18polluck_blockchain_18placeholder_native_Blockchain); - for (int i=0; i<2; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_tuple[i]); } - for (int i=0; i<11; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_codeobj_tab[i]); } - for (int i=0; i<102; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_string_tab[i]); } - for (int i=0; i<5; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_number_tab[i]); } + for (int i=0; i<1; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_tuple[i]); } + for (int i=0; i<10; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_codeobj_tab[i]); } + for (int i=0; i<109; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_string_tab[i]); } + for (int i=0; i<4; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_number_tab[i]); } /* #### Code section: module_state_traverse_contents ### */ /* CommonTypesMetaclass.module_state_traverse */ Py_VISIT(traverse_module_state->__pyx_CommonTypesMetaclassType); @@ -3337,8 +3364,8 @@ static CYTHON_INLINE PyObject *__pyx_convert_PyByteArray_string_to_py_6libcpp_6s return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":30 - * ctypedef unordered_map[uint64_t, Block*] BcHashmap +/* "polluck_blockchain/placeholder_native.pyx":31 + * cdef const size_t NONCE_OFFSET = 16 * * cdef timestamp_to_datetime(uint64_t ts): # <<<<<<<<<<<<<< * return datetime.datetime.fromtimestamp(float(ts), dopt_basics.datetime.TIMEZONE_UTC) @@ -3360,29 +3387,29 @@ static PyObject *__pyx_f_18polluck_blockchain_18placeholder_native_timestamp_to_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("timestamp_to_datetime", 0); - /* "polluck_blockchain/placeholder_native.pyx":31 + /* "polluck_blockchain/placeholder_native.pyx":32 * * cdef timestamp_to_datetime(uint64_t ts): * return datetime.datetime.fromtimestamp(float(ts), dopt_basics.datetime.TIMEZONE_UTC) # <<<<<<<<<<<<<< * - * + * cdef uint64_t current_timestamp_integer(): */ __Pyx_XDECREF(__pyx_r); - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 31, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 31, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_2 = __pyx_t_4; __Pyx_INCREF(__pyx_t_2); - __pyx_t_3 = PyFloat_FromDouble(((double)__pyx_v_ts)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 31, __pyx_L1_error) + __pyx_t_3 = PyFloat_FromDouble(((double)__pyx_v_ts)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_dopt_basics); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 31, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_dopt_basics); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 31, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_TIMEZONE_UTC); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 31, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_TIMEZONE_UTC); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_7 = 0; @@ -3393,15 +3420,15 @@ static PyObject *__pyx_f_18polluck_blockchain_18placeholder_native_timestamp_to_ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 31, __pyx_L1_error) + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":30 - * ctypedef unordered_map[uint64_t, Block*] BcHashmap + /* "polluck_blockchain/placeholder_native.pyx":31 + * cdef const size_t NONCE_OFFSET = 16 * * cdef timestamp_to_datetime(uint64_t ts): # <<<<<<<<<<<<<< * return datetime.datetime.fromtimestamp(float(ts), dopt_basics.datetime.TIMEZONE_UTC) @@ -3424,7 +3451,117 @@ static PyObject *__pyx_f_18polluck_blockchain_18placeholder_native_timestamp_to_ return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":37 +/* "polluck_blockchain/placeholder_native.pyx":34 + * return datetime.datetime.fromtimestamp(float(ts), dopt_basics.datetime.TIMEZONE_UTC) + * + * cdef uint64_t current_timestamp_integer(): # <<<<<<<<<<<<<< + * cdef uint64_t ts + * dt = dopt_basics.datetime.current_time_tz(cut_microseconds=True) +*/ + +static uint64_t __pyx_f_18polluck_blockchain_18placeholder_native_current_timestamp_integer(void) { + uint64_t __pyx_v_ts; + PyObject *__pyx_v_dt = NULL; + uint64_t __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + size_t __pyx_t_5; + uint64_t __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("current_timestamp_integer", 0); + + /* "polluck_blockchain/placeholder_native.pyx":36 + * cdef uint64_t current_timestamp_integer(): + * cdef uint64_t ts + * dt = dopt_basics.datetime.current_time_tz(cut_microseconds=True) # <<<<<<<<<<<<<< + * ts = int(dt.timestamp()) + * return ts +*/ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_dopt_basics); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 36, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 36, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_2 = __pyx_t_4; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_5 = 0; + { + PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_2, NULL}; + __pyx_t_3 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 36, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_cut_microseconds, Py_True, __pyx_t_3, __pyx_callargs+1, 0) < (0)) __PYX_ERR(0, 36, __pyx_L1_error) + __pyx_t_1 = __Pyx_Object_VectorcallMethod_CallFromBuilder((PyObject*)__pyx_mstate_global->__pyx_n_u_current_time_tz, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_3); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 36, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } + __pyx_v_dt = __pyx_t_1; + __pyx_t_1 = 0; + + /* "polluck_blockchain/placeholder_native.pyx":37 + * cdef uint64_t ts + * dt = dopt_basics.datetime.current_time_tz(cut_microseconds=True) + * ts = int(dt.timestamp()) # <<<<<<<<<<<<<< + * return ts + * +*/ + __pyx_t_4 = __pyx_v_dt; + __Pyx_INCREF(__pyx_t_4); + __pyx_t_5 = 0; + { + PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL}; + __pyx_t_1 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_timestamp, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 37, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } + __pyx_t_4 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 37, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_6 = __Pyx_PyLong_As_uint64_t(__pyx_t_4); if (unlikely((__pyx_t_6 == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 37, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_ts = ((uint64_t)__pyx_t_6); + + /* "polluck_blockchain/placeholder_native.pyx":38 + * dt = dopt_basics.datetime.current_time_tz(cut_microseconds=True) + * ts = int(dt.timestamp()) + * return ts # <<<<<<<<<<<<<< + * + * # cdef float_to_bytes(double num): +*/ + __pyx_r = __pyx_v_ts; + goto __pyx_L0; + + /* "polluck_blockchain/placeholder_native.pyx":34 + * return datetime.datetime.fromtimestamp(float(ts), dopt_basics.datetime.TIMEZONE_UTC) + * + * cdef uint64_t current_timestamp_integer(): # <<<<<<<<<<<<<< + * cdef uint64_t ts + * dt = dopt_basics.datetime.current_time_tz(cut_microseconds=True) +*/ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("polluck_blockchain.placeholder_native.current_timestamp_integer", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1LL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_dt); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "polluck_blockchain/placeholder_native.pyx":43 * # return struct.pack(">d", num) * * cdef int serialize_uint32(unsigned char* out, unsigned int v) except -1 nogil: # <<<<<<<<<<<<<< @@ -3435,7 +3572,7 @@ static PyObject *__pyx_f_18polluck_blockchain_18placeholder_native_timestamp_to_ static int __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint32(unsigned char *__pyx_v_out, unsigned int __pyx_v_v) { int __pyx_r; - /* "polluck_blockchain/placeholder_native.pyx":38 + /* "polluck_blockchain/placeholder_native.pyx":44 * * cdef int serialize_uint32(unsigned char* out, unsigned int v) except -1 nogil: * out[0] = (v >> 24) & 0xFF # <<<<<<<<<<<<<< @@ -3444,7 +3581,7 @@ static int __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint32(un */ (__pyx_v_out[0]) = ((__pyx_v_v >> 24) & 0xFF); - /* "polluck_blockchain/placeholder_native.pyx":39 + /* "polluck_blockchain/placeholder_native.pyx":45 * cdef int serialize_uint32(unsigned char* out, unsigned int v) except -1 nogil: * out[0] = (v >> 24) & 0xFF * out[1] = (v >> 16) & 0xFF # <<<<<<<<<<<<<< @@ -3453,7 +3590,7 @@ static int __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint32(un */ (__pyx_v_out[1]) = ((__pyx_v_v >> 16) & 0xFF); - /* "polluck_blockchain/placeholder_native.pyx":40 + /* "polluck_blockchain/placeholder_native.pyx":46 * out[0] = (v >> 24) & 0xFF * out[1] = (v >> 16) & 0xFF * out[2] = (v >> 8) & 0xFF # <<<<<<<<<<<<<< @@ -3462,7 +3599,7 @@ static int __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint32(un */ (__pyx_v_out[2]) = ((__pyx_v_v >> 8) & 0xFF); - /* "polluck_blockchain/placeholder_native.pyx":41 + /* "polluck_blockchain/placeholder_native.pyx":47 * out[1] = (v >> 16) & 0xFF * out[2] = (v >> 8) & 0xFF * out[3] = v & 0xFF # <<<<<<<<<<<<<< @@ -3471,7 +3608,7 @@ static int __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint32(un */ (__pyx_v_out[3]) = (__pyx_v_v & 0xFF); - /* "polluck_blockchain/placeholder_native.pyx":37 + /* "polluck_blockchain/placeholder_native.pyx":43 * # return struct.pack(">d", num) * * cdef int serialize_uint32(unsigned char* out, unsigned int v) except -1 nogil: # <<<<<<<<<<<<<< @@ -3484,7 +3621,7 @@ static int __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint32(un return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":43 +/* "polluck_blockchain/placeholder_native.pyx":49 * out[3] = v & 0xFF * * cdef int serialize_uint64(unsigned char* out, unsigned long long v) except -1 nogil: # <<<<<<<<<<<<<< @@ -3495,7 +3632,7 @@ static int __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint32(un static int __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint64(unsigned char *__pyx_v_out, unsigned PY_LONG_LONG __pyx_v_v) { int __pyx_r; - /* "polluck_blockchain/placeholder_native.pyx":44 + /* "polluck_blockchain/placeholder_native.pyx":50 * * cdef int serialize_uint64(unsigned char* out, unsigned long long v) except -1 nogil: * out[0] = (v >> 56) & 0xFF # <<<<<<<<<<<<<< @@ -3504,7 +3641,7 @@ static int __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint64(un */ (__pyx_v_out[0]) = ((__pyx_v_v >> 56) & 0xFF); - /* "polluck_blockchain/placeholder_native.pyx":45 + /* "polluck_blockchain/placeholder_native.pyx":51 * cdef int serialize_uint64(unsigned char* out, unsigned long long v) except -1 nogil: * out[0] = (v >> 56) & 0xFF * out[1] = (v >> 48) & 0xFF # <<<<<<<<<<<<<< @@ -3513,7 +3650,7 @@ static int __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint64(un */ (__pyx_v_out[1]) = ((__pyx_v_v >> 48) & 0xFF); - /* "polluck_blockchain/placeholder_native.pyx":46 + /* "polluck_blockchain/placeholder_native.pyx":52 * out[0] = (v >> 56) & 0xFF * out[1] = (v >> 48) & 0xFF * out[2] = (v >> 40) & 0xFF # <<<<<<<<<<<<<< @@ -3522,7 +3659,7 @@ static int __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint64(un */ (__pyx_v_out[2]) = ((__pyx_v_v >> 40) & 0xFF); - /* "polluck_blockchain/placeholder_native.pyx":47 + /* "polluck_blockchain/placeholder_native.pyx":53 * out[1] = (v >> 48) & 0xFF * out[2] = (v >> 40) & 0xFF * out[3] = (v >> 32) & 0xFF # <<<<<<<<<<<<<< @@ -3531,7 +3668,7 @@ static int __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint64(un */ (__pyx_v_out[3]) = ((__pyx_v_v >> 32) & 0xFF); - /* "polluck_blockchain/placeholder_native.pyx":48 + /* "polluck_blockchain/placeholder_native.pyx":54 * out[2] = (v >> 40) & 0xFF * out[3] = (v >> 32) & 0xFF * out[4] = (v >> 24) & 0xFF # <<<<<<<<<<<<<< @@ -3540,7 +3677,7 @@ static int __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint64(un */ (__pyx_v_out[4]) = ((__pyx_v_v >> 24) & 0xFF); - /* "polluck_blockchain/placeholder_native.pyx":49 + /* "polluck_blockchain/placeholder_native.pyx":55 * out[3] = (v >> 32) & 0xFF * out[4] = (v >> 24) & 0xFF * out[5] = (v >> 16) & 0xFF # <<<<<<<<<<<<<< @@ -3549,7 +3686,7 @@ static int __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint64(un */ (__pyx_v_out[5]) = ((__pyx_v_v >> 16) & 0xFF); - /* "polluck_blockchain/placeholder_native.pyx":50 + /* "polluck_blockchain/placeholder_native.pyx":56 * out[4] = (v >> 24) & 0xFF * out[5] = (v >> 16) & 0xFF * out[6] = (v >> 8) & 0xFF # <<<<<<<<<<<<<< @@ -3558,16 +3695,16 @@ static int __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint64(un */ (__pyx_v_out[6]) = ((__pyx_v_v >> 8) & 0xFF); - /* "polluck_blockchain/placeholder_native.pyx":51 + /* "polluck_blockchain/placeholder_native.pyx":57 * out[5] = (v >> 16) & 0xFF * out[6] = (v >> 8) & 0xFF * out[7] = v & 0xFF # <<<<<<<<<<<<<< * - * # cdef struct SerializeResult: + * */ (__pyx_v_out[7]) = (__pyx_v_v & 0xFF); - /* "polluck_blockchain/placeholder_native.pyx":43 + /* "polluck_blockchain/placeholder_native.pyx":49 * out[3] = v & 0xFF * * cdef int serialize_uint64(unsigned char* out, unsigned long long v) except -1 nogil: # <<<<<<<<<<<<<< @@ -3580,8 +3717,8 @@ static int __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint64(un return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":63 - * cdef const size_t NONCE_OFFSET = 16 +/* "polluck_blockchain/placeholder_native.pyx":60 + * * * cdef inline bint has_leading_zero_bits(const unsigned char *digest, int num_bits) nogil: # <<<<<<<<<<<<<< * cdef int i, full_bytes = num_bits // 8 @@ -3598,7 +3735,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l int __pyx_t_3; int __pyx_t_4; - /* "polluck_blockchain/placeholder_native.pyx":64 + /* "polluck_blockchain/placeholder_native.pyx":61 * * cdef inline bint has_leading_zero_bits(const unsigned char *digest, int num_bits) nogil: * cdef int i, full_bytes = num_bits // 8 # <<<<<<<<<<<<<< @@ -3607,7 +3744,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l */ __pyx_v_full_bytes = __Pyx_div_long(__pyx_v_num_bits, 8, 1); - /* "polluck_blockchain/placeholder_native.pyx":65 + /* "polluck_blockchain/placeholder_native.pyx":62 * cdef inline bint has_leading_zero_bits(const unsigned char *digest, int num_bits) nogil: * cdef int i, full_bytes = num_bits // 8 * cdef int rem_bits = num_bits % 8 # <<<<<<<<<<<<<< @@ -3616,7 +3753,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l */ __pyx_v_rem_bits = __Pyx_mod_long(__pyx_v_num_bits, 8, 1); - /* "polluck_blockchain/placeholder_native.pyx":67 + /* "polluck_blockchain/placeholder_native.pyx":64 * cdef int rem_bits = num_bits % 8 * * for i in range(full_bytes): # <<<<<<<<<<<<<< @@ -3628,7 +3765,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v_i = __pyx_t_3; - /* "polluck_blockchain/placeholder_native.pyx":68 + /* "polluck_blockchain/placeholder_native.pyx":65 * * for i in range(full_bytes): * if digest[i] != 0: # <<<<<<<<<<<<<< @@ -3638,7 +3775,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l __pyx_t_4 = ((__pyx_v_digest[__pyx_v_i]) != 0); if (__pyx_t_4) { - /* "polluck_blockchain/placeholder_native.pyx":69 + /* "polluck_blockchain/placeholder_native.pyx":66 * for i in range(full_bytes): * if digest[i] != 0: * return False # <<<<<<<<<<<<<< @@ -3648,7 +3785,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l __pyx_r = 0; goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":68 + /* "polluck_blockchain/placeholder_native.pyx":65 * * for i in range(full_bytes): * if digest[i] != 0: # <<<<<<<<<<<<<< @@ -3658,7 +3795,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l } } - /* "polluck_blockchain/placeholder_native.pyx":71 + /* "polluck_blockchain/placeholder_native.pyx":68 * return False * * if rem_bits: # <<<<<<<<<<<<<< @@ -3668,7 +3805,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l __pyx_t_4 = (__pyx_v_rem_bits != 0); if (__pyx_t_4) { - /* "polluck_blockchain/placeholder_native.pyx":72 + /* "polluck_blockchain/placeholder_native.pyx":69 * * if rem_bits: * if digest[full_bytes] >> (8 - rem_bits) != 0: # <<<<<<<<<<<<<< @@ -3678,7 +3815,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l __pyx_t_4 = (((__pyx_v_digest[__pyx_v_full_bytes]) >> (8 - __pyx_v_rem_bits)) != 0); if (__pyx_t_4) { - /* "polluck_blockchain/placeholder_native.pyx":73 + /* "polluck_blockchain/placeholder_native.pyx":70 * if rem_bits: * if digest[full_bytes] >> (8 - rem_bits) != 0: * return False # <<<<<<<<<<<<<< @@ -3688,7 +3825,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l __pyx_r = 0; goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":72 + /* "polluck_blockchain/placeholder_native.pyx":69 * * if rem_bits: * if digest[full_bytes] >> (8 - rem_bits) != 0: # <<<<<<<<<<<<<< @@ -3697,7 +3834,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l */ } - /* "polluck_blockchain/placeholder_native.pyx":71 + /* "polluck_blockchain/placeholder_native.pyx":68 * return False * * if rem_bits: # <<<<<<<<<<<<<< @@ -3706,7 +3843,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l */ } - /* "polluck_blockchain/placeholder_native.pyx":75 + /* "polluck_blockchain/placeholder_native.pyx":72 * return False * * return True # <<<<<<<<<<<<<< @@ -3716,8 +3853,8 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l __pyx_r = 1; goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":63 - * cdef const size_t NONCE_OFFSET = 16 + /* "polluck_blockchain/placeholder_native.pyx":60 + * * * cdef inline bint has_leading_zero_bits(const unsigned char *digest, int num_bits) nogil: # <<<<<<<<<<<<<< * cdef int i, full_bytes = num_bits // 8 @@ -3729,7 +3866,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":77 +/* "polluck_blockchain/placeholder_native.pyx":74 * return True * * cdef inline bint has_leading_zero_bytes(const unsigned char *digest, int num_bytes) nogil: # <<<<<<<<<<<<<< @@ -3747,7 +3884,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l int __pyx_t_3; int __pyx_t_4; - /* "polluck_blockchain/placeholder_native.pyx":78 + /* "polluck_blockchain/placeholder_native.pyx":75 * * cdef inline bint has_leading_zero_bytes(const unsigned char *digest, int num_bytes) nogil: * cdef int i, full_bytes = num_bytes // 8 # <<<<<<<<<<<<<< @@ -3756,7 +3893,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l */ __pyx_v_full_bytes = __Pyx_div_long(__pyx_v_num_bytes, 8, 1); - /* "polluck_blockchain/placeholder_native.pyx":79 + /* "polluck_blockchain/placeholder_native.pyx":76 * cdef inline bint has_leading_zero_bytes(const unsigned char *digest, int num_bytes) nogil: * cdef int i, full_bytes = num_bytes // 8 * cdef int rem_bits = num_bytes % 8 # <<<<<<<<<<<<<< @@ -3765,7 +3902,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l */ __pyx_v_rem_bits = __Pyx_mod_long(__pyx_v_num_bytes, 8, 1); - /* "polluck_blockchain/placeholder_native.pyx":81 + /* "polluck_blockchain/placeholder_native.pyx":78 * cdef int rem_bits = num_bytes % 8 * * for i in range(num_bytes): # <<<<<<<<<<<<<< @@ -3777,7 +3914,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v_i = __pyx_t_3; - /* "polluck_blockchain/placeholder_native.pyx":82 + /* "polluck_blockchain/placeholder_native.pyx":79 * * for i in range(num_bytes): * if digest[i] != 0: # <<<<<<<<<<<<<< @@ -3787,7 +3924,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l __pyx_t_4 = ((__pyx_v_digest[__pyx_v_i]) != 0); if (__pyx_t_4) { - /* "polluck_blockchain/placeholder_native.pyx":83 + /* "polluck_blockchain/placeholder_native.pyx":80 * for i in range(num_bytes): * if digest[i] != 0: * return False # <<<<<<<<<<<<<< @@ -3797,7 +3934,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l __pyx_r = 0; goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":82 + /* "polluck_blockchain/placeholder_native.pyx":79 * * for i in range(num_bytes): * if digest[i] != 0: # <<<<<<<<<<<<<< @@ -3807,7 +3944,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l } } - /* "polluck_blockchain/placeholder_native.pyx":85 + /* "polluck_blockchain/placeholder_native.pyx":82 * return False * * return True # <<<<<<<<<<<<<< @@ -3817,7 +3954,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l __pyx_r = 1; goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":77 + /* "polluck_blockchain/placeholder_native.pyx":74 * return True * * cdef inline bint has_leading_zero_bytes(const unsigned char *digest, int num_bytes) nogil: # <<<<<<<<<<<<<< @@ -3830,7 +3967,7 @@ static CYTHON_INLINE int __pyx_f_18polluck_blockchain_18placeholder_native_has_l return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":93 +/* "polluck_blockchain/placeholder_native.pyx":90 * bint ptr_owner * * def __cinit__(self, # <<<<<<<<<<<<<< @@ -3864,36 +4001,36 @@ static int __pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_1__cinit_ { PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_index,&__pyx_mstate_global->__pyx_n_u_nonce,&__pyx_mstate_global->__pyx_n_u_data,&__pyx_mstate_global->__pyx_n_u_previous_hash,&__pyx_mstate_global->__pyx_n_u_from_ptr,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_VARARGS(__pyx_kwds) : 0; - if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 93, __pyx_L3_error) + if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 90, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 5: values[4] = __Pyx_ArgRef_VARARGS(__pyx_args, 4); - if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 93, __pyx_L3_error) + if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 90, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_VARARGS(__pyx_args, 3); - if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 93, __pyx_L3_error) + if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 90, __pyx_L3_error) CYTHON_FALLTHROUGH; case 3: values[2] = __Pyx_ArgRef_VARARGS(__pyx_args, 2); - if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 93, __pyx_L3_error) + if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 90, __pyx_L3_error) CYTHON_FALLTHROUGH; case 2: values[1] = __Pyx_ArgRef_VARARGS(__pyx_args, 1); - if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 93, __pyx_L3_error) + if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 90, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_VARARGS(__pyx_args, 0); - if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 93, __pyx_L3_error) + if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 90, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; - if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "__cinit__", 0) < (0)) __PYX_ERR(0, 93, __pyx_L3_error) + if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "__cinit__", 0) < (0)) __PYX_ERR(0, 90, __pyx_L3_error) - /* "polluck_blockchain/placeholder_native.pyx":98 + /* "polluck_blockchain/placeholder_native.pyx":95 * data, * previous_hash, * from_ptr=False, # <<<<<<<<<<<<<< @@ -3902,23 +4039,23 @@ static int __pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_1__cinit_ */ if (!values[4]) values[4] = __Pyx_NewRef(((PyObject *)Py_False)); for (Py_ssize_t i = __pyx_nargs; i < 4; i++) { - if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, i); __PYX_ERR(0, 93, __pyx_L3_error) } + if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, i); __PYX_ERR(0, 90, __pyx_L3_error) } } } else { switch (__pyx_nargs) { case 5: values[4] = __Pyx_ArgRef_VARARGS(__pyx_args, 4); - if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 93, __pyx_L3_error) + if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[4])) __PYX_ERR(0, 90, __pyx_L3_error) CYTHON_FALLTHROUGH; case 4: values[3] = __Pyx_ArgRef_VARARGS(__pyx_args, 3); - if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 93, __pyx_L3_error) + if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 90, __pyx_L3_error) values[2] = __Pyx_ArgRef_VARARGS(__pyx_args, 2); - if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 93, __pyx_L3_error) + if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 90, __pyx_L3_error) values[1] = __Pyx_ArgRef_VARARGS(__pyx_args, 1); - if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 93, __pyx_L3_error) + if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 90, __pyx_L3_error) values[0] = __Pyx_ArgRef_VARARGS(__pyx_args, 0); - if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 93, __pyx_L3_error) + if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 90, __pyx_L3_error) break; default: goto __pyx_L5_argtuple_error; } @@ -3932,7 +4069,7 @@ static int __pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_1__cinit_ } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, __pyx_nargs); __PYX_ERR(0, 93, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, __pyx_nargs); __PYX_ERR(0, 90, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -3945,7 +4082,7 @@ static int __pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_1__cinit_ __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock___cinit__(((struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *)__pyx_v_self), __pyx_v_index, __pyx_v_nonce, __pyx_v_data, __pyx_v_previous_hash, __pyx_v_from_ptr); - /* "polluck_blockchain/placeholder_native.pyx":93 + /* "polluck_blockchain/placeholder_native.pyx":90 * bint ptr_owner * * def __cinit__(self, # <<<<<<<<<<<<<< @@ -3983,7 +4120,7 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock___cinit__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); - /* "polluck_blockchain/placeholder_native.pyx":100 + /* "polluck_blockchain/placeholder_native.pyx":97 * from_ptr=False, * ): * self.ptr_owner = False # <<<<<<<<<<<<<< @@ -3992,39 +4129,39 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock___cinit__ */ __pyx_v_self->ptr_owner = 0; - /* "polluck_blockchain/placeholder_native.pyx":101 + /* "polluck_blockchain/placeholder_native.pyx":98 * ): * self.ptr_owner = False * if not from_ptr: # <<<<<<<<<<<<<< * self.BlockC = new Block( * index, */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_from_ptr); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 101, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_from_ptr); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 98, __pyx_L1_error) __pyx_t_2 = (!__pyx_t_1); if (__pyx_t_2) { - /* "polluck_blockchain/placeholder_native.pyx":103 + /* "polluck_blockchain/placeholder_native.pyx":100 * if not from_ptr: * self.BlockC = new Block( * index, # <<<<<<<<<<<<<< * int(datetime.datetime(2025, 12, 1, 12, 0, 0).timestamp()), * nonce, */ - __pyx_t_3 = __Pyx_PyLong_As_uint64_t(__pyx_v_index); if (unlikely((__pyx_t_3 == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 103, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyLong_As_uint64_t(__pyx_v_index); if (unlikely((__pyx_t_3 == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 100, __pyx_L1_error) - /* "polluck_blockchain/placeholder_native.pyx":104 + /* "polluck_blockchain/placeholder_native.pyx":101 * self.BlockC = new Block( * index, * int(datetime.datetime(2025, 12, 1, 12, 0, 0).timestamp()), # <<<<<<<<<<<<<< * nonce, * data.encode("UTF-8"), */ - __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 104, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 101, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 104, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 101, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_mstate_global->__pyx_tuple[0], NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 104, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_mstate_global->__pyx_tuple[0], NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 101, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_5 = __pyx_t_6; @@ -4035,25 +4172,25 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock___cinit__ __pyx_t_4 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_timestamp, __pyx_callargs+__pyx_t_8, (1-__pyx_t_8) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 104, __pyx_L1_error) + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 101, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); } - __pyx_t_6 = __Pyx_PyNumber_Int(__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 104, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyNumber_Int(__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 101, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_9 = __Pyx_PyFloat_AsDouble(__pyx_t_6); if (unlikely((__pyx_t_9 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 104, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyFloat_AsDouble(__pyx_t_6); if (unlikely((__pyx_t_9 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 101, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - /* "polluck_blockchain/placeholder_native.pyx":105 + /* "polluck_blockchain/placeholder_native.pyx":102 * index, * int(datetime.datetime(2025, 12, 1, 12, 0, 0).timestamp()), * nonce, # <<<<<<<<<<<<<< * data.encode("UTF-8"), * previous_hash.encode("UTF-8"), */ - __pyx_t_10 = __Pyx_PyLong_As_uint64_t(__pyx_v_nonce); if (unlikely((__pyx_t_10 == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 105, __pyx_L1_error) + __pyx_t_10 = __Pyx_PyLong_As_uint64_t(__pyx_v_nonce); if (unlikely((__pyx_t_10 == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 102, __pyx_L1_error) - /* "polluck_blockchain/placeholder_native.pyx":106 + /* "polluck_blockchain/placeholder_native.pyx":103 * int(datetime.datetime(2025, 12, 1, 12, 0, 0).timestamp()), * nonce, * data.encode("UTF-8"), # <<<<<<<<<<<<<< @@ -4067,13 +4204,13 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock___cinit__ PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_mstate_global->__pyx_kp_u_UTF_8}; __pyx_t_6 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_encode, __pyx_callargs+__pyx_t_8, (2-__pyx_t_8) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 106, __pyx_L1_error) + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 103, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); } - __pyx_t_11 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_t_6); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 106, __pyx_L1_error) + __pyx_t_11 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_t_6); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 103, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - /* "polluck_blockchain/placeholder_native.pyx":107 + /* "polluck_blockchain/placeholder_native.pyx":104 * nonce, * data.encode("UTF-8"), * previous_hash.encode("UTF-8"), # <<<<<<<<<<<<<< @@ -4087,22 +4224,22 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock___cinit__ PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_mstate_global->__pyx_kp_u_UTF_8}; __pyx_t_6 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_encode, __pyx_callargs+__pyx_t_8, (2-__pyx_t_8) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 107, __pyx_L1_error) + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); } - __pyx_t_12 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_t_6); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 107, __pyx_L1_error) + __pyx_t_12 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_t_6); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - /* "polluck_blockchain/placeholder_native.pyx":108 + /* "polluck_blockchain/placeholder_native.pyx":105 * data.encode("UTF-8"), * previous_hash.encode("UTF-8"), * "".encode("UTF-8"), # <<<<<<<<<<<<<< * ) * if self.BlockC == NULL: */ - __pyx_t_13 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_mstate_global->__pyx_kp_b_); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 108, __pyx_L1_error) + __pyx_t_13 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_mstate_global->__pyx_kp_b_); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 105, __pyx_L1_error) - /* "polluck_blockchain/placeholder_native.pyx":102 + /* "polluck_blockchain/placeholder_native.pyx":99 * self.ptr_owner = False * if not from_ptr: * self.BlockC = new Block( # <<<<<<<<<<<<<< @@ -4113,11 +4250,11 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock___cinit__ __pyx_t_14 = new ::Block(__pyx_t_3, __pyx_t_9, __pyx_t_10, __pyx_t_11, __pyx_t_12, __pyx_t_13); } catch(...) { __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 102, __pyx_L1_error) + __PYX_ERR(0, 99, __pyx_L1_error) } __pyx_v_self->BlockC = __pyx_t_14; - /* "polluck_blockchain/placeholder_native.pyx":110 + /* "polluck_blockchain/placeholder_native.pyx":107 * "".encode("UTF-8"), * ) * if self.BlockC == NULL: # <<<<<<<<<<<<<< @@ -4127,16 +4264,16 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock___cinit__ __pyx_t_2 = (__pyx_v_self->BlockC == NULL); if (unlikely(__pyx_t_2)) { - /* "polluck_blockchain/placeholder_native.pyx":111 + /* "polluck_blockchain/placeholder_native.pyx":108 * ) * if self.BlockC == NULL: * raise MemoryError() # <<<<<<<<<<<<<< * * self.ptr_owner = True */ - PyErr_NoMemory(); __PYX_ERR(0, 111, __pyx_L1_error) + PyErr_NoMemory(); __PYX_ERR(0, 108, __pyx_L1_error) - /* "polluck_blockchain/placeholder_native.pyx":110 + /* "polluck_blockchain/placeholder_native.pyx":107 * "".encode("UTF-8"), * ) * if self.BlockC == NULL: # <<<<<<<<<<<<<< @@ -4145,7 +4282,7 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock___cinit__ */ } - /* "polluck_blockchain/placeholder_native.pyx":113 + /* "polluck_blockchain/placeholder_native.pyx":110 * raise MemoryError() * * self.ptr_owner = True # <<<<<<<<<<<<<< @@ -4154,7 +4291,7 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock___cinit__ */ __pyx_v_self->ptr_owner = 1; - /* "polluck_blockchain/placeholder_native.pyx":101 + /* "polluck_blockchain/placeholder_native.pyx":98 * ): * self.ptr_owner = False * if not from_ptr: # <<<<<<<<<<<<<< @@ -4163,7 +4300,7 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock___cinit__ */ } - /* "polluck_blockchain/placeholder_native.pyx":93 + /* "polluck_blockchain/placeholder_native.pyx":90 * bint ptr_owner * * def __cinit__(self, # <<<<<<<<<<<<<< @@ -4186,7 +4323,7 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock___cinit__ return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":115 +/* "polluck_blockchain/placeholder_native.pyx":112 * self.ptr_owner = True * * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -4234,7 +4371,7 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_2__init__ return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":118 +/* "polluck_blockchain/placeholder_native.pyx":115 * pass * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -4259,7 +4396,7 @@ static void __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_4__deall int __pyx_t_1; int __pyx_t_2; - /* "polluck_blockchain/placeholder_native.pyx":119 + /* "polluck_blockchain/placeholder_native.pyx":116 * * def __dealloc__(self): * if self.BlockC is not NULL and self.ptr_owner is True: # <<<<<<<<<<<<<< @@ -4277,7 +4414,7 @@ static void __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_4__deall __pyx_L4_bool_binop_done:; if (__pyx_t_1) { - /* "polluck_blockchain/placeholder_native.pyx":120 + /* "polluck_blockchain/placeholder_native.pyx":117 * def __dealloc__(self): * if self.BlockC is not NULL and self.ptr_owner is True: * del self.BlockC # <<<<<<<<<<<<<< @@ -4286,7 +4423,7 @@ static void __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_4__deall */ delete __pyx_v_self->BlockC; - /* "polluck_blockchain/placeholder_native.pyx":121 + /* "polluck_blockchain/placeholder_native.pyx":118 * if self.BlockC is not NULL and self.ptr_owner is True: * del self.BlockC * self.BlockC = NULL # <<<<<<<<<<<<<< @@ -4295,7 +4432,7 @@ static void __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_4__deall */ __pyx_v_self->BlockC = NULL; - /* "polluck_blockchain/placeholder_native.pyx":119 + /* "polluck_blockchain/placeholder_native.pyx":116 * * def __dealloc__(self): * if self.BlockC is not NULL and self.ptr_owner is True: # <<<<<<<<<<<<<< @@ -4304,7 +4441,7 @@ static void __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_4__deall */ } - /* "polluck_blockchain/placeholder_native.pyx":118 + /* "polluck_blockchain/placeholder_native.pyx":115 * pass * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -4315,7 +4452,7 @@ static void __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_4__deall /* function exit code */ } -/* "polluck_blockchain/placeholder_native.pyx":123 +/* "polluck_blockchain/placeholder_native.pyx":120 * self.BlockC = NULL * * @staticmethod # <<<<<<<<<<<<<< @@ -4325,7 +4462,7 @@ static void __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_4__deall static struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_from_ptr(::Block *__pyx_v_block, struct __pyx_opt_args_18polluck_blockchain_18placeholder_native_7PyBlock_from_ptr *__pyx_optional_args) { - /* "polluck_blockchain/placeholder_native.pyx":124 + /* "polluck_blockchain/placeholder_native.pyx":121 * * @staticmethod * cdef PyBlock from_ptr(Block *block, bint owner=False): # <<<<<<<<<<<<<< @@ -4351,77 +4488,77 @@ static struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx } } - /* "polluck_blockchain/placeholder_native.pyx":127 + /* "polluck_blockchain/placeholder_native.pyx":124 * cdef PyBlock py_block = PyBlock.__new__( * PyBlock, * block.index, # <<<<<<<<<<<<<< * block.nonce, * block.data, */ - __pyx_t_1 = __Pyx_PyLong_From_uint64_t(__pyx_v_block->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 127, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyLong_From_uint64_t(__pyx_v_block->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 124, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - /* "polluck_blockchain/placeholder_native.pyx":128 + /* "polluck_blockchain/placeholder_native.pyx":125 * PyBlock, * block.index, * block.nonce, # <<<<<<<<<<<<<< * block.data, * block.prev_hash, */ - __pyx_t_2 = __Pyx_PyLong_From_uint64_t(__pyx_v_block->nonce); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 128, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyLong_From_uint64_t(__pyx_v_block->nonce); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - /* "polluck_blockchain/placeholder_native.pyx":129 + /* "polluck_blockchain/placeholder_native.pyx":126 * block.index, * block.nonce, * block.data, # <<<<<<<<<<<<<< * block.prev_hash, * True, */ - __pyx_t_3 = __pyx_convert_PyBytes_string_to_py_6libcpp_6string_std__in_string(__pyx_v_block->data); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 129, __pyx_L1_error) + __pyx_t_3 = __pyx_convert_PyBytes_string_to_py_6libcpp_6string_std__in_string(__pyx_v_block->data); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 126, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - /* "polluck_blockchain/placeholder_native.pyx":130 + /* "polluck_blockchain/placeholder_native.pyx":127 * block.nonce, * block.data, * block.prev_hash, # <<<<<<<<<<<<<< * True, * ) */ - __pyx_t_4 = __pyx_convert_PyBytes_string_to_py_6libcpp_6string_std__in_string(__pyx_v_block->prev_hash); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 130, __pyx_L1_error) + __pyx_t_4 = __pyx_convert_PyBytes_string_to_py_6libcpp_6string_std__in_string(__pyx_v_block->prev_hash); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 127, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - /* "polluck_blockchain/placeholder_native.pyx":125 + /* "polluck_blockchain/placeholder_native.pyx":122 * @staticmethod * cdef PyBlock from_ptr(Block *block, bint owner=False): * cdef PyBlock py_block = PyBlock.__new__( # <<<<<<<<<<<<<< * PyBlock, * block.index, */ - __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 125, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 122, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_1); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1) != (0)) __PYX_ERR(0, 125, __pyx_L1_error); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1) != (0)) __PYX_ERR(0, 122, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_2); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2) != (0)) __PYX_ERR(0, 125, __pyx_L1_error); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2) != (0)) __PYX_ERR(0, 122, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_3); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3) != (0)) __PYX_ERR(0, 125, __pyx_L1_error); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3) != (0)) __PYX_ERR(0, 122, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_4); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4) != (0)) __PYX_ERR(0, 125, __pyx_L1_error); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4) != (0)) __PYX_ERR(0, 122, __pyx_L1_error); __Pyx_INCREF(Py_True); __Pyx_GIVEREF(Py_True); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 4, Py_True) != (0)) __PYX_ERR(0, 125, __pyx_L1_error); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 4, Py_True) != (0)) __PYX_ERR(0, 122, __pyx_L1_error); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_4 = 0; - __pyx_t_4 = ((PyObject *)__pyx_tp_new_18polluck_blockchain_18placeholder_native_PyBlock(((PyTypeObject *)__pyx_mstate_global->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock), __pyx_t_5, NULL)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 125, __pyx_L1_error) + __pyx_t_4 = ((PyObject *)__pyx_tp_new_18polluck_blockchain_18placeholder_native_PyBlock(((PyTypeObject *)__pyx_mstate_global->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock), __pyx_t_5, NULL)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 122, __pyx_L1_error) __Pyx_GOTREF((PyObject *)__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_py_block = ((struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *)__pyx_t_4); __pyx_t_4 = 0; - /* "polluck_blockchain/placeholder_native.pyx":133 + /* "polluck_blockchain/placeholder_native.pyx":130 * True, * ) * py_block.BlockC = block # <<<<<<<<<<<<<< @@ -4430,7 +4567,7 @@ static struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx */ __pyx_v_py_block->BlockC = __pyx_v_block; - /* "polluck_blockchain/placeholder_native.pyx":134 + /* "polluck_blockchain/placeholder_native.pyx":131 * ) * py_block.BlockC = block * py_block.ptr_owner = owner # <<<<<<<<<<<<<< @@ -4439,7 +4576,7 @@ static struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx */ __pyx_v_py_block->ptr_owner = __pyx_v_owner; - /* "polluck_blockchain/placeholder_native.pyx":136 + /* "polluck_blockchain/placeholder_native.pyx":133 * py_block.ptr_owner = owner * * return py_block # <<<<<<<<<<<<<< @@ -4451,7 +4588,7 @@ static struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx __pyx_r = __pyx_v_py_block; goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":123 + /* "polluck_blockchain/placeholder_native.pyx":120 * self.BlockC = NULL * * @staticmethod # <<<<<<<<<<<<<< @@ -4475,7 +4612,7 @@ static struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":138 +/* "polluck_blockchain/placeholder_native.pyx":135 * return py_block * * def __repr__(self): # <<<<<<<<<<<<<< @@ -4512,7 +4649,7 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_6__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__repr__", 0); - /* "polluck_blockchain/placeholder_native.pyx":139 + /* "polluck_blockchain/placeholder_native.pyx":136 * * def __repr__(self): * return f"PyBlock({self.index, self.timestamp, self.nonce, self.data})" # <<<<<<<<<<<<<< @@ -4520,43 +4657,43 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_6__ * def __str__(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 136, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_timestamp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 139, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_timestamp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 136, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_nonce); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 139, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_nonce); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 136, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 139, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 136, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 139, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 136, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_1); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1) != (0)) __PYX_ERR(0, 139, __pyx_L1_error); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1) != (0)) __PYX_ERR(0, 136, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_2); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2) != (0)) __PYX_ERR(0, 139, __pyx_L1_error); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2) != (0)) __PYX_ERR(0, 136, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_3); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3) != (0)) __PYX_ERR(0, 139, __pyx_L1_error); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3) != (0)) __PYX_ERR(0, 136, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_4); - if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4) != (0)) __PYX_ERR(0, 139, __pyx_L1_error); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4) != (0)) __PYX_ERR(0, 136, __pyx_L1_error); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_t_5, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 139, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_t_5, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 136, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_6[0] = __pyx_mstate_global->__pyx_kp_u_PyBlock; __pyx_t_6[1] = __pyx_t_4; __pyx_t_6[2] = __pyx_mstate_global->__pyx_kp_u__2; __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_6, 3, 8 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4) + 1, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4)); - if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 139, __pyx_L1_error) + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 136, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":138 + /* "polluck_blockchain/placeholder_native.pyx":135 * return py_block * * def __repr__(self): # <<<<<<<<<<<<<< @@ -4579,7 +4716,7 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_6__ return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":141 +/* "polluck_blockchain/placeholder_native.pyx":138 * return f"PyBlock({self.index, self.timestamp, self.nonce, self.data})" * * def __str__(self): # <<<<<<<<<<<<<< @@ -4613,12 +4750,12 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_8__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__str__", 0); - /* "polluck_blockchain/placeholder_native.pyx":142 + /* "polluck_blockchain/placeholder_native.pyx":139 * * def __str__(self): * return self.__repr__() # <<<<<<<<<<<<<< * - * # cpdef _perform_hash(self): + * # Python public API */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = ((PyObject *)__pyx_v_self); @@ -4628,14 +4765,14 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_8__ PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL}; __pyx_t_1 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_repr, __pyx_callargs+__pyx_t_3, (1-__pyx_t_3) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 142, __pyx_L1_error) + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":141 + /* "polluck_blockchain/placeholder_native.pyx":138 * return f"PyBlock({self.index, self.timestamp, self.nonce, self.data})" * * def __str__(self): # <<<<<<<<<<<<<< @@ -4655,7 +4792,7 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_8__ return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":161 +/* "polluck_blockchain/placeholder_native.pyx":142 * * # Python public API * @property # <<<<<<<<<<<<<< @@ -4687,7 +4824,7 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_5in int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - /* "polluck_blockchain/placeholder_native.pyx":163 + /* "polluck_blockchain/placeholder_native.pyx":144 * @property * def index(self): * return self.BlockC.index # <<<<<<<<<<<<<< @@ -4695,13 +4832,13 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_5in * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyLong_From_uint64_t(__pyx_v_self->BlockC->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 163, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyLong_From_uint64_t(__pyx_v_self->BlockC->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 144, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":161 + /* "polluck_blockchain/placeholder_native.pyx":142 * * # Python public API * @property # <<<<<<<<<<<<<< @@ -4720,7 +4857,7 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_5in return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":165 +/* "polluck_blockchain/placeholder_native.pyx":146 * return self.BlockC.index * * @property # <<<<<<<<<<<<<< @@ -4752,7 +4889,7 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_9ti int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - /* "polluck_blockchain/placeholder_native.pyx":167 + /* "polluck_blockchain/placeholder_native.pyx":148 * @property * def timestamp(self): * return timestamp_to_datetime(self.BlockC.timestamp) # <<<<<<<<<<<<<< @@ -4760,13 +4897,13 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_9ti * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_18polluck_blockchain_18placeholder_native_timestamp_to_datetime(__pyx_v_self->BlockC->timestamp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 167, __pyx_L1_error) + __pyx_t_1 = __pyx_f_18polluck_blockchain_18placeholder_native_timestamp_to_datetime(__pyx_v_self->BlockC->timestamp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":165 + /* "polluck_blockchain/placeholder_native.pyx":146 * return self.BlockC.index * * @property # <<<<<<<<<<<<<< @@ -4785,7 +4922,7 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_9ti return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":169 +/* "polluck_blockchain/placeholder_native.pyx":150 * return timestamp_to_datetime(self.BlockC.timestamp) * * @property # <<<<<<<<<<<<<< @@ -4817,7 +4954,7 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_4da int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - /* "polluck_blockchain/placeholder_native.pyx":171 + /* "polluck_blockchain/placeholder_native.pyx":152 * @property * def data(self): * return self.BlockC.data.decode("UTF-8") # <<<<<<<<<<<<<< @@ -4825,13 +4962,13 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_4da * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_decode_cpp_string(__pyx_v_self->BlockC->data, 0, PY_SSIZE_T_MAX, NULL, NULL, PyUnicode_DecodeUTF8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 171, __pyx_L1_error) + __pyx_t_1 = __Pyx_decode_cpp_string(__pyx_v_self->BlockC->data, 0, PY_SSIZE_T_MAX, NULL, NULL, PyUnicode_DecodeUTF8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":169 + /* "polluck_blockchain/placeholder_native.pyx":150 * return timestamp_to_datetime(self.BlockC.timestamp) * * @property # <<<<<<<<<<<<<< @@ -4850,7 +4987,7 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_4da return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":173 +/* "polluck_blockchain/placeholder_native.pyx":154 * return self.BlockC.data.decode("UTF-8") * * @property # <<<<<<<<<<<<<< @@ -4882,7 +5019,7 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_9pr int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - /* "polluck_blockchain/placeholder_native.pyx":175 + /* "polluck_blockchain/placeholder_native.pyx":156 * @property * def prev_hash(self): * return self.BlockC.prev_hash.decode("UTF-8") # <<<<<<<<<<<<<< @@ -4890,13 +5027,13 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_9pr * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_decode_cpp_string(__pyx_v_self->BlockC->prev_hash, 0, PY_SSIZE_T_MAX, NULL, NULL, PyUnicode_DecodeUTF8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 175, __pyx_L1_error) + __pyx_t_1 = __Pyx_decode_cpp_string(__pyx_v_self->BlockC->prev_hash, 0, PY_SSIZE_T_MAX, NULL, NULL, PyUnicode_DecodeUTF8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 156, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":173 + /* "polluck_blockchain/placeholder_native.pyx":154 * return self.BlockC.data.decode("UTF-8") * * @property # <<<<<<<<<<<<<< @@ -4915,7 +5052,7 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_9pr return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":177 +/* "polluck_blockchain/placeholder_native.pyx":158 * return self.BlockC.prev_hash.decode("UTF-8") * * @property # <<<<<<<<<<<<<< @@ -4947,21 +5084,21 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_5no int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - /* "polluck_blockchain/placeholder_native.pyx":179 + /* "polluck_blockchain/placeholder_native.pyx":160 * @property * def nonce(self): * return self.BlockC.nonce # <<<<<<<<<<<<<< * - * # @nonce.setter + * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyLong_From_uint64_t(__pyx_v_self->BlockC->nonce); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 179, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyLong_From_uint64_t(__pyx_v_self->BlockC->nonce); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":177 + /* "polluck_blockchain/placeholder_native.pyx":158 * return self.BlockC.prev_hash.decode("UTF-8") * * @property # <<<<<<<<<<<<<< @@ -4980,8 +5117,8 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_5no return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":185 - * # self._nonce = value +/* "polluck_blockchain/placeholder_native.pyx":162 + * return self.BlockC.nonce * * @property # <<<<<<<<<<<<<< * def hash(self): @@ -5012,22 +5149,22 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_4ha int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - /* "polluck_blockchain/placeholder_native.pyx":187 + /* "polluck_blockchain/placeholder_native.pyx":164 * @property * def hash(self): * return self.BlockC.hash.decode("UTF-8") # <<<<<<<<<<<<<< * - * cdef unsigned char* bytes_serialize_c(self, size_t *size) nogil: + * def bytes_serialize(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_decode_cpp_string(__pyx_v_self->BlockC->hash, 0, PY_SSIZE_T_MAX, NULL, NULL, PyUnicode_DecodeUTF8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 187, __pyx_L1_error) + __pyx_t_1 = __Pyx_decode_cpp_string(__pyx_v_self->BlockC->hash, 0, PY_SSIZE_T_MAX, NULL, NULL, PyUnicode_DecodeUTF8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 164, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":185 - * # self._nonce = value + /* "polluck_blockchain/placeholder_native.pyx":162 + * return self.BlockC.nonce * * @property # <<<<<<<<<<<<<< * def hash(self): @@ -5045,381 +5182,9 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_4ha return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":189 +/* "polluck_blockchain/placeholder_native.pyx":166 * return self.BlockC.hash.decode("UTF-8") * - * cdef unsigned char* bytes_serialize_c(self, size_t *size) nogil: # <<<<<<<<<<<<<< - * cdef: - * size_t total_len -*/ - -static unsigned char *__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_bytes_serialize_c(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self, size_t *__pyx_v_size) { - unsigned char *__pyx_v_buf; - size_t __pyx_v_pos; - unsigned char *__pyx_r; - int __pyx_t_1; - int __pyx_t_2; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyGILState_STATE __pyx_gilstate_save; - - /* "polluck_blockchain/placeholder_native.pyx":193 - * size_t total_len - * unsigned char* buf - * size_t pos = 0 # <<<<<<<<<<<<<< - * - * # index (8), timestamp (8), nonce (8), data, prev_hash -*/ - __pyx_v_pos = 0; - - /* "polluck_blockchain/placeholder_native.pyx":196 - * - * # index (8), timestamp (8), nonce (8), data, prev_hash - * size[0] = ( # <<<<<<<<<<<<<< - * (8 * 3) + - * self.BlockC.data.size() + -*/ - (__pyx_v_size[0]) = ((((size_t)0x18) + __pyx_v_self->BlockC->data.size()) + __pyx_v_self->BlockC->prev_hash.size()); - - /* "polluck_blockchain/placeholder_native.pyx":201 - * self.BlockC.prev_hash.size() - * ) - * buf = malloc(size[0] * sizeof(unsigned char)) # <<<<<<<<<<<<<< - * - * if buf == NULL: -*/ - __pyx_v_buf = ((unsigned char *)malloc(((__pyx_v_size[0]) * (sizeof(unsigned char))))); - - /* "polluck_blockchain/placeholder_native.pyx":203 - * buf = malloc(size[0] * sizeof(unsigned char)) - * - * if buf == NULL: # <<<<<<<<<<<<<< - * return NULL - * -*/ - __pyx_t_1 = (__pyx_v_buf == NULL); - if (__pyx_t_1) { - - /* "polluck_blockchain/placeholder_native.pyx":204 - * - * if buf == NULL: - * return NULL # <<<<<<<<<<<<<< - * - * serialize_uint64(buf + pos, self.BlockC.index) -*/ - __pyx_r = NULL; - goto __pyx_L0; - - /* "polluck_blockchain/placeholder_native.pyx":203 - * buf = malloc(size[0] * sizeof(unsigned char)) - * - * if buf == NULL: # <<<<<<<<<<<<<< - * return NULL - * -*/ - } - - /* "polluck_blockchain/placeholder_native.pyx":206 - * return NULL - * - * serialize_uint64(buf + pos, self.BlockC.index) # <<<<<<<<<<<<<< - * pos += 8 - * serialize_uint64(buf + pos, self.BlockC.timestamp) -*/ - __pyx_t_2 = __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint64((__pyx_v_buf + __pyx_v_pos), __pyx_v_self->BlockC->index); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 206, __pyx_L1_error) - - /* "polluck_blockchain/placeholder_native.pyx":207 - * - * serialize_uint64(buf + pos, self.BlockC.index) - * pos += 8 # <<<<<<<<<<<<<< - * serialize_uint64(buf + pos, self.BlockC.timestamp) - * pos += 8 -*/ - __pyx_v_pos = (__pyx_v_pos + 8); - - /* "polluck_blockchain/placeholder_native.pyx":208 - * serialize_uint64(buf + pos, self.BlockC.index) - * pos += 8 - * serialize_uint64(buf + pos, self.BlockC.timestamp) # <<<<<<<<<<<<<< - * pos += 8 - * serialize_uint64(buf + pos, self.BlockC.nonce) -*/ - __pyx_t_2 = __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint64((__pyx_v_buf + __pyx_v_pos), __pyx_v_self->BlockC->timestamp); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 208, __pyx_L1_error) - - /* "polluck_blockchain/placeholder_native.pyx":209 - * pos += 8 - * serialize_uint64(buf + pos, self.BlockC.timestamp) - * pos += 8 # <<<<<<<<<<<<<< - * serialize_uint64(buf + pos, self.BlockC.nonce) - * pos += 8 -*/ - __pyx_v_pos = (__pyx_v_pos + 8); - - /* "polluck_blockchain/placeholder_native.pyx":210 - * serialize_uint64(buf + pos, self.BlockC.timestamp) - * pos += 8 - * serialize_uint64(buf + pos, self.BlockC.nonce) # <<<<<<<<<<<<<< - * pos += 8 - * # Copy data -*/ - __pyx_t_2 = __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint64((__pyx_v_buf + __pyx_v_pos), __pyx_v_self->BlockC->nonce); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 210, __pyx_L1_error) - - /* "polluck_blockchain/placeholder_native.pyx":211 - * pos += 8 - * serialize_uint64(buf + pos, self.BlockC.nonce) - * pos += 8 # <<<<<<<<<<<<<< - * # Copy data - * memcpy( -*/ - __pyx_v_pos = (__pyx_v_pos + 8); - - /* "polluck_blockchain/placeholder_native.pyx":213 - * pos += 8 - * # Copy data - * memcpy( # <<<<<<<<<<<<<< - * buf + pos, - * self.BlockC.data.c_str(), -*/ - (void)(memcpy((__pyx_v_buf + __pyx_v_pos), __pyx_v_self->BlockC->data.c_str(), __pyx_v_self->BlockC->data.size())); - - /* "polluck_blockchain/placeholder_native.pyx":218 - * self.BlockC.data.size(), - * ) - * pos += self.BlockC.data.size() # <<<<<<<<<<<<<< - * # Copy prev_hash - * memcpy( -*/ - __pyx_v_pos = (__pyx_v_pos + __pyx_v_self->BlockC->data.size()); - - /* "polluck_blockchain/placeholder_native.pyx":220 - * pos += self.BlockC.data.size() - * # Copy prev_hash - * memcpy( # <<<<<<<<<<<<<< - * buf + pos, - * self.BlockC.prev_hash.c_str(), -*/ - (void)(memcpy((__pyx_v_buf + __pyx_v_pos), __pyx_v_self->BlockC->prev_hash.c_str(), __pyx_v_self->BlockC->prev_hash.size())); - - /* "polluck_blockchain/placeholder_native.pyx":225 - * self.BlockC.prev_hash.size(), - * ) - * pos += self.BlockC.prev_hash.size() # <<<<<<<<<<<<<< - * - * return buf -*/ - __pyx_v_pos = (__pyx_v_pos + __pyx_v_self->BlockC->prev_hash.size()); - - /* "polluck_blockchain/placeholder_native.pyx":227 - * pos += self.BlockC.prev_hash.size() - * - * return buf # <<<<<<<<<<<<<< - * - * cdef unsigned char* digest(self, unsigned char *data, size_t data_size, size_t *digest_size) nogil: -*/ - __pyx_r = __pyx_v_buf; - goto __pyx_L0; - - /* "polluck_blockchain/placeholder_native.pyx":189 - * return self.BlockC.hash.decode("UTF-8") - * - * cdef unsigned char* bytes_serialize_c(self, size_t *size) nogil: # <<<<<<<<<<<<<< - * cdef: - * size_t total_len -*/ - - /* function exit code */ - __pyx_L1_error:; - __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); - __Pyx_AddTraceback("polluck_blockchain.placeholder_native.PyBlock.bytes_serialize_c", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __Pyx_PyGILState_Release(__pyx_gilstate_save); - __pyx_L0:; - return __pyx_r; -} - -/* "polluck_blockchain/placeholder_native.pyx":229 - * return buf - * - * cdef unsigned char* digest(self, unsigned char *data, size_t data_size, size_t *digest_size) nogil: # <<<<<<<<<<<<<< - * cdef ossl.EVP_MD_CTX *ctx = ossl.EVP_MD_CTX_new() - * if ctx == NULL: -*/ - -static unsigned char *__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_digest(CYTHON_UNUSED struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self, unsigned char *__pyx_v_data, size_t __pyx_v_data_size, size_t *__pyx_v_digest_size) { - EVP_MD_CTX *__pyx_v_ctx; - EVP_MD const *__pyx_v_algo; - unsigned char *__pyx_v_digest; - size_t __pyx_v_dig_buff_len; - unsigned int __pyx_v_digest_len; - unsigned char *__pyx_r; - int __pyx_t_1; - - /* "polluck_blockchain/placeholder_native.pyx":230 - * - * cdef unsigned char* digest(self, unsigned char *data, size_t data_size, size_t *digest_size) nogil: - * cdef ossl.EVP_MD_CTX *ctx = ossl.EVP_MD_CTX_new() # <<<<<<<<<<<<<< - * if ctx == NULL: - * return NULL -*/ - __pyx_v_ctx = EVP_MD_CTX_new(); - - /* "polluck_blockchain/placeholder_native.pyx":231 - * cdef unsigned char* digest(self, unsigned char *data, size_t data_size, size_t *digest_size) nogil: - * cdef ossl.EVP_MD_CTX *ctx = ossl.EVP_MD_CTX_new() - * if ctx == NULL: # <<<<<<<<<<<<<< - * return NULL - * cdef const ossl.EVP_MD *algo = ossl.EVP_sha256() -*/ - __pyx_t_1 = (__pyx_v_ctx == NULL); - if (__pyx_t_1) { - - /* "polluck_blockchain/placeholder_native.pyx":232 - * cdef ossl.EVP_MD_CTX *ctx = ossl.EVP_MD_CTX_new() - * if ctx == NULL: - * return NULL # <<<<<<<<<<<<<< - * cdef const ossl.EVP_MD *algo = ossl.EVP_sha256() - * if algo == NULL: -*/ - __pyx_r = NULL; - goto __pyx_L0; - - /* "polluck_blockchain/placeholder_native.pyx":231 - * cdef unsigned char* digest(self, unsigned char *data, size_t data_size, size_t *digest_size) nogil: - * cdef ossl.EVP_MD_CTX *ctx = ossl.EVP_MD_CTX_new() - * if ctx == NULL: # <<<<<<<<<<<<<< - * return NULL - * cdef const ossl.EVP_MD *algo = ossl.EVP_sha256() -*/ - } - - /* "polluck_blockchain/placeholder_native.pyx":233 - * if ctx == NULL: - * return NULL - * cdef const ossl.EVP_MD *algo = ossl.EVP_sha256() # <<<<<<<<<<<<<< - * if algo == NULL: - * return NULL -*/ - __pyx_v_algo = EVP_sha256(); - - /* "polluck_blockchain/placeholder_native.pyx":234 - * return NULL - * cdef const ossl.EVP_MD *algo = ossl.EVP_sha256() - * if algo == NULL: # <<<<<<<<<<<<<< - * return NULL - * -*/ - __pyx_t_1 = (__pyx_v_algo == NULL); - if (__pyx_t_1) { - - /* "polluck_blockchain/placeholder_native.pyx":235 - * cdef const ossl.EVP_MD *algo = ossl.EVP_sha256() - * if algo == NULL: - * return NULL # <<<<<<<<<<<<<< - * - * cdef: -*/ - __pyx_r = NULL; - goto __pyx_L0; - - /* "polluck_blockchain/placeholder_native.pyx":234 - * return NULL - * cdef const ossl.EVP_MD *algo = ossl.EVP_sha256() - * if algo == NULL: # <<<<<<<<<<<<<< - * return NULL - * -*/ - } - - /* "polluck_blockchain/placeholder_native.pyx":242 - * unsigned int digest_len - * - * dig_buff_len = ossl.EVP_MD_size(algo) # <<<<<<<<<<<<<< - * digest = malloc(dig_buff_len * sizeof(unsigned char)) - * ossl.EVP_DigestInit_ex(ctx, algo, NULL) -*/ - __pyx_v_dig_buff_len = ((size_t)EVP_MD_size(__pyx_v_algo)); - - /* "polluck_blockchain/placeholder_native.pyx":243 - * - * dig_buff_len = ossl.EVP_MD_size(algo) - * digest = malloc(dig_buff_len * sizeof(unsigned char)) # <<<<<<<<<<<<<< - * ossl.EVP_DigestInit_ex(ctx, algo, NULL) - * ossl.EVP_DigestUpdate(ctx, data, data_size) -*/ - __pyx_v_digest = ((unsigned char *)malloc((__pyx_v_dig_buff_len * (sizeof(unsigned char))))); - - /* "polluck_blockchain/placeholder_native.pyx":244 - * dig_buff_len = ossl.EVP_MD_size(algo) - * digest = malloc(dig_buff_len * sizeof(unsigned char)) - * ossl.EVP_DigestInit_ex(ctx, algo, NULL) # <<<<<<<<<<<<<< - * ossl.EVP_DigestUpdate(ctx, data, data_size) - * ossl.EVP_DigestFinal_ex(ctx, digest, &digest_len) -*/ - (void)(EVP_DigestInit_ex(__pyx_v_ctx, __pyx_v_algo, NULL)); - - /* "polluck_blockchain/placeholder_native.pyx":245 - * digest = malloc(dig_buff_len * sizeof(unsigned char)) - * ossl.EVP_DigestInit_ex(ctx, algo, NULL) - * ossl.EVP_DigestUpdate(ctx, data, data_size) # <<<<<<<<<<<<<< - * ossl.EVP_DigestFinal_ex(ctx, digest, &digest_len) - * -*/ - (void)(EVP_DigestUpdate(__pyx_v_ctx, __pyx_v_data, __pyx_v_data_size)); - - /* "polluck_blockchain/placeholder_native.pyx":246 - * ossl.EVP_DigestInit_ex(ctx, algo, NULL) - * ossl.EVP_DigestUpdate(ctx, data, data_size) - * ossl.EVP_DigestFinal_ex(ctx, digest, &digest_len) # <<<<<<<<<<<<<< - * - * digest_size[0] = dig_buff_len -*/ - (void)(EVP_DigestFinal_ex(__pyx_v_ctx, __pyx_v_digest, (&__pyx_v_digest_len))); - - /* "polluck_blockchain/placeholder_native.pyx":248 - * ossl.EVP_DigestFinal_ex(ctx, digest, &digest_len) - * - * digest_size[0] = dig_buff_len # <<<<<<<<<<<<<< - * - * ossl.EVP_MD_CTX_free(ctx) -*/ - (__pyx_v_digest_size[0]) = __pyx_v_dig_buff_len; - - /* "polluck_blockchain/placeholder_native.pyx":250 - * digest_size[0] = dig_buff_len - * - * ossl.EVP_MD_CTX_free(ctx) # <<<<<<<<<<<<<< - * - * return digest -*/ - EVP_MD_CTX_free(__pyx_v_ctx); - - /* "polluck_blockchain/placeholder_native.pyx":252 - * ossl.EVP_MD_CTX_free(ctx) - * - * return digest # <<<<<<<<<<<<<< - * - * def bytes_serialize(self): -*/ - __pyx_r = __pyx_v_digest; - goto __pyx_L0; - - /* "polluck_blockchain/placeholder_native.pyx":229 - * return buf - * - * cdef unsigned char* digest(self, unsigned char *data, size_t data_size, size_t *digest_size) nogil: # <<<<<<<<<<<<<< - * cdef ossl.EVP_MD_CTX *ctx = ossl.EVP_MD_CTX_new() - * if ctx == NULL: -*/ - - /* function exit code */ - __pyx_L0:; - return __pyx_r; -} - -/* "polluck_blockchain/placeholder_native.pyx":254 - * return digest - * * def bytes_serialize(self): # <<<<<<<<<<<<<< * cdef: * unsigned char *serialize_res @@ -5488,46 +5253,46 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_10b int __pyx_clineno = 0; __Pyx_RefNannySetupContext("bytes_serialize", 0); - /* "polluck_blockchain/placeholder_native.pyx":258 + /* "polluck_blockchain/placeholder_native.pyx":170 * unsigned char *serialize_res * size_t serialize_size * try: # <<<<<<<<<<<<<< - * serialize_res = self.bytes_serialize_c(&serialize_size) + * serialize_res = bytes_serialize_c(self.BlockC, &serialize_size) * return serialize_res[:serialize_size] */ /*try:*/ { - /* "polluck_blockchain/placeholder_native.pyx":259 + /* "polluck_blockchain/placeholder_native.pyx":171 * size_t serialize_size * try: - * serialize_res = self.bytes_serialize_c(&serialize_size) # <<<<<<<<<<<<<< + * serialize_res = bytes_serialize_c(self.BlockC, &serialize_size) # <<<<<<<<<<<<<< * return serialize_res[:serialize_size] * finally: */ - __pyx_t_1 = ((struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_PyBlock *)__pyx_v_self->__pyx_vtab)->bytes_serialize_c(__pyx_v_self, (&__pyx_v_serialize_size)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 259, __pyx_L4_error) + __pyx_t_1 = __pyx_f_18polluck_blockchain_18placeholder_native_bytes_serialize_c(__pyx_v_self->BlockC, (&__pyx_v_serialize_size)); if (unlikely(__pyx_t_1 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 171, __pyx_L4_error) __pyx_v_serialize_res = __pyx_t_1; - /* "polluck_blockchain/placeholder_native.pyx":260 + /* "polluck_blockchain/placeholder_native.pyx":172 * try: - * serialize_res = self.bytes_serialize_c(&serialize_size) + * serialize_res = bytes_serialize_c(self.BlockC, &serialize_size) * return serialize_res[:serialize_size] # <<<<<<<<<<<<<< * finally: * free(serialize_res) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyBytes_FromStringAndSize(((char const *)__pyx_v_serialize_res) + 0, __pyx_v_serialize_size - 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 260, __pyx_L4_error) + __pyx_t_2 = __Pyx_PyBytes_FromStringAndSize(((char const *)__pyx_v_serialize_res) + 0, __pyx_v_serialize_size - 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 172, __pyx_L4_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L3_return; } - /* "polluck_blockchain/placeholder_native.pyx":262 + /* "polluck_blockchain/placeholder_native.pyx":174 * return serialize_res[:serialize_size] * finally: * free(serialize_res) # <<<<<<<<<<<<<< * - * cpdef mine(self, unsigned int difficulty, unsigned int max_nonce=0xFFFFFFFF): + * */ /*finally:*/ { __pyx_L4_error:; @@ -5570,8 +5335,8 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_10b } } - /* "polluck_blockchain/placeholder_native.pyx":254 - * return digest + /* "polluck_blockchain/placeholder_native.pyx":166 + * return self.BlockC.hash.decode("UTF-8") * * def bytes_serialize(self): # <<<<<<<<<<<<<< * cdef: @@ -5589,376 +5354,37 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_10b return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":264 - * free(serialize_res) +/* "polluck_blockchain/placeholder_native.pyx":177 * - * cpdef mine(self, unsigned int difficulty, unsigned int max_nonce=0xFFFFFFFF): # <<<<<<<<<<<<<< + * + * def perform_hash(self): # <<<<<<<<<<<<<< * cdef: - * unsigned char *serial_buf -*/ - -static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_13mine(PyObject *__pyx_v_self, -#if CYTHON_METH_FASTCALL -PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds -#else -PyObject *__pyx_args, PyObject *__pyx_kwds -#endif -); /*proto*/ -static PyObject *__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_mine(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self, unsigned int __pyx_v_difficulty, int __pyx_skip_dispatch, struct __pyx_opt_args_18polluck_blockchain_18placeholder_native_7PyBlock_mine *__pyx_optional_args) { - unsigned int __pyx_v_max_nonce = ((unsigned int)0xFFFFFFFF); - unsigned char *__pyx_v_serial_buf; - size_t __pyx_v_serialize_size; - unsigned char *__pyx_v_digest; - size_t __pyx_v_digest_size; - int __pyx_v_nonce_found; - int __pyx_v_nonce; - int __pyx_v_nonce_solution; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - size_t __pyx_t_7; - unsigned char *__pyx_t_8; - unsigned int __pyx_t_9; - unsigned int __pyx_t_10; - int __pyx_t_11; - int __pyx_t_12; - int __pyx_t_13; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("mine", 0); - if (__pyx_optional_args) { - if (__pyx_optional_args->__pyx_n > 0) { - __pyx_v_max_nonce = __pyx_optional_args->max_nonce; - } - } - /* Check if called by wrapper */ - if (unlikely(__pyx_skip_dispatch)) ; - /* Check if overridden in Python */ - else if ( - #if !CYTHON_USE_TYPE_SLOTS - unlikely(Py_TYPE(((PyObject *)__pyx_v_self)) != __pyx_mstate_global->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock && - __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), Py_TPFLAGS_HAVE_GC)) - #else - unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0 || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE))) - #endif - ) { - #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS - static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT; - if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) { - PY_UINT64_T __pyx_typedict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); - #endif - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_mine); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!__Pyx_IsSameCFunction(__pyx_t_1, (void(*)(void)) __pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_13mine)) { - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = NULL; - __Pyx_INCREF(__pyx_t_1); - __pyx_t_4 = __pyx_t_1; - __pyx_t_5 = __Pyx_PyLong_From_unsigned_int(__pyx_v_difficulty); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyLong_From_unsigned_int(__pyx_v_max_nonce); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = 1; - #if CYTHON_UNPACK_METHODS - if (unlikely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); - assert(__pyx_t_3); - PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx__function); - __Pyx_DECREF_SET(__pyx_t_4, __pyx__function); - __pyx_t_7 = 0; - } - #endif - { - PyObject *__pyx_callargs[3] = {__pyx_t_3, __pyx_t_5, __pyx_t_6}; - __pyx_t_2 = __Pyx_PyObject_FastCall((PyObject*)__pyx_t_4, __pyx_callargs+__pyx_t_7, (3-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - } - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; - } - #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS - __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); - __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self)); - if (unlikely(__pyx_typedict_guard != __pyx_tp_dict_version)) { - __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT; - } - #endif - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS - } - #endif - } - - /* "polluck_blockchain/placeholder_native.pyx":270 * unsigned char *digest - * size_t digest_size - * bint nonce_found = False # <<<<<<<<<<<<<< - * int nonce, nonce_solution = 0 - * */ - __pyx_v_nonce_found = 0; - - /* "polluck_blockchain/placeholder_native.pyx":271 - * size_t digest_size - * bint nonce_found = False - * int nonce, nonce_solution = 0 # <<<<<<<<<<<<<< - * - * serial_buf = self.bytes_serialize_c(&serialize_size) -*/ - __pyx_v_nonce_solution = 0; - - /* "polluck_blockchain/placeholder_native.pyx":273 - * int nonce, nonce_solution = 0 - * - * serial_buf = self.bytes_serialize_c(&serialize_size) # <<<<<<<<<<<<<< - * - * with nogil: -*/ - __pyx_t_8 = ((struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_PyBlock *)__pyx_v_self->__pyx_vtab)->bytes_serialize_c(__pyx_v_self, (&__pyx_v_serialize_size)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 273, __pyx_L1_error) - __pyx_v_serial_buf = __pyx_t_8; - - /* "polluck_blockchain/placeholder_native.pyx":275 - * serial_buf = self.bytes_serialize_c(&serialize_size) - * - * with nogil: # <<<<<<<<<<<<<< - * for nonce in range(max_nonce): - * serialize_uint64(serial_buf + NONCE_OFFSET, nonce) -*/ - { - PyThreadState * _save; - _save = PyEval_SaveThread(); - __Pyx_FastGIL_Remember(); - /*try:*/ { - - /* "polluck_blockchain/placeholder_native.pyx":276 - * - * with nogil: - * for nonce in range(max_nonce): # <<<<<<<<<<<<<< - * serialize_uint64(serial_buf + NONCE_OFFSET, nonce) - * digest = self.digest(serial_buf, serialize_size, &digest_size) -*/ - __pyx_t_9 = __pyx_v_max_nonce; - __pyx_t_10 = __pyx_t_9; - for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) { - __pyx_v_nonce = __pyx_t_11; - - /* "polluck_blockchain/placeholder_native.pyx":277 - * with nogil: - * for nonce in range(max_nonce): - * serialize_uint64(serial_buf + NONCE_OFFSET, nonce) # <<<<<<<<<<<<<< - * digest = self.digest(serial_buf, serialize_size, &digest_size) - * -*/ - __pyx_t_12 = __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint64((__pyx_v_serial_buf + __pyx_v_18polluck_blockchain_18placeholder_native_NONCE_OFFSET), ((uint64_t)__pyx_v_nonce)); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 277, __pyx_L4_error) - - /* "polluck_blockchain/placeholder_native.pyx":278 - * for nonce in range(max_nonce): - * serialize_uint64(serial_buf + NONCE_OFFSET, nonce) - * digest = self.digest(serial_buf, serialize_size, &digest_size) # <<<<<<<<<<<<<< - * - * if has_leading_zero_bits(digest, difficulty): -*/ - __pyx_t_8 = ((struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_PyBlock *)__pyx_v_self->__pyx_vtab)->digest(__pyx_v_self, __pyx_v_serial_buf, __pyx_v_serialize_size, (&__pyx_v_digest_size)); if (unlikely(__Pyx_ErrOccurredWithGIL())) __PYX_ERR(0, 278, __pyx_L4_error) - __pyx_v_digest = __pyx_t_8; - - /* "polluck_blockchain/placeholder_native.pyx":280 - * digest = self.digest(serial_buf, serialize_size, &digest_size) - * - * if has_leading_zero_bits(digest, difficulty): # <<<<<<<<<<<<<< - * nonce_found = True - * nonce_solution = nonce -*/ - __pyx_t_13 = __pyx_f_18polluck_blockchain_18placeholder_native_has_leading_zero_bits(__pyx_v_digest, __pyx_v_difficulty); if (unlikely(__pyx_t_13 == ((int)-1) && __Pyx_ErrOccurredWithGIL())) __PYX_ERR(0, 280, __pyx_L4_error) - if (__pyx_t_13) { - - /* "polluck_blockchain/placeholder_native.pyx":281 - * - * if has_leading_zero_bits(digest, difficulty): - * nonce_found = True # <<<<<<<<<<<<<< - * nonce_solution = nonce - * break -*/ - __pyx_v_nonce_found = 1; - - /* "polluck_blockchain/placeholder_native.pyx":282 - * if has_leading_zero_bits(digest, difficulty): - * nonce_found = True - * nonce_solution = nonce # <<<<<<<<<<<<<< - * break - * -*/ - __pyx_v_nonce_solution = __pyx_v_nonce; - - /* "polluck_blockchain/placeholder_native.pyx":283 - * nonce_found = True - * nonce_solution = nonce - * break # <<<<<<<<<<<<<< - * - * free(digest) -*/ - goto __pyx_L7_break; - - /* "polluck_blockchain/placeholder_native.pyx":280 - * digest = self.digest(serial_buf, serialize_size, &digest_size) - * - * if has_leading_zero_bits(digest, difficulty): # <<<<<<<<<<<<<< - * nonce_found = True - * nonce_solution = nonce -*/ - } - - /* "polluck_blockchain/placeholder_native.pyx":285 - * break - * - * free(digest) # <<<<<<<<<<<<<< - * - * if not nonce_found: -*/ - free(__pyx_v_digest); - } - __pyx_L7_break:; - } - - /* "polluck_blockchain/placeholder_native.pyx":275 - * serial_buf = self.bytes_serialize_c(&serialize_size) - * - * with nogil: # <<<<<<<<<<<<<< - * for nonce in range(max_nonce): - * serialize_uint64(serial_buf + NONCE_OFFSET, nonce) -*/ - /*finally:*/ { - /*normal exit:*/{ - __Pyx_FastGIL_Forget(); - PyEval_RestoreThread(_save); - goto __pyx_L5; - } - __pyx_L4_error: { - __Pyx_FastGIL_Forget(); - PyEval_RestoreThread(_save); - goto __pyx_L1_error; - } - __pyx_L5:; - } - } - - /* "polluck_blockchain/placeholder_native.pyx":287 - * free(digest) - * - * if not nonce_found: # <<<<<<<<<<<<<< - * raise RuntimeError("No valid nonce found") - * -*/ - __pyx_t_13 = (!__pyx_v_nonce_found); - if (unlikely(__pyx_t_13)) { - - /* "polluck_blockchain/placeholder_native.pyx":288 - * - * if not nonce_found: - * raise RuntimeError("No valid nonce found") # <<<<<<<<<<<<<< - * - * self.BlockC.nonce = nonce_solution -*/ - __pyx_t_2 = NULL; - __pyx_t_7 = 1; - { - PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_mstate_global->__pyx_kp_u_No_valid_nonce_found}; - __pyx_t_1 = __Pyx_PyObject_FastCall((PyObject*)(((PyTypeObject*)PyExc_RuntimeError)), __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 288, __pyx_L1_error) - - /* "polluck_blockchain/placeholder_native.pyx":287 - * free(digest) - * - * if not nonce_found: # <<<<<<<<<<<<<< - * raise RuntimeError("No valid nonce found") - * -*/ - } - - /* "polluck_blockchain/placeholder_native.pyx":290 - * raise RuntimeError("No valid nonce found") - * - * self.BlockC.nonce = nonce_solution # <<<<<<<<<<<<<< - * - * cdef unsigned char* perform_hash_c(self, size_t *digest_size) nogil: -*/ - __pyx_v_self->BlockC->nonce = ((uint64_t)__pyx_v_nonce_solution); - - /* "polluck_blockchain/placeholder_native.pyx":264 - * free(serialize_res) - * - * cpdef mine(self, unsigned int difficulty, unsigned int max_nonce=0xFFFFFFFF): # <<<<<<<<<<<<<< - * cdef: - * unsigned char *serial_buf -*/ - - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("polluck_blockchain.placeholder_native.PyBlock.mine", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} /* Python wrapper */ -static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_13mine(PyObject *__pyx_v_self, +static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_13perform_hash(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ -static PyMethodDef __pyx_mdef_18polluck_blockchain_18placeholder_native_7PyBlock_13mine = {"mine", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_13mine, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; -static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_13mine(PyObject *__pyx_v_self, +static PyMethodDef __pyx_mdef_18polluck_blockchain_18placeholder_native_7PyBlock_13perform_hash = {"perform_hash", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_13perform_hash, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_13perform_hash(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { - unsigned int __pyx_v_difficulty; - unsigned int __pyx_v_max_nonce; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; - PyObject* values[2] = {0,0}; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("mine (wrapper)", 0); + __Pyx_RefNannySetupContext("perform_hash (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); @@ -5967,263 +5393,30 @@ PyObject *__pyx_args, PyObject *__pyx_kwds #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); - { - PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_difficulty,&__pyx_mstate_global->__pyx_n_u_max_nonce,0}; - const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; - if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 264, __pyx_L3_error) - if (__pyx_kwds_len > 0) { - switch (__pyx_nargs) { - case 2: - values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); - if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 264, __pyx_L3_error) - CYTHON_FALLTHROUGH; - case 1: - values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); - if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 264, __pyx_L3_error) - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - const Py_ssize_t kwd_pos_args = __pyx_nargs; - if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "mine", 0) < (0)) __PYX_ERR(0, 264, __pyx_L3_error) - for (Py_ssize_t i = __pyx_nargs; i < 1; i++) { - if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("mine", 0, 1, 2, i); __PYX_ERR(0, 264, __pyx_L3_error) } - } - } else { - switch (__pyx_nargs) { - case 2: - values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); - if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 264, __pyx_L3_error) - CYTHON_FALLTHROUGH; - case 1: - values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); - if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 264, __pyx_L3_error) - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_difficulty = __Pyx_PyLong_As_unsigned_int(values[0]); if (unlikely((__pyx_v_difficulty == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 264, __pyx_L3_error) - if (values[1]) { - __pyx_v_max_nonce = __Pyx_PyLong_As_unsigned_int(values[1]); if (unlikely((__pyx_v_max_nonce == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 264, __pyx_L3_error) - } else { - __pyx_v_max_nonce = ((unsigned int)0xFFFFFFFF); - } - } - goto __pyx_L6_skip; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("mine", 0, 1, 2, __pyx_nargs); __PYX_ERR(0, 264, __pyx_L3_error) - __pyx_L6_skip:; - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { - Py_XDECREF(values[__pyx_temp]); - } - __Pyx_AddTraceback("polluck_blockchain.placeholder_native.PyBlock.mine", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_12mine(((struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *)__pyx_v_self), __pyx_v_difficulty, __pyx_v_max_nonce); + if (unlikely(__pyx_nargs > 0)) { __Pyx_RaiseArgtupleInvalid("perform_hash", 1, 0, 0, __pyx_nargs); return NULL; } + const Py_ssize_t __pyx_kwds_len = unlikely(__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; + if (unlikely(__pyx_kwds_len < 0)) return NULL; + if (unlikely(__pyx_kwds_len > 0)) {__Pyx_RejectKeywords("perform_hash", __pyx_kwds); return NULL;} + __pyx_r = __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_12perform_hash(((struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *)__pyx_v_self)); /* function exit code */ - for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { - Py_XDECREF(values[__pyx_temp]); - } __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_12mine(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self, unsigned int __pyx_v_difficulty, unsigned int __pyx_v_max_nonce) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - struct __pyx_opt_args_18polluck_blockchain_18placeholder_native_7PyBlock_mine __pyx_t_2; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("mine", 0); - __Pyx_XDECREF(__pyx_r); - __pyx_t_2.__pyx_n = 1; - __pyx_t_2.max_nonce = __pyx_v_max_nonce; - __pyx_t_1 = __pyx_vtabptr_18polluck_blockchain_18placeholder_native_PyBlock->mine(__pyx_v_self, __pyx_v_difficulty, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("polluck_blockchain.placeholder_native.PyBlock.mine", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "polluck_blockchain/placeholder_native.pyx":292 - * self.BlockC.nonce = nonce_solution - * - * cdef unsigned char* perform_hash_c(self, size_t *digest_size) nogil: # <<<<<<<<<<<<<< - * cdef: - * unsigned char *serialize_res -*/ - -static unsigned char *__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_perform_hash_c(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self, size_t *__pyx_v_digest_size) { - unsigned char *__pyx_v_serialize_res; - size_t __pyx_v_serialize_size; - unsigned char *__pyx_v_digest; - unsigned char *__pyx_r; - unsigned char *__pyx_t_1; - int __pyx_t_2; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - PyGILState_STATE __pyx_gilstate_save; - - /* "polluck_blockchain/placeholder_native.pyx":298 - * unsigned char *digest - * - * serialize_res = self.bytes_serialize_c(&serialize_size) # <<<<<<<<<<<<<< - * if serialize_res == NULL: - * return NULL -*/ - __pyx_t_1 = ((struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_PyBlock *)__pyx_v_self->__pyx_vtab)->bytes_serialize_c(__pyx_v_self, (&__pyx_v_serialize_size)); if (unlikely(__Pyx_ErrOccurredWithGIL())) __PYX_ERR(0, 298, __pyx_L1_error) - __pyx_v_serialize_res = __pyx_t_1; - - /* "polluck_blockchain/placeholder_native.pyx":299 - * - * serialize_res = self.bytes_serialize_c(&serialize_size) - * if serialize_res == NULL: # <<<<<<<<<<<<<< - * return NULL - * digest = self.digest(serialize_res, serialize_size, digest_size) -*/ - __pyx_t_2 = (__pyx_v_serialize_res == NULL); - if (__pyx_t_2) { - - /* "polluck_blockchain/placeholder_native.pyx":300 - * serialize_res = self.bytes_serialize_c(&serialize_size) - * if serialize_res == NULL: - * return NULL # <<<<<<<<<<<<<< - * digest = self.digest(serialize_res, serialize_size, digest_size) - * if digest == NULL: -*/ - __pyx_r = NULL; - goto __pyx_L0; - - /* "polluck_blockchain/placeholder_native.pyx":299 - * - * serialize_res = self.bytes_serialize_c(&serialize_size) - * if serialize_res == NULL: # <<<<<<<<<<<<<< - * return NULL - * digest = self.digest(serialize_res, serialize_size, digest_size) -*/ - } - - /* "polluck_blockchain/placeholder_native.pyx":301 - * if serialize_res == NULL: - * return NULL - * digest = self.digest(serialize_res, serialize_size, digest_size) # <<<<<<<<<<<<<< - * if digest == NULL: - * return NULL -*/ - __pyx_t_1 = ((struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_PyBlock *)__pyx_v_self->__pyx_vtab)->digest(__pyx_v_self, __pyx_v_serialize_res, __pyx_v_serialize_size, __pyx_v_digest_size); if (unlikely(__Pyx_ErrOccurredWithGIL())) __PYX_ERR(0, 301, __pyx_L1_error) - __pyx_v_digest = __pyx_t_1; - - /* "polluck_blockchain/placeholder_native.pyx":302 - * return NULL - * digest = self.digest(serialize_res, serialize_size, digest_size) - * if digest == NULL: # <<<<<<<<<<<<<< - * return NULL - * -*/ - __pyx_t_2 = (__pyx_v_digest == NULL); - if (__pyx_t_2) { - - /* "polluck_blockchain/placeholder_native.pyx":303 - * digest = self.digest(serialize_res, serialize_size, digest_size) - * if digest == NULL: - * return NULL # <<<<<<<<<<<<<< - * - * free(serialize_res) -*/ - __pyx_r = NULL; - goto __pyx_L0; - - /* "polluck_blockchain/placeholder_native.pyx":302 - * return NULL - * digest = self.digest(serialize_res, serialize_size, digest_size) - * if digest == NULL: # <<<<<<<<<<<<<< - * return NULL - * -*/ - } - - /* "polluck_blockchain/placeholder_native.pyx":305 - * return NULL - * - * free(serialize_res) # <<<<<<<<<<<<<< - * - * return digest -*/ - free(__pyx_v_serialize_res); - - /* "polluck_blockchain/placeholder_native.pyx":307 - * free(serialize_res) - * - * return digest # <<<<<<<<<<<<<< - * - * cpdef perform_hash(self): -*/ - __pyx_r = __pyx_v_digest; - goto __pyx_L0; - - /* "polluck_blockchain/placeholder_native.pyx":292 - * self.BlockC.nonce = nonce_solution - * - * cdef unsigned char* perform_hash_c(self, size_t *digest_size) nogil: # <<<<<<<<<<<<<< - * cdef: - * unsigned char *serialize_res -*/ - - /* function exit code */ - __pyx_L1_error:; - __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); - __Pyx_AddTraceback("polluck_blockchain.placeholder_native.PyBlock.perform_hash_c", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __Pyx_PyGILState_Release(__pyx_gilstate_save); - __pyx_L0:; - return __pyx_r; -} - -/* "polluck_blockchain/placeholder_native.pyx":309 - * return digest - * - * cpdef perform_hash(self): # <<<<<<<<<<<<<< - * cdef: - * unsigned char *digest -*/ - -static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_15perform_hash(PyObject *__pyx_v_self, -#if CYTHON_METH_FASTCALL -PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds -#else -PyObject *__pyx_args, PyObject *__pyx_kwds -#endif -); /*proto*/ -static PyObject *__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_perform_hash(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self, int __pyx_skip_dispatch) { +static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_12perform_hash(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self) { unsigned char *__pyx_v_digest; size_t __pyx_v_digest_size; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; + unsigned char *__pyx_t_1; + int __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - size_t __pyx_t_5; - unsigned char *__pyx_t_6; - int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + size_t __pyx_t_8; std::string __pyx_t_9; int __pyx_t_10; int __pyx_t_11; @@ -6238,157 +5431,97 @@ static PyObject *__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_perf const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("perform_hash", 0); - /* Check if called by wrapper */ - if (unlikely(__pyx_skip_dispatch)) ; - /* Check if overridden in Python */ - else if ( - #if !CYTHON_USE_TYPE_SLOTS - unlikely(Py_TYPE(((PyObject *)__pyx_v_self)) != __pyx_mstate_global->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock && - __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), Py_TPFLAGS_HAVE_GC)) - #else - unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0 || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE))) - #endif - ) { - #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS - static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT; - if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) { - PY_UINT64_T __pyx_typedict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); - #endif - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_perform_hash); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 309, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!__Pyx_IsSameCFunction(__pyx_t_1, (void(*)(void)) __pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_15perform_hash)) { - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = NULL; - __Pyx_INCREF(__pyx_t_1); - __pyx_t_4 = __pyx_t_1; - __pyx_t_5 = 1; - #if CYTHON_UNPACK_METHODS - if (unlikely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); - assert(__pyx_t_3); - PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx__function); - __Pyx_DECREF_SET(__pyx_t_4, __pyx__function); - __pyx_t_5 = 0; - } - #endif - { - PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; - __pyx_t_2 = __Pyx_PyObject_FastCall((PyObject*)__pyx_t_4, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 309, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - } - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; - } - #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS - __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); - __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self)); - if (unlikely(__pyx_typedict_guard != __pyx_tp_dict_version)) { - __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT; - } - #endif - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS - } - #endif - } - /* "polluck_blockchain/placeholder_native.pyx":314 + /* "polluck_blockchain/placeholder_native.pyx":182 * size_t digest_size * * try: # <<<<<<<<<<<<<< - * digest = self.perform_hash_c(&digest_size) + * digest = perform_hash_c(self.BlockC, &digest_size) * if digest == NULL: */ /*try:*/ { - /* "polluck_blockchain/placeholder_native.pyx":315 + /* "polluck_blockchain/placeholder_native.pyx":183 * * try: - * digest = self.perform_hash_c(&digest_size) # <<<<<<<<<<<<<< + * digest = perform_hash_c(self.BlockC, &digest_size) # <<<<<<<<<<<<<< * if digest == NULL: * raise MemoryError() */ - __pyx_t_6 = ((struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_PyBlock *)__pyx_v_self->__pyx_vtab)->perform_hash_c(__pyx_v_self, (&__pyx_v_digest_size)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 315, __pyx_L4_error) - __pyx_v_digest = __pyx_t_6; + __pyx_t_1 = __pyx_f_18polluck_blockchain_18placeholder_native_perform_hash_c(__pyx_v_self->BlockC, (&__pyx_v_digest_size)); if (unlikely(__pyx_t_1 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 183, __pyx_L4_error) + __pyx_v_digest = __pyx_t_1; - /* "polluck_blockchain/placeholder_native.pyx":316 + /* "polluck_blockchain/placeholder_native.pyx":184 * try: - * digest = self.perform_hash_c(&digest_size) + * digest = perform_hash_c(self.BlockC, &digest_size) * if digest == NULL: # <<<<<<<<<<<<<< * raise MemoryError() - * self.BlockC.hash = bytes(digest[:digest_size]).hex().encode("UTF-8") + * # TODO out: hash assignment in blockchain */ - __pyx_t_7 = (__pyx_v_digest == NULL); - if (unlikely(__pyx_t_7)) { + __pyx_t_2 = (__pyx_v_digest == NULL); + if (unlikely(__pyx_t_2)) { - /* "polluck_blockchain/placeholder_native.pyx":317 - * digest = self.perform_hash_c(&digest_size) + /* "polluck_blockchain/placeholder_native.pyx":185 + * digest = perform_hash_c(self.BlockC, &digest_size) * if digest == NULL: * raise MemoryError() # <<<<<<<<<<<<<< + * # TODO out: hash assignment in blockchain * self.BlockC.hash = bytes(digest[:digest_size]).hex().encode("UTF-8") - * finally: */ - PyErr_NoMemory(); __PYX_ERR(0, 317, __pyx_L4_error) + PyErr_NoMemory(); __PYX_ERR(0, 185, __pyx_L4_error) - /* "polluck_blockchain/placeholder_native.pyx":316 + /* "polluck_blockchain/placeholder_native.pyx":184 * try: - * digest = self.perform_hash_c(&digest_size) + * digest = perform_hash_c(self.BlockC, &digest_size) * if digest == NULL: # <<<<<<<<<<<<<< * raise MemoryError() - * self.BlockC.hash = bytes(digest[:digest_size]).hex().encode("UTF-8") + * # TODO out: hash assignment in blockchain */ } - /* "polluck_blockchain/placeholder_native.pyx":318 - * if digest == NULL: + /* "polluck_blockchain/placeholder_native.pyx":187 * raise MemoryError() + * # TODO out: hash assignment in blockchain * self.BlockC.hash = bytes(digest[:digest_size]).hex().encode("UTF-8") # <<<<<<<<<<<<<< * finally: * free(digest) */ - __pyx_t_3 = NULL; - __pyx_t_8 = __Pyx_PyBytes_FromStringAndSize(((char const *)__pyx_v_digest) + 0, __pyx_v_digest_size - 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 318, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 = 1; + __pyx_t_6 = NULL; + __pyx_t_7 = __Pyx_PyBytes_FromStringAndSize(((char const *)__pyx_v_digest) + 0, __pyx_v_digest_size - 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 187, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = 1; { - PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_8}; - __pyx_t_4 = __Pyx_PyObject_FastCall((PyObject*)(&PyBytes_Type), __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 318, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_4); + PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_t_7}; + __pyx_t_5 = __Pyx_PyObject_FastCall((PyObject*)(&PyBytes_Type), __pyx_callargs+__pyx_t_8, (2-__pyx_t_8) | (__pyx_t_8*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 187, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_5); } - __pyx_t_2 = __pyx_t_4; - __Pyx_INCREF(__pyx_t_2); - __pyx_t_5 = 0; + __pyx_t_4 = __pyx_t_5; + __Pyx_INCREF(__pyx_t_4); + __pyx_t_8 = 0; { - PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL}; - __pyx_t_1 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_hex, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 318, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_1); + PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL}; + __pyx_t_3 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_hex, __pyx_callargs+__pyx_t_8, (1-__pyx_t_8) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 187, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_3); } - __pyx_t_4 = PyUnicode_AsUTF8String(((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 318, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_9 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_t_4); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 318, __pyx_L4_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_5 = PyUnicode_AsUTF8String(((PyObject*)__pyx_t_3)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 187, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_9 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_t_5); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 187, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_self->BlockC->hash = __PYX_STD_MOVE_IF_SUPPORTED(__pyx_t_9); } - /* "polluck_blockchain/placeholder_native.pyx":320 + /* "polluck_blockchain/placeholder_native.pyx":189 * self.BlockC.hash = bytes(digest[:digest_size]).hex().encode("UTF-8") * finally: * free(digest) # <<<<<<<<<<<<<< - * + * # TODO rework * return self.hash */ /*finally:*/ { @@ -6401,11 +5534,11 @@ static PyObject *__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_perf __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_ExceptionSwap(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18); if ( unlikely(__Pyx_GetException(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15) < 0)) __Pyx_ErrFetch(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15); __Pyx_XGOTREF(__pyx_t_13); @@ -6433,103 +5566,35 @@ static PyObject *__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_perf __pyx_L5:; } - /* "polluck_blockchain/placeholder_native.pyx":322 + /* "polluck_blockchain/placeholder_native.pyx":191 * free(digest) - * + * # TODO rework * return self.hash # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_hash); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 322, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_hash); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 191, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":309 - * return digest + /* "polluck_blockchain/placeholder_native.pyx":177 * - * cpdef perform_hash(self): # <<<<<<<<<<<<<< + * + * def perform_hash(self): # <<<<<<<<<<<<<< * cdef: * unsigned char *digest */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("polluck_blockchain.placeholder_native.PyBlock.perform_hash", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_15perform_hash(PyObject *__pyx_v_self, -#if CYTHON_METH_FASTCALL -PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds -#else -PyObject *__pyx_args, PyObject *__pyx_kwds -#endif -); /*proto*/ -static PyMethodDef __pyx_mdef_18polluck_blockchain_18placeholder_native_7PyBlock_15perform_hash = {"perform_hash", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_15perform_hash, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; -static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_15perform_hash(PyObject *__pyx_v_self, -#if CYTHON_METH_FASTCALL -PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds -#else -PyObject *__pyx_args, PyObject *__pyx_kwds -#endif -) { - #if !CYTHON_METH_FASTCALL - CYTHON_UNUSED Py_ssize_t __pyx_nargs; - #endif - CYTHON_UNUSED PyObject *const *__pyx_kwvalues; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("perform_hash (wrapper)", 0); - #if !CYTHON_METH_FASTCALL - #if CYTHON_ASSUME_SAFE_SIZE - __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); - #else - __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; - #endif - #endif - __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); - if (unlikely(__pyx_nargs > 0)) { __Pyx_RaiseArgtupleInvalid("perform_hash", 1, 0, 0, __pyx_nargs); return NULL; } - const Py_ssize_t __pyx_kwds_len = unlikely(__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; - if (unlikely(__pyx_kwds_len < 0)) return NULL; - if (unlikely(__pyx_kwds_len > 0)) {__Pyx_RejectKeywords("perform_hash", __pyx_kwds); return NULL;} - __pyx_r = __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_14perform_hash(((struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_14perform_hash(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("perform_hash", 0); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_perform_hash(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 309, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); __Pyx_AddTraceback("polluck_blockchain.placeholder_native.PyBlock.perform_hash", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -6545,15 +5610,15 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_14p */ /* Python wrapper */ -static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_17__reduce_cython__(PyObject *__pyx_v_self, +static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_15__reduce_cython__(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ -static PyMethodDef __pyx_mdef_18polluck_blockchain_18placeholder_native_7PyBlock_17__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_17__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; -static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_17__reduce_cython__(PyObject *__pyx_v_self, +static PyMethodDef __pyx_mdef_18polluck_blockchain_18placeholder_native_7PyBlock_15__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_15__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_15__reduce_cython__(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else @@ -6579,14 +5644,14 @@ PyObject *__pyx_args, PyObject *__pyx_kwds const Py_ssize_t __pyx_kwds_len = unlikely(__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len < 0)) return NULL; if (unlikely(__pyx_kwds_len > 0)) {__Pyx_RejectKeywords("__reduce_cython__", __pyx_kwds); return NULL;} - __pyx_r = __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_16__reduce_cython__(((struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *)__pyx_v_self)); + __pyx_r = __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_14__reduce_cython__(((struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_16__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self) { +static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_14__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; @@ -6626,15 +5691,15 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_16_ */ /* Python wrapper */ -static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_19__setstate_cython__(PyObject *__pyx_v_self, +static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_17__setstate_cython__(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ -static PyMethodDef __pyx_mdef_18polluck_blockchain_18placeholder_native_7PyBlock_19__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_19__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; -static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_19__setstate_cython__(PyObject *__pyx_v_self, +static PyMethodDef __pyx_mdef_18polluck_blockchain_18placeholder_native_7PyBlock_17__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_17__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_17__setstate_cython__(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else @@ -6700,7 +5765,7 @@ PyObject *__pyx_args, PyObject *__pyx_kwds __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_18__setstate_cython__(((struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *)__pyx_v_self), __pyx_v___pyx_state); + __pyx_r = __pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_16__setstate_cython__(((struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *)__pyx_v_self), __pyx_v___pyx_state); /* function exit code */ for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { @@ -6710,7 +5775,7 @@ PyObject *__pyx_args, PyObject *__pyx_kwds return __pyx_r; } -static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_18__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_16__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; @@ -6742,11 +5807,760 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_7PyBlock_18_ return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":345 +/* "polluck_blockchain/placeholder_native.pyx":194 + * + * + * cdef unsigned char* bytes_serialize_c(Block *block, size_t *size) nogil: # <<<<<<<<<<<<<< + * cdef: + * size_t total_len +*/ + +static unsigned char *__pyx_f_18polluck_blockchain_18placeholder_native_bytes_serialize_c(::Block *__pyx_v_block, size_t *__pyx_v_size) { + unsigned char *__pyx_v_buf; + size_t __pyx_v_pos; + unsigned char *__pyx_r; + int __pyx_t_1; + int __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyGILState_STATE __pyx_gilstate_save; + + /* "polluck_blockchain/placeholder_native.pyx":198 + * size_t total_len + * unsigned char* buf + * size_t pos = 0 # <<<<<<<<<<<<<< + * + * # index (8), timestamp (8), nonce (8), data, prev_hash +*/ + __pyx_v_pos = 0; + + /* "polluck_blockchain/placeholder_native.pyx":201 + * + * # index (8), timestamp (8), nonce (8), data, prev_hash + * size[0] = ( # <<<<<<<<<<<<<< + * (8 * 3) + + * block.data.size() + +*/ + (__pyx_v_size[0]) = ((((size_t)0x18) + __pyx_v_block->data.size()) + __pyx_v_block->prev_hash.size()); + + /* "polluck_blockchain/placeholder_native.pyx":206 + * block.prev_hash.size() + * ) + * buf = malloc(size[0] * sizeof(unsigned char)) # <<<<<<<<<<<<<< + * + * if buf == NULL: +*/ + __pyx_v_buf = ((unsigned char *)malloc(((__pyx_v_size[0]) * (sizeof(unsigned char))))); + + /* "polluck_blockchain/placeholder_native.pyx":208 + * buf = malloc(size[0] * sizeof(unsigned char)) + * + * if buf == NULL: # <<<<<<<<<<<<<< + * return NULL + * +*/ + __pyx_t_1 = (__pyx_v_buf == NULL); + if (__pyx_t_1) { + + /* "polluck_blockchain/placeholder_native.pyx":209 + * + * if buf == NULL: + * return NULL # <<<<<<<<<<<<<< + * + * serialize_uint64(buf + pos, block.index) +*/ + __pyx_r = NULL; + goto __pyx_L0; + + /* "polluck_blockchain/placeholder_native.pyx":208 + * buf = malloc(size[0] * sizeof(unsigned char)) + * + * if buf == NULL: # <<<<<<<<<<<<<< + * return NULL + * +*/ + } + + /* "polluck_blockchain/placeholder_native.pyx":211 + * return NULL + * + * serialize_uint64(buf + pos, block.index) # <<<<<<<<<<<<<< + * pos += 8 + * serialize_uint64(buf + pos, block.timestamp) +*/ + __pyx_t_2 = __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint64((__pyx_v_buf + __pyx_v_pos), __pyx_v_block->index); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 211, __pyx_L1_error) + + /* "polluck_blockchain/placeholder_native.pyx":212 + * + * serialize_uint64(buf + pos, block.index) + * pos += 8 # <<<<<<<<<<<<<< + * serialize_uint64(buf + pos, block.timestamp) + * pos += 8 +*/ + __pyx_v_pos = (__pyx_v_pos + 8); + + /* "polluck_blockchain/placeholder_native.pyx":213 + * serialize_uint64(buf + pos, block.index) + * pos += 8 + * serialize_uint64(buf + pos, block.timestamp) # <<<<<<<<<<<<<< + * pos += 8 + * serialize_uint64(buf + pos, block.nonce) +*/ + __pyx_t_2 = __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint64((__pyx_v_buf + __pyx_v_pos), __pyx_v_block->timestamp); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 213, __pyx_L1_error) + + /* "polluck_blockchain/placeholder_native.pyx":214 + * pos += 8 + * serialize_uint64(buf + pos, block.timestamp) + * pos += 8 # <<<<<<<<<<<<<< + * serialize_uint64(buf + pos, block.nonce) + * pos += 8 +*/ + __pyx_v_pos = (__pyx_v_pos + 8); + + /* "polluck_blockchain/placeholder_native.pyx":215 + * serialize_uint64(buf + pos, block.timestamp) + * pos += 8 + * serialize_uint64(buf + pos, block.nonce) # <<<<<<<<<<<<<< + * pos += 8 + * # Copy data +*/ + __pyx_t_2 = __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint64((__pyx_v_buf + __pyx_v_pos), __pyx_v_block->nonce); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 215, __pyx_L1_error) + + /* "polluck_blockchain/placeholder_native.pyx":216 + * pos += 8 + * serialize_uint64(buf + pos, block.nonce) + * pos += 8 # <<<<<<<<<<<<<< + * # Copy data + * memcpy( +*/ + __pyx_v_pos = (__pyx_v_pos + 8); + + /* "polluck_blockchain/placeholder_native.pyx":218 + * pos += 8 + * # Copy data + * memcpy( # <<<<<<<<<<<<<< + * buf + pos, + * block.data.c_str(), +*/ + (void)(memcpy((__pyx_v_buf + __pyx_v_pos), __pyx_v_block->data.c_str(), __pyx_v_block->data.size())); + + /* "polluck_blockchain/placeholder_native.pyx":223 + * block.data.size(), + * ) + * pos += block.data.size() # <<<<<<<<<<<<<< + * # Copy prev_hash + * memcpy( +*/ + __pyx_v_pos = (__pyx_v_pos + __pyx_v_block->data.size()); + + /* "polluck_blockchain/placeholder_native.pyx":225 + * pos += block.data.size() + * # Copy prev_hash + * memcpy( # <<<<<<<<<<<<<< + * buf + pos, + * block.prev_hash.c_str(), +*/ + (void)(memcpy((__pyx_v_buf + __pyx_v_pos), __pyx_v_block->prev_hash.c_str(), __pyx_v_block->prev_hash.size())); + + /* "polluck_blockchain/placeholder_native.pyx":230 + * block.prev_hash.size(), + * ) + * pos += block.prev_hash.size() # <<<<<<<<<<<<<< + * + * return buf +*/ + __pyx_v_pos = (__pyx_v_pos + __pyx_v_block->prev_hash.size()); + + /* "polluck_blockchain/placeholder_native.pyx":232 + * pos += block.prev_hash.size() + * + * return buf # <<<<<<<<<<<<<< + * + * cdef unsigned char* SHA256_digest(const void *data, size_t data_size, size_t *digest_size) nogil: +*/ + __pyx_r = __pyx_v_buf; + goto __pyx_L0; + + /* "polluck_blockchain/placeholder_native.pyx":194 + * + * + * cdef unsigned char* bytes_serialize_c(Block *block, size_t *size) nogil: # <<<<<<<<<<<<<< + * cdef: + * size_t total_len +*/ + + /* function exit code */ + __pyx_L1_error:; + __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + __Pyx_AddTraceback("polluck_blockchain.placeholder_native.bytes_serialize_c", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_PyGILState_Release(__pyx_gilstate_save); + __pyx_L0:; + return __pyx_r; +} + +/* "polluck_blockchain/placeholder_native.pyx":234 + * return buf + * + * cdef unsigned char* SHA256_digest(const void *data, size_t data_size, size_t *digest_size) nogil: # <<<<<<<<<<<<<< + * cdef ossl.EVP_MD_CTX *ctx = ossl.EVP_MD_CTX_new() + * if ctx == NULL: +*/ + +static unsigned char *__pyx_f_18polluck_blockchain_18placeholder_native_SHA256_digest(void const *__pyx_v_data, size_t __pyx_v_data_size, size_t *__pyx_v_digest_size) { + EVP_MD_CTX *__pyx_v_ctx; + EVP_MD const *__pyx_v_algo; + unsigned char *__pyx_v_digest; + size_t __pyx_v_dig_buff_len; + unsigned int __pyx_v_digest_len; + unsigned char *__pyx_r; + int __pyx_t_1; + + /* "polluck_blockchain/placeholder_native.pyx":235 + * + * cdef unsigned char* SHA256_digest(const void *data, size_t data_size, size_t *digest_size) nogil: + * cdef ossl.EVP_MD_CTX *ctx = ossl.EVP_MD_CTX_new() # <<<<<<<<<<<<<< + * if ctx == NULL: + * return NULL +*/ + __pyx_v_ctx = EVP_MD_CTX_new(); + + /* "polluck_blockchain/placeholder_native.pyx":236 + * cdef unsigned char* SHA256_digest(const void *data, size_t data_size, size_t *digest_size) nogil: + * cdef ossl.EVP_MD_CTX *ctx = ossl.EVP_MD_CTX_new() + * if ctx == NULL: # <<<<<<<<<<<<<< + * return NULL + * cdef const ossl.EVP_MD *algo = ossl.EVP_sha256() +*/ + __pyx_t_1 = (__pyx_v_ctx == NULL); + if (__pyx_t_1) { + + /* "polluck_blockchain/placeholder_native.pyx":237 + * cdef ossl.EVP_MD_CTX *ctx = ossl.EVP_MD_CTX_new() + * if ctx == NULL: + * return NULL # <<<<<<<<<<<<<< + * cdef const ossl.EVP_MD *algo = ossl.EVP_sha256() + * if algo == NULL: +*/ + __pyx_r = NULL; + goto __pyx_L0; + + /* "polluck_blockchain/placeholder_native.pyx":236 + * cdef unsigned char* SHA256_digest(const void *data, size_t data_size, size_t *digest_size) nogil: + * cdef ossl.EVP_MD_CTX *ctx = ossl.EVP_MD_CTX_new() + * if ctx == NULL: # <<<<<<<<<<<<<< + * return NULL + * cdef const ossl.EVP_MD *algo = ossl.EVP_sha256() +*/ + } + + /* "polluck_blockchain/placeholder_native.pyx":238 + * if ctx == NULL: + * return NULL + * cdef const ossl.EVP_MD *algo = ossl.EVP_sha256() # <<<<<<<<<<<<<< + * if algo == NULL: + * return NULL +*/ + __pyx_v_algo = EVP_sha256(); + + /* "polluck_blockchain/placeholder_native.pyx":239 + * return NULL + * cdef const ossl.EVP_MD *algo = ossl.EVP_sha256() + * if algo == NULL: # <<<<<<<<<<<<<< + * return NULL + * +*/ + __pyx_t_1 = (__pyx_v_algo == NULL); + if (__pyx_t_1) { + + /* "polluck_blockchain/placeholder_native.pyx":240 + * cdef const ossl.EVP_MD *algo = ossl.EVP_sha256() + * if algo == NULL: + * return NULL # <<<<<<<<<<<<<< + * + * cdef: +*/ + __pyx_r = NULL; + goto __pyx_L0; + + /* "polluck_blockchain/placeholder_native.pyx":239 + * return NULL + * cdef const ossl.EVP_MD *algo = ossl.EVP_sha256() + * if algo == NULL: # <<<<<<<<<<<<<< + * return NULL + * +*/ + } + + /* "polluck_blockchain/placeholder_native.pyx":247 + * unsigned int digest_len + * + * dig_buff_len = ossl.EVP_MD_size(algo) # <<<<<<<<<<<<<< + * digest_size[0] = dig_buff_len + * digest = malloc(dig_buff_len * sizeof(unsigned char)) +*/ + __pyx_v_dig_buff_len = ((size_t)EVP_MD_size(__pyx_v_algo)); + + /* "polluck_blockchain/placeholder_native.pyx":248 + * + * dig_buff_len = ossl.EVP_MD_size(algo) + * digest_size[0] = dig_buff_len # <<<<<<<<<<<<<< + * digest = malloc(dig_buff_len * sizeof(unsigned char)) + * ossl.EVP_DigestInit_ex(ctx, algo, NULL) +*/ + (__pyx_v_digest_size[0]) = __pyx_v_dig_buff_len; + + /* "polluck_blockchain/placeholder_native.pyx":249 + * dig_buff_len = ossl.EVP_MD_size(algo) + * digest_size[0] = dig_buff_len + * digest = malloc(dig_buff_len * sizeof(unsigned char)) # <<<<<<<<<<<<<< + * ossl.EVP_DigestInit_ex(ctx, algo, NULL) + * ossl.EVP_DigestUpdate(ctx, data, data_size) +*/ + __pyx_v_digest = ((unsigned char *)malloc((__pyx_v_dig_buff_len * (sizeof(unsigned char))))); + + /* "polluck_blockchain/placeholder_native.pyx":250 + * digest_size[0] = dig_buff_len + * digest = malloc(dig_buff_len * sizeof(unsigned char)) + * ossl.EVP_DigestInit_ex(ctx, algo, NULL) # <<<<<<<<<<<<<< + * ossl.EVP_DigestUpdate(ctx, data, data_size) + * ossl.EVP_DigestFinal_ex(ctx, digest, &digest_len) +*/ + (void)(EVP_DigestInit_ex(__pyx_v_ctx, __pyx_v_algo, NULL)); + + /* "polluck_blockchain/placeholder_native.pyx":251 + * digest = malloc(dig_buff_len * sizeof(unsigned char)) + * ossl.EVP_DigestInit_ex(ctx, algo, NULL) + * ossl.EVP_DigestUpdate(ctx, data, data_size) # <<<<<<<<<<<<<< + * ossl.EVP_DigestFinal_ex(ctx, digest, &digest_len) + * +*/ + (void)(EVP_DigestUpdate(__pyx_v_ctx, __pyx_v_data, __pyx_v_data_size)); + + /* "polluck_blockchain/placeholder_native.pyx":252 + * ossl.EVP_DigestInit_ex(ctx, algo, NULL) + * ossl.EVP_DigestUpdate(ctx, data, data_size) + * ossl.EVP_DigestFinal_ex(ctx, digest, &digest_len) # <<<<<<<<<<<<<< + * + * ossl.EVP_MD_CTX_free(ctx) +*/ + (void)(EVP_DigestFinal_ex(__pyx_v_ctx, __pyx_v_digest, (&__pyx_v_digest_len))); + + /* "polluck_blockchain/placeholder_native.pyx":254 + * ossl.EVP_DigestFinal_ex(ctx, digest, &digest_len) + * + * ossl.EVP_MD_CTX_free(ctx) # <<<<<<<<<<<<<< + * + * return digest +*/ + EVP_MD_CTX_free(__pyx_v_ctx); + + /* "polluck_blockchain/placeholder_native.pyx":256 + * ossl.EVP_MD_CTX_free(ctx) + * + * return digest # <<<<<<<<<<<<<< + * + * +*/ + __pyx_r = __pyx_v_digest; + goto __pyx_L0; + + /* "polluck_blockchain/placeholder_native.pyx":234 + * return buf + * + * cdef unsigned char* SHA256_digest(const void *data, size_t data_size, size_t *digest_size) nogil: # <<<<<<<<<<<<<< + * cdef ossl.EVP_MD_CTX *ctx = ossl.EVP_MD_CTX_new() + * if ctx == NULL: +*/ + + /* function exit code */ + __pyx_L0:; + return __pyx_r; +} + +/* "polluck_blockchain/placeholder_native.pyx":259 + * + * + * cdef unsigned char* perform_hash_c(Block *block, size_t *digest_size) nogil: # <<<<<<<<<<<<<< + * cdef: + * unsigned char *serialize_res +*/ + +static unsigned char *__pyx_f_18polluck_blockchain_18placeholder_native_perform_hash_c(::Block *__pyx_v_block, size_t *__pyx_v_digest_size) { + unsigned char *__pyx_v_serialize_res; + size_t __pyx_v_serialize_size; + unsigned char *__pyx_v_digest; + unsigned char *__pyx_r; + unsigned char *__pyx_t_1; + int __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyGILState_STATE __pyx_gilstate_save; + + /* "polluck_blockchain/placeholder_native.pyx":265 + * unsigned char *digest + * + * serialize_res = bytes_serialize_c(block, &serialize_size) # <<<<<<<<<<<<<< + * if serialize_res == NULL: + * return NULL +*/ + __pyx_t_1 = __pyx_f_18polluck_blockchain_18placeholder_native_bytes_serialize_c(__pyx_v_block, (&__pyx_v_serialize_size)); if (unlikely(__pyx_t_1 == ((void *)NULL) && __Pyx_ErrOccurredWithGIL())) __PYX_ERR(0, 265, __pyx_L1_error) + __pyx_v_serialize_res = __pyx_t_1; + + /* "polluck_blockchain/placeholder_native.pyx":266 + * + * serialize_res = bytes_serialize_c(block, &serialize_size) + * if serialize_res == NULL: # <<<<<<<<<<<<<< + * return NULL + * digest = SHA256_digest(serialize_res, serialize_size, digest_size) +*/ + __pyx_t_2 = (__pyx_v_serialize_res == NULL); + if (__pyx_t_2) { + + /* "polluck_blockchain/placeholder_native.pyx":267 + * serialize_res = bytes_serialize_c(block, &serialize_size) + * if serialize_res == NULL: + * return NULL # <<<<<<<<<<<<<< + * digest = SHA256_digest(serialize_res, serialize_size, digest_size) + * free(serialize_res) +*/ + __pyx_r = NULL; + goto __pyx_L0; + + /* "polluck_blockchain/placeholder_native.pyx":266 + * + * serialize_res = bytes_serialize_c(block, &serialize_size) + * if serialize_res == NULL: # <<<<<<<<<<<<<< + * return NULL + * digest = SHA256_digest(serialize_res, serialize_size, digest_size) +*/ + } + + /* "polluck_blockchain/placeholder_native.pyx":268 + * if serialize_res == NULL: + * return NULL + * digest = SHA256_digest(serialize_res, serialize_size, digest_size) # <<<<<<<<<<<<<< + * free(serialize_res) + * if digest == NULL: +*/ + __pyx_t_1 = __pyx_f_18polluck_blockchain_18placeholder_native_SHA256_digest(__pyx_v_serialize_res, __pyx_v_serialize_size, __pyx_v_digest_size); if (unlikely(__pyx_t_1 == ((void *)NULL) && __Pyx_ErrOccurredWithGIL())) __PYX_ERR(0, 268, __pyx_L1_error) + __pyx_v_digest = __pyx_t_1; + + /* "polluck_blockchain/placeholder_native.pyx":269 + * return NULL + * digest = SHA256_digest(serialize_res, serialize_size, digest_size) + * free(serialize_res) # <<<<<<<<<<<<<< + * if digest == NULL: + * return NULL +*/ + free(__pyx_v_serialize_res); + + /* "polluck_blockchain/placeholder_native.pyx":270 + * digest = SHA256_digest(serialize_res, serialize_size, digest_size) + * free(serialize_res) + * if digest == NULL: # <<<<<<<<<<<<<< + * return NULL + * +*/ + __pyx_t_2 = (__pyx_v_digest == NULL); + if (__pyx_t_2) { + + /* "polluck_blockchain/placeholder_native.pyx":271 + * free(serialize_res) + * if digest == NULL: + * return NULL # <<<<<<<<<<<<<< + * + * return digest +*/ + __pyx_r = NULL; + goto __pyx_L0; + + /* "polluck_blockchain/placeholder_native.pyx":270 + * digest = SHA256_digest(serialize_res, serialize_size, digest_size) + * free(serialize_res) + * if digest == NULL: # <<<<<<<<<<<<<< + * return NULL + * +*/ + } + + /* "polluck_blockchain/placeholder_native.pyx":273 + * return NULL + * + * return digest # <<<<<<<<<<<<<< + * + * +*/ + __pyx_r = __pyx_v_digest; + goto __pyx_L0; + + /* "polluck_blockchain/placeholder_native.pyx":259 + * + * + * cdef unsigned char* perform_hash_c(Block *block, size_t *digest_size) nogil: # <<<<<<<<<<<<<< + * cdef: + * unsigned char *serialize_res +*/ + + /* function exit code */ + __pyx_L1_error:; + __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + __Pyx_AddTraceback("polluck_blockchain.placeholder_native.perform_hash_c", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_PyGILState_Release(__pyx_gilstate_save); + __pyx_L0:; + return __pyx_r; +} + +/* "polluck_blockchain/placeholder_native.pyx":276 + * + * + * cdef int mine_block(Block *block, unsigned int difficulty, uint64_t *nonce_solution, unsigned int max_nonce=0xFFFFFFFF) nogil: # <<<<<<<<<<<<<< + * cdef: + * unsigned char *serial_buf +*/ + +static int __pyx_f_18polluck_blockchain_18placeholder_native_mine_block(::Block *__pyx_v_block, unsigned int __pyx_v_difficulty, uint64_t *__pyx_v_nonce_solution, struct __pyx_opt_args_18polluck_blockchain_18placeholder_native_mine_block *__pyx_optional_args) { + unsigned int __pyx_v_max_nonce = ((unsigned int)0xFFFFFFFF); + unsigned char *__pyx_v_serial_buf; + size_t __pyx_v_serialize_size; + unsigned char *__pyx_v_digest; + size_t __pyx_v_digest_size; + int __pyx_v_nonce_found; + int __pyx_v_nonce; + int __pyx_r; + unsigned char *__pyx_t_1; + unsigned int __pyx_t_2; + unsigned int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyGILState_STATE __pyx_gilstate_save; + if (__pyx_optional_args) { + if (__pyx_optional_args->__pyx_n > 0) { + __pyx_v_max_nonce = __pyx_optional_args->max_nonce; + } + } + + /* "polluck_blockchain/placeholder_native.pyx":282 + * unsigned char *digest + * size_t digest_size + * bint nonce_found = False # <<<<<<<<<<<<<< + * int nonce + * +*/ + __pyx_v_nonce_found = 0; + + /* "polluck_blockchain/placeholder_native.pyx":285 + * int nonce + * + * serial_buf = bytes_serialize_c(block, &serialize_size) # <<<<<<<<<<<<<< + * + * with nogil: +*/ + __pyx_t_1 = __pyx_f_18polluck_blockchain_18placeholder_native_bytes_serialize_c(__pyx_v_block, (&__pyx_v_serialize_size)); if (unlikely(__pyx_t_1 == ((void *)NULL) && __Pyx_ErrOccurredWithGIL())) __PYX_ERR(0, 285, __pyx_L1_error) + __pyx_v_serial_buf = __pyx_t_1; + + /* "polluck_blockchain/placeholder_native.pyx":287 + * serial_buf = bytes_serialize_c(block, &serialize_size) + * + * with nogil: # <<<<<<<<<<<<<< + * for nonce in range(max_nonce): + * serialize_uint64(serial_buf + NONCE_OFFSET, nonce) +*/ + { + __Pyx_UnknownThreadState _save; + _save = __Pyx_SaveUnknownThread(); + __Pyx_FastGIL_Remember(); + /*try:*/ { + + /* "polluck_blockchain/placeholder_native.pyx":288 + * + * with nogil: + * for nonce in range(max_nonce): # <<<<<<<<<<<<<< + * serialize_uint64(serial_buf + NONCE_OFFSET, nonce) + * digest = SHA256_digest(serial_buf, serialize_size, &digest_size) +*/ + __pyx_t_2 = __pyx_v_max_nonce; + __pyx_t_3 = __pyx_t_2; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_nonce = __pyx_t_4; + + /* "polluck_blockchain/placeholder_native.pyx":289 + * with nogil: + * for nonce in range(max_nonce): + * serialize_uint64(serial_buf + NONCE_OFFSET, nonce) # <<<<<<<<<<<<<< + * digest = SHA256_digest(serial_buf, serialize_size, &digest_size) + * +*/ + __pyx_t_5 = __pyx_f_18polluck_blockchain_18placeholder_native_serialize_uint64((__pyx_v_serial_buf + __pyx_v_18polluck_blockchain_18placeholder_native_NONCE_OFFSET), ((uint64_t)__pyx_v_nonce)); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 289, __pyx_L4_error) + + /* "polluck_blockchain/placeholder_native.pyx":290 + * for nonce in range(max_nonce): + * serialize_uint64(serial_buf + NONCE_OFFSET, nonce) + * digest = SHA256_digest(serial_buf, serialize_size, &digest_size) # <<<<<<<<<<<<<< + * + * if has_leading_zero_bits(digest, difficulty): +*/ + __pyx_t_1 = __pyx_f_18polluck_blockchain_18placeholder_native_SHA256_digest(__pyx_v_serial_buf, __pyx_v_serialize_size, (&__pyx_v_digest_size)); if (unlikely(__pyx_t_1 == ((void *)NULL) && __Pyx_ErrOccurredWithGIL())) __PYX_ERR(0, 290, __pyx_L4_error) + __pyx_v_digest = __pyx_t_1; + + /* "polluck_blockchain/placeholder_native.pyx":292 + * digest = SHA256_digest(serial_buf, serialize_size, &digest_size) + * + * if has_leading_zero_bits(digest, difficulty): # <<<<<<<<<<<<<< + * nonce_found = True + * nonce_solution[0] = nonce +*/ + __pyx_t_6 = __pyx_f_18polluck_blockchain_18placeholder_native_has_leading_zero_bits(__pyx_v_digest, __pyx_v_difficulty); if (unlikely(__pyx_t_6 == ((int)-1) && __Pyx_ErrOccurredWithGIL())) __PYX_ERR(0, 292, __pyx_L4_error) + if (__pyx_t_6) { + + /* "polluck_blockchain/placeholder_native.pyx":293 + * + * if has_leading_zero_bits(digest, difficulty): + * nonce_found = True # <<<<<<<<<<<<<< + * nonce_solution[0] = nonce + * break +*/ + __pyx_v_nonce_found = 1; + + /* "polluck_blockchain/placeholder_native.pyx":294 + * if has_leading_zero_bits(digest, difficulty): + * nonce_found = True + * nonce_solution[0] = nonce # <<<<<<<<<<<<<< + * break + * +*/ + (__pyx_v_nonce_solution[0]) = __pyx_v_nonce; + + /* "polluck_blockchain/placeholder_native.pyx":295 + * nonce_found = True + * nonce_solution[0] = nonce + * break # <<<<<<<<<<<<<< + * + * free(digest) +*/ + goto __pyx_L7_break; + + /* "polluck_blockchain/placeholder_native.pyx":292 + * digest = SHA256_digest(serial_buf, serialize_size, &digest_size) + * + * if has_leading_zero_bits(digest, difficulty): # <<<<<<<<<<<<<< + * nonce_found = True + * nonce_solution[0] = nonce +*/ + } + + /* "polluck_blockchain/placeholder_native.pyx":297 + * break + * + * free(digest) # <<<<<<<<<<<<<< + * + * free(serial_buf) +*/ + free(__pyx_v_digest); + } + __pyx_L7_break:; + } + + /* "polluck_blockchain/placeholder_native.pyx":287 + * serial_buf = bytes_serialize_c(block, &serialize_size) + * + * with nogil: # <<<<<<<<<<<<<< + * for nonce in range(max_nonce): + * serialize_uint64(serial_buf + NONCE_OFFSET, nonce) +*/ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_FastGIL_Forget(); + __Pyx_RestoreUnknownThread(_save); + goto __pyx_L5; + } + __pyx_L4_error: { + __Pyx_FastGIL_Forget(); + __Pyx_RestoreUnknownThread(_save); + goto __pyx_L1_error; + } + __pyx_L5:; + } + } + + /* "polluck_blockchain/placeholder_native.pyx":299 + * free(digest) + * + * free(serial_buf) # <<<<<<<<<<<<<< + * + * if not nonce_found: +*/ + free(__pyx_v_serial_buf); + + /* "polluck_blockchain/placeholder_native.pyx":301 + * free(serial_buf) + * + * if not nonce_found: # <<<<<<<<<<<<<< + * return 1 + * +*/ + __pyx_t_6 = (!__pyx_v_nonce_found); + if (__pyx_t_6) { + + /* "polluck_blockchain/placeholder_native.pyx":302 + * + * if not nonce_found: + * return 1 # <<<<<<<<<<<<<< + * + * return 0 +*/ + __pyx_r = 1; + goto __pyx_L0; + + /* "polluck_blockchain/placeholder_native.pyx":301 + * free(serial_buf) + * + * if not nonce_found: # <<<<<<<<<<<<<< + * return 1 + * +*/ + } + + /* "polluck_blockchain/placeholder_native.pyx":304 + * return 1 + * + * return 0 # <<<<<<<<<<<<<< + * + * +*/ + __pyx_r = 0; + goto __pyx_L0; + + /* "polluck_blockchain/placeholder_native.pyx":276 + * + * + * cdef int mine_block(Block *block, unsigned int difficulty, uint64_t *nonce_solution, unsigned int max_nonce=0xFFFFFFFF) nogil: # <<<<<<<<<<<<<< + * cdef: + * unsigned char *serial_buf +*/ + + /* function exit code */ + __pyx_L1_error:; + __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + __Pyx_AddTraceback("polluck_blockchain.placeholder_native.mine_block", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __Pyx_PyGILState_Release(__pyx_gilstate_save); + __pyx_L0:; + return __pyx_r; +} + +/* "polluck_blockchain/placeholder_native.pyx":313 * cdef bint _genesis_done * * def __cinit__(self): # <<<<<<<<<<<<<< - * self._difficulty = 1 + * self._difficulty = 26 * self._index = 0 */ @@ -6788,26 +6602,26 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain___cin int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); - /* "polluck_blockchain/placeholder_native.pyx":346 + /* "polluck_blockchain/placeholder_native.pyx":314 * * def __cinit__(self): - * self._difficulty = 1 # <<<<<<<<<<<<<< + * self._difficulty = 26 # <<<<<<<<<<<<<< * self._index = 0 * self._genesis_done = 0 */ - __pyx_v_self->_difficulty = 1; + __pyx_v_self->_difficulty = 26; - /* "polluck_blockchain/placeholder_native.pyx":347 + /* "polluck_blockchain/placeholder_native.pyx":315 * def __cinit__(self): - * self._difficulty = 1 + * self._difficulty = 26 * self._index = 0 # <<<<<<<<<<<<<< * self._genesis_done = 0 * self._chain = new unordered_map[uint64_t, Block*]() */ __pyx_v_self->_index = ((uint64_t)0); - /* "polluck_blockchain/placeholder_native.pyx":348 - * self._difficulty = 1 + /* "polluck_blockchain/placeholder_native.pyx":316 + * self._difficulty = 26 * self._index = 0 * self._genesis_done = 0 # <<<<<<<<<<<<<< * self._chain = new unordered_map[uint64_t, Block*]() @@ -6815,7 +6629,7 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain___cin */ __pyx_v_self->_genesis_done = 0; - /* "polluck_blockchain/placeholder_native.pyx":349 + /* "polluck_blockchain/placeholder_native.pyx":317 * self._index = 0 * self._genesis_done = 0 * self._chain = new unordered_map[uint64_t, Block*]() # <<<<<<<<<<<<<< @@ -6826,11 +6640,11 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain___cin __pyx_t_1 = new std::unordered_map (); } catch(...) { __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 349, __pyx_L1_error) + __PYX_ERR(0, 317, __pyx_L1_error) } __pyx_v_self->_chain = __pyx_t_1; - /* "polluck_blockchain/placeholder_native.pyx":350 + /* "polluck_blockchain/placeholder_native.pyx":318 * self._genesis_done = 0 * self._chain = new unordered_map[uint64_t, Block*]() * if self._chain is NULL: # <<<<<<<<<<<<<< @@ -6840,7 +6654,7 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain___cin __pyx_t_2 = (__pyx_v_self->_chain == NULL); if (unlikely(__pyx_t_2)) { - /* "polluck_blockchain/placeholder_native.pyx":351 + /* "polluck_blockchain/placeholder_native.pyx":319 * self._chain = new unordered_map[uint64_t, Block*]() * if self._chain is NULL: * raise MemoryError("Could not allocate hasmap") # <<<<<<<<<<<<<< @@ -6853,14 +6667,14 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain___cin PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_mstate_global->__pyx_kp_u_Could_not_allocate_hasmap}; __pyx_t_3 = __Pyx_PyObject_FastCall((PyObject*)(((PyTypeObject*)PyExc_MemoryError)), __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 351, __pyx_L1_error) + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 319, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 351, __pyx_L1_error) + __PYX_ERR(0, 319, __pyx_L1_error) - /* "polluck_blockchain/placeholder_native.pyx":350 + /* "polluck_blockchain/placeholder_native.pyx":318 * self._genesis_done = 0 * self._chain = new unordered_map[uint64_t, Block*]() * if self._chain is NULL: # <<<<<<<<<<<<<< @@ -6869,11 +6683,11 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain___cin */ } - /* "polluck_blockchain/placeholder_native.pyx":345 + /* "polluck_blockchain/placeholder_native.pyx":313 * cdef bint _genesis_done * * def __cinit__(self): # <<<<<<<<<<<<<< - * self._difficulty = 1 + * self._difficulty = 26 * self._index = 0 */ @@ -6890,12 +6704,12 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain___cin return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":353 +/* "polluck_blockchain/placeholder_native.pyx":321 * raise MemoryError("Could not allocate hasmap") * * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< + * # self.db_path = db_path * pass - * */ /* Python wrapper */ @@ -6938,7 +6752,7 @@ static int __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_2__in return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":356 +/* "polluck_blockchain/placeholder_native.pyx":325 * pass * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -6963,7 +6777,7 @@ static void __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_4__d std::unordered_map ::iterator __pyx_v_it; int __pyx_t_1; - /* "polluck_blockchain/placeholder_native.pyx":358 + /* "polluck_blockchain/placeholder_native.pyx":327 * def __dealloc__(self): * # ownership is typically not transferred from the Blockchain extension class * cdef BcHashmap.iterator it = self._chain.begin() # <<<<<<<<<<<<<< @@ -6972,7 +6786,7 @@ static void __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_4__d */ __pyx_v_it = __pyx_v_self->_chain->begin(); - /* "polluck_blockchain/placeholder_native.pyx":359 + /* "polluck_blockchain/placeholder_native.pyx":328 * # ownership is typically not transferred from the Blockchain extension class * cdef BcHashmap.iterator it = self._chain.begin() * if self._chain is not NULL: # <<<<<<<<<<<<<< @@ -6982,7 +6796,7 @@ static void __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_4__d __pyx_t_1 = (__pyx_v_self->_chain != NULL); if (__pyx_t_1) { - /* "polluck_blockchain/placeholder_native.pyx":360 + /* "polluck_blockchain/placeholder_native.pyx":329 * cdef BcHashmap.iterator it = self._chain.begin() * if self._chain is not NULL: * while it != self._chain.end(): # <<<<<<<<<<<<<< @@ -6993,7 +6807,7 @@ static void __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_4__d __pyx_t_1 = (__pyx_v_it != __pyx_v_self->_chain->end()); if (!__pyx_t_1) break; - /* "polluck_blockchain/placeholder_native.pyx":361 + /* "polluck_blockchain/placeholder_native.pyx":330 * if self._chain is not NULL: * while it != self._chain.end(): * del dereference(it).second # <<<<<<<<<<<<<< @@ -7002,7 +6816,7 @@ static void __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_4__d */ delete (*__pyx_v_it).second; - /* "polluck_blockchain/placeholder_native.pyx":362 + /* "polluck_blockchain/placeholder_native.pyx":331 * while it != self._chain.end(): * del dereference(it).second * postincrement(it) # <<<<<<<<<<<<<< @@ -7012,7 +6826,7 @@ static void __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_4__d (void)((__pyx_v_it++)); } - /* "polluck_blockchain/placeholder_native.pyx":364 + /* "polluck_blockchain/placeholder_native.pyx":333 * postincrement(it) * * del self._chain # <<<<<<<<<<<<<< @@ -7021,7 +6835,7 @@ static void __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_4__d */ delete __pyx_v_self->_chain; - /* "polluck_blockchain/placeholder_native.pyx":365 + /* "polluck_blockchain/placeholder_native.pyx":334 * * del self._chain * self._chain = NULL # <<<<<<<<<<<<<< @@ -7030,7 +6844,7 @@ static void __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_4__d */ __pyx_v_self->_chain = NULL; - /* "polluck_blockchain/placeholder_native.pyx":359 + /* "polluck_blockchain/placeholder_native.pyx":328 * # ownership is typically not transferred from the Blockchain extension class * cdef BcHashmap.iterator it = self._chain.begin() * if self._chain is not NULL: # <<<<<<<<<<<<<< @@ -7039,7 +6853,7 @@ static void __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_4__d */ } - /* "polluck_blockchain/placeholder_native.pyx":356 + /* "polluck_blockchain/placeholder_native.pyx":325 * pass * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -7050,7 +6864,7 @@ static void __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_4__d /* function exit code */ } -/* "polluck_blockchain/placeholder_native.pyx":367 +/* "polluck_blockchain/placeholder_native.pyx":336 * self._chain = NULL * * def __len__(self): # <<<<<<<<<<<<<< @@ -7076,17 +6890,17 @@ static Py_ssize_t __pyx_pw_18polluck_blockchain_18placeholder_native_10Blockchai static Py_ssize_t __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_6__len__(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self) { Py_ssize_t __pyx_r; - /* "polluck_blockchain/placeholder_native.pyx":368 + /* "polluck_blockchain/placeholder_native.pyx":337 * * def __len__(self): * return self._index + 1 # <<<<<<<<<<<<<< * - * def print_key_value_pair(self): + * @property */ __pyx_r = (__pyx_v_self->_index + 1); goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":367 + /* "polluck_blockchain/placeholder_native.pyx":336 * self._chain = NULL * * def __len__(self): # <<<<<<<<<<<<<< @@ -7099,9 +6913,353 @@ static Py_ssize_t __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchai return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":370 +/* "polluck_blockchain/placeholder_native.pyx":339 * return self._index + 1 * + * @property # <<<<<<<<<<<<<< + * def difficulty(self): + * return self._difficulty +*/ + +/* Python wrapper */ +static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_10Blockchain_10difficulty_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_10Blockchain_10difficulty_1__get__(PyObject *__pyx_v_self) { + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); + __pyx_r = __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_10difficulty___get__(((struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_10difficulty___get__(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "polluck_blockchain/placeholder_native.pyx":341 + * @property + * def difficulty(self): + * return self._difficulty # <<<<<<<<<<<<<< + * + * @difficulty.setter +*/ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyLong_From_unsigned_int(__pyx_v_self->_difficulty); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 341, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "polluck_blockchain/placeholder_native.pyx":339 + * return self._index + 1 + * + * @property # <<<<<<<<<<<<<< + * def difficulty(self): + * return self._difficulty +*/ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("polluck_blockchain.placeholder_native.Blockchain.difficulty.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "polluck_blockchain/placeholder_native.pyx":343 + * return self._difficulty + * + * @difficulty.setter # <<<<<<<<<<<<<< + * def difficulty(self, value): + * if not isinstance(value, int): +*/ + +/* Python wrapper */ +static int __pyx_pw_18polluck_blockchain_18placeholder_native_10Blockchain_10difficulty_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_18polluck_blockchain_18placeholder_native_10Blockchain_10difficulty_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); + __pyx_r = __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_10difficulty_2__set__(((struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_10difficulty_2__set__(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + size_t __pyx_t_5; + unsigned int __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); + + /* "polluck_blockchain/placeholder_native.pyx":345 + * @difficulty.setter + * def difficulty(self, value): + * if not isinstance(value, int): # <<<<<<<<<<<<<< + * raise TypeError("Difficulty must be integer value") + * if value <= 0: +*/ + __pyx_t_1 = PyLong_Check(__pyx_v_value); + __pyx_t_2 = (!__pyx_t_1); + if (unlikely(__pyx_t_2)) { + + /* "polluck_blockchain/placeholder_native.pyx":346 + * def difficulty(self, value): + * if not isinstance(value, int): + * raise TypeError("Difficulty must be integer value") # <<<<<<<<<<<<<< + * if value <= 0: + * raise ValueError("Difficulty must be greater than 0") +*/ + __pyx_t_4 = NULL; + __pyx_t_5 = 1; + { + PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_mstate_global->__pyx_kp_u_Difficulty_must_be_integer_value}; + __pyx_t_3 = __Pyx_PyObject_FastCall((PyObject*)(((PyTypeObject*)PyExc_TypeError)), __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 346, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 346, __pyx_L1_error) + + /* "polluck_blockchain/placeholder_native.pyx":345 + * @difficulty.setter + * def difficulty(self, value): + * if not isinstance(value, int): # <<<<<<<<<<<<<< + * raise TypeError("Difficulty must be integer value") + * if value <= 0: +*/ + } + + /* "polluck_blockchain/placeholder_native.pyx":347 + * if not isinstance(value, int): + * raise TypeError("Difficulty must be integer value") + * if value <= 0: # <<<<<<<<<<<<<< + * raise ValueError("Difficulty must be greater than 0") + * self._difficulty = value +*/ + __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_mstate_global->__pyx_int_0, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 347, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 347, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__pyx_t_2)) { + + /* "polluck_blockchain/placeholder_native.pyx":348 + * raise TypeError("Difficulty must be integer value") + * if value <= 0: + * raise ValueError("Difficulty must be greater than 0") # <<<<<<<<<<<<<< + * self._difficulty = value + * +*/ + __pyx_t_4 = NULL; + __pyx_t_5 = 1; + { + PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_mstate_global->__pyx_kp_u_Difficulty_must_be_greater_than}; + __pyx_t_3 = __Pyx_PyObject_FastCall((PyObject*)(((PyTypeObject*)PyExc_ValueError)), __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 348, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 348, __pyx_L1_error) + + /* "polluck_blockchain/placeholder_native.pyx":347 + * if not isinstance(value, int): + * raise TypeError("Difficulty must be integer value") + * if value <= 0: # <<<<<<<<<<<<<< + * raise ValueError("Difficulty must be greater than 0") + * self._difficulty = value +*/ + } + + /* "polluck_blockchain/placeholder_native.pyx":349 + * if value <= 0: + * raise ValueError("Difficulty must be greater than 0") + * self._difficulty = value # <<<<<<<<<<<<<< + * + * @property +*/ + __pyx_t_6 = __Pyx_PyLong_As_unsigned_int(__pyx_v_value); if (unlikely((__pyx_t_6 == (unsigned int)-1) && PyErr_Occurred())) __PYX_ERR(0, 349, __pyx_L1_error) + __pyx_v_self->_difficulty = __pyx_t_6; + + /* "polluck_blockchain/placeholder_native.pyx":343 + * return self._difficulty + * + * @difficulty.setter # <<<<<<<<<<<<<< + * def difficulty(self, value): + * if not isinstance(value, int): +*/ + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("polluck_blockchain.placeholder_native.Blockchain.difficulty.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "polluck_blockchain/placeholder_native.pyx":351 + * self._difficulty = value + * + * @property # <<<<<<<<<<<<<< + * def genesis_done(self): + * return self._genesis_done +*/ + +/* Python wrapper */ +static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_10Blockchain_12genesis_done_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_10Blockchain_12genesis_done_1__get__(PyObject *__pyx_v_self) { + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); + __pyx_r = __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_12genesis_done___get__(((struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_12genesis_done___get__(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "polluck_blockchain/placeholder_native.pyx":353 + * @property + * def genesis_done(self): + * return self._genesis_done # <<<<<<<<<<<<<< + * + * @property +*/ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->_genesis_done); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 353, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "polluck_blockchain/placeholder_native.pyx":351 + * self._difficulty = value + * + * @property # <<<<<<<<<<<<<< + * def genesis_done(self): + * return self._genesis_done +*/ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("polluck_blockchain.placeholder_native.Blockchain.genesis_done.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "polluck_blockchain/placeholder_native.pyx":355 + * return self._genesis_done + * + * @property # <<<<<<<<<<<<<< + * def index(self): + * return self._index +*/ + +/* Python wrapper */ +static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_10Blockchain_5index_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_10Blockchain_5index_1__get__(PyObject *__pyx_v_self) { + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); + __pyx_r = __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_5index___get__(((struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_5index___get__(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "polluck_blockchain/placeholder_native.pyx":357 + * @property + * def index(self): + * return self._index # <<<<<<<<<<<<<< + * + * def print_key_value_pair(self): +*/ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyLong_From_uint64_t(__pyx_v_self->_index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 357, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "polluck_blockchain/placeholder_native.pyx":355 + * return self._genesis_done + * + * @property # <<<<<<<<<<<<<< + * def index(self): + * return self._index +*/ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("polluck_blockchain.placeholder_native.Blockchain.index.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "polluck_blockchain/placeholder_native.pyx":359 + * return self._index + * * def print_key_value_pair(self): # <<<<<<<<<<<<<< * cdef BcHashmap.iterator it = self._chain.begin() * cdef Block *block @@ -7166,7 +7324,7 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain int __pyx_clineno = 0; __Pyx_RefNannySetupContext("print_key_value_pair", 0); - /* "polluck_blockchain/placeholder_native.pyx":371 + /* "polluck_blockchain/placeholder_native.pyx":360 * * def print_key_value_pair(self): * cdef BcHashmap.iterator it = self._chain.begin() # <<<<<<<<<<<<<< @@ -7175,7 +7333,7 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain */ __pyx_v_it = __pyx_v_self->_chain->begin(); - /* "polluck_blockchain/placeholder_native.pyx":373 + /* "polluck_blockchain/placeholder_native.pyx":362 * cdef BcHashmap.iterator it = self._chain.begin() * cdef Block *block * while it != self._chain.end(): # <<<<<<<<<<<<<< @@ -7186,7 +7344,7 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain __pyx_t_1 = (__pyx_v_it != __pyx_v_self->_chain->end()); if (!__pyx_t_1) break; - /* "polluck_blockchain/placeholder_native.pyx":374 + /* "polluck_blockchain/placeholder_native.pyx":363 * cdef Block *block * while it != self._chain.end(): * print(dereference(it).first) # <<<<<<<<<<<<<< @@ -7194,7 +7352,7 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain * py_block = PyBlock.from_ptr(block) */ __pyx_t_3 = NULL; - __pyx_t_4 = __Pyx_PyLong_From_uint64_t((*__pyx_v_it).first); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 374, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyLong_From_uint64_t((*__pyx_v_it).first); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = 1; { @@ -7202,12 +7360,12 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain __pyx_t_2 = __Pyx_PyObject_FastCall((PyObject*)__pyx_builtin_print, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 374, __pyx_L1_error) + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "polluck_blockchain/placeholder_native.pyx":375 + /* "polluck_blockchain/placeholder_native.pyx":364 * while it != self._chain.end(): * print(dereference(it).first) * block = dereference(it).second # <<<<<<<<<<<<<< @@ -7217,19 +7375,19 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain __pyx_t_6 = (*__pyx_v_it).second; __pyx_v_block = __pyx_t_6; - /* "polluck_blockchain/placeholder_native.pyx":376 + /* "polluck_blockchain/placeholder_native.pyx":365 * print(dereference(it).first) * block = dereference(it).second * py_block = PyBlock.from_ptr(block) # <<<<<<<<<<<<<< * print(py_block) * postincrement(it) */ - __pyx_t_2 = ((PyObject *)__pyx_vtabptr_18polluck_blockchain_18placeholder_native_PyBlock->from_ptr(__pyx_v_block, NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 376, __pyx_L1_error) + __pyx_t_2 = ((PyObject *)__pyx_vtabptr_18polluck_blockchain_18placeholder_native_PyBlock->from_ptr(__pyx_v_block, NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 365, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XDECREF_SET(__pyx_v_py_block, ((struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *)__pyx_t_2)); __pyx_t_2 = 0; - /* "polluck_blockchain/placeholder_native.pyx":377 + /* "polluck_blockchain/placeholder_native.pyx":366 * block = dereference(it).second * py_block = PyBlock.from_ptr(block) * print(py_block) # <<<<<<<<<<<<<< @@ -7242,23 +7400,23 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain PyObject *__pyx_callargs[2] = {__pyx_t_4, ((PyObject *)__pyx_v_py_block)}; __pyx_t_2 = __Pyx_PyObject_FastCall((PyObject*)__pyx_builtin_print, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 377, __pyx_L1_error) + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 366, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "polluck_blockchain/placeholder_native.pyx":378 + /* "polluck_blockchain/placeholder_native.pyx":367 * py_block = PyBlock.from_ptr(block) * print(py_block) * postincrement(it) # <<<<<<<<<<<<<< * - * @property + * cdef Block* get_block_c(self, uint64_t idx) nogil: */ (void)((__pyx_v_it++)); } - /* "polluck_blockchain/placeholder_native.pyx":370 - * return self._index + 1 + /* "polluck_blockchain/placeholder_native.pyx":359 + * return self._index * * def print_key_value_pair(self): # <<<<<<<<<<<<<< * cdef BcHashmap.iterator it = self._chain.begin() @@ -7281,163 +7439,63 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":380 +/* "polluck_blockchain/placeholder_native.pyx":369 * postincrement(it) * - * @property # <<<<<<<<<<<<<< - * def genesis_done(self): - * return self._genesis_done -*/ - -/* Python wrapper */ -static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_10Blockchain_12genesis_done_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_10Blockchain_12genesis_done_1__get__(PyObject *__pyx_v_self) { - CYTHON_UNUSED PyObject *const *__pyx_kwvalues; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); - __pyx_r = __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_12genesis_done___get__(((struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_12genesis_done___get__(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "polluck_blockchain/placeholder_native.pyx":382 - * @property - * def genesis_done(self): - * return self._genesis_done # <<<<<<<<<<<<<< - * - * @property -*/ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->_genesis_done); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "polluck_blockchain/placeholder_native.pyx":380 - * postincrement(it) - * - * @property # <<<<<<<<<<<<<< - * def genesis_done(self): - * return self._genesis_done -*/ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("polluck_blockchain.placeholder_native.Blockchain.genesis_done.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "polluck_blockchain/placeholder_native.pyx":384 - * return self._genesis_done - * - * @property # <<<<<<<<<<<<<< - * def index(self): - * return self._index -*/ - -/* Python wrapper */ -static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_10Blockchain_5index_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_18polluck_blockchain_18placeholder_native_10Blockchain_5index_1__get__(PyObject *__pyx_v_self) { - CYTHON_UNUSED PyObject *const *__pyx_kwvalues; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); - __pyx_r = __pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_5index___get__(((struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_5index___get__(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "polluck_blockchain/placeholder_native.pyx":386 - * @property - * def index(self): - * return self._index # <<<<<<<<<<<<<< - * - * # TODO error handling -*/ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyLong_From_uint64_t(__pyx_v_self->_index); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 386, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "polluck_blockchain/placeholder_native.pyx":384 - * return self._genesis_done - * - * @property # <<<<<<<<<<<<<< - * def index(self): - * return self._index -*/ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("polluck_blockchain.placeholder_native.Blockchain.index.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "polluck_blockchain/placeholder_native.pyx":389 - * - * # TODO error handling - * cdef Block* get_block_c(self, uint64_t idx): # <<<<<<<<<<<<<< - * return self._chain[0][idx] - * + * cdef Block* get_block_c(self, uint64_t idx) nogil: # <<<<<<<<<<<<<< + * if idx > self._index: + * return NULL */ static ::Block *__pyx_f_18polluck_blockchain_18placeholder_native_10Blockchain_get_block_c(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self, uint64_t __pyx_v_idx) { ::Block *__pyx_r; + int __pyx_t_1; - /* "polluck_blockchain/placeholder_native.pyx":390 - * # TODO error handling - * cdef Block* get_block_c(self, uint64_t idx): + /* "polluck_blockchain/placeholder_native.pyx":370 + * + * cdef Block* get_block_c(self, uint64_t idx) nogil: + * if idx > self._index: # <<<<<<<<<<<<<< + * return NULL + * return self._chain[0][idx] +*/ + __pyx_t_1 = (__pyx_v_idx > __pyx_v_self->_index); + if (__pyx_t_1) { + + /* "polluck_blockchain/placeholder_native.pyx":371 + * cdef Block* get_block_c(self, uint64_t idx) nogil: + * if idx > self._index: + * return NULL # <<<<<<<<<<<<<< + * return self._chain[0][idx] + * +*/ + __pyx_r = NULL; + goto __pyx_L0; + + /* "polluck_blockchain/placeholder_native.pyx":370 + * + * cdef Block* get_block_c(self, uint64_t idx) nogil: + * if idx > self._index: # <<<<<<<<<<<<<< + * return NULL + * return self._chain[0][idx] +*/ + } + + /* "polluck_blockchain/placeholder_native.pyx":372 + * if idx > self._index: + * return NULL * return self._chain[0][idx] # <<<<<<<<<<<<<< * - * def get_block(self, idx): + * cdef int add_block(self, Block *block) nogil: */ __pyx_r = ((__pyx_v_self->_chain[0])[__pyx_v_idx]); goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":389 - * - * # TODO error handling - * cdef Block* get_block_c(self, uint64_t idx): # <<<<<<<<<<<<<< - * return self._chain[0][idx] + /* "polluck_blockchain/placeholder_native.pyx":369 + * postincrement(it) * + * cdef Block* get_block_c(self, uint64_t idx) nogil: # <<<<<<<<<<<<<< + * if idx > self._index: + * return NULL */ /* function exit code */ @@ -7445,9 +7503,236 @@ static ::Block *__pyx_f_18polluck_blockchain_18placeholder_native_10Blockchain_g return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":392 +/* "polluck_blockchain/placeholder_native.pyx":374 * return self._chain[0][idx] * + * cdef int add_block(self, Block *block) nogil: # <<<<<<<<<<<<<< + * cdef: + * uint64_t mined_nonce +*/ + +static int __pyx_f_18polluck_blockchain_18placeholder_native_10Blockchain_add_block(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self, ::Block *__pyx_v_block) { + uint64_t __pyx_v_mined_nonce; + size_t __pyx_v_digest_size; + unsigned char *__pyx_v_sha256_digest; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + unsigned char *__pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + size_t __pyx_t_9; + std::string __pyx_t_10; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyGILState_STATE __pyx_gilstate_save; + __Pyx_RefNannySetupContext("add_block", 1); + + /* "polluck_blockchain/placeholder_native.pyx":380 + * unsigned char *sha256_digest + * # mine block + * if mine_block(block, self._difficulty, &mined_nonce) != 0: # <<<<<<<<<<<<<< + * return 1 + * block.nonce = mined_nonce +*/ + __pyx_t_1 = __pyx_f_18polluck_blockchain_18placeholder_native_mine_block(__pyx_v_block, __pyx_v_self->_difficulty, (&__pyx_v_mined_nonce), NULL); if (unlikely(__pyx_t_1 == ((int)-1) && __Pyx_ErrOccurredWithGIL())) __PYX_ERR(0, 380, __pyx_L1_error) + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "polluck_blockchain/placeholder_native.pyx":381 + * # mine block + * if mine_block(block, self._difficulty, &mined_nonce) != 0: + * return 1 # <<<<<<<<<<<<<< + * block.nonce = mined_nonce + * # hash block, add hash to block, add block to blockchain hashmap +*/ + __pyx_r = 1; + goto __pyx_L0; + + /* "polluck_blockchain/placeholder_native.pyx":380 + * unsigned char *sha256_digest + * # mine block + * if mine_block(block, self._difficulty, &mined_nonce) != 0: # <<<<<<<<<<<<<< + * return 1 + * block.nonce = mined_nonce +*/ + } + + /* "polluck_blockchain/placeholder_native.pyx":382 + * if mine_block(block, self._difficulty, &mined_nonce) != 0: + * return 1 + * block.nonce = mined_nonce # <<<<<<<<<<<<<< + * # hash block, add hash to block, add block to blockchain hashmap + * sha256_digest = perform_hash_c(block, &digest_size) +*/ + __pyx_v_block->nonce = __pyx_v_mined_nonce; + + /* "polluck_blockchain/placeholder_native.pyx":384 + * block.nonce = mined_nonce + * # hash block, add hash to block, add block to blockchain hashmap + * sha256_digest = perform_hash_c(block, &digest_size) # <<<<<<<<<<<<<< + * with gil: + * block.hash = bytes(sha256_digest[:digest_size]).hex().encode("UTF-8") +*/ + __pyx_t_3 = __pyx_f_18polluck_blockchain_18placeholder_native_perform_hash_c(__pyx_v_block, (&__pyx_v_digest_size)); if (unlikely(__pyx_t_3 == ((void *)NULL) && __Pyx_ErrOccurredWithGIL())) __PYX_ERR(0, 384, __pyx_L1_error) + __pyx_v_sha256_digest = __pyx_t_3; + + /* "polluck_blockchain/placeholder_native.pyx":385 + * # hash block, add hash to block, add block to blockchain hashmap + * sha256_digest = perform_hash_c(block, &digest_size) + * with gil: # <<<<<<<<<<<<<< + * block.hash = bytes(sha256_digest[:digest_size]).hex().encode("UTF-8") + * free(sha256_digest) +*/ + { + PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + /*try:*/ { + + /* "polluck_blockchain/placeholder_native.pyx":386 + * sha256_digest = perform_hash_c(block, &digest_size) + * with gil: + * block.hash = bytes(sha256_digest[:digest_size]).hex().encode("UTF-8") # <<<<<<<<<<<<<< + * free(sha256_digest) + * self._chain[0][block.index] = block +*/ + __pyx_t_7 = NULL; + __pyx_t_8 = __Pyx_PyBytes_FromStringAndSize(((char const *)__pyx_v_sha256_digest) + 0, __pyx_v_digest_size - 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 386, __pyx_L5_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = 1; + { + PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_t_8}; + __pyx_t_6 = __Pyx_PyObject_FastCall((PyObject*)(&PyBytes_Type), __pyx_callargs+__pyx_t_9, (2-__pyx_t_9) | (__pyx_t_9*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 386, __pyx_L5_error) + __Pyx_GOTREF(__pyx_t_6); + } + __pyx_t_5 = __pyx_t_6; + __Pyx_INCREF(__pyx_t_5); + __pyx_t_9 = 0; + { + PyObject *__pyx_callargs[2] = {__pyx_t_5, NULL}; + __pyx_t_4 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_hex, __pyx_callargs+__pyx_t_9, (1-__pyx_t_9) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 386, __pyx_L5_error) + __Pyx_GOTREF(__pyx_t_4); + } + __pyx_t_6 = PyUnicode_AsUTF8String(((PyObject*)__pyx_t_4)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 386, __pyx_L5_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_10 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_t_6); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 386, __pyx_L5_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_block->hash = __PYX_STD_MOVE_IF_SUPPORTED(__pyx_t_10); + } + + /* "polluck_blockchain/placeholder_native.pyx":385 + * # hash block, add hash to block, add block to blockchain hashmap + * sha256_digest = perform_hash_c(block, &digest_size) + * with gil: # <<<<<<<<<<<<<< + * block.hash = bytes(sha256_digest[:digest_size]).hex().encode("UTF-8") + * free(sha256_digest) +*/ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_PyGILState_Release(__pyx_gilstate_save); + goto __pyx_L6; + } + __pyx_L5_error: { + __Pyx_PyGILState_Release(__pyx_gilstate_save); + goto __pyx_L1_error; + } + __pyx_L6:; + } + } + + /* "polluck_blockchain/placeholder_native.pyx":387 + * with gil: + * block.hash = bytes(sha256_digest[:digest_size]).hex().encode("UTF-8") + * free(sha256_digest) # <<<<<<<<<<<<<< + * self._chain[0][block.index] = block + * +*/ + free(__pyx_v_sha256_digest); + + /* "polluck_blockchain/placeholder_native.pyx":388 + * block.hash = bytes(sha256_digest[:digest_size]).hex().encode("UTF-8") + * free(sha256_digest) + * self._chain[0][block.index] = block # <<<<<<<<<<<<<< + * + * if self._genesis_done: +*/ + ((__pyx_v_self->_chain[0])[__pyx_v_block->index]) = __pyx_v_block; + + /* "polluck_blockchain/placeholder_native.pyx":390 + * self._chain[0][block.index] = block + * + * if self._genesis_done: # <<<<<<<<<<<<<< + * self._index += 1 + * +*/ + if (__pyx_v_self->_genesis_done) { + + /* "polluck_blockchain/placeholder_native.pyx":391 + * + * if self._genesis_done: + * self._index += 1 # <<<<<<<<<<<<<< + * + * return 0 +*/ + __pyx_v_self->_index = (__pyx_v_self->_index + 1); + + /* "polluck_blockchain/placeholder_native.pyx":390 + * self._chain[0][block.index] = block + * + * if self._genesis_done: # <<<<<<<<<<<<<< + * self._index += 1 + * +*/ + } + + /* "polluck_blockchain/placeholder_native.pyx":393 + * self._index += 1 + * + * return 0 # <<<<<<<<<<<<<< + * + * # // Python public API +*/ + __pyx_r = 0; + goto __pyx_L0; + + /* "polluck_blockchain/placeholder_native.pyx":374 + * return self._chain[0][idx] + * + * cdef int add_block(self, Block *block) nogil: # <<<<<<<<<<<<<< + * cdef: + * uint64_t mined_nonce +*/ + + /* function exit code */ + __pyx_L1_error:; + __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("polluck_blockchain.placeholder_native.Blockchain.add_block", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __Pyx_PyGILState_Release(__pyx_gilstate_save); + __pyx_L0:; + __Pyx_RefNannyFinishContextNogil() + return __pyx_r; +} + +/* "polluck_blockchain/placeholder_native.pyx":396 + * + * # // Python public API * def get_block(self, idx): # <<<<<<<<<<<<<< * if idx < 0 or idx > self._index: * raise IndexError("Index value is out of bounds") @@ -7492,32 +7777,32 @@ PyObject *__pyx_args, PyObject *__pyx_kwds { PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_idx,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; - if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 392, __pyx_L3_error) + if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 396, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); - if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 392, __pyx_L3_error) + if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 396, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; - if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "get_block", 0) < (0)) __PYX_ERR(0, 392, __pyx_L3_error) + if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "get_block", 0) < (0)) __PYX_ERR(0, 396, __pyx_L3_error) for (Py_ssize_t i = __pyx_nargs; i < 1; i++) { - if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("get_block", 1, 1, 1, i); __PYX_ERR(0, 392, __pyx_L3_error) } + if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("get_block", 1, 1, 1, i); __PYX_ERR(0, 396, __pyx_L3_error) } } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); - if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 392, __pyx_L3_error) + if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 396, __pyx_L3_error) } __pyx_v_idx = values[0]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get_block", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 392, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("get_block", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 396, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -7555,32 +7840,32 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain int __pyx_clineno = 0; __Pyx_RefNannySetupContext("get_block", 0); - /* "polluck_blockchain/placeholder_native.pyx":393 - * + /* "polluck_blockchain/placeholder_native.pyx":397 + * # // Python public API * def get_block(self, idx): * if idx < 0 or idx > self._index: # <<<<<<<<<<<<<< * raise IndexError("Index value is out of bounds") * */ - __pyx_t_2 = PyObject_RichCompare(__pyx_v_idx, __pyx_mstate_global->__pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 393, __pyx_L1_error) - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 393, __pyx_L1_error) + __pyx_t_2 = PyObject_RichCompare(__pyx_v_idx, __pyx_mstate_global->__pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 397, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 397, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (!__pyx_t_3) { } else { __pyx_t_1 = __pyx_t_3; goto __pyx_L4_bool_binop_done; } - __pyx_t_2 = __Pyx_PyLong_From_uint64_t(__pyx_v_self->_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 393, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyLong_From_uint64_t(__pyx_v_self->_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 397, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_RichCompare(__pyx_v_idx, __pyx_t_2, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 393, __pyx_L1_error) + __pyx_t_4 = PyObject_RichCompare(__pyx_v_idx, __pyx_t_2, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 397, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 393, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 397, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_1 = __pyx_t_3; __pyx_L4_bool_binop_done:; if (unlikely(__pyx_t_1)) { - /* "polluck_blockchain/placeholder_native.pyx":394 + /* "polluck_blockchain/placeholder_native.pyx":398 * def get_block(self, idx): * if idx < 0 or idx > self._index: * raise IndexError("Index value is out of bounds") # <<<<<<<<<<<<<< @@ -7593,15 +7878,15 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_mstate_global->__pyx_kp_u_Index_value_is_out_of_bounds}; __pyx_t_4 = __Pyx_PyObject_FastCall((PyObject*)(((PyTypeObject*)PyExc_IndexError)), __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 394, __pyx_L1_error) + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 398, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); } __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 394, __pyx_L1_error) + __PYX_ERR(0, 398, __pyx_L1_error) - /* "polluck_blockchain/placeholder_native.pyx":393 - * + /* "polluck_blockchain/placeholder_native.pyx":397 + * # // Python public API * def get_block(self, idx): * if idx < 0 or idx > self._index: # <<<<<<<<<<<<<< * raise IndexError("Index value is out of bounds") @@ -7609,36 +7894,75 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain */ } - /* "polluck_blockchain/placeholder_native.pyx":396 + /* "polluck_blockchain/placeholder_native.pyx":400 * raise IndexError("Index value is out of bounds") * * cdef Block *block = self.get_block_c(idx) # <<<<<<<<<<<<<< + * if block == NULL: + * raise IndexError("Provided index not found") +*/ + __pyx_t_6 = __Pyx_PyLong_As_uint64_t(__pyx_v_idx); if (unlikely((__pyx_t_6 == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 400, __pyx_L1_error) + __pyx_t_7 = ((struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_Blockchain *)__pyx_v_self->__pyx_vtab)->get_block_c(__pyx_v_self, __pyx_t_6); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 400, __pyx_L1_error) + __pyx_v_block = __pyx_t_7; + + /* "polluck_blockchain/placeholder_native.pyx":401 + * + * cdef Block *block = self.get_block_c(idx) + * if block == NULL: # <<<<<<<<<<<<<< + * raise IndexError("Provided index not found") + * return PyBlock.from_ptr(block, owner=False) +*/ + __pyx_t_1 = (__pyx_v_block == NULL); + if (unlikely(__pyx_t_1)) { + + /* "polluck_blockchain/placeholder_native.pyx":402 + * cdef Block *block = self.get_block_c(idx) + * if block == NULL: + * raise IndexError("Provided index not found") # <<<<<<<<<<<<<< * return PyBlock.from_ptr(block, owner=False) * */ - __pyx_t_6 = __Pyx_PyLong_As_uint64_t(__pyx_v_idx); if (unlikely((__pyx_t_6 == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 396, __pyx_L1_error) - __pyx_t_7 = ((struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_Blockchain *)__pyx_v_self->__pyx_vtab)->get_block_c(__pyx_v_self, __pyx_t_6); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 396, __pyx_L1_error) - __pyx_v_block = __pyx_t_7; + __pyx_t_2 = NULL; + __pyx_t_5 = 1; + { + PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_mstate_global->__pyx_kp_u_Provided_index_not_found}; + __pyx_t_4 = __Pyx_PyObject_FastCall((PyObject*)(((PyTypeObject*)PyExc_IndexError)), __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 402, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 402, __pyx_L1_error) - /* "polluck_blockchain/placeholder_native.pyx":397 + /* "polluck_blockchain/placeholder_native.pyx":401 * * cdef Block *block = self.get_block_c(idx) + * if block == NULL: # <<<<<<<<<<<<<< + * raise IndexError("Provided index not found") + * return PyBlock.from_ptr(block, owner=False) +*/ + } + + /* "polluck_blockchain/placeholder_native.pyx":403 + * if block == NULL: + * raise IndexError("Provided index not found") * return PyBlock.from_ptr(block, owner=False) # <<<<<<<<<<<<<< * - * cdef void add_block(self, Block *block): + * cdef string hash_data(self, data): */ __Pyx_XDECREF(__pyx_r); __pyx_t_8.__pyx_n = 1; __pyx_t_8.owner = 0; - __pyx_t_4 = ((PyObject *)__pyx_vtabptr_18polluck_blockchain_18placeholder_native_PyBlock->from_ptr(__pyx_v_block, &__pyx_t_8)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 397, __pyx_L1_error) + __pyx_t_4 = ((PyObject *)__pyx_vtabptr_18polluck_blockchain_18placeholder_native_PyBlock->from_ptr(__pyx_v_block, &__pyx_t_8)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 403, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0; - /* "polluck_blockchain/placeholder_native.pyx":392 - * return self._chain[0][idx] + /* "polluck_blockchain/placeholder_native.pyx":396 * + * # // Python public API * def get_block(self, idx): # <<<<<<<<<<<<<< * if idx < 0 or idx > self._index: * raise IndexError("Index value is out of bounds") @@ -7656,69 +7980,188 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":399 +/* "polluck_blockchain/placeholder_native.pyx":405 * return PyBlock.from_ptr(block, owner=False) * - * cdef void add_block(self, Block *block): # <<<<<<<<<<<<<< - * self._chain[0][block.index] = block - * if self._genesis_done: + * cdef string hash_data(self, data): # <<<<<<<<<<<<<< + * cdef: + * string data_str */ -static void __pyx_f_18polluck_blockchain_18placeholder_native_10Blockchain_add_block(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self, ::Block *__pyx_v_block) { +static std::string __pyx_f_18polluck_blockchain_18placeholder_native_10Blockchain_hash_data(CYTHON_UNUSED struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self, PyObject *__pyx_v_data) { + std::string __pyx_v_data_str; + unsigned char *__pyx_v_data_digest; + size_t __pyx_v_digest_size; + std::string __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + size_t __pyx_t_3; + std::string __pyx_t_4; + unsigned char *__pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("hash_data", 0); - /* "polluck_blockchain/placeholder_native.pyx":400 - * - * cdef void add_block(self, Block *block): - * self._chain[0][block.index] = block # <<<<<<<<<<<<<< - * if self._genesis_done: - * self._index += 1 + /* "polluck_blockchain/placeholder_native.pyx":410 + * unsigned char *data_digest + * size_t digest_size + * data_str = data.encode("UTF-8") # <<<<<<<<<<<<<< + * data_digest = SHA256_digest(data_str.c_str(), data_str.size(), &digest_size) + * if data_digest == NULL: */ - ((__pyx_v_self->_chain[0])[__pyx_v_block->index]) = __pyx_v_block; + __pyx_t_2 = __pyx_v_data; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_3 = 0; + { + PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_mstate_global->__pyx_kp_u_UTF_8}; + __pyx_t_1 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_encode, __pyx_callargs+__pyx_t_3, (2-__pyx_t_3) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 410, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } + __pyx_t_4 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_t_1); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 410, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_data_str = __PYX_STD_MOVE_IF_SUPPORTED(__pyx_t_4); - /* "polluck_blockchain/placeholder_native.pyx":401 - * cdef void add_block(self, Block *block): - * self._chain[0][block.index] = block - * if self._genesis_done: # <<<<<<<<<<<<<< - * self._index += 1 - * + /* "polluck_blockchain/placeholder_native.pyx":411 + * size_t digest_size + * data_str = data.encode("UTF-8") + * data_digest = SHA256_digest(data_str.c_str(), data_str.size(), &digest_size) # <<<<<<<<<<<<<< + * if data_digest == NULL: + * raise RuntimeError("Failed to hash data") */ - if (__pyx_v_self->_genesis_done) { + __pyx_t_5 = __pyx_f_18polluck_blockchain_18placeholder_native_SHA256_digest(__pyx_v_data_str.c_str(), __pyx_v_data_str.size(), (&__pyx_v_digest_size)); if (unlikely(__pyx_t_5 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 411, __pyx_L1_error) + __pyx_v_data_digest = __pyx_t_5; - /* "polluck_blockchain/placeholder_native.pyx":402 - * self._chain[0][block.index] = block - * if self._genesis_done: - * self._index += 1 # <<<<<<<<<<<<<< - * - * def create_genesis_block(self): + /* "polluck_blockchain/placeholder_native.pyx":412 + * data_str = data.encode("UTF-8") + * data_digest = SHA256_digest(data_str.c_str(), data_str.size(), &digest_size) + * if data_digest == NULL: # <<<<<<<<<<<<<< + * raise RuntimeError("Failed to hash data") + * data_str = bytes(data_digest[:digest_size]).hex().encode("UTF-8") */ - __pyx_v_self->_index = (__pyx_v_self->_index + 1); + __pyx_t_6 = (__pyx_v_data_digest == NULL); + if (unlikely(__pyx_t_6)) { - /* "polluck_blockchain/placeholder_native.pyx":401 - * cdef void add_block(self, Block *block): - * self._chain[0][block.index] = block - * if self._genesis_done: # <<<<<<<<<<<<<< - * self._index += 1 - * + /* "polluck_blockchain/placeholder_native.pyx":413 + * data_digest = SHA256_digest(data_str.c_str(), data_str.size(), &digest_size) + * if data_digest == NULL: + * raise RuntimeError("Failed to hash data") # <<<<<<<<<<<<<< + * data_str = bytes(data_digest[:digest_size]).hex().encode("UTF-8") + * free(data_digest) +*/ + __pyx_t_2 = NULL; + __pyx_t_3 = 1; + { + PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_mstate_global->__pyx_kp_u_Failed_to_hash_data}; + __pyx_t_1 = __Pyx_PyObject_FastCall((PyObject*)(((PyTypeObject*)PyExc_RuntimeError)), __pyx_callargs+__pyx_t_3, (2-__pyx_t_3) | (__pyx_t_3*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 413, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 413, __pyx_L1_error) + + /* "polluck_blockchain/placeholder_native.pyx":412 + * data_str = data.encode("UTF-8") + * data_digest = SHA256_digest(data_str.c_str(), data_str.size(), &digest_size) + * if data_digest == NULL: # <<<<<<<<<<<<<< + * raise RuntimeError("Failed to hash data") + * data_str = bytes(data_digest[:digest_size]).hex().encode("UTF-8") */ } - /* "polluck_blockchain/placeholder_native.pyx":399 + /* "polluck_blockchain/placeholder_native.pyx":414 + * if data_digest == NULL: + * raise RuntimeError("Failed to hash data") + * data_str = bytes(data_digest[:digest_size]).hex().encode("UTF-8") # <<<<<<<<<<<<<< + * free(data_digest) + * +*/ + __pyx_t_8 = NULL; + __pyx_t_9 = __Pyx_PyBytes_FromStringAndSize(((char const *)__pyx_v_data_digest) + 0, __pyx_v_digest_size - 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 414, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_3 = 1; + { + PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_t_9}; + __pyx_t_7 = __Pyx_PyObject_FastCall((PyObject*)(&PyBytes_Type), __pyx_callargs+__pyx_t_3, (2-__pyx_t_3) | (__pyx_t_3*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 414, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + } + __pyx_t_2 = __pyx_t_7; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_3 = 0; + { + PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL}; + __pyx_t_1 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_hex, __pyx_callargs+__pyx_t_3, (1-__pyx_t_3) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 414, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } + __pyx_t_7 = PyUnicode_AsUTF8String(((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 414, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_t_7); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 414, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_data_str = __PYX_STD_MOVE_IF_SUPPORTED(__pyx_t_4); + + /* "polluck_blockchain/placeholder_native.pyx":415 + * raise RuntimeError("Failed to hash data") + * data_str = bytes(data_digest[:digest_size]).hex().encode("UTF-8") + * free(data_digest) # <<<<<<<<<<<<<< + * + * return data_str +*/ + free(__pyx_v_data_digest); + + /* "polluck_blockchain/placeholder_native.pyx":417 + * free(data_digest) + * + * return data_str # <<<<<<<<<<<<<< + * + * def create_genesis_block(self): +*/ + __pyx_r = __pyx_v_data_str; + goto __pyx_L0; + + /* "polluck_blockchain/placeholder_native.pyx":405 * return PyBlock.from_ptr(block, owner=False) * - * cdef void add_block(self, Block *block): # <<<<<<<<<<<<<< - * self._chain[0][block.index] = block - * if self._genesis_done: + * cdef string hash_data(self, data): # <<<<<<<<<<<<<< + * cdef: + * string data_str */ /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("polluck_blockchain.placeholder_native.Blockchain.hash_data", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_pretend_to_initialize(&__pyx_r); + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":404 - * self._index += 1 +/* "polluck_blockchain/placeholder_native.pyx":419 + * return data_str * * def create_genesis_block(self): # <<<<<<<<<<<<<< - * cdef Block *block = new Block( - * self._index, + * genesis_prev_hash = ("0" * 64).encode("UTF-8") + * cdef string data_str = self.hash_data("Genesis Block") */ /* Python wrapper */ @@ -7764,156 +8207,202 @@ PyObject *__pyx_args, PyObject *__pyx_kwds } static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain_12create_genesis_block(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *__pyx_v_self) { + PyObject *__pyx_v_genesis_prev_hash = NULL; + std::string __pyx_v_data_str; ::Block *__pyx_v_block; + int __pyx_v_res; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; + std::string __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - size_t __pyx_t_5; - double __pyx_t_6; - std::string __pyx_t_7; + PyObject *__pyx_t_5 = NULL; + size_t __pyx_t_6; + double __pyx_t_7; std::string __pyx_t_8; - std::string __pyx_t_9; - ::Block *__pyx_t_10; + ::Block *__pyx_t_9; + int __pyx_t_10; + int __pyx_t_11; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("create_genesis_block", 0); - /* "polluck_blockchain/placeholder_native.pyx":407 + /* "polluck_blockchain/placeholder_native.pyx":420 + * + * def create_genesis_block(self): + * genesis_prev_hash = ("0" * 64).encode("UTF-8") # <<<<<<<<<<<<<< + * cdef string data_str = self.hash_data("Genesis Block") + * +*/ + __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_b_00000000000000000000000000000000); + __pyx_v_genesis_prev_hash = __pyx_mstate_global->__pyx_kp_b_00000000000000000000000000000000; + + /* "polluck_blockchain/placeholder_native.pyx":421 + * def create_genesis_block(self): + * genesis_prev_hash = ("0" * 64).encode("UTF-8") + * cdef string data_str = self.hash_data("Genesis Block") # <<<<<<<<<<<<<< + * + * cdef Block *block = new Block( +*/ + __pyx_t_1 = ((struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_Blockchain *)__pyx_v_self->__pyx_vtab)->hash_data(__pyx_v_self, __pyx_mstate_global->__pyx_kp_u_Genesis_Block); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 421, __pyx_L1_error) + __pyx_v_data_str = __PYX_STD_MOVE_IF_SUPPORTED(__pyx_t_1); + + /* "polluck_blockchain/placeholder_native.pyx":425 * cdef Block *block = new Block( * self._index, * int(datetime.datetime(2025, 12, 1, 12, 0, 0).timestamp()), # <<<<<<<<<<<<<< * 0, - * "Genesis Block".encode("UTF-8"), + * data_str, */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 407, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 425, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_mstate_global->__pyx_tuple[0], NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 425, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_2 = __pyx_t_3; - __Pyx_INCREF(__pyx_t_2); - __pyx_t_5 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_mstate_global->__pyx_tuple[0], NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 425, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_3 = __pyx_t_4; + __Pyx_INCREF(__pyx_t_3); + __pyx_t_6 = 0; { - PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL}; - __pyx_t_1 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_timestamp, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); + PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; + __pyx_t_2 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_timestamp, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 425, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); } - __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = __Pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 407, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyNumber_Int(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 425, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_7 = __Pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_7 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 425, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "polluck_blockchain/placeholder_native.pyx":409 - * int(datetime.datetime(2025, 12, 1, 12, 0, 0).timestamp()), + /* "polluck_blockchain/placeholder_native.pyx":428 * 0, - * "Genesis Block".encode("UTF-8"), # <<<<<<<<<<<<<< - * "0".encode("UTF-8"), - * "".encode("UTF-8"), -*/ - __pyx_t_7 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_mstate_global->__pyx_kp_b_Genesis_Block); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 409, __pyx_L1_error) - - /* "polluck_blockchain/placeholder_native.pyx":410 - * 0, - * "Genesis Block".encode("UTF-8"), - * "0".encode("UTF-8"), # <<<<<<<<<<<<<< + * data_str, + * genesis_prev_hash, # <<<<<<<<<<<<<< * "".encode("UTF-8"), * ) */ - __pyx_t_8 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_mstate_global->__pyx_kp_b_0); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 410, __pyx_L1_error) + __pyx_t_1 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_v_genesis_prev_hash); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 428, __pyx_L1_error) - /* "polluck_blockchain/placeholder_native.pyx":411 - * "Genesis Block".encode("UTF-8"), - * "0".encode("UTF-8"), + /* "polluck_blockchain/placeholder_native.pyx":429 + * data_str, + * genesis_prev_hash, * "".encode("UTF-8"), # <<<<<<<<<<<<<< * ) - * block.hash = "dummy hash".encode("UTF-8") + * cdef int res = self.add_block(block) */ - __pyx_t_9 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_mstate_global->__pyx_kp_b_); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 411, __pyx_L1_error) + __pyx_t_8 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_mstate_global->__pyx_kp_b_); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 429, __pyx_L1_error) - /* "polluck_blockchain/placeholder_native.pyx":405 + /* "polluck_blockchain/placeholder_native.pyx":423 + * cdef string data_str = self.hash_data("Genesis Block") * - * def create_genesis_block(self): * cdef Block *block = new Block( # <<<<<<<<<<<<<< * self._index, * int(datetime.datetime(2025, 12, 1, 12, 0, 0).timestamp()), */ try { - __pyx_t_10 = new ::Block(__pyx_v_self->_index, __pyx_t_6, 0, __pyx_t_7, __pyx_t_8, __pyx_t_9); + __pyx_t_9 = new ::Block(__pyx_v_self->_index, __pyx_t_7, 0, __pyx_v_data_str, __pyx_t_1, __pyx_t_8); } catch(...) { __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 405, __pyx_L1_error) + __PYX_ERR(0, 423, __pyx_L1_error) } - __pyx_v_block = __pyx_t_10; + __pyx_v_block = __pyx_t_9; - /* "polluck_blockchain/placeholder_native.pyx":413 + /* "polluck_blockchain/placeholder_native.pyx":431 * "".encode("UTF-8"), * ) - * block.hash = "dummy hash".encode("UTF-8") # <<<<<<<<<<<<<< - * self.add_block(block) + * cdef int res = self.add_block(block) # <<<<<<<<<<<<<< + * if res != 0: + * raise RuntimeError("Could not mine block. No nonce found") +*/ + __pyx_t_10 = ((struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_Blockchain *)__pyx_v_self->__pyx_vtab)->add_block(__pyx_v_self, __pyx_v_block); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 431, __pyx_L1_error) + __pyx_v_res = __pyx_t_10; + + /* "polluck_blockchain/placeholder_native.pyx":432 + * ) + * cdef int res = self.add_block(block) + * if res != 0: # <<<<<<<<<<<<<< + * raise RuntimeError("Could not mine block. No nonce found") * self._genesis_done = True */ - __pyx_t_9 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_mstate_global->__pyx_kp_b_dummy_hash); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 413, __pyx_L1_error) - __pyx_v_block->hash = __PYX_STD_MOVE_IF_SUPPORTED(__pyx_t_9); + __pyx_t_11 = (__pyx_v_res != 0); + if (unlikely(__pyx_t_11)) { - /* "polluck_blockchain/placeholder_native.pyx":414 - * ) - * block.hash = "dummy hash".encode("UTF-8") - * self.add_block(block) # <<<<<<<<<<<<<< + /* "polluck_blockchain/placeholder_native.pyx":433 + * cdef int res = self.add_block(block) + * if res != 0: + * raise RuntimeError("Could not mine block. No nonce found") # <<<<<<<<<<<<<< * self._genesis_done = True * */ - ((struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_Blockchain *)__pyx_v_self->__pyx_vtab)->add_block(__pyx_v_self, __pyx_v_block); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 414, __pyx_L1_error) + __pyx_t_2 = NULL; + __pyx_t_6 = 1; + { + PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_mstate_global->__pyx_kp_u_Could_not_mine_block_No_nonce_fo}; + __pyx_t_4 = __Pyx_PyObject_FastCall((PyObject*)(((PyTypeObject*)PyExc_RuntimeError)), __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 433, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 433, __pyx_L1_error) - /* "polluck_blockchain/placeholder_native.pyx":415 - * block.hash = "dummy hash".encode("UTF-8") - * self.add_block(block) + /* "polluck_blockchain/placeholder_native.pyx":432 + * ) + * cdef int res = self.add_block(block) + * if res != 0: # <<<<<<<<<<<<<< + * raise RuntimeError("Could not mine block. No nonce found") + * self._genesis_done = True +*/ + } + + /* "polluck_blockchain/placeholder_native.pyx":434 + * if res != 0: + * raise RuntimeError("Could not mine block. No nonce found") * self._genesis_done = True # <<<<<<<<<<<<<< * * def new_block(self, data): */ __pyx_v_self->_genesis_done = 1; - /* "polluck_blockchain/placeholder_native.pyx":404 - * self._index += 1 + /* "polluck_blockchain/placeholder_native.pyx":419 + * return data_str * * def create_genesis_block(self): # <<<<<<<<<<<<<< - * cdef Block *block = new Block( - * self._index, + * genesis_prev_hash = ("0" * 64).encode("UTF-8") + * cdef string data_str = self.hash_data("Genesis Block") */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("polluck_blockchain.placeholder_native.Blockchain.create_genesis_block", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_genesis_prev_hash); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "polluck_blockchain/placeholder_native.pyx":417 +/* "polluck_blockchain/placeholder_native.pyx":436 * self._genesis_done = True * * def new_block(self, data): # <<<<<<<<<<<<<< - * if not self._genesis_done: - * raise RuntimeError("Create a genesis block first.") + * cdef: + * Block *prev_block */ /* Python wrapper */ @@ -7955,32 +8444,32 @@ PyObject *__pyx_args, PyObject *__pyx_kwds { PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_data,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; - if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 417, __pyx_L3_error) + if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 436, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); - if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 417, __pyx_L3_error) + if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 436, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; - if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "new_block", 0) < (0)) __PYX_ERR(0, 417, __pyx_L3_error) + if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "new_block", 0) < (0)) __PYX_ERR(0, 436, __pyx_L3_error) for (Py_ssize_t i = __pyx_nargs; i < 1; i++) { - if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("new_block", 1, 1, 1, i); __PYX_ERR(0, 417, __pyx_L3_error) } + if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("new_block", 1, 1, 1, i); __PYX_ERR(0, 436, __pyx_L3_error) } } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); - if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 417, __pyx_L3_error) + if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 436, __pyx_L3_error) } __pyx_v_data = values[0]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("new_block", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 417, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("new_block", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 436, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -8005,40 +8494,43 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain ::Block *__pyx_v_prev_block; std::string __pyx_v_prev_hash; uint64_t __pyx_v_new_idx; + std::string __pyx_v_data_str; ::Block *__pyx_v_block; + int __pyx_v_res; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; size_t __pyx_t_4; - ::Block *__pyx_t_5; + int __pyx_t_5; std::string __pyx_t_6; - PyObject *__pyx_t_7 = NULL; + ::Block *__pyx_t_7; PyObject *__pyx_t_8 = NULL; - double __pyx_t_9; - std::string __pyx_t_10; + PyObject *__pyx_t_9 = NULL; + double __pyx_t_10; + int __pyx_t_11; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("new_block", 0); - /* "polluck_blockchain/placeholder_native.pyx":418 + /* "polluck_blockchain/placeholder_native.pyx":445 + * size_t digest_size * - * def new_block(self, data): * if not self._genesis_done: # <<<<<<<<<<<<<< * raise RuntimeError("Create a genesis block first.") - * + * if not isinstance(data, str): */ __pyx_t_1 = (!__pyx_v_self->_genesis_done); if (unlikely(__pyx_t_1)) { - /* "polluck_blockchain/placeholder_native.pyx":419 - * def new_block(self, data): + /* "polluck_blockchain/placeholder_native.pyx":446 + * * if not self._genesis_done: * raise RuntimeError("Create a genesis block first.") # <<<<<<<<<<<<<< - * - * cdef Block *prev_block = self.get_block_c(self._index) + * if not isinstance(data, str): + * raise TypeError("Data must be a string") */ __pyx_t_3 = NULL; __pyx_t_4 = 1; @@ -8046,142 +8538,211 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_mstate_global->__pyx_kp_u_Create_a_genesis_block_first}; __pyx_t_2 = __Pyx_PyObject_FastCall((PyObject*)(((PyTypeObject*)PyExc_RuntimeError)), __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 419, __pyx_L1_error) + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 446, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 419, __pyx_L1_error) + __PYX_ERR(0, 446, __pyx_L1_error) - /* "polluck_blockchain/placeholder_native.pyx":418 + /* "polluck_blockchain/placeholder_native.pyx":445 + * size_t digest_size * - * def new_block(self, data): * if not self._genesis_done: # <<<<<<<<<<<<<< * raise RuntimeError("Create a genesis block first.") + * if not isinstance(data, str): +*/ + } + + /* "polluck_blockchain/placeholder_native.pyx":447 + * if not self._genesis_done: + * raise RuntimeError("Create a genesis block first.") + * if not isinstance(data, str): # <<<<<<<<<<<<<< + * raise TypeError("Data must be a string") + * +*/ + __pyx_t_1 = PyUnicode_Check(__pyx_v_data); + __pyx_t_5 = (!__pyx_t_1); + if (unlikely(__pyx_t_5)) { + + /* "polluck_blockchain/placeholder_native.pyx":448 + * raise RuntimeError("Create a genesis block first.") + * if not isinstance(data, str): + * raise TypeError("Data must be a string") # <<<<<<<<<<<<<< + * + * data_str = self.hash_data(data) +*/ + __pyx_t_3 = NULL; + __pyx_t_4 = 1; + { + PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_mstate_global->__pyx_kp_u_Data_must_be_a_string}; + __pyx_t_2 = __Pyx_PyObject_FastCall((PyObject*)(((PyTypeObject*)PyExc_TypeError)), __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 448, __pyx_L1_error) + + /* "polluck_blockchain/placeholder_native.pyx":447 + * if not self._genesis_done: + * raise RuntimeError("Create a genesis block first.") + * if not isinstance(data, str): # <<<<<<<<<<<<<< + * raise TypeError("Data must be a string") * */ } - /* "polluck_blockchain/placeholder_native.pyx":421 - * raise RuntimeError("Create a genesis block first.") + /* "polluck_blockchain/placeholder_native.pyx":450 + * raise TypeError("Data must be a string") * - * cdef Block *prev_block = self.get_block_c(self._index) # <<<<<<<<<<<<<< - * cdef string prev_hash = prev_block.prev_hash - * cdef uint64_t new_idx = self._index + 1 + * data_str = self.hash_data(data) # <<<<<<<<<<<<<< + * prev_block = self.get_block_c(self._index) + * prev_hash = prev_block.prev_hash */ - __pyx_t_5 = ((struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_Blockchain *)__pyx_v_self->__pyx_vtab)->get_block_c(__pyx_v_self, __pyx_v_self->_index); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 421, __pyx_L1_error) - __pyx_v_prev_block = __pyx_t_5; + __pyx_t_6 = ((struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_Blockchain *)__pyx_v_self->__pyx_vtab)->hash_data(__pyx_v_self, __pyx_v_data); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 450, __pyx_L1_error) + __pyx_v_data_str = __PYX_STD_MOVE_IF_SUPPORTED(__pyx_t_6); - /* "polluck_blockchain/placeholder_native.pyx":422 + /* "polluck_blockchain/placeholder_native.pyx":451 * - * cdef Block *prev_block = self.get_block_c(self._index) - * cdef string prev_hash = prev_block.prev_hash # <<<<<<<<<<<<<< - * cdef uint64_t new_idx = self._index + 1 + * data_str = self.hash_data(data) + * prev_block = self.get_block_c(self._index) # <<<<<<<<<<<<<< + * prev_hash = prev_block.prev_hash + * new_idx = self._index + 1 +*/ + __pyx_t_7 = ((struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_Blockchain *)__pyx_v_self->__pyx_vtab)->get_block_c(__pyx_v_self, __pyx_v_self->_index); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 451, __pyx_L1_error) + __pyx_v_prev_block = __pyx_t_7; + + /* "polluck_blockchain/placeholder_native.pyx":452 + * data_str = self.hash_data(data) + * prev_block = self.get_block_c(self._index) + * prev_hash = prev_block.prev_hash # <<<<<<<<<<<<<< + * new_idx = self._index + 1 * */ __pyx_t_6 = __pyx_v_prev_block->prev_hash; __pyx_v_prev_hash = __PYX_STD_MOVE_IF_SUPPORTED(__pyx_t_6); - /* "polluck_blockchain/placeholder_native.pyx":423 - * cdef Block *prev_block = self.get_block_c(self._index) - * cdef string prev_hash = prev_block.prev_hash - * cdef uint64_t new_idx = self._index + 1 # <<<<<<<<<<<<<< + /* "polluck_blockchain/placeholder_native.pyx":453 + * prev_block = self.get_block_c(self._index) + * prev_hash = prev_block.prev_hash + * new_idx = self._index + 1 # <<<<<<<<<<<<<< * * cdef Block *block = new Block( */ __pyx_v_new_idx = (__pyx_v_self->_index + 1); - /* "polluck_blockchain/placeholder_native.pyx":427 + /* "polluck_blockchain/placeholder_native.pyx":457 * cdef Block *block = new Block( * new_idx, * int(datetime.datetime(2025, 12, 1, 12, 0, 0).timestamp()), # <<<<<<<<<<<<<< * 0, - * data.encode("UTF-8"), + * data_str, */ - __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 427, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 427, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_mstate_global->__pyx_tuple[0], NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 427, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_datetime); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 457, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_3 = __pyx_t_7; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_mstate_global->__pyx_tuple[0], NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 457, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_3 = __pyx_t_8; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; __pyx_t_2 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_timestamp, __pyx_callargs+__pyx_t_4, (1-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 427, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } - __pyx_t_7 = __Pyx_PyNumber_Int(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 427, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyNumber_Int(__pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 457, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_9 = __Pyx_PyFloat_AsDouble(__pyx_t_7); if (unlikely((__pyx_t_9 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 427, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_10 = __Pyx_PyFloat_AsDouble(__pyx_t_8); if (unlikely((__pyx_t_10 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 457, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - /* "polluck_blockchain/placeholder_native.pyx":429 - * int(datetime.datetime(2025, 12, 1, 12, 0, 0).timestamp()), - * 0, - * data.encode("UTF-8"), # <<<<<<<<<<<<<< - * prev_hash, - * "".encode("UTF-8"), -*/ - __pyx_t_2 = __pyx_v_data; - __Pyx_INCREF(__pyx_t_2); - __pyx_t_4 = 0; - { - PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_mstate_global->__pyx_kp_u_UTF_8}; - __pyx_t_7 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_encode, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 429, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - } - __pyx_t_6 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_t_7); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 429, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "polluck_blockchain/placeholder_native.pyx":431 - * data.encode("UTF-8"), + /* "polluck_blockchain/placeholder_native.pyx":461 + * data_str, * prev_hash, * "".encode("UTF-8"), # <<<<<<<<<<<<<< * ) - * self.add_block(block) + * cdef int res = self.add_block(block) */ - __pyx_t_10 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_mstate_global->__pyx_kp_b_); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 431, __pyx_L1_error) + __pyx_t_6 = __pyx_convert_string_from_py_6libcpp_6string_std__in_string(__pyx_mstate_global->__pyx_kp_b_); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 461, __pyx_L1_error) - /* "polluck_blockchain/placeholder_native.pyx":425 - * cdef uint64_t new_idx = self._index + 1 + /* "polluck_blockchain/placeholder_native.pyx":455 + * new_idx = self._index + 1 * * cdef Block *block = new Block( # <<<<<<<<<<<<<< * new_idx, * int(datetime.datetime(2025, 12, 1, 12, 0, 0).timestamp()), */ try { - __pyx_t_5 = new ::Block(__pyx_v_new_idx, __pyx_t_9, 0, __pyx_t_6, __pyx_v_prev_hash, __pyx_t_10); + __pyx_t_7 = new ::Block(__pyx_v_new_idx, __pyx_t_10, 0, __pyx_v_data_str, __pyx_v_prev_hash, __pyx_t_6); } catch(...) { __Pyx_CppExn2PyErr(); - __PYX_ERR(0, 425, __pyx_L1_error) + __PYX_ERR(0, 455, __pyx_L1_error) } - __pyx_v_block = __pyx_t_5; + __pyx_v_block = __pyx_t_7; - /* "polluck_blockchain/placeholder_native.pyx":433 + /* "polluck_blockchain/placeholder_native.pyx":463 * "".encode("UTF-8"), * ) - * self.add_block(block) # <<<<<<<<<<<<<< - * - * # def __init__( + * cdef int res = self.add_block(block) # <<<<<<<<<<<<<< + * if res != 0: + * raise RuntimeError("Could not mine block. No nonce found") */ - ((struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_Blockchain *)__pyx_v_self->__pyx_vtab)->add_block(__pyx_v_self, __pyx_v_block); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 433, __pyx_L1_error) + __pyx_t_11 = ((struct __pyx_vtabstruct_18polluck_blockchain_18placeholder_native_Blockchain *)__pyx_v_self->__pyx_vtab)->add_block(__pyx_v_self, __pyx_v_block); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 463, __pyx_L1_error) + __pyx_v_res = __pyx_t_11; - /* "polluck_blockchain/placeholder_native.pyx":417 + /* "polluck_blockchain/placeholder_native.pyx":464 + * ) + * cdef int res = self.add_block(block) + * if res != 0: # <<<<<<<<<<<<<< + * raise RuntimeError("Could not mine block. No nonce found") + * +*/ + __pyx_t_5 = (__pyx_v_res != 0); + if (unlikely(__pyx_t_5)) { + + /* "polluck_blockchain/placeholder_native.pyx":465 + * cdef int res = self.add_block(block) + * if res != 0: + * raise RuntimeError("Could not mine block. No nonce found") # <<<<<<<<<<<<<< + * +*/ + __pyx_t_2 = NULL; + __pyx_t_4 = 1; + { + PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_mstate_global->__pyx_kp_u_Could_not_mine_block_No_nonce_fo}; + __pyx_t_8 = __Pyx_PyObject_FastCall((PyObject*)(((PyTypeObject*)PyExc_RuntimeError)), __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 465, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + } + __Pyx_Raise(__pyx_t_8, 0, 0, 0); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __PYX_ERR(0, 465, __pyx_L1_error) + + /* "polluck_blockchain/placeholder_native.pyx":464 + * ) + * cdef int res = self.add_block(block) + * if res != 0: # <<<<<<<<<<<<<< + * raise RuntimeError("Could not mine block. No nonce found") + * +*/ + } + + /* "polluck_blockchain/placeholder_native.pyx":436 * self._genesis_done = True * * def new_block(self, data): # <<<<<<<<<<<<<< - * if not self._genesis_done: - * raise RuntimeError("Create a genesis block first.") + * cdef: + * Block *prev_block */ /* function exit code */ @@ -8190,8 +8751,8 @@ static PyObject *__pyx_pf_18polluck_blockchain_18placeholder_native_10Blockchain __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); __Pyx_AddTraceback("polluck_blockchain.placeholder_native.Blockchain.new_block", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -8476,8 +9037,9 @@ static PyObject *__pyx_getprop_18polluck_blockchain_18placeholder_native_7PyBloc static PyMethodDef __pyx_methods_18polluck_blockchain_18placeholder_native_PyBlock[] = { {"bytes_serialize", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_11bytes_serialize, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, - {"__reduce_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_17__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, - {"__setstate_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_19__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {"perform_hash", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_13perform_hash, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {"__reduce_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_15__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {"__setstate_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_18polluck_blockchain_18placeholder_native_7PyBlock_17__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, {0, 0, 0, 0} }; @@ -8628,6 +9190,20 @@ static void __pyx_tp_dealloc_18polluck_blockchain_18placeholder_native_Blockchai #endif } +static PyObject *__pyx_getprop_18polluck_blockchain_18placeholder_native_10Blockchain_difficulty(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_18polluck_blockchain_18placeholder_native_10Blockchain_10difficulty_1__get__(o); +} + +static int __pyx_setprop_18polluck_blockchain_18placeholder_native_10Blockchain_difficulty(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_18polluck_blockchain_18placeholder_native_10Blockchain_10difficulty_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + static PyObject *__pyx_getprop_18polluck_blockchain_18placeholder_native_10Blockchain_genesis_done(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_18polluck_blockchain_18placeholder_native_10Blockchain_12genesis_done_1__get__(o); } @@ -8647,6 +9223,7 @@ static PyMethodDef __pyx_methods_18polluck_blockchain_18placeholder_native_Block }; static struct PyGetSetDef __pyx_getsets_18polluck_blockchain_18placeholder_native_Blockchain[] = { + {"difficulty", __pyx_getprop_18polluck_blockchain_18placeholder_native_10Blockchain_difficulty, __pyx_setprop_18polluck_blockchain_18placeholder_native_10Blockchain_difficulty, 0, 0}, {"genesis_done", __pyx_getprop_18polluck_blockchain_18placeholder_native_10Blockchain_genesis_done, 0, 0, 0}, {"index", __pyx_getprop_18polluck_blockchain_18placeholder_native_10Blockchain_index, 0, 0, 0}, {0, 0, 0, 0, 0} @@ -8818,21 +9395,16 @@ static int __Pyx_modinit_type_init_code(__pyx_mstatetype *__pyx_mstate) { /*--- Type init code ---*/ __pyx_vtabptr_18polluck_blockchain_18placeholder_native_PyBlock = &__pyx_vtable_18polluck_blockchain_18placeholder_native_PyBlock; __pyx_vtable_18polluck_blockchain_18placeholder_native_PyBlock.from_ptr = (struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *(*)(::Block *, struct __pyx_opt_args_18polluck_blockchain_18placeholder_native_7PyBlock_from_ptr *__pyx_optional_args))__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_from_ptr; - __pyx_vtable_18polluck_blockchain_18placeholder_native_PyBlock.bytes_serialize_c = (unsigned char *(*)(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *, size_t *))__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_bytes_serialize_c; - __pyx_vtable_18polluck_blockchain_18placeholder_native_PyBlock.digest = (unsigned char *(*)(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *, unsigned char *, size_t, size_t *))__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_digest; - __pyx_vtable_18polluck_blockchain_18placeholder_native_PyBlock.mine = (PyObject *(*)(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *, unsigned int, int __pyx_skip_dispatch, struct __pyx_opt_args_18polluck_blockchain_18placeholder_native_7PyBlock_mine *__pyx_optional_args))__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_mine; - __pyx_vtable_18polluck_blockchain_18placeholder_native_PyBlock.perform_hash_c = (unsigned char *(*)(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *, size_t *))__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_perform_hash_c; - __pyx_vtable_18polluck_blockchain_18placeholder_native_PyBlock.perform_hash = (PyObject *(*)(struct __pyx_obj_18polluck_blockchain_18placeholder_native_PyBlock *, int __pyx_skip_dispatch))__pyx_f_18polluck_blockchain_18placeholder_native_7PyBlock_perform_hash; #if CYTHON_USE_TYPE_SPECS - __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_18polluck_blockchain_18placeholder_native_PyBlock_spec, NULL); if (unlikely(!__pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock)) __PYX_ERR(0, 88, __pyx_L1_error) - if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_18polluck_blockchain_18placeholder_native_PyBlock_spec, __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock) < (0)) __PYX_ERR(0, 88, __pyx_L1_error) + __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_18polluck_blockchain_18placeholder_native_PyBlock_spec, NULL); if (unlikely(!__pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock)) __PYX_ERR(0, 85, __pyx_L1_error) + if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_18polluck_blockchain_18placeholder_native_PyBlock_spec, __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock) < (0)) __PYX_ERR(0, 85, __pyx_L1_error) #else __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock = &__pyx_type_18polluck_blockchain_18placeholder_native_PyBlock; #endif #if !CYTHON_COMPILING_IN_LIMITED_API #endif #if !CYTHON_USE_TYPE_SPECS - if (__Pyx_PyType_Ready(__pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock) < (0)) __PYX_ERR(0, 88, __pyx_L1_error) + if (__Pyx_PyType_Ready(__pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock) < (0)) __PYX_ERR(0, 85, __pyx_L1_error) #endif #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000 PyUnstable_Object_EnableDeferredRefcount((PyObject*)__pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock); @@ -8842,23 +9414,24 @@ static int __Pyx_modinit_type_init_code(__pyx_mstatetype *__pyx_mstate) { __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock->tp_getattro = PyObject_GenericGetAttr; } #endif - if (__Pyx_SetVtable(__pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock, __pyx_vtabptr_18polluck_blockchain_18placeholder_native_PyBlock) < (0)) __PYX_ERR(0, 88, __pyx_L1_error) - if (__Pyx_MergeVtables(__pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock) < (0)) __PYX_ERR(0, 88, __pyx_L1_error) - if (PyObject_SetAttr(__pyx_m, __pyx_mstate_global->__pyx_n_u_PyBlock_2, (PyObject *) __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock) < (0)) __PYX_ERR(0, 88, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject *) __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock) < (0)) __PYX_ERR(0, 88, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock, __pyx_vtabptr_18polluck_blockchain_18placeholder_native_PyBlock) < (0)) __PYX_ERR(0, 85, __pyx_L1_error) + if (__Pyx_MergeVtables(__pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock) < (0)) __PYX_ERR(0, 85, __pyx_L1_error) + if (PyObject_SetAttr(__pyx_m, __pyx_mstate_global->__pyx_n_u_PyBlock_2, (PyObject *) __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock) < (0)) __PYX_ERR(0, 85, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject *) __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock) < (0)) __PYX_ERR(0, 85, __pyx_L1_error) __pyx_vtabptr_18polluck_blockchain_18placeholder_native_Blockchain = &__pyx_vtable_18polluck_blockchain_18placeholder_native_Blockchain; __pyx_vtable_18polluck_blockchain_18placeholder_native_Blockchain.get_block_c = (::Block *(*)(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *, uint64_t))__pyx_f_18polluck_blockchain_18placeholder_native_10Blockchain_get_block_c; - __pyx_vtable_18polluck_blockchain_18placeholder_native_Blockchain.add_block = (void (*)(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *, ::Block *))__pyx_f_18polluck_blockchain_18placeholder_native_10Blockchain_add_block; + __pyx_vtable_18polluck_blockchain_18placeholder_native_Blockchain.add_block = (int (*)(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *, ::Block *))__pyx_f_18polluck_blockchain_18placeholder_native_10Blockchain_add_block; + __pyx_vtable_18polluck_blockchain_18placeholder_native_Blockchain.hash_data = (std::string (*)(struct __pyx_obj_18polluck_blockchain_18placeholder_native_Blockchain *, PyObject *))__pyx_f_18polluck_blockchain_18placeholder_native_10Blockchain_hash_data; #if CYTHON_USE_TYPE_SPECS - __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_18polluck_blockchain_18placeholder_native_Blockchain_spec, NULL); if (unlikely(!__pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain)) __PYX_ERR(0, 339, __pyx_L1_error) - if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_18polluck_blockchain_18placeholder_native_Blockchain_spec, __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain) < (0)) __PYX_ERR(0, 339, __pyx_L1_error) + __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_18polluck_blockchain_18placeholder_native_Blockchain_spec, NULL); if (unlikely(!__pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain)) __PYX_ERR(0, 307, __pyx_L1_error) + if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_18polluck_blockchain_18placeholder_native_Blockchain_spec, __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain) < (0)) __PYX_ERR(0, 307, __pyx_L1_error) #else __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain = &__pyx_type_18polluck_blockchain_18placeholder_native_Blockchain; #endif #if !CYTHON_COMPILING_IN_LIMITED_API #endif #if !CYTHON_USE_TYPE_SPECS - if (__Pyx_PyType_Ready(__pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain) < (0)) __PYX_ERR(0, 339, __pyx_L1_error) + if (__Pyx_PyType_Ready(__pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain) < (0)) __PYX_ERR(0, 307, __pyx_L1_error) #endif #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000 PyUnstable_Object_EnableDeferredRefcount((PyObject*)__pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain); @@ -8868,10 +9441,10 @@ static int __Pyx_modinit_type_init_code(__pyx_mstatetype *__pyx_mstate) { __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain->tp_getattro = PyObject_GenericGetAttr; } #endif - if (__Pyx_SetVtable(__pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain, __pyx_vtabptr_18polluck_blockchain_18placeholder_native_Blockchain) < (0)) __PYX_ERR(0, 339, __pyx_L1_error) - if (__Pyx_MergeVtables(__pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain) < (0)) __PYX_ERR(0, 339, __pyx_L1_error) - if (PyObject_SetAttr(__pyx_m, __pyx_mstate_global->__pyx_n_u_Blockchain, (PyObject *) __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain) < (0)) __PYX_ERR(0, 339, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject *) __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain) < (0)) __PYX_ERR(0, 339, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain, __pyx_vtabptr_18polluck_blockchain_18placeholder_native_Blockchain) < (0)) __PYX_ERR(0, 307, __pyx_L1_error) + if (__Pyx_MergeVtables(__pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain) < (0)) __PYX_ERR(0, 307, __pyx_L1_error) + if (PyObject_SetAttr(__pyx_m, __pyx_mstate_global->__pyx_n_u_Blockchain, (PyObject *) __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain) < (0)) __PYX_ERR(0, 307, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject *) __pyx_mstate->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain) < (0)) __PYX_ERR(0, 307, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -9237,50 +9810,34 @@ __Pyx_RefNannySetupContext("PyInit_placeholder_native", 0); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_dopt_basics, __pyx_t_2) < (0)) __PYX_ERR(0, 13, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "polluck_blockchain/placeholder_native.pyx":254 - * return digest + /* "polluck_blockchain/placeholder_native.pyx":166 + * return self.BlockC.hash.decode("UTF-8") * * def bytes_serialize(self): # <<<<<<<<<<<<<< * cdef: * unsigned char *serialize_res */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_7PyBlock_11bytes_serialize, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_PyBlock_bytes_serialize, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[0])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 254, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_7PyBlock_11bytes_serialize, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_PyBlock_bytes_serialize, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[0])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 166, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000 PyUnstable_Object_EnableDeferredRefcount(__pyx_t_2); #endif - if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock, __pyx_mstate_global->__pyx_n_u_bytes_serialize, __pyx_t_2) < (0)) __PYX_ERR(0, 254, __pyx_L1_error) + if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock, __pyx_mstate_global->__pyx_n_u_bytes_serialize, __pyx_t_2) < (0)) __PYX_ERR(0, 166, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "polluck_blockchain/placeholder_native.pyx":264 - * free(serialize_res) + /* "polluck_blockchain/placeholder_native.pyx":177 * - * cpdef mine(self, unsigned int difficulty, unsigned int max_nonce=0xFFFFFFFF): # <<<<<<<<<<<<<< - * cdef: - * unsigned char *serial_buf -*/ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_7PyBlock_13mine, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_PyBlock_mine, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[1])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000 - PyUnstable_Object_EnableDeferredRefcount(__pyx_t_2); - #endif - __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_2, __pyx_mstate_global->__pyx_tuple[1]); - if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock, __pyx_mstate_global->__pyx_n_u_mine, __pyx_t_2) < (0)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "polluck_blockchain/placeholder_native.pyx":309 - * return digest * - * cpdef perform_hash(self): # <<<<<<<<<<<<<< + * def perform_hash(self): # <<<<<<<<<<<<<< * cdef: * unsigned char *digest */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_7PyBlock_15perform_hash, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_PyBlock_perform_hash, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[2])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 309, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_7PyBlock_13perform_hash, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_PyBlock_perform_hash, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[1])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 177, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000 PyUnstable_Object_EnableDeferredRefcount(__pyx_t_2); #endif - if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock, __pyx_mstate_global->__pyx_n_u_perform_hash, __pyx_t_2) < (0)) __PYX_ERR(0, 309, __pyx_L1_error) + if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_18polluck_blockchain_18placeholder_native_PyBlock, __pyx_mstate_global->__pyx_n_u_perform_hash, __pyx_t_2) < (0)) __PYX_ERR(0, 177, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "(tree fragment)":1 @@ -9288,7 +9845,7 @@ __Pyx_RefNannySetupContext("PyInit_placeholder_native", 0); * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" * def __setstate_cython__(self, __pyx_state): */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_7PyBlock_17__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_PyBlock___reduce_cython, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[3])); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_7PyBlock_15__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_PyBlock___reduce_cython, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[2])); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000 PyUnstable_Object_EnableDeferredRefcount(__pyx_t_2); @@ -9302,7 +9859,7 @@ __Pyx_RefNannySetupContext("PyInit_placeholder_native", 0); * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_7PyBlock_19__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_PyBlock___setstate_cython, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[4])); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_7PyBlock_17__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_PyBlock___setstate_cython, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[3])); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000 PyUnstable_Object_EnableDeferredRefcount(__pyx_t_2); @@ -9310,64 +9867,64 @@ __Pyx_RefNannySetupContext("PyInit_placeholder_native", 0); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_setstate_cython, __pyx_t_2) < (0)) __PYX_ERR(1, 3, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "polluck_blockchain/placeholder_native.pyx":370 - * return self._index + 1 + /* "polluck_blockchain/placeholder_native.pyx":359 + * return self._index * * def print_key_value_pair(self): # <<<<<<<<<<<<<< * cdef BcHashmap.iterator it = self._chain.begin() * cdef Block *block */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_10Blockchain_9print_key_value_pair, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Blockchain_print_key_value_pair, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[5])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 370, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_10Blockchain_9print_key_value_pair, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Blockchain_print_key_value_pair, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[4])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000 PyUnstable_Object_EnableDeferredRefcount(__pyx_t_2); #endif - if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain, __pyx_mstate_global->__pyx_n_u_print_key_value_pair, __pyx_t_2) < (0)) __PYX_ERR(0, 370, __pyx_L1_error) + if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain, __pyx_mstate_global->__pyx_n_u_print_key_value_pair, __pyx_t_2) < (0)) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "polluck_blockchain/placeholder_native.pyx":392 - * return self._chain[0][idx] + /* "polluck_blockchain/placeholder_native.pyx":396 * + * # // Python public API * def get_block(self, idx): # <<<<<<<<<<<<<< * if idx < 0 or idx > self._index: * raise IndexError("Index value is out of bounds") */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_10Blockchain_11get_block, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Blockchain_get_block, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[6])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 392, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_10Blockchain_11get_block, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Blockchain_get_block, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[5])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 396, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000 PyUnstable_Object_EnableDeferredRefcount(__pyx_t_2); #endif - if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain, __pyx_mstate_global->__pyx_n_u_get_block, __pyx_t_2) < (0)) __PYX_ERR(0, 392, __pyx_L1_error) + if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain, __pyx_mstate_global->__pyx_n_u_get_block, __pyx_t_2) < (0)) __PYX_ERR(0, 396, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "polluck_blockchain/placeholder_native.pyx":404 - * self._index += 1 + /* "polluck_blockchain/placeholder_native.pyx":419 + * return data_str * * def create_genesis_block(self): # <<<<<<<<<<<<<< - * cdef Block *block = new Block( - * self._index, + * genesis_prev_hash = ("0" * 64).encode("UTF-8") + * cdef string data_str = self.hash_data("Genesis Block") */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_10Blockchain_13create_genesis_block, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Blockchain_create_genesis_block, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[7])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 404, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_10Blockchain_13create_genesis_block, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Blockchain_create_genesis_block, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[6])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 419, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000 PyUnstable_Object_EnableDeferredRefcount(__pyx_t_2); #endif - if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain, __pyx_mstate_global->__pyx_n_u_create_genesis_block, __pyx_t_2) < (0)) __PYX_ERR(0, 404, __pyx_L1_error) + if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain, __pyx_mstate_global->__pyx_n_u_create_genesis_block, __pyx_t_2) < (0)) __PYX_ERR(0, 419, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "polluck_blockchain/placeholder_native.pyx":417 + /* "polluck_blockchain/placeholder_native.pyx":436 * self._genesis_done = True * * def new_block(self, data): # <<<<<<<<<<<<<< - * if not self._genesis_done: - * raise RuntimeError("Create a genesis block first.") + * cdef: + * Block *prev_block */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_10Blockchain_15new_block, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Blockchain_new_block, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[8])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 417, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_10Blockchain_15new_block, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Blockchain_new_block, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[7])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 436, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000 PyUnstable_Object_EnableDeferredRefcount(__pyx_t_2); #endif - if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain, __pyx_mstate_global->__pyx_n_u_new_block, __pyx_t_2) < (0)) __PYX_ERR(0, 417, __pyx_L1_error) + if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_18polluck_blockchain_18placeholder_native_Blockchain, __pyx_mstate_global->__pyx_n_u_new_block, __pyx_t_2) < (0)) __PYX_ERR(0, 436, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "(tree fragment)":1 @@ -9375,7 +9932,7 @@ __Pyx_RefNannySetupContext("PyInit_placeholder_native", 0); * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" * def __setstate_cython__(self, __pyx_state): */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_10Blockchain_17__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Blockchain___reduce_cython, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[9])); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_10Blockchain_17__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Blockchain___reduce_cython, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[8])); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000 PyUnstable_Object_EnableDeferredRefcount(__pyx_t_2); @@ -9389,7 +9946,7 @@ __Pyx_RefNannySetupContext("PyInit_placeholder_native", 0); * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" */ - __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_10Blockchain_19__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Blockchain___setstate_cython, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[10])); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_18polluck_blockchain_18placeholder_native_10Blockchain_19__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Blockchain___setstate_cython, NULL, __pyx_mstate_global->__pyx_n_u_polluck_blockchain_placeholder_n, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[9])); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030E0000 PyUnstable_Object_EnableDeferredRefcount(__pyx_t_2); @@ -9443,7 +10000,7 @@ __Pyx_RefNannySetupContext("PyInit_placeholder_native", 0); static int __Pyx_InitCachedBuiltins(__pyx_mstatetype *__pyx_mstate) { CYTHON_UNUSED_VAR(__pyx_mstate); - __pyx_builtin_print = __Pyx_GetBuiltinName(__pyx_mstate->__pyx_n_u_print); if (!__pyx_builtin_print) __PYX_ERR(0, 374, __pyx_L1_error) + __pyx_builtin_print = __Pyx_GetBuiltinName(__pyx_mstate->__pyx_n_u_print); if (!__pyx_builtin_print) __PYX_ERR(0, 363, __pyx_L1_error) /* Cached unbound methods */ __pyx_mstate->__pyx_umethod_PyDict_Type_items.type = (PyObject*)&PyDict_Type; @@ -9463,31 +10020,20 @@ static int __Pyx_InitCachedConstants(__pyx_mstatetype *__pyx_mstate) { CYTHON_UNUSED_VAR(__pyx_mstate); __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "polluck_blockchain/placeholder_native.pyx":104 + /* "polluck_blockchain/placeholder_native.pyx":101 * self.BlockC = new Block( * index, * int(datetime.datetime(2025, 12, 1, 12, 0, 0).timestamp()), # <<<<<<<<<<<<<< * nonce, * data.encode("UTF-8"), */ - __pyx_mstate_global->__pyx_tuple[0] = PyTuple_Pack(6, __pyx_mstate_global->__pyx_int_2025, __pyx_mstate_global->__pyx_int_12, __pyx_mstate_global->__pyx_int_1, __pyx_mstate_global->__pyx_int_12, __pyx_mstate_global->__pyx_int_0, __pyx_mstate_global->__pyx_int_0); if (unlikely(!__pyx_mstate_global->__pyx_tuple[0])) __PYX_ERR(0, 104, __pyx_L1_error) + __pyx_mstate_global->__pyx_tuple[0] = PyTuple_Pack(6, __pyx_mstate_global->__pyx_int_2025, __pyx_mstate_global->__pyx_int_12, __pyx_mstate_global->__pyx_int_1, __pyx_mstate_global->__pyx_int_12, __pyx_mstate_global->__pyx_int_0, __pyx_mstate_global->__pyx_int_0); if (unlikely(!__pyx_mstate_global->__pyx_tuple[0])) __PYX_ERR(0, 101, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[0]); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[0]); - - /* "polluck_blockchain/placeholder_native.pyx":264 - * free(serialize_res) - * - * cpdef mine(self, unsigned int difficulty, unsigned int max_nonce=0xFFFFFFFF): # <<<<<<<<<<<<<< - * cdef: - * unsigned char *serial_buf -*/ - __pyx_mstate_global->__pyx_tuple[1] = PyTuple_Pack(1, __pyx_mstate_global->__pyx_int_4294967295); if (unlikely(!__pyx_mstate_global->__pyx_tuple[1])) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[1]); - __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[1]); #if CYTHON_IMMORTAL_CONSTANTS { PyObject **table = __pyx_mstate->__pyx_tuple; - for (Py_ssize_t i=0; i<2; ++i) { + for (Py_ssize_t i=0; i<1; ++i) { #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING Py_SET_REFCNT(table[i], _Py_IMMORTAL_REFCNT_LOCAL); #else @@ -9507,34 +10053,34 @@ static int __Pyx_InitCachedConstants(__pyx_mstatetype *__pyx_mstate) { static int __Pyx_InitConstants(__pyx_mstatetype *__pyx_mstate) { CYTHON_UNUSED_VAR(__pyx_mstate); { - const struct { const unsigned int length: 8; } index[] = {{25},{29},{28},{20},{8},{5},{1},{1},{7},{6},{2},{9},{50},{45},{14},{10},{28},{30},{31},{20},{20},{31},{7},{25},{27},{23},{12},{20},{20},{12},{18},{5},{15},{18},{20},{4},{8},{10},{11},{20},{6},{8},{13},{8},{9},{12},{4},{7},{3},{3},{5},{13},{2},{5},{8},{9},{4},{10},{8},{9},{7},{5},{12},{37},{3},{10},{9},{13},{5},{20},{8},{11},{14},{12},{10},{17},{13},{8},{4},{13},{14},{12},{10},{12},{19},{6},{8},{4},{9},{6},{0},{1},{13},{10},{52},{121},{37},{101},{71},{73},{137},{9}}; - #if (CYTHON_COMPRESS_STRINGS) == 2 /* compression: bz2 (1159 bytes) */ -const char* const cstring = "BZh91AY&SY\210\325\3277\000\000\241\177\377\375\377\377\357\367\177\374\347\277\367\367\326\277\357\377\360@@@@@@@@@@@@@\000@\000P\003\376-`\000\003c\203T\365OB\217D\323\000\364\215M\036\246\2004d\000\014\203 4\032\000\320\320\321\246M\2420'\224\021=P\241\264\322\031=\033R2hi\223\023\02020\214\215\r\006\232m\021\243\322\0314\320\0322\032\r\001\223f\210 #\021\223L\230LL\230&\023\023A\221\202\032\030\023\004\302\006\201\200\010\034\000\000\000\320\000\000\003@\r\000\000\320\000\003@\000\000\000\224\322&CS \230\232m&\2024CM\032\000\032\000\000\000\000\000\r\007\251\243'\246\245\225\323\337f\376\217\357\262\334\275\230\302+\266\34773\304\355\310\2377?=\202\020\201!2U\031\005\"\254\366\363\232\214\315U\203\026\211\231\257DZj4xf\007F\264:%!\0165\310E\3232d\310\373\361\252\251M\225\316\362\261\224%7\2448\2366\226Jj56 B\361+,Z\246F\251\370\265t\351\262\330$\300QDQf\023\327\201\331=;\365A*\2102gN\"\014\260IX\230\374J\177F@\314|\034&\0018@\341\020\001\034z\245\224\263u\033\020\010\354\"\221b\231n\024V'3\033$\3347\023c\000\340\202\350 \362(|\207[\305\007\315+f\n:t\207\277\306r\235*\2774\353\322\"\351[\367\376Y\366\377\035]\330\233\347m\3134bq\3623\302\035\357'`\360%5_\301\0137?\031D\244\306-G\"\222f\277\210?\3103@!S\361p\367y\343\2737 \245\201\246\005\320\024\220Mw\027\035\204c\334\276\0263:\021\377%\030\325V;\t\262\304<\"W\006\035LL:\212jP\205\326Fj\317\034\355U\231\203\026c\376\310\202\235\310\005\032\262u\263X.\307\016m3\031\310\025\233K5\340\333\355\325\342\200\373m\326g\353\206\2101\274\230}\273l:[3xI\360\032\215\002l\026\2774\330i\010bH/\252T+\275\253Q\033\241\227r<\026W\212\334\273\327\314\231\177\354\263\361\306\003W:b/\246\305\230\341\207=\037\031\261\346F\017S\306\t$\221\031\225\033\255S\312q\031?\373\300\320\221^g\265\362\234\272\332\253\361ZtJ\303\035\245\030\223\336ZH\201\007\202h\265M^\013\241\326\320i\312\332z\032\250(\276\212B.`\213\266\230\364\260D\306\232g%E\206q\2347n\013\240r\343\207N\232,c\204b\021\324J\242\334\211\226*\313q\030\321LS\315n4S\025i\266\361V""\014\326\210\273a\263xZ\002\3552\232bB\244\271FL\223&\022I$V\320\"\027\222\245\352-\255\215wYUD'\272\246\300\230I@\267\324\233W&\343\224:\325\272b\001I\355\211\253x\216\307\213t\360\303\2069A\233V\345{\306\263Ql\006M\013\315\362\262=\3440\302\352P\302\355\303F\237\321\362\2740Y\265U-/\"\273)(\03388\305\303\324\352@\214Cs\036C\036~\rZ\313\357Be[VV\201;,\306\360\212\020\271\332\311\341\236-tGUR\n\333\334k\2650L \374\217\r)\257 \233\371ym\313}8\261\325\215\343\270b8\005\311J\200\203\214O\242]\001\306\211\235F\342R8m\252\226\365\325\214_\250\327\3219\360\032\243Rt\332_\031\241\360\2135\2242\231\014\231\2320M\214Z\004bq\350-\375=\240-\211\206\216C0\325I\030\206&\231\262\330\016{i\363\233|\324X5b\272@\002\\\304\231\016f\204\036\252\217I\201\311\t\013\324\002\254\201f\200f\340\231\014\025\21284H\024\035\351\343\302\tP\234\256m/\266*\001j\252\253B\260\205h\372\347@\362\314{wL\r\014\342\026{YwO[\000'\032\277\023T{E\301\022!FZ\335\257c\225\321\000e\024\247\372-Ja\250\360\006\343\340\327\250\236\037Ee'K\256/\332k`M\037\336)\031\332\241\305\\=\005\334\303\227\205\"\n\356Bd%\017j \212\000c\022\232\t\300\200\177aJi\302<\233(\036\"\024\210\211\021\234!\202@@\006\004\000\024tL\037\370\273\222)\302\204\204F\256\271\270"; - PyObject *data = __Pyx_DecompressString(cstring, 1159, 2); + const struct { const unsigned int length: 8; } index[] = {{25},{36},{29},{21},{33},{32},{19},{13},{28},{24},{8},{5},{1},{1},{7},{6},{2},{9},{50},{45},{14},{10},{28},{30},{31},{20},{20},{31},{7},{25},{27},{23},{20},{20},{12},{18},{5},{15},{18},{20},{15},{16},{4},{11},{8},{8},{6},{11},{11},{20},{6},{8},{13},{8},{17},{9},{12},{4},{7},{3},{3},{5},{13},{2},{5},{8},{10},{8},{9},{7},{5},{12},{37},{3},{10},{9},{13},{5},{20},{8},{11},{14},{12},{10},{17},{13},{8},{3},{4},{13},{14},{12},{10},{12},{19},{6},{8},{4},{9},{6},{0},{64},{75},{70},{170},{39},{71},{118},{9}}; + #if (CYTHON_COMPRESS_STRINGS) == 2 /* compression: bz2 (1195 bytes) */ +const char* const cstring = "BZh91AY&SY\235r\326;\000\000\242\177\377\375\377\377\247\367\177\375W\277\267\3673\277\357\377\360@@@@@@@@@@@@@\000@\000P\004,(\231\211\017J\341\004\242\212yS\362\r'\243M)\343F\224\037\252\006\217Q\352\006\203 \r\000\006OH\003\320L\301M\350\236\224\032%\033M\031L\324\021\351\036\246\206\200\000\000\000\000\000\000\000\000\000\000Jh\202\232i\241\240\230M\rS\322\006\232h\000\320\000\000\000\000\001\351\036\241\265\0321\016\000\001\240\001\240\r\000\000\0321\000\003@\000\000\000\003@\006\251\351)\247\350P\375S\323Bz\236\246\322\006\201\204\000d\302h2d\030\203L@\032h\032a\006\035q\377p\030\214+\227*fS\215\222V\245\317\241\2614\n\252\212\202\243E$lq\272\223\032\213\330\260\033\010\222a\273\212X\346\266\263:\004\244\202\344#\0216\310\2368\356\301Q\244\356\343\272I\261\275\260\325\201\322\347\350\353s\377|\302\t?_\367\376\267\1773\257]\346\271\321)v\211\223\355)\333N\314\260R3h\327\274\333\255\242o\307\252$_\357\322\250\356 \372\366\365\253\242\035#K\351D#:\354K\335oF\334\271s(Z\036\362\366\035{\225)\253\r1\3734)\207Q\033\240\323)\022\017+\366\212\211\263\277\275-\307\211'\177\240\177L\247\273\275F\031\030\177\2208no\301\0168\340\262f.\375\3146\351r\366p\207\027K\370:\224\235~G\2575\224\2431b9T\320\030\271\003\253\000<\002\233\347\343\357\263KBu>CD\027@\260\240\252\355\255\366\022\227o\034X7\022\204#\376\233\273\316\223\313\204\252.\036E0@\321\003\260\363zX\344,S\2406\363j\240\323\213:\361\231\256\254\010\017@gB|\325\020\240\216\2168\240N\027\016.PT\256\340\214##\245\302\332F,w\256\0149d\250\220D\014\014\241aPb8\347\317.\332m\341\2420L)\n \026\213gA\022A\202\t2\205\303K\002\241\001F\021\374\340+\331\255z\2105\211\220O\2351\260\245\311o\207\212D\013\3625\233\200\301)O\010\"\211u/F\211\007J*\344\374\017y\275\352:\223\304$\222F\n\023'\240)\027\361YE*\014\361\331\233F\034\006\033!g:7\005\265\306\365\226\023\244X\031&Z5G\2561\005\010!\3414\202m\200\326\272^\037!\262\366\330r\2346\210\223\351\267\024\247\014\365n,R\2357\233\262\232\230'%\322Q\222#I0$\022\n\2053@lN\n\331\2416""\022\244\211\345E\200\214\020\223\n_ZC\004\263\t4-\340\311A&\026lvs\3550\266:dm\254P\004O\203\022\250\n\003h\264\355M\217V\014\014TWS\241 L\204\311\204\222M`A&2\024\305\222M\210h\317\353\310\307Y4=\030\020$)\026R\255\206\207N\220W\304O7\t1\307^I6\273\215\311\240\2526l7\306Pf\340\342\301\254\330j0\300\310\244\2567\020Rm\323$m\333u\265m\267h4\347\346{\3365,\324\325J\360=I\331m \341\342\345\027/\240\341\001\214S\004:|fZ\031\310A\002\013\221\202\300,\024 \010\031\"`4\0250\374F!S3\265,\335\246MU!)N\313\347v(q\261\354\030\261\210\036\367\202\326\275\303!$\316>\336\303\340\274\343\311s\"\327\337|\357yi.9\014\017(\264;\305\014\022N0\300P\317\302\014\027L$\231\303$e\201\316\016\024p\256\021\t\004\252A\001\303\221\240\033\020\205\346\306\251\261:\rC\3458\r\322\007ZY:0\343l\346C6\206\244\344\232\364p\010Qh\213N\301i\022v\221VB\220\232M(\335\021'\273\336\341\301\267^\343^\375\244\330R\372m\230\321UW\332\016\2333\305\345\344\207\2225\264\210\260\214}\303\360a\272~\212\247\227'\006\r\303\004>;\346\356\305_\215]E\372V1\034\356\037\252\177x\205\310\222\372X\305\257\327R\266?>Z\375\311s3v\317\001\025\214jh\263\225}\221g\"\276f\267\323I\254\323\254A$\223k\312q\366\037\371R\233M/\227\255\304\365\202n\321\3154^\267\333\227\260u7k\356\275M=RzS\373DJ\024\034!$\324\210{\224\324\241F\214P\245\030\024\334\255^\2579\267\376.\344\212p\241!:\345\254v"; + PyObject *data = __Pyx_DecompressString(cstring, 1195, 2); if (unlikely(!data)) __PYX_ERR(0, 1, __pyx_L1_error) const char* const bytes = __Pyx_PyBytes_AsString(data); #if !CYTHON_ASSUME_SAFE_MACROS if (likely(bytes)); else { Py_DECREF(data); __PYX_ERR(0, 1, __pyx_L1_error) } #endif - #elif (CYTHON_COMPRESS_STRINGS) != 0 /* compression: zlib (1032 bytes) */ -const char* const cstring = "x\332\205TKo\0337\020\216Z\243\226\335\265\243\215\345\246F\372X\005I\2216\215R'\005\332\002}@~4\261\3218U\341\264E\341\202\240\270\224Ex\265\\\355r\035\251'\037u\344\221G\036\367\270G\037u\354Q\307=\352'\344't\270zX\255\014\364\260\344pf8\217o>\356.\217=\327\361\271p\260\347q\202\005uZ8j\343`7\244\346\200\235S\352\323\210EN\003\314gN\223\205\221\250\036\370.\355:\347\330\213\251\003&\036\013\2077\235\006\217}7:\342\306\300LP\237P\247i\224?\367v\314\355\007\257\216\177|\364\365\247?\270,\302\r\217R\337\254\247\204Ec\311\365\271\343\322&\216=\341 \024R7&\024!\307\205$\202\233p\217D\310\316\031\366\300J\230\317\004BQH\036\007\334\363br\206\362\002I\0133\377q\340aB[\334si\210|,\3309\255\006\275\356\267\021\334\367O#\036\207\204~\2773s\277\222\252\263\264\244'Z\334G\350_\266\210\212H\000*\327YI\216\027\232\2405.f\316|J\305\202\316\247\257\027t\001T(\320\031\355\241\034]\024`\026N\320\233l\2135^\031\026\n\234\232\032=A#0\207\200\036\373\213N\325m\346\317\344\200\206M\036\266\021\214\277e.v\341\333cD\240#\332\025\277\320\346\361\301\213\375?^\036\355\243W\307\2738\352\371\204\361*\341!\314\036\202Dy\037\377\311B<\260 \346#\021\3028\032\030z\274\006$\027\013\014\037\025\254M]\326l2\002\363\357\271<\000\300p\304H4'V\247\216\324'\034\250\022\3626\nDhv\243\205\336\333\001B\315\330'\010\315\020\317\3051,ys\346\363X\243E\273\314\3552\303d\004\265\314Za\202\t\332\216\020j\303<\314\332E9\223\rVp\344n\354\301\216\200Wm\330g34\002\304\313]\347\241\\dgu\221\235\001\017\202\220\236\217\235r)\277\n\002\343q49\0001\256cG\320\233\266\t\024G\223>\215x.\314\2432\245vb\354\215\313\275zV\013,\232)\000\217\374\020\204\206P^s6O\320EW\207\310,\206q\023$@\232<\3369\036\242k8\t\2570\006Z!\340\212Yan\263\331\345]E_<\233\374rrb\272q\273\3353?\245\326E-+\276\333\377\262\037\312[\362\251t\325]\265\247\013\231uK~\246j\252>*~\000g+\251%\365\254\370\236d\252\243\327\222\372\364\216\220\333\306\363s\205UgT\254\350\262>I\355\364^\212\263\242\243W\223\212\331\226\364\363d'\301&\320\201\256g\326Zf\335\354w""dQ\255h[\177\222,%\273\211H\237\246\215\313\325A%\267\226\344\262\354\250B.\257\367Oe]\302e\253\177(\261\354\\\324\336\024o\254\254f\026T5t\236\244\225t;\255e\326\206\374N\277\245+#\270[\220\266\251n\222\014\316\377\227\356\216\372JW\364\266q{mR\314%]\353\377.O\364\355\244\220\330\331\264\002\020\206\326\207*\207\340\276>Nn\247\357\244\340\272\336'rC\356\251e%L,[\332\200\n\321vf\225\345O\372m\243\373H1\335I\nc#\344\336R\266\252@C\253yC\233\362X}l2\001jy)D\331Y\311\036\303\321U\261\256\351_\223'\311\237\227\367.\033\203\345A\347\357\302\244\333Q\361\246\231\303pi\177P\177c\335Xs\024\264\360 )\214\212\020r\270\3650\3316\303\033\255\255\233P+j\323\314*+9\272\240\357\300\\\374\313\303\001\316J[\252\254~\203\024'\303\355\332\300\036TF\245\215\341\006\004I\336O\355\254|WW\262\362}\300\263\2749*\225eM\002-\314\370;s\303\267\372\317\3447\352P\343\213B\266\264\332\177(\353\377\000\243\266\303)"; - PyObject *data = __Pyx_DecompressString(cstring, 1032, 1); + #elif (CYTHON_COMPRESS_STRINGS) != 0 /* compression: zlib (1048 bytes) */ +const char* const cstring = "x\332\255S\315o\033E\024\257\241\"Np?\234\264TH)\254Q\251\010\020\267\241\025B\025\037r\343\026\005\225P\243\024\t$\030\215g\307\366(\353\235\365\314\254k\347\224\243\217s\234\343\036\367\350c\2169r\354q\217\376\023\370\023x3\273\331\004\234\033X\336\3357\357\363\367~\357\315.\217\003\337\013\271\362p\020p\202\025\365\006X\016q\264[\032\206,\244^\027\214\207Mo\237\203*$\324\353\3618\364w\005\265\001\330\353\323\220J&s/\257\307\204T\3156V\330\033\306Ry]\353\"\225`a\277\315z=F\342@MKS\337%\021\236\032\340\320{x\211\003\013\025\355\203\303\030\0071}\216Y@}Oq\013s\340\371P\344\373\242\370S[|/\364\351$w\365@\307c\345\361\236\327\265h\345K\301\307\314\207h\346\234lo\256\215\227S\027\372\311\253\203\347\333_m}\3473\211\273\001\245\241}\367\t\223\271\344\207\334\363i\017\0036\017!A\375\230P\204<\037\n)\307\3126t8f8\000+a!S\010IA\036D<\010br\210\0345d\200Y\370 \n0\241\003\036\370T\240\020+6\246\315h:\371:gH\362X\020\372\355\323\322\375\\j\226e\311T\rx\210\320?l\222*\251\200\312\313\254\304\221\214\2129\345`.\230\373T-\351B\372zI\027\001B\205\016\351\0249\206Q\204\231(\330+>\313\030\317\rK\000\317L\335\251\242\022\314\002\330cG\364L\035Q\321\343b\210\354\244\255\363\004\2366#\n\355\323\211\372\231\366\016\366~|\366\333O\373\317\320\253\203],\247!a\274I\270\200\231\303\306J\207\375_\231I\000\026\304B\244\004\214\240\213\241\257K\210!\261\020\024\372TlH\221:\"\261BCF\004\227\224pX#\273s\366A>\353S\251\234\010\263\203/\265\021\205\326\275\221\204\242>\217\200],\031\221\027\304\346\231?\r\t\207\275\022|\210\"%\354\327j\201\250a\204P/\016\t*\321E\202\216\035\033\345\274\254\255 \325\031\354\023\260\356\200N\230?qk\216 \256$\205)\246\350P\"4\204i\"\370\r\271\037\007\324J!\206fQ9t+@\nw\331/\316ay\235\233\313\353\034\361\310AuN%h+0\036\313\342\000\233t\331:E\323\263\316\340N\240\2425+\216\225\275\205\026\352(\306A\016\367\374\036.\255]\251\000\n\334!\022\366-%\rz\345>\344\212\263\203\035\226\333\322\202\014\220\212\013\177aw\321%{\014\323\217a-\221\262#wkS\216\3205&\037\376\307\337q""\353\257\265+\253kY\355\266\376#\331I\332\351\352\274>od\265\033\263\327\232\230zv\263\276\250\335\324+zb\342\244\225\374\222~\221\376~r\357\244{\272r:\372\263bM\025]_To\314\224\3369ne\325wg\217gB\257\353G\3327\037\231vR\311j\353\372S\3232\235Eu\023\316\265\264\225v\254\333\227zC\267JcV}O33J\256\245\035\000\264~e\265\006y \245u\370\334`3\3123\037\231\272\271\237\347\3342;\246\265\250n\350\307\372(\251'\215\254z[\037\230\315\244\223\370)\034n\351\037\014\316\252\353\372\236\036\230nR\261\325\367\222NV\273f[\033\351\252Y\205\250\373\351\325t7U\363G\363\356\311\332i\303Y\363\377\365Y_w4^T\357he\236@V\234#\220\272Qb\002\244UG\335\346\233\315\355\264\223\372\363\255\223\235\023hjC\177\223\274\2254\nv,-\037'\007\351\235\371;sHx}F\240\365\266Y1*\201\376\352\272\016\331HR\317j\267\364\213\344m\253\373\300\260d\224Vr#\324{\037\332n\3304w\315\257I\037*\001\230\017!\374\211\025\313\316\240\330\377\327[V\255\275\251\3355\235\343Jvum\366\231\356\374\r:+\003\346"; + PyObject *data = __Pyx_DecompressString(cstring, 1048, 1); if (unlikely(!data)) __PYX_ERR(0, 1, __pyx_L1_error) const char* const bytes = __Pyx_PyBytes_AsString(data); #if !CYTHON_ASSUME_SAFE_MACROS if (likely(bytes)); else { Py_DECREF(data); __PYX_ERR(0, 1, __pyx_L1_error) } #endif - #else /* compression: none (1797 bytes) */ -const char* const bytes = "Could not allocate hasmapCreate a genesis block first.Index value is out of boundsNo valid nonce foundPyBlock(UTF-8)?disableenablegcisenabledno default __reduce__ due to non-trivial __cinit__src/polluck_blockchain/placeholder_native.pyxBlockchainBlockchain.__reduce_cython__Blockchain.__setstate_cython__Blockchain.create_genesis_blockBlockchain.get_blockBlockchain.new_blockBlockchain.print_key_value_pairPyBlockPyBlock.__reduce_cython__PyBlock.__setstate_cython__PyBlock.bytes_serializePyBlock.minePyBlock.perform_hash__Pyx_PyDict_NextRefTIMEZONE_UTCasyncio.coroutinesblockbytes_serializecline_in_tracebackcreate_genesis_blockdatadatetimedifficultydopt_basicsdopt_basics.datetimeencodefrom_ptrfromtimestamp__func__get_block__getstate__hashhashlibhexidxindex_is_coroutineititems__main__max_noncemine__module____name__new_blocknew_idxnonceperform_hashpolluck_blockchain.placeholder_nativepopprev_blockprev_hashprevious_hashprintprint_key_value_pairpy_block__pyx_state__pyx_vtable____qualname____reduce____reduce_cython____reduce_ex____repr__selfserialize_resserialize_size__set_name__setdefault__setstate____setstate_cython__struct__test__timetimestampvalues0Genesis Blockdummy hash\200A\330\010\013\2104\210r\220\022\2203\220d\230\"\230D\240\001\330\014\022\220*\230A\230Q\340\010\034\230D\240\014\250A\250Q\330\010\026\220i\230q\240\r\250Q\200A\330\010\013\2104\210t\2201\330\014\022\220,\230a\230q\340\010!\240\024\240\\\260\021\260$\260a\330\010 \240\n\250!\330\010 \240\004\240H\250B\250a\340\010\034\230I\240Q\330\014\r\330\014\017\210q\220\010\230\t\240\021\240&\250\004\250C\250t\2603\260b\270\n\300!\330\014\r\330\014\020\220\007\220q\230\001\330\014\r\330\014\016\210g\220Q\220a\340\010\014\210J\220a\220q\200A\360\010\000\t\n\330\014\034\230D\320 2\260!\2601\260A\330\014\023\220=\240\002\240!\340\014\020\220\001\220\021\200A\330\010\034\230I\240Q\330\014\020\220\001\330\014\017\210q\220\010\230\t\240\021\240&\250\004\250C\250t\2603\260b\270\n\300!\330\014\r\330\014\033""\2307\240!\2401\330\014\017\210w\220a\220q\330\014\016\210g\220Q\220a\340\010\r\210X\220\\\240\027\250\001\250\021\330\010\014\210J\220a\220q\330\010\014\320\014\035\230Q\200A\330\010%\240T\250\027\260\006\260a\340\010\016\210c\220\023\220D\230\007\230t\2401\330\014\021\220\021\220,\230c\240\021\330\014\024\220L\240\003\2401\330\014\036\230i\240q\250\001\330\014\021\220\021\220!\330\014\031\230\021\230!\200A\360\n\000\t\n\330\014\025\220T\230\037\250\001\250\021\250!\330\014\017\210w\220c\230\021\330\020\021\330\014\020\220\007\220x\230u\240A\240V\2502\250]\270$\270b\300\007\300q\310\001\340\014\020\220\001\220\021\340\010\017\210t\2201\320\004E\300Q\360\014\000\r \230q\330\014(\250\001\340\010\025\220T\320\031+\2501\250A\250Q\340\r\016\330\014\020\220\t\230\025\230a\230q\330\020 \240\001\240\033\250B\250n\270J\300a\330\020\031\230\024\230W\240A\240\\\3201A\300\021\300!\340\020\023\320\023(\250\001\250\030\260\021\330\024\"\240!\330\024%\240Q\330\024\025\340\020\024\220A\220Q\340\010\013\2104\210q\330\014\022\220,\230a\230q\340\010\014\210G\2209\230J\240a\200\001\330\004\n\210+\220Q"; + #else /* compression: none (1998 bytes) */ +const char* const bytes = "Could not allocate hasmapCould not mine block. No nonce foundCreate a genesis block first.Data must be a stringDifficulty must be greater than 0Difficulty must be integer valueFailed to hash dataGenesis BlockIndex value is out of boundsProvided index not foundPyBlock(UTF-8)?disableenablegcisenabledno default __reduce__ due to non-trivial __cinit__src/polluck_blockchain/placeholder_native.pyxBlockchainBlockchain.__reduce_cython__Blockchain.__setstate_cython__Blockchain.create_genesis_blockBlockchain.get_blockBlockchain.new_blockBlockchain.print_key_value_pairPyBlockPyBlock.__reduce_cython__PyBlock.__setstate_cython__PyBlock.bytes_serializePyBlock.perform_hash__Pyx_PyDict_NextRefTIMEZONE_UTCasyncio.coroutinesblockbytes_serializecline_in_tracebackcreate_genesis_blockcurrent_time_tzcut_microsecondsdatadata_digestdata_strdatetimedigestdigest_sizedopt_basicsdopt_basics.datetimeencodefrom_ptrfromtimestamp__func__genesis_prev_hashget_block__getstate__hashhashlibhexidxindex_is_coroutineititems__main____module____name__new_blocknew_idxnonceperform_hashpolluck_blockchain.placeholder_nativepopprev_blockprev_hashprevious_hashprintprint_key_value_pairpy_block__pyx_state__pyx_vtable____qualname____reduce____reduce_cython____reduce_ex____repr__resselfserialize_resserialize_size__set_name__setdefault__setstate____setstate_cython__struct__test__timetimestampvalues0000000000000000000000000000000000000000000000000000000000000000\200A\360\n\000\t\n\330\014\025\220^\2401\240D\250\t\260\021\260!\330\014\017\210w\220c\230\021\330\020\021\340\014\020\220\007\220x\230u\240A\240V\2502\250]\270$\270b\300\007\300q\310\001\340\014\020\220\001\220\021\340\010\017\210t\2201\200A\330\010\013\2104\210r\220\022\2203\220d\230\"\230D\240\001\330\014\022\220*\230A\230Q\340\010\034\230D\240\014\250A\250Q\330\010\013\2106\220\023\220A\330\014\022\220*\230A\230Q\330\010\026\220i\230q\240\r\250Q\200A\360\022\000\t\014\2104\210t\2201\330\014\022\220,\230a\230q\330\010\013\2104\210z\230\021\230&""\240\001\330\014\022\220)\2301\230A\340\010\023\2204\220z\240\021\240!\330\010\025\220T\230\034\240Q\240d\250!\330\010\024\220J\230a\330\010\022\220$\220h\230b\240\001\340\010\034\230I\240Q\330\014\r\330\014\017\210q\220\010\230\t\240\021\240&\250\004\250C\250t\2603\260b\270\n\300!\330\014\r\330\014\r\330\014\r\330\014\016\210g\220Q\220a\340\010\027\220t\230:\240Q\240a\330\010\013\2104\210s\220!\330\014\022\220,\230a\230q\200A\360\010\000\t\n\330\014\034\320\034-\250Q\250d\260)\2701\270A\330\014\023\220=\240\002\240!\340\014\020\220\001\220\021\200A\330\010%\240T\250\027\260\006\260a\340\010\016\210c\220\023\220D\230\007\230t\2401\330\014\021\220\021\220,\230c\240\021\330\014\024\220L\240\003\2401\330\014\036\230i\240q\250\001\330\014\021\220\021\220!\330\014\031\230\021\230!\200A\330\010\035\230Y\240g\250Q\250a\330\010\037\230t\240:\250Q\250a\340\010\034\230I\240Q\330\014\020\220\001\330\014\017\210q\220\010\230\t\240\021\240&\250\004\250C\250t\2603\260b\270\n\300!\330\014\r\330\014\r\330\014\r\330\014\016\210g\220Q\220a\340\010\027\220t\230:\240Q\240a\330\010\013\2104\210s\220!\330\014\022\220,\230a\230q\330\010\014\320\014\035\230Q\200\001\330\004\n\210+\220Q"; PyObject *data = NULL; CYTHON_UNUSED_VAR(__Pyx_DecompressString); #endif PyObject **stringtab = __pyx_mstate->__pyx_string_tab; Py_ssize_t pos = 0; - for (int i = 0; i < 90; i++) { + for (int i = 0; i < 100; i++) { Py_ssize_t bytes_length = index[i].length; PyObject *string = PyUnicode_DecodeUTF8(bytes + pos, bytes_length, NULL); - if (likely(string) && i >= 15) PyUnicode_InternInPlace(&string); + if (likely(string) && i >= 21) PyUnicode_InternInPlace(&string); if (unlikely(!string)) { Py_XDECREF(data); __PYX_ERR(0, 1, __pyx_L1_error) @@ -9542,7 +10088,7 @@ const char* const bytes = "Could not allocate hasmapCreate a genesis block first stringtab[i] = string; pos += bytes_length; } - for (int i = 90; i < 102; i++) { + for (int i = 100; i < 109; i++) { Py_ssize_t bytes_length = index[i].length; PyObject *string = PyBytes_FromStringAndSize(bytes + pos, bytes_length); stringtab[i] = string; @@ -9553,15 +10099,15 @@ const char* const bytes = "Could not allocate hasmapCreate a genesis block first } } Py_XDECREF(data); - for (Py_ssize_t i = 0; i < 102; i++) { + for (Py_ssize_t i = 0; i < 109; i++) { if (unlikely(PyObject_Hash(stringtab[i]) == -1)) { __PYX_ERR(0, 1, __pyx_L1_error) } } #if CYTHON_IMMORTAL_CONSTANTS { - PyObject **table = stringtab + 90; - for (Py_ssize_t i=0; i<12; ++i) { + PyObject **table = stringtab + 100; + for (Py_ssize_t i=0; i<9; ++i) { #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING Py_SET_REFCNT(table[i], _Py_IMMORTAL_REFCNT_LOCAL); #else @@ -9575,16 +10121,15 @@ const char* const bytes = "Could not allocate hasmapCreate a genesis block first PyObject **numbertab = __pyx_mstate->__pyx_number_tab + 0; int8_t const cint_constants_1[] = {0,1,12}; int16_t const cint_constants_2[] = {2025}; - int64_t const cint_constants_8[] = {4294967295LL}; - for (int i = 0; i < 5; i++) { - numbertab[i] = PyLong_FromLongLong((i < 3 ? cint_constants_1[i - 0] : (i < 4 ? cint_constants_2[i - 3] : cint_constants_8[i - 4]))); + for (int i = 0; i < 4; i++) { + numbertab[i] = PyLong_FromLong((i < 3 ? cint_constants_1[i - 0] : cint_constants_2[i - 3])); if (unlikely(!numbertab[i])) __PYX_ERR(0, 1, __pyx_L1_error) } } #if CYTHON_IMMORTAL_CONSTANTS { PyObject **table = __pyx_mstate->__pyx_number_tab; - for (Py_ssize_t i=0; i<5; ++i) { + for (Py_ssize_t i=0; i<4; ++i) { #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING Py_SET_REFCNT(table[i], _Py_IMMORTAL_REFCNT_LOCAL); #else @@ -9602,7 +10147,7 @@ typedef struct { unsigned int argcount : 2; unsigned int num_posonly_args : 1; unsigned int num_kwonly_args : 1; - unsigned int nlocals : 3; + unsigned int nlocals : 4; unsigned int flags : 10; unsigned int first_line : 9; } __Pyx_PyCode_New_function_description; @@ -9621,59 +10166,54 @@ static int __Pyx_CreateCodeObjects(__pyx_mstatetype *__pyx_mstate) { PyObject* tuple_dedup_map = PyDict_New(); if (unlikely(!tuple_dedup_map)) return -1; { - const __Pyx_PyCode_New_function_description descr = {1, 0, 0, 3, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 254}; + const __Pyx_PyCode_New_function_description descr = {1, 0, 0, 3, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 166}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self, __pyx_mstate->__pyx_n_u_serialize_res, __pyx_mstate->__pyx_n_u_serialize_size}; - __pyx_mstate_global->__pyx_codeobj_tab[0] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_src_polluck_blockchain_placehold, __pyx_mstate->__pyx_n_u_bytes_serialize, __pyx_mstate->__pyx_kp_b_iso88591_A_D_2_1A, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[0])) goto bad; + __pyx_mstate_global->__pyx_codeobj_tab[0] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_src_polluck_blockchain_placehold, __pyx_mstate->__pyx_n_u_bytes_serialize, __pyx_mstate->__pyx_kp_b_iso88591_A_Qd_1A, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[0])) goto bad; } { - const __Pyx_PyCode_New_function_description descr = {3, 0, 0, 3, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 264}; - PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self, __pyx_mstate->__pyx_n_u_difficulty, __pyx_mstate->__pyx_n_u_max_nonce}; - __pyx_mstate_global->__pyx_codeobj_tab[1] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_src_polluck_blockchain_placehold, __pyx_mstate->__pyx_n_u_mine, __pyx_mstate->__pyx_kp_b_iso88591_EQ_q_T_1AQ_aq_BnJa_WA_1A_Q_AQ_4, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[1])) goto bad; - } - { - const __Pyx_PyCode_New_function_description descr = {1, 0, 0, 1, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 309}; - PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self}; - __pyx_mstate_global->__pyx_codeobj_tab[2] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_src_polluck_blockchain_placehold, __pyx_mstate->__pyx_n_u_perform_hash, __pyx_mstate->__pyx_kp_b_iso88591_A_T_wc_xuAV2_b_q_t1, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[2])) goto bad; + const __Pyx_PyCode_New_function_description descr = {1, 0, 0, 3, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 177}; + PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self, __pyx_mstate->__pyx_n_u_digest, __pyx_mstate->__pyx_n_u_digest_size}; + __pyx_mstate_global->__pyx_codeobj_tab[1] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_src_polluck_blockchain_placehold, __pyx_mstate->__pyx_n_u_perform_hash, __pyx_mstate->__pyx_kp_b_iso88591_A_1D_wc_xuAV2_b_q_t1, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[1])) goto bad; } { const __Pyx_PyCode_New_function_description descr = {1, 0, 0, 1, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 1}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self}; - __pyx_mstate_global->__pyx_codeobj_tab[3] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_stringsource, __pyx_mstate->__pyx_n_u_reduce_cython, __pyx_mstate->__pyx_kp_b_iso88591_Q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[3])) goto bad; + __pyx_mstate_global->__pyx_codeobj_tab[2] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_stringsource, __pyx_mstate->__pyx_n_u_reduce_cython, __pyx_mstate->__pyx_kp_b_iso88591_Q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[2])) goto bad; } { const __Pyx_PyCode_New_function_description descr = {2, 0, 0, 2, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 3}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self, __pyx_mstate->__pyx_n_u_pyx_state}; - __pyx_mstate_global->__pyx_codeobj_tab[4] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_stringsource, __pyx_mstate->__pyx_n_u_setstate_cython, __pyx_mstate->__pyx_kp_b_iso88591_Q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[4])) goto bad; + __pyx_mstate_global->__pyx_codeobj_tab[3] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_stringsource, __pyx_mstate->__pyx_n_u_setstate_cython, __pyx_mstate->__pyx_kp_b_iso88591_Q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[3])) goto bad; } { - const __Pyx_PyCode_New_function_description descr = {1, 0, 0, 4, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 370}; + const __Pyx_PyCode_New_function_description descr = {1, 0, 0, 4, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 359}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self, __pyx_mstate->__pyx_n_u_it, __pyx_mstate->__pyx_n_u_block, __pyx_mstate->__pyx_n_u_py_block}; - __pyx_mstate_global->__pyx_codeobj_tab[5] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_src_polluck_blockchain_placehold, __pyx_mstate->__pyx_n_u_print_key_value_pair, __pyx_mstate->__pyx_kp_b_iso88591_A_T_a_c_D_t1_c_L_1_iq, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[5])) goto bad; + __pyx_mstate_global->__pyx_codeobj_tab[4] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_src_polluck_blockchain_placehold, __pyx_mstate->__pyx_n_u_print_key_value_pair, __pyx_mstate->__pyx_kp_b_iso88591_A_T_a_c_D_t1_c_L_1_iq, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[4])) goto bad; } { - const __Pyx_PyCode_New_function_description descr = {2, 0, 0, 3, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 392}; + const __Pyx_PyCode_New_function_description descr = {2, 0, 0, 3, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 396}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self, __pyx_mstate->__pyx_n_u_idx, __pyx_mstate->__pyx_n_u_block}; - __pyx_mstate_global->__pyx_codeobj_tab[6] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_src_polluck_blockchain_placehold, __pyx_mstate->__pyx_n_u_get_block, __pyx_mstate->__pyx_kp_b_iso88591_A_4r_3d_D_AQ_D_AQ_iq_Q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[6])) goto bad; + __pyx_mstate_global->__pyx_codeobj_tab[5] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_src_polluck_blockchain_placehold, __pyx_mstate->__pyx_n_u_get_block, __pyx_mstate->__pyx_kp_b_iso88591_A_4r_3d_D_AQ_D_AQ_6_A_AQ_iq_Q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[5])) goto bad; } { - const __Pyx_PyCode_New_function_description descr = {1, 0, 0, 2, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 404}; - PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self, __pyx_mstate->__pyx_n_u_block}; - __pyx_mstate_global->__pyx_codeobj_tab[7] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_src_polluck_blockchain_placehold, __pyx_mstate->__pyx_n_u_create_genesis_block, __pyx_mstate->__pyx_kp_b_iso88591_A_IQ_q_Ct3b_7_1_waq_gQa_X_Jaq_Q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[7])) goto bad; + const __Pyx_PyCode_New_function_description descr = {1, 0, 0, 5, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 419}; + PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self, __pyx_mstate->__pyx_n_u_genesis_prev_hash, __pyx_mstate->__pyx_n_u_data_str, __pyx_mstate->__pyx_n_u_block, __pyx_mstate->__pyx_n_u_res}; + __pyx_mstate_global->__pyx_codeobj_tab[6] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_src_polluck_blockchain_placehold, __pyx_mstate->__pyx_n_u_create_genesis_block, __pyx_mstate->__pyx_kp_b_iso88591_A_YgQa_t_Qa_IQ_q_Ct3b_gQa_t_Qa_4, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[6])) goto bad; } { - const __Pyx_PyCode_New_function_description descr = {2, 0, 0, 6, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 417}; - PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self, __pyx_mstate->__pyx_n_u_data, __pyx_mstate->__pyx_n_u_prev_block, __pyx_mstate->__pyx_n_u_prev_hash, __pyx_mstate->__pyx_n_u_new_idx, __pyx_mstate->__pyx_n_u_block}; - __pyx_mstate_global->__pyx_codeobj_tab[8] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_src_polluck_blockchain_placehold, __pyx_mstate->__pyx_n_u_new_block, __pyx_mstate->__pyx_kp_b_iso88591_A_4t1_aq_a_HBa_IQ_q_Ct3b_q_gQa_J, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[8])) goto bad; + const __Pyx_PyCode_New_function_description descr = {2, 0, 0, 10, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 436}; + PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self, __pyx_mstate->__pyx_n_u_data, __pyx_mstate->__pyx_n_u_prev_block, __pyx_mstate->__pyx_n_u_prev_hash, __pyx_mstate->__pyx_n_u_new_idx, __pyx_mstate->__pyx_n_u_data_str, __pyx_mstate->__pyx_n_u_data_digest, __pyx_mstate->__pyx_n_u_digest_size, __pyx_mstate->__pyx_n_u_block, __pyx_mstate->__pyx_n_u_res}; + __pyx_mstate_global->__pyx_codeobj_tab[7] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_src_polluck_blockchain_placehold, __pyx_mstate->__pyx_n_u_new_block, __pyx_mstate->__pyx_kp_b_iso88591_A_4t1_aq_4z_1A_4z_T_Qd_Ja_hb_IQ, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[7])) goto bad; } { const __Pyx_PyCode_New_function_description descr = {1, 0, 0, 1, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 1}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self}; - __pyx_mstate_global->__pyx_codeobj_tab[9] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_stringsource, __pyx_mstate->__pyx_n_u_reduce_cython, __pyx_mstate->__pyx_kp_b_iso88591_Q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[9])) goto bad; + __pyx_mstate_global->__pyx_codeobj_tab[8] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_stringsource, __pyx_mstate->__pyx_n_u_reduce_cython, __pyx_mstate->__pyx_kp_b_iso88591_Q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[8])) goto bad; } { const __Pyx_PyCode_New_function_description descr = {2, 0, 0, 2, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 3}; PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self, __pyx_mstate->__pyx_n_u_pyx_state}; - __pyx_mstate_global->__pyx_codeobj_tab[10] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_stringsource, __pyx_mstate->__pyx_n_u_setstate_cython, __pyx_mstate->__pyx_kp_b_iso88591_Q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[10])) goto bad; + __pyx_mstate_global->__pyx_codeobj_tab[9] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_stringsource, __pyx_mstate->__pyx_n_u_setstate_cython, __pyx_mstate->__pyx_kp_b_iso88591_Q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[9])) goto bad; } Py_DECREF(tuple_dedup_map); return 0; @@ -10093,6 +10633,51 @@ static PyObject *__Pyx_PyObject_FastCallMethod(PyObject *name, PyObject *const * } #endif +/* PyObjectVectorCallKwBuilder (used by PyObjectVectorCallMethodKwBuilder) */ +#if CYTHON_VECTORCALL +static int __Pyx_VectorcallBuilder_AddArg(PyObject *key, PyObject *value, PyObject *builder, PyObject **args, int n) { + (void)__Pyx_PyObject_FastCallDict; + if (__Pyx_PyTuple_SET_ITEM(builder, n, key) != (0)) return -1; + Py_INCREF(key); + args[n] = value; + return 0; +} +CYTHON_UNUSED static int __Pyx_VectorcallBuilder_AddArg_Check(PyObject *key, PyObject *value, PyObject *builder, PyObject **args, int n) { + (void)__Pyx_VectorcallBuilder_AddArgStr; + if (unlikely(!PyUnicode_Check(key))) { + PyErr_SetString(PyExc_TypeError, "keywords must be strings"); + return -1; + } + return __Pyx_VectorcallBuilder_AddArg(key, value, builder, args, n); +} +static int __Pyx_VectorcallBuilder_AddArgStr(const char *key, PyObject *value, PyObject *builder, PyObject **args, int n) { + PyObject *pyKey = PyUnicode_FromString(key); + if (!pyKey) return -1; + return __Pyx_VectorcallBuilder_AddArg(pyKey, value, builder, args, n); +} +#else // CYTHON_VECTORCALL +CYTHON_UNUSED static int __Pyx_VectorcallBuilder_AddArg_Check(PyObject *key, PyObject *value, PyObject *builder, CYTHON_UNUSED PyObject **args, CYTHON_UNUSED int n) { + if (unlikely(!PyUnicode_Check(key))) { + PyErr_SetString(PyExc_TypeError, "keywords must be strings"); + return -1; + } + return PyDict_SetItem(builder, key, value); +} +#endif + +/* PyObjectVectorCallMethodKwBuilder */ +#if !CYTHON_VECTORCALL || PY_VERSION_HEX < 0x03090000 +static PyObject *__Pyx_Object_VectorcallMethod_CallFromBuilder(PyObject *name, PyObject *const *args, size_t nargsf, PyObject *kwnames) { + PyObject *result; + PyObject *obj = PyObject_GetAttr(args[0], name); + if (unlikely(!obj)) + return NULL; + result = __Pyx_Object_Vectorcall_CallFromBuilder(obj, args+1, nargsf-1, kwnames); + Py_DECREF(obj); + return result; +} +#endif + /* DivInt[long] */ static CYTHON_INLINE long __Pyx_div_long(long a, long b, int b_is_constant) { long q = a / b; @@ -11440,15 +12025,6 @@ static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject } #endif -/* ErrOccurredWithGIL */ -static CYTHON_INLINE int __Pyx_ErrOccurredWithGIL(void) { - int err; - PyGILState_STATE _save = PyGILState_Ensure(); - err = !!PyErr_Occurred(); - PyGILState_Release(_save); - return err; -} - /* RaiseException */ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { PyObject* owned_instance = NULL; @@ -11557,6 +12133,70 @@ bad: return; } +/* ErrOccurredWithGIL */ +static CYTHON_INLINE int __Pyx_ErrOccurredWithGIL(void) { + int err; + PyGILState_STATE _save = PyGILState_Ensure(); + err = !!PyErr_Occurred(); + PyGILState_Release(_save); + return err; +} + +/* ReleaseUnknownGil */ +static __Pyx_UnknownThreadState __Pyx_SaveUnknownThread(void) { +#if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030d0000 + if (__Pyx_get_runtime_version() >= 0x030d0000) { + PyThreadState *ts = PyThreadState_Swap(NULL); + __Pyx_UnknownThreadState out = { ts, PyGILState_UNLOCKED }; + return out; + } else { + PyGILState_STATE gil_state = PyGILState_Ensure(); + PyThreadState *ts = PyEval_SaveThread(); + __Pyx_UnknownThreadState out = { ts, gil_state }; + return out; + } +#elif __PYX_LIMITED_VERSION_HEX >= 0x030d0000 + return PyThreadState_Swap(NULL); +#else + #if CYTHON_COMPILING_IN_PYPY || PY_VERSION_HEX < 0x030C0000 + if (PyGILState_Check()) + #else + if (_PyThreadState_UncheckedGet()) // UncheckedGet is a reliable check for the GIL from 3.12 upwards + #endif + { + return PyEval_SaveThread(); + } + return NULL; // Nothing to release - we don't have the GIL +#endif +} +static void __Pyx_RestoreUnknownThread(__Pyx_UnknownThreadState state) { +#if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030d0000 + if (!state.ts) return; + PyEval_RestoreThread(state.ts); + if (__Pyx_get_runtime_version() < 0x030d0000) { + PyGILState_Release(state.gil_state); + } +#else + if (state) { + PyEval_RestoreThread(state); + } +#endif +} +static CYTHON_INLINE int __Pyx_UnknownThreadStateDefinitelyHadGil(__Pyx_UnknownThreadState state) { + #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030d0000 + return ((state.ts != NULL) && (__Pyx_get_runtime_version() >= 0x030d0000)); + #else + return state != NULL; + #endif +} +static CYTHON_INLINE int __Pyx_UnknownThreadStateMayHaveHadGil(__Pyx_UnknownThreadState state) { + #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030d0000 + return state.ts != NULL; + #else + return state != NULL; + #endif +} + /* AllocateExtensionType */ static PyObject *__Pyx_AllocateExtensionType(PyTypeObject *t, int is_final) { if (is_final || likely(!__Pyx_PyType_HasFeature(t, Py_TPFLAGS_IS_ABSTRACT))) { @@ -14119,288 +14759,6 @@ bad: return (target_type) value;\ } -/* CIntFromPy */ -static CYTHON_INLINE unsigned int __Pyx_PyLong_As_unsigned_int(PyObject *x) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const unsigned int neg_one = (unsigned int) -1, const_zero = (unsigned int) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - const int is_unsigned = neg_one > const_zero; - if (unlikely(!PyLong_Check(x))) { - unsigned int val; - PyObject *tmp = __Pyx_PyNumber_Long(x); - if (!tmp) return (unsigned int) -1; - val = __Pyx_PyLong_As_unsigned_int(tmp); - Py_DECREF(tmp); - return val; - } - if (is_unsigned) { -#if CYTHON_USE_PYLONG_INTERNALS - if (unlikely(__Pyx_PyLong_IsNeg(x))) { - goto raise_neg_overflow; - } else if (__Pyx_PyLong_IsCompact(x)) { - __PYX_VERIFY_RETURN_INT(unsigned int, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x)) - } else { - const digit* digits = __Pyx_PyLong_Digits(x); - assert(__Pyx_PyLong_DigitCount(x) > 1); - switch (__Pyx_PyLong_DigitCount(x)) { - case 2: - if ((8 * sizeof(unsigned int) > 1 * PyLong_SHIFT)) { - if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { - __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if ((8 * sizeof(unsigned int) >= 2 * PyLong_SHIFT)) { - return (unsigned int) (((((unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])); - } - } - break; - case 3: - if ((8 * sizeof(unsigned int) > 2 * PyLong_SHIFT)) { - if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { - __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if ((8 * sizeof(unsigned int) >= 3 * PyLong_SHIFT)) { - return (unsigned int) (((((((unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])); - } - } - break; - case 4: - if ((8 * sizeof(unsigned int) > 3 * PyLong_SHIFT)) { - if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { - __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if ((8 * sizeof(unsigned int) >= 4 * PyLong_SHIFT)) { - return (unsigned int) (((((((((unsigned int)digits[3]) << PyLong_SHIFT) | (unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])); - } - } - break; - } - } -#endif -#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7 - if (unlikely(Py_SIZE(x) < 0)) { - goto raise_neg_overflow; - } -#else - { - int result = PyObject_RichCompareBool(x, Py_False, Py_LT); - if (unlikely(result < 0)) - return (unsigned int) -1; - if (unlikely(result == 1)) - goto raise_neg_overflow; - } -#endif - if ((sizeof(unsigned int) <= sizeof(unsigned long))) { - __PYX_VERIFY_RETURN_INT_EXC(unsigned int, unsigned long, PyLong_AsUnsignedLong(x)) - } else if ((sizeof(unsigned int) <= sizeof(unsigned PY_LONG_LONG))) { - __PYX_VERIFY_RETURN_INT_EXC(unsigned int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) - } - } else { -#if CYTHON_USE_PYLONG_INTERNALS - if (__Pyx_PyLong_IsCompact(x)) { - __PYX_VERIFY_RETURN_INT(unsigned int, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x)) - } else { - const digit* digits = __Pyx_PyLong_Digits(x); - assert(__Pyx_PyLong_DigitCount(x) > 1); - switch (__Pyx_PyLong_SignedDigitCount(x)) { - case -2: - if ((8 * sizeof(unsigned int) - 1 > 1 * PyLong_SHIFT)) { - if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { - __PYX_VERIFY_RETURN_INT(unsigned int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if ((8 * sizeof(unsigned int) - 1 > 2 * PyLong_SHIFT)) { - return (unsigned int) (((unsigned int)-1)*(((((unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]))); - } - } - break; - case 2: - if ((8 * sizeof(unsigned int) > 1 * PyLong_SHIFT)) { - if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { - __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if ((8 * sizeof(unsigned int) - 1 > 2 * PyLong_SHIFT)) { - return (unsigned int) ((((((unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]))); - } - } - break; - case -3: - if ((8 * sizeof(unsigned int) - 1 > 2 * PyLong_SHIFT)) { - if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { - __PYX_VERIFY_RETURN_INT(unsigned int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if ((8 * sizeof(unsigned int) - 1 > 3 * PyLong_SHIFT)) { - return (unsigned int) (((unsigned int)-1)*(((((((unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]))); - } - } - break; - case 3: - if ((8 * sizeof(unsigned int) > 2 * PyLong_SHIFT)) { - if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { - __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if ((8 * sizeof(unsigned int) - 1 > 3 * PyLong_SHIFT)) { - return (unsigned int) ((((((((unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]))); - } - } - break; - case -4: - if ((8 * sizeof(unsigned int) - 1 > 3 * PyLong_SHIFT)) { - if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { - __PYX_VERIFY_RETURN_INT(unsigned int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if ((8 * sizeof(unsigned int) - 1 > 4 * PyLong_SHIFT)) { - return (unsigned int) (((unsigned int)-1)*(((((((((unsigned int)digits[3]) << PyLong_SHIFT) | (unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]))); - } - } - break; - case 4: - if ((8 * sizeof(unsigned int) > 3 * PyLong_SHIFT)) { - if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { - __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if ((8 * sizeof(unsigned int) - 1 > 4 * PyLong_SHIFT)) { - return (unsigned int) ((((((((((unsigned int)digits[3]) << PyLong_SHIFT) | (unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]))); - } - } - break; - } - } -#endif - if ((sizeof(unsigned int) <= sizeof(long))) { - __PYX_VERIFY_RETURN_INT_EXC(unsigned int, long, PyLong_AsLong(x)) - } else if ((sizeof(unsigned int) <= sizeof(PY_LONG_LONG))) { - __PYX_VERIFY_RETURN_INT_EXC(unsigned int, PY_LONG_LONG, PyLong_AsLongLong(x)) - } - } - { - unsigned int val; - int ret = -1; -#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API - Py_ssize_t bytes_copied = PyLong_AsNativeBytes( - x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0)); - if (unlikely(bytes_copied == -1)) { - } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) { - goto raise_overflow; - } else { - ret = 0; - } -#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray) - int one = 1; int is_little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&val; - ret = _PyLong_AsByteArray((PyLongObject *)x, - bytes, sizeof(val), - is_little, !is_unsigned); -#else - PyObject *v; - PyObject *stepval = NULL, *mask = NULL, *shift = NULL; - int bits, remaining_bits, is_negative = 0; - int chunk_size = (sizeof(long) < 8) ? 30 : 62; - if (likely(PyLong_CheckExact(x))) { - v = __Pyx_NewRef(x); - } else { - v = PyNumber_Long(x); - if (unlikely(!v)) return (unsigned int) -1; - assert(PyLong_CheckExact(v)); - } - { - int result = PyObject_RichCompareBool(v, Py_False, Py_LT); - if (unlikely(result < 0)) { - Py_DECREF(v); - return (unsigned int) -1; - } - is_negative = result == 1; - } - if (is_unsigned && unlikely(is_negative)) { - Py_DECREF(v); - goto raise_neg_overflow; - } else if (is_negative) { - stepval = PyNumber_Invert(v); - Py_DECREF(v); - if (unlikely(!stepval)) - return (unsigned int) -1; - } else { - stepval = v; - } - v = NULL; - val = (unsigned int) 0; - mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done; - shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done; - for (bits = 0; bits < (int) sizeof(unsigned int) * 8 - chunk_size; bits += chunk_size) { - PyObject *tmp, *digit; - long idigit; - digit = PyNumber_And(stepval, mask); - if (unlikely(!digit)) goto done; - idigit = PyLong_AsLong(digit); - Py_DECREF(digit); - if (unlikely(idigit < 0)) goto done; - val |= ((unsigned int) idigit) << bits; - tmp = PyNumber_Rshift(stepval, shift); - if (unlikely(!tmp)) goto done; - Py_DECREF(stepval); stepval = tmp; - } - Py_DECREF(shift); shift = NULL; - Py_DECREF(mask); mask = NULL; - { - long idigit = PyLong_AsLong(stepval); - if (unlikely(idigit < 0)) goto done; - remaining_bits = ((int) sizeof(unsigned int) * 8) - bits - (is_unsigned ? 0 : 1); - if (unlikely(idigit >= (1L << remaining_bits))) - goto raise_overflow; - val |= ((unsigned int) idigit) << bits; - } - if (!is_unsigned) { - if (unlikely(val & (((unsigned int) 1) << (sizeof(unsigned int) * 8 - 1)))) - goto raise_overflow; - if (is_negative) - val = ~val; - } - ret = 0; - done: - Py_XDECREF(shift); - Py_XDECREF(mask); - Py_XDECREF(stepval); -#endif - if (unlikely(ret)) - return (unsigned int) -1; - return val; - } -raise_overflow: - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to unsigned int"); - return (unsigned int) -1; -raise_neg_overflow: - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned int"); - return (unsigned int) -1; -} - -/* PyObjectVectorCallKwBuilder (used by CIntToPy) */ -#if CYTHON_VECTORCALL -static int __Pyx_VectorcallBuilder_AddArg(PyObject *key, PyObject *value, PyObject *builder, PyObject **args, int n) { - (void)__Pyx_PyObject_FastCallDict; - if (__Pyx_PyTuple_SET_ITEM(builder, n, key) != (0)) return -1; - Py_INCREF(key); - args[n] = value; - return 0; -} -CYTHON_UNUSED static int __Pyx_VectorcallBuilder_AddArg_Check(PyObject *key, PyObject *value, PyObject *builder, PyObject **args, int n) { - (void)__Pyx_VectorcallBuilder_AddArgStr; - if (unlikely(!PyUnicode_Check(key))) { - PyErr_SetString(PyExc_TypeError, "keywords must be strings"); - return -1; - } - return __Pyx_VectorcallBuilder_AddArg(key, value, builder, args, n); -} -static int __Pyx_VectorcallBuilder_AddArgStr(const char *key, PyObject *value, PyObject *builder, PyObject **args, int n) { - PyObject *pyKey = PyUnicode_FromString(key); - if (!pyKey) return -1; - return __Pyx_VectorcallBuilder_AddArg(pyKey, value, builder, args, n); -} -#else // CYTHON_VECTORCALL -CYTHON_UNUSED static int __Pyx_VectorcallBuilder_AddArg_Check(PyObject *key, PyObject *value, PyObject *builder, CYTHON_UNUSED PyObject **args, CYTHON_UNUSED int n) { - if (unlikely(!PyUnicode_Check(key))) { - PyErr_SetString(PyExc_TypeError, "keywords must be strings"); - return -1; - } - return PyDict_SetItem(builder, key, value); -} -#endif - /* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyLong_From_uint64_t(uint64_t value) { #ifdef __Pyx_HAS_GCC_DIAGNOSTIC @@ -14470,6 +14828,256 @@ static CYTHON_INLINE PyObject* __Pyx_PyLong_From_uint64_t(uint64_t value) { } } +/* CIntFromPy */ +static CYTHON_INLINE uint64_t __Pyx_PyLong_As_uint64_t(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const uint64_t neg_one = (uint64_t) -1, const_zero = (uint64_t) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; + if (unlikely(!PyLong_Check(x))) { + uint64_t val; + PyObject *tmp = __Pyx_PyNumber_Long(x); + if (!tmp) return (uint64_t) -1; + val = __Pyx_PyLong_As_uint64_t(tmp); + Py_DECREF(tmp); + return val; + } + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + if (unlikely(__Pyx_PyLong_IsNeg(x))) { + goto raise_neg_overflow; + } else if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(uint64_t, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_DigitCount(x)) { + case 2: + if ((8 * sizeof(uint64_t) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(uint64_t) >= 2 * PyLong_SHIFT)) { + return (uint64_t) (((((uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])); + } + } + break; + case 3: + if ((8 * sizeof(uint64_t) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(uint64_t) >= 3 * PyLong_SHIFT)) { + return (uint64_t) (((((((uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])); + } + } + break; + case 4: + if ((8 * sizeof(uint64_t) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(uint64_t) >= 4 * PyLong_SHIFT)) { + return (uint64_t) (((((((((uint64_t)digits[3]) << PyLong_SHIFT) | (uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])); + } + } + break; + } + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7 + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (uint64_t) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if ((sizeof(uint64_t) <= sizeof(unsigned long))) { + __PYX_VERIFY_RETURN_INT_EXC(uint64_t, unsigned long, PyLong_AsUnsignedLong(x)) + } else if ((sizeof(uint64_t) <= sizeof(unsigned PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(uint64_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(uint64_t, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_SignedDigitCount(x)) { + case -2: + if ((8 * sizeof(uint64_t) - 1 > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(uint64_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(uint64_t) - 1 > 2 * PyLong_SHIFT)) { + return (uint64_t) (((uint64_t)-1)*(((((uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]))); + } + } + break; + case 2: + if ((8 * sizeof(uint64_t) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(uint64_t) - 1 > 2 * PyLong_SHIFT)) { + return (uint64_t) ((((((uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]))); + } + } + break; + case -3: + if ((8 * sizeof(uint64_t) - 1 > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(uint64_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(uint64_t) - 1 > 3 * PyLong_SHIFT)) { + return (uint64_t) (((uint64_t)-1)*(((((((uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]))); + } + } + break; + case 3: + if ((8 * sizeof(uint64_t) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(uint64_t) - 1 > 3 * PyLong_SHIFT)) { + return (uint64_t) ((((((((uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]))); + } + } + break; + case -4: + if ((8 * sizeof(uint64_t) - 1 > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(uint64_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(uint64_t) - 1 > 4 * PyLong_SHIFT)) { + return (uint64_t) (((uint64_t)-1)*(((((((((uint64_t)digits[3]) << PyLong_SHIFT) | (uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]))); + } + } + break; + case 4: + if ((8 * sizeof(uint64_t) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(uint64_t) - 1 > 4 * PyLong_SHIFT)) { + return (uint64_t) ((((((((((uint64_t)digits[3]) << PyLong_SHIFT) | (uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]))); + } + } + break; + } + } +#endif + if ((sizeof(uint64_t) <= sizeof(long))) { + __PYX_VERIFY_RETURN_INT_EXC(uint64_t, long, PyLong_AsLong(x)) + } else if ((sizeof(uint64_t) <= sizeof(PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(uint64_t, PY_LONG_LONG, PyLong_AsLongLong(x)) + } + } + { + uint64_t val; + int ret = -1; +#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API + Py_ssize_t bytes_copied = PyLong_AsNativeBytes( + x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0)); + if (unlikely(bytes_copied == -1)) { + } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) { + goto raise_overflow; + } else { + ret = 0; + } +#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray) + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + ret = _PyLong_AsByteArray((PyLongObject *)x, + bytes, sizeof(val), + is_little, !is_unsigned); +#else + PyObject *v; + PyObject *stepval = NULL, *mask = NULL, *shift = NULL; + int bits, remaining_bits, is_negative = 0; + int chunk_size = (sizeof(long) < 8) ? 30 : 62; + if (likely(PyLong_CheckExact(x))) { + v = __Pyx_NewRef(x); + } else { + v = PyNumber_Long(x); + if (unlikely(!v)) return (uint64_t) -1; + assert(PyLong_CheckExact(v)); + } + { + int result = PyObject_RichCompareBool(v, Py_False, Py_LT); + if (unlikely(result < 0)) { + Py_DECREF(v); + return (uint64_t) -1; + } + is_negative = result == 1; + } + if (is_unsigned && unlikely(is_negative)) { + Py_DECREF(v); + goto raise_neg_overflow; + } else if (is_negative) { + stepval = PyNumber_Invert(v); + Py_DECREF(v); + if (unlikely(!stepval)) + return (uint64_t) -1; + } else { + stepval = v; + } + v = NULL; + val = (uint64_t) 0; + mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done; + shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done; + for (bits = 0; bits < (int) sizeof(uint64_t) * 8 - chunk_size; bits += chunk_size) { + PyObject *tmp, *digit; + long idigit; + digit = PyNumber_And(stepval, mask); + if (unlikely(!digit)) goto done; + idigit = PyLong_AsLong(digit); + Py_DECREF(digit); + if (unlikely(idigit < 0)) goto done; + val |= ((uint64_t) idigit) << bits; + tmp = PyNumber_Rshift(stepval, shift); + if (unlikely(!tmp)) goto done; + Py_DECREF(stepval); stepval = tmp; + } + Py_DECREF(shift); shift = NULL; + Py_DECREF(mask); mask = NULL; + { + long idigit = PyLong_AsLong(stepval); + if (unlikely(idigit < 0)) goto done; + remaining_bits = ((int) sizeof(uint64_t) * 8) - bits - (is_unsigned ? 0 : 1); + if (unlikely(idigit >= (1L << remaining_bits))) + goto raise_overflow; + val |= ((uint64_t) idigit) << bits; + } + if (!is_unsigned) { + if (unlikely(val & (((uint64_t) 1) << (sizeof(uint64_t) * 8 - 1)))) + goto raise_overflow; + if (is_negative) + val = ~val; + } + ret = 0; + done: + Py_XDECREF(shift); + Py_XDECREF(mask); + Py_XDECREF(stepval); +#endif + if (unlikely(ret)) + return (uint64_t) -1; + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to uint64_t"); + return (uint64_t) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to uint64_t"); + return (uint64_t) -1; +} + /* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyLong_From_int(int value) { #ifdef __Pyx_HAS_GCC_DIAGNOSTIC @@ -14789,256 +15397,6 @@ raise_neg_overflow: return (int) -1; } -/* CIntFromPy */ -static CYTHON_INLINE uint64_t __Pyx_PyLong_As_uint64_t(PyObject *x) { -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const uint64_t neg_one = (uint64_t) -1, const_zero = (uint64_t) 0; -#ifdef __Pyx_HAS_GCC_DIAGNOSTIC -#pragma GCC diagnostic pop -#endif - const int is_unsigned = neg_one > const_zero; - if (unlikely(!PyLong_Check(x))) { - uint64_t val; - PyObject *tmp = __Pyx_PyNumber_Long(x); - if (!tmp) return (uint64_t) -1; - val = __Pyx_PyLong_As_uint64_t(tmp); - Py_DECREF(tmp); - return val; - } - if (is_unsigned) { -#if CYTHON_USE_PYLONG_INTERNALS - if (unlikely(__Pyx_PyLong_IsNeg(x))) { - goto raise_neg_overflow; - } else if (__Pyx_PyLong_IsCompact(x)) { - __PYX_VERIFY_RETURN_INT(uint64_t, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x)) - } else { - const digit* digits = __Pyx_PyLong_Digits(x); - assert(__Pyx_PyLong_DigitCount(x) > 1); - switch (__Pyx_PyLong_DigitCount(x)) { - case 2: - if ((8 * sizeof(uint64_t) > 1 * PyLong_SHIFT)) { - if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { - __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if ((8 * sizeof(uint64_t) >= 2 * PyLong_SHIFT)) { - return (uint64_t) (((((uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])); - } - } - break; - case 3: - if ((8 * sizeof(uint64_t) > 2 * PyLong_SHIFT)) { - if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { - __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if ((8 * sizeof(uint64_t) >= 3 * PyLong_SHIFT)) { - return (uint64_t) (((((((uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])); - } - } - break; - case 4: - if ((8 * sizeof(uint64_t) > 3 * PyLong_SHIFT)) { - if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { - __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if ((8 * sizeof(uint64_t) >= 4 * PyLong_SHIFT)) { - return (uint64_t) (((((((((uint64_t)digits[3]) << PyLong_SHIFT) | (uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])); - } - } - break; - } - } -#endif -#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7 - if (unlikely(Py_SIZE(x) < 0)) { - goto raise_neg_overflow; - } -#else - { - int result = PyObject_RichCompareBool(x, Py_False, Py_LT); - if (unlikely(result < 0)) - return (uint64_t) -1; - if (unlikely(result == 1)) - goto raise_neg_overflow; - } -#endif - if ((sizeof(uint64_t) <= sizeof(unsigned long))) { - __PYX_VERIFY_RETURN_INT_EXC(uint64_t, unsigned long, PyLong_AsUnsignedLong(x)) - } else if ((sizeof(uint64_t) <= sizeof(unsigned PY_LONG_LONG))) { - __PYX_VERIFY_RETURN_INT_EXC(uint64_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) - } - } else { -#if CYTHON_USE_PYLONG_INTERNALS - if (__Pyx_PyLong_IsCompact(x)) { - __PYX_VERIFY_RETURN_INT(uint64_t, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x)) - } else { - const digit* digits = __Pyx_PyLong_Digits(x); - assert(__Pyx_PyLong_DigitCount(x) > 1); - switch (__Pyx_PyLong_SignedDigitCount(x)) { - case -2: - if ((8 * sizeof(uint64_t) - 1 > 1 * PyLong_SHIFT)) { - if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { - __PYX_VERIFY_RETURN_INT(uint64_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if ((8 * sizeof(uint64_t) - 1 > 2 * PyLong_SHIFT)) { - return (uint64_t) (((uint64_t)-1)*(((((uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]))); - } - } - break; - case 2: - if ((8 * sizeof(uint64_t) > 1 * PyLong_SHIFT)) { - if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { - __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if ((8 * sizeof(uint64_t) - 1 > 2 * PyLong_SHIFT)) { - return (uint64_t) ((((((uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]))); - } - } - break; - case -3: - if ((8 * sizeof(uint64_t) - 1 > 2 * PyLong_SHIFT)) { - if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { - __PYX_VERIFY_RETURN_INT(uint64_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if ((8 * sizeof(uint64_t) - 1 > 3 * PyLong_SHIFT)) { - return (uint64_t) (((uint64_t)-1)*(((((((uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]))); - } - } - break; - case 3: - if ((8 * sizeof(uint64_t) > 2 * PyLong_SHIFT)) { - if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { - __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if ((8 * sizeof(uint64_t) - 1 > 3 * PyLong_SHIFT)) { - return (uint64_t) ((((((((uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]))); - } - } - break; - case -4: - if ((8 * sizeof(uint64_t) - 1 > 3 * PyLong_SHIFT)) { - if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { - __PYX_VERIFY_RETURN_INT(uint64_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if ((8 * sizeof(uint64_t) - 1 > 4 * PyLong_SHIFT)) { - return (uint64_t) (((uint64_t)-1)*(((((((((uint64_t)digits[3]) << PyLong_SHIFT) | (uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]))); - } - } - break; - case 4: - if ((8 * sizeof(uint64_t) > 3 * PyLong_SHIFT)) { - if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { - __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if ((8 * sizeof(uint64_t) - 1 > 4 * PyLong_SHIFT)) { - return (uint64_t) ((((((((((uint64_t)digits[3]) << PyLong_SHIFT) | (uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]))); - } - } - break; - } - } -#endif - if ((sizeof(uint64_t) <= sizeof(long))) { - __PYX_VERIFY_RETURN_INT_EXC(uint64_t, long, PyLong_AsLong(x)) - } else if ((sizeof(uint64_t) <= sizeof(PY_LONG_LONG))) { - __PYX_VERIFY_RETURN_INT_EXC(uint64_t, PY_LONG_LONG, PyLong_AsLongLong(x)) - } - } - { - uint64_t val; - int ret = -1; -#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API - Py_ssize_t bytes_copied = PyLong_AsNativeBytes( - x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0)); - if (unlikely(bytes_copied == -1)) { - } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) { - goto raise_overflow; - } else { - ret = 0; - } -#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray) - int one = 1; int is_little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&val; - ret = _PyLong_AsByteArray((PyLongObject *)x, - bytes, sizeof(val), - is_little, !is_unsigned); -#else - PyObject *v; - PyObject *stepval = NULL, *mask = NULL, *shift = NULL; - int bits, remaining_bits, is_negative = 0; - int chunk_size = (sizeof(long) < 8) ? 30 : 62; - if (likely(PyLong_CheckExact(x))) { - v = __Pyx_NewRef(x); - } else { - v = PyNumber_Long(x); - if (unlikely(!v)) return (uint64_t) -1; - assert(PyLong_CheckExact(v)); - } - { - int result = PyObject_RichCompareBool(v, Py_False, Py_LT); - if (unlikely(result < 0)) { - Py_DECREF(v); - return (uint64_t) -1; - } - is_negative = result == 1; - } - if (is_unsigned && unlikely(is_negative)) { - Py_DECREF(v); - goto raise_neg_overflow; - } else if (is_negative) { - stepval = PyNumber_Invert(v); - Py_DECREF(v); - if (unlikely(!stepval)) - return (uint64_t) -1; - } else { - stepval = v; - } - v = NULL; - val = (uint64_t) 0; - mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done; - shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done; - for (bits = 0; bits < (int) sizeof(uint64_t) * 8 - chunk_size; bits += chunk_size) { - PyObject *tmp, *digit; - long idigit; - digit = PyNumber_And(stepval, mask); - if (unlikely(!digit)) goto done; - idigit = PyLong_AsLong(digit); - Py_DECREF(digit); - if (unlikely(idigit < 0)) goto done; - val |= ((uint64_t) idigit) << bits; - tmp = PyNumber_Rshift(stepval, shift); - if (unlikely(!tmp)) goto done; - Py_DECREF(stepval); stepval = tmp; - } - Py_DECREF(shift); shift = NULL; - Py_DECREF(mask); mask = NULL; - { - long idigit = PyLong_AsLong(stepval); - if (unlikely(idigit < 0)) goto done; - remaining_bits = ((int) sizeof(uint64_t) * 8) - bits - (is_unsigned ? 0 : 1); - if (unlikely(idigit >= (1L << remaining_bits))) - goto raise_overflow; - val |= ((uint64_t) idigit) << bits; - } - if (!is_unsigned) { - if (unlikely(val & (((uint64_t) 1) << (sizeof(uint64_t) * 8 - 1)))) - goto raise_overflow; - if (is_negative) - val = ~val; - } - ret = 0; - done: - Py_XDECREF(shift); - Py_XDECREF(mask); - Py_XDECREF(stepval); -#endif - if (unlikely(ret)) - return (uint64_t) -1; - return val; - } -raise_overflow: - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to uint64_t"); - return (uint64_t) -1; -raise_neg_overflow: - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to uint64_t"); - return (uint64_t) -1; -} - /* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyLong_From_unsigned_int(unsigned int value) { #ifdef __Pyx_HAS_GCC_DIAGNOSTIC @@ -15108,6 +15466,256 @@ static CYTHON_INLINE PyObject* __Pyx_PyLong_From_unsigned_int(unsigned int value } } +/* CIntFromPy */ +static CYTHON_INLINE unsigned int __Pyx_PyLong_As_unsigned_int(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const unsigned int neg_one = (unsigned int) -1, const_zero = (unsigned int) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; + if (unlikely(!PyLong_Check(x))) { + unsigned int val; + PyObject *tmp = __Pyx_PyNumber_Long(x); + if (!tmp) return (unsigned int) -1; + val = __Pyx_PyLong_As_unsigned_int(tmp); + Py_DECREF(tmp); + return val; + } + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + if (unlikely(__Pyx_PyLong_IsNeg(x))) { + goto raise_neg_overflow; + } else if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(unsigned int, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_DigitCount(x)) { + case 2: + if ((8 * sizeof(unsigned int) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(unsigned int) >= 2 * PyLong_SHIFT)) { + return (unsigned int) (((((unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])); + } + } + break; + case 3: + if ((8 * sizeof(unsigned int) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(unsigned int) >= 3 * PyLong_SHIFT)) { + return (unsigned int) (((((((unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])); + } + } + break; + case 4: + if ((8 * sizeof(unsigned int) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(unsigned int) >= 4 * PyLong_SHIFT)) { + return (unsigned int) (((((((((unsigned int)digits[3]) << PyLong_SHIFT) | (unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])); + } + } + break; + } + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7 + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (unsigned int) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if ((sizeof(unsigned int) <= sizeof(unsigned long))) { + __PYX_VERIFY_RETURN_INT_EXC(unsigned int, unsigned long, PyLong_AsUnsignedLong(x)) + } else if ((sizeof(unsigned int) <= sizeof(unsigned PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(unsigned int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(unsigned int, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_SignedDigitCount(x)) { + case -2: + if ((8 * sizeof(unsigned int) - 1 > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(unsigned int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(unsigned int) - 1 > 2 * PyLong_SHIFT)) { + return (unsigned int) (((unsigned int)-1)*(((((unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]))); + } + } + break; + case 2: + if ((8 * sizeof(unsigned int) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(unsigned int) - 1 > 2 * PyLong_SHIFT)) { + return (unsigned int) ((((((unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]))); + } + } + break; + case -3: + if ((8 * sizeof(unsigned int) - 1 > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(unsigned int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(unsigned int) - 1 > 3 * PyLong_SHIFT)) { + return (unsigned int) (((unsigned int)-1)*(((((((unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]))); + } + } + break; + case 3: + if ((8 * sizeof(unsigned int) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(unsigned int) - 1 > 3 * PyLong_SHIFT)) { + return (unsigned int) ((((((((unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]))); + } + } + break; + case -4: + if ((8 * sizeof(unsigned int) - 1 > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(unsigned int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(unsigned int) - 1 > 4 * PyLong_SHIFT)) { + return (unsigned int) (((unsigned int)-1)*(((((((((unsigned int)digits[3]) << PyLong_SHIFT) | (unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]))); + } + } + break; + case 4: + if ((8 * sizeof(unsigned int) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(unsigned int) - 1 > 4 * PyLong_SHIFT)) { + return (unsigned int) ((((((((((unsigned int)digits[3]) << PyLong_SHIFT) | (unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]))); + } + } + break; + } + } +#endif + if ((sizeof(unsigned int) <= sizeof(long))) { + __PYX_VERIFY_RETURN_INT_EXC(unsigned int, long, PyLong_AsLong(x)) + } else if ((sizeof(unsigned int) <= sizeof(PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(unsigned int, PY_LONG_LONG, PyLong_AsLongLong(x)) + } + } + { + unsigned int val; + int ret = -1; +#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API + Py_ssize_t bytes_copied = PyLong_AsNativeBytes( + x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0)); + if (unlikely(bytes_copied == -1)) { + } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) { + goto raise_overflow; + } else { + ret = 0; + } +#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray) + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + ret = _PyLong_AsByteArray((PyLongObject *)x, + bytes, sizeof(val), + is_little, !is_unsigned); +#else + PyObject *v; + PyObject *stepval = NULL, *mask = NULL, *shift = NULL; + int bits, remaining_bits, is_negative = 0; + int chunk_size = (sizeof(long) < 8) ? 30 : 62; + if (likely(PyLong_CheckExact(x))) { + v = __Pyx_NewRef(x); + } else { + v = PyNumber_Long(x); + if (unlikely(!v)) return (unsigned int) -1; + assert(PyLong_CheckExact(v)); + } + { + int result = PyObject_RichCompareBool(v, Py_False, Py_LT); + if (unlikely(result < 0)) { + Py_DECREF(v); + return (unsigned int) -1; + } + is_negative = result == 1; + } + if (is_unsigned && unlikely(is_negative)) { + Py_DECREF(v); + goto raise_neg_overflow; + } else if (is_negative) { + stepval = PyNumber_Invert(v); + Py_DECREF(v); + if (unlikely(!stepval)) + return (unsigned int) -1; + } else { + stepval = v; + } + v = NULL; + val = (unsigned int) 0; + mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done; + shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done; + for (bits = 0; bits < (int) sizeof(unsigned int) * 8 - chunk_size; bits += chunk_size) { + PyObject *tmp, *digit; + long idigit; + digit = PyNumber_And(stepval, mask); + if (unlikely(!digit)) goto done; + idigit = PyLong_AsLong(digit); + Py_DECREF(digit); + if (unlikely(idigit < 0)) goto done; + val |= ((unsigned int) idigit) << bits; + tmp = PyNumber_Rshift(stepval, shift); + if (unlikely(!tmp)) goto done; + Py_DECREF(stepval); stepval = tmp; + } + Py_DECREF(shift); shift = NULL; + Py_DECREF(mask); mask = NULL; + { + long idigit = PyLong_AsLong(stepval); + if (unlikely(idigit < 0)) goto done; + remaining_bits = ((int) sizeof(unsigned int) * 8) - bits - (is_unsigned ? 0 : 1); + if (unlikely(idigit >= (1L << remaining_bits))) + goto raise_overflow; + val |= ((unsigned int) idigit) << bits; + } + if (!is_unsigned) { + if (unlikely(val & (((unsigned int) 1) << (sizeof(unsigned int) * 8 - 1)))) + goto raise_overflow; + if (is_negative) + val = ~val; + } + ret = 0; + done: + Py_XDECREF(shift); + Py_XDECREF(mask); + Py_XDECREF(stepval); +#endif + if (unlikely(ret)) + return (unsigned int) -1; + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to unsigned int"); + return (unsigned int) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned int"); + return (unsigned int) -1; +} + /* FormatTypeName */ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030d0000 static __Pyx_TypeName diff --git a/src/polluck_blockchain/placeholder_native.pyx b/src/polluck_blockchain/placeholder_native.pyx index fa5a3b5..f333105 100644 --- a/src/polluck_blockchain/placeholder_native.pyx +++ b/src/polluck_blockchain/placeholder_native.pyx @@ -21,15 +21,21 @@ from libc.stdlib cimport malloc, free from libc.string cimport memcpy from cython.operator import postincrement, dereference cimport polluck_blockchain.openssl_evp as ossl -from cython.parallel cimport prange +# from cython.parallel cimport prange ctypedef unsigned long ULong ctypedef unordered_map[uint64_t, Block*] BcHashmap +cdef const size_t NONCE_OFFSET = 16 cdef timestamp_to_datetime(uint64_t ts): return datetime.datetime.fromtimestamp(float(ts), dopt_basics.datetime.TIMEZONE_UTC) +cdef uint64_t current_timestamp_integer(): + cdef uint64_t ts + dt = dopt_basics.datetime.current_time_tz(cut_microseconds=True) + ts = int(dt.timestamp()) + return ts # cdef float_to_bytes(double num): # return struct.pack(">d", num) @@ -50,15 +56,6 @@ cdef int serialize_uint64(unsigned char* out, unsigned long long v) except -1 no out[6] = (v >> 8) & 0xFF out[7] = v & 0xFF -# cdef struct SerializeResult: -# unsigned char *ptr -# size_t size - -# cdef struct DigestResult: -# unsigned char *ptr -# size_t size - -cdef const size_t NONCE_OFFSET = 16 cdef inline bint has_leading_zero_bits(const unsigned char *digest, int num_bits) nogil: cdef int i, full_bytes = num_bits // 8 @@ -141,22 +138,6 @@ cdef class PyBlock: def __str__(self): return self.__repr__() - # cpdef _perform_hash(self): - # parts = bytearray() - # parts.extend(self._index.to_bytes(8, "big")) - # parts.extend(float_to_bytes(self._timestamp)) - # parts.extend(self._data) - # parts.extend(self._prev_hash) - # parts.extend(self._nonce.to_bytes(8, "big")) - - # return hashlib.sha256(parts) - - # def compute_hash_bytes(self): - # return self._perform_hash().digest() - - # def compute_hash(self): - # return self._perform_hash().hexdigest() - # Python public API @property def index(self): @@ -178,172 +159,159 @@ cdef class PyBlock: def nonce(self): return self.BlockC.nonce - # @nonce.setter - # def nonce(self, value: int): - # self._nonce = value - @property def hash(self): return self.BlockC.hash.decode("UTF-8") - cdef unsigned char* bytes_serialize_c(self, size_t *size) nogil: - cdef: - size_t total_len - unsigned char* buf - size_t pos = 0 - - # index (8), timestamp (8), nonce (8), data, prev_hash - size[0] = ( - (8 * 3) + - self.BlockC.data.size() + - self.BlockC.prev_hash.size() - ) - buf = malloc(size[0] * sizeof(unsigned char)) - - if buf == NULL: - return NULL - - serialize_uint64(buf + pos, self.BlockC.index) - pos += 8 - serialize_uint64(buf + pos, self.BlockC.timestamp) - pos += 8 - serialize_uint64(buf + pos, self.BlockC.nonce) - pos += 8 - # Copy data - memcpy( - buf + pos, - self.BlockC.data.c_str(), - self.BlockC.data.size(), - ) - pos += self.BlockC.data.size() - # Copy prev_hash - memcpy( - buf + pos, - self.BlockC.prev_hash.c_str(), - self.BlockC.prev_hash.size(), - ) - pos += self.BlockC.prev_hash.size() - - return buf - - cdef unsigned char* digest(self, unsigned char *data, size_t data_size, size_t *digest_size) nogil: - cdef ossl.EVP_MD_CTX *ctx = ossl.EVP_MD_CTX_new() - if ctx == NULL: - return NULL - cdef const ossl.EVP_MD *algo = ossl.EVP_sha256() - if algo == NULL: - return NULL - - cdef: - unsigned char* digest - size_t dig_buff_len - unsigned int digest_len - - dig_buff_len = ossl.EVP_MD_size(algo) - digest = malloc(dig_buff_len * sizeof(unsigned char)) - ossl.EVP_DigestInit_ex(ctx, algo, NULL) - ossl.EVP_DigestUpdate(ctx, data, data_size) - ossl.EVP_DigestFinal_ex(ctx, digest, &digest_len) - - digest_size[0] = dig_buff_len - - ossl.EVP_MD_CTX_free(ctx) - - return digest - def bytes_serialize(self): cdef: unsigned char *serialize_res size_t serialize_size try: - serialize_res = self.bytes_serialize_c(&serialize_size) + serialize_res = bytes_serialize_c(self.BlockC, &serialize_size) return serialize_res[:serialize_size] finally: free(serialize_res) - - cpdef mine(self, unsigned int difficulty, unsigned int max_nonce=0xFFFFFFFF): - cdef: - unsigned char *serial_buf - size_t serialize_size - unsigned char *digest - size_t digest_size - bint nonce_found = False - int nonce, nonce_solution = 0 - serial_buf = self.bytes_serialize_c(&serialize_size) - - with nogil: - for nonce in range(max_nonce): - serialize_uint64(serial_buf + NONCE_OFFSET, nonce) - digest = self.digest(serial_buf, serialize_size, &digest_size) - if has_leading_zero_bits(digest, difficulty): - nonce_found = True - nonce_solution = nonce - break - - free(digest) - - if not nonce_found: - raise RuntimeError("No valid nonce found") - - self.BlockC.nonce = nonce_solution - - cdef unsigned char* perform_hash_c(self, size_t *digest_size) nogil: - cdef: - unsigned char *serialize_res - size_t serialize_size - unsigned char *digest - - serialize_res = self.bytes_serialize_c(&serialize_size) - if serialize_res == NULL: - return NULL - digest = self.digest(serialize_res, serialize_size, digest_size) - if digest == NULL: - return NULL - - free(serialize_res) - - return digest - - cpdef perform_hash(self): + def perform_hash(self): cdef: unsigned char *digest size_t digest_size try: - digest = self.perform_hash_c(&digest_size) + digest = perform_hash_c(self.BlockC, &digest_size) if digest == NULL: raise MemoryError() + # TODO out: hash assignment in blockchain self.BlockC.hash = bytes(digest[:digest_size]).hex().encode("UTF-8") finally: free(digest) - + # TODO rework return self.hash +cdef unsigned char* bytes_serialize_c(Block *block, size_t *size) nogil: + cdef: + size_t total_len + unsigned char* buf + size_t pos = 0 + + # index (8), timestamp (8), nonce (8), data, prev_hash + size[0] = ( + (8 * 3) + + block.data.size() + + block.prev_hash.size() + ) + buf = malloc(size[0] * sizeof(unsigned char)) + + if buf == NULL: + return NULL + + serialize_uint64(buf + pos, block.index) + pos += 8 + serialize_uint64(buf + pos, block.timestamp) + pos += 8 + serialize_uint64(buf + pos, block.nonce) + pos += 8 + # Copy data + memcpy( + buf + pos, + block.data.c_str(), + block.data.size(), + ) + pos += block.data.size() + # Copy prev_hash + memcpy( + buf + pos, + block.prev_hash.c_str(), + block.prev_hash.size(), + ) + pos += block.prev_hash.size() + + return buf + +cdef unsigned char* SHA256_digest(const void *data, size_t data_size, size_t *digest_size) nogil: + cdef ossl.EVP_MD_CTX *ctx = ossl.EVP_MD_CTX_new() + if ctx == NULL: + return NULL + cdef const ossl.EVP_MD *algo = ossl.EVP_sha256() + if algo == NULL: + return NULL + + cdef: + unsigned char* digest + size_t dig_buff_len + unsigned int digest_len + + dig_buff_len = ossl.EVP_MD_size(algo) + digest_size[0] = dig_buff_len + digest = malloc(dig_buff_len * sizeof(unsigned char)) + ossl.EVP_DigestInit_ex(ctx, algo, NULL) + ossl.EVP_DigestUpdate(ctx, data, data_size) + ossl.EVP_DigestFinal_ex(ctx, digest, &digest_len) + + ossl.EVP_MD_CTX_free(ctx) + + return digest +cdef unsigned char* perform_hash_c(Block *block, size_t *digest_size) nogil: + cdef: + unsigned char *serialize_res + size_t serialize_size + unsigned char *digest + + serialize_res = bytes_serialize_c(block, &serialize_size) + if serialize_res == NULL: + return NULL + digest = SHA256_digest(serialize_res, serialize_size, digest_size) + free(serialize_res) + if digest == NULL: + return NULL + + return digest - # @hash.setter - # def hash(self, value): - # if not isinstance(value, str): - # raise TypeError("No string") - # self._hash = value.encode("UTF-8") +cdef int mine_block(Block *block, unsigned int difficulty, uint64_t *nonce_solution, unsigned int max_nonce=0xFFFFFFFF) nogil: + cdef: + unsigned char *serial_buf + size_t serialize_size + unsigned char *digest + size_t digest_size + bint nonce_found = False + int nonce -# cdef void add_block(BcHashmap *map, Block *block): -# map[block.index] = block + serial_buf = bytes_serialize_c(block, &serialize_size) + + with nogil: + for nonce in range(max_nonce): + serialize_uint64(serial_buf + NONCE_OFFSET, nonce) + digest = SHA256_digest(serial_buf, serialize_size, &digest_size) + + if has_leading_zero_bits(digest, difficulty): + nonce_found = True + nonce_solution[0] = nonce + break + + free(digest) + + free(serial_buf) + + if not nonce_found: + return 1 + + return 0 cdef class Blockchain: - cdef int _difficulty + cdef unsigned int _difficulty cdef uint64_t _index cdef BcHashmap *_chain cdef bint _genesis_done def __cinit__(self): - self._difficulty = 1 + self._difficulty = 26 self._index = 0 self._genesis_done = 0 self._chain = new unordered_map[uint64_t, Block*]() @@ -351,8 +319,9 @@ cdef class Blockchain: raise MemoryError("Could not allocate hasmap") def __init__(self, *args, **kwargs): + # self.db_path = db_path pass - + def __dealloc__(self): # ownership is typically not transferred from the Blockchain extension class cdef BcHashmap.iterator it = self._chain.begin() @@ -367,6 +336,26 @@ cdef class Blockchain: def __len__(self): return self._index + 1 + @property + def difficulty(self): + return self._difficulty + + @difficulty.setter + def difficulty(self, value): + if not isinstance(value, int): + raise TypeError("Difficulty must be integer value") + if value <= 0: + raise ValueError("Difficulty must be greater than 0") + self._difficulty = value + + @property + def genesis_done(self): + return self._genesis_done + + @property + def index(self): + return self._index + def print_key_value_pair(self): cdef BcHashmap.iterator it = self._chain.begin() cdef Block *block @@ -377,109 +366,101 @@ cdef class Blockchain: print(py_block) postincrement(it) - @property - def genesis_done(self): - return self._genesis_done - - @property - def index(self): - return self._index - - # TODO error handling - cdef Block* get_block_c(self, uint64_t idx): + cdef Block* get_block_c(self, uint64_t idx) nogil: + if idx > self._index: + return NULL return self._chain[0][idx] + + cdef int add_block(self, Block *block) nogil: + cdef: + uint64_t mined_nonce + size_t digest_size + unsigned char *sha256_digest + # mine block + if mine_block(block, self._difficulty, &mined_nonce) != 0: + return 1 + block.nonce = mined_nonce + # hash block, add hash to block, add block to blockchain hashmap + sha256_digest = perform_hash_c(block, &digest_size) + with gil: + block.hash = bytes(sha256_digest[:digest_size]).hex().encode("UTF-8") + free(sha256_digest) + self._chain[0][block.index] = block + + if self._genesis_done: + self._index += 1 + + return 0 + # // Python public API def get_block(self, idx): if idx < 0 or idx > self._index: raise IndexError("Index value is out of bounds") cdef Block *block = self.get_block_c(idx) + if block == NULL: + raise IndexError("Provided index not found") return PyBlock.from_ptr(block, owner=False) - cdef void add_block(self, Block *block): - self._chain[0][block.index] = block - if self._genesis_done: - self._index += 1 + cdef string hash_data(self, data): + cdef: + string data_str + unsigned char *data_digest + size_t digest_size + data_str = data.encode("UTF-8") + data_digest = SHA256_digest(data_str.c_str(), data_str.size(), &digest_size) + if data_digest == NULL: + raise RuntimeError("Failed to hash data") + data_str = bytes(data_digest[:digest_size]).hex().encode("UTF-8") + free(data_digest) + + return data_str def create_genesis_block(self): + genesis_prev_hash = ("0" * 64).encode("UTF-8") + cdef string data_str = self.hash_data("Genesis Block") + cdef Block *block = new Block( self._index, int(datetime.datetime(2025, 12, 1, 12, 0, 0).timestamp()), 0, - "Genesis Block".encode("UTF-8"), - "0".encode("UTF-8"), + data_str, + genesis_prev_hash, "".encode("UTF-8"), ) - block.hash = "dummy hash".encode("UTF-8") - self.add_block(block) + cdef int res = self.add_block(block) + if res != 0: + raise RuntimeError("Could not mine block. No nonce found") self._genesis_done = True def new_block(self, data): + cdef: + Block *prev_block + string prev_hash + uint64_t new_idx + string data_str + unsigned char *data_digest + size_t digest_size + if not self._genesis_done: raise RuntimeError("Create a genesis block first.") + if not isinstance(data, str): + raise TypeError("Data must be a string") - cdef Block *prev_block = self.get_block_c(self._index) - cdef string prev_hash = prev_block.prev_hash - cdef uint64_t new_idx = self._index + 1 + data_str = self.hash_data(data) + prev_block = self.get_block_c(self._index) + prev_hash = prev_block.prev_hash + new_idx = self._index + 1 cdef Block *block = new Block( new_idx, int(datetime.datetime(2025, 12, 1, 12, 0, 0).timestamp()), 0, - data.encode("UTF-8"), + data_str, prev_hash, "".encode("UTF-8"), ) - self.add_block(block) + cdef int res = self.add_block(block) + if res != 0: + raise RuntimeError("Could not mine block. No nonce found") -# def __init__( -# self, -# difficulty: int = 1, -# ) -> None: -# self._difficulty = difficulty - - # @property - # def index(self): - # return self._index - - # @property - # def difficulty(self): - # return self._difficulty - - # cdef create_genesis_block(self): - # genesis = Block( - # index=0, - # data="Genesis Block", - # previous_hash="0", - # nonce=0, - # ) - # genesis.hash = genesis.compute_hash() - # self.chain[self._index] = genesis - - # cdef proof_of_work(self, block: Block): - # prefix = "0" * self._difficulty - # while True: - # block_hash = block.compute_hash() - # if block_hash.startswith(prefix): - # return block_hash - # block._nonce += 1 - - # cdef add_block(self, data: str): - # prev_hash = self.chain[self._index].hash - # new_block = Block( - # index=(self._index + 1), - # data=data, - # previous_hash=prev_hash, - # nonce=0, - # ) - - # # start = time.perf_counter() - # new_block.hash = self.proof_of_work(new_block) - # # elapsed = time.perf_counter() - start - - # self.chain.append(new_block) - # self._index += 1 - # print(f"Mined block {new_block.index} with nonce={new_block.nonce}") - # # print(f"Mined block {new_block.index} in {elapsed:.3f}s with nonce={new_block.nonce}") - - # return new_block