Skip to content
This repository has been archived by the owner on Mar 2, 2023. It is now read-only.

Commit

Permalink
Check that btcd is running on the right chain
Browse files Browse the repository at this point in the history
We have a similar check in electrum_backend.go. Let's do the same check
for Btcd.
  • Loading branch information
alokmenghrajani committed Oct 14, 2018
1 parent 9a51414 commit c804c8f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions backend/btcd_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ func NewBtcdBackend(maxBlockHeight int64, hostPort, user, pass string, network u
return nil, errors.Wrap(err, "could not create a Btcd RPC client")
}

// Check that we are talking to the right chain
genesis, err := client.GetBlockHash(0)
if err != nil {
return nil, errors.Wrap(err, "GetBlockHash(0) failed")
}
if genesis.String() != utils.GenesisBlock(network) {
return nil, errors.New(fmt.Sprintf("Unexpected genesis block %s != %s", genesis.String(), utils.GenesisBlock(network)))
}
fmt.Printf("%+v\n", genesis)

actualMaxHeight, err := client.GetBlockCount()
maxAllowedHeight := actualMaxHeight - minConfirmations
if err != nil {
Expand Down

0 comments on commit c804c8f

Please sign in to comment.