rpc: make getblock return orphan blocks with confirmation=-1

This commit is contained in:
Roy Lee 2022-08-31 18:00:47 -07:00
parent 2d04d31894
commit 5d7a219e35
2 changed files with 6 additions and 3 deletions

View file

@ -1394,8 +1394,8 @@ func (b *BlockChain) BlockAttributesByHash(hash *chainhash.Hash, prevHash *chain
attrs *BlockAttributes, best *BestState, err error) {
best = b.BestSnapshot()
node := b.index.LookupNode(hash)
if node == nil || !b.bestChain.Contains(node) {
str := fmt.Sprintf("block %s is not in the main chain", hash)
if node == nil {
str := fmt.Sprintf("block %s not found", hash)
return nil, best, errNotInMainChain(str)
}
@ -1405,6 +1405,9 @@ func (b *BlockChain) BlockAttributesByHash(hash *chainhash.Hash, prevHash *chain
MedianTime: node.CalcPastMedianTime(),
ChainWork: node.workSum,
}
if !b.bestChain.Contains(node) {
attrs.Confirmations = -1
}
// Populate prev block hash if there is one.
if node.height > 0 {

View file

@ -1211,7 +1211,7 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i
if err != nil {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCBlockNotFound,
Message: "Block not found",
Message: "Block not found: " + err.Error(),
}
}
// If verbosity is 0, return the serialized block as a hex encoded string.