working getBlock
This commit is contained in:
parent
5fd1f8614b
commit
44bb54842f
@ -9,6 +9,10 @@ bitcoind.start(function(err) {
|
|||||||
console.log('bitcoind: error="%s"', err.message);
|
console.log('bitcoind: error="%s"', err.message);
|
||||||
});
|
});
|
||||||
bitcoind.on('open', function(status) {
|
bitcoind.on('open', function(status) {
|
||||||
|
setTimeout(function() {
|
||||||
|
var block = bitcoind.getBlock(0);
|
||||||
|
console.log(block);
|
||||||
|
}, 1000);
|
||||||
console.log('bitcoind: status="%s"', status);
|
console.log('bitcoind: status="%s"', status);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -119,6 +119,10 @@ Bitcoin.prototype.start = function(callback) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Bitcoin.prototype.getBlock = function(hash) {
|
||||||
|
return JSON.parse(bitcoindjs.getBlock(hash));
|
||||||
|
};
|
||||||
|
|
||||||
Bitcoin.prototype.log =
|
Bitcoin.prototype.log =
|
||||||
Bitcoin.prototype.info = function() {
|
Bitcoin.prototype.info = function() {
|
||||||
if (typeof arguments[0] !== 'string') {
|
if (typeof arguments[0] !== 'string') {
|
||||||
|
|||||||
@ -77,6 +77,12 @@
|
|||||||
#include "threadsafety.h"
|
#include "threadsafety.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
|
#include "json/json_spirit_value.h"
|
||||||
|
|
||||||
|
// using namespace json_spirit;
|
||||||
|
|
||||||
|
extern json_spirit::Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bitcoin Globals
|
* Bitcoin Globals
|
||||||
* Relevant:
|
* Relevant:
|
||||||
@ -345,6 +351,19 @@ NAN_METHOD(IsStopped) {
|
|||||||
|
|
||||||
NAN_METHOD(GetBlock) {
|
NAN_METHOD(GetBlock) {
|
||||||
NanScope();
|
NanScope();
|
||||||
|
std::string strHash = "0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f";
|
||||||
|
uint256 hash(strHash);
|
||||||
|
CBlock block;
|
||||||
|
CBlockIndex* pblockindex = mapBlockIndex[hash];
|
||||||
|
ReadBlockFromDisk(block, pblockindex);
|
||||||
|
json_spirit::Object result = blockToJSON(block, pblockindex);
|
||||||
|
json_spirit::Object rpc_result = JSONRPCReplyObj(result, json_spirit::Value::null, 0);
|
||||||
|
std::string out = json_spirit::write_string(json_spirit::Value(rpc_result), false) + "\n";
|
||||||
|
// https://www.google.com/search?q=json.parse%20in%20v8%20c%2B%2B
|
||||||
|
// https://v8.googlecode.com/svn/trunk/src/json-parser.h
|
||||||
|
// NanReturnValue(NanNew<Object>(v8::ParseJsonValue(NanNew<String>(out))));
|
||||||
|
NanReturnValue(NanNew<String>(out));
|
||||||
|
#if 0
|
||||||
int nHeight = 0;
|
int nHeight = 0;
|
||||||
CBlockIndex *pindex = chainActive[nHeight];
|
CBlockIndex *pindex = chainActive[nHeight];
|
||||||
CBlock block;
|
CBlock block;
|
||||||
@ -356,9 +375,11 @@ NAN_METHOD(GetBlock) {
|
|||||||
// return true;
|
// return true;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// NanReturnValue(NanNew<String>(""));
|
blockToJSON(block);
|
||||||
|
NanReturnValue(NanNew<String>(block.ToString()));
|
||||||
}
|
}
|
||||||
NanReturnValue(NanNew<Boolean>(false));
|
NanReturnValue(NanNew<Boolean>(false));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user