From 833bba4348f894d4e21908073e0251df427a5864 Mon Sep 17 00:00:00 2001 From: "alexey.stratulat" <alexey.stratulat@demlabs.net> Date: Fri, 8 Nov 2019 01:07:51 +0700 Subject: [PATCH] [+] Added object ChainTxOutCond. This object are wrapping over structur dap_chain_tx_out_cond_t. Added functions to convert an list object type ChainTxOutCond to an dap_chain_tx_out_cond_t** and back. --- include/wrapping_dap_chain_datum_tx.h | 53 +++++++++++++++++++++++++++ src/wrapping_dap_chain_datum_tx.c | 20 ++++++++++ 2 files changed, 73 insertions(+) diff --git a/include/wrapping_dap_chain_datum_tx.h b/include/wrapping_dap_chain_datum_tx.h index e6504429..9da07a60 100644 --- a/include/wrapping_dap_chain_datum_tx.h +++ b/include/wrapping_dap_chain_datum_tx.h @@ -5,6 +5,7 @@ #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" { @@ -206,6 +207,58 @@ static PyTypeObject DapChainDatumTx_DapChainDatumTxObjectType = { /* -------------------------------------- */ +typedef struct PyDapChainTxOutCond{ + PyObject_HEAD + dap_chain_tx_out_cond_t *out_cond; +}PyDapChainTxOutCondObject; + +static PyTypeObject DapChainTxOutCond_DapChainTxOutCondObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ChainTxOutCond", /* 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 diff --git a/src/wrapping_dap_chain_datum_tx.c b/src/wrapping_dap_chain_datum_tx.c index 03e4a9e4..49bc2c7d 100644 --- a/src/wrapping_dap_chain_datum_tx.c +++ b/src/wrapping_dap_chain_datum_tx.c @@ -149,4 +149,24 @@ static PyObject* DapChainDatumTxArrayToPyList(dap_chain_datum_tx_t** datum_txs){ 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; +} + /* -------------------------------------- */ -- GitLab