Skip to content

Commit

Permalink
rpc: make getblock return orphan blocks with confirmation=-1
Browse files Browse the repository at this point in the history
  • Loading branch information
roylee17 committed Sep 1, 2022
1 parent 2d04d31 commit 5d7a219
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions blockchain/chain.go
Expand Up @@ -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)
}

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion rpcserver.go
Expand Up @@ -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.
Expand Down

0 comments on commit 5d7a219

Please sign in to comment.