Skip to content

Commit

Permalink
Rename functions in global namespace to have the BTC prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
vitsalis committed Jul 8, 2022
1 parent b35999c commit 4134221
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions types/btcutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"github.com/btcsuite/btcd/wire"
)

// ValidateHeader
// ValidateBTCHeader
// Perform the checks that [checkBlockHeaderSanity](https://github.com/btcsuite/btcd/blob/master/blockchain/validate.go#L430) of btcd does
//
// We skip the "timestamp should not be 2 hours into the future" check
// since this might introduce undeterministic behavior
func ValidateHeader(header *wire.BlockHeader, powLimit *big.Int) error {
func ValidateBTCHeader(header *wire.BlockHeader, powLimit *big.Int) error {
msgBlock := &wire.MsgBlock{Header: *header}

block := btcutil.NewBlock(msgBlock)
Expand All @@ -38,20 +38,20 @@ func ValidateHeader(header *wire.BlockHeader, powLimit *big.Int) error {
return nil
}

func GetBaseHeaderHex() string {
func GetBaseBTCHeaderHex() string {
// TODO: get this from a configuration file
hex := "00006020c6c5a20e29da938a252c945411eba594cbeba021a1e20000000000000000000039e4bd0cd0b5232bb380a9576fcfe7d8fb043523f7a158187d9473e44c1740e6b4fa7c62ba01091789c24c22"
return hex
}

func GetBaseHeaderHeight() uint64 {
func GetBaseBTCHeaderHeight() uint64 {
// TODO: get this from a configuration file
height := uint64(736056)
return height
}

func GetBaseHeaderBytes() BTCHeaderBytes {
hex := GetBaseHeaderHex()
func GetBaseBTCHeaderBytes() BTCHeaderBytes {
hex := GetBaseBTCHeaderHex()
headerBytes, err := NewBTCHeaderBytesFromHex(hex)
if err != nil {
panic("Base BTC header hex cannot be converted to bytes")
Expand Down
4 changes: 2 additions & 2 deletions types/btcutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *btcutilsTestSuite) SetupSuite() {
s.testnetPowLimit = btcchaincfg.TestNet3Params.PowLimit
}

func (s *btcutilsTestSuite) TestValidateHeader() {
func (s *btcutilsTestSuite) TestValidateBTCHeader() {
data := []struct {
name string
header *wire.BlockHeader
Expand All @@ -53,7 +53,7 @@ func (s *btcutilsTestSuite) TestValidateHeader() {
}

for _, d := range data {
err := types.ValidateHeader(d.header, d.powLimit)
err := types.ValidateBTCHeader(d.header, d.powLimit)
if d.hasErr {
s.Require().Error(err, d.name)
} else {
Expand Down
2 changes: 1 addition & 1 deletion x/btccheckpoint/btcutils/btcutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func ParseProof(

header := types.BTCHeaderBytes(btcHeader).ToBlockHeader()

e = types.ValidateHeader(header, powLimit)
e = types.ValidateBTCHeader(header, powLimit)

if e != nil {
return nil, e
Expand Down
4 changes: 2 additions & 2 deletions x/btclightclient/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
)

func TestGenesis(t *testing.T) {
headerBytes := bbl.GetBaseHeaderBytes()
height := bbl.GetBaseHeaderHeight()
headerBytes := bbl.GetBaseBTCHeaderBytes()
height := bbl.GetBaseBTCHeaderHeight()

genesisState := types.GenesisState{
Params: types.DefaultParams(),
Expand Down
2 changes: 1 addition & 1 deletion x/btclightclient/types/base_btc_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func FuzzBaseBTCHeader(f *testing.F) {
defaultHeader := bbl.GetBaseHeaderBytes()
defaultHeader := bbl.GetBaseBTCHeaderBytes()
defaultBtcdHeader := defaultHeader.ToBlockHeader()

f.Add(
Expand Down
4 changes: 2 additions & 2 deletions x/btclightclient/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

// DefaultGenesis returns the default Capability genesis state
func DefaultGenesis() *GenesisState {
headerBytes := bbl.GetBaseHeaderBytes()
height := bbl.GetBaseHeaderHeight()
headerBytes := bbl.GetBaseBTCHeaderBytes()
height := bbl.GetBaseBTCHeaderHeight()

return &GenesisState{
Params: DefaultParams(),
Expand Down
2 changes: 1 addition & 1 deletion x/btclightclient/types/header_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func FuzzNewHeaderInfo(f *testing.F) {
defaultHeader := bbl.GetBaseHeaderBytes()
defaultHeader := bbl.GetBaseBTCHeaderBytes()
btcdHeader := defaultHeader.ToBlockHeader()
f.Add(
btcdHeader.Version,
Expand Down
2 changes: 1 addition & 1 deletion x/btclightclient/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (msg *MsgInsertHeader) ValidateBasic() error {
}

func (msg *MsgInsertHeader) ValidateHeader(powLimit *big.Int) error {
return bbl.ValidateHeader(msg.Header.ToBlockHeader(), powLimit)
return bbl.ValidateBTCHeader(msg.Header.ToBlockHeader(), powLimit)
}

func (msg *MsgInsertHeader) GetSigners() []sdk.AccAddress {
Expand Down
2 changes: 1 addition & 1 deletion x/btclightclient/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func FuzzMsgInsertHeader(f *testing.F) {
addressBytes := []byte("from________________")
defaultHeader := bbl.GetBaseHeaderBytes()
defaultHeader := bbl.GetBaseBTCHeaderBytes()
defaultBtcdHeader := defaultHeader.ToBlockHeader()

// Maximum btc difficulty possible
Expand Down

0 comments on commit 4134221

Please sign in to comment.