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

Commit

Permalink
Merge pull request #20 from square/alok/btcd_genesis_check
Browse files Browse the repository at this point in the history
Check that btcd is running on the right chain
  • Loading branch information
mbyczkowski committed Oct 15, 2018
2 parents 690db13 + c804c8f commit 614e62b
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 614e62b

Please sign in to comment.