本文整理汇总了C++中CTransaction::FetchInputs方法的典型用法代码示例。如果您正苦于以下问题:C++ CTransaction::FetchInputs方法的具体用法?C++ CTransaction::FetchInputs怎么用?C++ CTransaction::FetchInputs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CTransaction
的用法示例。
在下文中一共展示了CTransaction::FetchInputs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getTxFees
double BlockBrowser::getTxFees(std::string txid)
{
uint256 hash;
hash.SetHex(txid);
CTransaction tx;
uint256 hashBlock = 0;
CTxDB txdb("r");
if (!GetTransaction(hash, tx, hashBlock))
return convertCoins(MIN_TX_FEE);
MapPrevTx mapInputs;
map<uint256, CTxIndex> mapUnused;
bool fInvalid;
if (!tx.FetchInputs(txdb, mapUnused, false, false, mapInputs, fInvalid))
return convertCoins(MIN_TX_FEE);
qint64 nTxFees = tx.GetValueIn(mapInputs)-tx.GetValueOut();
if(tx.IsCoinStake() || tx.IsCoinBase()) {
ui->feesLabel->setText(QString("Reward:"));
nTxFees *= -1;
}
else
ui->feesLabel->setText(QString("Fees:"));
return convertCoins(nTxFees);
}
示例2: on_signTransactionButton_clicked
void MultisigDialog::on_signTransactionButton_clicked()
{
ui->signedTransaction->clear();
if(!model)
return;
CWallet *wallet = model->getWallet();
// Decode the raw transaction
std::vector<unsigned char> txData(ParseHex(ui->transaction->text().toStdString()));
CDataStream ss(txData, SER_NETWORK, PROTOCOL_VERSION);
CTransaction tx;
try
{
ss >> tx;
}
catch(std::exception &e)
{
(void)e;
return;
}
CTransaction mergedTx(tx);
// Fetch previous transactions (inputs)
std::map<COutPoint, CScript> mapPrevOut;
for(unsigned int i = 0; i < mergedTx.vin.size(); i++)
{
CTransaction tempTx;
MapPrevTx mapPrevTx;
CTxDB txdb("r");
std::map<uint256, CTxIndex> unused;
bool fInvalid;
tempTx.vin.push_back(mergedTx.vin[i]);
tempTx.FetchInputs(txdb, unused, false, false, mapPrevTx, fInvalid);
BOOST_FOREACH(const CTxIn& txin, tempTx.vin)
{
const uint256& prevHash = txin.prevout.hash;
if(mapPrevTx.count(prevHash) && mapPrevTx[prevHash].second.vout.size() > txin.prevout.n)
mapPrevOut[txin.prevout] = mapPrevTx[prevHash].second.vout[txin.prevout.n].scriptPubKey;
}
}
// Add the redeem scripts to the wallet keystore
for(int i = 0; i < ui->inputs->count(); i++)
{
MultisigInputEntry *entry = qobject_cast<MultisigInputEntry *>(ui->inputs->itemAt(i)->widget());
if(entry)
{
QString redeemScriptStr = entry->getRedeemScript();
if(redeemScriptStr.size() > 0)
{
std::vector<unsigned char> scriptData(ParseHex(redeemScriptStr.toStdString()));
CScript redeemScript(scriptData.begin(), scriptData.end());
wallet->AddCScript(redeemScript);
}
}
}
WalletModel::UnlockContext ctx(model->requestUnlock());
if(!ctx.isValid())
return;
// Sign what we can
bool fComplete = true;
for(unsigned int i = 0; i < mergedTx.vin.size(); i++)
{
CTxIn& txin = mergedTx.vin[i];
if(mapPrevOut.count(txin.prevout) == 0)
{
fComplete = false;
continue;
}
const CScript& prevPubKey = mapPrevOut[txin.prevout];
txin.scriptSig.clear();
SignSignature(*wallet, prevPubKey, mergedTx, i, SIGHASH_ALL);
txin.scriptSig = CombineSignatures(prevPubKey, mergedTx, i, txin.scriptSig, tx.vin[i].scriptSig);
if(!VerifyScript(txin.scriptSig, prevPubKey, mergedTx, i, true, 0))
{
fComplete = false;
}
}
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
ssTx << mergedTx;
ui->signedTransaction->setText(HexStr(ssTx.begin(), ssTx.end()).c_str());
if(fComplete)
{
ui->statusLabel->setText(tr("Transaction signature is complete"));
ui->sendTransactionButton->setEnabled(true);
}
else
{
ui->statusLabel->setText(tr("Transaction is NOT completely signed"));
ui->sendTransactionButton->setEnabled(false);
}
//.........这里部分代码省略.........
示例3: signrawtransaction
UniValue signrawtransaction(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 4)
throw runtime_error(
"signrawtransaction <hex string> [{\"txid\":txid,\"vout\":n,\"scriptPubKey\":hex,\"redeemScript\":hex},...] [<privatekey1>,...] [sighashtype=\"ALL\"]\n"
"Sign inputs for raw transaction (serialized, hex-encoded).\n"
"Second optional argument (may be null) is an array of previous transaction outputs that\n"
"this transaction depends on but may not yet be in the blockchain.\n"
"Third optional argument (may be null) is an array of base58-encoded private\n"
"keys that can also be used to sign the transaction.\n"
"Fourth optional argument is a string that is one of six values; ALL, NONE, SINGLE or\n"
"ALL|ANYONECANPAY, NONE|ANYONECANPAY, SINGLE|ANYONECANPAY.\n"
"Returns json object with keys:\n"
" hex : raw transaction with signature(s) (hex-encoded string)\n"
" complete : 1 if transaction has a complete set of signature (0 if not)"
#ifdef ENABLE_WALLET
+ HelpRequiringPassphrase()
#endif
);
RPCTypeCheck(params, list_of(UniValue::VSTR)(UniValue::VARR)(UniValue::VARR)(UniValue::VSTR), true);
vector<unsigned char> txData(ParseHex(params[0].get_str()));
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
vector<CTransaction> txVariants;
while (!ssData.empty())
{
try {
CTransaction tx;
ssData >> tx;
txVariants.push_back(tx);
}
catch (std::exception &e) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
}
}
if (txVariants.empty())
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Missing transaction");
// mergedTx will end up with all the signatures; it
// starts as a clone of the rawtx:
CTransaction mergedTx(txVariants[0]);
bool fComplete = true;
// Fetch previous transactions (inputs):
map<COutPoint, CScript> mapPrevOut;
for (unsigned int i = 0; i < mergedTx.vin.size(); i++)
{
CTransaction tempTx;
MapPrevTx mapPrevTx;
CTxDB txdb("r");
map<uint256, CTxIndex> unused;
bool fInvalid;
// FetchInputs aborts on failure, so we go one at a time.
tempTx.vin.push_back(mergedTx.vin[i]);
tempTx.FetchInputs(txdb, unused, false, false, mapPrevTx, fInvalid);
// Copy results into mapPrevOut:
BOOST_FOREACH(const CTxIn& txin, tempTx.vin)
{
const uint256& prevHash = txin.prevout.hash;
if (mapPrevTx.count(prevHash) && mapPrevTx[prevHash].second.vout.size()>txin.prevout.n)
mapPrevOut[txin.prevout] = mapPrevTx[prevHash].second.vout[txin.prevout.n].scriptPubKey;
}
}
bool fGivenKeys = false;
#ifdef ENABLE_WALLET
CMergedKeyStore tempKeystore(pwalletMain);
#else
CBasicKeyStore tempKeystore;
#endif
if (params.size() > 2 && !params[2].isNull())
{
fGivenKeys = true;
UniValue keys = params[2].get_array();
for (unsigned int idx = 0; idx < keys.size(); idx++)
{
CBitcoinSecret vchSecret;
bool fGood = vchSecret.SetString(keys[idx].get_str());
if (!fGood)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key");
CKey key = vchSecret.GetKey();
// 5TY1TqhFLax7w7Hoa6YtrejzoAuWTf5Tf1RKSvVED9tadmUMYjX and Lg7s3TveHSrHbpmAZ5Vmt9an6nim2f4gekrLRR5bJeEfT2fXkRoT are the zero privkey
// they pass the above check, but aren't valid privkeys
if (!key.IsValid()) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key");
}
tempKeystore.AddKey(key);
}
}
#ifdef ENABLE_WALLET
else
EnsureWalletIsUnlocked();
#endif
//.........这里部分代码省略.........