aboutsummaryrefslogtreecommitdiff
path: root/src/rpcmining.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpcmining.cpp')
-rw-r--r--src/rpcmining.cpp41
1 files changed, 19 insertions, 22 deletions
diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp
index 96712482d5..96518c6d8c 100644
--- a/src/rpcmining.cpp
+++ b/src/rpcmining.cpp
@@ -198,7 +198,7 @@ Value getwork(const Array& params, bool fHelp)
Value getblocktemplate(const Array& params, bool fHelp)
{
- if (fHelp || params.size() > 1)
+ if (fHelp || params.size() != 1)
throw runtime_error(
"getblocktemplate [params]\n"
"Returns data needed to construct a block to work on:\n"
@@ -281,7 +281,9 @@ Value getblocktemplate(const Array& params, bool fHelp)
Array transactions;
map<uint256, int64_t> setTxIndex;
int i = 0;
- CTxDB txdb("r");
+ CCoinsDB coindb("r");
+ CCoinsViewDB viewdb(coindb);
+ CCoinsViewCache view(viewdb);
BOOST_FOREACH (CTransaction& tx, pblock->vtx)
{
uint256 txHash = tx.GetHash();
@@ -298,25 +300,21 @@ Value getblocktemplate(const Array& params, bool fHelp)
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))
+ Array deps;
+ BOOST_FOREACH (const CTxIn &in, tx.vin)
{
- 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));
+ if (setTxIndex.count(in.prevout.hash))
+ deps.push_back(setTxIndex[in.prevout.hash]);
+ }
+ entry.push_back(Pair("depends", deps));
- int64_t nSigOps = tx.GetLegacySigOpCount();
- nSigOps += tx.GetP2SHSigOpCount(mapInputs);
- entry.push_back(Pair("sigops", nSigOps));
+ int64_t nSigOps = tx.GetLegacySigOpCount();
+ if (tx.HaveInputs(view))
+ {
+ entry.push_back(Pair("fee", (int64_t)(tx.GetValueIn(view) - tx.GetValueOut())));
+ nSigOps += tx.GetP2SHSigOpCount(view);
}
+ entry.push_back(Pair("sigops", nSigOps));
transactions.push_back(entry);
}
@@ -364,18 +362,17 @@ Value submitblock(const Array& params, bool fHelp)
vector<unsigned char> blockData(ParseHex(params[0].get_str()));
CDataStream ssBlock(blockData, SER_NETWORK, PROTOCOL_VERSION);
- CBlock block;
+ CBlock pblock;
try {
- ssBlock >> block;
+ ssBlock >> pblock;
}
catch (std::exception &e) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
}
- bool fAccepted = ProcessBlock(NULL, &block);
+ bool fAccepted = ProcessBlock(NULL, &pblock);
if (!fAccepted)
return "rejected";
return Value::null;
}
-