Skip to content

Commit

Permalink
Update exposed db objects in incentive module
Browse files Browse the repository at this point in the history
  • Loading branch information
samricotta committed Oct 15, 2024
1 parent c6167e5 commit b751b8b
Show file tree
Hide file tree
Showing 5 changed files with 465 additions and 57 deletions.
27 changes: 24 additions & 3 deletions proto/babylon/incentive/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "babylon/incentive/params.proto";
import "babylon/incentive/incentive.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/babylonlabs-io/babylon/x/incentive/types";

Expand Down Expand Up @@ -56,10 +57,30 @@ message QueryBTCStakingGaugeRequest {
uint64 height = 1;
}

message BTCStakingGaugeResponse {
// coins that have been in the gauge
// can have multiple coin denoms
repeated cosmos.base.v1beta1.Coin coins = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];

}

message BTCTimestampingGaugeResponse {
// coins that have been in the gauge
// can have multiple coin denoms
repeated cosmos.base.v1beta1.Coin coins = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];

}

// QueryBTCStakingGaugeResponse is response type for the Query/BTCStakingGauge RPC method.
message QueryBTCStakingGaugeResponse {
// gauge is the BTC staking gauge at the queried height
Gauge gauge = 1;
BTCStakingGaugeResponse gauge = 1;
}

// QueryBTCTimestampingGaugeRequest is request type for the Query/BTCTimestampingGauge RPC method.
Expand All @@ -71,5 +92,5 @@ message QueryBTCTimestampingGaugeRequest {
// QueryBTCTimestampingGaugeResponse is response type for the Query/BTCTimestampingGauge RPC method.
message QueryBTCTimestampingGaugeResponse {
// gauge is the BTC timestamping gauge at the queried epoch
Gauge gauge = 1;
}
BTCTimestampingGaugeResponse gauge = 1;
}
1 change: 1 addition & 0 deletions test/e2e/btc_timestamping_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ func (s *BTCTimestampingTestSuite) Test6InterceptFeeCollector() {
if err != nil {
return false
}
btcTimestampingGauge = response.Gauge
s.T().Logf("BTC timestamping gauge at current epoch %d: %s", curEpoch, btcTimestampingGauge.String())
return !btcTimestampingGauge.Coins.Empty()
}, time.Second*10, time.Second)
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/configurer/chain/queries_incentive.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"
)

func (n *NodeConfig) QueryBTCStakingGauge(height uint64) (*incentivetypes.Gauge, error) {
func (n *NodeConfig) QueryBTCStakingGauge(height uint64) (*incentivetypes.BTCStakingGaugeResponse, error) {
path := fmt.Sprintf("/babylon/incentive/btc_staking_gauge/%d", height)
bz, err := n.QueryGRPCGateway(path, url.Values{})
if err != nil {
Expand Down Expand Up @@ -52,7 +52,7 @@ func (n *NodeConfig) QueryRewardGauge(sAddr sdk.AccAddress) (map[string]*incenti
return resp.RewardGauges, nil
}

func (n *NodeConfig) QueryBTCTimestampingGauge(epoch uint64) (*incentivetypes.Gauge, error) {
func (n *NodeConfig) QueryBTCTimestampingGauge(epoch uint64) (*incentivetypes.BTCTimestampingGaugeResponse, error) {
path := fmt.Sprintf("/babylon/incentive/btc_timestamping_gauge/%d", epoch)
bz, err := n.QueryGRPCGateway(path, url.Values{})
if err != nil {
Expand All @@ -64,5 +64,5 @@ func (n *NodeConfig) QueryBTCTimestampingGauge(epoch uint64) (*incentivetypes.Ga
return nil, err
}

return resp.Gauge, nil
return resp.Gauge.Gauge, nil
}
16 changes: 14 additions & 2 deletions x/incentive/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (k Keeper) BTCStakingGauge(goCtx context.Context, req *types.QueryBTCStakin
return nil, types.ErrBTCStakingGaugeNotFound
}

return &types.QueryBTCStakingGaugeResponse{Gauge: gauge}, nil
return &types.QueryBTCStakingGaugeResponse{Gauge: convertGaugeToBTCStakingResponse(*gauge)}, nil
}

func (k Keeper) BTCTimestampingGauge(goCtx context.Context, req *types.QueryBTCTimestampingGaugeRequest) (*types.QueryBTCTimestampingGaugeResponse, error) {
Expand All @@ -69,5 +69,17 @@ func (k Keeper) BTCTimestampingGauge(goCtx context.Context, req *types.QueryBTCT
return nil, types.ErrBTCTimestampingGaugeNotFound
}

return &types.QueryBTCTimestampingGaugeResponse{Gauge: gauge}, nil
return &types.QueryBTCTimestampingGaugeResponse{Gauge: convertGaugeToBTCTimestampingResponse(*gauge)}, nil
}

func convertGaugeToBTCStakingResponse(gauge types.Gauge) *types.BTCStakingGaugeResponse {
return &types.BTCStakingGaugeResponse{
Coins: gauge.Coins,
}
}

func convertGaugeToBTCTimestampingResponse(gauge types.Gauge) *types.BTCTimestampingGaugeResponse {
return &types.BTCTimestampingGaugeResponse{
Coins: gauge.Coins,
}
}
Loading

0 comments on commit b751b8b

Please sign in to comment.