-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: btclightclient: Abstract the usage of btcd types and store BTCH…
…eaderInfo objects (#58)
- Loading branch information
Showing
30 changed files
with
538 additions
and
591 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,21 @@ | ||
package keeper | ||
|
||
import ( | ||
bbl "github.com/babylonchain/babylon/types" | ||
"github.com/babylonchain/babylon/x/btclightclient/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func (k Keeper) GetBaseBTCHeader(ctx sdk.Context) types.BaseBTCHeader { | ||
baseBtcdHeader := k.HeadersState(ctx).GetBaseBTCHeader() | ||
|
||
if baseBtcdHeader == nil { | ||
return types.BaseBTCHeader{} | ||
} | ||
|
||
baseHash := baseBtcdHeader.BlockHash() | ||
height, err := k.HeadersState(ctx).GetHeaderHeight(&baseHash) | ||
|
||
if err != nil { | ||
return types.BaseBTCHeader{} | ||
} | ||
|
||
headerBytes := bbl.NewBTCHeaderBytesFromBlockHeader(baseBtcdHeader) | ||
return types.BaseBTCHeader{Header: &headerBytes, Height: height} | ||
func (k Keeper) GetBaseBTCHeader(ctx sdk.Context) types.BTCHeaderInfo { | ||
baseBtcHeader := k.HeadersState(ctx).GetBaseBTCHeader() | ||
return *baseBtcHeader | ||
} | ||
|
||
// SetBaseBTCHeader checks whether a base BTC header exists and | ||
// if not inserts it into storage | ||
func (k Keeper) SetBaseBTCHeader(ctx sdk.Context, baseBTCHeader types.BaseBTCHeader) { | ||
func (k Keeper) SetBaseBTCHeader(ctx sdk.Context, baseBTCHeader types.BTCHeaderInfo) { | ||
existingHeader := k.HeadersState(ctx).GetBaseBTCHeader() | ||
if existingHeader != nil { | ||
panic("A base BTC Header has already been set") | ||
} | ||
|
||
btcdHeader := baseBTCHeader.Header.ToBlockHeader() | ||
|
||
// The cumulative work for the Base BTC header is only the work | ||
// for that particular header. This means that it is very important | ||
// that no forks will happen that discard the base header because we | ||
// will not be able to detect those. Cumulative work will build based | ||
// on the sum of the work of the chain starting from the base header. | ||
blockWork := types.CalcWork(btcdHeader) | ||
|
||
k.HeadersState(ctx).CreateHeader(btcdHeader, baseBTCHeader.Height, blockWork) | ||
k.HeadersState(ctx).CreateHeader(&baseBTCHeader) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.