aboutsummaryrefslogtreecommitdiff
path: root/src/rpcmining.cpp
diff options
context:
space:
mode:
authorLuke Dashjr <luke-jr+git@utopios.org>2014-10-30 02:56:33 +0000
committerLuke Dashjr <luke-jr+git@utopios.org>2014-11-18 19:20:10 +0000
commit3dcbb9b6b488f077d4ab7e4296dffbf3aea4a0fb (patch)
tree287a28eb494933d9b41cb50c77f9bdd81f9ce066 /src/rpcmining.cpp
parent132ea9b48f65dcb4784a7e9688f3b194d5578c80 (diff)
Abstract DecodeHexBlk and BIP22ValidationResult functions out of submitblock
Diffstat (limited to 'src/rpcmining.cpp')
-rw-r--r--src/rpcmining.cpp42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp
index 879a504115..577f377796 100644
--- a/src/rpcmining.cpp
+++ b/src/rpcmining.cpp
@@ -283,6 +283,25 @@ Value prioritisetransaction(const Array& params, bool fHelp)
}
+// NOTE: Assumes a conclusive result; if result is inconclusive, it must be handled by caller
+static Value BIP22ValidationResult(const CValidationState& state)
+{
+ if (state.IsValid())
+ return Value::null;
+
+ std::string strRejectReason = state.GetRejectReason();
+ if (state.IsError())
+ throw JSONRPCError(RPC_VERIFY_ERROR, strRejectReason);
+ if (state.IsInvalid())
+ {
+ if (strRejectReason.empty())
+ return "rejected";
+ return strRejectReason;
+ }
+ // Should be impossible
+ return "valid?";
+}
+
Value getblocktemplate(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1)
@@ -566,15 +585,9 @@ Value submitblock(const Array& params, bool fHelp)
+ HelpExampleRpc("submitblock", "\"mydata\"")
);
- vector<unsigned char> blockData(ParseHex(params[0].get_str()));
- CDataStream ssBlock(blockData, SER_NETWORK, PROTOCOL_VERSION);
CBlock pblock;
- try {
- ssBlock >> pblock;
- }
- catch (const std::exception &) {
+ if (!DecodeHexBlk(pblock, params[0].get_str()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
- }
CValidationState state;
submitblock_StateCatcher sc(pblock.GetHash());
@@ -587,20 +600,7 @@ Value submitblock(const Array& params, bool fHelp)
return "inconclusive";
state = sc.state;
}
- if (state.IsError())
- {
- std::string strRejectReason = state.GetRejectReason();
- throw JSONRPCError(RPC_VERIFY_ERROR, strRejectReason);
- }
- if (state.IsInvalid())
- {
- std::string strRejectReason = state.GetRejectReason();
- if (strRejectReason.empty())
- return "rejected";
- return strRejectReason;
- }
-
- return Value::null;
+ return BIP22ValidationResult(state);
}
Value estimatefee(const Array& params, bool fHelp)