Skip to content
Snippets Groups Projects
Commit 6846a891 authored by alexey.stratulat's avatar alexey.stratulat
Browse files

[+] Added functions getPKey, certToAddr. Added constructor for object ChainWallet.

parent 462815ae
No related branches found
No related tags found
1 merge request!1Features 2773
......@@ -7,7 +7,8 @@
#include "wrapping_dap_chain_common.h"
#include "libdap_crypto_key_python.h"
#include "wrapping_dap_sign.h"
//#include "wrapping_dap_sign
#include "wrapping_dap_pkey.h"
#include "wrapping_cert.h"
#ifdef __cplusplus
extern "C"{
......@@ -27,7 +28,7 @@ void dap_chain_wallet_deinit_py(void);
PyObject *dap_chain_wallet_get_path_py(PyObject *self, PyObject *argv);
PyObject *dap_chain_wallet_create_with_seed_py(PyObject *self, PyObject *argv);
PyObject *dap_chain_wallet_create_py(PyObject *self, PyObject *argv);
PyObject *dap_chain_wallet_create_py(PyTypeObject *type, PyObject *argv, PyObject *kwds);
PyObject *dap_chain_wallet_open_file_py(PyObject *self, PyObject *argv);
PyObject *dap_chain_wallet_open_py(PyObject *self, PyObject *argv);
PyObject *dap_chain_wallet_save_py(PyObject *self, PyObject *argv);
......@@ -49,8 +50,10 @@ static PyMethodDef ChainWalletMethods[] = {
{"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, ""},
{"certToAddr", (PyCFunction)dap_cert_to_addr_py, METH_VARARGS | METH_STATIC, ""},
{"getAddr", (PyCFunction)dap_chain_wallet_get_addr_py, METH_VARARGS, ""},
{"getCertsNumber", (PyCFunction)dap_chain_wallet_get_certs_number_py, METH_NOARGS, ""},
{"getPKey", (PyCFunction)dap_chain_wallet_get_pkey_py, METH_VARARGS, ""},
{"getKey", (PyCFunction)dap_chain_wallet_get_key_py, METH_VARARGS, ""},
{NULL, NULL, 0, NULL}
};
......@@ -94,7 +97,7 @@ static PyTypeObject DapChainWallet_dapChainWalletType = {
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew, /* tp_new */
dap_chain_wallet_create_py,/* tp_new */
0, /* tp_free */
0, /* tp_is_gc*/
0, /* tp_bases*/
......
......@@ -37,6 +37,24 @@ PyObject *dap_chain_wallet_create_with_seed_py(PyObject *self, PyObject *argv){
seed_size);
return Py_BuildValue("(O)", obj_wallet);
}
PyObject *dap_chain_wallet_create_py(PyTypeObject *type, PyObject *argv, PyObject *kwds){
(void)kwds;
PyDapChainWalletObject *self;
const char *wallet_name;
const char *path_wallets;
PyObject *obj_sign_type;
if (!PyArg_ParseTuple(argv, "ssO", &wallet_name, &path_wallets, &obj_sign_type))
return NULL;
self = (PyDapChainWalletObject*)type->tp_alloc(type, 0);
if (self != NULL){
self->wallet = dap_chain_wallet_create(wallet_name, path_wallets, *((PyDapSignTypeObject*)obj_sign_type)->sign_type);
if (self->wallet == NULL){
Py_XDECREF(self);
return NULL;
}
}
return (PyObject*)self;
}
PyObject *dap_chain_wallet_open_file_py(PyObject *self, PyObject *argv){
(void)self;
const char *file_path;
......@@ -69,7 +87,16 @@ void dap_chain_wallet_close_py(PyDapChainWalletObject *self){
PyObject *dap_cert_to_addr_py(PyObject *self, PyObject *argv){
(void)self;
return NULL;
PyObject *obj_cert;
PyObject *obj_net_id;
if (!PyArg_ParseTuple(argv, "OO", &obj_cert, &obj_net_id))
return NULL;
PyObject *obj_addr = _PyObject_New(&DapChainAddrObject_DapChainAddrObjectType);
((PyDapChainAddrObject*)obj_addr)->addr = dap_cert_to_addr(
((PyCryptoCertObject*)obj_cert)->cert,
((PyDapChainNetIdObject*)obj_net_id)->net_id
);
return Py_BuildValue("(O)", obj_addr);
}
PyObject *dap_chain_wallet_get_addr_py(PyObject *self, PyObject *argv){
......@@ -88,6 +115,15 @@ PyObject *dap_chain_wallet_get_certs_number_py(PyObject *self, PyObject *argv){
size_t result = dap_chain_wallet_get_certs_number(((PyDapChainWalletObject*)self)->wallet);
return PyLong_FromLong(result);
}
PyObject *dap_chain_wallet_get_pkey_py(PyObject *self, PyObject *argv){
uint32_t key_idx;
if (!PyArg_ParseTuple(argv, "I", &key_idx))
return NULL;
PyObject *obj_pkey = _PyObject_New(&DapPkeyObject_DapPkeyObjectType);
((PyDapPkeyObject*)obj_pkey)->pkey = dap_chain_wallet_get_pkey(((PyDapChainWalletObject*)self)->wallet,
key_idx);
return Py_BuildValue("(O)", obj_pkey);
}
PyObject *dap_chain_wallet_get_key_py(PyObject *self, PyObject *argv){
uint32_t key_idx;
if (!PyArg_ParseTuple(argv, "I", &key_idx))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment