Initial efforts to make bitmsghash a valid python extension
This commit is contained in:
parent
450839079c
commit
794cf2657c
|
@ -19,6 +19,9 @@
|
|||
|
||||
#include "openssl/sha.h"
|
||||
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#include <Python.h>
|
||||
|
||||
#define HASH_SIZE 64
|
||||
#define BUFLEN 16384
|
||||
|
||||
|
@ -164,3 +167,37 @@ extern "C" EXPORT unsigned long long BitmessagePOW(unsigned char * starthash, un
|
|||
free(threaddata);
|
||||
return successval;
|
||||
}
|
||||
|
||||
// python module definitions
|
||||
static PyObject *
|
||||
bitmessage_pow(PyObject *self, PyObject *args)
|
||||
{
|
||||
const char *initial_hash;
|
||||
unsigned long long target;
|
||||
unsigned long long nonce;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "yK", &initial_hash, target))
|
||||
return NULL;
|
||||
nonce = BitmessagePOW((unsigned char *)initial_hash, target);
|
||||
return PyLong_FromUnsignedLongLong(nonce);
|
||||
};
|
||||
|
||||
static PyMethodDef BitmsghashMethods[] = {
|
||||
{"bitmessage_pow", bitmessage_pow, METH_VARARGS,
|
||||
"Do the Bitmessage PoW and return nonce."},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
static struct PyModuleDef bitmsghashmodule = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"bitmsghash",
|
||||
"A C extension for PoW borrowed from PyBitmessage",
|
||||
-1,
|
||||
BitmsghashMethods
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC
|
||||
PyInit_bitmsghash(void)
|
||||
{
|
||||
return PyModule_Create(&bitmsghashmodule);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user