-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scaffold: map morse_claimable_account --no-message --module migration…
… --index address public_key total_tokens claimed:bool
- Loading branch information
1 parent
67dbfb6
commit f4d445c
Showing
21 changed files
with
5,274 additions
and
131 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
782 changes: 782 additions & 0 deletions
782
api/poktroll/migration/morse_claimable_account.pulsar.go
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] ; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)), | ||
) | ||
} |
Oops, something went wrong.