Skip to content

Commit

Permalink
add back client registerCounterparty
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaSripal committed Jan 13, 2025
1 parent 9b38e61 commit e1167c9
Show file tree
Hide file tree
Showing 12 changed files with 1,086 additions and 4 deletions.
39 changes: 39 additions & 0 deletions modules/core/02-client/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,45 @@ func (k *Keeper) SetClientState(ctx context.Context, clientID string, clientStat
store.Set(host.ClientStateKey(), types.MustMarshalClientState(k.cdc, clientState))
}

// GetClientCreator returns the creator of a client
func (k *Keeper) GetClientCreator(ctx context.Context, clientID string) sdk.AccAddress {
store := k.ClientStore(ctx, clientID)
bz := store.Get(types.CreatorKey())
if len(bz) == 0 {
return nil
}
return sdk.AccAddress(bz)
}

// SetClientCreator sets the creator of a client
func (k *Keeper) SetClientCreator(ctx context.Context, clientID string, creator sdk.AccAddress) {
store := k.ClientStore(ctx, clientID)
store.Set(types.CreatorKey(), creator.Bytes())
}

// DeleteClientCreator deletes the creator of a client
func (k *Keeper) DeleteClientCreator(ctx context.Context, clientID string) {
store := k.ClientStore(ctx, clientID)
store.Delete(types.CreatorKey())
}

func (k *Keeper) SetClientCounterparty(ctx context.Context, clientID string, counterparty types.CounterpartyInfo) {
store := k.ClientStore(ctx, clientID)
store.Set(types.CounterpartyKey(), k.cdc.MustMarshal(&counterparty))
}

func (k *Keeper) GetClientCounterparty(ctx context.Context, clientID string) (types.CounterpartyInfo, bool) {
store := k.ClientStore(ctx, clientID)
bz := store.Get(types.CounterpartyKey())
if len(bz) == 0 {
return types.CounterpartyInfo{}, false
}

var counterparty types.CounterpartyInfo
k.cdc.MustUnmarshal(bz, &counterparty)
return counterparty, true
}

// GetClientConsensusState gets the stored consensus state from a client at a given height.
func (k *Keeper) GetClientConsensusState(ctx context.Context, clientID string, height exported.Height) (exported.ConsensusState, bool) {
store := k.ClientStore(ctx, clientID)
Expand Down
19 changes: 19 additions & 0 deletions modules/core/02-client/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,25 @@ func (suite *KeeperTestSuite) TestSetClientState() {
suite.Require().Equal(clientState, retrievedState, "Client states are not equal")
}

func (suite *KeeperTestSuite) TestSetClientCreator() {
creator := suite.chainA.SenderAccount.GetAddress()
suite.keeper.SetClientCreator(suite.ctx, testClientID, creator)
getCreator := suite.keeper.GetClientCreator(suite.ctx, testClientID)
suite.Require().Equal(creator, getCreator)
suite.keeper.DeleteClientCreator(suite.ctx, testClientID)
getCreator = suite.keeper.GetClientCreator(suite.ctx, testClientID)
suite.Require().Equal(sdk.AccAddress(nil), getCreator)
}

func (suite *KeeperTestSuite) TestSetClientCounterparty() {
counterparty := types.NewCounterpartyInfo([][]byte{[]byte("ibc"), []byte("channel-7")})
suite.keeper.SetClientCounterparty(suite.ctx, testClientID, counterparty)

retrievedCounterparty, found := suite.keeper.GetClientCounterparty(suite.ctx, testClientID)
suite.Require().True(found, "GetCounterparty failed")
suite.Require().Equal(counterparty, retrievedCounterparty, "Counterparties are not equal")
}

func (suite *KeeperTestSuite) TestSetClientConsensusState() {
suite.keeper.SetClientConsensusState(suite.ctx, testClientID, testClientHeight, suite.consensusState)

Expand Down
7 changes: 7 additions & 0 deletions modules/core/02-client/types/counterparty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package types

func NewCounterpartyInfo(counterpartyMessagingKey [][]byte) CounterpartyInfo {
return CounterpartyInfo{
CounterpartyMessagingKey: counterpartyMessagingKey,
}
}
Loading

0 comments on commit e1167c9

Please sign in to comment.