Skip to content

Commit

Permalink
fix: export genesis error (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
taramakage authored Jul 27, 2023
1 parent 8578510 commit d63bd12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions modules/side-chain/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) {

for _, blockHeader := range data.BlockHeaders {
k.setBlockHeader(ctx, blockHeader.SpaceId, blockHeader.Height, blockHeader.Header)
if blockHeader.TxHash != "" {
k.setBlockHeaderTxHashString(ctx, blockHeader.SpaceId, blockHeader.Height, blockHeader.TxHash)
}
}

for _, spaceLatestHeight := range data.SpaceLatestHeights {
Expand Down
16 changes: 11 additions & 5 deletions modules/side-chain/keeper/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,13 @@ func (k Keeper) GetBlockHeaders(ctx sdk.Context) []types.BlockHeader {
}

for i := 0; i < len(headers); i++ {
txHash, err := k.GetBlockHeaderTxHash(ctx, headers[i].SpaceId, headers[i].Height)
if err != nil {
panic("fail to get block header tx hash")
if k.HasBlockHeaderTxHash(ctx, headers[i].SpaceId, headers[i].Height) {
txHash, err := k.GetBlockHeaderTxHash(ctx, headers[i].SpaceId, headers[i].Height)
if err != nil {
panic("fail to get block header tx hash")
}
headers[i].TxHash = txHash
}
headers[i].TxHash = txHash

}

return headers
Expand Down Expand Up @@ -229,6 +230,11 @@ func (k Keeper) setBlockHeaderTxHash(ctx sdk.Context, spaceId, blockHeight uint6
store.Set(types.BlockHeaderTxHashStoreKey(spaceId, blockHeight), []byte(txHash.String()))
}

func (k Keeper) setBlockHeaderTxHashString(ctx sdk.Context, spaceId, blockHeight uint64, txHashStr string) {
store := ctx.KVStore(k.storeKey)
store.Set(types.BlockHeaderTxHashStoreKey(spaceId, blockHeight), []byte(txHashStr))
}

func (k Keeper) GetSpaceLatestHeights(ctx sdk.Context) []types.SpaceLatestHeight {
latestHeights := make([]types.SpaceLatestHeight, 0)
store := ctx.KVStore(k.storeKey)
Expand Down

0 comments on commit d63bd12

Please sign in to comment.