From 27a137022c22a810ce429cd121e5d79949c8e63d Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 25 Sep 2014 15:33:37 -0700 Subject: [PATCH] remove unused conversions. --- src/bitcoindjs.cc | 149 ---------------------------------------------- 1 file changed, 149 deletions(-) diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 30607565..8b283393 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -1299,155 +1299,6 @@ ctx_to_js(const CTransaction& tx, uint256 hashBlock, Local entry) { } } -#if 0 -static inline void -hex_to_ctx(string strHex, const CTransaction& tx) { - CDataStream stream(ParseHex(strHex), SER_NETWORK, PROTOCOL_VERSION); - // CTransaction tx; - stream >> tx; -} - -static inline void -js_to_ctx(Local entry, const CTransaction& tx, uint256 hashBlock) { - String::Utf8Value tx_hex_(entry->Get(NanNew("hex"))->ToString()); - std::string tx_hex = std::string(*txHex_); - if (tx_hex[1] != 'x') { - tx_hex = "0x" + tx_hex; - } - // std::string tx_hex = data->tx_hex; - // uint256 hash(tx_hex); - std::string strHex(tx_hex); - // CTransaction tx; - hex_to_ctx(strHex, tx); -} - -static inline void -js_to_ctx(Local entry, const CTransaction& tx, uint256 hashBlock) { - // 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(txout.nValue)); - out->Set(NanNew("n"), NanNew((boost::int64_t)vo)); - - 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)); - } - } - } - - - - CTransaction rawTx; - - BOOST_FOREACH(const Value& input, inputs) { - const Object& o = input.get_obj(); - - uint256 txid = ParseHashO(o, "txid"); - - const Value& vout_v = find_value(o, "vout"); - if (vout_v.type() != int_type) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key"); - int nOutput = vout_v.get_int(); - if (nOutput < 0) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive"); - - CTxIn in(COutPoint(txid, nOutput)); - rawTx.vin.push_back(in); - } - - set setAddress; - BOOST_FOREACH(const Pair& s, sendTo) { - CBitcoinAddress address(s.name_); - if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Bitcoin address: ")+s.name_); - - if (setAddress.count(address)) - throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+s.name_); - setAddress.insert(address); - - CScript scriptPubKey; - scriptPubKey.SetDestination(address.Get()); - int64_t nAmount = AmountFromValue(s.value_); - - CTxOut out(nAmount, scriptPubKey); - rawTx.vout.push_back(out); - } - - CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); - ss << rawTx; - return HexStr(ss.begin(), ss.end()); -} -#endif - /** * Init */