diff options
Diffstat (limited to 'src/rpcmining.cpp')
-rw-r--r-- | src/rpcmining.cpp | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 8af3c46348..879a504115 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -527,6 +527,24 @@ Value getblocktemplate(const Array& params, bool fHelp) return result; } +class submitblock_StateCatcher : public CValidationInterface +{ +public: + uint256 hash; + bool found; + CValidationState state; + + submitblock_StateCatcher(const uint256 &hashIn) : hash(hashIn), found(false), state() {}; + +protected: + virtual void BlockChecked(const CBlock& block, const CValidationState& stateIn) { + if (block.GetHash() != hash) + return; + found = true; + state = stateIn; + }; +}; + Value submitblock(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) @@ -559,9 +577,28 @@ Value submitblock(const Array& params, bool fHelp) } CValidationState state; - bool fAccepted = ProcessBlock(state, NULL, &pblock); - if (!fAccepted) - return "rejected"; // TODO: report validation state + submitblock_StateCatcher sc(pblock.GetHash()); + RegisterValidationInterface(&sc); + bool fAccepted = ProcessNewBlock(state, NULL, &pblock); + UnregisterValidationInterface(&sc); + if (fAccepted) + { + if (!sc.found) + 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; } |