diff --git a/.gitignore b/.gitignore index c6127b38c1aa25968a88db3940604d41529e4cf5..a752edf4c581d5a2b4fa518a38f5f0128d4e5e3d 100644 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,9 @@ *.idb *.pdb +#Build directory +build/ + # Kernel Module Compile Results *.mod* *.cmd diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000000000000000000000000000000000..e27df003d77cbf6733ddb33c3decc699459bb7de --- /dev/null +++ b/.gitmodules @@ -0,0 +1,63 @@ +[submodule "libdap"] + path = libdap + url = https://gitlab.demlabs.net/cellframe/libdap.git +[submodule "libdap-chain"] + path = libdap-chain + url = https://gitlab.demlabs.net/cellframe/libdap-chain.git +[submodule "libdap-chain-crypto"] + path = libdap-chain-crypto + url = https://gitlab.demlabs.net/cellframe/libdap-chain-crypto.git +[submodule "libdap-crypto"] + path = libdap-crypto + url = https://gitlab.demlabs.net/cellframe/libdap-crypto.git +[submodule "libdap-chain-mempool"] + path = libdap-chain-mempool + url = https://gitlab.demlabs.net/cellframe/libdap-chain-mempool.git +[submodule "libdap-server-core"] + path = libdap-server-core + url = https://gitlab.demlabs.net/cellframe/libdap-server-core.git +[submodule "libdap-chain-net"] + path = libdap-chain-net + url = https://gitlab.demlabs.net/cellframe/libdap-chain-net.git +[submodule "libdap-chain-global-db"] + path = libdap-chain-global-db + url = https://gitlab.demlabs.net/cellframe/libdap-chain-global-db.git +[submodule "libdap-client"] + path = libdap-client + url = https://gitlab.demlabs.net/cellframe/libdap-client.git +[submodule "libdap-server"] + path = libdap-server + url = https://gitlab.demlabs.net/cellframe/libdap-server.git +[submodule "libdap-stream"] + path = libdap-stream + url = https://gitlab.demlabs.net/cellframe/libdap-stream.git +[submodule "libdap-stream-ch"] + path = libdap-stream-ch + url = https://gitlab.demlabs.net/cellframe/libdap-stream-ch.git +[submodule "libdap-server-udp"] + path = libdap-server-udp + url = https://gitlab.demlabs.net/cellframe/libdap-server-udp.git +[submodule "libdap-stream-ch-chain-net"] + path = libdap-stream-ch-chain-net + url = https://gitlab.demlabs.net/cellframe/libdap-stream-ch-chain-net.git +[submodule "libdap-stream-ch-chain"] + path = libdap-stream-ch-chain + url = https://gitlab.demlabs.net/cellframe/libdap-stream-ch-chain.git +[submodule "libdap-chain-wallet"] + path = libdap-chain-wallet + url = https://gitlab.demlabs.net/cellframe/libdap-chain-wallet.git +[submodule "libdap-chain-net-srv"] + path = libdap-chain-net-srv + url = https://gitlab.demlabs.net/cellframe/libdap-chain-net-srv.git +[submodule "libdap-server-http-db-auth"] + path = libdap-server-http-db-auth + url = https://gitlab.demlabs.net/cellframe/libdap-server-http-db-auth.git +[submodule "libdap-chain-gdb"] + path = libdap-chain-gdb + url = https://gitlab.demlabs.net/cellframe/libdap-chain-gdb.git +[submodule "libdap-crypto-python"] + path = libdap-crypto-python + url = https://gitlab.demlabs.net/cellframe/libdap-crypto-python.git +[submodule "libdap-python"] + path = libdap-python + url = https://gitlab.demlabs.net/cellframe/libdap-python.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..739291c39fd271223a178e4f129b977a1253a3ef --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,97 @@ +project(dap_chain_python_module C) +cmake_minimum_required(VERSION 2.8) + +set(CMAKE_VERBOSE_MAKEFILE ON) +set(CMAKE_COLOR_MAKEFILE ON) +set(CMAKE_C_STANDARD 11) +set(SUBMODULES_NO_BUILD ON) +add_definitions("-fpic") + +#if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON)) +# if (NOT (TARGET dap_core)) + add_subdirectory(libdap) +# target_compile_options( +# dap_core PRIVATE +# "-fpic" +# ) +# endif() +# if (NOT (TARGET dap_crypto)) +# add_subdirectory(libdap-crypto) +# target_compile_options( +# dap_crypto PRIVATE +# "-fpic" + # ) + # endif() +#endif() +#add_definitions("-DDAP_APP_NAME=\"TestPRJ\" -DSYSTEM_CONFIGS_DIR=\"${CMAKE_CURRENT_BINARY_DIR}\"") +add_definitions ("-DNODE_NETNAME=\"cellframe\"") +if(UNIX) + add_definitions("-DDAP_OS_UNIX") +endif() + +add_subdirectory(libdap-python) +add_subdirectory(libdap-crypto) +add_subdirectory(libdap-chain) +add_subdirectory(libdap-chain-crypto) +add_subdirectory(libdap-chain-mempool) +add_subdirectory(libdap-chain-net) +add_subdirectory(libdap-server-core) +add_subdirectory(libdap-chain-global-db) +add_subdirectory(libdap-client) +add_subdirectory(libdap-server) +add_subdirectory(libdap-stream) +add_subdirectory(libdap-stream-ch) +add_subdirectory(libdap-server-udp) +add_subdirectory(libdap-stream-ch-chain-net) +add_subdirectory(libdap-stream-ch-chain) +add_subdirectory(libdap-chain-wallet) +add_subdirectory(libdap-chain-net-srv) +add_subdirectory(libdap-server-http-db-auth) +add_subdirectory(libdap-chain-gdb) +add_subdirectory(libdap-crypto-python) + +file(GLOB CHAIN_PYTHON_SRCS src/*.c) +file(GLOB CHAIN_PYTHON_HEADERS include/*.h) + +set(Python_ADDITIONAL_VERSIONS 3.7) +find_package (PythonLibs REQUIRED) +include_directories(${PYTHON_INCLUDE_DIR} include/) + +add_library(${PROJECT_NAME} STATIC ${CHAIN_PYTHON_SRCS} ${CHAIN_PYTHON_HEADERS}) + +target_link_libraries(${PROJECT_NAME}) + +#target_compile_options( +# dap_core PRIVATE +# "-fpic" +#) +#target_compile_options( +# dap_crypto PRIVATE +# "-fpic" +#) + + +target_link_libraries(${PROJECT_NAME} dap_core dap_crypto dap_chain dap_chain_crypto dap_server_core dap_chain_net dap_crypto_python_module dap_python_module) +#target_link_libraries(${PROJECT_NAME} dap_core dap_crypto dap_chain dap_chain_global_db dap_chain_crypto dap_chain_mempool +# +# ) #dap_chain_crypto dap_chain_mempool dap_chain_global_db ) +#target_link_libraries(${PROJECT_NAME} dap_core dap_crypto) + +target_include_directories(${PROJECT_NAME} PUBLIC include/ ) + +#if(BUILD_DAP_CRYPTO_PYTHON_TESTS) +# add_subdirectory(test) +# file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/test_b58.py +# DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/) +# file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/test_b64.py +# DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/) +# file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/test_iaes256_cbc.py +# DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/) +# file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/test_iaes256_cbc.py +# DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/) +# file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/test_oaes.py +# DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/) + + +#endif() + diff --git a/include/dap_defines.h b/include/dap_defines.h new file mode 100644 index 0000000000000000000000000000000000000000..cff99e5ae2921471a13f379a58e25752d5f50d34 --- /dev/null +++ b/include/dap_defines.h @@ -0,0 +1,21 @@ +#pragma once +#define DAP_APP_NAME NODE_NETNAME "-node" + +//#ifdef _WIN32 +// #define SYSTEM_PREFIX "%USERPROFILE%/opt/"DAP_APP_NAME +//#else + #define SYSTEM_PREFIX "/opt/"DAP_APP_NAME +// #define SYSTEM_PREFIX "opt/"DAP_APP_NAME +//#endif + +#define LOCAL_PREFIX "~/."DAP_APP_NAME + +#define SYSTEM_CONFIGS_DIR SYSTEM_PREFIX"/etc" +#define LOCAL_CONFIGS_DIR LOCAL_PREFIX"/etc" +#define SYSTEM_LOGS_DIR SYSTEM_PREFIX"/var/log" + +#define SYSTEM_CONFIG_GLOBAL_FILENAME SYSTEM_PREFIX"/etc/"DAP_APP_NAME".cfg" +#define LOCAL_CONFIG_GLOBAL LOCAL_PREFIX"/etc/"DAP_APP_NAME".cfg" + +#define SYSTEM_PID_FILE_PATH SYSTEM_PREFIX"/run/"DAP_APP_NAME".pid" +#define LOCAL_PID_FILE_PATH SYSTEM_PREFIX"/run/"DAP_APP_NAME".pid" diff --git a/include/libdap-chain-python.h b/include/libdap-chain-python.h new file mode 100644 index 0000000000000000000000000000000000000000..aea379053f2371d8060985fe76e5cc9081158913 --- /dev/null +++ b/include/libdap-chain-python.h @@ -0,0 +1,101 @@ +#define PY_SSIZE_T_CLEAN + +//#define DAP_APP_NAME NODE_NETNAME "-node" +//#define SYSTEM_PREFIX "/opt/"DAP_APP_NAME +//#define SYSTEM_CONFIGS_DIR SYSTEM_PREFIX"/etc" + +#include "Python.h" +#include "dap_defines.h" +//#define DAP_APP_NAME "BINDING_CHAIN_PYTHON" +#include "dap_chain.h" +#include "dap_chain_node_client.h" +#include "wrapping_dap_chain_ledger.h" +#include "wrapping_dap_chain_common_objects.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#undef LOG_TAG +#define LOG_TAG "libdap-chain-python" + +typedef struct PyDapChain{ + PyObject_HEAD + dap_chain_t *chain_t; +} PyDapChainObject; + +int init_chain_py(); +void deinit_chain_py(); + +void PyDapChainObject_dealloc(PyDapChainObject* chain); +PyObject *PyDapChainObject_new(PyTypeObject *type_object, PyObject *args, PyObject *kwds); + + +PyObject *dap_chain_find_by_id_py(PyObject *self, PyObject *args); +//PyObject *dap_chain_load_from_cfg_py(PyObject *self, PyObject *args); +PyObject *dap_chain_has_file_store_py(PyObject *self, PyObject *args); +PyObject *dap_chain_save_all_py(PyObject *self, PyObject *args); +PyObject *dap_chain_load_all_py(PyObject *self, PyObject *args); +PyObject *dap_chain_load_from_cfg_py(PyObject *self, PyObject *args); +//PyObject *dap_chain_init_net_cfg_name_py(PyObject *self, PyObject *args); //dap_chain_init_net_cfg_name +//PyObject *dap_chain_close_py(PyObject *self, PyObject *args); +//PyObject *dap_chain_info_dump_log_py(PyObject *self, PyObject *args); //dap_chain_info_dump_log + +static PyMethodDef DapChainMethods[] = { + {"findById", (PyCFunction)dap_chain_find_by_id_py, METH_VARARGS|METH_STATIC, ""}, + {"loadFromCfg", (PyCFunction)dap_chain_has_file_store_py, METH_VARARGS|METH_STATIC, ""}, + {"hasFileStore", (PyCFunction)dap_chain_has_file_store_py, METH_NOARGS, ""}, + {"saveAll", (PyCFunction)dap_chain_save_all, METH_NOARGS, ""}, + {"loadAll", (PyCFunction)dap_chain_load_all_py, METH_NOARGS, ""}, + //{"close", (PyCFunction)dap_chain_close_py, METH_NOARGS, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject dapChainObject_dapChainType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain", /* tp_name */ + sizeof(PyDapChainObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PyDapChainObject_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainMethods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyDapChainObject_new, /* tp_new */ + +}; + +#ifdef __cplusplus +} +#endif + + diff --git a/include/libdap_chain_atom_iter_python.h b/include/libdap_chain_atom_iter_python.h new file mode 100644 index 0000000000000000000000000000000000000000..0f09dd345b26de1c2a188d6d3615061acaa34407 --- /dev/null +++ b/include/libdap_chain_atom_iter_python.h @@ -0,0 +1,62 @@ +#include "Python.h" +#include "dap_chain.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyChainAtomPtr{ + PyObject_HEAD + dap_chain_atom_iter_t *atom_iter; +} PyChainAtomIterObject; + +static PyMethodDef DapChainAtomIterMethods[] = { + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject dapChainAtomPtr_dapChainAtomPtrType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.AtomIter", /* tp_name */ + sizeof(PyChainAtomIterObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain atom iter objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainAtomIterMethods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ + +}; + +#ifdef __cplusplus +} +#endif diff --git a/include/libdap_chain_type_python.h b/include/libdap_chain_type_python.h new file mode 100644 index 0000000000000000000000000000000000000000..029b9f916912825794a3f797671be99a165e5545 --- /dev/null +++ b/include/libdap_chain_type_python.h @@ -0,0 +1,64 @@ +#include "Python.h" +#include "dap_chain.h" + +typedef struct PyChainType{ + PyObject_HEAD +} PyChainTypeObject; + +PyObject* CHAIN_TYPE_FIRST_PY(); +PyObject* CHAIN_TYPE_TOKEN_PY(); +PyObject* CHAIN_TYPE_EMISSION_PY(); +PyObject* CHAIN_TYPE_TX_PY(); +PyObject* CHAIN_TYPE_LAST_PY(); + +static PyMethodDef DapChainTypeMethods[] = { + {"CHAIN_TYPE_FIRST", (PyCFunction)CHAIN_TYPE_FIRST_PY, METH_NOARGS|METH_STATIC, ""}, + {"CHAIN_TYPE_TOKEN", (PyCFunction)CHAIN_TYPE_TOKEN_PY, METH_NOARGS|METH_STATIC, ""}, + {"CHAIN_TYPE_EMISSION", (PyCFunction)CHAIN_TYPE_EMISSION_PY, METH_NOARGS|METH_STATIC, ""}, + {"CHAIN_TYPE_TX", (PyCFunction)CHAIN_TYPE_TX_PY, METH_NOARGS|METH_STATIC, ""}, + {"CHAIN_TYPE_LAST", (PyCFunction)CHAIN_TYPE_LAST_PY, METH_NOARGS|METH_STATIC, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject dapChainTypeObject_dapChainTypeType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.Type", /* tp_name */ + sizeof(PyChainTypeObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain type objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainTypeMethods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ + +}; diff --git a/include/wrapping_dap_chain_cell.h b/include/wrapping_dap_chain_cell.h new file mode 100644 index 0000000000000000000000000000000000000000..f25d82973055a3a12c537d5a76a1bf627ab58ca1 --- /dev/null +++ b/include/wrapping_dap_chain_cell.h @@ -0,0 +1,175 @@ +#ifndef _WRAPPING_DAP_CHAIN_CELL_ +#define _WRAPPING_DAP_CHAIN_CELL_ +#include "Python.h" +#include "dap_chain_cell.h" +#include "libdap-chain-python.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int init(void); + +/* DAP chain cell */ +typedef struct PyDapChainCell{ + PyObject_HEAD + dap_chain_cell_t *cell; +}PyDapChainCellObject; + +void DapChainCellObject_delete(PyDapChainCellObject* object); +PyObject *DapChainCellObject_create(PyTypeObject *type_object, PyObject *args, PyObject *kwds); + +PyObject *dap_chain_cell_load_py(PyObject *self, PyObject *args); +PyObject *dap_chain_cell_file_update_py(PyObject *self, PyObject *args); +PyObject *dap_chain_cell_file_append_py(PyObject *self, PyObject *args); + +static PyMethodDef PyDapChainCellObjectMethods[] ={ + {"load", dap_chain_cell_load_py, METH_VARARGS | METH_STATIC, ""}, + {"update", dap_chain_cell_file_update_py, METH_VARARGS, ""}, + {"append", dap_chain_cell_file_append_py, METH_VARARGS, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainCell_DapChainCellObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.Cell", /* tp_name */ + sizeof(PyDapChainCellObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain cell object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyDapChainCellObjectMethods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +/* ------------------------------------------- */ + +typedef struct PyDapChainCellDeclReq{ + PyObject_HEAD + dap_chain_cell_decl_req_t *decl_req; +}PyDapChainCellDeclReqObject; + +static PyTypeObject DapChainCellDeclReq_DapChainCellDeclReqObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.DapChainCellDeclReq", /* tp_name */ + sizeof(PyDapChainCellDeclReqObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain cell decl req object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +typedef struct PyDapChainCellDecl{ + PyObject_HEAD + dap_chain_cell_decl_t* decl; +}PyDapChainDeclObject; + +static PyTypeObject DapChainDecl_DapChainDeclObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.DapChainCellDecl", /* tp_name */ + sizeof(PyDapChainDeclObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain cell decl object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +#ifdef __cplusplus +} +#endif + +#endif //_WRAPPING_DAP_CHAIN_CELL_ diff --git a/include/wrapping_dap_chain_common.h b/include/wrapping_dap_chain_common.h new file mode 100644 index 0000000000000000000000000000000000000000..1783327d3f3da74e446163982ba864fa59813d83 --- /dev/null +++ b/include/wrapping_dap_chain_common.h @@ -0,0 +1,76 @@ +#include "Python.h" +#include "dap_chain_common.h" +#include "wrapping_dap_chain_common_objects.h" +#include "libdap_crypto_key_python.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyDapChainCommon{ + PyObject_HEAD +}PyDapChainCommonObject; + +PyObject *dap_chain_hash_slow_to_str_py(PyObject *self, PyObject *args); +PyObject *dap_chain_str_to_hash_fast_py(PyObject *self, PyObject *args); +PyObject *dap_chain_addr_to_str_py(PyObject *self, PyObject *args); +PyObject *dap_chain_addr_from_str_py(PyObject *self, PyObject *args); +PyObject *dap_chain_addr_fill_py(PyObject *self, PyObject *args); +PyObject *dap_chain_addr_check_sum_py(PyObject *self, PyObject *args); + +static PyMethodDef PyDapChainCommonObjectMethods[] ={ + {"hashSlowToStr", dap_chain_hash_slow_to_str_py, METH_VARARGS|METH_STATIC, ""}, + {"strTpHashFast", dap_chain_str_to_hash_fast_py, METH_VARARGS|METH_STATIC, ""}, + {"addrToStr", dap_chain_addr_to_str_py, METH_VARARGS|METH_STATIC, ""}, + {"addrFromStr", dap_chain_addr_from_str_py, METH_VARARGS|METH_STATIC, ""}, + {"addrFill", dap_chain_addr_fill_py, METH_VARARGS|METH_STATIC, ""}, + {"addrCheckSum", dap_chain_addr_check_sum_py, METH_VARARGS|METH_STATIC, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject ChainCommonObject_ChainCommonType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.Common", /* tp_name */ + sizeof(PyDapChainCommonObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain common objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyDapChainCommonObjectMethods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ + +}; + +#ifdef __cplusplus +} +#endif diff --git a/include/wrapping_dap_chain_common_objects.h b/include/wrapping_dap_chain_common_objects.h new file mode 100644 index 0000000000000000000000000000000000000000..d54516bdd6db36f6509d1c156538cea3e920ce18 --- /dev/null +++ b/include/wrapping_dap_chain_common_objects.h @@ -0,0 +1,570 @@ +#ifndef _WRAPPING_DAP_CHAIN_COMMON_OBJECTS_ +#define _WRAPPING_DAP_CHAIN_COMMON_OBJECTS_ + +#include "Python.h" +#include "dap_chain_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* DAP Chain ID*/ +typedef struct PyDapChainId{ + PyObject_HEAD + dap_chain_id_t id; +}PyDapChainIdObject; + +static PyTypeObject DapChainIdObject_DapChainIdObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.ID", /* tp_name */ + sizeof(PyDapChainIdObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain id object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +/*-------------------------------*/ + +/* DAP chain cell id */ + +typedef struct PyDapChainCellId{ + PyObject_HEAD + dap_chain_cell_id_t id; +}PyDapChainCellIdObject; + +static PyTypeObject DapChainCellIdObject_DapChainCellIdObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.CellID", /* tp_name */ + sizeof(PyDapChainCellIdObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain cell id object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +/*-------------------------------*/ + +/* DAP chain Addr */ + +typedef struct PyDapChainNodeAddr{ + PyObject_HEAD + dap_chain_node_addr_t *node_addr; +}PyDapChainNodeAddrObject; + +static PyTypeObject DapChainNodeAddrObject_DapChainNodeAddrObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.NodeAddr", /* tp_name */ + sizeof(PyDapChainNodeAddrObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain node addr object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +/*-------------------------------*/ + +typedef struct PyDapChainNodeRole{ + PyObject_HEAD + dap_chain_node_role_t *node_role; +}PyDapChainNodeRoleObject; + +/* DAP Chain Net ID */ + +typedef struct PyDapChainNetId{ + PyObject_HEAD + dap_chain_net_id_t net_id; +}PyDapChainNetIdObject; + +static PyTypeObject DapChainNetIdObject_DapChainNetIdObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.NetID", /* tp_name */ + sizeof(PyDapChainNetIdObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain net id object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +/* ------------------------------- */ + +/* DAP chain Hash Slow Object */ +typedef struct PyDapChainHashSlow{ + PyObject_HEAD + dap_chain_hash_slow_t *hash_slow; +}PyDapChainHashSlowObject; + +static PyTypeObject DapChainHashSlowObject_DapChainHashSlowObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.HashSlow", /* tp_name */ + sizeof(PyDapChainHashSlowObject),/* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain hash slow object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + + +/* ---------------------------------- */ +/* DAP chain hash fast object */ + +typedef struct PyDapChainHashFast{ + PyObject_HEAD + dap_chain_hash_fast_t *hash_fast; +}PyDapChainHashFastObject; + +static PyTypeObject DapChainHashFastObject_DapChainHashFastObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.HashFast", /* tp_name */ + sizeof(PyDapChainHashFastObject),/* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain hash fast object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +/* ----------------------------------- */ + +typedef struct PyDapChainHashSlowKind{ + PyObject_HEAD + dap_chain_hash_slow_kind_t *hash_slow_kind; +}PyDapChainHashSlowKindObject; + +static PyTypeObject DapChainHashSlowKindObject_DapChainHashSlowKindObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.HashSlowKind", /* tp_name */ + sizeof(PyDapChainHashSlowKindObject),/* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain hash slow kind object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +/* ----------------------------------- */ + +typedef struct PyDapChainPkeyType{ + PyObject_HEAD + dap_chain_pkey_type_t *pkey_type; +}PyDapChainPkeyTypeObject; + +static PyTypeObject DapChainPkeyTypeObject_DapChainPkeyTypeObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.PkeyType", /* tp_name */ + sizeof(PyDapChainPkeyTypeObject),/* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain pkey type object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +/* ----------------------------------- */ + +typedef struct PyDapChainPkey{ + PyObject_HEAD + dap_chain_pkey_t *pkey; +}PyDapChainPkeyObject; + +static PyTypeObject DapChainPkeyObject_DapChainPkeyObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.Pkey", /* tp_name */ + sizeof(PyDapChainPkeyObject),/* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain pkey object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +/* ----------------------------------- */ + +typedef struct PyDapChainSignType{ + PyObject_HEAD + dap_chain_sign_type_t *sign_type; +}PyDapChainSignTypeObject; + +static PyTypeObject DapChainSignTypeObject_DapChainSignTypeObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.SignType", /* tp_name */ + sizeof(PyDapChainSignTypeObject),/* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain sign type object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +/* ----------------------------------- */ + +/* DAP chain addr object */ +typedef struct PyDapChainAddr{ + PyObject_HEAD + dap_chain_addr_t *addr; +}PyDapChainAddrObject; + +static PyTypeObject DapChainAddrObject_DapChainAddrObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.Addr", /* tp_name */ + sizeof(PyDapChainAddrObject),/* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain addr object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +/* ----------------------------- */ + +#ifdef __cplusplus +} +#endif + +#endif //_WRAPPING_DAP_CHAIN_COMMON_OBJECTS_ diff --git a/include/wrapping_dap_chain_cs.h b/include/wrapping_dap_chain_cs.h new file mode 100644 index 0000000000000000000000000000000000000000..2ddf02f33d16a31b6829c21a04fd49c3bb9979bb --- /dev/null +++ b/include/wrapping_dap_chain_cs.h @@ -0,0 +1,85 @@ +#ifndef _WRAPPING_DAP_CHAIN_CS_ +#define _WRAPPING_DAP_CHAIN_CS_ + +#include "Python.h" +#include "dap_chain_cs.h" +#include "libdap-chain-python.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyDapChainCs{ + PyObject_HEAD + dap_chain_cs_t *cs; + dap_chain_callback_new_cfg_t callback_new_cfg; +}PyDapChainCsObject; +static PyObject *binded_object_callback_new_cfg = NULL; + +PyObject *DapChainCSObject_new(PyTypeObject *type_object, PyObject *args, PyObject *kwds); + +int dap_chain_cs_init_py(void); +void dap_chain_cs_deinit_py(void); + +PyObject *dap_chain_cs_add_py (PyObject *self, PyObject *args); +PyObject *dap_chain_cs_create_py(PyObject *self, PyObject *args); + +PyObject *dap_chain_class_add_py (PyObject *self, PyObject *args); +PyObject *dap_chain_class_create_py(PyObject *self, PyObject *args); + +static PyMethodDef DapChainCSMethods[] = { + {"csAdd", (PyCFunction)dap_chain_cs_add_py, METH_VARARGS, ""}, + {"csCreate", (PyCFunction)dap_chain_cs_create_py, METH_VARARGS, ""}, + {"classAdd", (PyCFunction)dap_chain_class_add_py, METH_VARARGS, ""}, + {"classCreate", (PyCFunction)dap_chain_class_create_py, METH_VARARGS, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainCsObject_DapChainCsObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.CS", /* tp_name */ + sizeof(PyDapChainCsObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain cs object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainCSMethods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + DapChainCSObject_new, /* tp_new */ +}; + + +#ifdef __cplusplus +} +#endif + +#endif //_WRAPPING_DAP_CHAIN_CS_ diff --git a/include/wrapping_dap_chain_datum.h b/include/wrapping_dap_chain_datum.h new file mode 100644 index 0000000000000000000000000000000000000000..784bd6979ab84d497fc6451828f61f8db4dbfea8 --- /dev/null +++ b/include/wrapping_dap_chain_datum.h @@ -0,0 +1,163 @@ +#ifndef _WRAPPING_DAP_CHAIN_DATUM_ +#define _WRAPPING_DAP_CHAIN_DATUM_ +#include "Python.h" +#include "dap_chain_datum.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* DAP Chain datum type id */ +typedef struct PyDapChainDatumTypeId{ + PyObject_HEAD + dap_chain_datum_typeid_t *type_id; +}PyDapChainDatumTypeIdObject; + +static PyTypeObject DapChainDatumTypeIdObject_DapChainDatumTypeIdObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.DatumTypeId", /* tp_name */ + sizeof(PyDapChainDatumTypeIdObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain datum type id object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; +/* -------------------------------- */ + +typedef struct PyDapChainDatum{ + PyObject_HEAD + dap_chain_datum_t *datum; +}PyDapChainDatumObject; + +//void PyDapChainDatumObject_dealloc(PyDapChainDatumObject* object); +PyObject *DapChainDatumObject_new(PyTypeObject *type_object, PyObject *args, PyObject *kwds); + +static PyTypeObject DapChainDatumObject_DapChainDatumObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.Datum", /* tp_name */ + sizeof(PyDapChainDatumObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain datum object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + DapChainDatumObject_new, /* tp_new */ +}; +/* -------------------------------- */ + +/* DAP Chain datum iter*/ +typedef struct PyDapChainDatumIter{ + PyObject_HEAD + dap_chain_datum_iter_t *datum_iter; +}PyDapChainDatumIterObject; + +static PyTypeObject DapChainDatumIterObject_DapChainDatumIterObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.DatumIter", /* tp_name */ + sizeof(PyDapChainDatumIterObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain datum iter object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; +/* -------------------------------- */ + +#ifdef __cplusplus +} +#endif + +#endif //_WRAPPING_DAP_CHAIN_DATUM_ diff --git a/include/wrapping_dap_chain_datum_token.h b/include/wrapping_dap_chain_datum_token.h new file mode 100644 index 0000000000000000000000000000000000000000..82f667748f3a7bde9a7eb6c7faa35f97e357f1f0 --- /dev/null +++ b/include/wrapping_dap_chain_datum_token.h @@ -0,0 +1,104 @@ +#include "Python.h" +#include "dap_chain_datum_token.h" + +/* DAP chain datum token */ + +typedef struct PyDapChainDatumToken{ + PyObject_HEAD + dap_chain_datum_token_t *token; +}PyDapChainDatumTokenObject; + +static PyTypeObject DapChainDatumToken_DapChainDatumTokenObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.DatumTokenObject", /* tp_name */ + sizeof(PyDapChainDatumTokenObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain datum token object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +/* ------------------------------------------- */ + +/* DAP chain datum token emission */ + +typedef struct PyDapChainDatumTokenEmission{ + PyObject_HEAD + dap_chain_datum_token_emission_t *token_emission; +}PyDapChainDatumTokenEmissionObject; + +static PyTypeObject DapChainDatumTokenEmission_DapChainDatumTokenEmissionObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.DatumTokenEmission", /* tp_name */ + sizeof(PyDapChainDatumTokenEmissionObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain datum token emission object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +/* ------------------------------------------- */ diff --git a/include/wrapping_dap_chain_datum_tx.h b/include/wrapping_dap_chain_datum_tx.h new file mode 100644 index 0000000000000000000000000000000000000000..1b2564ec1d6ccd6eee9a2668edf92e5b421d9eda --- /dev/null +++ b/include/wrapping_dap_chain_datum_tx.h @@ -0,0 +1,266 @@ +#ifndef _WRAPPING_DAP_CHAIN_DATUM_TX_ +#define _WRAPPING_DAP_CHAIN_DATUM_TX_ + +#include "Python.h" +#include "dap_chain_datum_tx.h" +#include "wrapping_dap_chain_common.h" +#include "libdap_crypto_key_python.h" +#include "dap_chain_datum_tx_out_cond.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* DAP chain tx iter type */ +typedef struct PyDapChainTxItemType{ + PyObject_HEAD +}PyDapChainTxItemTypeObject; + +PyObject *TX_ITEM_TYPE_IN_PY(void); +PyObject *TX_ITEM_TYPE_OUT_PY(void); +PyObject *TX_ITEM_TYPE_PKEY_PY(void); +PyObject *TX_ITEM_TYPE_SIG_PY(void); +PyObject *TX_ITEM_TYPE_TOKEN_PY(void); +PyObject *TX_ITEM_TYPE_IN_COND_PY(void); +PyObject *TX_ITEM_TYPE_OUT_COND_PY(void); +PyObject *TX_ITEM_TYPE_OUT_SERVICE_RECEIPT_PY(void); + +static PyMethodDef PyDapChainTxItemTypeObjectMethods[] ={ + {"TX_ITEM_TYPE_IN", (PyCFunction)TX_ITEM_TYPE_IN_PY, METH_NOARGS | METH_STATIC, ""}, + {"TX_ITEM_TYPE_OUT", (PyCFunction)TX_ITEM_TYPE_OUT_PY, METH_NOARGS | METH_STATIC, ""}, + {"TX_ITEM_TYPE_PKEY", (PyCFunction)TX_ITEM_TYPE_PKEY_PY, METH_NOARGS | METH_STATIC, ""}, + {"TX_ITEM_TYPE_SIG", (PyCFunction)TX_ITEM_TYPE_SIG_PY, METH_NOARGS | METH_STATIC, ""}, + {"TX_ITEM_TYPE_TOKEN", (PyCFunction)TX_ITEM_TYPE_TOKEN_PY, METH_NOARGS | METH_STATIC, ""}, + {"TX_ITEM_TYPE_IN_COND", (PyCFunction)TX_ITEM_TYPE_IN_COND_PY, METH_NOARGS | METH_STATIC, ""}, + {"TX_ITEM_TYPE_OUT_COND", (PyCFunction)TX_ITEM_TYPE_OUT_COND_PY, METH_NOARGS | METH_STATIC, ""}, + {"TX_ITEM_TYPE_OUT_SERVICE_RECEIPT", (PyCFunction)TX_ITEM_TYPE_OUT_SERVICE_RECEIPT_PY, + METH_NOARGS | METH_STATIC, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainTxItemObject_DapChainTxItemTypeObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.TxItemType", /* tp_name */ + sizeof(PyDapChainTxItemTypeObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain tx item type object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyDapChainTxItemTypeObjectMethods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +/* -------------------------------------- */ + +/* DAP chain tx cond*/ +typedef struct PyDapChainTxCondType{ + PyObject_HEAD + dap_chain_tx_cond_type_t *tx_cond_type_t; +}PyDapChainTxCondTypeObject; + +static PyTypeObject DapChainTxType_DapChainTxCondTypeObject = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.TxCondType", /* tp_name */ + sizeof(PyDapChainTxCondTypeObject),/* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain tx cond type object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +/* -------------------------------------- */ + +/* DAP chain datum tx */ +typedef struct PyDapChainDatumTx{ + PyObject_HEAD + dap_chain_datum_tx_t *datum_tx; +}PyDapChainDatumTxObject; + +PyObject *PyDapChainDatumTxObject_create(PyTypeObject *type_object, PyObject *args, PyObject *kwds); +void PyDapChainDatumTxObject_delete(PyDapChainDatumTxObject* datumTx); +PyObject *dap_chain_datum_tx_get_size_py(PyObject *self, PyObject *args); +PyObject *dap_chain_datum_tx_add_item_py(PyObject *self, PyObject *args); +PyObject *dap_chain_datum_tx_add_in_item_py(PyObject *self, PyObject *args); +PyObject *dap_chain_datum_tx_add_out_item_py(PyObject *self, PyObject *args); +PyObject *dap_chain_datum_tx_add_out_cond_item_py(PyObject *self, PyObject *args); +PyObject *dap_chain_datum_tx_add_sign_item_py(PyObject *self, PyObject *args); +PyObject *dap_chain_datum_tx_verify_sign_py(PyObject *self, PyObject *args); + +static dap_chain_datum_tx_t **PyListToDapChainDatumTxArray(PyObject *a_in_obj); +static PyObject* DapChainDatumTxArrayToPyList(dap_chain_datum_tx_t** datum_txs); + + +static PyMethodDef PyDapChainDatumTxObjectMethods[] ={ + {"getSize", (PyCFunction)dap_chain_datum_tx_get_size_py, METH_VARARGS, ""}, + {"addItem", (PyCFunction)dap_chain_datum_tx_add_item_py, METH_VARARGS | METH_STATIC, ""}, + {"addInItem", (PyCFunction)dap_chain_datum_tx_add_in_item_py, METH_VARARGS | METH_STATIC, ""}, + {"addOutItem", (PyCFunction)dap_chain_datum_tx_add_out_item_py, METH_VARARGS | METH_STATIC, ""}, + {"addOutCond", (PyCFunction)dap_chain_datum_tx_add_out_cond_item_py, METH_VARARGS | METH_STATIC, ""}, + {"addSignItem", (PyCFunction)dap_chain_datum_tx_add_sign_item_py, METH_VARARGS | METH_STATIC, ""}, + {"verifySign", (PyCFunction)dap_chain_datum_tx_verify_sign_py, METH_VARARGS, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainDatumTx_DapChainDatumTxObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.DatumTx", /* tp_name */ + sizeof(PyDapChainDatumTxObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PyDapChainDatumTxObject_delete, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain datum tx object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyDapChainDatumTxObjectMethods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyDapChainDatumTxObject_create, /* tp_new */ +}; + +/* -------------------------------------- */ + +typedef struct PyDapChainTxOutCond{ + PyObject_HEAD + dap_chain_tx_out_cond_t *out_cond; +}PyDapChainTxOutCondObject; + +static PyTypeObject DapChainTxOutCond_DapChainTxOutCondObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.TxOutCond", /* tp_name */ + sizeof(PyDapChainTxOutCondObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain tx out cond object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ +}; + +dap_chain_tx_out_cond_t **PyListToDapChainTxOutCond(PyObject *list); +PyObject *DapChainTxOutCondObjectToPyList(dap_chain_tx_out_cond_t **out_cond); + +/* -------------------------------------- */ + +#ifdef __cplusplus +} +#endif + +#endif //_WRAPPING_DAP_CHAIN_DATUM_TX_ diff --git a/include/wrapping_dap_chain_ledger.h b/include/wrapping_dap_chain_ledger.h new file mode 100644 index 0000000000000000000000000000000000000000..f020aea901cb99d486f41f8bf076f36bb96fc354 --- /dev/null +++ b/include/wrapping_dap_chain_ledger.h @@ -0,0 +1,124 @@ +#include "Python.h" +#include "dap_chain_ledger.h" +#include "wrapping_dap_chain_common_objects.h" +#include "wrapping_dap_chain_datum_tx.h" +#include "wrapping_dap_chain_datum_token.h" +#include "libdap-python.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PyDapChainLedger{ + PyObject_HEAD + dap_ledger_t *ledger; +}PyDapChainLedgerObject; + +//construct +PyObject *DapChainLedgerObject_create(PyTypeObject *type_object, PyObject *args, PyObject *kwds); +//destructor +void DapChainLedgerObject_free(PyDapChainLedgerObject* object); + +PyObject *dap_chain_ledger_set_local_cell_id_py(PyObject *self, PyObject *args); +PyObject *dap_chain_node_datum_tx_calc_hash_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_add_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_token_add_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_token_emission_add_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_token_emission_find_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_get_token_ticker_by_hash_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_addr_get_token_ticker_all_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_addr_get_token_ticker_all_fast_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_cache_check_py(PyObject *self, PyObject *args); +PyObject *dap_chain_node_datum_tx_cache_check_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_remove_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_purge_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_count_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_count_from_to_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_hash_is_used_out_item_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_calc_balance_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_calc_balance_full_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_find_by_hash_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_find_by_addr_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_find_by_pkey_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_cache_find_out_cond_py(PyObject *self, PyObject *args); +PyObject *dap_chain_ledger_tx_cache_get_out_cond_value_py(PyObject *self, PyObject *args); + +static PyMethodDef DapChainLedgerMethods[] = { + {"setLocalCellId", (PyCFunction)dap_chain_ledger_set_local_cell_id_py, METH_VARARGS, ""}, + {"nodeDatumTxCalcHash", (PyCFunction)dap_chain_node_datum_tx_calc_hash_py, METH_VARARGS, ""}, + {"txAdd", (PyCFunction)dap_chain_ledger_tx_add_py, METH_VARARGS, ""}, + {"tokenAdd", (PyCFunction)dap_chain_ledger_token_add_py, METH_VARARGS, ""}, + {"tokenEmissionAdd", (PyCFunction)dap_chain_ledger_token_emission_add_py, METH_VARARGS, ""}, + {"tokenEmissionFind", (PyCFunction)dap_chain_ledger_token_emission_find_py, METH_VARARGS, ""}, + {"txGetTokenTickerByHash", (PyCFunction)dap_chain_ledger_tx_get_token_ticker_by_hash_py, METH_VARARGS, ""}, + {"addrGetTokenTickerAll", (PyCFunction)dap_chain_ledger_addr_get_token_ticker_all_py, METH_VARARGS, ""}, + {"addrGetTokenTickerAllFast", (PyCFunction)dap_chain_ledger_addr_get_token_ticker_all_fast_py, METH_VARARGS, ""}, + {"txCacheCheck", (PyCFunction)dap_chain_ledger_tx_cache_check_py, METH_VARARGS, ""}, + {"datumTxCacheCheck", (PyCFunction)dap_chain_node_datum_tx_cache_check_py, METH_VARARGS, ""}, + {"txRemove", (PyCFunction)dap_chain_ledger_tx_remove_py, METH_VARARGS, ""}, + {"purge", (PyCFunction)dap_chain_ledger_purge_py, METH_VARARGS, ""}, + {"count", (PyCFunction)dap_chain_ledger_count_py, METH_VARARGS, ""}, + {"countFromTo", (PyCFunction)dap_chain_ledger_count_from_to_py, METH_VARARGS, ""}, + {"txHashIsUsedOutItem", (PyCFunction)dap_chain_ledger_tx_hash_is_used_out_item_py, METH_VARARGS, ""}, + {"calcBalance", (PyCFunction)dap_chain_ledger_calc_balance_py, METH_VARARGS, ""}, + {"calcBalanceFull", (PyCFunction)dap_chain_ledger_calc_balance_full_py, METH_VARARGS, ""}, + {"txFindByHash", (PyCFunction)dap_chain_ledger_tx_find_by_hash_py, METH_VARARGS, ""}, + {"txFindByAddr", (PyCFunction)dap_chain_ledger_tx_find_by_addr_py, METH_VARARGS, ""}, + {"txFindByPkey", (PyCFunction)dap_chain_ledger_tx_find_by_pkey_py, METH_VARARGS, ""}, + {"txCacheFindOutCond", (PyCFunction)dap_chain_ledger_tx_cache_find_out_cond_py, METH_VARARGS, ""}, + {"txCacheGetOutCondValue", (PyCFunction)dap_chain_ledger_tx_cache_get_out_cond_value_py, METH_VARARGS, ""}, + + {NULL, NULL, 0, NULL} +}; + +PyTypeObject DapChainLedger_DapChainLedgerType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.Chain.Ledger", /* tp_name */ + sizeof(PyDapChainLedgerObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Chain ledger objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainLedgerMethods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ + +}; + +static char*** ListStringToArrayStringFormatChar(PyObject *list); +static size_t *ListIntToSizeT(PyObject *list); + + +#ifdef __cplusplus +} +#endif diff --git a/libdap b/libdap new file mode 160000 index 0000000000000000000000000000000000000000..4e8e7c7de1c2b87ca4599e63f2719504a3b41206 --- /dev/null +++ b/libdap @@ -0,0 +1 @@ +Subproject commit 4e8e7c7de1c2b87ca4599e63f2719504a3b41206 diff --git a/libdap-chain b/libdap-chain new file mode 160000 index 0000000000000000000000000000000000000000..5952caa80d23284c73074a267c96a8927e68adeb --- /dev/null +++ b/libdap-chain @@ -0,0 +1 @@ +Subproject commit 5952caa80d23284c73074a267c96a8927e68adeb diff --git a/libdap-chain-crypto b/libdap-chain-crypto new file mode 160000 index 0000000000000000000000000000000000000000..3f9ca3093acde91b6cd92c7c3b95d8c1d9dea66d --- /dev/null +++ b/libdap-chain-crypto @@ -0,0 +1 @@ +Subproject commit 3f9ca3093acde91b6cd92c7c3b95d8c1d9dea66d diff --git a/libdap-chain-gdb b/libdap-chain-gdb new file mode 160000 index 0000000000000000000000000000000000000000..6ef661685f2792242433bf340f253d255f39e881 --- /dev/null +++ b/libdap-chain-gdb @@ -0,0 +1 @@ +Subproject commit 6ef661685f2792242433bf340f253d255f39e881 diff --git a/libdap-chain-global-db b/libdap-chain-global-db new file mode 160000 index 0000000000000000000000000000000000000000..c877f6176af12172c125a40b5fde75fe8aa2dfc2 --- /dev/null +++ b/libdap-chain-global-db @@ -0,0 +1 @@ +Subproject commit c877f6176af12172c125a40b5fde75fe8aa2dfc2 diff --git a/libdap-chain-mempool b/libdap-chain-mempool new file mode 160000 index 0000000000000000000000000000000000000000..baf3fd7bdaead5d008a2e3595486792ea5083b20 --- /dev/null +++ b/libdap-chain-mempool @@ -0,0 +1 @@ +Subproject commit baf3fd7bdaead5d008a2e3595486792ea5083b20 diff --git a/libdap-chain-net b/libdap-chain-net new file mode 160000 index 0000000000000000000000000000000000000000..f1654804d37d534215f5d16a7d09c8f02966143c --- /dev/null +++ b/libdap-chain-net @@ -0,0 +1 @@ +Subproject commit f1654804d37d534215f5d16a7d09c8f02966143c diff --git a/libdap-chain-net-srv b/libdap-chain-net-srv new file mode 160000 index 0000000000000000000000000000000000000000..be35813a341b88738d909329974407cab87c0143 --- /dev/null +++ b/libdap-chain-net-srv @@ -0,0 +1 @@ +Subproject commit be35813a341b88738d909329974407cab87c0143 diff --git a/libdap-chain-wallet b/libdap-chain-wallet new file mode 160000 index 0000000000000000000000000000000000000000..7cbed9ab134af5fb033a017cd17c4ead14356694 --- /dev/null +++ b/libdap-chain-wallet @@ -0,0 +1 @@ +Subproject commit 7cbed9ab134af5fb033a017cd17c4ead14356694 diff --git a/libdap-client b/libdap-client new file mode 160000 index 0000000000000000000000000000000000000000..9f47ebe9e7b1f326800a5ddde661a3e30a4381c2 --- /dev/null +++ b/libdap-client @@ -0,0 +1 @@ +Subproject commit 9f47ebe9e7b1f326800a5ddde661a3e30a4381c2 diff --git a/libdap-crypto b/libdap-crypto new file mode 160000 index 0000000000000000000000000000000000000000..bb48d2efb77ee770c6f36c296811688f2ad9c348 --- /dev/null +++ b/libdap-crypto @@ -0,0 +1 @@ +Subproject commit bb48d2efb77ee770c6f36c296811688f2ad9c348 diff --git a/libdap-crypto-python b/libdap-crypto-python new file mode 160000 index 0000000000000000000000000000000000000000..e0fef50bbe630c2835020fbebf3bcdfe064255a8 --- /dev/null +++ b/libdap-crypto-python @@ -0,0 +1 @@ +Subproject commit e0fef50bbe630c2835020fbebf3bcdfe064255a8 diff --git a/libdap-python b/libdap-python new file mode 160000 index 0000000000000000000000000000000000000000..4a15aca686aa56313f8ef8157c7d0aba7c9d7154 --- /dev/null +++ b/libdap-python @@ -0,0 +1 @@ +Subproject commit 4a15aca686aa56313f8ef8157c7d0aba7c9d7154 diff --git a/libdap-server b/libdap-server new file mode 160000 index 0000000000000000000000000000000000000000..fdcfd4fe6727f4d4151affef761007c95d5a36eb --- /dev/null +++ b/libdap-server @@ -0,0 +1 @@ +Subproject commit fdcfd4fe6727f4d4151affef761007c95d5a36eb diff --git a/libdap-server-core b/libdap-server-core new file mode 160000 index 0000000000000000000000000000000000000000..73dfe6c2616ef8a805231560051de3c407d7cd89 --- /dev/null +++ b/libdap-server-core @@ -0,0 +1 @@ +Subproject commit 73dfe6c2616ef8a805231560051de3c407d7cd89 diff --git a/libdap-server-http-db-auth b/libdap-server-http-db-auth new file mode 160000 index 0000000000000000000000000000000000000000..bdab475c9dfe0ad876cd642a798e1b0b54ca314e --- /dev/null +++ b/libdap-server-http-db-auth @@ -0,0 +1 @@ +Subproject commit bdab475c9dfe0ad876cd642a798e1b0b54ca314e diff --git a/libdap-server-udp b/libdap-server-udp new file mode 160000 index 0000000000000000000000000000000000000000..2aaaad5981206379c1a7e7c8af3dc3d6aa26e2e7 --- /dev/null +++ b/libdap-server-udp @@ -0,0 +1 @@ +Subproject commit 2aaaad5981206379c1a7e7c8af3dc3d6aa26e2e7 diff --git a/libdap-stream b/libdap-stream new file mode 160000 index 0000000000000000000000000000000000000000..a7ee4c8a206e6e5bb1290ba83b00abe0052f2183 --- /dev/null +++ b/libdap-stream @@ -0,0 +1 @@ +Subproject commit a7ee4c8a206e6e5bb1290ba83b00abe0052f2183 diff --git a/libdap-stream-ch b/libdap-stream-ch new file mode 160000 index 0000000000000000000000000000000000000000..f2eabb784a6286356359e69cb50a2957a57aa0b0 --- /dev/null +++ b/libdap-stream-ch @@ -0,0 +1 @@ +Subproject commit f2eabb784a6286356359e69cb50a2957a57aa0b0 diff --git a/libdap-stream-ch-chain b/libdap-stream-ch-chain new file mode 160000 index 0000000000000000000000000000000000000000..5f869621cac54e87615ed031aed81b48d38df9b0 --- /dev/null +++ b/libdap-stream-ch-chain @@ -0,0 +1 @@ +Subproject commit 5f869621cac54e87615ed031aed81b48d38df9b0 diff --git a/libdap-stream-ch-chain-net b/libdap-stream-ch-chain-net new file mode 160000 index 0000000000000000000000000000000000000000..b43008b98e4a7220059457732e81aa6a80021739 --- /dev/null +++ b/libdap-stream-ch-chain-net @@ -0,0 +1 @@ +Subproject commit b43008b98e4a7220059457732e81aa6a80021739 diff --git a/src/libdap-chain-python.c b/src/libdap-chain-python.c new file mode 100644 index 0000000000000000000000000000000000000000..6d04a59f6fd6f20192c01651a43cd37338229d18 --- /dev/null +++ b/src/libdap-chain-python.c @@ -0,0 +1,76 @@ +#include "libdap-chain-python.h" + + +int init_chain_py(){ + return dap_chain_init(); +} + +void deinit_chain_py(){ + dap_chain_deinit(); +} + +PyObject *dap_chain_find_by_id_py(PyObject *self, PyObject *args){ + PyObject *obj_net_id; + PyObject *obj_chain_id; + if (!PyArg_ParseTuple(args, "O|O", &obj_net_id, &obj_chain_id)) + return NULL; + PyObject *new_obj = _PyObject_New(&dapChainObject_dapChainType); + ((PyDapChainObject*)new_obj)->chain_t = dap_chain_find_by_id(((PyDapChainNetIdObject*)obj_net_id)->net_id, ((PyDapChainIdObject*)obj_chain_id)->id); + return Py_BuildValue("O", &new_obj); +} + +//PyObject *dap_chain_load_from_cfg_py(PyObject *self, PyObject *args){ +//return NULL; +//} + +PyObject *dap_chain_has_file_store_py(PyObject *self, PyObject *args){ + bool res = dap_chain_has_file_store(((PyDapChainObject*)self)->chain_t); + if (res) + return Py_BuildValue("O", Py_True); + else + return Py_BuildValue("O", Py_False); +} + +PyObject *dap_chain_save_all_py(PyObject *self, PyObject *args){ + return PyLong_FromLong( dap_chain_save_all(((PyDapChainObject*)self)->chain_t) ); +} + +PyObject *dap_chain_load_all_py(PyObject *self, PyObject *args){ + return PyLong_FromLong(dap_chain_load_all(((PyDapChainObject*)self)->chain_t)); +} + +PyObject *dap_chain_load_from_cfg_py(PyObject *self, PyObject *args){ + PyObject *obj_ledger; + const char *chain_net_name; + PyObject *obj_net_id; + const char *cfg_name; + if (!PyArg_ParseTuple(args, "O|s|O|s", &obj_ledger, &chain_net_name, &obj_net_id, &cfg_name)) + return NULL; + PyObject *res_obj = _PyObject_New(&dapChainObject_dapChainType); + ((PyDapChainObject*)res_obj)->chain_t = dap_chain_load_from_cfg(((PyDapChainLedgerObject*)obj_ledger)->ledger, chain_net_name, ((PyDapChainNetIdObject*)obj_net_id)->net_id, cfg_name); + return Py_BuildValue("O", &res_obj); +} + +//PyObject *dap_chain_init_net_cfg_name_py(PyObject *self, PyObject *args){ +//return NULL; +//} + +//PyObject *dap_chain_close_py(PyObject *self, PyObject *args){ +// dap_chain_close(((PyDapChainObject*)self)->chain_t); +// return PyLong_FromLong(0); +//} + +//PyObject *dap_chain_info_dump_log_py(PyObject *self, PyObject *args){ +//return NULL; +//} + + +PyObject *PyDapChainObject_new(PyTypeObject *type_object, PyObject *args, PyObject *kwds){ + PyDapChainObject *obj = (PyDapChainObject*)PyType_GenericNew(type_object, args, kwds); + return (PyObject *)obj; +} + +void PyDapChainObject_dealloc(PyDapChainObject* chain){ + dap_chain_delete(chain->chain_t); + Py_TYPE(chain)->tp_free((PyObject*)chain); +} diff --git a/src/libdap_chain_type_python.c b/src/libdap_chain_type_python.c new file mode 100644 index 0000000000000000000000000000000000000000..7ba65602d0f11cee60556e805b723e319cfe758d --- /dev/null +++ b/src/libdap_chain_type_python.c @@ -0,0 +1,17 @@ +#include "libdap_chain_type_python.h" + +PyObject* CHAIN_TYPE_FIRST_PY(){ + return PyLong_FromLong(CHAIN_TYPE_FIRST); +} +PyObject* CHAIN_TYPE_TOKEN_PY(){ + return PyLong_FromLong(CHAIN_TYPE_TOKEN); +} +PyObject* CHAIN_TYPE_EMISSION_PY(){ + return PyLong_FromLong(CHAIN_TYPE_EMISSION); +} +PyObject* CHAIN_TYPE_TX_PY(){ + return PyLong_FromLong(CHAIN_TYPE_TX); +} +PyObject* CHAIN_TYPE_LAST_PY(){ + return PyLong_FromLong(CHAIN_TYPE_LAST); +} diff --git a/src/wrapping_dap_chain_cell.c b/src/wrapping_dap_chain_cell.c new file mode 100644 index 0000000000000000000000000000000000000000..6d1369b415a738df0ca915262c0c771e88545db7 --- /dev/null +++ b/src/wrapping_dap_chain_cell.c @@ -0,0 +1,33 @@ +#include "wrapping_dap_chain_cell.h" + +void DapChainCellObject_delete(PyDapChainCellObject* object){ + dap_chain_cell_delete(object->cell); + Py_TYPE(object)->tp_free((PyObject*)object); +} +PyObject *DapChainCellObject_create(PyTypeObject *type_object, PyObject *args, PyObject *kwds){ + PyDapChainCellObject *obj = (PyDapChainCellObject*)PyType_GenericNew(type_object, args, kwds); + obj->cell = dap_chain_cell_create(); + return (PyObject *)obj; +} + +PyObject *dap_chain_cell_load_py(PyObject *self, PyObject *args){ + PyObject *obj_chain; + const char *cell_file_path; + if (!PyArg_ParseTuple(args, "O|s", &obj_chain, &cell_file_path)) + return NULL; + int res = dap_chain_cell_load(((PyDapChainObject*)obj_chain)->chain_t, cell_file_path); + return PyLong_FromLong(res); +} +PyObject *dap_chain_cell_file_update_py(PyObject *self, PyObject *args){ + int res = dap_chain_cell_file_update(((PyDapChainCellObject*)self)->cell); + return PyLong_FromLong(res); +} +PyObject *dap_chain_cell_file_append_py(PyObject *self, PyObject *args){ + PyObject *atom_bytes; + size_t atom_size; + if (!PyArg_ParseTuple(args, "S|n", &atom_bytes, &atom_size)) + return NULL; + void *atom = PyBytes_AsString(atom_bytes); + int res = dap_chain_cell_file_append(((PyDapChainCellObject*)self)->cell, atom, atom_size); + return PyLong_FromLong(res); +} diff --git a/src/wrapping_dap_chain_common.c b/src/wrapping_dap_chain_common.c new file mode 100644 index 0000000000000000000000000000000000000000..dfbfa9c862575554f9e1a8e1dde31d44e3119fab --- /dev/null +++ b/src/wrapping_dap_chain_common.c @@ -0,0 +1,56 @@ +#include "wrapping_dap_chain_common.h" + +PyObject *dap_chain_hash_slow_to_str_py(PyObject *self, PyObject *args){ + PyObject *hashSlow; + char *str; + size_t strMax; + if (!PyArg_ParseTuple(args, "O|s|n", &hashSlow, &str, &strMax)) + return NULL; + size_t result = dap_chain_hash_slow_to_str(((PyDapChainHashSlowObject*)hashSlow)->hash_slow, str, strMax); + return PyLong_FromSize_t(result); +} + +PyObject *dap_chain_str_to_hash_fast_py(PyObject *self, PyObject *args){ + const char *hashStr; + PyObject *hashFast; + if (!PyArg_ParseTuple(args, "s|O", &hashStr, &hashFast)) + return NULL; + int result = dap_chain_str_to_hash_fast(hashStr, ((PyDapChainHashFastObject*)hashFast)->hash_fast); + return PyLong_FromLong(result); +} + +PyObject *dap_chain_addr_to_str_py(PyObject *self, PyObject *args){ + PyObject *addr; + if (!PyArg_ParseTuple(args, "O", &addr)) + return NULL; + char *result = dap_chain_addr_to_str(((PyDapChainAddrObject*)addr)->addr); + return Py_BuildValue("s", result); +} + +PyObject *dap_chain_addr_from_str_py(PyObject *self, PyObject *args){ + const char *str; + if (!PyArg_ParseTuple(args, "s", &str)) + return NULL; + PyObject *addrObject = _PyObject_New(&DapChainAddrObject_DapChainAddrObjectType); + ((PyDapChainAddrObject*)addrObject)->addr = dap_chain_addr_from_str(str); + return Py_BuildValue("O", addrObject); +} + +PyObject *dap_chain_addr_fill_py(PyObject *self, PyObject *args){ + PyObject *addr; + PyObject *key; + PyObject *net_id; + if (!PyArg_ParseTuple(args, "O|O|O", &addr, &key, &net_id)) + return NULL; + dap_chain_addr_fill(((PyDapChainAddrObject*)addr)->addr, ((PyCryptoKeyObject*)key)->key, + &(((PyDapChainNetIdObject*)net_id)->net_id)); + return PyLong_FromLong(0); +} + +PyObject *dap_chain_addr_check_sum_py(PyObject *self, PyObject *args){ + PyObject *addrObject; + if (!PyArg_ParseTuple(args, "O", &addrObject)) + return NULL; + int result = dap_chain_addr_check_sum(((PyDapChainAddrObject*)addrObject)->addr); + return PyLong_FromLong(result); +} diff --git a/src/wrapping_dap_chain_cs.c b/src/wrapping_dap_chain_cs.c new file mode 100644 index 0000000000000000000000000000000000000000..12aa1316240ce72d85ffea9cd25a457d9aaefdbf --- /dev/null +++ b/src/wrapping_dap_chain_cs.c @@ -0,0 +1,85 @@ +#include "wrapping_dap_chain_cs.h" + +/* Callback created */ +static int wrapping_dap_chain_callback_new_cfg(dap_chain_t* chain, dap_config_t* cfg) +{ + PyObject *arglist; + PyObject *result; + PyObject *obj_chain= _PyObject_New(&dapChainObject_dapChainType); + ((PyDapChainObject*)obj_chain)->chain_t = chain; + arglist = Py_BuildValue("O", obj_chain); + result = PyObject_CallObject(binded_object_callback_new_cfg, arglist); + Py_DECREF(arglist); + int r = -1; + if (PyLong_Check(result)){ + r = (int)PyLong_AsLong(result); + } + Py_DECREF(result); + return r; +} +/*--------------------------------*/ +int dap_chain_cs_init_py(void){ + return dap_chain_cs_init(); +} +void dap_chain_cs_deinit_py(void){ + dap_chain_cs_deinit(); +} + +PyObject *DapChainCSObject_new(PyTypeObject *type_object, PyObject *args, PyObject *kwds) +{ + PyDapChainCsObject *obj = (PyDapChainCsObject*)PyType_GenericNew(type_object, args, kwds); + obj->callback_new_cfg = wrapping_dap_chain_callback_new_cfg; + return (PyObject *)obj; +} + +PyObject *dap_chain_cs_add_py (PyObject *self, PyObject *args){ + const char* cs_str; + PyObject *obj_callback_init; + if (!PyArg_ParseTuple(args, "s|O:set_callback", &cs_str, &obj_callback_init)){ + return NULL; + } else { + if (!PyCallable_Check(obj_callback_init)) + { + PyErr_SetString(PyExc_TypeError, "paramentr must be callable"); + return NULL; + } + } + Py_XINCREF(obj_callback_init); + Py_XDECREF(binded_object_callback_new_cfg); + binded_object_callback_new_cfg = obj_callback_init; + dap_chain_cs_add(cs_str, ((PyDapChainCsObject*)self)->callback_new_cfg); + return PyLong_FromLong(0); +} +PyObject *dap_chain_cs_create_py(PyObject *self, PyObject *args){ + PyObject *obj_chain; + if (!PyArg_ParseTuple(args, "O", &obj_chain)) + return NULL; + int res = dap_chain_cs_create(((PyDapChainObject*)obj_chain)->chain_t, g_config); + return PyLong_FromLong(res); +} + +PyObject *dap_chain_class_add_py (PyObject *self, PyObject *args){ + const char* cs_str; + PyObject *obj_callback_init; + if (!PyArg_ParseTuple(args, "s|O:set_callback", &cs_str, &obj_callback_init)){ + return NULL; + } else { + if (!PyCallable_Check(obj_callback_init)) + { + PyErr_SetString(PyExc_TypeError, "paramentr must be callable"); + return NULL; + } + } + Py_XINCREF(obj_callback_init); + Py_XDECREF(binded_object_callback_new_cfg); + binded_object_callback_new_cfg = obj_callback_init; + dap_chain_class_add(cs_str, ((PyDapChainCsObject*)self)->callback_new_cfg); + return PyLong_FromLong(0); +} +PyObject *dap_chain_class_create_py(PyObject *self, PyObject *args){ + PyObject *obj_chain; + if (!PyArg_ParseTuple(args, "O", &obj_chain)) + return NULL; + int res = dap_chain_class_create(((PyDapChainObject*)obj_chain)->chain_t, g_config); + return PyLong_FromLong(res); +} diff --git a/src/wrapping_dap_chain_datum.c b/src/wrapping_dap_chain_datum.c new file mode 100644 index 0000000000000000000000000000000000000000..05fcacf1e1eaf17cfe99dc7db002eb8d8ae74e46 --- /dev/null +++ b/src/wrapping_dap_chain_datum.c @@ -0,0 +1,16 @@ +#include "wrapping_dap_chain_datum.h" + +//void PyDapChainDatumObject_dealloc(PyDapChainDatumObject* object){ +//} + +PyObject *PyDapChainDatumObject_new(PyTypeObject *type_object, PyObject *args, PyObject *kwds){ + uint16_t type_id; + PyBytesObject *bytes; + size_t data_size; + if (!PyArg_ParseTuple(args, "H|S|n", &type_id, &bytes, &data_size)) + return NULL; + PyDapChainDatumObject *obj = (PyDapChainDatumObject*)PyType_GenericNew(type_object, args, kwds); + void* bytes_v = (void *)PyBytes_AsString((PyObject*)bytes); + obj->datum = dap_chain_datum_create(type_id, bytes_v, data_size); + return (PyObject *)obj; +} diff --git a/src/wrapping_dap_chain_datum_tx.c b/src/wrapping_dap_chain_datum_tx.c new file mode 100644 index 0000000000000000000000000000000000000000..49bc2c7df64e9574d4f0770e940797b0bd473501 --- /dev/null +++ b/src/wrapping_dap_chain_datum_tx.c @@ -0,0 +1,172 @@ +#include "wrapping_dap_chain_datum_tx.h" + +/* DAP chain tx iter type */ + +PyObject *TX_ITEM_TYPE_IN_PY(void){ + return PyLong_FromLong(TX_ITEM_TYPE_IN); +} +PyObject *TX_ITEM_TYPE_OUT_PY(void){ + return PyLong_FromLong(TX_ITEM_TYPE_OUT); +} +PyObject *TX_ITEM_TYPE_PKEY_PY(void){ + return PyLong_FromLong(TX_ITEM_TYPE_PKEY); +} +PyObject *TX_ITEM_TYPE_SIG_PY(void){ + return PyLong_FromLong(TX_ITEM_TYPE_SIG); +} +PyObject *TX_ITEM_TYPE_TOKEN_PY(void){ + return PyLong_FromLong(TX_ITEM_TYPE_TOKEN); +} +PyObject *TX_ITEM_TYPE_IN_COND_PY(void){ + return PyLong_FromLong(TX_ITEM_TYPE_IN_COND); +} +PyObject *TX_ITEM_TYPE_OUT_COND_PY(void){ + return PyLong_FromLong(TX_ITEM_TYPE_OUT_COND); +} +PyObject *TX_ITEM_TYPE_OUT_SERVICE_RECEIPT_PY(void){ + return PyLong_FromLong(TX_ITEM_TYPE_OUT_SERVICE_RECEIPT); +} + +/* -------------------------------------- */ + +/* DAP chain datum tx */ +PyObject *PyDapChainDatumTxObject_create(PyTypeObject *type_object, PyObject *args, PyObject *kwds){ + PyDapChainDatumTxObject *obj = (PyDapChainDatumTxObject*)PyType_GenericNew(type_object, args, kwds); + obj->datum_tx = dap_chain_datum_tx_create(); + return (PyObject *)obj; +} +void PyDapChainDatumTxObject_delete(PyDapChainDatumTxObject* datumTx){ + dap_chain_datum_tx_delete(datumTx->datum_tx); + Py_TYPE(datumTx)->tp_free((PyObject*)datumTx); +} + +PyObject *dap_chain_datum_tx_get_size_py(PyObject *self, PyObject *args){ + size_t size = dap_chain_datum_tx_get_size(((PyDapChainDatumTxObject*)self)->datum_tx); + return PyLong_FromSize_t(size); +} +PyObject *dap_chain_datum_tx_add_item_py(PyObject *self, PyObject *args){ + PyObject *in_obj; + u_int8_t *a_item; + if (!PyArg_ParseTuple(args, "O|b", &in_obj, &a_item)) + return NULL; + dap_chain_datum_tx_t **txs = PyListToDapChainDatumTxArray(in_obj); + int res = dap_chain_datum_tx_add_item(txs, a_item); + if (res == -1){ + return NULL; + } else { + PyObject *out = DapChainDatumTxArrayToPyList(txs); + return Py_BuildValue("O", out); + } +} +PyObject *dap_chain_datum_tx_add_in_item_py(PyObject *self, PyObject *args){ + PyObject *in_obj_datum_txs; + PyObject *in_obj_hash_fast; + uint32_t in_tx_out_pref_idx; + if (!PyArg_ParseTuple(args, "O|O|I", &in_obj_datum_txs, &in_obj_hash_fast, &in_tx_out_pref_idx)) + return NULL; + dap_chain_datum_tx_t **a_txs = PyListToDapChainDatumTxArray(in_obj_datum_txs); + int res = dap_chain_datum_tx_add_in_item(a_txs, ((PyDapChainHashFastObject*)in_obj_hash_fast)->hash_fast, + in_tx_out_pref_idx); + if (res == -1){ + return NULL; + } else { + PyObject *out = DapChainDatumTxArrayToPyList(a_txs); + return Py_BuildValue("O", out); + } +} +PyObject *dap_chain_datum_tx_add_out_item_py(PyObject *self, PyObject *args){ + PyObject *in_obj_datum_txs; + PyObject *in_addr; + uint64_t value; + if (!PyArg_ParseTuple(args, "O|O|k", &in_obj_datum_txs, &in_addr, value)) + return NULL; + dap_chain_datum_tx_t **txs = PyListToDapChainDatumTxArray(in_obj_datum_txs); + int res = dap_chain_datum_tx_add_out_item(txs, ((PyDapChainAddrObject*)in_addr)->addr, value); + if (res == -1){ + return NULL; + } else { + PyObject *out = DapChainDatumTxArrayToPyList(txs); + return Py_BuildValue("O", out); + } +} +PyObject *dap_chain_datum_tx_add_out_cond_item_py(PyObject *self, PyObject *args){ + PyObject *obj_txs; + PyObject *obj_key; + PyObject *obj_addr; + uint64_t value; + PyBytesObject *bytes_cond; + size_t cond_size; + if (!PyArg_ParseTuple(args, "O|O|O|k|S|n", &obj_txs, &obj_key, &obj_addr, &value, &bytes_cond, &cond_size)) + return NULL; + dap_chain_datum_tx_t **txs = PyListToDapChainDatumTxArray(obj_txs); + void *cond = PyBytes_AsString((PyObject *)bytes_cond); + + int res = dap_chain_datum_tx_add_out_cond_item(txs, ((PyCryptoKeyObject*)obj_key)->key, + ((PyDapChainAddrObject*)obj_addr)->addr, value, cond, cond_size); + if (res == -1){ + return NULL; + } else { + PyObject *out = DapChainDatumTxArrayToPyList(txs); + return Py_BuildValue("O", out); + } +} +PyObject *dap_chain_datum_tx_add_sign_item_py(PyObject *self, PyObject *args){ + PyObject *obj_txs; + PyObject *obj_key; + if (!PyArg_ParseTuple(args, "O|O", &obj_txs, &obj_key)) + return NULL; + dap_chain_datum_tx_t **txs = PyListToDapChainDatumTxArray(obj_txs); + int res = dap_chain_datum_tx_add_sign_item(txs, ((PyCryptoKeyObject*)obj_key)->key); + if (res == -1){ + return NULL; + } else { + PyObject *out = DapChainDatumTxArrayToPyList(txs); + return Py_BuildValue("O", out); + } +} +PyObject *dap_chain_datum_tx_verify_sign_py(PyObject *self, PyObject *args){ + int res = dap_chain_datum_tx_verify_sign(((PyDapChainDatumTxObject*)self)->datum_tx); + return PyLong_FromLong(res); +} + +static dap_chain_datum_tx_t **PyListToDapChainDatumTxArray(PyObject *a_in_obj){ + Py_ssize_t size = PyList_Size(a_in_obj); + dap_chain_datum_tx_t **txs = calloc(sizeof(dap_chain_datum_tx_t), (size_t)size); + for (Py_ssize_t i = 0; i < size;i++){ + txs[i] = ((PyDapChainDatumTxObject*)PyList_GetItem(a_in_obj, i))->datum_tx; + } + return txs; +} + +static PyObject* DapChainDatumTxArrayToPyList(dap_chain_datum_tx_t** datum_txs){ + size_t len = sizeof(datum_txs) / sizeof(datum_txs[0]); + PyObject* list = PyList_New((Py_ssize_t)len); + for (size_t i=0; i < len; i++){ + PyObject *obj = _PyObject_New(&DapChainDatumTx_DapChainDatumTxObjectType); + ((PyDapChainDatumTxObject*)obj)->datum_tx = datum_txs[i]; + PyList_Append(list, obj); + } + return list; +} + +dap_chain_tx_out_cond_t **PyListToDapChainTxOutCond(PyObject *list){ + Py_ssize_t size = PyList_Size(list); + dap_chain_tx_out_cond_t **out_conds = calloc(sizeof(dap_chain_tx_out_cond_t), (size_t)size); + for (Py_ssize_t i=0; i < size; i++){ + out_conds[i] = ((PyDapChainTxOutCondObject*)PyList_GetItem(list, i))->out_cond; + } + return out_conds; +} + +PyObject *DapChainTxOutCondObjectToPyList(dap_chain_tx_out_cond_t **out_cond){ + size_t len = sizeof(out_cond) / sizeof(out_cond[0]); + PyObject *list = PyList_New((Py_ssize_t)len); + for (size_t i=0; i< len;i++ ){ + PyObject *obj = _PyObject_New(&DapChainTxOutCond_DapChainTxOutCondObjectType); + ((PyDapChainTxOutCondObject*)obj)->out_cond = out_cond[i]; + PyList_Append(list, obj); + } + return list; +} + +/* -------------------------------------- */ diff --git a/src/wrapping_dap_chain_ledger.c b/src/wrapping_dap_chain_ledger.c new file mode 100644 index 0000000000000000000000000000000000000000..76248e83cf16645e46ff0112d4203343a476ff35 --- /dev/null +++ b/src/wrapping_dap_chain_ledger.c @@ -0,0 +1,260 @@ +#include "wrapping_dap_chain_ledger.h" + +PyObject *DapChainLedgerObject_create(PyTypeObject *type_object, PyObject *args, PyObject *kwds){ + uint16_t check_flag; + if (!PyArg_ParseTuple(args, "H", &check_flag)) + return NULL; + PyDapChainLedgerObject *obj = (PyDapChainLedgerObject *)PyType_GenericNew(type_object, args, kwds); + obj->ledger = dap_chain_ledger_create(check_flag); + return (PyObject *)obj; +} +void DapChainLedgerObject_free(PyDapChainLedgerObject* object){ + dap_chain_ledger_handle_free(object->ledger); + Py_TYPE(object)->tp_free(object); +} + +PyObject *dap_chain_ledger_set_local_cell_id_py(PyObject *self, PyObject *args){ + PyObject *obj_local_cell_id; + if (!PyArg_ParseTuple(args, "O", &obj_local_cell_id)) + return NULL; + dap_chain_ledger_set_local_cell_id(((PyDapChainLedgerObject*)self)->ledger, + ((PyDapChainCellIdObject*)obj_local_cell_id)->id); + return PyLong_FromLong(0); +} +PyObject *dap_chain_node_datum_tx_calc_hash_py(PyObject *self, PyObject *args){ + PyObject *obj_tx; + if (!PyArg_ParseTuple(args, "O", &obj_tx)) + return NULL; + PyObject *obj_h_fast = _PyObject_New(&DapChainHashFastObject_DapChainHashFastObjectType); + ((PyDapChainHashFastObject*)obj_h_fast)->hash_fast = dap_chain_node_datum_tx_calc_hash(((PyDapChainDatumTxObject*)obj_tx)->datum_tx); + return Py_BuildValue("O", obj_h_fast); + +} +PyObject *dap_chain_ledger_tx_add_py(PyObject *self, PyObject *args){ + PyObject *obj_datum_tx; + if (!PyArg_ParseTuple(args, "O", &obj_datum_tx)) + return NULL; + int res = dap_chain_ledger_tx_add(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainDatumTxObject*)obj_datum_tx)->datum_tx); + return PyLong_FromLong(res); +} +PyObject *dap_chain_ledger_token_add_py(PyObject *self, PyObject *args) +{ + PyObject *token; + size_t token_size; + if (!PyArg_ParseTuple(args, "O|n", &token, &token_size)) + return NULL; + int res = dap_chain_ledger_token_add(((PyDapChainLedgerObject*)self)->ledger, + ((PyDapChainDatumTokenObject*)token)->token, token_size); + return PyLong_FromLong(res); +} +PyObject *dap_chain_ledger_token_emission_add_py(PyObject *self, PyObject *args){ + PyObject *token_emission; + size_t token_emissiom_size; + if (!PyArg_ParseTuple(args, "O|n", &token_emission, &token_emissiom_size)) + return NULL; + int res = dap_chain_ledger_token_emission_add(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainDatumTokenEmissionObject*)token_emission)->token_emission, token_emissiom_size); + return PyLong_FromLong(res); +} +PyObject *dap_chain_ledger_token_emission_find_py(PyObject *self, PyObject *args){ + PyObject *h_fast; + const char *token_ticker; + if (!PyArg_ParseTuple(args, "s|O", &token_ticker, &h_fast)) + return NULL; + PyObject *token_emission = _PyObject_New(&DapChainDatumTokenEmission_DapChainDatumTokenEmissionObjectType); + ((PyDapChainDatumTokenEmissionObject*)token_emission)->token_emission = dap_chain_ledger_token_emission_find( + ((PyDapChainLedgerObject*)self)->ledger, token_ticker, ((PyDapChainHashFastObject*)h_fast)->hash_fast); + return Py_BuildValue("O", &token_emission); +} +PyObject *dap_chain_ledger_tx_get_token_ticker_by_hash_py(PyObject *self, PyObject *args){ + PyObject *obj_tx_hash; + if (!PyArg_ParseTuple(args, "O", &obj_tx_hash)) + return NULL; + const char *res = dap_chain_ledger_tx_get_token_ticker_by_hash(((PyDapChainHashFastObject*)obj_tx_hash)->hash_fast); + return Py_BuildValue("s", res); +} +PyObject *dap_chain_ledger_addr_get_token_ticker_all_py(PyObject *self, PyObject *args){ + PyObject *obj_addr; + PyObject *obj_tickers; + PyObject *obj_tickers_size; + if (!PyArg_ParseTuple(args, "O|O|O", &obj_addr, &obj_tickers, &obj_tickers_size)) + return NULL; + char ***tickers = ListStringToArrayStringFormatChar(obj_tickers); + size_t *tickers_size = ListIntToSizeT(obj_tickers_size); + dap_chain_ledger_addr_get_token_ticker_all(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainAddrObject*)obj_addr)->addr, tickers, tickers_size); + return PyLong_FromLong(0); +} +PyObject *dap_chain_ledger_addr_get_token_ticker_all_fast_py(PyObject *self, PyObject *args){ + PyObject *obj_addr; + PyObject *obj_tickers; + PyObject *obj_tickers_size; + if (!PyArg_ParseTuple(args, "O|O|O", &obj_addr, &obj_tickers, &obj_tickers_size)) + return NULL; + char ***tickers = ListStringToArrayStringFormatChar(obj_tickers); + size_t *tickers_size = ListIntToSizeT(obj_tickers_size); + dap_chain_ledger_addr_get_token_ticker_all_fast(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainAddrObject*)obj_addr)->addr, tickers, tickers_size); + return PyLong_FromLong(0); +} +PyObject *dap_chain_ledger_tx_cache_check_py(PyObject *self, PyObject *args){ + PyObject *obj_datum_tx; + PyObject *list_bound_items; + PyObject *list_tx_out; + if (!PyArg_ParseTuple(args, "O|O|O", &obj_datum_tx, &list_bound_items, &list_tx_out)) + return NULL; + Py_ssize_t size_list_bound_item = PyList_Size(list_bound_items); + dap_list_t **bound_items = calloc(sizeof(dap_list_t**), (size_t)size_list_bound_item); + for (Py_ssize_t i = 0; i < size_list_bound_item;i++){ + PyObject *obj = PyList_GetItem(list_bound_items, i); + dap_list_t *l = pyListToDapList(obj); + bound_items[i] = l; + } + Py_ssize_t size_tx_out = PyList_Size(list_tx_out); + dap_list_t **tx_out = calloc(sizeof(dap_list_t**), (size_t)size_tx_out); + for (Py_ssize_t i = 0; i < size_tx_out;i++){ + PyObject *obj = PyList_GetItem(list_bound_items, i); + dap_list_t *l = pyListToDapList(obj); + tx_out[i] = l; + } + int res = dap_chain_ledger_tx_cache_check(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainDatumTxObject*)obj_datum_tx)->datum_tx, bound_items, tx_out); + return PyLong_FromLong(res); +} +PyObject *dap_chain_node_datum_tx_cache_check_py(PyObject *self, PyObject *args){ + PyObject *obj_datum_tx; + PyObject *list_bound_items; + if (!PyArg_ParseTuple(args, "O|O", &obj_datum_tx, &list_bound_items)) + return NULL; + Py_ssize_t size = PyList_Size(list_bound_items); + dap_list_t **bound_items = calloc(sizeof (dap_list_t**), (size_t)size); + for (int i = 0; i < size ; i++){ + PyObject *obj = PyList_GetItem(list_bound_items, i); + dap_list_t *l = pyListToDapList(obj); + bound_items[i] = l; + } + int res = dap_chain_node_datum_tx_cache_check(((PyDapChainDatumTxObject*)obj_datum_tx)->datum_tx, bound_items); + return PyLong_FromLong(res); +} +PyObject *dap_chain_ledger_tx_remove_py(PyObject *self, PyObject *args){ + PyObject *obj_h_fast; + if (!PyArg_ParseTuple(args, "O", &obj_h_fast)) + return NULL; + int res = dap_chain_ledger_tx_remove(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainHashFastObject*)obj_h_fast)->hash_fast); + return PyLong_FromLong(res); +} +PyObject *dap_chain_ledger_purge_py(PyObject *self, PyObject *args){ + dap_chain_ledger_purge(((PyDapChainLedgerObject*)self)->ledger); + return PyLong_FromLong(0); +} +PyObject *dap_chain_ledger_count_py(PyObject *self, PyObject *args){ + long long res = (long long)dap_chain_ledger_count(((PyDapChainLedgerObject*)self)->ledger); + return PyLong_FromLongLong(res); +} +PyObject *dap_chain_ledger_count_from_to_py(PyObject *self, PyObject *args){ + long ts_from, ts_to; + if (!PyArg_ParseTuple(args, "l|l", &ts_from, &ts_to)) + return NULL; + uint64_t res = dap_chain_ledger_count_from_to(((PyDapChainLedgerObject*)self)->ledger, (time_t)ts_from, (time_t)ts_to); + return PyLong_FromUnsignedLongLong(res); +} +PyObject *dap_chain_ledger_tx_hash_is_used_out_item_py(PyObject *self, PyObject *args){ + PyObject *obj_h_fast; + int idx_out; + if (!PyArg_ParseTuple(args, "O|i", &obj_h_fast, &idx_out)) + return NULL; + bool res = dap_chain_ledger_tx_hash_is_used_out_item(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainHashFastObject*)obj_h_fast)->hash_fast, idx_out); + if (res) + return Py_BuildValue("O", Py_True); + else + return Py_BuildValue("O", Py_False); +} +PyObject *dap_chain_ledger_calc_balance_py(PyObject *self, PyObject *args){ + PyObject *addr; + const char *token_ticker; + if (!PyArg_ParseTuple(args, "O|s", &addr, &token_ticker)) + return NULL; + uint64_t res = dap_chain_ledger_calc_balance(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainAddrObject*)addr)->addr, token_ticker); + return Py_BuildValue("k", res); +} +PyObject *dap_chain_ledger_calc_balance_full_py(PyObject *self, PyObject *args){ + PyObject *addr; + const char *token_ticker; + if (!PyArg_ParseTuple(args, "O|s", &addr, &token_ticker)) + return NULL; + uint64_t res = dap_chain_ledger_calc_balance_full(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainAddrObject*)addr)->addr, token_ticker); + return Py_BuildValue("k", res); +} +PyObject *dap_chain_ledger_tx_find_by_hash_py(PyObject *self, PyObject *args){ + PyObject *h_fast; + if (!PyArg_ParseTuple(args, "O", &h_fast)) + return NULL; + PyObject *res = _PyObject_New(&DapChainDatumTx_DapChainDatumTxObjectType); + ((PyDapChainDatumTxObject*)res)->datum_tx = dap_chain_ledger_tx_find_by_hash(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainHashFastObject*)h_fast)->hash_fast); + return Py_BuildValue("O", res); +} +PyObject *dap_chain_ledger_tx_find_by_addr_py(PyObject *self, PyObject *args){ + const char *token; + PyObject *addr; + PyObject *first_hash; + if (!PyArg_ParseTuple(args, "s|O|O", &token, &addr, &first_hash)) + return NULL; + PyObject *res = _PyObject_New(&DapChainDatumTx_DapChainDatumTxObjectType); + ((PyDapChainDatumTxObject*)res)->datum_tx = dap_chain_ledger_tx_find_by_addr(((PyDapChainLedgerObject*)self)->ledger, token, ((PyDapChainAddrObject*)addr)->addr, ((PyDapChainHashFastObject*)first_hash)->hash_fast); + return Py_BuildValue("O", res); +} +PyObject *dap_chain_ledger_tx_find_by_pkey_py(PyObject *self, PyObject *args){ + char *p_key; + size_t p_key_size; + PyObject *obj_first_hash; + if (!PyArg_ParseTuple(args, "s|n|O", &p_key, &p_key_size, &obj_first_hash)) + return NULL; + PyObject *res = _PyObject_New(&DapChainDatumTx_DapChainDatumTxObjectType); + ((PyDapChainDatumTxObject*)res)->datum_tx = dap_chain_ledger_tx_find_by_pkey(((PyDapChainLedgerObject*)self)->ledger, p_key, p_key_size, ((PyDapChainHashFastObject*)obj_first_hash)->hash_fast); + return Py_BuildValue("O", res); +} +PyObject *dap_chain_ledger_tx_cache_find_out_cond_py(PyObject *self, PyObject *args){ + PyObject *obj_addr; + PyObject *obj_first_hash; + if (!PyArg_ParseTuple(args, "O|O", &obj_addr, &obj_first_hash)) + return NULL; + PyObject *res = _PyObject_New(&DapChainDatumTx_DapChainDatumTxObjectType); + ((PyDapChainDatumTxObject*)res)->datum_tx = dap_chain_ledger_tx_cache_find_out_cond(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainAddrObject*)obj_addr)->addr, ((PyDapChainHashFastObject*)obj_first_hash)->hash_fast); + return Py_BuildValue("O", res); +} +PyObject *dap_chain_ledger_tx_cache_get_out_cond_value_py(PyObject *self, PyObject *args){ + PyObject *obj_addr; + PyObject *obj_out_conds; + if (!PyArg_ParseTuple(args, "O|O", &obj_addr, &obj_out_conds)) + return NULL; + if (!PyList_Check(obj_out_conds)){ + PyErr_SetString(PyExc_TypeError, "Thse second argument received isn't array"); + return NULL; + } + dap_chain_tx_out_cond_t **out_conds = PyListToDapChainTxOutCond(obj_out_conds); + uint64_t res = dap_chain_ledger_tx_cache_get_out_cond_value(((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainAddrObject*)obj_addr)->addr, out_conds); + return PyLong_FromUnsignedLongLong(res); +} + +static char*** ListStringToArrayStringFormatChar(PyObject *list){ + Py_ssize_t size = PyList_Size(list); + char ***data = calloc(sizeof(char**), (size_t)size); + for (Py_ssize_t i = 0; i < size; i++){ + PyObject *obj_two = PyList_GetItem(list,i); + Py_ssize_t size_seentenses = PyList_Size(obj_two); + char **sentences = calloc(sizeof(char**), (size_t)size_seentenses); + for (int j=0; j < size_seentenses;j++){ + PyObject *obj_byte = PyList_GetItem(obj_two, j); + char *word = PyBytes_AsString(obj_byte); + sentences[j] = word; + } + data[i] = sentences; + } + return data; +} + +static size_t *ListIntToSizeT(PyObject *list){ + Py_ssize_t size = PyList_Size(list); + size_t *res_size_t = calloc(sizeof(size_t), (size_t)size); + for (Py_ssize_t i=0; i<size;i++){ + PyObject *obj = PyList_GetItem(list, i); + res_size_t[i] = (size_t)PyLong_AsSsize_t(obj); + } + return res_size_t; +}