added query and fixed linter aspects

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2025-05-21 12:36:56 +02:00
parent 24ac3eca63
commit 94710dd5df
No known key found for this signature in database
13 changed files with 46 additions and 42 deletions

View File

@ -15,6 +15,7 @@ import (
// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string) *cobra.Command {
_ = queryRoute
// Group der queries under a subcommand
cmd := &cobra.Command{
Use: types.ModuleName,

View File

@ -1,7 +1,6 @@
package cli
import (
"fmt"
"time"
"github.com/spf13/cobra"
@ -15,16 +14,11 @@ var (
DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds())
)
const (
flagPacketTimeoutTimestamp = "packet-timeout-timestamp"
listSeparator = ","
)
// GetTxCmd returns the transaction commands for this module
func GetTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName),
Short: types.ModuleName + " transactions subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,

View File

@ -0,0 +1,20 @@
package keeper
import (
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/util"
)
// storeAsset is a helper for storing any asset type.
func (k Keeper) storeAsset(ctx sdk.Context, keyPrefix []byte, zigbeeID string, value []byte) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), keyPrefix)
store.Set(util.SerializeString(zigbeeID), value)
}
// lookupAsset is a helper for looking up any asset type.
func (k Keeper) lookupAsset(ctx sdk.Context, keyPrefix []byte, zigbeeID string) (bz []byte, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), keyPrefix)
bz = store.Get(util.SerializeString(zigbeeID))
return bz, bz != nil
}

View File

@ -1,27 +1,21 @@
package keeper
import (
"github.com/planetmint/planetmint-go/util"
"github.com/planetmint/planetmint-go/x/der/types"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/x/der/types"
)
func (k Keeper) StoreDerAttest(ctx sdk.Context, asset types.DER) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.DerAssetKey))
appendValue := k.cdc.MustMarshal(&asset)
store.Set(util.SerializeString(asset.ZigbeeID), appendValue)
k.storeAsset(ctx, types.KeyPrefix(types.DerAssetKey), asset.ZigbeeID, appendValue)
}
func (k Keeper) LookupDerAsset(ctx sdk.Context, zigbeeID string) (val types.DER, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.DerAssetKey))
derAsset := store.Get(util.SerializeString(zigbeeID))
if derAsset == nil {
bz, found := k.lookupAsset(ctx, types.KeyPrefix(types.DerAssetKey), zigbeeID)
if !found {
return val, false
}
if err := k.cdc.Unmarshal(derAsset, &val); err != nil {
if err := k.cdc.Unmarshal(bz, &val); err != nil {
return val, false
}
return val, true

View File

@ -1,8 +1,6 @@
package keeper
import (
"fmt"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
@ -47,5 +45,5 @@ func NewKeeper(
}
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
return ctx.Logger().With("module", "x/"+types.ModuleName)
}

View File

@ -1,27 +1,21 @@
package keeper
import (
"github.com/planetmint/planetmint-go/util"
"github.com/planetmint/planetmint-go/x/der/types"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/x/der/types"
)
func (k Keeper) StoreLiquidDerAttest(ctx sdk.Context, asset types.LiquidDerAsset) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.LiquidDerAssetKey))
appendValue := k.cdc.MustMarshal(&asset)
store.Set(util.SerializeString(asset.ZigbeeID), appendValue)
k.storeAsset(ctx, types.KeyPrefix(types.LiquidDerAssetKey), asset.ZigbeeID, appendValue)
}
func (k Keeper) LookupLiquidDerAsset(ctx sdk.Context, zigbeeID string) (val types.LiquidDerAsset, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.LiquidDerAssetKey))
derAsset := store.Get(util.SerializeString(zigbeeID))
if derAsset == nil {
bz, found := k.lookupAsset(ctx, types.KeyPrefix(types.LiquidDerAssetKey), zigbeeID)
if !found {
return val, false
}
if err := k.cdc.Unmarshal(derAsset, &val); err != nil {
if err := k.cdc.Unmarshal(bz, &val); err != nil {
return val, false
}
return val, true

View File

@ -40,9 +40,7 @@ func (k msgServer) handleDERNFTIssuance(goCtx context.Context, der *types.DER, p
if err != nil {
logger.Error(ctx, err, "DER NFT issuance failed")
return
}
} else {
logger.Info(ctx, "DER NFT issuance successful: "+der.ZigbeeID)
return
}
}

View File

@ -7,6 +7,7 @@ import (
// GetParams get all parameters as types.Params
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
_ = ctx
return types.NewParams()
}

View File

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
// this line is used by starport scaffolding # 1
"github.com/grpc-ecosystem/grpc-gateway/runtime"
@ -62,6 +63,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
var genState types.GenesisState
_ = config
if err := cdc.UnmarshalJSON(bz, &genState); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}
@ -70,7 +72,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
_ = types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
}
// GetTxCmd returns the root Tx command for the module. The subcommands of this root command are used by end-users to generate new transactions containing messages defined in the module

View File

@ -51,7 +51,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {}
// ProposalContents doesn't return any content functions for governance proposals.
func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent {
func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg {
return nil
}

View File

@ -3,10 +3,10 @@ package types
// DONTCOVER
import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
errorsmod "cosmossdk.io/errors"
)
// x/der module sentinel errors
var (
ErrSample = sdkerrors.Register(ModuleName, 1100, "sample error")
ErrSample = errorsmod.Register(ModuleName, 1100, "sample error")
)

View File

@ -1,6 +1,7 @@
package types
import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
@ -40,7 +41,7 @@ func (msg *MsgNotarizeLiquidDerAsset) GetSignBytes() []byte {
func (msg *MsgNotarizeLiquidDerAsset) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
return nil
}

View File

@ -1,6 +1,7 @@
package types
import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
@ -40,7 +41,7 @@ func (msg *MsgRegisterDER) GetSignBytes() []byte {
func (msg *MsgRegisterDER) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
return nil
}