bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secretKey, std::string strTxHash, std::string strOutputIndex) { CScript pubScript; // Find possible candidates vector<COutput> possibleCoins = SelectCoinsMasternode(); COutput *selectedOutput; // Find the vin if(!strTxHash.empty()) { // Let's find it uint256 txHash(strTxHash); int outputIndex = boost::lexical_cast<int>(strOutputIndex); bool found = false; BOOST_FOREACH(COutput& out, possibleCoins) { if(out.tx->GetHash() == txHash && out.i == outputIndex) { selectedOutput = &out; found = true; break; } } if(!found) { LogPrintf("CActiveMasternode::GetMasterNodeVin - Could not locate valid vin\n"); return false; } } else {
bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secretKey, std::string strTxHash, std::string strOutputIndex) { // Find possible candidates TRY_LOCK(pwalletMain->cs_wallet, fWallet); if (!fWallet) return false; vector<COutput> possibleCoins = SelectCoinsMasternode(); COutput* selectedOutput; // Find the vin if (!strTxHash.empty()) { // Let's find it uint256 txHash(strTxHash); int outputIndex; try { outputIndex = std::stoi(strOutputIndex.c_str()); } catch (const std::exception& e) { LogPrintf("%s: %s on strOutputIndex\n", __func__, e.what()); return false; } bool found = false; BOOST_FOREACH (COutput& out, possibleCoins) { if (out.tx->GetHash() == txHash && out.i == outputIndex) { selectedOutput = &out; found = true; break; } } if (!found) { LogPrintf("CActiveMasternode::GetMasterNodeVin - Could not locate valid vin\n"); return false; } } else {
shared_ptr<Payload> BitcoinP2P::getTx( const InvEntry& entry, uint32_t timeout) { //blocks until data is received or timeout expires if (entry.invtype_ != Inv_Msg_Tx && entry.invtype_ != Inv_Msg_Witness_Tx) throw GetDataException("entry type isnt Inv_Msg_Tx"); BinaryDataRef txHash(entry.hash, 32); shared_ptr<GetDataStatus> gdsPtr = nullptr; //check if we already have a callback registered for this hash { { auto getTxCallBackMap = getTxCallbackMap_.get(); auto iter = getTxCallBackMap->find(txHash); if (iter != getTxCallBackMap->end()) { gdsPtr = iter->second; auto fut = gdsPtr->getFuture(); if (fut.wait_for(chrono::seconds(0)) == future_status::ready) { return fut.get(); } } } } bool createCallback = false; if (gdsPtr == nullptr) createCallback = true; if (createCallback) { gdsPtr = make_shared<GetDataStatus>(); //register callback registerGetTxCallback(txHash, gdsPtr); } shared_ptr<Payload> payloadPtr = nullptr; auto fut = gdsPtr->getFuture(); //timeout is in sec, let's make it ms auto timeoutMS = timeout * 1000; unsigned timeIncrement = 200; //poll node every 200ms chrono::milliseconds chronoIncrement(timeIncrement); unsigned timeTally = 0; while (1) { //send message Payload_GetData payload(entry); sendMessage(move(payload)); //wait on promise auto&& status = fut.wait_for(chronoIncrement); if (status == future_status::ready) { payloadPtr = fut.get(); break; } timeTally += timeIncrement; if (timeout > 0) { if (timeTally > timeoutMS) { gdsPtr->setStatus(false); break; } } } if (createCallback) unregisterGetTxCallback(txHash); return payloadPtr; }