Skip to content

Commit

Permalink
add back protos, fix app imports
Browse files Browse the repository at this point in the history
  • Loading branch information
nullpointer0x00 committed Apr 11, 2024
1 parent ce56620 commit 704de1c
Show file tree
Hide file tree
Showing 11 changed files with 12,016 additions and 90 deletions.
7 changes: 1 addition & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,10 @@ import (
oraclekeeper "github.com/provenance-io/provenance/x/oracle/keeper"
oraclemodule "github.com/provenance-io/provenance/x/oracle/module"
oracletypes "github.com/provenance-io/provenance/x/oracle/types"
<<<<<<< HEAD
=======
rewardkeeper "github.com/provenance-io/provenance/x/reward/keeper"
rewardmodule "github.com/provenance-io/provenance/x/reward/module"
rewardtypes "github.com/provenance-io/provenance/x/reward/types"

"github.com/provenance-io/provenance/x/sanction"
sanctionkeeper "github.com/provenance-io/provenance/x/sanction/keeper"
sanctionmodule "github.com/provenance-io/provenance/x/sanction/module"
>>>>>>> main
triggerkeeper "github.com/provenance-io/provenance/x/trigger/keeper"
triggermodule "github.com/provenance-io/provenance/x/trigger/module"
triggertypes "github.com/provenance-io/provenance/x/trigger/types"
Expand Down
84 changes: 0 additions & 84 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/provenance-io/provenance/app/params"
"github.com/provenance-io/provenance/internal"
"github.com/provenance-io/provenance/internal/pioconfig"
)
Expand Down Expand Up @@ -513,86 +512,3 @@ func NewPubKeyFromHex(pk string) (res cryptotypes.PubKey) {
}
return &ed25519.PubKey{Key: pkBytes}
}
<<<<<<< HEAD
=======

// SetupWithGenesisRewardsProgram initializes a new SimApp with the provided
// rewards programs, genesis accounts, validators, and balances.
func SetupWithGenesisRewardsProgram(t *testing.T, nextRewardProgramID uint64, genesisRewards []rewardtypes.RewardProgram, genAccs []authtypes.GenesisAccount, valSet *cmttypes.ValidatorSet, balances ...banktypes.Balance) *App {
t.Helper()

// Make sure there's a validator set with at least one validator in it.
if valSet == nil || len(valSet.Validators) == 0 {
privVal := mock.NewPV()
pubKey, err := privVal.GetPubKey()
require.NoError(t, err)
validator := cmttypes.NewValidator(pubKey, 1)
if valSet == nil {
valSet = cmttypes.NewValidatorSet([]*cmttypes.Validator{validator})
} else {
require.NoError(t, valSet.UpdateWithChangeSet([]*cmttypes.Validator{validator}))
}
}

app, genesisState := setup(t, true, 0, "")
genesisState = genesisStateWithValSet(t, app, genesisState, valSet, genAccs, balances...)
genesisState = genesisStateWithRewards(t, app, genesisState, nextRewardProgramID, genesisRewards)

stateBytes, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(t, err, "marshaling genesis state to json")

_, err = app.InitChain(
&abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
ConsensusParams: DefaultConsensusParams,
AppStateBytes: stateBytes,
},
)
require.NoError(t, err, "InitChain")

_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{
Height: app.LastBlockHeight() + 1,
Hash: app.LastCommitID().Hash,
NextValidatorsHash: valSet.Hash(),
Time: time.Now().UTC(),
})
require.NoError(t, err, "FinalizeBlock")

return app
}

func genesisStateWithRewards(t *testing.T,
app *App, genesisState GenesisState,
nextRewardProgramID uint64, genesisRewards []rewardtypes.RewardProgram,
) GenesisState {
rewardGenesisState := rewardtypes.NewGenesisState(
nextRewardProgramID,
genesisRewards,
[]rewardtypes.ClaimPeriodRewardDistribution{},
[]rewardtypes.RewardAccountState{},
)
var err error
genesisState[rewardtypes.ModuleName], err = app.AppCodec().MarshalJSON(rewardGenesisState)
require.NoError(t, err, "marshaling reward genesis state JSON")
return genesisState
}

// MakeTestEncodingConfig creates an encoding config suitable for unit tests.
func MakeTestEncodingConfig(t *testing.T) params.EncodingConfig {
tempDir, err := os.MkdirTemp("", "tempprovapp")
switch {
case t != nil:
require.NoError(t, err, "failed to create temp dir %q", tempDir)
case err != nil:
panic(fmt.Errorf("failed to create temp dir %q: %w", tempDir, err))
}
defer os.RemoveAll(tempDir)

tempApp := New(log.NewNopLogger(), dbm.NewMemDB(), nil, true, nil,
tempDir,
0,
simtestutil.EmptyAppOptions{},
)
return tempApp.GetEncodingConfig()
}
>>>>>>> main
24 changes: 24 additions & 0 deletions proto/provenance/reward/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
syntax = "proto3";
package provenance.reward.v1;

import "gogoproto/gogo.proto";
import "provenance/reward/v1/reward.proto";

option go_package = "github.com/provenance-io/provenance/x/reward/types";
option java_package = "io.provenance.reward.v1";
option java_multiple_files = true;

// GenesisState defines the reward module's genesis state.
message GenesisState {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// Reward program id is the next auto incremented id to be assigned to the next created reward program
uint64 reward_program_id = 1;
// Reward programs to initially start with.
repeated RewardProgram reward_programs = 2 [(gogoproto.nullable) = false];
// Claim period reward distributions to initially start with.
repeated ClaimPeriodRewardDistribution claim_period_reward_distributions = 3 [(gogoproto.nullable) = false];
// Reward account states to initially start with.
repeated RewardAccountState reward_account_states = 4 [(gogoproto.nullable) = false];
}
152 changes: 152 additions & 0 deletions proto/provenance/reward/v1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
syntax = "proto3";
package provenance.reward.v1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "provenance/reward/v1/reward.proto";

option go_package = "github.com/provenance-io/provenance/x/reward/types";
option java_package = "io.provenance.reward.v1";
option java_multiple_files = true;

// Query defines the gRPC querier service for reward module.
service Query {

// RewardProgramByID returns a reward program matching the ID.
rpc RewardProgramByID(QueryRewardProgramByIDRequest) returns (QueryRewardProgramByIDResponse) {
option (google.api.http).get = "/provenance/rewards/v1/reward_programs/{id}";
}
// RewardPrograms returns a list of reward programs matching the query type.
rpc RewardPrograms(QueryRewardProgramsRequest) returns (QueryRewardProgramsResponse) {
option (google.api.http).get = "/provenance/rewards/v1/reward_programs";
}

// ClaimPeriodRewardDistributions returns a list of claim period reward distributions matching the claim_status.
rpc ClaimPeriodRewardDistributions(QueryClaimPeriodRewardDistributionsRequest)
returns (QueryClaimPeriodRewardDistributionsResponse) {
option (google.api.http).get = "/provenance/rewards/v1/claim_period_reward_distributions";
}

// ClaimPeriodRewardDistributionsByID returns a claim period reward distribution matching the ID.
rpc ClaimPeriodRewardDistributionsByID(QueryClaimPeriodRewardDistributionsByIDRequest)
returns (QueryClaimPeriodRewardDistributionsByIDResponse) {
option (google.api.http).get =
"/provenance/rewards/v1/claim_period_reward_distributions/{reward_id}/claim_periods/{claim_period_id}";
}

// RewardDistributionsByAddress returns a list of reward claims belonging to the account and matching the claim
// status.
rpc RewardDistributionsByAddress(QueryRewardDistributionsByAddressRequest)
returns (QueryRewardDistributionsByAddressResponse) {
option (google.api.http).get = "/provenance/rewards/v1/reward_claims/{address}";
}
}

// QueryRewardProgramByIDRequest queries for the Reward Program with an identifier of id
message QueryRewardProgramByIDRequest {
// The id of the reward program to query.
uint64 id = 1;
}

// QueryRewardProgramByIDResponse contains the requested RewardProgram
message QueryRewardProgramByIDResponse {
// The reward program object that was queried for.
RewardProgram reward_program = 1;
}

// QueryRewardProgramsRequest queries for all reward programs matching the query_type
message QueryRewardProgramsRequest {
// QueryType is the state of reward program to query
enum QueryType {
// unspecified type
QUERY_TYPE_UNSPECIFIED = 0;
// all reward programs states
QUERY_TYPE_ALL = 1;
// pending reward program state=
QUERY_TYPE_PENDING = 2;
// active reward program state
QUERY_TYPE_ACTIVE = 3;
// pending and active reward program states
QUERY_TYPE_OUTSTANDING = 4;
// finished reward program state
QUERY_TYPE_FINISHED = 5;
}
// A filter on the types of reward programs.
QueryType query_type = 1;
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 99;
}

// QueryRewardProgramsResponse contains the list of RewardPrograms matching the query
message QueryRewardProgramsResponse {
// List of RewardProgram objects matching the query_type.
repeated RewardProgram reward_programs = 1 [(gogoproto.nullable) = false];
// pagination defines an optional pagination for the response.
cosmos.base.query.v1beta1.PageResponse pagination = 99;
}

// QueryClaimPeriodRewardDistributionsRequest queries for all the ClaimPeriodRewardDistributions with pagination.
message QueryClaimPeriodRewardDistributionsRequest {
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 99;
}

// QueryClaimPeriodRewardDistributionsResponse returns the list of paginated ClaimPeriodRewardDistributions
message QueryClaimPeriodRewardDistributionsResponse {
// List of all ClaimPeriodRewardDistribution objects queried for.
repeated ClaimPeriodRewardDistribution claim_period_reward_distributions = 1 [(gogoproto.nullable) = false];
// pagination defines an optional pagination for the response.
cosmos.base.query.v1beta1.PageResponse pagination = 99;
}

// QueryClaimPeriodRewardDistributionsByIDRequest queries for a single ClaimPeriodRewardDistribution
message QueryClaimPeriodRewardDistributionsByIDRequest {
// The reward program that the claim period reward distribution belongs to.
uint64 reward_id = 1;
// The claim period that the claim period reward distribution was created for.
uint64 claim_period_id = 2;
}

// QueryClaimPeriodRewardDistributionsByIDResponse returns the requested ClaimPeriodRewardDistribution
message QueryClaimPeriodRewardDistributionsByIDResponse {
// The ClaimPeriodRewardDistribution object that was queried for.
ClaimPeriodRewardDistribution claim_period_reward_distribution = 1;
}

// QueryRewardDistributionsByAddressRequest queries for reward claims by address that match the claim_status.
message QueryRewardDistributionsByAddressRequest {
// The address that the claim belongs to.
string address = 1;
// The status that the reward account must have.
RewardAccountState.ClaimStatus claim_status = 2;
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 99;
}

// QueryRewardDistributionsByAddressResponse returns the reward claims for an address that match the claim_status.
message QueryRewardDistributionsByAddressResponse {
// The address that the reward account belongs to.
string address = 1;
// List of RewardAccounts queried for.
repeated RewardAccountResponse reward_account_state = 2 [(gogoproto.nullable) = false];
// pagination defines an optional pagination for the response.
cosmos.base.query.v1beta1.PageResponse pagination = 99;
}

// RewardAccountResponse is an address' reward claim for a reward program's claim period.
message RewardAccountResponse {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = true;

// The id of the reward program that this claim belongs to.
uint64 reward_program_id = 1;

// total rewards claimed for all eligible claim periods in program.
cosmos.base.v1beta1.Coin total_reward_claim = 2 [(gogoproto.nullable) = false];
// The status of the claim.
RewardAccountState.ClaimStatus claim_status = 3;
// The claim period that the claim belongs to.
uint64 claim_id = 4;
}
Loading

0 comments on commit 704de1c

Please sign in to comment.