From 40dca54613dfc15da9c1acf760ce6c6fbef27ebe Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 2 Oct 2014 13:07:28 -0700 Subject: [PATCH] refactor. --- src/bitcoindjs.cc | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index ac73727f..f07d7a5b 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -2677,7 +2677,22 @@ jsblock_to_cblock(const Local obj, CBlock& block) { std::string mhash_ = *mhash__; if (mhash_[1] != 'x') mhash_ = "0x" + mhash_; uint256 mhash(mhash_); + block->hashMerkleRoot = mhash; + block->nTime = (unsigned int)obj->Get(NanNew("time"))->IntegerValue(); + block->nNonce = (unsigned int)obj->Get(NanNew("nonce"))->IntegerValue(); + block->nBits = (unsigned int)obj->Get(NanNew("bits"))->IntegerValue(); + + if (obj->Get(NanNew("previousblockhash"))->IsString()) { + String::AsciiValue hash__(obj->Get(NanNew("previousblockhash"))->ToString()); + std::string hash_ = *hash__; + if (hash_[1] != 'x') hash_ = "0x" + hash_; + uint256 hash(hash_); + block->hashPrevBlock = hash; + } else { + uint256 hash(std::string("0000000000000000000000000000000000000000000000000000000000000000")); + block->hashPrevBlock = hash; + } Local txs = Local::Cast(obj->Get("tx")); for (int ti = 0; ti < txs->Length(); ti++) { @@ -2736,23 +2751,9 @@ jsblock_to_cblock(const Local obj, CBlock& block) { tx.vout.push_back(txout); } + block->vtx.push_back(tx); } - - block->nTime = (unsigned int)obj->Get(NanNew("time"))->IntegerValue(); - block->nNonce = (unsigned int)obj->Get(NanNew("nonce"))->IntegerValue(); - block->nBits = (unsigned int)obj->Get(NanNew("bits"))->IntegerValue(); - - if (obj->Get(NanNew("previousblockhash"))->IsString()) { - String::AsciiValue hash__(obj->Get(NanNew("previousblockhash"))->ToString()); - std::string hash_ = *hash__; - if (hash_[1] != 'x') hash_ = "0x" + hash_; - uint256 hash(hash_); - block->hashPrevBlock = hash; - } else { - uint256 hash(std::string("0000000000000000000000000000000000000000000000000000000000000000")); - block->hashPrevBlock = hash; - } } static inline void