aboutsummaryrefslogtreecommitdiff
path: root/src/bitcoinrpc.cpp
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@exmulti.com>2012-08-21 02:06:09 -0400
committerJeff Garzik <jgarzik@redhat.com>2012-08-21 02:06:09 -0400
commitddd1ffb4f1b433c64b4cc91b9fdd6b0958d2d14e (patch)
tree5ef783af2cb00040e563161f820f0f4da9c32c89 /src/bitcoinrpc.cpp
parent79f2525ab69146480033d6aa3c00c986f1c933f1 (diff)
downloadbitcoin-ddd1ffb4f1b433c64b4cc91b9fdd6b0958d2d14e.tar.xz
RPC, cosmetic: de-indent getblocktemplate()
Diffstat (limited to 'src/bitcoinrpc.cpp')
-rw-r--r--src/bitcoinrpc.cpp188
1 files changed, 93 insertions, 95 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index 49bea89bde..b20191b45c 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -1959,123 +1959,121 @@ Value getblocktemplate(const Array& params, bool fHelp)
if (strMode != "template")
throw JSONRPCError(-8, "Invalid mode");
- {
- if (vNodes.empty())
- throw JSONRPCError(-9, "Bitcoin is not connected!");
-
- if (IsInitialBlockDownload())
- throw JSONRPCError(-10, "Bitcoin is downloading blocks...");
+ if (vNodes.empty())
+ throw JSONRPCError(-9, "Bitcoin is not connected!");
- static CReserveKey reservekey(pwalletMain);
+ if (IsInitialBlockDownload())
+ throw JSONRPCError(-10, "Bitcoin is downloading blocks...");
- // Update block
- static unsigned int nTransactionsUpdatedLast;
- static CBlockIndex* pindexPrev;
- static int64 nStart;
- static CBlock* pblock;
- if (pindexPrev != pindexBest ||
- (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 5))
- {
- // Clear pindexPrev so future calls make a new block, despite any failures from here on
- pindexPrev = NULL;
+ static CReserveKey reservekey(pwalletMain);
- // Store the pindexBest used before CreateNewBlock, to avoid races
- nTransactionsUpdatedLast = nTransactionsUpdated;
- CBlockIndex* pindexPrevNew = pindexBest;
- nStart = GetTime();
+ // Update block
+ static unsigned int nTransactionsUpdatedLast;
+ static CBlockIndex* pindexPrev;
+ static int64 nStart;
+ static CBlock* pblock;
+ if (pindexPrev != pindexBest ||
+ (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 5))
+ {
+ // Clear pindexPrev so future calls make a new block, despite any failures from here on
+ pindexPrev = NULL;
- // Create new block
- if(pblock)
- {
- delete pblock;
- pblock = NULL;
- }
- pblock = CreateNewBlock(reservekey);
- if (!pblock)
- throw JSONRPCError(-7, "Out of memory");
+ // Store the pindexBest used before CreateNewBlock, to avoid races
+ nTransactionsUpdatedLast = nTransactionsUpdated;
+ CBlockIndex* pindexPrevNew = pindexBest;
+ nStart = GetTime();
- // Need to update only after we know CreateNewBlock succeeded
- pindexPrev = pindexPrevNew;
+ // Create new block
+ if(pblock)
+ {
+ delete pblock;
+ pblock = NULL;
}
+ pblock = CreateNewBlock(reservekey);
+ if (!pblock)
+ throw JSONRPCError(-7, "Out of memory");
- // Update nTime
- pblock->UpdateTime(pindexPrev);
- pblock->nNonce = 0;
+ // Need to update only after we know CreateNewBlock succeeded
+ pindexPrev = pindexPrevNew;
+ }
- Array transactions;
- map<uint256, int64_t> setTxIndex;
- int i = 0;
- CTxDB txdb("r");
- BOOST_FOREACH (CTransaction& tx, pblock->vtx)
- {
- uint256 txHash = tx.GetHash();
- setTxIndex[txHash] = i++;
+ // Update nTime
+ pblock->UpdateTime(pindexPrev);
+ pblock->nNonce = 0;
- if (tx.IsCoinBase())
- continue;
+ Array transactions;
+ map<uint256, int64_t> setTxIndex;
+ int i = 0;
+ CTxDB txdb("r");
+ BOOST_FOREACH (CTransaction& tx, pblock->vtx)
+ {
+ uint256 txHash = tx.GetHash();
+ setTxIndex[txHash] = i++;
- Object entry;
+ if (tx.IsCoinBase())
+ continue;
- CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
- ssTx << tx;
- entry.push_back(Pair("data", HexStr(ssTx.begin(), ssTx.end())));
+ Object entry;
+
+ CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
+ ssTx << tx;
+ entry.push_back(Pair("data", HexStr(ssTx.begin(), ssTx.end())));
- entry.push_back(Pair("hash", txHash.GetHex()));
+ entry.push_back(Pair("hash", txHash.GetHex()));
- MapPrevTx mapInputs;
- map<uint256, CTxIndex> mapUnused;
- bool fInvalid = false;
- if (tx.FetchInputs(txdb, mapUnused, false, false, mapInputs, fInvalid))
+ MapPrevTx mapInputs;
+ map<uint256, CTxIndex> mapUnused;
+ bool fInvalid = false;
+ if (tx.FetchInputs(txdb, mapUnused, false, false, mapInputs, fInvalid))
+ {
+ entry.push_back(Pair("fee", (int64_t)(tx.GetValueIn(mapInputs) - tx.GetValueOut())));
+
+ Array deps;
+ BOOST_FOREACH (MapPrevTx::value_type& inp, mapInputs)
{
- entry.push_back(Pair("fee", (int64_t)(tx.GetValueIn(mapInputs) - tx.GetValueOut())));
-
- Array deps;
- BOOST_FOREACH (MapPrevTx::value_type& inp, mapInputs)
- {
- if (setTxIndex.count(inp.first))
- deps.push_back(setTxIndex[inp.first]);
- }
- entry.push_back(Pair("depends", deps));
-
- int64_t nSigOps = tx.GetLegacySigOpCount();
- nSigOps += tx.GetP2SHSigOpCount(mapInputs);
- entry.push_back(Pair("sigops", nSigOps));
+ if (setTxIndex.count(inp.first))
+ deps.push_back(setTxIndex[inp.first]);
}
+ entry.push_back(Pair("depends", deps));
- transactions.push_back(entry);
+ int64_t nSigOps = tx.GetLegacySigOpCount();
+ nSigOps += tx.GetP2SHSigOpCount(mapInputs);
+ entry.push_back(Pair("sigops", nSigOps));
}
- Object aux;
- aux.push_back(Pair("flags", HexStr(COINBASE_FLAGS.begin(), COINBASE_FLAGS.end())));
+ transactions.push_back(entry);
+ }
- uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();
+ Object aux;
+ aux.push_back(Pair("flags", HexStr(COINBASE_FLAGS.begin(), COINBASE_FLAGS.end())));
- static Array aMutable;
- if (aMutable.empty())
- {
- aMutable.push_back("time");
- aMutable.push_back("transactions");
- aMutable.push_back("prevblock");
- }
-
- Object result;
- result.push_back(Pair("version", pblock->nVersion));
- result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex()));
- result.push_back(Pair("transactions", transactions));
- result.push_back(Pair("coinbaseaux", aux));
- result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue));
- result.push_back(Pair("target", hashTarget.GetHex()));
- result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1));
- result.push_back(Pair("mutable", aMutable));
- result.push_back(Pair("noncerange", "00000000ffffffff"));
- result.push_back(Pair("sigoplimit", (int64_t)MAX_BLOCK_SIGOPS));
- result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SIZE));
- result.push_back(Pair("curtime", (int64_t)pblock->nTime));
- result.push_back(Pair("bits", HexBits(pblock->nBits)));
- result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));
+ uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();
- return result;
+ static Array aMutable;
+ if (aMutable.empty())
+ {
+ aMutable.push_back("time");
+ aMutable.push_back("transactions");
+ aMutable.push_back("prevblock");
}
+
+ Object result;
+ result.push_back(Pair("version", pblock->nVersion));
+ result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex()));
+ result.push_back(Pair("transactions", transactions));
+ result.push_back(Pair("coinbaseaux", aux));
+ result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue));
+ result.push_back(Pair("target", hashTarget.GetHex()));
+ result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1));
+ result.push_back(Pair("mutable", aMutable));
+ result.push_back(Pair("noncerange", "00000000ffffffff"));
+ result.push_back(Pair("sigoplimit", (int64_t)MAX_BLOCK_SIGOPS));
+ result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SIZE));
+ result.push_back(Pair("curtime", (int64_t)pblock->nTime));
+ result.push_back(Pair("bits", HexBits(pblock->nBits)));
+ result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));
+
+ return result;
}
Value submitblock(const Array& params, bool fHelp)