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

Check that btcd is running on the right chain #20

Merged
merged 1 commit into from
Oct 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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