Skip to content

Commit 9765a50

Browse files
committed
Implement BIP 23 Block Proposal
1 parent 3dcbb9b commit 9765a50

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/rpcmining.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,36 @@ Value getblocktemplate(const Array& params, bool fHelp)
379379
else
380380
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
381381
lpval = find_value(oparam, "longpollid");
382+
383+
if (strMode == "proposal")
384+
{
385+
const Value& dataval = find_value(oparam, "data");
386+
if (dataval.type() != str_type)
387+
throw JSONRPCError(RPC_TYPE_ERROR, "Missing data String key for proposal");
388+
389+
CBlock block;
390+
if (!DecodeHexBlk(block, dataval.get_str()))
391+
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
392+
393+
uint256 hash = block.GetHash();
394+
BlockMap::iterator mi = mapBlockIndex.find(hash);
395+
if (mi != mapBlockIndex.end()) {
396+
CBlockIndex *pindex = mi->second;
397+
if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
398+
return "duplicate";
399+
if (pindex->nStatus & BLOCK_FAILED_MASK)
400+
return "duplicate-invalid";
401+
return "duplicate-inconclusive";
402+
}
403+
404+
CBlockIndex* const pindexPrev = chainActive.Tip();
405+
// TestBlockValidity only supports blocks built on the current Tip
406+
if (block.hashPrevBlock != pindexPrev->GetBlockHash())
407+
return "inconclusive-not-best-prevblk";
408+
CValidationState state;
409+
TestBlockValidity(state, block, pindexPrev, false, true);
410+
return BIP22ValidationResult(state);
411+
}
382412
}
383413

384414
if (strMode != "template")
@@ -481,6 +511,8 @@ Value getblocktemplate(const Array& params, bool fHelp)
481511
UpdateTime(pblock, pindexPrev);
482512
pblock->nNonce = 0;
483513

514+
static const Array aCaps = boost::assign::list_of("proposal");
515+
484516
Array transactions;
485517
map<uint256, int64_t> setTxIndex;
486518
int i = 0;
@@ -527,6 +559,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
527559
}
528560

529561
Object result;
562+
result.push_back(Pair("capabilities", aCaps));
530563
result.push_back(Pair("version", pblock->nVersion));
531564
result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex()));
532565
result.push_back(Pair("transactions", transactions));

0 commit comments

Comments
 (0)