mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-07 14:46:39 +00:00
add sentinel errors for machine module (#116)
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
94022e1102
commit
4db2fbc43f
@ -2,7 +2,6 @@ package keeper
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
config "github.com/planetmint/planetmint-go/config"
|
config "github.com/planetmint/planetmint-go/config"
|
||||||
@ -13,6 +12,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
"github.com/crgimenes/go-osc"
|
"github.com/crgimenes/go-osc"
|
||||||
|
|
||||||
|
errorsmod "cosmossdk.io/errors"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,21 +36,21 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach
|
|||||||
|
|
||||||
isValidIssuerPlanetmint := validateExtendedPublicKey(msg.Machine.IssuerPlanetmint, config.PlmntNetParams)
|
isValidIssuerPlanetmint := validateExtendedPublicKey(msg.Machine.IssuerPlanetmint, config.PlmntNetParams)
|
||||||
if !isValidIssuerPlanetmint {
|
if !isValidIssuerPlanetmint {
|
||||||
return nil, errors.New("invalid planetmint key")
|
return nil, errorsmod.Wrap(types.ErrInvalidKey, "planetmint")
|
||||||
}
|
}
|
||||||
isValidIssuerLiquid := validateExtendedPublicKey(msg.Machine.IssuerLiquid, config.LiquidNetParams)
|
isValidIssuerLiquid := validateExtendedPublicKey(msg.Machine.IssuerLiquid, config.LiquidNetParams)
|
||||||
if !isValidIssuerLiquid {
|
if !isValidIssuerLiquid {
|
||||||
return nil, errors.New("invalid liquid key")
|
return nil, errorsmod.Wrap(types.ErrInvalidKey, "liquid")
|
||||||
}
|
}
|
||||||
if k.isNFTCreationRequest(msg.Machine) {
|
if k.isNFTCreationRequest(msg.Machine) {
|
||||||
err := k.issueMachineNFT(msg.Machine)
|
err := k.issueMachineNFT(msg.Machine)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("an error occurred while issuing the machine NFT")
|
return nil, types.ErrNFTIssuanceFailed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.Machine.GetType() == 0 { // 0 == RDDL_MACHINE_UNDEFINED
|
if msg.Machine.GetType() == 0 { // 0 == RDDL_MACHINE_UNDEFINED
|
||||||
return nil, errors.New("the machine type has to be defined")
|
return nil, types.ErrMachineTypeUndefined
|
||||||
}
|
}
|
||||||
|
|
||||||
k.StoreMachine(ctx, *msg.Machine)
|
k.StoreMachine(ctx, *msg.Machine)
|
||||||
|
@ -3,7 +3,6 @@ package keeper
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/planetmint/planetmint-go/x/machine/types"
|
"github.com/planetmint/planetmint-go/x/machine/types"
|
||||||
|
|
||||||
@ -15,12 +14,12 @@ func (k msgServer) RegisterTrustAnchor(goCtx context.Context, msg *types.MsgRegi
|
|||||||
|
|
||||||
isValidTrustAnchorPubkey := validatePublicKey(msg.TrustAnchor.Pubkey)
|
isValidTrustAnchorPubkey := validatePublicKey(msg.TrustAnchor.Pubkey)
|
||||||
if !isValidTrustAnchorPubkey {
|
if !isValidTrustAnchorPubkey {
|
||||||
return nil, errors.New("invalid trust anchor pubkey")
|
return nil, types.ErrInvalidTrustAnchorKey
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, found := k.GetTrustAnchor(ctx, msg.TrustAnchor.Pubkey)
|
_, _, found := k.GetTrustAnchor(ctx, msg.TrustAnchor.Pubkey)
|
||||||
if found {
|
if found {
|
||||||
return nil, errors.New("trust anchor is already registered")
|
return nil, types.ErrTrustAnchorAlreadyRegistered
|
||||||
}
|
}
|
||||||
|
|
||||||
err := k.StoreTrustAnchor(ctx, *msg.TrustAnchor, false)
|
err := k.StoreTrustAnchor(ctx, *msg.TrustAnchor, false)
|
||||||
|
@ -52,7 +52,7 @@ func TestMsgServerAttestMachineInvalidLiquidKey(t *testing.T) {
|
|||||||
_, err := msgServer.RegisterTrustAnchor(ctx, taMsg)
|
_, err := msgServer.RegisterTrustAnchor(ctx, taMsg)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
_, err = msgServer.AttestMachine(ctx, msg)
|
_, err = msgServer.AttestMachine(ctx, msg)
|
||||||
assert.EqualError(t, err, "invalid liquid key")
|
assert.EqualError(t, err, "liquid: invalid key")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMsgServerRegisterTrustAnchor(t *testing.T) {
|
func TestMsgServerRegisterTrustAnchor(t *testing.T) {
|
||||||
|
@ -12,4 +12,9 @@ var (
|
|||||||
ErrTrustAnchorNotFound = errorsmod.Register(ModuleName, 3, "trust anchor not found")
|
ErrTrustAnchorNotFound = errorsmod.Register(ModuleName, 3, "trust anchor not found")
|
||||||
ErrTrustAnchorAlreadyInUse = errorsmod.Register(ModuleName, 4, "trust anchor already in use")
|
ErrTrustAnchorAlreadyInUse = errorsmod.Register(ModuleName, 4, "trust anchor already in use")
|
||||||
ErrMachineIsNotCreator = errorsmod.Register(ModuleName, 5, "the machine.address is no the message creator address")
|
ErrMachineIsNotCreator = errorsmod.Register(ModuleName, 5, "the machine.address is no the message creator address")
|
||||||
|
ErrInvalidKey = errorsmod.Register(ModuleName, 6, "invalid key")
|
||||||
|
ErrNFTIssuanceFailed = errorsmod.Register(ModuleName, 7, "an error occurred while issuing the machine NFT")
|
||||||
|
ErrMachineTypeUndefined = errorsmod.Register(ModuleName, 8, "the machine type has to be defined")
|
||||||
|
ErrInvalidTrustAnchorKey = errorsmod.Register(ModuleName, 9, "invalid trust anchor pubkey")
|
||||||
|
ErrTrustAnchorAlreadyRegistered = errorsmod.Register(ModuleName, 10, "trust anchor is already registered")
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user