Skip to content

Commit

Permalink
scaffold: map morse_claimable_account --no-message --module migration…
Browse files Browse the repository at this point in the history
… --index address public_key total_tokens claimed:bool
  • Loading branch information
bryanchriswhite committed Feb 12, 2025
1 parent 67dbfb6 commit f4d445c
Show file tree
Hide file tree
Showing 21 changed files with 5,274 additions and 131 deletions.
215 changes: 187 additions & 28 deletions api/poktroll/migration/genesis.pulsar.go

Large diffs are not rendered by default.

782 changes: 782 additions & 0 deletions api/poktroll/migration/morse_claimable_account.pulsar.go

Large diffs are not rendered by default.

2,225 changes: 2,182 additions & 43 deletions api/poktroll/migration/query.pulsar.go

Large diffs are not rendered by default.

80 changes: 79 additions & 1 deletion api/poktroll/migration/query_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions proto/poktroll/migration/genesis.proto
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
syntax = "proto3";

package poktroll.migration;

import "amino/amino.proto";
import "gogoproto/gogo.proto";
import "poktroll/migration/params.proto";
import "poktroll/migration/morse_claimable_account.proto";

option go_package = "github.com/pokt-network/poktroll/x/migration/types";
option (gogoproto.stable_marshaler_all) = true;

// GenesisState defines the migration module's genesis state.
message GenesisState {

// params defines all the parameters of the module.
Params params = 1 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
Params params = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
repeated MorseClaimableAccount morseClaimableAccountList = 2 [(gogoproto.nullable) = false] ;
}

13 changes: 13 additions & 0 deletions proto/poktroll/migration/morse_claimable_account.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
syntax = "proto3";
package poktroll.migration;

option go_package = "github.com/pokt-network/poktroll/x/migration/types";

message MorseClaimableAccount {
string address = 1;
string publicKey = 2;
string totalTokens = 3;
bool claimed = 4;

}

43 changes: 36 additions & 7 deletions proto/poktroll/migration/query.proto
Original file line number Diff line number Diff line change
@@ -1,31 +1,60 @@
syntax = "proto3";

package poktroll.migration;

import "amino/amino.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "poktroll/migration/params.proto";
import "poktroll/migration/morse_claimable_account.proto";

option go_package = "github.com/pokt-network/poktroll/x/migration/types";
option (gogoproto.stable_marshaler_all) = true;

// Query defines the gRPC querier service.
service Query {

// Parameters queries the parameters of the module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
rpc Params (QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/pokt-network/poktroll/migration/params";

}

// Queries a list of MorseClaimableAccount items.
rpc MorseClaimableAccount (QueryGetMorseClaimableAccountRequest) returns (QueryGetMorseClaimableAccountResponse) {
option (google.api.http).get = "/pokt-network/poktroll/migration/morse_claimable_account/{address}";

}
rpc MorseClaimableAccountAll (QueryAllMorseClaimableAccountRequest) returns (QueryAllMorseClaimableAccountResponse) {
option (google.api.http).get = "/pokt-network/poktroll/migration/morse_claimable_account";

}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {

// params holds all the parameters of this module.
Params params = 1 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
}
Params params = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

message QueryGetMorseClaimableAccountRequest {
string address = 1;
}

message QueryGetMorseClaimableAccountResponse {
MorseClaimableAccount morseClaimableAccount = 1 [(gogoproto.nullable) = false];
}

message QueryAllMorseClaimableAccountRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllMorseClaimableAccountResponse {
repeated MorseClaimableAccount morseClaimableAccount = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

70 changes: 70 additions & 0 deletions x/migration/keeper/morse_claimable_account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package keeper

import (
"context"

"cosmossdk.io/store/prefix"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/pokt-network/poktroll/x/migration/types"
)

// SetMorseClaimableAccount set a specific morseClaimableAccount in the store from its index
func (k Keeper) SetMorseClaimableAccount(ctx context.Context, morseClaimableAccount types.MorseClaimableAccount) {
storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.MorseClaimableAccountKeyPrefix))
b := k.cdc.MustMarshal(&morseClaimableAccount)
store.Set(types.MorseClaimableAccountKey(
morseClaimableAccount.Address,
), b)
}

// GetMorseClaimableAccount returns a morseClaimableAccount from its index
func (k Keeper) GetMorseClaimableAccount(
ctx context.Context,
address string,

) (val types.MorseClaimableAccount, found bool) {
storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.MorseClaimableAccountKeyPrefix))

b := store.Get(types.MorseClaimableAccountKey(
address,
))
if b == nil {
return val, false
}

k.cdc.MustUnmarshal(b, &val)
return val, true
}

// RemoveMorseClaimableAccount removes a morseClaimableAccount from the store
func (k Keeper) RemoveMorseClaimableAccount(
ctx context.Context,
address string,

) {
storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.MorseClaimableAccountKeyPrefix))
store.Delete(types.MorseClaimableAccountKey(
address,
))
}

// GetAllMorseClaimableAccount returns all morseClaimableAccount
func (k Keeper) GetAllMorseClaimableAccount(ctx context.Context) (list []types.MorseClaimableAccount) {
storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.MorseClaimableAccountKeyPrefix))
iterator := storetypes.KVStorePrefixIterator(store, []byte{})

defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
var val types.MorseClaimableAccount
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}

return
}
63 changes: 63 additions & 0 deletions x/migration/keeper/morse_claimable_account_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package keeper_test

import (
"context"
"strconv"
"testing"

keepertest "github.com/pokt-network/poktroll/testutil/keeper"
"github.com/pokt-network/poktroll/testutil/nullify"
"github.com/pokt-network/poktroll/x/migration/keeper"
"github.com/pokt-network/poktroll/x/migration/types"
"github.com/stretchr/testify/require"
)

// Prevent strconv unused error
var _ = strconv.IntSize

func createNMorseClaimableAccount(keeper keeper.Keeper, ctx context.Context, n int) []types.MorseClaimableAccount {
items := make([]types.MorseClaimableAccount, n)
for i := range items {
items[i].Address = strconv.Itoa(i)

keeper.SetMorseClaimableAccount(ctx, items[i])
}
return items
}

func TestMorseClaimableAccountGet(t *testing.T) {
keeper, ctx := keepertest.MigrationKeeper(t)
items := createNMorseClaimableAccount(keeper, ctx, 10)
for _, item := range items {
rst, found := keeper.GetMorseClaimableAccount(ctx,
item.Address,
)
require.True(t, found)
require.Equal(t,
nullify.Fill(&item),
nullify.Fill(&rst),
)
}
}
func TestMorseClaimableAccountRemove(t *testing.T) {
keeper, ctx := keepertest.MigrationKeeper(t)
items := createNMorseClaimableAccount(keeper, ctx, 10)
for _, item := range items {
keeper.RemoveMorseClaimableAccount(ctx,
item.Address,
)
_, found := keeper.GetMorseClaimableAccount(ctx,
item.Address,
)
require.False(t, found)
}
}

func TestMorseClaimableAccountGetAll(t *testing.T) {
keeper, ctx := keepertest.MigrationKeeper(t)
items := createNMorseClaimableAccount(keeper, ctx, 10)
require.ElementsMatch(t,
nullify.Fill(items),
nullify.Fill(keeper.GetAllMorseClaimableAccount(ctx)),
)
}
Loading

0 comments on commit f4d445c

Please sign in to comment.