Address decoding

This commit is contained in:
lucas
2014-05-17 16:40:59 +01:00
parent 61e0c967ea
commit a641070b9d
10 changed files with 2133 additions and 3 deletions
+25 -2
View File
@@ -9,6 +9,7 @@
#include "cryptonote_protocol/blobdatatype.h"
#include "crypto/crypto.h"
#include "crypto/hash.h"
#include "common/base58.h"
using namespace node;
using namespace v8;
@@ -46,9 +47,31 @@ Handle<Value> convert_blob(const Arguments& args) {
return scope.Close(buff->handle_);
}
Handle<Value> address_decode(const Arguments& args) {
HandleScope scope;
if (args.Length() < 1)
return except("You must provide one argument.");
Local<Object> target = args[0]->ToObject();
if (!Buffer::HasInstance(target))
return except("Argument should be a buffer object.");
blobdata input = std::string(Buffer::Data(target), Buffer::Length(target));
blobdata output = "";
uint64_t prefix;
tools::base58::decode_addr(input, prefix, output);
Buffer* buff = Buffer::New(output.data(), output.size());
return scope.Close(buff->handle_);
}
void init(Handle<Object> exports) {
exports->Set(String::NewSymbol("convert_blob"),
FunctionTemplate::New(convert_blob)->GetFunction());
exports->Set(String::NewSymbol("convert_blob"), FunctionTemplate::New(convert_blob)->GetFunction());
exports->Set(String::NewSymbol("address_decode"), FunctionTemplate::New(address_decode)->GetFunction());
}
NODE_MODULE(cryptonote, init)