From 7de108725a568d8899631877a8c568ca9d8314d9 Mon Sep 17 00:00:00 2001 From: "alexey.stratulat" <alexey.stratulat@demlabs.net> Date: Wed, 27 Nov 2019 00:05:04 +0700 Subject: [PATCH] [+] Added the ability to work with Python for the following types of objects: ChainID, ChainCellID, ChainNodeAddr, ChainHashSlow, ChainHashFast, ChainHashSlowKind, ChainAddr, ChainLedger. They are implemented in libdap-chain-python. --- include/python-cellframe.h | 1 + src/python-cellframe.c | 31 ++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/python-cellframe.h b/include/python-cellframe.h index 3ea970a9..cc02a5fb 100644 --- a/include/python-cellframe.h +++ b/include/python-cellframe.h @@ -11,6 +11,7 @@ #include "libdap_chain_atom_iter_python.h" #include "wrapping_dap_chain_cell.h" #include "wrapping_dap_chain_common.h" +#include "wrapping_dap_chain_common_objects.h" #include "wrapping_dap_chain_cs.h" #include "wrapping_dap_chain_datum.h" #include "wrapping_dap_chain_datum_token.h" diff --git a/src/python-cellframe.c b/src/python-cellframe.c index f43cafec..5e525c79 100644 --- a/src/python-cellframe.c +++ b/src/python-cellframe.c @@ -101,6 +101,11 @@ static PyObject *python_cellframe_init(PyObject *self, PyObject *args){ "Fields thread_cnt and conn are not numerical or absent."); return NULL; } + if (dap_chain_cs_init_py() != 0){ + PyErr_SetString(CellFrame_error, "Failed to initialize Chain CS. " + "Fields thread_cnt and conn are not numerical or absent."); + return NULL; + } } } return PyLong_FromLong(0); @@ -119,6 +124,15 @@ PyMODINIT_FUNC PyInit_CellFrame(void){ PyType_Ready(&dapChainAtomPtr_dapChainAtomPtrType) < 0 || PyType_Ready(&DapChainCell_DapChainCellObjectType) < 0 || PyType_Ready(&ChainCommonObject_ChainCommonType) < 0 || + + PyType_Ready(&DapChainIdObject_DapChainIdObjectType) < 0 || + PyType_Ready(&DapChainCellIdObject_DapChainCellIdObjectType) < 0 || + PyType_Ready(&DapChainNodeAddrObject_DapChainNodeAddrObjectType) < 0 || + PyType_Ready(&DapChainHashSlowObject_DapChainHashSlowObjectType) < 0 || + PyType_Ready(&DapChainHashFastObject_DapChainHashFastObjectType) < 0 || + PyType_Ready(&DapChainHashSlowKindObject_DapChainHashSlowKindObjectType) < 0 || + PyType_Ready(&DapChainAddrObject_DapChainAddrObjectType) < 0 || + PyType_Ready(&DapChainCsObject_DapChainCsObjectType) < 0 || PyType_Ready(&DapChainDatumTypeIdObject_DapChainDatumTypeIdObjectType) < 0 || PyType_Ready(&DapChainDatumObject_DapChainDatumObjectType) < 0 || @@ -128,8 +142,8 @@ PyMODINIT_FUNC PyInit_CellFrame(void){ PyType_Ready(&DapChainTxItemObject_DapChainTxItemTypeObjectType) < 0 || PyType_Ready(&DapChainTxType_DapChainTxCondTypeObject) < 0 || PyType_Ready(&DapChainDatumTx_DapChainDatumTxObjectType) < 0 || - PyType_Ready(&DapChainTxOutCond_DapChainTxOutCondObjectType) < 0 -// PyType_Ready(&DapChainLedger_DapChainLedgerType) < 0 + PyType_Ready(&DapChainTxOutCond_DapChainTxOutCondObjectType) < 0 || + PyType_Ready(&DapChainLedger_DapChainLedgerType) < 0 // ============= ) return NULL; @@ -163,6 +177,16 @@ PyMODINIT_FUNC PyInit_CellFrame(void){ PyModule_AddObject(module, "ChainAtomIter", (PyObject*)&dapChainAtomPtr_dapChainAtomPtrType); PyModule_AddObject(module, "ChainCell", (PyObject*)&DapChainCell_DapChainCellObjectType); PyModule_AddObject(module, "ChainCommon", (PyObject*)&ChainCommonObject_ChainCommonType); + + PyModule_AddObject(module, "ChainID", (PyObject*)&DapChainIdObject_DapChainIdObjectType); + PyModule_AddObject(module, "ChainCellID", (PyObject*)&DapChainCellIdObject_DapChainCellIdObjectType); + PyModule_AddObject(module, "ChainNodeAddr", (PyObject*)&DapChainNodeAddrObject_DapChainNodeAddrObjectType); +// PyModule_AddObject(module, "ChainNetID", (PyObject*)&DapChainNetIdObject_DapChainNetIdObjectType); + PyModule_AddObject(module, "ChainHashSlow", (PyObject*)&DapChainHashSlowObject_DapChainHashSlowObjectType); + PyModule_AddObject(module, "ChainHashFast", (PyObject*)&DapChainHashFastObject_DapChainHashFastObjectType); + PyModule_AddObject(module, "ChainHashSlowKind", (PyObject*)&DapChainHashSlowKindObject_DapChainHashSlowKindObjectType); + PyModule_AddObject(module, "ChainAddr", (PyObject*)&DapChainAddrObject_DapChainAddrObjectType); + PyModule_AddObject(module, "ChainCS", (PyObject*)&DapChainCsObject_DapChainCsObjectType); PyModule_AddObject(module, "ChainDatumTypeID", (PyObject*)&DapChainDatumTypeIdObject_DapChainDatumTypeIdObjectType); PyModule_AddObject(module, "ChainDatum", (PyObject*)&DapChainDatumObject_DapChainDatumObjectType); @@ -173,7 +197,7 @@ PyMODINIT_FUNC PyInit_CellFrame(void){ PyModule_AddObject(module, "ChainTxCondType", (PyObject*)&DapChainTxType_DapChainTxCondTypeObject); PyModule_AddObject(module, "ChainDatumTx", (PyObject*)&DapChainDatumTx_DapChainDatumTxObjectType); PyModule_AddObject(module, "ChainTxOutCond", (PyObject*)&DapChainTxOutCond_DapChainTxOutCondObjectType); -// PyModule_AddObject(module, "ChainLedger", (PyObject*)&DapChainLedger_DapChainLedgerType); + PyModule_AddObject(module, "ChainLedger", (PyObject*)&DapChainLedger_DapChainLedgerType); // ============= @@ -187,6 +211,7 @@ static PyObject *python_cellframe_deinit(PyObject *self, PyObject *args){ dap_crypto_deinit(); if (init_chain){ deinit_chain_py(); + dap_chain_cs_deinit_py(); } return PyLong_FromLong(0); } -- GitLab