diff --git a/include/dap_chain_wallet_python.h b/include/dap_chain_wallet_python.h index be59c120d63775c8215520075a38ab5bb15f6275..8dffa4dcf4193b19dea6d7b8f6d64578f5635d93 100644 --- a/include/dap_chain_wallet_python.h +++ b/include/dap_chain_wallet_python.h @@ -4,6 +4,9 @@ #include <Python.h> #include "dap_common.h" #include "dap_chain_wallet.h" +#include "wrapping_dap_chain_common.h" +#include "libdap_crypto_key_python.h" +//#include "wrapping_dap_sign #ifdef __cplusplus extern "C"{ @@ -35,16 +38,19 @@ PyObject *dap_cert_to_addr_py(PyObject *self, PyObject *argv); PyObject *dap_chain_wallet_get_addr_py(PyObject *self, PyObject *argv); PyObject *dap_chain_wallet_get_certs_number_py(PyObject *self, PyObject *argv); PyObject *dap_chain_wallet_get_pkey_py(PyObject *self, PyObject *argv); -PyObject *dap_chain_wallet_get_key_p(PyObject *self, PyObject *argv); +PyObject *dap_chain_wallet_get_key_py(PyObject *self, PyObject *argv); //PyObject *dap_chain_wallet_save_file_py(PyObject *self, PyObject *argv); static PyMethodDef ChainWalletMethods[] = { {"getPath", (PyCFunction)dap_chain_wallet_get_path_py, METH_VARARGS | METH_STATIC, ""}, + {"createWithSeed", (PyCFunction)dap_chain_wallet_create_with_seed_py, METH_VARARGS | METH_STATIC, ""}, {"openFile", (PyCFunction)dap_chain_wallet_open_file_py, METH_VARARGS | METH_STATIC, ""}, {"open", (PyCFunction)dap_chain_wallet_open_py, METH_VARARGS | METH_STATIC, ""}, {"save", (PyCFunction)dap_chain_wallet_save_py, METH_NOARGS, ""}, + {"getAddr", (PyCFunction)dap_chain_wallet_get_addr_py, METH_VARARGS, ""}, {"getCertsNumber", (PyCFunction)dap_chain_wallet_get_certs_number_py, METH_NOARGS, ""}, + {"getKey", (PyCFunction)dap_chain_wallet_get_key_py, METH_VARARGS, ""}, {NULL, NULL, 0, NULL} }; diff --git a/src/dap_chain_wallet_python.c b/src/dap_chain_wallet_python.c index 22a1cfd9b048d83fcd8ff13bb8531138e8751c92..f9712b2e3d3848543921a4e766969431b94654e0 100644 --- a/src/dap_chain_wallet_python.c +++ b/src/dap_chain_wallet_python.c @@ -14,6 +14,20 @@ PyObject *dap_chain_wallet_get_path_py(PyObject *self, PyObject *argv){ return Py_BuildValue("(s)", path); } +PyObject *dap_chain_wallet_create_with_seed_py(PyObject *self, PyObject *argv){ + (void)self; + const char *wallet_name; + const char *path_wallets; + PyObject *obj_sig_type; + PyObject *obj_seed; + if (!PyArg_ParseTuple(argv, "ssOO", &wallet_name, &path_wallets, &obj_sig_type, &obj_seed)) + return NULL; + if (PyBytes_Check(obj_seed)){ + PyErr_SetString(PyExc_TypeError, "Fourth argument to not have a Bytes object type"); + return NULL; + } + return NULL;; +} PyObject *dap_chain_wallet_open_file_py(PyObject *self, PyObject *argv){ (void)self; const char *file_path; @@ -44,8 +58,35 @@ void dap_chain_wallet_close_py(PyDapChainWalletObject *self){ Py_TYPE(self)->tp_free((PyObject*)self); } +PyObject *dap_cert_to_addr_py(PyObject *self, PyObject *argv){ + (void)self; + return NULL; +} + +PyObject *dap_chain_wallet_get_addr_py(PyObject *self, PyObject *argv){ + PyObject *obj_net_id; + if (!PyArg_ParseTuple(argv, "O", &obj_net_id)) + return NULL; + PyObject *obj_addr = _PyObject_New(&DapChainAddrObject_DapChainAddrObjectType); + ((PyDapChainAddrObject*)obj_addr)->addr = dap_chain_wallet_get_addr( + ((PyDapChainWalletObject*)self)->wallet, + ((PyDapChainNetIdObject*)obj_net_id)->net_id + ); + return Py_BuildValue("(O)", obj_addr); +} PyObject *dap_chain_wallet_get_certs_number_py(PyObject *self, PyObject *argv){ (void)argv; size_t result = dap_chain_wallet_get_certs_number(((PyDapChainWalletObject*)self)->wallet); return PyLong_FromLong(result); } +PyObject *dap_chain_wallet_get_key_py(PyObject *self, PyObject *argv){ + uint32_t key_idx; + if (!PyArg_ParseTuple(argv, "I", &key_idx)) + return NULL; + PyObject *obj_key = _PyObject_New(&PyCryptoKeyObject_PyCryptoKeyType); + ((PyCryptoKeyObject*)obj_key)->key = dap_chain_wallet_get_key( + ((PyDapChainWalletObject*)self)->wallet, + key_idx + ); + return Py_BuildValue("(O)", obj_key); +}