From f69c49aba1e9ea779c65a6745685366b53ce8a85 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 22 Sep 2014 13:22:01 -0700 Subject: [PATCH] remove synchronous GetTx. --- src/bitcoindjs.cc | 160 +--------------------------------------------- 1 file changed, 1 insertion(+), 159 deletions(-) diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index f61e2b00..47a47626 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -903,164 +903,6 @@ async_get_block_after(uv_work_t *req) { * bitcoind.getTx(hash, callback) */ -// Synchronous: - -#if 0 -NAN_METHOD(GetTx) { - NanScope(); - - if (args.Length() < 2 - || !args[0]->IsString() - || !args[1]->IsString() - || !args[2]->IsFunction()) { - return NanThrowError( - "Usage: bitcoindjs.getTx(txHash, [blockHash], callback)"); - } - - String::Utf8Value txHash_(args[0]->ToString()); - String::Utf8Value blockHash_(args[1]->ToString()); - Local callback = Local::Cast(args[2]); - - Persistent cb; - cb = Persistent::New(callback); - - std::string txHash = std::string(*txHash_); - std::string blockHash = std::string(*blockHash_); - - bool noBlockHash = false; - if (blockHash.empty()) { - blockHash = std::string("0x0000000000000000000000000000000000000000000000000000000000000000"); - noBlockHash = true; - } - - if (txHash[1] != 'x') { - txHash = "0x" + txHash; - } - - if (blockHash[1] != 'x') { - blockHash = "0x" + blockHash; - } - - uint256 hash(txHash); - uint256 hashBlock(blockHash); - CTransaction tx; - - if (!GetTransaction(hash, tx, hashBlock, noBlockHash ? true : false)) { - Local err = Exception::Error(String::New("Bad Transaction.")); - const unsigned argc = 1; - Local argv[argc] = { err }; - TryCatch try_catch; - cb->Call(Context::GetCurrent()->Global(), argc, argv); - if (try_catch.HasCaught()) { - node::FatalException(try_catch); - } - cb.Dispose(); - NanReturnValue(Undefined()); - } else { - CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); - ssTx << tx; - string strHex = HexStr(ssTx.begin(), ssTx.end()); - - Local entry = NanNew(); - entry->Set(NanNew("hex"), NanNew(strHex)); - entry->Set(NanNew("txid"), NanNew(tx.GetHash().GetHex())); - entry->Set(NanNew("version"), NanNew(tx.nVersion)); - entry->Set(NanNew("locktime"), NanNew(tx.nLockTime)); - - Local vin = NanNew(); - int vi = 0; - BOOST_FOREACH(const CTxIn& txin, tx.vin) { - Local in = NanNew(); - if (tx.IsCoinBase()) { - in->Set(NanNew("coinbase"), NanNew(HexStr(txin.scriptSig.begin(), txin.scriptSig.end()))); - } else { - in->Set(NanNew("txid"), NanNew(txin.prevout.hash.GetHex())); - in->Set(NanNew("vout"), NanNew((boost::int64_t)txin.prevout.n)); - Local o = NanNew(); - o->Set(NanNew("asm"), NanNew(txin.scriptSig.ToString())); - o->Set(NanNew("hex"), NanNew(HexStr(txin.scriptSig.begin(), txin.scriptSig.end()))); - in->Set(NanNew("scriptSig"), o); - } - in->Set(NanNew("sequence"), NanNew((boost::int64_t)txin.nSequence)); - vin->Set(vi, in); - vi++; - } - entry->Set(NanNew("vin"), vin); - - Local vout = NanNew(); - for (unsigned int vo = 0; vo < tx.vout.size(); vo++) { - const CTxOut& txout = tx.vout[vo]; - Local out = NanNew(); - //out->Set(NanNew("value"), NanNew(ValueFromAmount(txout.nValue))); - out->Set(NanNew("value"), NanNew(txout.nValue)); - out->Set(NanNew("n"), NanNew((boost::int64_t)vo)); - - // ScriptPubKeyToJSON(txout.scriptPubKey, o, true); - Local o = NanNew(); - { - const CScript& scriptPubKey = txout.scriptPubKey; - Local out = o; - bool fIncludeHex = true; - // --- - txnouttype type; - vector addresses; - int nRequired; - out->Set(NanNew("asm"), NanNew(scriptPubKey.ToString())); - if (fIncludeHex) { - out->Set(NanNew("hex"), NanNew(HexStr(scriptPubKey.begin(), scriptPubKey.end()))); - } - if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired)) { - out->Set(NanNew("type"), NanNew(GetTxnOutputType(type))); - } else { - out->Set(NanNew("reqSigs"), NanNew(nRequired)); - out->Set(NanNew("type"), NanNew(GetTxnOutputType(type))); - Local a = NanNew(); - int ai = 0; - BOOST_FOREACH(const CTxDestination& addr, addresses) { - a->Set(ai, NanNew(CBitcoinAddress(addr).ToString())); - ai++; - } - out->Set(NanNew("addresses"), a); - } - } - out->Set(NanNew("scriptPubKey"), o); - - vout->Set(vo, out); - } - entry->Set(NanNew("vout"), vout); - - if (hashBlock != 0) { - entry->Set(NanNew("blockhash"), NanNew(hashBlock.GetHex())); - map::iterator mi = mapBlockIndex.find(hashBlock); - if (mi != mapBlockIndex.end() && (*mi).second) { - CBlockIndex* pindex = (*mi).second; - if (chainActive.Contains(pindex)) { - entry->Set(NanNew("confirmations"), - NanNew(1 + chainActive.Height() - pindex->nHeight)); - entry->Set(NanNew("time"), NanNew((boost::int64_t)pindex->nTime)); - entry->Set(NanNew("blocktime"), NanNew((boost::int64_t)pindex->nTime)); - } else { - entry->Set(NanNew("confirmations"), NanNew(0)); - } - } - } - - const unsigned argc = 2; - Local argv[argc] = { - Local::New(Null()), - Local::New(entry) - }; - TryCatch try_catch; - cb->Call(Context::GetCurrent()->Global(), argc, argv); - if (try_catch.HasCaught()) { - node::FatalException(try_catch); - } - cb.Dispose(); - NanReturnValue(Undefined()); - } -} -#endif - NAN_METHOD(GetTx) { NanScope(); @@ -1123,7 +965,7 @@ async_get_tx(uv_work_t *req) { if (GetTransaction(hash, tx, hashBlock, hashBlock == 0 ? true : false)) { data->result_tx = tx; } else { - data->err_msg = std::string("get_block(): failed."); + data->err_msg = std::string("get_tx(): failed."); } }