diff --git a/CellFrame/python-cellframe.c b/CellFrame/python-cellframe.c index af45ad84d765dbeeb27e887224924581f4cc1a2c..78d7bccd7895031b71ef7aac28268a44c4c71cb5 100644 --- a/CellFrame/python-cellframe.c +++ b/CellFrame/python-cellframe.c @@ -383,7 +383,7 @@ PyMODINIT_FUNC PyInit_libCellFrame(void){ PyType_Ready( &DapChainAtomIter_DapChainAtomIterType ) < 0 || PyType_Ready(&DapChainAtomPtr_DapChainAtomPtrType) < 0 || PyType_Ready( &DapChainCell_DapChainCellObjectType ) < 0 || -// PyType_Ready(&ChainCommonObject_ChainCommonType) < 0 || + PyType_Ready(&DapChainCommonObject_DapChainCommonType) < 0 || PyType_Ready( &DapChainCellIDObject_DapChainCellIDType) < 0 || PyType_Ready( &DapChainCellIDObject_DapChainCellIDType) < 0 || @@ -484,7 +484,7 @@ PyMODINIT_FUNC PyInit_libCellFrame(void){ PyModule_AddObject(module, "ChainAtomIter", (PyObject*)&DapChainAtomIter_DapChainAtomIterType); PyModule_AddObject(module, "ChainAtomPtr", (PyObject*)&DapChainAtomPtr_DapChainAtomPtrType); PyModule_AddObject(module, "ChainCell", (PyObject*)&DapChainCell_DapChainCellObjectType); -// PyModule_AddObject(module, "ChainCommon", (PyObject*)&ChainCommonObject_ChainCommonType); + PyModule_AddObject(module, "ChainCommon", (PyObject*)&DapChainCommonObject_DapChainCommonType); // PyModule_AddObject(module, "ChainID", (PyObject*)&DapChainIDObject_DapChainIDType); PyModule_AddObject(module, "ChainCellID", (PyObject*)&DapChainCellIDObject_DapChainCellIDType); diff --git a/modules/cellframe-sdk/chain/src/wrapping_dap_chain_ledger.c b/modules/cellframe-sdk/chain/src/wrapping_dap_chain_ledger.c index 8f84a0561d6b6b5ef8c310f17c788d4581d6c3fb..a12e9c8366bcc96f4fb2467bcc7894191a9764cd 100644 --- a/modules/cellframe-sdk/chain/src/wrapping_dap_chain_ledger.c +++ b/modules/cellframe-sdk/chain/src/wrapping_dap_chain_ledger.c @@ -195,7 +195,7 @@ PyObject *dap_chain_ledger_calc_balance_py(PyObject *self, PyObject *args){ ((PyDapChainLedgerObject*)self)->ledger, ((PyDapChainAddrObject*)addr)->addr, token_ticker); uint64_t res = dap_chain_uint128_to(balance); - char* coins = dap_chain_balance_to_coins(res); + char* coins = dap_chain_balance_to_coins(balance); return Py_BuildValue("sk", coins, res); } PyObject *dap_chain_ledger_calc_balance_full_py(PyObject *self, PyObject *args){ diff --git a/modules/cellframe-sdk/common/include/wrapping_dap_chain_common.h b/modules/cellframe-sdk/common/include/wrapping_dap_chain_common.h index d70c37d3b181ab0198c4f6c1572c7390da0d9d89..5a4fe6901b6575e9eeceb3c757a66fc2e8f4499d 100644 --- a/modules/cellframe-sdk/common/include/wrapping_dap_chain_common.h +++ b/modules/cellframe-sdk/common/include/wrapping_dap_chain_common.h @@ -531,6 +531,62 @@ static PyTypeObject DapChainSlowKindObject_DapChainSlowKindType = { }; +/*=================*/ + +/**/ +typedef struct PyDapChainCommon{ + PyObject_HEAD +}PyDapChainCommonObject; + +PyObject * dap_chain_balance_to_coins_py(PyObject *self, PyObject *args); + +static PyMethodDef DapChainCommonMethodsDef[] = { + {"balanceToCoins", (PyCFunction)dap_chain_balance_to_coins_py, METH_VARARGS | METH_STATIC, ""}, + {NULL, NULL, 0, NULL} +}; + +static PyTypeObject DapChainCommonObject_DapChainCommonType = { + PyVarObject_HEAD_INIT(NULL, 0) + "CellFrame.ChainCommon" , /* 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 object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + DapChainCommonMethodsDef, /* 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/modules/cellframe-sdk/common/src/wrapping_dap_chain_common.c b/modules/cellframe-sdk/common/src/wrapping_dap_chain_common.c index 44c2d0f039f3e7911c29ee6532511e1c41184222..1ebdc0ce0a6cfb7775da4d22f9cf4b69effbc436 100644 --- a/modules/cellframe-sdk/common/src/wrapping_dap_chain_common.c +++ b/modules/cellframe-sdk/common/src/wrapping_dap_chain_common.c @@ -76,3 +76,13 @@ PyObject *dap_chain_net_srv_uid_from_str_py(PyObject *self, PyObject *args){ ((PyDapChainNetSrvUIDObject*)obj)->net_srv_uid = dap_chain_net_srv_uid_from_str(str); return Py_BuildValue("O", obj); } + +PyObject * dap_chain_balance_to_coins_py(PyObject *self, PyObject *args){ + (void)self; + uint64_t balance=0; + if (!PyArg_ParseTuple(args, "k", &balance)){ + return NULL; + } + const char *str = dap_chain_balance_to_coins(dap_chain_uint128_to(balance)); + return Py_BuildValue("s", str); +} 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 282da1267f54dc4ab87164d5327f02e9c604ae75..d6bf30b29fef57a72b4176029e2a69859ea9d3c3 100644 --- a/modules/cellframe-sdk/net/include/libdap_chain_net_python.h +++ b/modules/cellframe-sdk/net/include/libdap_chain_net_python.h @@ -76,6 +76,7 @@ PyObject *dap_chain_net_links_connect_py(PyObject *self, PyObject *args); PyObject *dap_chain_net_get_chain_by_chain_type_py(PyObject *self, PyObject *args); 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); static PyMethodDef DapChainNetMethods[] = { {"loadAll", dap_chain_net_load_all_py, METH_NOARGS | METH_STATIC, ""}, @@ -100,6 +101,7 @@ static PyMethodDef DapChainNetMethods[] = { {"getChainByChainType", dap_chain_net_get_chain_by_chain_type_py, METH_VARARGS, ""}, {"getLedger", dap_chain_net_get_ledger_py, METH_NOARGS, ""}, {"getName", dap_chain_net_get_name_py, METH_NOARGS, ""}, + {"getTxByHash", dap_chain_net_get_tx_by_hash_py, METH_VARARGS, ""}, {NULL, NULL, 0, NULL} }; 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 ae9a4b94db041201324023e00647031a233ba3db..3f81f3f6c6768137b18d858622374ea0b88959fe 100644 --- a/modules/cellframe-sdk/net/src/libdap_chain_net_python.c +++ b/modules/cellframe-sdk/net/src/libdap_chain_net_python.c @@ -167,3 +167,19 @@ PyObject *dap_chain_net_get_name_py(PyObject *self, PyObject *args){ PyObject *obj_name = PyUnicode_FromString(((PyDapChainNetObject*)self)->chain_net->pub.name); return obj_name; } + +PyObject *dap_chain_net_get_tx_by_hash_py(PyObject *self, PyObject *args){ + PyObject *obj_hash; + if (!PyArg_ParseTuple(args, "O", &obj_hash)){ + return NULL; + } + PyDapChainDatumTxObject *obj_tx = PyObject_New(PyDapChainDatumTxObject, &DapChainDatumTx_DapChainDatumTxObjectType); + PyObject_Dir((PyObject*)obj_tx); + obj_tx->datum_tx = dap_chain_net_get_tx_by_hash(((PyDapChainNetObject*)self)->chain_net, + ((PyDapHashFastObject*)obj_hash)->hash_fast, TX_SEARCH_TYPE_LOCAL); + if(obj_tx->datum_tx == NULL){ + Py_XDECREF(obj_tx); + return Py_None; + } + return (PyObject*)obj_tx; +} diff --git a/modules/dap-sdk/crypto/include/wrapping_dap_sign.h b/modules/dap-sdk/crypto/include/wrapping_dap_sign.h index 55fbaa5ab2529937d5aa4bbf96c188099bc134f1..2ba1a48f86784c891cdccba8c8b68ab54043fa7b 100644 --- a/modules/dap-sdk/crypto/include/wrapping_dap_sign.h +++ b/modules/dap-sdk/crypto/include/wrapping_dap_sign.h @@ -86,11 +86,13 @@ typedef struct PyDapSign{ PyObject *wrapping_dap_sign_get_type(PyObject *self, void *closure); PyObject *wrapping_dap_sign_get_pkey(PyObject *self, void *closure); +PyObject *wrapping_dap_sign_get_pkey_hash(PyObject *self, void *closure); PyObject *wrapping_dap_sign_get_size(PyObject *self, void *closure); static PyGetSetDef DapSignObjectGetsSetsDef[] = { {"type", (getter)wrapping_dap_sign_get_type, NULL, NULL, NULL}, {"pkey", (getter)wrapping_dap_sign_get_pkey, NULL, NULL, NULL}, + {"pkeyHash", (getter)wrapping_dap_sign_get_pkey_hash, NULL,NULL, NULL}, {"size", (getter)wrapping_dap_sign_get_size, NULL, NULL, NULL}, {NULL} }; diff --git a/modules/dap-sdk/crypto/src/wrapping_dap_sign.c b/modules/dap-sdk/crypto/src/wrapping_dap_sign.c index 9ac7d27548fa4e9d389583ae84930b66e49eab85..be175709d7c1ca4674be570454ed08402a9c7ac9 100644 --- a/modules/dap-sdk/crypto/src/wrapping_dap_sign.c +++ b/modules/dap-sdk/crypto/src/wrapping_dap_sign.c @@ -18,6 +18,14 @@ PyObject *wrapping_dap_sign_get_pkey(PyObject *self, void *closure){ obj_pkey->pkey = (dap_pkey_t*)((PyDapSignObject*)self)->sign->pkey_n_sign; return (PyObject*)obj_pkey; } +PyObject *wrapping_dap_sign_get_pkey_hash(PyObject *self, void *closure){ + (void)closure; + PyDapHashFastObject *obj_hash = PyObject_New(PyDapHashFastObject, &DapHashFastObject_DapHashFastObjectType); + PyObject_Dir((PyObject*)obj_hash); + obj_hash->hash_fast = DAP_NEW(dap_chain_hash_fast_t); + dap_sign_get_pkey_hash(((PyDapSignObject*)self)->sign, obj_hash->hash_fast); + return (PyObject*)obj_hash; +} PyObject *wrapping_dap_sign_get_size(PyObject *self, void *closure){ (void)closure; return Py_BuildValue("I", ((PyDapSignObject*)self)->sign->header.sign_size); diff --git a/setup.py b/setup.py index 8ab0204d2e05e0d0d8f8061c3a61dbacbe8cafd8..28b026490719b6b290f54d53d1b41872f4d416d9 100755 --- a/setup.py +++ b/setup.py @@ -70,9 +70,9 @@ class CMakeBuild(build_ext): setup( name="CellFrame", - version="2.9-33", + version="2.9-34", description="CellFrame SDK", - author='Demlabs (2007-2021)', + author='Demlabs (2007-2022)', license="GNU GPLv3", packages=['CellFrame'], ext_modules=[CMakeExtension('CellFrame/libCellFrame')],