From 0fbca8094ef83426e5731d8ecec49bbaff53a60b Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Fri, 17 Jul 2015 21:32:38 -0400 Subject: [PATCH] Added comments to getMempoolOutputs --- src/bitcoindjs.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 9dfffd2e..78ccd507 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -993,9 +993,13 @@ NAN_METHOD(GetMempoolOutputs) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); + // Instatiate an empty array that we will fill later + // with matching outputs. Local outputs = Array::New(isolate); int arrayIndex = 0; + // Decode the input address into the hash bytes + // that we can then match to the scriptPubKeys data v8::String::Utf8Value param1(args[0]->ToString()); std::string *input = new std::string(*param1); const char* psz = input->c_str(); @@ -1003,16 +1007,18 @@ NAN_METHOD(GetMempoolOutputs) { DecodeBase58(psz, vAddress); vector hashBytes(vAddress.begin()+1, vAddress.begin()+21); + // Iterate through the entire mempool std::map mapTx = mempool.mapTx; for(std::map::iterator it = mapTx.begin(); it != mapTx.end(); it++) { + uint256 txid = it->first; CTxMemPoolEntry entry = it->second; - const CTransaction tx = entry.GetTx(); int outputIndex = 0; + // Iterate through each output BOOST_FOREACH(const CTxOut& txout, tx.vout) { CScript script = txout.scriptPubKey; @@ -1022,15 +1028,16 @@ NAN_METHOD(GetMempoolOutputs) { if (Solver(script, type, hashResults)) { + // See if the script is any of the standard address types if (type == TX_PUBKEYHASH || type == TX_SCRIPTHASH) { vector scripthashBytes = hashResults.front(); + // Compare the hash bytes with the input hash bytes if(equal(hashBytes.begin(), hashBytes.end(), scripthashBytes.begin())) { Local output = NanNew(); - // todo: include the script output->Set(NanNew("script"), NanNew(script.ToString())); uint64_t satoshis = txout.nValue; @@ -1039,6 +1046,8 @@ NAN_METHOD(GetMempoolOutputs) { output->Set(NanNew("outputIndex"), NanNew(outputIndex)); + // We have a match and push the results to the array + // that is returned as the result outputs->Set(arrayIndex, output); arrayIndex++;