From 7d0c31363d4c9ac3e07b0655901bca1ee0c76cc4 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 19 Sep 2014 15:42:30 -0700 Subject: [PATCH] major GetBlock cleanup. --- lib/bitcoind.js | 4 --- src/bitcoindjs.cc | 63 ----------------------------------------------- 2 files changed, 67 deletions(-) diff --git a/lib/bitcoind.js b/lib/bitcoind.js index bed25b12..3afdfa37 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -121,10 +121,6 @@ Bitcoin.prototype.start = function(callback) { Bitcoin.prototype.getBlock = function(hash, callback) { return bitcoindjs.getBlock(hash, callback); - return bitcoindjs.getBlock(hash, function(err, block) { - if (err) return callback(err) - return callback(null, JSON.parse(block)); - }); }; Bitcoin.prototype.log = diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 4d421c0e..e6bbd98f 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -77,13 +77,6 @@ #include "threadsafety.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 * Relevant: @@ -184,9 +177,6 @@ async_get_block(uv_work_t *req); static void async_get_block_after(uv_work_t *req); -Local -block_to_obj(const CBlock& block, const CBlockIndex* blockindex); - extern "C" void init(Handle); @@ -199,8 +189,6 @@ static volatile bool shutdownComplete = false; struct async_block_data { std::string hash; std::string err_msg; - std::string result; - Local result_obj; CBlock result_block; CBlockIndex* result_blockindex; Persistent callback; @@ -693,11 +681,9 @@ NAN_METHOD(GetBlock) { Local callback = Local::Cast(args[1]); std::string hashp = std::string(*hash); - //char *hashc = (char *)hashp.c_str(); async_block_data *data = new async_block_data(); data->err_msg = std::string(""); - data->result = std::string(""); data->hash = hashp; data->callback = Persistent::New(callback); @@ -724,14 +710,6 @@ async_get_block(uv_work_t *req) { CBlock block; CBlockIndex* pblockindex = mapBlockIndex[hash]; if (ReadBlockFromDisk(block, pblockindex)) { -#if 0 - 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"; - data->result = out; -#endif - //Local out = block_to_obj(block, pblockindex); - //data->result_obj = out; data->result_block = block; data->result_blockindex = pblockindex; } else { @@ -877,9 +855,6 @@ async_get_block_after(uv_work_t *req) { const unsigned argc = 2; Local argv[argc] = { Local::New(Null()), - //Local::New(NanNew("")) - //Local::New(NanNew(data->result)) - //Local::New(data->result_obj) Local::New(obj) }; TryCatch try_catch; @@ -895,44 +870,6 @@ async_get_block_after(uv_work_t *req) { delete req; } -Local -block_to_obj(const CBlock& block, const CBlockIndex* blockindex) { - Local obj = NanNew(); - obj->Set(NanNew("hash"), NanNew(block.GetHash().GetHex().c_str())); - CMerkleTx txGen(block.vtx[0]); - txGen.SetMerkleBranch(&block); - obj->Set(NanNew("confirmations"), NanNew((int)txGen.GetDepthInMainChain())); - obj->Set(NanNew("size"), NanNew((int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION))); - return obj; - -#if 0 - Object result; - result.push_back(Pair("hash", block.GetHash().GetHex())); - CMerkleTx txGen(block.vtx[0]); - txGen.SetMerkleBranch(&block); - result.push_back(Pair("confirmations", (int)txGen.GetDepthInMainChain())); - result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION))); - result.push_back(Pair("height", blockindex->nHeight)); - result.push_back(Pair("version", block.nVersion)); - result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex())); - Array txs; - BOOST_FOREACH(const CTransaction&tx, block.vtx) - txs.push_back(tx.GetHash().GetHex()); - result.push_back(Pair("tx", txs)); - result.push_back(Pair("time", (boost::int64_t)block.GetBlockTime())); - result.push_back(Pair("nonce", (boost::uint64_t)block.nNonce)); - result.push_back(Pair("bits", HexBits(block.nBits))); - result.push_back(Pair("difficulty", GetDifficulty(blockindex))); - result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex())); - if (blockindex->pprev) - result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex())); - CBlockIndex *pnext = chainActive.Next(blockindex); - if (pnext) - result.push_back(Pair("nextblockhash", pnext->GetBlockHash().GetHex())); - return result; -#endif -} - /** * Init */