[NOD-356] Add indication in getBlock that a block is an orphan. (#437)

This commit is contained in:
stasatdaglabs 2019-10-29 15:53:56 +02:00 committed by Dan Aharoni
parent 7c9f5a65d8
commit 8ea97aa3fd
2 changed files with 10 additions and 0 deletions

View File

@ -65,6 +65,7 @@ const (
ErrRPCSubnetworkNotFound RPCErrorCode = -5
ErrRPCRawTxString RPCErrorCode = -32602
ErrRPCDecodeHexString RPCErrorCode = -22
ErrRPCOrphanBlock RPCErrorCode = -6
)
// Errors that are specific to btcd.

View File

@ -22,6 +22,15 @@ func handleGetBlock(s *Server, cmd interface{}, closeChan <-chan struct{}) (inte
if err != nil {
return nil, rpcDecodeHexError(c.Hash)
}
// Return an appropriate error if the block is an orphan
if s.cfg.DAG.IsKnownOrphan(hash) {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCOrphanBlock,
Message: "Block is an orphan",
}
}
var blkBytes []byte
err = s.cfg.DB.View(func(dbTx database.Tx) error {
var err error