From 7cced37d3b96696a4172092db416d624c40bee1e Mon Sep 17 00:00:00 2001 From: "alexey.stratulat" <alexey.stratulat@demlabs.net> Date: Wed, 26 Jan 2022 23:53:06 +0700 Subject: [PATCH] [+] Added an id attribute to an object of type ChainNet, which returns an object of type ChainNetId. --- .../net/include/libdap_chain_net_python.h | 12 +++++++++--- .../cellframe-sdk/net/src/libdap_chain_net_python.c | 8 ++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/cellframe-sdk/net/include/libdap_chain_net_python.h b/modules/cellframe-sdk/net/include/libdap_chain_net_python.h index d6bf30b2..36c62ceb 100644 --- a/modules/cellframe-sdk/net/include/libdap_chain_net_python.h +++ b/modules/cellframe-sdk/net/include/libdap_chain_net_python.h @@ -77,6 +77,7 @@ PyObject *dap_chain_net_get_chain_by_chain_type_py(PyObject *self, PyObject *arg PyObject *dap_chain_net_get_ledger_py(PyObject *self, PyObject *args); PyObject *dap_chain_net_get_name_py(PyObject *self, PyObject *args); PyObject *dap_chain_net_get_tx_by_hash_py(PyObject *self, PyObject *args); +PyObject *dap_chain_net_python_get_id(PyObject *self, void *closure); static PyMethodDef DapChainNetMethods[] = { {"loadAll", dap_chain_net_load_all_py, METH_NOARGS | METH_STATIC, ""}, @@ -105,6 +106,11 @@ static PyMethodDef DapChainNetMethods[] = { {NULL, NULL, 0, NULL} }; +static PyGetSetDef DapChainNetGetsSetsDef[] = { + {"id", (getter)dap_chain_net_python_get_id, NULL, NULL, NULL}, + {NULL} +}; + static PyTypeObject DapChainNetObject_DapChainNetObjectType = { PyVarObject_HEAD_INIT(NULL, 0) "CellFrame.ChainNet", /* tp_name */ @@ -134,9 +140,9 @@ static PyTypeObject DapChainNetObject_DapChainNetObjectType = { 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ - DapChainNetMethods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ + DapChainNetMethods, /* tp_methods */ + 0, /* tp_members */ + DapChainNetGetsSetsDef, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ diff --git a/modules/cellframe-sdk/net/src/libdap_chain_net_python.c b/modules/cellframe-sdk/net/src/libdap_chain_net_python.c index 3f81f3f6..5d1a0c8d 100644 --- a/modules/cellframe-sdk/net/src/libdap_chain_net_python.c +++ b/modules/cellframe-sdk/net/src/libdap_chain_net_python.c @@ -183,3 +183,11 @@ PyObject *dap_chain_net_get_tx_by_hash_py(PyObject *self, PyObject *args){ } return (PyObject*)obj_tx; } + +PyObject *dap_chain_net_python_get_id(PyObject *self, void *closure){ + (void)closure; + PyDapChainNetIdObject *obj_net_id = PyObject_New(PyDapChainNetObject, &DapChainNetIdObject_DapChainNetIdObjectType); + PyObject_Dir((PyObject*)obj_net_id); + obj_net_id->net_id = ((PyDapChainNetObject*)self)->chain_net->pub.id; + return (PyObject*)obj_net_id; +} -- GitLab