-
Notifications
You must be signed in to change notification settings - Fork 4
/
yespower-module.c
55 lines (48 loc) · 1.25 KB
/
yespower-module.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <Python.h>
static PyObject *yespower_getpowhash(PyObject *self, PyObject *args)
{
char *output;
PyObject *value;
#if PY_MAJOR_VERSION >= 3
PyBytesObject *input;
#else
PyStringObject *input;
#endif
if (!PyArg_ParseTuple(args, "S", &input))
return NULL;
Py_INCREF(input);
output = PyMem_Malloc(32);
#if PY_MAJOR_VERSION >= 3
yespower_hash((char *)PyBytes_AsString((PyObject*) input), output);
#else
yespower_hash((char *)PyString_AsString((PyObject*) input), output);
#endif
Py_DECREF(input);
#if PY_MAJOR_VERSION >= 3
value = Py_BuildValue("y#", output, 32);
#else
value = Py_BuildValue("s#", output, 32);
#endif
PyMem_Free(output);
return value;
}
static PyMethodDef YespowerMethods[] = {
{ "getPoWHash", yespower_getpowhash, METH_VARARGS, "Returns the proof of work hash using yespower" },
{ NULL, NULL, 0, NULL }
};
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef YespowerModule = {
PyModuleDef_HEAD_INIT,
"yespower_hash",
"...",
-1,
YespowerMethods
};
PyMODINIT_FUNC PyInit_crp_yespower_1_0(void) {
return PyModule_Create(&YespowerModule);
}
#else
PyMODINIT_FUNC initcrp_yespower_1_0(void) {
(void) Py_InitModule("crp_yespower_1_0", YespowerMethods);
}
#endif