这篇教程C++ GetTransaction函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中GetTransaction函数的典型用法代码示例。如果您正苦于以下问题:C++ GetTransaction函数的具体用法?C++ GetTransaction怎么用?C++ GetTransaction使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了GetTransaction函数的23个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: getTxTotalValuedouble getTxTotalValue(std::string txid){ uint256 hash; hash.SetHex(txid); CTransaction tx; uint256 hashBlock = 0; if (!GetTransaction(hash, tx, hashBlock)) return 1000; CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << tx; double value = 0; double buffer = 0; for (unsigned int i = 0; i < tx.vout.size(); i++) { const CTxOut& txout = tx.vout[i]; buffer = value + convertCoins(txout.nValue); value = buffer; } return value;}
开发者ID:cryptodeveloper,项目名称:Transfercoin,代码行数:25,
示例2: getOutputsstd::string getOutputs(std::string txid){ uint256 hash; hash.SetHex(txid); CTransaction tx; uint256 hashBlock = 0; if (!GetTransaction(hash, tx, hashBlock)) return "fail"; CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << tx; std::string str = ""; for (unsigned int i = 0; i < tx.vout.size(); i++) { const CTxOut& txout = tx.vout[i]; CTxDestination source; ExtractDestination(txout.scriptPubKey, source); CBitcoinAddress addressSource(source); std::string lol7 = addressSource.ToString(); double buffer = convertCoins(txout.nValue); std::ostringstream ss; ss << std::fixed << std::setprecision(4) << buffer; std::string amount = ss.str(); str.append(lol7); str.append(": "); str.append(amount); str.append(" TX"); str.append("/n"); } return str;}
开发者ID:cryptodeveloper,项目名称:Transfercoin,代码行数:34,
示例3: on_transactionId_textChangedvoid MultisigInputEntry::on_transactionId_textChanged(const QString &transactionId){ ui->transactionOutput->clear(); if(transactionId.isEmpty()) return; // Make list of transaction outputs txHash.SetHex(transactionId.toStdString().c_str()); CTransaction tx; uint256 blockHash = 0; if(!GetTransaction(txHash, tx, blockHash)) return; for(unsigned int i = 0; i < tx.vout.size(); i++) { QString idStr; idStr.setNum(i); const CTxOut& txOut = tx.vout[i]; int64_t amount = txOut.nValue; QString amountStr; amountStr.sprintf("%.6f", (double) amount / COIN); CScript script = txOut.scriptPubKey; CTxDestination addr; if(ExtractDestination(script, addr)) { CBitcoinAddress address(addr); QString addressStr(address.ToString().c_str()); ui->transactionOutput->addItem(idStr + QString(" - ") + addressStr + QString(" - ") + amountStr + QString(" MPRO")); } else ui->transactionOutput->addItem(idStr + QString(" - ") + amountStr + QString(" MPRO")); }}
开发者ID:MEDIUMPROJECT,项目名称:MEDIUM,代码行数:32,
示例4: getPrevOutCTxOut getPrevOut(const COutPoint& out){ CTransaction tx; uint256 hashBlock; if (GetTransaction(out.hash, tx, hashBlock, true)) return tx.vout[out.n]; return CTxOut();}
开发者ID:michaili,项目名称:PIVX,代码行数:8,
示例5: getInputsstd::string getInputs(std::string txid) { uint256 hash; hash.SetHex(txid); CTransaction tx; uint256 hashBlock = 0; if (!GetTransaction(hash, tx, hashBlock)) { return "fail"; } CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << tx; std::string str = ""; for (unsigned int i = 0; i < tx.vin.size(); i++) { uint256 hash; const CTxIn& vin = tx.vin[i]; hash.SetHex(vin.prevout.hash.ToString()); CTransaction wtxPrev; uint256 hashBlock = 0; if (!GetTransaction(hash, wtxPrev, hashBlock)) { return "fail"; } CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << wtxPrev; CTxDestination source; ExtractDestination(wtxPrev.vout[vin.prevout.n].scriptPubKey, source); CBitcoinAddress addressSource(source); std::string lol6 = addressSource.ToString(); const CScript target = wtxPrev.vout[vin.prevout.n].scriptPubKey; double buffer = convertCoins(getInputValue(wtxPrev, target)); std::string amount = boost::to_string(buffer); str.append(lol6); str.append(": "); str.append(amount); str.append("SHADE"); str.append("/n"); } return str;}
开发者ID:EarlyClues,项目名称:Shade,代码行数:46,
示例6: getTxFeesdouble getTxFees(std::string txid){ uint256 hash; hash.SetHex(txid); CTransaction tx; uint256 hashBlock = 0; if (!GetTransaction(hash, tx, hashBlock)) return 0.0001; CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << tx; double value = 0; double buffer = 0; for (unsigned int i = 0; i < tx.vout.size(); i++) { const CTxOut& txout = tx.vout[i]; buffer = value + convertCoins(txout.nValue); value = buffer; } double value0 = 0; double buffer0 = 0; double swp=0; for (unsigned int i = 0; i < tx.vin.size(); i++) { uint256 hash0; const CTxIn& vin = tx.vin[i]; hash0.SetHex(vin.prevout.hash.ToString()); CTransaction wtxPrev; uint256 hashBlock0 = 0; if (!GetTransaction(hash0, wtxPrev, hashBlock0)) return 0; CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << wtxPrev; const CScript target = wtxPrev.vout[vin.prevout.n].scriptPubKey; swp =convertCoins(getInputValue(wtxPrev, target)); buffer0 = value0 + convertCoins(getInputValue(wtxPrev, target)); value0 = buffer0; } return value0 - value;}
开发者ID:MsCollec,项目名称:Sync2,代码行数:46,
示例7: GetTransactionbool MgServerFeatureTransactionPool::RollbackTransaction(CREFSTRING transactionId){ Ptr<MgServerFeatureTransaction> tran = GetTransaction(transactionId); if (NULL != tran.p) { tran->Rollback(); } return RemoveTransaction(transactionId);}
开发者ID:kanbang,项目名称:Colt,代码行数:10,
示例8: trvoid MultisigDialog::on_sendTransactionButton_clicked(){ int64_t transactionSize = ui->signedTransaction->text().size() / 2; if(transactionSize == 0) return; // Check the fee int64_t fee = (int64_t ) (ui->fee->text().toDouble() * COIN); int64_t minFee = MIN_TX_FEE * (1 + (int64_t) transactionSize / 1000); if(fee < minFee) { QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Confirm send transaction"), tr("The fee of the transaction (%1 XBTC21) is smaller than the expected fee (%2 XBTC21). Do you want to send the transaction anyway?").arg((double) fee / COIN).arg((double) minFee / COIN), QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel); if(ret != QMessageBox::Yes) return; } else if(fee > minFee) { QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Confirm send transaction"), tr("The fee of the transaction (%1 XBTC21) is bigger than the expected fee (%2 XBTC21). Do you want to send the transaction anyway?").arg((double) fee / COIN).arg((double) minFee / COIN), QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel); if(ret != QMessageBox::Yes) return; } // Decode the raw transaction std::vector<unsigned char> txData(ParseHex(ui->signedTransaction->text().toStdString())); CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION); CTransaction tx; try { ssData >> tx; } catch(std::exception &e) { (void)e; return; } uint256 txHash = tx.GetHash(); // Check if the transaction is already in the blockchain CTransaction existingTx; uint256 blockHash = 0; if(GetTransaction(txHash, existingTx, blockHash)) { if(blockHash != 0) return; } // Send the transaction to the local node CTxDB txdb("r"); if(!tx.AcceptToMemoryPool(txdb, false)) return; SyncWithWallets(tx, NULL, true); //(CInv(MSG_TX, txHash), tx); RelayTransaction(tx, txHash);}
开发者ID:Bitcoin21,项目名称:V1.0,代码行数:54,
示例9: MessageGetViaBranchstruct Transaction *MatchRequest(MESSAGE *message){ char *branch = MessageGetViaBranch(message); SIP_METHOD method = MessageGetMethod(message); if (method == SIP_METHOD_CANCEL) { method = SIP_METHOD_INVITE; } char *methodName = MethodMap2String(method); return GetTransaction(branch, methodName);}
开发者ID:yjjfirst,项目名称:x-sip,代码行数:12,
示例10: ValidateTimeoutbool MgServerFeatureTransactionPool::CommitTransaction(CREFSTRING transactionId){ ValidateTimeout(transactionId); Ptr<MgServerFeatureTransaction> tran = GetTransaction(transactionId); if (NULL != tran.p) { tran->Commit(); } return RemoveTransaction(transactionId);}
开发者ID:kanbang,项目名称:Colt,代码行数:12,
示例11: rest_txstatic bool rest_tx(HTTPRequest* req, const std::string& strURIPart){ if (!CheckWarmup(req)) return false; std::string hashStr; const RetFormat rf = ParseDataFormat(hashStr, strURIPart); uint256 hash; if (!ParseHashStr(hashStr, hash)) return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr); if (g_txindex) { g_txindex->BlockUntilSyncedToCurrentChain(); } CTransactionRef tx; uint256 hashBlock = uint256(); if (!GetTransaction(hash, tx, Params().GetConsensus(), hashBlock, true)) return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found"); CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags()); ssTx << tx; switch (rf) { case RetFormat::BINARY: { std::string binaryTx = ssTx.str(); req->WriteHeader("Content-Type", "application/octet-stream"); req->WriteReply(HTTP_OK, binaryTx); return true; } case RetFormat::HEX: { std::string strHex = HexStr(ssTx.begin(), ssTx.end()) + "/n"; req->WriteHeader("Content-Type", "text/plain"); req->WriteReply(HTTP_OK, strHex); return true; } case RetFormat::JSON: { UniValue objTx(UniValue::VOBJ); TxToUniv(*tx, hashBlock, objTx); std::string strJSON = objTx.write() + "/n"; req->WriteHeader("Content-Type", "application/json"); req->WriteReply(HTTP_OK, strJSON); return true; } default: { return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")"); } }}
开发者ID:fujicoin,项目名称:fujicoin,代码行数:52,
示例12: getexplorerBlockHashbool BlockExplorer::switchTo(const QString& query){ bool IsOk; int64_t AsInt = query.toInt(&IsOk); // If query is integer, get hash from height if (IsOk && AsInt >= 0 && AsInt <= chainActive.Tip()->nHeight) { std::string hex = getexplorerBlockHash(AsInt); uint256 hash = uint256S(hex); CBlockIndex* pIndex = mapBlockIndex[hash]; if (pIndex) { setBlock(pIndex); return true; } } // If the query is not an integer, assume it is a block hash uint256 hash = uint256S(query.toUtf8().constData()); // std::map<uint256, CBlockIndex*>::iterator iter = mapBlockIndex.find(hash); BlockMap::iterator iter = mapBlockIndex.find(hash); if (iter != mapBlockIndex.end()) { setBlock(iter->second); return true; } // If the query is neither an integer nor a block hash, assume a transaction hash CTransaction tx; uint256 hashBlock = 0; if (GetTransaction(hash, tx, hashBlock, true)) { setContent(TxToString(hashBlock, tx)); return true; } // If the query is not an integer, nor a block hash, nor a transaction hash, assume an address CBitcoinAddress Address; Address.SetString(query.toUtf8().constData()); if (Address.IsValid()) { std::string Content = AddressToString(Address); if (Content.empty()) return false; setContent(Content); return true; } return false;}
开发者ID:michaili,项目名称:PIVX,代码行数:46,
示例13: getAmountint64 MultisigInputEntry::getAmount(){ int64 amount = 0; int nOutput = ui->transactionOutput->currentIndex(); CTransaction tx; uint256 blockHash = 0; if(GetTransaction(txHash, tx, blockHash)) { if(nOutput < tx.vout.size()) { const CTxOut& txOut = tx.vout[nOutput]; amount = txOut.nValue; } } return amount;}
开发者ID:tomasmartins,项目名称:TRMWallet,代码行数:18,
示例14: on_transactionOutput_currentIndexChangedvoid MultisigInputEntry::on_transactionOutput_currentIndexChanged(int index){ if(ui->transactionOutput->itemText(index).isEmpty()) return; CTransaction tx; uint256 blockHash = 0; if(!GetTransaction(txHash, tx, blockHash)) return; const CTxOut& txOut = tx.vout[index]; CScript script = txOut.scriptPubKey; if(script.IsPayToScriptHash()) { ui->redeemScript->setEnabled(true); if(model) { /* FIXME // Try to find the redeem script CBitcoinAddress dest; if(ExtractAddress(script, dest)) { CScriptID scriptID = boost::get<CScriptID>(dest); CScriptID scriptID; if(dest.GetScriptID(scriptID)) { CScript redeemScript; if(model->getWallet()->GetCScript(scriptID, redeemScript)) ui->redeemScript->setText(HexStr(redeemScript.begin(), redeemScript.end()).c_str()); } } */ } } else { ui->redeemScript->setEnabled(false); } emit updateAmount();}
开发者ID:d5000,项目名称:slimcoin,代码行数:42,
示例15: GetMinCollateralFeebool CGovernanceObject::IsCollateralValid(std::string& strError, bool& fMissingConfirmations) const{ strError = ""; fMissingConfirmations = false; CAmount nMinFee = GetMinCollateralFee(); uint256 nExpectedHash = GetHash(); CTransactionRef txCollateral; uint256 nBlockHash; // RETRIEVE TRANSACTION IN QUESTION if (!GetTransaction(nCollateralHash, txCollateral, Params().GetConsensus(), nBlockHash, true)) { strError = strprintf("Can't find collateral tx %s", nCollateralHash.ToString()); LogPrintf("CGovernanceObject::IsCollateralValid -- %s/n", strError); return false; } if (nBlockHash == uint256()) { strError = strprintf("Collateral tx %s is not mined yet", txCollateral->ToString()); LogPrintf("CGovernanceObject::IsCollateralValid -- %s/n", strError); return false; } if (txCollateral->vout.size() < 1) { strError = strprintf("tx vout size less than 1 | %d", txCollateral->vout.size()); LogPrintf("CGovernanceObject::IsCollateralValid -- %s/n", strError); return false; } // LOOK FOR SPECIALIZED GOVERNANCE SCRIPT (PROOF OF BURN) CScript findScript; findScript << OP_RETURN << ToByteVector(nExpectedHash); LogPrint("gobject", "CGovernanceObject::IsCollateralValid -- txCollateral->vout.size() = %s, findScript = %s, nMinFee = %lld/n", txCollateral->vout.size(), ScriptToAsmStr(findScript, false), nMinFee); bool foundOpReturn = false; for (const auto& output : txCollateral->vout) { LogPrint("gobject", "CGovernanceObject::IsCollateralValid -- txout = %s, output.nValue = %lld, output.scriptPubKey = %s/n", output.ToString(), output.nValue, ScriptToAsmStr(output.scriptPubKey, false)); if (!output.scriptPubKey.IsPayToPublicKeyHash() && !output.scriptPubKey.IsUnspendable()) { strError = strprintf("Invalid Script %s", txCollateral->ToString()); LogPrintf("CGovernanceObject::IsCollateralValid -- %s/n", strError); return false; } if (output.scriptPubKey == findScript && output.nValue >= nMinFee) { foundOpReturn = true; } } if (!foundOpReturn) { strError = strprintf("Couldn't find opReturn %s in %s", nExpectedHash.ToString(), txCollateral->ToString()); LogPrintf("CGovernanceObject::IsCollateralValid -- %s/n", strError); return false; } // GET CONFIRMATIONS FOR TRANSACTION AssertLockHeld(cs_main); int nConfirmationsIn = 0; if (nBlockHash != uint256()) { BlockMap::iterator mi = mapBlockIndex.find(nBlockHash); if (mi != mapBlockIndex.end() && (*mi).second) { CBlockIndex* pindex = (*mi).second; if (chainActive.Contains(pindex)) { nConfirmationsIn += chainActive.Height() - pindex->nHeight + 1; } } } if ((nConfirmationsIn < GOVERNANCE_FEE_CONFIRMATIONS) && (!instantsend.IsLockedInstantSendTransaction(nCollateralHash) || llmq::quorumInstantSendManager->IsLocked(nCollateralHash))) { strError = strprintf("Collateral requires at least %d confirmations to be relayed throughout the network (it has only %d)", GOVERNANCE_FEE_CONFIRMATIONS, nConfirmationsIn); if (nConfirmationsIn >= GOVERNANCE_MIN_RELAY_FEE_CONFIRMATIONS) { fMissingConfirmations = true; strError += ", pre-accepted -- waiting for required confirmations"; } else { strError += ", rejected -- try again later"; } LogPrintf("CGovernanceObject::IsCollateralValid -- %s/n", strError); return false; } strError = "valid"; return true;}
开发者ID:dashpay,项目名称:dash,代码行数:89,
示例16: LOCK2bool CInstantSend::ResolveConflicts(const CTxLockCandidate& txLockCandidate){ LOCK2(cs_main, cs_instantsend); uint256 txHash = txLockCandidate.GetHash(); // make sure the lock is ready if(!txLockCandidate.IsAllOutPointsReady()) return false; AssertLockHeld(mempool.cs); // protect mempool.mapNextTx for (const auto& txin : txLockCandidate.txLockRequest.tx->vin) { uint256 hashConflicting; if(GetLockedOutPointTxHash(txin.prevout, hashConflicting) && txHash != hashConflicting) { // completed lock which conflicts with another completed one? // this means that majority of MNs in the quorum for this specific tx input are malicious! std::map<uint256, CTxLockCandidate>::iterator itLockCandidate = mapTxLockCandidates.find(txHash); std::map<uint256, CTxLockCandidate>::iterator itLockCandidateConflicting = mapTxLockCandidates.find(hashConflicting); if(itLockCandidate == mapTxLockCandidates.end() || itLockCandidateConflicting == mapTxLockCandidates.end()) { // safety check, should never really happen LogPrintf("CInstantSend::ResolveConflicts -- ERROR: Found conflicting completed Transaction Lock, but one of txLockCandidate-s is missing, txid=%s, conflicting txid=%s/n", txHash.ToString(), hashConflicting.ToString()); return false; } LogPrintf("CInstantSend::ResolveConflicts -- WARNING: Found conflicting completed Transaction Lock, dropping both, txid=%s, conflicting txid=%s/n", txHash.ToString(), hashConflicting.ToString()); CTxLockRequest txLockRequest = itLockCandidate->second.txLockRequest; CTxLockRequest txLockRequestConflicting = itLockCandidateConflicting->second.txLockRequest; itLockCandidate->second.SetConfirmedHeight(0); // expired itLockCandidateConflicting->second.SetConfirmedHeight(0); // expired CheckAndRemove(); // clean up // AlreadyHave should still return "true" for both of them mapLockRequestRejected.insert(std::make_pair(txHash, txLockRequest)); mapLockRequestRejected.insert(std::make_pair(hashConflicting, txLockRequestConflicting)); // TODO: clean up mapLockRequestRejected later somehow // (not a big issue since we already PoSe ban malicious masternodes // and they won't be able to spam) // TODO: ban all malicious masternodes permanently, do not accept anything from them, ever // TODO: notify zmq+script about this double-spend attempt // and let merchant cancel/hold the order if it's not too late... // can't do anything else, fallback to regular txes return false; } else if (mempool.mapNextTx.count(txin.prevout)) { // check if it's in mempool hashConflicting = mempool.mapNextTx.find(txin.prevout)->second->GetHash(); if(txHash == hashConflicting) continue; // matches current, not a conflict, skip to next txin // conflicts with tx in mempool LogPrintf("CInstantSend::ResolveConflicts -- ERROR: Failed to complete Transaction Lock, conflicts with mempool, txid=%s/n", txHash.ToString()); return false; } } // FOREACH // No conflicts were found so far, check to see if it was already included in block CTransactionRef txTmp; uint256 hashBlock; if(GetTransaction(txHash, txTmp, Params().GetConsensus(), hashBlock, true) && hashBlock != uint256()) { LogPrint("instantsend", "CInstantSend::ResolveConflicts -- Done, %s is included in block %s/n", txHash.ToString(), hashBlock.ToString()); return true; } // Not in block yet, make sure all its inputs are still unspent for (const auto& txin : txLockCandidate.txLockRequest.tx->vin) { Coin coin; if(!GetUTXOCoin(txin.prevout, coin)) { // Not in UTXO anymore? A conflicting tx was mined while we were waiting for votes. LogPrintf("CInstantSend::ResolveConflicts -- ERROR: Failed to find UTXO %s, can't complete Transaction Lock/n", txin.prevout.ToStringShort()); return false; } } LogPrint("instantsend", "CInstantSend::ResolveConflicts -- Done, txid=%s/n", txHash.ToString()); return true;}
开发者ID:einalex,项目名称:syscoin,代码行数:74,
示例17: updateWallet void updateWallet(const uint256 &hash, int status) { const QList<AdsModelRecord>::iterator lower = qLowerBound( cache.begin(), cache.end(), hash, TxLessThan()); const bool inModel = (lower != cache.end() && (*lower).hash == hash); const int lowerIndex = (lower - cache.begin()); { switch(status) { case CT_NEW: { if(inModel) { break; } CTransaction tx; uint256 hashBlock; if (!GetTransaction(hash, tx, hashBlock)) { break; } const AdsModelRecord toInsert = AdsModelRecord::decomposeTransaction(tx); parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex); cache.insert(lowerIndex, toInsert); parent->endInsertRows(); } break; case CT_DELETED: if(!inModel) { break; } // Removed -- remove entire transaction from table parent->beginRemoveRows(QModelIndex(), lowerIndex, lowerIndex); cache.erase(lower); parent->endRemoveRows(); break; case CT_UPDATED: // Miscellaneous updates -- nothing to do, status update will take care of this, and is only computed for // visible transactions. break; } } if (cache.size() > MAX_ADS) { // remove records, exceeding limit, beginning from oldest. QList<AdsModelRecord>::iterator i = cache.begin(), iend = cache.end(); QList<AdsModelRecord>::iterator imindate = iend; for(; i != iend; ++ i) { if (imindate == cache.end() || (*i).time < (*imindate).time) { imindate = i; } } if (imindate != iend) { updateWallet((*imindate).hash, CT_DELETED); } } }
开发者ID:CraigsCoin,项目名称:CraigsCoin,代码行数:62,
示例18: addrvoid SecondAuthDialog::on_signMessageButton_clicked(){ /* Clear old signature to ensure users don't get confused on error with an old signature displayed */ ui->signatureOut->clear(); CBitcoinAddress addr(ui->addressIn->text().toStdString()); if (!addr.IsValid()) { ui->addressIn->setValid(false); ui->statusLabel->setStyleSheet("QLabel { color: red; }"); ui->statusLabel->setText(tr("The entered address is invalid.") + QString(" ") + tr("Please check the address and try again.")); return; } CKeyID keyID; if (!addr.GetKeyID(keyID)) { ui->addressIn->setValid(false); ui->statusLabel->setStyleSheet("QLabel { color: red; }"); ui->statusLabel->setText(tr("The entered address does not refer to a key.") + QString(" ") + tr("Please check the address and try again.")); return; } WalletModel::UnlockContext ctx(model->requestUnlock()); if (!ctx.isValid()) { ui->statusLabel->setStyleSheet("QLabel { color: red; }"); ui->statusLabel->setText(tr("Wallet unlock was cancelled.")); return; } CKey key; if (!pwalletMain->GetKey(keyID, key)) { ui->statusLabel->setStyleSheet("QLabel { color: red; }"); ui->statusLabel->setText(tr("Private key for the entered address is not available.")); return; } uint256 hash; hash.SetHex(ui->messageIn->text().toStdString()); CTransaction tx; uint256 hashBlock = 0; if (!GetTransaction(hash, tx, hashBlock) || !hashBlock) { ui->statusLabel->setStyleSheet("QLabel { color: red; }"); ui->statusLabel->setText(tr("No information available about transaction.")); return; } CDataStream ss(SER_GETHASH, 0); ss << strMessageMagic; ss << ui->messageIn->text().toStdString(); std::vector<unsigned char> vchSig; if (!key.SignCompact(Hash(ss.begin(), ss.end()), vchSig)) { ui->statusLabel->setStyleSheet("QLabel { color: red; }"); ui->statusLabel->setText(QString("<nobr>") + tr("Message signing failed.") + QString("</nobr>")); return; } ui->statusLabel->setStyleSheet("QLabel { color: green; }"); ui->statusLabel->setText(QString("<nobr>") + tr("Message signed.") + QString("</nobr>")); ui->signatureOut->setText(QString::fromStdString(EncodeBase64(&vchSig[0], vchSig.size())));}
开发者ID:BitSeedsOrg,项目名称:Bitseeds,代码行数:66,
示例19: oldVinbool MultisigDialog::signMultisigTx(CMutableTransaction& tx, string& errorOut, QVBoxLayout* keyList){ //will be set false if all inputs are not fully signed(valid) bool fComplete = true; //if keyslist is not default value AND has items in list then true bool fGivenKeys = (keyList != nullptr) && (keyList->count() > 0); try{ //copy of vin for reference before vin is mutated vector<CTxIn> oldVin(tx.vin); CBasicKeyStore privKeystore; //if keys were given, attempt to collect redeem and scriptpubkey if(fGivenKeys){ for(int i = 0; i < keyList->count(); i++){ QWidget* keyFrame = qobject_cast<QWidget*>(keyList->itemAt(i)->widget()); QLineEdit* key = keyFrame->findChild<QLineEdit*>("key"); CBitcoinSecret vchSecret; if (!vchSecret.SetString(key->text().toStdString())) throw runtime_error("Invalid private key"); CKey cKey = vchSecret.GetKey(); if (!cKey.IsValid()) throw runtime_error("Private key outside allowed range"); privKeystore.AddKey(cKey); } for(CTxIn& txin : tx.vin){ //get inputs CTransaction txVin; uint256 hashBlock; if (!GetTransaction(txin.prevout.hash, txVin, hashBlock, true)) throw runtime_error("txin could not be found"); if (hashBlock == 0) throw runtime_error("txin is unconfirmed"); //get pubkey from input CScript prevPubKey = txVin.vout[txin.prevout.n].scriptPubKey; //get payment destination CTxDestination address; if(!ExtractDestination(prevPubKey, address)){ throw runtime_error("Could not find address for destination."); } //get redeem script related to destination CScriptID hash = boost::get<CScriptID>(address); CScript redeemScript; if (!pwalletMain->GetCScript(hash, redeemScript)){ errorOut = "could not redeem"; } privKeystore.AddCScript(redeemScript); } }else{ if (model->getEncryptionStatus() == model->Locked) { if (!model->requestUnlock(true).isValid()) { // Unlock wallet was cancelled throw runtime_error("Error: Your wallet is locked. Please enter the wallet passphrase first."); } } } //choose between local wallet and provided const CKeyStore& keystore = fGivenKeys ? privKeystore : *pwalletMain; //attempt to sign each input from local wallet int nIn = 0; for(CTxIn& txin : tx.vin){ //get inputs CTransaction txVin; uint256 hashBlock; if (!GetTransaction(txin.prevout.hash, txVin, hashBlock, true)) throw runtime_error("txin could not be found"); if (hashBlock == 0) throw runtime_error("txin is unconfirmed"); txin.scriptSig.clear(); CScript prevPubKey = txVin.vout[txin.prevout.n].scriptPubKey; //sign what we can SignSignature(keystore, prevPubKey, tx, nIn); //merge in any previous signatures txin.scriptSig = CombineSignatures(prevPubKey, tx, nIn, txin.scriptSig, oldVin[nIn].scriptSig); if (!VerifyScript(txin.scriptSig, prevPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, MutableTransactionSignatureChecker(&tx, nIn))){ fComplete = false; } nIn++; } ui->signButtonStatus->setText(buildMultisigTxStatusString(fComplete, tx)); }catch(const runtime_error& e){ errorOut = string(e.what()); fComplete = false;//.........这里部分代码省略.........
开发者ID:michaili,项目名称:PIVX,代码行数:101,
示例20: LOCKQString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx){ QString strHTML; { LOCK(wallet->cs_wallet); strHTML.reserve(4000); strHTML += "<html><font face='verdana, arial, helvetica, sans-serif'>"; int64_t nTime = wtx.GetTxTime(); int64_t nCredit = wtx.GetCredit(MINE_ALL); int64_t nDebit = wtx.GetDebit(MINE_ALL); int64_t nNet = nCredit - nDebit; strHTML += "<b>" + tr("Status") + ":</b> " + FormatTxStatus(wtx); int nRequests = wtx.GetRequestCount(); if (nRequests != -1) { if (nRequests == 0) strHTML += tr(", has not been successfully broadcast yet"); else if (nRequests > 0) strHTML += tr(", broadcast through %n node(s)", "", nRequests); } strHTML += "<br>"; strHTML += "<b>" + tr("Date") + ":</b> " + (nTime ? GUIUtil::dateTimeStr(nTime) : "") + "<br>"; // // From // if (wtx.IsCoinBase() || wtx.IsCoinStake()) { strHTML += "<b>" + tr("Source") + ":</b> " + tr("Generated") + "<br>"; } else if (wtx.mapValue.count("from") && !wtx.mapValue["from"].empty()) { // Online transaction strHTML += "<b>" + tr("From") + ":</b> " + GUIUtil::HtmlEscape(wtx.mapValue["from"]) + "<br>"; } else { // Offline transaction if (nNet > 0) { // Credit BOOST_FOREACH(const CTxOut& txout, wtx.vout) { if (wallet->IsMine(txout)) { CTxDestination address; if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*wallet, address)) { if (wallet->mapAddressBook.count(address)) { std::vector<CTxDestination> addedAddresses; for (unsigned int i = 0; i < wtx.vin.size(); i++) { uint256 hash; const CTxIn& vin = wtx.vin[i]; hash.SetHex(vin.prevout.hash.ToString()); CTransaction wtxPrev; uint256 hashBlock = 0; if (!GetTransaction(hash, wtxPrev, hashBlock)) { strHTML += "<b>" + tr("From") + ":</b> " + tr("unknown") + "<br>"; continue; } CTxDestination senderAddress; if (!ExtractDestination(wtxPrev.vout[vin.prevout.n].scriptPubKey, senderAddress) ) { strHTML += "<b>" + tr("From") + ":</b> " + tr("unknown") + "<br>"; } else if(std::find(addedAddresses.begin(), addedAddresses.end(), senderAddress) == addedAddresses.end() ) { addedAddresses.push_back(senderAddress); strHTML += "<b>" + tr("From") + ":</b> "; strHTML += GUIUtil::HtmlEscape(CBitcoinAddress(senderAddress).ToString()); if(wallet->mapAddressBook.find(senderAddress) != wallet->mapAddressBook.end()) if (!wallet->mapAddressBook[senderAddress].empty()) { strHTML += " (" + tr("label") + ": " + GUIUtil::HtmlEscape(wallet->mapAddressBook[senderAddress]) + ")"; } strHTML += "<br>"; } } strHTML += "<b>" + tr("To") + ":</b> "; strHTML += GUIUtil::HtmlEscape(CBitcoinAddress(address).ToString()); if (!wallet->mapAddressBook[address].empty()) strHTML += " (" + tr("own address") + ", " + tr("label") + ": " + GUIUtil::HtmlEscape(wallet->mapAddressBook[address]) + ")"; else strHTML += " (" + tr("own address") + ")"; strHTML += "<br>"; } } break; } } } }//.........这里部分代码省略.........
开发者ID:0xDEADFACE,项目名称:novacoin,代码行数:101,
示例21: getrawtransactionUniValue getrawtransaction(const JSONRPCRequest& request){ if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) throw std::runtime_error( "getrawtransaction /"txid/" ( verbose )/n" "/nNOTE: By default this function only works for mempool transactions. If the -txindex option is/n" "enabled, it also works for blockchain transactions./n" "DEPRECATED: for now, it also works for transactions with unspent outputs./n" "/nReturn the raw transaction data./n" "/nIf verbose is 'true', returns an Object with information about 'txid'./n" "If verbose is 'false' or omitted, returns a string that is serialized, hex-encoded data for 'txid'./n" "/nArguments:/n" "1. /"txid/" (string, required) The transaction id/n" "2. verbose (bool, optional, default=false) If false, return a string, otherwise return a json object/n" "/nResult (if verbose is not set or set to false):/n" "/"data/" (string) The serialized, hex-encoded data for 'txid'/n" "/nResult (if verbose is set to true):/n" "{/n" " /"hex/" : /"data/", (string) The serialized, hex-encoded data for 'txid'/n" " /"txid/" : /"id/", (string) The transaction id (same as provided)/n" " /"hash/" : /"id/", (string) The transaction hash (differs from txid for witness transactions)/n" " /"size/" : n, (numeric) The serialized transaction size/n" " /"vsize/" : n, (numeric) The virtual transaction size (differs from size for witness transactions)/n" " /"version/" : n, (numeric) The version/n" " /"locktime/" : ttt, (numeric) The lock time/n" " /"vin/" : [ (array of json objects)/n" " {/n" " /"txid/": /"id/", (string) The transaction id/n" " /"vout/": n, (numeric) /n" " /"scriptSig/": { (json object) The script/n" " /"asm/": /"asm/", (string) asm/n" " /"hex/": /"hex/" (string) hex/n" " },/n" " /"sequence/": n (numeric) The script sequence number/n" " /"txinwitness/": [/"hex/", ...] (array of string) hex-encoded witness data (if any)/n" " }/n" " ,.../n" " ],/n" " /"vout/" : [ (array of json objects)/n" " {/n" " /"value/" : x.xxx, (numeric) The value in " + CURRENCY_UNIT + "/n" " /"n/" : n, (numeric) index/n" " /"scriptPubKey/" : { (json object)/n" " /"asm/" : /"asm/", (string) the asm/n" " /"hex/" : /"hex/", (string) the hex/n" " /"reqSigs/" : n, (numeric) The required sigs/n" " /"type/" : /"pubkeyhash/", (string) The type, eg 'pubkeyhash'/n" " /"addresses/" : [ (json array of string)/n" " /"address/" (string) bitcoin address/n" " ,.../n" " ]/n" " }/n" " }/n" " ,.../n" " ],/n" " /"blockhash/" : /"hash/", (string) the block hash/n" " /"confirmations/" : n, (numeric) The confirmations/n" " /"time/" : ttt, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT)/n" " /"blocktime/" : ttt (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)/n" "}/n" "/nExamples:/n" + HelpExampleCli("getrawtransaction", "/"mytxid/"") + HelpExampleCli("getrawtransaction", "/"mytxid/" true") + HelpExampleRpc("getrawtransaction", "/"mytxid/", true") ); LOCK(cs_main); uint256 hash = ParseHashV(request.params[0], "parameter 1"); // Accept either a bool (true) or a num (>=1) to indicate verbose output. bool fVerbose = false; if (!request.params[1].isNull()) { if (request.params[1].isNum()) { if (request.params[1].get_int() != 0) { fVerbose = true; } } else if(request.params[1].isBool()) { if(request.params[1].isTrue()) { fVerbose = true; } } else { throw JSONRPCError(RPC_TYPE_ERROR, "Invalid type provided. Verbose parameter must be a boolean."); } } CTransactionRef tx; uint256 hashBlock; if (!GetTransaction(hash, tx, Params().GetConsensus(), hashBlock, true)) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string(fTxIndex ? "No such mempool or blockchain transaction" : "No such mempool transaction. Use -txindex to enable blockchain transaction queries") + ". Use gettransaction for wallet transactions.");//.........这里部分代码省略.........
开发者ID:21E14,项目名称:bitcoin,代码行数:101,
示例22: CMutableTransactionbool CMasternodeBroadcast::CheckInputsAndAdd(int& nDoS){ // we are a masternode with the same vin (i.e. already activated) and this mnb is ours (matches our Masternode privkey) // so nothing to do here for us if(fMasterNode && vin.prevout == activeMasternode.vin.prevout && pubkey2 == activeMasternode.pubKeyMasternode) return true; // search existing Masternode list CMasternode* pmn = mnodeman.Find(vin); if(pmn != NULL) { // nothing to do here if we already know about this masternode and it's enabled if(pmn->IsEnabled()) return true; // if it's not enabled, remove old MN first and continue else mnodeman.Remove(pmn->vin); } CValidationState state; CMutableTransaction tx = CMutableTransaction(); CTxOut vout = CTxOut(999.99*COIN, darkSendPool.collateralPubKey); tx.vin.push_back(vin); tx.vout.push_back(vout); { TRY_LOCK(cs_main, lockMain); if(!lockMain) { // not mnb fault, let it to be checked again later mnodeman.mapSeenMasternodeBroadcast.erase(GetHash()); masternodeSync.mapSeenSyncMNB.erase(GetHash()); return false; } if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL)) { //set nDos state.IsInvalid(nDoS); return false; } } LogPrint("masternode", "mnb - Accepted Masternode entry/n"); if(GetInputAge(vin) < MASTERNODE_MIN_CONFIRMATIONS){ LogPrintf("mnb - Input must have at least %d confirmations/n", MASTERNODE_MIN_CONFIRMATIONS); // maybe we miss few blocks, let this mnb to be checked again later mnodeman.mapSeenMasternodeBroadcast.erase(GetHash()); masternodeSync.mapSeenSyncMNB.erase(GetHash()); return false; } // verify that sig time is legit in past // should be at least not earlier than block when 1000 DASH tx got MASTERNODE_MIN_CONFIRMATIONS uint256 hashBlock = 0; CTransaction tx2; GetTransaction(vin.prevout.hash, tx2, hashBlock, true); BlockMap::iterator mi = mapBlockIndex.find(hashBlock); if (mi != mapBlockIndex.end() && (*mi).second) { CBlockIndex* pMNIndex = (*mi).second; // block for 1000 DASH tx -> 1 confirmation CBlockIndex* pConfIndex = chainActive[pMNIndex->nHeight + MASTERNODE_MIN_CONFIRMATIONS - 1]; // block where tx got MASTERNODE_MIN_CONFIRMATIONS if(pConfIndex->GetBlockTime() > sigTime) { LogPrintf("mnb - Bad sigTime %d for Masternode %20s %105s (%i conf block is at %d)/n", sigTime, addr.ToString(), vin.ToString(), MASTERNODE_MIN_CONFIRMATIONS, pConfIndex->GetBlockTime()); return false; } } LogPrintf("mnb - Got NEW Masternode entry - %s - %s - %s - %lli /n", GetHash().ToString(), addr.ToString(), vin.ToString(), sigTime); CMasternode mn(*this); mnodeman.Add(mn); // if it matches our Masternode privkey, then we've been remotely activated if(pubkey2 == activeMasternode.pubKeyMasternode && protocolVersion == PROTOCOL_VERSION){ activeMasternode.EnableHotColdMasterNode(vin, addr); } bool isLocal = addr.IsRFC1918() || addr.IsLocal(); if(Params().NetworkID() == CBaseChainParams::REGTEST) isLocal = false; if(!isLocal) Relay(); return true;}
开发者ID:Nobelia,项目名称:darkforest,代码行数:83,
示例23: gettxoutproofUniValue gettxoutproof(const JSONRPCRequest& request){ if (request.fHelp || (request.params.size() != 1 && request.params.size() != 2)) throw std::runtime_error( "gettxoutproof [/"txid/",...] ( blockhash )/n" "/nReturns a hex-encoded proof that /"txid/" was included in a block./n" "/nNOTE: By default this function only works sometimes. This is when there is an/n" "unspent output in the utxo for this transaction. To make it always work,/n" "you need to maintain a transaction index, using the -txindex command line option or/n" "specify the block in which the transaction is included manually (by blockhash)./n" "/nArguments:/n" "1. /"txids/" (string) A json array of txids to filter/n" " [/n" " /"txid/" (string) A transaction hash/n" " ,.../n" " ]/n" "2. /"blockhash/" (string, optional) If specified, looks for txid in the block with this hash/n" "/nResult:/n" "/"data/" (string) A string that is a serialized, hex-encoded data for the proof./n" ); std::set<uint256> setTxids; uint256 oneTxid; UniValue txids = request.params[0].get_array(); for (unsigned int idx = 0; idx < txids.size(); idx++) { const UniValue& txid = txids[idx]; if (txid.get_str().length() != 64 || !IsHex(txid.get_str())) throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid txid ")+txid.get_str()); uint256 hash(uint256S(txid.get_str())); if (setTxids.count(hash)) throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated txid: ")+txid.get_str()); setTxids.insert(hash); oneTxid = hash; } LOCK(cs_main); CBlockIndex* pblockindex = nullptr; uint256 hashBlock; if (!request.params[1].isNull()) { hashBlock = uint256S(request.params[1].get_str()); if (!mapBlockIndex.count(hashBlock)) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); pblockindex = mapBlockIndex[hashBlock]; } else { // Loop through txids and try to find which block they're in. Exit loop once a block is found. for (const auto& tx : setTxids) { const Coin& coin = AccessByTxid(*pcoinsTip, tx); if (!coin.IsSpent()) { pblockindex = chainActive[coin.nHeight]; break; } } } if (pblockindex == nullptr) { CTransactionRef tx; if (!GetTransaction(oneTxid, tx, Params().GetConsensus(), hashBlock, false) || hashBlock.IsNull()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not yet in block"); if (!mapBlockIndex.count(hashBlock)) throw JSONRPCError(RPC_INTERNAL_ERROR, "Transaction index corrupt"); pblockindex = mapBlockIndex[hashBlock]; } CBlock block; if(!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus())) throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); unsigned int ntxFound = 0; for (const auto& tx : block.vtx) if (setTxids.count(tx->GetHash())) ntxFound++; if (ntxFound != setTxids.size()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Not all transactions found in specified or retrieved block"); CDataStream ssMB(SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS); CMerkleBlock mb(block, setTxids); ssMB << mb; std::string strHex = HexStr(ssMB.begin(), ssMB.end()); return strHex;}
开发者ID:21E14,项目名称:bitcoin,代码行数:84,
注:本文中的GetTransaction函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ GetTransactionSnapshot函数代码示例 C++ GetTotalStatValue函数代码示例 |