From df37ae6be10a2b6a51f1bebd33c41494fe8d4988 Mon Sep 17 00:00:00 2001
From: "alexey.stratulat" <alexey.stratulat@demlabs.net>
Date: Mon, 20 Apr 2020 22:36:10 +0700
Subject: [PATCH] [+] Added functions createWithSeed, getAddr, getKey in
 ChainWallet object.

---
 include/dap_chain_wallet_python.h |  8 +++++-
 src/dap_chain_wallet_python.c     | 41 +++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/include/dap_chain_wallet_python.h b/include/dap_chain_wallet_python.h
index be59c12..8dffa4d 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 22a1cfd..f9712b2 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);
+}
-- 
GitLab