本文整理汇总了C++中CTransaction类的典型用法代码示例。如果您正苦于以下问题:C++ CTransaction类的具体用法?C++ CTransaction怎么用?C++ CTransaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CTransaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HexBits
auxpow.push_back(Pair("chainMerkleBranch", chainMerkle));
auxpow.push_back(Pair("chainIndex", (boost::uint64_t)block.auxpow->nChainIndex));
Object parent_block;
parent_block.push_back(Pair("hash", block.auxpow->parentBlockHeader.GetHash().GetHex()));
parent_block.push_back(Pair("version", (boost::uint64_t)block.auxpow->parentBlockHeader.nVersion));
parent_block.push_back(Pair("previousblockhash", block.auxpow->parentBlockHeader.hashPrevBlock.GetHex()));
parent_block.push_back(Pair("merkleroot", block.auxpow->parentBlockHeader.hashMerkleRoot.GetHex()));
parent_block.push_back(Pair("time", (boost::int64_t)block.auxpow->parentBlockHeader.nTime));
parent_block.push_back(Pair("bits", HexBits(block.auxpow->parentBlockHeader.nBits)));
parent_block.push_back(Pair("nonce", (boost::uint64_t)block.auxpow->parentBlockHeader.nNonce));
auxpow.push_back(Pair("parent_block", Value(parent_block)));
result.push_back(Pair("auxpow", Value(auxpow)));
}
Array txs;
BOOST_FOREACH(const CTransaction&tx, block.vtx)
txs.push_back(tx.GetHash().GetHex());
result.push_back(Pair("tx", txs));
result.push_back(Pair("time", block.GetBlockTime()));
result.push_back(Pair("nonce", (uint64_t)block.nNonce));
result.push_back(Pair("bits", HexBits(block.nBits)));
result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
if (blockindex->pprev)
result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
CBlockIndex *pnext = chainActive.Next(blockindex);
if (pnext)
result.push_back(Pair("nextblockhash", pnext->GetBlockHash().GetHex()));
return result;
}
示例2: ssStartKey
//.........这里部分代码省略.........
// Load bnBestInvalidTrust, OK if it doesn't exist
CBigNum bnBestInvalidTrust;
ReadBestInvalidTrust(bnBestInvalidTrust);
// Verify blocks in the best chain
int nCheckLevel = GetArg("-checklevel", 1);
int nCheckDepth = GetArg( "-checkblocks", 2500);
if (nCheckDepth == 0)
nCheckDepth = 1000000000; // suffices until the year 19000
if (nCheckDepth > nBestHeight)
nCheckDepth = nBestHeight;
printf("Verifying last %i blocks at level %i\n", nCheckDepth, nCheckLevel);
CBlockIndex* pindexFork = NULL;
map<pair<unsigned int, unsigned int>, CBlockIndex*> mapBlockPos;
for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev)
{
if (fRequestShutdown || pindex->nHeight < nBestHeight-nCheckDepth)
break;
CBlock block;
if (!block.ReadFromDisk(pindex))
return error("LoadBlockIndex() : block.ReadFromDisk failed");
// check level 1: verify block validity
// check level 7: verify block signature too
if (nCheckLevel>0 && !block.CheckBlock(true, true))
{
printf("LoadBlockIndex() : *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
pindexFork = pindex->pprev;
}
// check level 2: verify transaction index validity
if (nCheckLevel>1)
{
pair<unsigned int, unsigned int> pos = make_pair(pindex->nFile, pindex->nBlockPos);
mapBlockPos[pos] = pindex;
BOOST_FOREACH(const CTransaction &tx, block.vtx)
{
uint256 hashTx = tx.GetHash();
CTxIndex txindex;
if (ReadTxIndex(hashTx, txindex))
{
// check level 3: checker transaction hashes
if (nCheckLevel>2 || pindex->nFile != txindex.pos.nFile || pindex->nBlockPos != txindex.pos.nBlockPos)
{
// either an error or a duplicate transaction
CTransaction txFound;
if (!txFound.ReadFromDisk(txindex.pos))
{
printf("LoadBlockIndex() : *** cannot read mislocated transaction %s\n", hashTx.ToString().c_str());
pindexFork = pindex->pprev;
}
else
if (txFound.GetHash() != hashTx) // not a duplicate tx
{
printf("LoadBlockIndex(): *** invalid tx position for %s\n", hashTx.ToString().c_str());
pindexFork = pindex->pprev;
}
}
// check level 4: check whether spent txouts were spent within the main chain
unsigned int nOutput = 0;
if (nCheckLevel>3)
{
BOOST_FOREACH(const CDiskTxPos &txpos, txindex.vSpent)
{
if (!txpos.IsNull())
{
pair<unsigned int, unsigned int> posFind = make_pair(txpos.nFile, txpos.nBlockPos);
if (!mapBlockPos.count(posFind))
示例3: TxToString
std::string TxToString(uint256 BlockHash, const CTransaction& tx)
{
CAmount Input = 0;
CAmount Output = tx.GetValueOut();
std::string InputsContentCells[] = {_("#"), _("Taken from"), _("Address"), _("Amount")};
std::string InputsContent = makeHTMLTableRow(InputsContentCells, sizeof(InputsContentCells) / sizeof(std::string));
std::string OutputsContentCells[] = {_("#"), _("Redeemed in"), _("Address"), _("Amount")};
std::string OutputsContent = makeHTMLTableRow(OutputsContentCells, sizeof(OutputsContentCells) / sizeof(std::string));
if (tx.IsCoinBase()) {
std::string InputsContentCells[] =
{
"0",
"coinbase",
"-",
ValueToString(Output)};
InputsContent += makeHTMLTableRow(InputsContentCells, sizeof(InputsContentCells) / sizeof(std::string));
} else
for (unsigned int i = 0; i < tx.vin.size(); i++) {
COutPoint Out = tx.vin[i].prevout;
CTxOut PrevOut = getPrevOut(tx.vin[i].prevout);
if (PrevOut.nValue < 0)
Input = -Params().MaxMoneyOut();
else
Input += PrevOut.nValue;
std::string InputsContentCells[] =
{
itostr(i),
"<span>" + makeHRef(Out.hash.GetHex()) + ":" + itostr(Out.n) + "</span>",
ScriptToString(PrevOut.scriptPubKey, true),
ValueToString(PrevOut.nValue)};
InputsContent += makeHTMLTableRow(InputsContentCells, sizeof(InputsContentCells) / sizeof(std::string));
}
uint256 TxHash = tx.GetHash();
for (unsigned int i = 0; i < tx.vout.size(); i++) {
const CTxOut& Out = tx.vout[i];
uint256 HashNext = uint256S("0");
unsigned int nNext = 0;
bool fAddrIndex = false;
getNextIn(COutPoint(TxHash, i), HashNext, nNext);
std::string OutputsContentCells[] =
{
itostr(i),
(HashNext == uint256S("0")) ? (fAddrIndex ? _("no") : _("unknown")) : "<span>" + makeHRef(HashNext.GetHex()) + ":" + itostr(nNext) + "</span>",
ScriptToString(Out.scriptPubKey, true),
ValueToString(Out.nValue)};
OutputsContent += makeHTMLTableRow(OutputsContentCells, sizeof(OutputsContentCells) / sizeof(std::string));
}
InputsContent = table + InputsContent + "</table>";
OutputsContent = table + OutputsContent + "</table>";
std::string Hash = TxHash.GetHex();
std::string Labels[] =
{
_("In Block"), "",
_("Size"), itostr(GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION)),
_("Input"), tx.IsCoinBase() ? "-" : ValueToString(Input),
_("Output"), ValueToString(Output),
_("Fees"), tx.IsCoinBase() ? "-" : ValueToString(Input - Output),
_("Timestamp"), "",
_("Hash"), "<pre>" + Hash + "</pre>",
};
// std::map<uint256, CBlockIndex*>::iterator iter = mapBlockIndex.find(BlockHash);
BlockMap::iterator iter = mapBlockIndex.find(BlockHash);
if (iter != mapBlockIndex.end()) {
CBlockIndex* pIndex = iter->second;
Labels[0 * 2 + 1] = makeHRef(itostr(pIndex->nHeight));
Labels[5 * 2 + 1] = TimeToString(pIndex->nTime);
}
std::string Content;
Content += "<h2>" + _("Transaction") + " <span>" + Hash + "</span></h2>";
Content += makeHTMLTable(Labels, sizeof(Labels) / (2 * sizeof(std::string)), 2);
Content += "</br>";
Content += "<h3>" + _("Inputs") + "</h3>";
Content += InputsContent;
Content += "</br>";
Content += "<h3>" + _("Outputs") + "</h3>";
Content += OutputsContent;
return Content;
}
示例4: decomposeTransaction
static AdsModelRecord decomposeTransaction(const CTransaction &tx)
{
BOOST_ASSERT(!tx.msg.empty());
return AdsModelRecord (tx.GetHash(), tx.nTime, tx.msg);
}
示例5: EraseTxIndex
bool CTxDB::EraseTxIndex(const CTransaction& tx)
{
uint256 hash = tx.GetHash();
return Erase(make_pair(string("tx"), hash));
}
示例6: txData
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);
}
//.........这里部分代码省略.........
示例7: TxToJSON
void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
{
entry.push_back(Pair("txid", tx.GetHash().GetHex()));
entry.push_back(Pair("version", tx.nVersion));
entry.push_back(Pair("time", (boost::int64_t)tx.nTime));
entry.push_back(Pair("locktime", (boost::int64_t)tx.nLockTime));
if (tx.nVersion >= 2)
{
entry.push_back(Pair("tx-comment", tx.strTxComment));
}
Array vin;
BOOST_FOREACH(const CTxIn& txin, tx.vin)
{
Object in;
if (tx.IsCoinBase())
in.push_back(Pair("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())));
else
{
in.push_back(Pair("txid", txin.prevout.hash.GetHex()));
in.push_back(Pair("vout", (boost::int64_t)txin.prevout.n));
Object o;
o.push_back(Pair("asm", txin.scriptSig.ToString()));
o.push_back(Pair("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())));
in.push_back(Pair("scriptSig", o));
}
in.push_back(Pair("sequence", (boost::int64_t)txin.nSequence));
vin.push_back(in);
}
entry.push_back(Pair("vin", vin));
Array vout;
for (unsigned int i = 0; i < tx.vout.size(); i++)
{
const CTxOut& txout = tx.vout[i];
Object out;
out.push_back(Pair("value", ValueFromAmount(txout.nValue)));
out.push_back(Pair("n", (boost::int64_t)i));
Object o;
ScriptPubKeyToJSON(txout.scriptPubKey, o);
out.push_back(Pair("scriptPubKey", o));
vout.push_back(out);
}
entry.push_back(Pair("vout", vout));
if (hashBlock != 0)
{
entry.push_back(Pair("blockhash", hashBlock.GetHex()));
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock);
if (mi != mapBlockIndex.end() && (*mi).second)
{
CBlockIndex* pindex = (*mi).second;
if (pindex->IsInMainChain())
{
entry.push_back(Pair("confirmations", 1 + nBestHeight - pindex->nHeight));
entry.push_back(Pair("time", (boost::int64_t)pindex->nTime));
entry.push_back(Pair("blocktime", (boost::int64_t)pindex->nTime));
}
else
entry.push_back(Pair("confirmations", 0));
}
}
}
示例8: SendFailedL
// -----------------------------------------------------------------------------
// CInviteClientTa_Completed::SendFailedL
// -----------------------------------------------------------------------------
//
void CInviteClientTa_Completed::SendFailedL(CTransaction& aTransaction,
TInt aError) const
{
aTransaction.TerminatedL(aError);
}
示例9: BOOST_FOREACH
bool CTxDB::LoadBlockIndex()
{
if (!LoadBlockIndexGuts())
return false;
if (fRequestShutdown)
return true;
// Calculate bnChainTrust
vector<pair<int, CBlockIndex*> > vSortedByHeight;
vSortedByHeight.reserve(mapBlockIndex.size());
BOOST_FOREACH(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex)
{
CBlockIndex* pindex = item.second;
vSortedByHeight.push_back(make_pair(pindex->nHeight, pindex));
}
sort(vSortedByHeight.begin(), vSortedByHeight.end());
BOOST_FOREACH(const PAIRTYPE(int, CBlockIndex*)& item, vSortedByHeight)
{
CBlockIndex* pindex = item.second;
pindex->bnChainTrust = (pindex->pprev ? pindex->pprev->bnChainTrust : 0) + pindex->GetBlockTrust();
// ppcoin: calculate stake modifier checksum
pindex->nStakeModifierChecksum = GetStakeModifierChecksum(pindex);
if (!CheckStakeModifierCheckpoints(pindex->nHeight, pindex->nStakeModifierChecksum))
return error("CTxDB::LoadBlockIndex() : Failed stake modifier checkpoint height=%d, modifier=0x%016"PRI64x, pindex->nHeight, pindex->nStakeModifier);
}
// Load hashBestChain pointer to end of best chain
if (!ReadHashBestChain(hashBestChain))
{
if (pindexGenesisBlock == NULL)
return true;
return error("CTxDB::LoadBlockIndex() : hashBestChain not loaded");
}
if (!mapBlockIndex.count(hashBestChain))
return error("CTxDB::LoadBlockIndex() : hashBestChain not found in the block index");
pindexBest = mapBlockIndex[hashBestChain];
nBestHeight = pindexBest->nHeight;
bnBestChainTrust = pindexBest->bnChainTrust;
printf("LoadBlockIndex(): hashBestChain=%s height=%d trust=%s date=%s\n",
hashBestChain.ToString().substr(0,20).c_str(), nBestHeight, bnBestChainTrust.ToString().c_str(),
DateTimeStrFormat("%x %H:%M:%S", pindexBest->GetBlockTime()).c_str());
// ppcoin: load hashSyncCheckpoint
if (!ReadSyncCheckpoint(Checkpoints::hashSyncCheckpoint))
return error("CTxDB::LoadBlockIndex() : hashSyncCheckpoint not loaded");
printf("LoadBlockIndex(): synchronized checkpoint %s\n", Checkpoints::hashSyncCheckpoint.ToString().c_str());
// Load bnBestInvalidTrust, OK if it doesn't exist
ReadBestInvalidTrust(bnBestInvalidTrust);
// Verify blocks in the best chain
int nCheckLevel = GetArg("-checklevel", 1);
int nCheckDepth = GetArg( "-checkblocks", 2500);
if (nCheckDepth == 0)
nCheckDepth = 1000000000; // suffices until the year 19000
if (nCheckDepth > nBestHeight)
nCheckDepth = nBestHeight;
printf("Verifying last %i blocks at level %i\n", nCheckDepth, nCheckLevel);
CBlockIndex* pindexFork = NULL;
map<pair<unsigned int, unsigned int>, CBlockIndex*> mapBlockPos;
for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev)
{
if (fRequestShutdown || pindex->nHeight < nBestHeight-nCheckDepth)
break;
CBlock block;
if (!block.ReadFromDisk(pindex))
return error("LoadBlockIndex() : block.ReadFromDisk failed");
// check level 1: verify block validity
if (nCheckLevel>0 && !block.CheckBlock())
{
printf("LoadBlockIndex() : *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
pindexFork = pindex->pprev;
}
// check level 2: verify transaction index validity
if (nCheckLevel>1)
{
pair<unsigned int, unsigned int> pos = make_pair(pindex->nFile, pindex->nBlockPos);
mapBlockPos[pos] = pindex;
BOOST_FOREACH(const CTransaction &tx, block.vtx)
{
uint256 hashTx = tx.GetHash();
CTxIndex txindex;
if (ReadTxIndex(hashTx, txindex))
{
// check level 3: checker transaction hashes
if (nCheckLevel>2 || pindex->nFile != txindex.pos.nFile || pindex->nBlockPos != txindex.pos.nBlockPos)
{
// either an error or a duplicate transaction
CTransaction txFound;
if (!txFound.ReadFromDisk(txindex.pos))
{
printf("LoadBlockIndex() : *** cannot read mislocated transaction %s\n", hashTx.ToString().c_str());
pindexFork = pindex->pprev;
}
else
if (txFound.GetHash() != hashTx) // not a duplicate tx
{
printf("LoadBlockIndex(): *** invalid tx position for %s\n", hashTx.ToString().c_str());
pindexFork = pindex->pprev;
//.........这里部分代码省略.........
示例10: TxToJSON
void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
{
CTxDB txdb("r");
entry.push_back(Pair("txid", tx.GetHash().GetHex()));
entry.push_back(Pair("version", tx.nVersion));
entry.push_back(Pair("time", (boost::int64_t)tx.nTime));
entry.push_back(Pair("locktime", (boost::int64_t)tx.nLockTime));
if (tx.nVersion > 1) {
entry.push_back(Pair("tx-comment", tx.strTxComment));
entry.push_back(Pair("product-id", (boost::int64_t)tx.nProdTypeID));
}
Array vin;
BOOST_FOREACH(const CTxIn& txin, tx.vin)
{
Object in;
if (tx.IsCoinBase())
in.push_back(Pair("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())));
else
{
in.push_back(Pair("txid", txin.prevout.hash.GetHex()));
in.push_back(Pair("vout", (boost::int64_t)txin.prevout.n));
Object o;
o.push_back(Pair("asm", txin.scriptSig.ToString()));
o.push_back(Pair("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())));
in.push_back(Pair("scriptSig", o));
}
in.push_back(Pair("sequence", (boost::int64_t)txin.nSequence));
// [TODO] Refactor this! See getturboredemption.
CTransaction txPrev;
CTxIndex txindex;
if (!txPrev.ReadFromDisk(txdb, txin.prevout, txindex))
{
if (fDebug)
{
printf("TxToJSON: could not read txin from disk\n");
}
continue; // previous transaction not in main chain?
}
CTxOut prevtxout = txPrev.vout[txin.prevout.n];
int nRequired;
txnouttype type;
vector<CTxDestination> addresses;
if (ExtractDestinations(prevtxout.scriptPubKey, type, addresses, nRequired))
{
in.push_back(Pair("value", ValueFromAmount(prevtxout.nValue)));
}
else
{
in.push_back(Pair("type", GetTxnOutputType(TX_NONSTANDARD)));
}
Array a;
BOOST_FOREACH(const CTxDestination& addr, addresses)
{
a.push_back(CBitcoinAddress(addr).ToString());
}
in.push_back(Pair("addresses", a));
vin.push_back(in);
}
示例11: scaninput
Value scaninput(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 4 || params.size() < 2)
throw runtime_error(
"scaninput <txid> <nout> [difficulty] [days]\n"
"Scan specified input for suitable kernel solutions.\n"
" [difficulty] - upper limit for difficulty, current difficulty by default;\n"
" [days] - time window, 365 days by default.\n"
);
uint256 hash;
hash.SetHex(params[0].get_str());
uint32_t nOut = params[1].get_int(), nBits = GetNextTargetRequired(pindexBest, true), nDays = 365;
if (params.size() > 2)
{
CBigNum bnTarget(nPoWBase);
bnTarget *= 1000;
bnTarget /= (int) (params[2].get_real() * 1000);
nBits = bnTarget.GetCompact();
}
if (params.size() > 3)
{
nDays = params[3].get_int();
}
CTransaction tx;
uint256 hashBlock = 0;
if (GetTransaction(hash, tx, hashBlock))
{
if (nOut > tx.vout.size())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Incorrect output number");
if (hashBlock == 0)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to find transaction in the blockchain");
CTxDB txdb("r");
CBlock block;
CTxIndex txindex;
// Load transaction index item
if (!txdb.ReadTxIndex(tx.GetHash(), txindex))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to read block index item");
// Read block header
if (!block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "CBlock::ReadFromDisk() failed");
uint64_t nStakeModifier = 0;
if (!GetKernelStakeModifier(block.GetHash(), nStakeModifier))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No kernel stake modifier generated yet");
std::pair<uint32_t, uint32_t> interval;
interval.first = GetTime();
// Only count coins meeting min age requirement
if (nStakeMinAge + block.nTime > interval.first)
interval.first += (nStakeMinAge + block.nTime - interval.first);
interval.second = interval.first + nDays * 86400;
SHA256_CTX ctx;
GetKernelMidstate(nStakeModifier, block.nTime, txindex.pos.nTxPos - txindex.pos.nBlockPos, tx.nTime, nOut, ctx);
std::pair<uint256, uint32_t> solution;
if (ScanMidstateForward(ctx, nBits, tx.nTime, tx.vout[nOut].nValue, interval, solution))
{
Object r;
r.push_back(Pair("hash", solution.first.GetHex()));
r.push_back(Pair("time", DateTimeStrFormat(solution.second)));
return r;
}
}
else
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction");
return Value::null;
}
示例12: name_pending
UniValue
name_pending (const UniValue& params, bool fHelp)
{
if (fHelp || params.size () > 1)
throw std::runtime_error (
"name_pending (\"name\")\n"
"\nList unconfirmed name operations in the mempool.\n"
"\nIf a name is given, only check for operations on this name.\n"
"\nArguments:\n"
"1. \"name\" (string, optional) only look for this name\n"
"\nResult:\n"
"[\n"
" {\n"
" \"op\": xxxx (string) the operation being performed\n"
" \"name\": xxxx (string) the name operated on\n"
" \"value\": xxxx (string) the name's new value\n"
" \"txid\": xxxx (string) the txid corresponding to the operation\n"
" \"ismine\": xxxx (boolean) whether the name is owned by the wallet\n"
" },\n"
" ...\n"
"]\n"
+ HelpExampleCli ("name_pending", "")
+ HelpExampleCli ("name_pending", "\"d/domob\"")
+ HelpExampleRpc ("name_pending", "")
);
#ifdef ENABLE_WALLET
LOCK2 (pwalletMain ? &pwalletMain->cs_wallet : NULL, mempool.cs);
#else
LOCK (mempool.cs);
#endif
std::vector<uint256> txHashes;
if (params.size () == 0)
mempool.queryHashes (txHashes);
else
{
const std::string name = params[0].get_str ();
const valtype vchName = ValtypeFromString (name);
const uint256 txid = mempool.getTxForName (vchName);
if (!txid.IsNull ())
txHashes.push_back (txid);
}
UniValue arr(UniValue::VARR);
for (std::vector<uint256>::const_iterator i = txHashes.begin ();
i != txHashes.end (); ++i)
{
CTransaction tx;
if (!mempool.lookup (*i, tx) || !tx.IsNamecoin ())
continue;
for (unsigned i = 0; i < tx.vout.size (); ++i)
{
const CNameScript op(tx.vout[i].scriptPubKey);
if (!op.isNameOp () || !op.isAnyUpdate ())
continue;
const valtype vchName = op.getOpName ();
const valtype vchValue = op.getOpValue ();
const std::string name = ValtypeToString (vchName);
const std::string value = ValtypeToString (vchValue);
std::string strOp;
switch (op.getNameOp ())
{
case OP_NAME_FIRSTUPDATE:
strOp = "name_firstupdate";
break;
case OP_NAME_UPDATE:
strOp = "name_update";
break;
default:
assert (false);
}
UniValue obj(UniValue::VOBJ);
obj.push_back (Pair ("op", strOp));
obj.push_back (Pair ("name", name));
obj.push_back (Pair ("value", value));
obj.push_back (Pair ("txid", tx.GetHash ().GetHex ()));
#ifdef ENABLE_WALLET
isminetype mine = ISMINE_NO;
if (pwalletMain)
mine = IsMine (*pwalletMain, op.getAddress ());
const bool isMine = (mine & ISMINE_SPENDABLE);
obj.push_back (Pair ("ismine", isMine));
#endif
arr.push_back (obj);
}
}
return arr;
}
示例13: TxToJSON
void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
{
entry.push_back(Pair("txid", tx.GetHash().GetHex()));
entry.push_back(Pair("version", tx.nVersion));
entry.push_back(Pair("time", (int64_t)tx.nTime));
entry.push_back(Pair("locktime", (int64_t)tx.nLockTime));
std::vector<uint8_t> vchImage;
Array vin;
BOOST_FOREACH(const CTxIn& txin, tx.vin)
{
Object in;
if (tx.IsCoinBase())
{
in.push_back(Pair("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())));
} else
{
if (tx.nVersion == ANON_TXN_VERSION
&& txin.IsAnonInput())
{
txin.ExtractKeyImage(vchImage);
int nRingSize = txin.ExtractRingSize();
in.push_back(Pair("keyimage", HexStr(vchImage)));
in.push_back(Pair("ringsize", nRingSize));
} else
{
in.push_back(Pair("txid", txin.prevout.hash.GetHex()));
in.push_back(Pair("vout", (int64_t)txin.prevout.n));
};
Object o;
o.push_back(Pair("asm", txin.scriptSig.ToString()));
o.push_back(Pair("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())));
in.push_back(Pair("scriptSig", o));
}
in.push_back(Pair("sequence", (int64_t)txin.nSequence));
vin.push_back(in);
};
entry.push_back(Pair("vin", vin));
Array vout;
for (unsigned int i = 0; i < tx.vout.size(); i++)
{
const CTxOut& txout = tx.vout[i];
Object out;
out.push_back(Pair("value", ValueFromAmount(txout.nValue)));
out.push_back(Pair("n", (int64_t)i));
Object o;
ScriptPubKeyToJSON(txout.scriptPubKey, o, false);
out.push_back(Pair("scriptPubKey", o));
vout.push_back(out);
};
entry.push_back(Pair("vout", vout));
if (hashBlock != 0)
{
entry.push_back(Pair("blockhash", hashBlock.GetHex()));
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock);
if (mi != mapBlockIndex.end() && (*mi).second)
{
CBlockIndex* pindex = (*mi).second;
if (pindex->IsInMainChain())
{
entry.push_back(Pair("confirmations", 1 + nBestHeight - pindex->nHeight));
entry.push_back(Pair("time", (int64_t)pindex->nTime));
entry.push_back(Pair("blocktime", (int64_t)pindex->nTime));
}
else
entry.push_back(Pair("confirmations", 0));
}
}
}
示例14: IsStandardTx
bool IsStandardTx(const CTransaction& tx, std::string& reason)
{
if (tx.nVersion > CTransaction::CURRENT_VERSION || tx.nVersion < 1) {
reason = "version";
return false;
}
// Extremely large transactions with lots of inputs can cost the network
// almost as much to process as they cost the sender in fees, because
// computing signature hashes is O(ninputs*txsize). Limiting transactions
// to MAX_STANDARD_TX_SIZE mitigates CPU exhaustion attacks.
unsigned int sz = tx.GetSerializeSize(SER_NETWORK, CTransaction::CURRENT_VERSION);
if (sz >= MAX_STANDARD_TX_SIZE) {
reason = "tx-size";
return false;
}
BOOST_FOREACH(const CTxIn& txin, tx.vin)
{
// Biggest 'standard' txin is a 15-of-15 P2SH multisig with compressed
// keys. (remember the 520 byte limit on redeemScript size) That works
// out to a (15*(33+1))+3=513 byte redeemScript, 513+1+15*(73+1)+3=1627
// bytes of scriptSig, which we round off to 1650 bytes for some minor
// future-proofing. That's also enough to spend a 20-of-20
// CHECKMULTISIG scriptPubKey, though such a scriptPubKey is not
// considered standard)
if (txin.scriptSig.size() > 1650) {
reason = "scriptsig-size";
return false;
}
if (!txin.scriptSig.IsPushOnly()) {
reason = "scriptsig-not-pushonly";
return false;
}
if (txin.scriptSig.IsLotteryClaim()) {
LogPrintf("DEBUG: transaction is lottery claim.");
continue;
}
}
unsigned int nDataOut = 0;
txnouttype whichType;
BOOST_FOREACH(const CTxOut& txout, tx.vout) {
if (txout.scriptPubKey.IsLotteryEntry()) {
LogPrintf("DEBUG: transaction is lottery entry.");
continue;
}
if (!::IsStandard(txout.scriptPubKey, whichType)) {
reason = "scriptpubkey";
return false;
}
if (whichType == TX_NULL_DATA)
nDataOut++;
else if ((whichType == TX_MULTISIG) && (!fIsBareMultisigStd)) {
reason = "bare-multisig";
return false;
} else if (txout.IsDust(::minRelayTxFee)) {
reason = "dust";
return false;
}
}
// only one OP_RETURN txout is permitted
if (nDataOut > 1) {
reason = "multi-op-return";
return false;
}
return true;
}
示例15: ProcessMessageInstantX
void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream& vRecv)
{
if(fLiteMode) return; //disable all darksend/masternode related functionality
if(!IsSporkActive(SPORK_2_INSTANTX)) return;
if(!masternodeSync.IsBlockchainSynced()) return;
if (strCommand == NetMsgType::IX)
{
//LogPrintf("ProcessMessageInstantX::ix\n");
CDataStream vMsg(vRecv);
CTransaction tx;
vRecv >> tx;
// FIXME: this part of simulating inv is not good actually, leaving it only for 12.1 backwards compatibility
// and since we are using invs for relaying even initial ix request, this can (and should) be safely removed in 12.2
CInv inv(MSG_TXLOCK_REQUEST, tx.GetHash());
pfrom->AddInventoryKnown(inv);
GetMainSignals().Inventory(inv.hash);
// have we seen it already?
if(mapTxLockReq.count(inv.hash) || mapTxLockReqRejected.count(inv.hash)) return;
// is it a valid one?
if(!IsIXTXValid(tx)) return;
BOOST_FOREACH(const CTxOut o, tx.vout){
// IX supports normal scripts and unspendable scripts (used in DS collateral and Budget collateral).
// TODO: Look into other script types that are normal and can be included
if(!o.scriptPubKey.IsNormalPaymentScript() && !o.scriptPubKey.IsUnspendable()){
LogPrintf("ProcessMessageInstantX::ix - Invalid Script %s", tx.ToString());
return;
}
}
int nBlockHeight = CreateNewLock(tx);
bool fMissingInputs = false;
CValidationState state;
bool fAccepted = false;
{
LOCK(cs_main);
fAccepted = AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs);
}
if (fAccepted)
{
RelayInv(inv);
DoConsensusVote(tx, nBlockHeight);
mapTxLockReq.insert(make_pair(tx.GetHash(), tx));
LogPrintf("ProcessMessageInstantX::ix - Transaction Lock Request: %s %s : accepted %s\n",
pfrom->addr.ToString(), pfrom->cleanSubVer,
tx.GetHash().ToString()
);
// Masternodes will sometimes propagate votes before the transaction is known to the client.
// If this just happened - update transaction status, try forcing external script notification,
// lock inputs and resolve conflicting locks
if(IsLockedIXTransaction(tx.GetHash())) {
UpdateLockedTransaction(tx, true);
LockTransactionInputs(tx);
ResolveConflicts(tx);
}
return;
} else {
mapTxLockReqRejected.insert(make_pair(tx.GetHash(), tx));
// can we get the conflicting transaction as proof?
LogPrintf("ProcessMessageInstantX::ix - Transaction Lock Request: %s %s : rejected %s\n",
pfrom->addr.ToString(), pfrom->cleanSubVer,
tx.GetHash().ToString()
);
LockTransactionInputs(tx);
ResolveConflicts(tx);
return;
}
}