[wip] laconic module fixes

- msg & query servers

- clean up logging, errors

- don't use sdk global config
This commit is contained in:
Roy Crihfield 2024-12-01 20:05:51 +08:00
parent 72a93dec2f
commit b55e05e4ec
22 changed files with 649 additions and 635 deletions

View File

@ -1,9 +1,5 @@
package params package params
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
const ( const (
CoinUnit = "lnt" CoinUnit = "lnt"
BaseCoinUnit = "alnt" BaseCoinUnit = "alnt"
@ -29,7 +25,6 @@ var (
) )
func init() { func init() {
SetAddressPrefixes()
RegisterDenoms() RegisterDenoms()
} }
@ -45,10 +40,3 @@ func RegisterDenoms() {
// panic(err) // panic(err)
// } // }
} }
func SetAddressPrefixes() {
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
}

View File

@ -100,7 +100,7 @@ func (tf *TestFixture) Setup(t *testing.T) error {
accountsModKeeper, accountsModKeeper,
maccPerms, maccPerms,
utils.NewAddressCodec(), utils.NewAddressCodec(),
sdk.GetConfig().GetBech32AccountAddrPrefix(), params.Bech32PrefixAccAddr,
authority.String(), authority.String(),
) )

View File

@ -5,18 +5,17 @@ import (
errorsmod "cosmossdk.io/errors" errorsmod "cosmossdk.io/errors"
addresscodec "github.com/cosmos/cosmos-sdk/codec/address" addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
_ "git.vdb.to/cerc-io/laconicd/app/params" // import for side-effects "git.vdb.to/cerc-io/laconicd/app/params"
) )
type addressCodec struct { type addressCodec struct {
bech32codec address.Codec address.Codec
} }
func (ac addressCodec) StringToBytes(text string) ([]byte, error) { func (ac addressCodec) StringToBytes(text string) ([]byte, error) {
bz, err := ac.bech32codec.StringToBytes(text) bz, err := ac.Codec.StringToBytes(text)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -27,24 +26,28 @@ func (ac addressCodec) StringToBytes(text string) ([]byte, error) {
return bz, nil return bz, nil
} }
func (ac addressCodec) BytesToString(bz []byte) (string, error) {
return ac.bech32codec.BytesToString(bz)
}
func NewAddressCodec() address.Codec { func NewAddressCodec() address.Codec {
return addressCodec{ return addressCodec{
bech32codec: addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), Codec: addresscodec.NewBech32Codec(params.Bech32PrefixAccAddr),
} }
} }
func NewValAddressCodec() address.ValidatorAddressCodec { func NewValAddressCodec() address.ValidatorAddressCodec {
return addressCodec{ return addressCodec{
bech32codec: addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), Codec: addresscodec.NewBech32Codec(params.Bech32PrefixValAddr),
} }
} }
func NewConsAddressCodec() address.ConsensusAddressCodec { func NewConsAddressCodec() address.ConsensusAddressCodec {
return addressCodec{ return addressCodec{
bech32codec: addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()), Codec: addresscodec.NewBech32Codec(params.Bech32PrefixConsAddr),
} }
} }
func MustBytesToString(ac address.Codec, bz []byte) string {
str, err := ac.BytesToString(bz)
if err != nil {
panic(err)
}
return str
}

View File

@ -3,12 +3,15 @@ package utils
import ( import (
"fmt" "fmt"
"cosmossdk.io/core/gas"
"cosmossdk.io/log" "cosmossdk.io/log"
storetypes "cosmossdk.io/store/types" storetypes "cosmossdk.io/store/types"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
) )
const RefundModuleGasDescriptor = "laconic module gas refund"
func CtxWithCustomKVGasConfig(ctx *sdk.Context) *sdk.Context { func CtxWithCustomKVGasConfig(ctx *sdk.Context) *sdk.Context {
updatedCtx := ctx.WithKVGasConfig(storetypes.GasConfig{ updatedCtx := ctx.WithKVGasConfig(storetypes.GasConfig{
HasCost: 0, HasCost: 0,
@ -23,7 +26,16 @@ func CtxWithCustomKVGasConfig(ctx *sdk.Context) *sdk.Context {
return &updatedCtx return &updatedCtx
} }
func LogTxGasConsumed(ctx sdk.Context, logger log.Logger, tx string) { func LogTxGasConsumed(gm gas.Meter, logger log.Logger, method string) {
gasConsumed := ctx.GasMeter().GasConsumed() gasConsumed := gm.Consumed()
logger.Info("tx executed", "method", tx, "gas_consumed", fmt.Sprintf("%d", gasConsumed)) logger.Info("tx executed", "method", method, "gas_consumed", fmt.Sprintf("%d", gasConsumed))
}
func TrackGasConsumption(meter gas.Meter) func(log.Logger, string) {
startGas := meter.Consumed()
return func(logger log.Logger, method string) {
endGas := meter.Consumed()
meter.Refund(endGas-startGas, RefundModuleGasDescriptor)
LogTxGasConsumed(meter, logger, method)
}
} }

38
utils/modules.go Normal file
View File

@ -0,0 +1,38 @@
package utils
import (
coreaddress "cosmossdk.io/core/address"
errorsmod "cosmossdk.io/errors"
govtypes "cosmossdk.io/x/gov/types"
"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// AddressOrModuleAddress returns with this precedence:
// - the preferred address if it is valid, or
// - a module address with the preferred name, or
// - a module address with the alt name
func AddressOrModuleAddress(preferred, alt string) types.AccAddress {
if preferred != "" {
addrCodec := NewAddressCodec()
if addr, err := addrCodec.StringToBytes(preferred); err == nil {
return addr
}
return address.Module(preferred)
}
return address.Module(alt)
}
func CheckAuthorityAddress(ac coreaddress.Codec, expected sdk.AccAddress, msgaddr string) error {
authority, err := ac.StringToBytes(msgaddr)
if err != nil {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msgaddr)
}
if !expected.Equals(types.AccAddress(authority)) {
return errorsmod.Wrapf(govtypes.ErrInvalidSigner,
"invalid authority; expected %s, got %s", MustBytesToString(ac, expected), msgaddr)
}
return nil
}

View File

@ -5,12 +5,12 @@ import (
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"slices" "slices"
"time" "time"
"cosmossdk.io/collections" "cosmossdk.io/collections"
"cosmossdk.io/collections/indexes" "cosmossdk.io/collections/indexes"
"cosmossdk.io/core/address"
"cosmossdk.io/core/appmodule" "cosmossdk.io/core/appmodule"
errorsmod "cosmossdk.io/errors" errorsmod "cosmossdk.io/errors"
"cosmossdk.io/log" "cosmossdk.io/log"
@ -18,6 +18,7 @@ import (
bank "cosmossdk.io/x/bank/keeper" bank "cosmossdk.io/x/bank/keeper"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
auth "github.com/cosmos/cosmos-sdk/x/auth/keeper" auth "github.com/cosmos/cosmos-sdk/x/auth/keeper"
@ -68,11 +69,11 @@ func newBidsIndexes(sb *collections.SchemaBuilder) BidsIndexes {
type Keeper struct { type Keeper struct {
appmodule.Environment appmodule.Environment
cdc codec.BinaryCodec cdc codec.BinaryCodec
logger log.Logger logger log.Logger
// addressCodec address.Codec //TODO addressCodec address.Codec
authority string authority types.AccAddress
// External keepers // External keepers
accountKeeper auth.AccountKeeper accountKeeper auth.AccountKeeper
@ -96,20 +97,17 @@ type Keeper struct {
func NewKeeper( func NewKeeper(
env appmodule.Environment, env appmodule.Environment,
cdc codec.BinaryCodec, cdc codec.BinaryCodec,
addressCodec address.Codec,
accountKeeper auth.AccountKeeper, accountKeeper auth.AccountKeeper,
bankKeeper bank.Keeper, bankKeeper bank.Keeper,
authority string, authority types.AccAddress,
logger log.Logger, logger log.Logger,
) *Keeper { ) *Keeper {
// ensure that authority is a valid AccAddress
if _, err := accountKeeper.AddressCodec().StringToBytes(authority); err != nil {
panic("authority is not a valid acc address")
}
sb := collections.NewSchemaBuilder(env.KVStoreService) sb := collections.NewSchemaBuilder(env.KVStoreService)
k := Keeper{ k := Keeper{
Environment: env, Environment: env,
cdc: cdc, cdc: cdc,
addressCodec: addressCodec,
logger: logger.With(log.ModuleKey, "x/"+auctiontypes.ModuleName), logger: logger.With(log.ModuleKey, "x/"+auctiontypes.ModuleName),
authority: authority, authority: authority,
accountKeeper: accountKeeper, accountKeeper: accountKeeper,
@ -265,7 +263,7 @@ func (k Keeper) GetAuctionById(ctx context.Context, id string) (auctiontypes.Auc
auction, err := k.Auctions.Get(ctx, id) auction, err := k.Auctions.Get(ctx, id)
if err != nil { if err != nil {
if errors.Is(err, collections.ErrNotFound) { if errors.Is(err, collections.ErrNotFound) {
return auctiontypes.Auction{}, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction not found.") return auctiontypes.Auction{}, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction not found")
} }
return auctiontypes.Auction{}, err return auctiontypes.Auction{}, err
} }
@ -343,7 +341,7 @@ func (k Keeper) CreateAuction(ctx context.Context, msg auctiontypes.MsgCreateAuc
sdkErr := k.bankKeeper.SendCoinsFromAccountToModule(ctx, signerAddress, auctiontypes.ModuleName, sdk.NewCoins(totalLockedAmount)) sdkErr := k.bankKeeper.SendCoinsFromAccountToModule(ctx, signerAddress, auctiontypes.ModuleName, sdk.NewCoins(totalLockedAmount))
if sdkErr != nil { if sdkErr != nil {
return nil, errorsmod.Wrap(sdkErr, "Auction error transferring maximum price amount") return nil, errorsmod.Wrap(sdkErr, "Error transferring maximum price amount")
} }
} }
@ -375,7 +373,7 @@ func (k Keeper) CommitBid(ctx context.Context, msg auctiontypes.MsgCommitBid) (*
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction not found.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction not found")
} }
auction, err := k.GetAuctionById(ctx, msg.AuctionId) auction, err := k.GetAuctionById(ctx, msg.AuctionId)
@ -384,7 +382,7 @@ func (k Keeper) CommitBid(ctx context.Context, msg auctiontypes.MsgCommitBid) (*
} }
if auction.Status != auctiontypes.AuctionStatusCommitPhase { if auction.Status != auctiontypes.AuctionStatusCommitPhase {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction is not in commit phase.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction is not in commit phase")
} }
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
@ -442,7 +440,7 @@ func (k Keeper) RevealBid(ctx context.Context, msg auctiontypes.MsgRevealBid) (*
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction not found.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction not found")
} }
auction, err := k.GetAuctionById(ctx, msg.AuctionId) auction, err := k.GetAuctionById(ctx, msg.AuctionId)
@ -451,7 +449,7 @@ func (k Keeper) RevealBid(ctx context.Context, msg auctiontypes.MsgRevealBid) (*
} }
if auction.Status != auctiontypes.AuctionStatusRevealPhase { if auction.Status != auctiontypes.AuctionStatusRevealPhase {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction is not in reveal phase.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction is not in reveal phase")
} }
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
@ -466,7 +464,7 @@ func (k Keeper) RevealBid(ctx context.Context, msg auctiontypes.MsgRevealBid) (*
} }
if !bidExists { if !bidExists {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bid not found.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bid not found")
} }
bid, err := k.GetBid(ctx, msg.AuctionId, msg.Signer) bid, err := k.GetBid(ctx, msg.AuctionId, msg.Signer)
@ -475,65 +473,65 @@ func (k Keeper) RevealBid(ctx context.Context, msg auctiontypes.MsgRevealBid) (*
} }
if bid.Status != auctiontypes.BidStatusCommitted { if bid.Status != auctiontypes.BidStatusCommitted {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bid not in committed state.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bid not in committed state")
} }
revealBytes, err := hex.DecodeString(msg.Reveal) revealBytes, err := hex.DecodeString(msg.Reveal)
if err != nil { if err != nil {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal string.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal string")
} }
cid, err := utils.CIDFromJSONBytes(revealBytes) cid, err := utils.CIDFromJSONBytes(revealBytes)
if err != nil { if err != nil {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal JSON.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal JSON")
} }
if bid.CommitHash != cid { if bid.CommitHash != cid {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Commit hash mismatch.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Commit hash mismatch")
} }
var reveal map[string]interface{} var reveal map[string]interface{}
err = json.Unmarshal(revealBytes, &reveal) err = json.Unmarshal(revealBytes, &reveal)
if err != nil { if err != nil {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Reveal JSON unmarshal error.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Reveal JSON unmarshal error")
} }
headerInfo := k.HeaderService.HeaderInfo(ctx) headerInfo := k.HeaderService.HeaderInfo(ctx)
chainId, err := utils.GetAttributeAsString(reveal, "chainId") chainId, err := utils.GetAttributeAsString(reveal, "chainId")
if err != nil || chainId != headerInfo.ChainID { if err != nil || chainId != headerInfo.ChainID {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal chainID.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal chainID")
} }
auctionId, err := utils.GetAttributeAsString(reveal, "auctionId") auctionId, err := utils.GetAttributeAsString(reveal, "auctionId")
if err != nil || auctionId != msg.AuctionId { if err != nil || auctionId != msg.AuctionId {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal auction Id.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal auction Id")
} }
bidderAddress, err := utils.GetAttributeAsString(reveal, "bidderAddress") bidderAddress, err := utils.GetAttributeAsString(reveal, "bidderAddress")
if err != nil { if err != nil {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal bid address.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal bid address")
} }
if bidderAddress != msg.Signer { if bidderAddress != msg.Signer {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Reveal bid address mismatch.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Reveal bid address mismatch")
} }
bidAmountStr, err := utils.GetAttributeAsString(reveal, "bidAmount") bidAmountStr, err := utils.GetAttributeAsString(reveal, "bidAmount")
if err != nil { if err != nil {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal bid amount.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal bid amount")
} }
bidAmount, err := sdk.ParseCoinNormalized(bidAmountStr) bidAmount, err := sdk.ParseCoinNormalized(bidAmountStr)
if err != nil { if err != nil {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal bid amount.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal bid amount")
} }
if auction.Kind == auctiontypes.AuctionKindVickrey && bidAmount.IsLT(auction.MinimumBid) { if auction.Kind == auctiontypes.AuctionKindVickrey && bidAmount.IsLT(auction.MinimumBid) {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bid is lower than minimum bid.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bid is lower than minimum bid")
} }
if auction.Kind == auctiontypes.AuctionKindProvider && auction.MaxPrice.IsLT(bidAmount) { if auction.Kind == auctiontypes.AuctionKindProvider && auction.MaxPrice.IsLT(bidAmount) {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bid is higher than max price.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bid is higher than max price")
} }
// Lock bid amount. // Lock bid amount.
@ -555,11 +553,6 @@ func (k Keeper) RevealBid(ctx context.Context, msg auctiontypes.MsgRevealBid) (*
return &auction, nil return &auction, nil
} }
// GetAuthority returns the x/auction module's authority.
func (k Keeper) GetAuthority() string {
return k.authority
}
// GetParams gets the auction module's parameters. // GetParams gets the auction module's parameters.
func (k Keeper) GetParams(ctx context.Context) (*auctiontypes.Params, error) { func (k Keeper) GetParams(ctx context.Context) (*auctiontypes.Params, error) {
params, err := k.Params.Get(ctx) params, err := k.Params.Get(ctx)
@ -610,7 +603,7 @@ func (k Keeper) processAuctionPhases(ctx context.Context) error {
return err return err
} }
k.logger.Info(fmt.Sprintf("Moved auction %s to reveal phase.", auction.Id)) k.logger.Info("Moved auction to reveal phase", "id", auction.Id)
} }
// Reveal -> Expired state. // Reveal -> Expired state.
@ -620,7 +613,7 @@ func (k Keeper) processAuctionPhases(ctx context.Context) error {
return err return err
} }
k.logger.Info(fmt.Sprintf("Moved auction %s to expired state.", auction.Id)) k.logger.Info("Moved auction to expired state", "id", auction.Id)
} }
// If auction has expired, pick a winner from revealed bids. // If auction has expired, pick a winner from revealed bids.
@ -651,7 +644,7 @@ func (k Keeper) deleteCompletedAuctions(ctx context.Context) error {
} }
for _, auction := range auctions { for _, auction := range auctions {
k.logger.Info(fmt.Sprintf("Deleting completed auction %s after timeout.", auction.Id)) k.logger.Info("Deleting completed auction after timeout", "id", auction.Id)
if err := k.DeleteAuction(ctx, *auction); err != nil { if err := k.DeleteAuction(ctx, *auction); err != nil {
return err return err
} }
@ -662,7 +655,8 @@ func (k Keeper) deleteCompletedAuctions(ctx context.Context) error {
// Pick winner for vickrey auction // Pick winner for vickrey auction
func (k Keeper) pickAuctionWinner(ctx context.Context, auction *auctiontypes.Auction) error { func (k Keeper) pickAuctionWinner(ctx context.Context, auction *auctiontypes.Auction) error {
k.logger.Info(fmt.Sprintf("Picking auction %s winner.", auction.Id)) logger := k.logger.With("id", auction.Id)
logger.Info("Picking auction winner")
var highestBid *auctiontypes.Bid var highestBid *auctiontypes.Bid
var secondHighestBid *auctiontypes.Bid var secondHighestBid *auctiontypes.Bid
@ -673,38 +667,38 @@ func (k Keeper) pickAuctionWinner(ctx context.Context, auction *auctiontypes.Auc
} }
for _, bid := range bids { for _, bid := range bids {
k.logger.Info(fmt.Sprintf("Processing bid %s %s", bid.BidderAddress, bid.BidAmount.String())) logger.Info("Processing bid", "address", bid.BidderAddress, "amount", bid.BidAmount)
// Only consider revealed bids. // Only consider revealed bids.
if bid.Status != auctiontypes.BidStatusRevealed { if bid.Status != auctiontypes.BidStatusRevealed {
k.logger.Info(fmt.Sprintf("Ignoring unrevealed bid %s %s", bid.BidderAddress, bid.BidAmount.String())) logger.Info("Ignoring unrevealed bid", "address", bid.BidderAddress, "amount", bid.BidAmount)
continue continue
} }
// Init highest bid. // Init highest bid.
if highestBid == nil { if highestBid == nil {
highestBid = bid highestBid = bid
k.logger.Info(fmt.Sprintf("Initializing 1st bid %s %s", bid.BidderAddress, bid.BidAmount.String())) logger.Info("Initializing 1st bid", "address", bid.BidderAddress, "amount", bid.BidAmount)
continue continue
} }
//nolint: all //nolint: all
if highestBid.BidAmount.IsLT(bid.BidAmount) { if highestBid.BidAmount.IsLT(bid.BidAmount) {
k.logger.Info(fmt.Sprintf("New highest bid %s %s", bid.BidderAddress, bid.BidAmount.String())) logger.Info("New highest bid", "address", bid.BidderAddress, "amount", bid.BidAmount)
secondHighestBid = highestBid secondHighestBid = highestBid
highestBid = bid highestBid = bid
k.logger.Info(fmt.Sprintf("Updated 1st bid %s %s", highestBid.BidderAddress, highestBid.BidAmount.String())) logger.Info("Updated 1st bid", "address", highestBid.BidderAddress, "amount", highestBid.BidAmount)
k.logger.Info(fmt.Sprintf("Updated 2nd bid %s %s", secondHighestBid.BidderAddress, secondHighestBid.BidAmount.String())) logger.Info("Updated 2nd bid", "address", secondHighestBid.BidderAddress, "amount", secondHighestBid.BidAmount)
} else if secondHighestBid == nil || secondHighestBid.BidAmount.IsLT(bid.BidAmount) { } else if secondHighestBid == nil || secondHighestBid.BidAmount.IsLT(bid.BidAmount) {
k.logger.Info(fmt.Sprintf("New 2nd highest bid %s %s", bid.BidderAddress, bid.BidAmount.String())) logger.Info("New 2nd highest bid", "address", bid.BidderAddress, "amount", bid.BidAmount)
secondHighestBid = bid secondHighestBid = bid
k.logger.Info(fmt.Sprintf("Updated 2nd bid %s %s", secondHighestBid.BidderAddress, secondHighestBid.BidAmount.String())) logger.Info("Updated 2nd bid", "address", secondHighestBid.BidderAddress, "amount", secondHighestBid.BidAmount)
} else { } else {
k.logger.Info(fmt.Sprintf("Ignoring bid as it doesn't affect 1st/2nd price %s %s", bid.BidderAddress, bid.BidAmount.String())) logger.Info("Ignoring bid as it doesn't affect 1st/2nd price", "address", bid.BidderAddress, "amount", bid.BidAmount)
} }
} }
@ -720,11 +714,12 @@ func (k Keeper) pickAuctionWinner(ctx context.Context, auction *auctiontypes.Auc
if secondHighestBid != nil { if secondHighestBid != nil {
auction.WinningPrice = secondHighestBid.BidAmount auction.WinningPrice = secondHighestBid.BidAmount
} }
k.logger.Info(fmt.Sprintf("Auction %s winner %s.", auction.Id, auction.WinnerAddresses[0])) logger.Info("Auction winner chosen",
k.logger.Info(fmt.Sprintf("Auction %s winner bid %s.", auction.Id, auction.WinningBids[0].String())) "address", auction.WinnerAddresses[0],
k.logger.Info(fmt.Sprintf("Auction %s winning price %s.", auction.Id, auction.WinningPrice.String())) "bid", auction.WinningBids[0],
"price", auction.WinningPrice)
} else { } else {
k.logger.Info(fmt.Sprintf("Auction %s has no valid revealed bids (no winner).", auction.Id)) logger.Info("Auction has no valid revealed bids (no winner)")
} }
if err := k.SaveAuction(ctx, auction); err != nil { if err := k.SaveAuction(ctx, auction); err != nil {
@ -736,15 +731,15 @@ func (k Keeper) pickAuctionWinner(ctx context.Context, auction *auctiontypes.Auc
for _, bid := range bids { for _, bid := range bids {
bidderAddress, err := addrCodec.StringToBytes(bid.BidderAddress) bidderAddress, err := addrCodec.StringToBytes(bid.BidderAddress)
if err != nil { if err != nil {
k.logger.Error(fmt.Sprintf("Invalid bidderAddress address. %v", err)) logger.Error("Invalid bidderAddress address", "error", err)
panic("Invalid bidder address.") panic("Invalid bidder address")
} }
if bid.Status == auctiontypes.BidStatusRevealed { if bid.Status == auctiontypes.BidStatusRevealed {
// Send reveal fee back to bidders that've revealed the bid. // Send reveal fee back to bidders that've revealed the bid.
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, auctiontypes.ModuleName, bidderAddress, sdk.NewCoins(bid.RevealFee)) sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, auctiontypes.ModuleName, bidderAddress, sdk.NewCoins(bid.RevealFee))
if sdkErr != nil { if sdkErr != nil {
k.logger.Error(fmt.Sprintf("Auction error returning reveal fee: %v", sdkErr)) logger.Error("Error returning reveal fee", "error", sdkErr)
panic(sdkErr) panic(sdkErr)
} }
} }
@ -752,7 +747,7 @@ func (k Keeper) pickAuctionWinner(ctx context.Context, auction *auctiontypes.Auc
// Send back locked bid amount to all bidders. // Send back locked bid amount to all bidders.
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, auctiontypes.ModuleName, bidderAddress, sdk.NewCoins(bid.BidAmount)) sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, auctiontypes.ModuleName, bidderAddress, sdk.NewCoins(bid.BidAmount))
if sdkErr != nil { if sdkErr != nil {
k.logger.Error(fmt.Sprintf("Auction error returning bid amount: %v", sdkErr)) logger.Error("Error returning bid amount", "error", sdkErr)
panic(sdkErr) panic(sdkErr)
} }
} }
@ -761,22 +756,22 @@ func (k Keeper) pickAuctionWinner(ctx context.Context, auction *auctiontypes.Auc
if len(auction.WinnerAddresses) != 0 { if len(auction.WinnerAddresses) != 0 {
winnerAddress, err := addrCodec.StringToBytes(auction.WinnerAddresses[0]) winnerAddress, err := addrCodec.StringToBytes(auction.WinnerAddresses[0])
if err != nil { if err != nil {
k.logger.Error(fmt.Sprintf("Invalid winner address. %v", err)) logger.Error("Invalid winner address", "error", err)
panic("Invalid winner address.") panic("Invalid winner address")
} }
// Take 2nd price from winner. // Take 2nd price from winner.
sdkErr := k.bankKeeper.SendCoinsFromAccountToModule(ctx, winnerAddress, auctiontypes.ModuleName, sdk.NewCoins(auction.WinningPrice)) sdkErr := k.bankKeeper.SendCoinsFromAccountToModule(ctx, winnerAddress, auctiontypes.ModuleName, sdk.NewCoins(auction.WinningPrice))
if sdkErr != nil { if sdkErr != nil {
k.logger.Error(fmt.Sprintf("Auction error taking funds from winner: %v", sdkErr)) logger.Error("Error taking funds from winner", "error", sdkErr)
panic(sdkErr) panic(sdkErr)
} }
// Burn anything over the min. bid amount. // Burn anything over the min. bid amount.
amountToBurn := auction.WinningPrice.Sub(auction.MinimumBid) amountToBurn := auction.WinningPrice.Sub(auction.MinimumBid)
if amountToBurn.IsNegative() { if amountToBurn.IsNegative() {
k.logger.Error("Auction coins to burn cannot be negative.") logger.Error("Auction coins to burn cannot be negative")
panic("Auction coins to burn cannot be negative.") panic("Auction coins to burn cannot be negative")
} }
// Use auction burn module account instead of actually burning coins to better keep track of supply. // Use auction burn module account instead of actually burning coins to better keep track of supply.
@ -787,15 +782,15 @@ func (k Keeper) pickAuctionWinner(ctx context.Context, auction *auctiontypes.Auc
sdk.NewCoins(amountToBurn), sdk.NewCoins(amountToBurn),
) )
if sdkErr != nil { if sdkErr != nil {
k.logger.Error(fmt.Sprintf("Auction error burning coins: %v", sdkErr)) logger.Error("Error burning coins", "error", sdkErr)
panic(sdkErr) panic(sdkErr)
} }
} }
// Notify other modules (hook). // Notify other modules (hook).
k.logger.Info(fmt.Sprintf("Auction %s notifying %d modules.", auction.Id, len(k.usageKeepers))) // k.logger.Info(fmt.Sprintf("Auction notifying %d modules", len(k.usageKeepers)))
for _, keeper := range k.usageKeepers { for _, keeper := range k.usageKeepers {
k.logger.Info(fmt.Sprintf("Auction %s notifying module %s.", auction.Id, keeper.ModuleName())) logger.Info("Auction notifying module", "module", keeper.ModuleName())
keeper.OnAuctionWinnerSelected(ctx, auction.Id, uint64(k.HeaderService.HeaderInfo(ctx).Height)) keeper.OnAuctionWinnerSelected(ctx, auction.Id, uint64(k.HeaderService.HeaderInfo(ctx).Height))
} }
@ -804,7 +799,8 @@ func (k Keeper) pickAuctionWinner(ctx context.Context, auction *auctiontypes.Auc
// Pick winner for provider auction // Pick winner for provider auction
func (k Keeper) pickProviderAuctionWinners(ctx context.Context, auction *auctiontypes.Auction) error { func (k Keeper) pickProviderAuctionWinners(ctx context.Context, auction *auctiontypes.Auction) error {
k.logger.Info(fmt.Sprintf("Picking auction %s winners.", auction.Id)) logger := k.logger.With("id", auction.Id)
logger.Info("Picking auction winners", auction.Id)
bids, err := k.GetBids(ctx, auction.Id) bids, err := k.GetBids(ctx, auction.Id)
if err != nil { if err != nil {
@ -813,11 +809,11 @@ func (k Keeper) pickProviderAuctionWinners(ctx context.Context, auction *auction
revealedBids := make([]*auctiontypes.Bid, 0, len(bids)) revealedBids := make([]*auctiontypes.Bid, 0, len(bids))
for _, bid := range bids { for _, bid := range bids {
k.logger.Info(fmt.Sprintf("Processing bid %s %s", bid.BidderAddress, bid.BidAmount.String())) logger.Info("Processing bid", "address", bid.BidderAddress, "amount", bid.BidAmount)
// Only consider revealed bids. // Only consider revealed bids.
if bid.Status != auctiontypes.BidStatusRevealed { if bid.Status != auctiontypes.BidStatusRevealed {
k.logger.Info(fmt.Sprintf("Ignoring unrevealed bid %s %s", bid.BidderAddress, bid.BidAmount.String())) logger.Info("Ignoring unrevealed bid", "address", bid.BidderAddress, "amount", bid.BidAmount)
continue continue
} }
@ -858,11 +854,11 @@ func (k Keeper) pickProviderAuctionWinners(ctx context.Context, auction *auction
auction.WinningPrice = winnerBids[len(winnerBids)-1].BidAmount auction.WinningPrice = winnerBids[len(winnerBids)-1].BidAmount
for _, bid := range winnerBids { for _, bid := range winnerBids {
k.logger.Info(fmt.Sprintf("Auction %s winner address: %s, bid amount: %s.", auction.Id, bid.BidderAddress, bid.BidAmount.String())) logger.Info("Auction winner", "address", bid.BidderAddress, "bid", bid.BidAmount)
} }
k.logger.Info(fmt.Sprintf("Auction %s winning price %s.", auction.Id, auction.WinningPrice.String())) logger.Info("Auction winning price", "price", auction.WinningPrice)
} else { } else {
k.logger.Info(fmt.Sprintf("Auction %s has no valid revealed bids (no winner).", auction.Id)) logger.Info("Auction has no valid revealed bids (no winner)")
} }
if err := k.SaveAuction(ctx, auction); err != nil { if err := k.SaveAuction(ctx, auction); err != nil {
@ -874,15 +870,15 @@ func (k Keeper) pickProviderAuctionWinners(ctx context.Context, auction *auction
for _, bid := range bids { for _, bid := range bids {
bidderAddress, err := addrCodec.StringToBytes(bid.BidderAddress) bidderAddress, err := addrCodec.StringToBytes(bid.BidderAddress)
if err != nil { if err != nil {
k.logger.Error(fmt.Sprintf("Invalid bidderAddress address. %v", err)) logger.Error("Invalid bidderAddress address", "error", err)
panic("Invalid bidder address.") panic("Invalid bidder address")
} }
if bid.Status == auctiontypes.BidStatusRevealed { if bid.Status == auctiontypes.BidStatusRevealed {
// Send reveal fee back to bidders that've revealed the bid. // Send reveal fee back to bidders that've revealed the bid.
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, auctiontypes.ModuleName, bidderAddress, sdk.NewCoins(bid.RevealFee)) sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, auctiontypes.ModuleName, bidderAddress, sdk.NewCoins(bid.RevealFee))
if sdkErr != nil { if sdkErr != nil {
k.logger.Error(fmt.Sprintf("Auction error returning reveal fee: %v", sdkErr)) logger.Error("Error returning reveal fee", "error", sdkErr)
panic(sdkErr) panic(sdkErr)
} }
} }
@ -896,8 +892,8 @@ func (k Keeper) pickProviderAuctionWinners(ctx context.Context, auction *auction
ownerAccAddress, err := addrCodec.StringToBytes(auction.OwnerAddress) ownerAccAddress, err := addrCodec.StringToBytes(auction.OwnerAddress)
if err != nil { if err != nil {
k.logger.Error(fmt.Sprintf("Invalid auction owner address. %v", err)) logger.Error("Invalid auction owner address", "error", err)
panic("Invalid auction owner address.") panic("Invalid auction owner address")
} }
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount( sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(
@ -907,14 +903,13 @@ func (k Keeper) pickProviderAuctionWinners(ctx context.Context, auction *auction
sdk.NewCoins(creatorLeftOverAmount), sdk.NewCoins(creatorLeftOverAmount),
) )
if sdkErr != nil { if sdkErr != nil {
k.logger.Error(fmt.Sprintf("Auction error returning leftover locked amount: %v", sdkErr)) logger.Error("Error returning leftover locked amount", "error", sdkErr)
panic(sdkErr) panic(sdkErr)
} }
// Notify other modules (hook). // Notify other modules (hook).
k.logger.Info(fmt.Sprintf("Auction %s notifying %d modules.", auction.Id, len(k.usageKeepers)))
for _, keeper := range k.usageKeepers { for _, keeper := range k.usageKeepers {
k.logger.Info(fmt.Sprintf("Auction %s notifying module %s.", auction.Id, keeper.ModuleName())) logger.Info("Auction notifying module", "module", keeper.ModuleName())
keeper.OnAuctionWinnerSelected(ctx, auction.Id, uint64(k.HeaderService.HeaderInfo(ctx).Height)) keeper.OnAuctionWinnerSelected(ctx, auction.Id, uint64(k.HeaderService.HeaderInfo(ctx).Height))
} }
@ -928,20 +923,20 @@ func (k Keeper) ReleaseFunds(ctx context.Context, msg auctiontypes.MsgReleaseFun
} }
if auction.Kind != auctiontypes.AuctionKindProvider { if auction.Kind != auctiontypes.AuctionKindProvider {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction kind must be provider.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction kind must be provider")
} }
// Only the auction owner can release funds. // Only the auction owner can release funds.
if msg.Signer != auction.OwnerAddress { if msg.Signer != auction.OwnerAddress {
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Only auction owner can release funds.") return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Only auction owner can release funds")
} }
if auction.Status != auctiontypes.AuctionStatusCompleted { if auction.Status != auctiontypes.AuctionStatusCompleted {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction is not completed.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction is not completed")
} }
if auction.FundsReleased { if auction.FundsReleased {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction funds already released.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction funds already released")
} }
// Mark funds as released in the stored auction // Mark funds as released in the stored auction
@ -951,24 +946,25 @@ func (k Keeper) ReleaseFunds(ctx context.Context, msg auctiontypes.MsgReleaseFun
} }
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
logger := k.logger.With("id", auction.Id)
// Process winner accounts. // Process winner accounts.
for _, winnerAddress := range auction.WinnerAddresses { for _, winner := range auction.WinnerAddresses {
winnerAccAddress, err := addrCodec.StringToBytes(winnerAddress) winnerAddress, err := addrCodec.StringToBytes(winner)
if err != nil { if err != nil {
k.logger.Error(fmt.Sprintf("Invalid winner address. %v", err)) logger.Error("Invalid winner address", "error", err)
panic("Invalid winner address.") panic("Invalid winner address")
} }
// Send winning price to winning bidders // Send winning price to winning bidders
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount( sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(
ctx, ctx,
auctiontypes.ModuleName, auctiontypes.ModuleName,
winnerAccAddress, winnerAddress,
sdk.NewCoins(auction.WinningPrice), sdk.NewCoins(auction.WinningPrice),
) )
if sdkErr != nil { if sdkErr != nil {
k.logger.Error(fmt.Sprintf("Auction error sending funds to winner: %v", sdkErr)) logger.Error("Error sending funds to winner", "error", sdkErr)
panic(sdkErr) panic(sdkErr)
} }
} }

View File

@ -3,8 +3,8 @@ package keeper
import ( import (
"context" "context"
errorsmod "cosmossdk.io/errors" "cosmossdk.io/core/event"
govtypes "cosmossdk.io/x/gov/types" "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"git.vdb.to/cerc-io/laconicd/utils" "git.vdb.to/cerc-io/laconicd/utils"
@ -22,9 +22,9 @@ func NewMsgServerImpl(keeper *Keeper) auctiontypes.MsgServer {
return &msgServer{k: keeper} return &msgServer{k: keeper}
} }
func (ms msgServer) CreateAuction(c context.Context, msg *auctiontypes.MsgCreateAuction) (*auctiontypes.MsgCreateAuctionResponse, error) { func (ms msgServer) CreateAuction(ctx context.Context, msg *auctiontypes.MsgCreateAuction) (*auctiontypes.MsgCreateAuctionResponse, error) {
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) defer refundGas(ms.k.logger, "CreateAuction")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
_, err := addrCodec.StringToBytes(msg.Signer) _, err := addrCodec.StringToBytes(msg.Signer)
@ -37,34 +37,34 @@ func (ms msgServer) CreateAuction(c context.Context, msg *auctiontypes.MsgCreate
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewEvent( auctiontypes.EventTypeCreateAuction,
auctiontypes.EventTypeCreateAuction, event.NewAttribute(auctiontypes.AttributeKeyCommitsDuration, msg.CommitsDuration.String()),
sdk.NewAttribute(auctiontypes.AttributeKeyCommitsDuration, msg.CommitsDuration.String()), event.NewAttribute(auctiontypes.AttributeKeyCommitFee, msg.CommitFee.String()),
sdk.NewAttribute(auctiontypes.AttributeKeyCommitFee, msg.CommitFee.String()), event.NewAttribute(auctiontypes.AttributeKeyRevealFee, msg.RevealFee.String()),
sdk.NewAttribute(auctiontypes.AttributeKeyRevealFee, msg.RevealFee.String()), event.NewAttribute(auctiontypes.AttributeKeyMinimumBid, msg.MinimumBid.String()),
sdk.NewAttribute(auctiontypes.AttributeKeyMinimumBid, msg.MinimumBid.String()), ); err != nil {
), return nil, errors.Wrapf(err, "failed to emit event: %s", auctiontypes.EventTypeCreateAuction)
sdk.NewEvent( }
sdk.EventTypeMessage, if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory), sdk.EventTypeMessage,
sdk.NewAttribute(auctiontypes.AttributeKeySigner, msg.Signer), event.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory),
), event.NewAttribute(auctiontypes.AttributeKeySigner, msg.Signer),
}) ); err != nil {
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
utils.LogTxGasConsumed(ctx, ms.k.logger, "CreateAuction") }
return &auctiontypes.MsgCreateAuctionResponse{Auction: resp}, nil return &auctiontypes.MsgCreateAuctionResponse{Auction: resp}, nil
} }
// CommitBid is the command for committing a bid // CommitBid is the command for committing a bid
func (ms msgServer) CommitBid(c context.Context, msg *auctiontypes.MsgCommitBid) (*auctiontypes.MsgCommitBidResponse, error) { func (ms msgServer) CommitBid(ctx context.Context, msg *auctiontypes.MsgCommitBid) (*auctiontypes.MsgCommitBidResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) defer refundGas(ms.k.logger, "CommitBid")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
_, err := addrCodec.StringToBytes(msg.Signer) _, err := addrCodec.StringToBytes(msg.Signer)
@ -77,32 +77,32 @@ func (ms msgServer) CommitBid(c context.Context, msg *auctiontypes.MsgCommitBid)
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewEvent( auctiontypes.EventTypeCommitBid,
auctiontypes.EventTypeCommitBid, event.NewAttribute(auctiontypes.AttributeKeyAuctionId, msg.AuctionId),
sdk.NewAttribute(auctiontypes.AttributeKeyAuctionId, msg.AuctionId), event.NewAttribute(auctiontypes.AttributeKeyCommitHash, msg.CommitHash),
sdk.NewAttribute(auctiontypes.AttributeKeyCommitHash, msg.CommitHash), ); err != nil {
), return nil, errors.Wrapf(err, "failed to emit event: %s", auctiontypes.EventTypeCommitBid)
sdk.NewEvent( }
sdk.EventTypeMessage, if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory), sdk.EventTypeMessage,
sdk.NewAttribute(auctiontypes.AttributeKeySigner, msg.Signer), event.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory),
), event.NewAttribute(auctiontypes.AttributeKeySigner, msg.Signer),
}) ); err != nil {
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
utils.LogTxGasConsumed(ctx, ms.k.logger, "CommitBid") }
return &auctiontypes.MsgCommitBidResponse{Bid: resp}, nil return &auctiontypes.MsgCommitBidResponse{Bid: resp}, nil
} }
// RevealBid is the command for revealing a bid // RevealBid is the command for revealing a bid
func (ms msgServer) RevealBid(c context.Context, msg *auctiontypes.MsgRevealBid) (*auctiontypes.MsgRevealBidResponse, error) { func (ms msgServer) RevealBid(ctx context.Context, msg *auctiontypes.MsgRevealBid) (*auctiontypes.MsgRevealBidResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) defer refundGas(ms.k.logger, "RevealBid")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
_, err := addrCodec.StringToBytes(msg.Signer) _, err := addrCodec.StringToBytes(msg.Signer)
@ -115,36 +115,34 @@ func (ms msgServer) RevealBid(c context.Context, msg *auctiontypes.MsgRevealBid)
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewEvent( auctiontypes.EventTypeRevealBid,
auctiontypes.EventTypeRevealBid, event.NewAttribute(auctiontypes.AttributeKeyAuctionId, msg.AuctionId),
sdk.NewAttribute(auctiontypes.AttributeKeyAuctionId, msg.AuctionId), event.NewAttribute(auctiontypes.AttributeKeyReveal, msg.Reveal),
sdk.NewAttribute(auctiontypes.AttributeKeyReveal, msg.Reveal), ); err != nil {
), return nil, errors.Wrapf(err, "failed to emit event: %s", auctiontypes.EventTypeRevealBid)
sdk.NewEvent( }
sdk.EventTypeMessage, if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory), sdk.EventTypeMessage,
sdk.NewAttribute(auctiontypes.AttributeKeySigner, msg.Signer), event.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory),
), event.NewAttribute(auctiontypes.AttributeKeySigner, msg.Signer),
}) ); err != nil {
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
utils.LogTxGasConsumed(ctx, ms.k.logger, "RevealBid") }
return &auctiontypes.MsgRevealBidResponse{Auction: resp}, nil return &auctiontypes.MsgRevealBidResponse{Auction: resp}, nil
} }
// UpdateParams defines a method to perform updation of module params. // UpdateParams defines a method to perform updation of module params.
func (ms msgServer) UpdateParams(c context.Context, msg *auctiontypes.MsgUpdateParams) (*auctiontypes.MsgUpdateParamsResponse, error) { func (ms msgServer) UpdateParams(ctx context.Context, msg *auctiontypes.MsgUpdateParams) (*auctiontypes.MsgUpdateParamsResponse, error) {
if ms.k.authority != msg.Authority { if err := utils.CheckAuthorityAddress(ms.k.addressCodec, ms.k.authority, msg.Authority); err != nil {
return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.k.authority, msg.Authority) return nil, err
} }
if err := msg.Params.Validate(); err != nil { if err := msg.Params.Validate(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c)
if err := ms.k.SetParams(ctx, msg.Params); err != nil { if err := ms.k.SetParams(ctx, msg.Params); err != nil {
return nil, err return nil, err
} }
@ -153,13 +151,13 @@ func (ms msgServer) UpdateParams(c context.Context, msg *auctiontypes.MsgUpdateP
} }
// ReleaseFunds is the command to pay the winning amounts to provider auction winners // ReleaseFunds is the command to pay the winning amounts to provider auction winners
func (ms msgServer) ReleaseFunds(c context.Context, msg *auctiontypes.MsgReleaseFunds) (*auctiontypes.MsgReleaseFundsResponse, error) { func (ms msgServer) ReleaseFunds(ctx context.Context, msg *auctiontypes.MsgReleaseFunds) (*auctiontypes.MsgReleaseFundsResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) defer refundGas(ms.k.logger, "ReleaseFunds")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
_, err := addrCodec.StringToBytes(msg.Signer) _, err := addrCodec.StringToBytes(msg.Signer)
@ -172,19 +170,19 @@ func (ms msgServer) ReleaseFunds(c context.Context, msg *auctiontypes.MsgRelease
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewEvent( auctiontypes.EventTypeReleaseFunds,
auctiontypes.EventTypeReleaseFunds, event.NewAttribute(auctiontypes.AttributeKeyAuctionId, msg.AuctionId),
sdk.NewAttribute(auctiontypes.AttributeKeyAuctionId, msg.AuctionId), ); err != nil {
), return nil, errors.Wrapf(err, "failed to emit event: %s", auctiontypes.EventTypeReleaseFunds)
sdk.NewEvent( }
sdk.EventTypeMessage, if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory), sdk.EventTypeMessage,
sdk.NewAttribute(auctiontypes.AttributeKeySigner, msg.Signer), event.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory),
), event.NewAttribute(auctiontypes.AttributeKeySigner, msg.Signer),
}) ); err != nil {
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
utils.LogTxGasConsumed(ctx, ms.k.logger, "ReleaseFunds") }
return &auctiontypes.MsgReleaseFundsResponse{Auction: resp}, nil return &auctiontypes.MsgReleaseFundsResponse{Auction: resp}, nil
} }

View File

@ -1,6 +1,7 @@
package module package module
import ( import (
"cosmossdk.io/core/address"
"cosmossdk.io/core/appmodule" "cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject" "cosmossdk.io/depinject"
"cosmossdk.io/depinject/appconfig" "cosmossdk.io/depinject/appconfig"
@ -9,9 +10,9 @@ import (
govtypes "cosmossdk.io/x/gov/types" govtypes "cosmossdk.io/x/gov/types"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
auth "github.com/cosmos/cosmos-sdk/x/auth/keeper" auth "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
modulev1 "git.vdb.to/cerc-io/laconicd/api/cerc/auction/module/v1" modulev1 "git.vdb.to/cerc-io/laconicd/api/cerc/auction/module/v1"
"git.vdb.to/cerc-io/laconicd/utils"
"git.vdb.to/cerc-io/laconicd/x/auction" "git.vdb.to/cerc-io/laconicd/x/auction"
"git.vdb.to/cerc-io/laconicd/x/auction/keeper" "git.vdb.to/cerc-io/laconicd/x/auction/keeper"
) )
@ -35,9 +36,10 @@ func init() {
type ModuleInputs struct { type ModuleInputs struct {
depinject.In depinject.In
Env appmodule.Environment Env appmodule.Environment
Config *modulev1.Module Config *modulev1.Module
Cdc codec.Codec Cdc codec.Codec
AddressCodec address.Codec
AccountKeeper auth.AccountKeeper AccountKeeper auth.AccountKeeper
BankKeeper bank.Keeper BankKeeper bank.Keeper
@ -58,12 +60,9 @@ type ModuleOutputs struct {
func ProvideModule(in ModuleInputs) ModuleOutputs { func ProvideModule(in ModuleInputs) ModuleOutputs {
// default to governance authority if not provided // default to governance authority if not provided
authority := authtypes.NewModuleAddress(govtypes.ModuleName) authority := utils.AddressOrModuleAddress(in.Config.Authority, govtypes.ModuleName)
if in.Config.Authority != "" {
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}
k := keeper.NewKeeper(in.Env, in.Cdc, in.AccountKeeper, in.BankKeeper, authority.String(), in.Logger) k := keeper.NewKeeper(in.Env, in.Cdc, in.AddressCodec, in.AccountKeeper, in.BankKeeper, authority, in.Logger)
m := NewAppModule(in.Cdc, k) m := NewAppModule(in.Cdc, k)
return ModuleOutputs{Module: m, Keeper: k} return ModuleOutputs{Module: m, Keeper: k}

View File

@ -9,13 +9,14 @@ import (
"cosmossdk.io/collections" "cosmossdk.io/collections"
"cosmossdk.io/collections/indexes" "cosmossdk.io/collections/indexes"
"cosmossdk.io/core/address"
"cosmossdk.io/core/appmodule" "cosmossdk.io/core/appmodule"
"cosmossdk.io/core/store"
errorsmod "cosmossdk.io/errors" errorsmod "cosmossdk.io/errors"
"cosmossdk.io/log" "cosmossdk.io/log"
bank "cosmossdk.io/x/bank/keeper" bank "cosmossdk.io/x/bank/keeper"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
auth "github.com/cosmos/cosmos-sdk/x/auth/keeper" auth "github.com/cosmos/cosmos-sdk/x/auth/keeper"
@ -45,10 +46,11 @@ func newBondIndexes(sb *collections.SchemaBuilder) BondsIndexes {
type Keeper struct { type Keeper struct {
appmodule.Environment appmodule.Environment
cdc codec.BinaryCodec cdc codec.BinaryCodec
logger log.Logger addressCodec address.Codec
logger log.Logger
authority string authority types.AccAddress
// External keepers // External keepers
accountKeeper auth.AccountKeeper accountKeeper auth.AccountKeeper
@ -67,18 +69,13 @@ type Keeper struct {
func NewKeeper( func NewKeeper(
env appmodule.Environment, env appmodule.Environment,
cdc codec.BinaryCodec, cdc codec.BinaryCodec,
storeService store.KVStoreService, addressCodec address.Codec,
accountKeeper auth.AccountKeeper, accountKeeper auth.AccountKeeper,
bankKeeper bank.Keeper, bankKeeper bank.Keeper,
authority string, authority types.AccAddress,
logger log.Logger, logger log.Logger,
) *Keeper { ) *Keeper {
// ensure that authority is a valid AccAddress sb := collections.NewSchemaBuilder(env.KVStoreService)
if _, err := accountKeeper.AddressCodec().StringToBytes(authority); err != nil {
panic("authority is not a valid acc address")
}
sb := collections.NewSchemaBuilder(storeService)
k := Keeper{ k := Keeper{
Environment: env, Environment: env,
cdc: cdc, cdc: cdc,
@ -172,7 +169,7 @@ func (k Keeper) GetBondById(ctx context.Context, id string) (bondtypes.Bond, err
bond, err := k.Bonds.Get(ctx, id) bond, err := k.Bonds.Get(ctx, id)
if err != nil { if err != nil {
if errors.Is(err, collections.ErrNotFound) { if errors.Is(err, collections.ErrNotFound) {
err = errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found") return bondtypes.Bond{}, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found")
} }
return bondtypes.Bond{}, err return bondtypes.Bond{}, err
} }
@ -222,7 +219,7 @@ func (k Keeper) CreateBond(ctx context.Context, ownerAddress sdk.AccAddress, coi
bond := bondtypes.Bond{Id: bondId, Owner: ownerAddress.String(), Balance: coins} bond := bondtypes.Bond{Id: bondId, Owner: ownerAddress.String(), Balance: coins}
if bond.Balance.IsAnyGT(maxBondAmount) { if bond.Balance.IsAnyGT(maxBondAmount) {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Max bond amount exceeded.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Max bond amount exceeded")
} }
// Move funds into the bond account module. // Move funds into the bond account module.
@ -245,7 +242,7 @@ func (k Keeper) RefillBond(ctx context.Context, id string, ownerAddress sdk.AccA
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found")
} }
bond, err := k.GetBondById(ctx, id) bond, err := k.GetBondById(ctx, id)
@ -254,13 +251,13 @@ func (k Keeper) RefillBond(ctx context.Context, id string, ownerAddress sdk.AccA
} }
if bond.Owner != ownerAddress.String() { if bond.Owner != ownerAddress.String() {
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.") return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch")
} }
// Check if account has funds. // Check if account has funds.
for _, coin := range coins { for _, coin := range coins {
if !k.bankKeeper.HasBalance(ctx, ownerAddress, coin) { if !k.bankKeeper.HasBalance(ctx, ownerAddress, coin) {
return nil, errorsmod.Wrap(sdkerrors.ErrInsufficientFunds, "Insufficient funds.") return nil, errorsmod.Wrap(sdkerrors.ErrInsufficientFunds, "Insufficient funds")
} }
} }
@ -271,7 +268,7 @@ func (k Keeper) RefillBond(ctx context.Context, id string, ownerAddress sdk.AccA
updatedBalance := bond.Balance.Add(coins...) updatedBalance := bond.Balance.Add(coins...)
if updatedBalance.IsAnyGT(maxBondAmount) { if updatedBalance.IsAnyGT(maxBondAmount) {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Max bond amount exceeded.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Max bond amount exceeded")
} }
// Move funds into the bond account module. // Move funds into the bond account module.
@ -295,7 +292,7 @@ func (k Keeper) WithdrawBond(ctx context.Context, id string, ownerAddress sdk.Ac
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found")
} }
bond, err := k.GetBondById(ctx, id) bond, err := k.GetBondById(ctx, id)
@ -304,12 +301,12 @@ func (k Keeper) WithdrawBond(ctx context.Context, id string, ownerAddress sdk.Ac
} }
if bond.Owner != ownerAddress.String() { if bond.Owner != ownerAddress.String() {
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.") return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch")
} }
updatedBalance, isNeg := bond.Balance.SafeSub(coins...) updatedBalance, isNeg := bond.Balance.SafeSub(coins...)
if isNeg { if isNeg {
return nil, errorsmod.Wrap(sdkerrors.ErrInsufficientFunds, "Insufficient bond balance.") return nil, errorsmod.Wrap(sdkerrors.ErrInsufficientFunds, "Insufficient bond balance")
} }
// Move funds from the bond into the account. // Move funds from the bond into the account.
@ -333,7 +330,7 @@ func (k Keeper) CancelBond(ctx context.Context, id string, ownerAddress sdk.AccA
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found")
} }
bond, err := k.GetBondById(ctx, id) bond, err := k.GetBondById(ctx, id)
@ -342,13 +339,13 @@ func (k Keeper) CancelBond(ctx context.Context, id string, ownerAddress sdk.AccA
} }
if bond.Owner != ownerAddress.String() { if bond.Owner != ownerAddress.String() {
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.") return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch")
} }
// Check if bond is used in other modules. // Check if bond is used in other modules.
for _, usageKeeper := range k.usageKeepers { for _, usageKeeper := range k.usageKeepers {
if usageKeeper.UsesBond(ctx, id) { if usageKeeper.UsesBond(ctx, id) {
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, fmt.Sprintf("Bond in use by the '%s' module.", usageKeeper.ModuleName())) return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, fmt.Sprintf("Bond in use by the '%s' module", usageKeeper.ModuleName()))
} }
} }
@ -367,11 +364,6 @@ func (k Keeper) CancelBond(ctx context.Context, id string, ownerAddress sdk.AccA
return &bond, nil return &bond, nil
} }
// GetAuthority returns the x/bond module's authority.
func (k Keeper) GetAuthority() string {
return k.authority
}
// GetParams gets the bond module's parameters. // GetParams gets the bond module's parameters.
func (k Keeper) GetParams(ctx context.Context) (*bondtypes.Params, error) { func (k Keeper) GetParams(ctx context.Context) (*bondtypes.Params, error) {
params, err := k.Params.Get(ctx) params, err := k.Params.Get(ctx)
@ -403,7 +395,7 @@ func (k Keeper) TransferRentToModuleAccount(ctx context.Context, id, moduleAccou
if err != nil { if err != nil {
return err return err
} }
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.") return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found")
} }
bond, err := k.GetBondById(ctx, id) bond, err := k.GetBondById(ctx, id)
@ -415,13 +407,13 @@ func (k Keeper) TransferRentToModuleAccount(ctx context.Context, id, moduleAccou
updatedBalance, isNeg := bond.Balance.SafeSub(rent...) updatedBalance, isNeg := bond.Balance.SafeSub(rent...)
if isNeg { if isNeg {
// Check if bond has sufficient funds. // Check if bond has sufficient funds.
return errorsmod.Wrap(sdkerrors.ErrInsufficientFunds, "Insufficient funds.") return errorsmod.Wrap(sdkerrors.ErrInsufficientFunds, "Insufficient funds")
} }
// Move funds from bond module to record rent module. // Move funds from bond module to record rent module.
err = k.bankKeeper.SendCoinsFromModuleToModule(ctx, bondtypes.ModuleName, moduleAccount, rent) err = k.bankKeeper.SendCoinsFromModuleToModule(ctx, bondtypes.ModuleName, moduleAccount, rent)
if err != nil { if err != nil {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Error transferring funds.") return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Error transferring funds")
} }
// Update bond balance. // Update bond balance.

View File

@ -3,8 +3,8 @@ package keeper
import ( import (
"context" "context"
errorsmod "cosmossdk.io/errors" "cosmossdk.io/core/event"
govtypes "cosmossdk.io/x/gov/types" "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"git.vdb.to/cerc-io/laconicd/utils" "git.vdb.to/cerc-io/laconicd/utils"
@ -15,57 +15,58 @@ type msgHandlers struct {
k *Keeper k *Keeper
} }
// NewHandlers returns an implementation of the module MsgServer interface. // NewMsgServerImpl returns an implementation of the module MsgServer interface.
func NewHandlers(keeper *Keeper) msgHandlers { func NewMsgServerImpl(keeper *Keeper) msgHandlers {
return msgHandlers{k: keeper} return msgHandlers{k: keeper}
} }
func (ms msgHandlers) CreateBond(c context.Context, msg *bond.MsgCreateBond) (*bond.MsgCreateBondResponse, error) { func (ms msgHandlers) CreateBond(ctx context.Context, msg *bond.MsgCreateBond) (*bond.MsgCreateBondResponse, error) {
panic("handlers.CreateBond is definitely called") ms.k.logger.Debug("handlers.CreateBond", "msg", msg)
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) defer refundGas(ms.k.logger, "CreateBond")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
signerAddress, err := addrCodec.StringToBytes(msg.Signer) signerAddress, err := addrCodec.StringToBytes(msg.Signer)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp, err := ms.k.CreateBond(ctx, signerAddress, msg.Coins) resp, err := ms.k.CreateBond(ctx, signerAddress, msg.Coins)
if err != nil { if err != nil {
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ eventManager := ms.k.EventService.EventManager(ctx)
sdk.NewEvent( if err := eventManager.EmitKV(
bond.EventTypeCreateBond, bond.EventTypeCreateBond,
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer), event.NewAttribute(bond.AttributeKeySigner, msg.Signer),
sdk.NewAttribute(sdk.AttributeKeyAmount, msg.Coins.String()), event.NewAttribute(sdk.AttributeKeyAmount, msg.Coins.String()),
), ); err != nil {
sdk.NewEvent( return nil, errors.Wrapf(err, "failed to emit event: %s", bond.EventTypeCreateBond)
sdk.EventTypeMessage, }
sdk.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory), if err := eventManager.EmitKV(
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer), sdk.EventTypeMessage,
), event.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory),
}) event.NewAttribute(bond.AttributeKeySigner, msg.Signer),
); err != nil {
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "CreateBond") return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
}
return &bond.MsgCreateBondResponse{Id: resp.Id}, nil return &bond.MsgCreateBondResponse{Id: resp.Id}, nil
} }
// RefillBond implements bond.MsgServer. // RefillBond implements bond.MsgServer.
func (ms msgHandlers) RefillBond(c context.Context, msg *bond.MsgRefillBond) (*bond.MsgRefillBondResponse, error) { func (ms msgHandlers) RefillBond(ctx context.Context, msg *bond.MsgRefillBond) (*bond.MsgRefillBondResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) defer refundGas(ms.k.logger, "RefillBond")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
signerAddress, err := addrCodec.StringToBytes(msg.Signer) signerAddress, err := addrCodec.StringToBytes(msg.Signer)
@ -78,33 +79,34 @@ func (ms msgHandlers) RefillBond(c context.Context, msg *bond.MsgRefillBond) (*b
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ eventManager := ms.k.EventService.EventManager(ctx)
sdk.NewEvent( if err := eventManager.EmitKV(
bond.EventTypeRefillBond, bond.EventTypeRefillBond,
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer), event.NewAttribute(bond.AttributeKeySigner, msg.Signer),
sdk.NewAttribute(bond.AttributeKeyBondId, msg.Id), event.NewAttribute(bond.AttributeKeyBondId, msg.Id),
sdk.NewAttribute(sdk.AttributeKeyAmount, msg.Coins.String()), event.NewAttribute(sdk.AttributeKeyAmount, msg.Coins.String()),
), ); err != nil {
sdk.NewEvent( return nil, errors.Wrapf(err, "failed to emit event: %s", bond.EventTypeRefillBond)
sdk.EventTypeMessage, }
sdk.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory), if err := eventManager.EmitKV(
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer), sdk.EventTypeMessage,
), event.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory),
}) event.NewAttribute(bond.AttributeKeySigner, msg.Signer),
); err != nil {
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "RefillBond") return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
}
return &bond.MsgRefillBondResponse{}, nil return &bond.MsgRefillBondResponse{}, nil
} }
// WithdrawBond implements bond.MsgServer. // WithdrawBond implements bond.MsgServer.
func (ms msgHandlers) WithdrawBond(c context.Context, msg *bond.MsgWithdrawBond) (*bond.MsgWithdrawBondResponse, error) { func (ms msgHandlers) WithdrawBond(ctx context.Context, msg *bond.MsgWithdrawBond) (*bond.MsgWithdrawBondResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) defer refundGas(ms.k.logger, "WithdrawBond")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
signerAddress, err := addrCodec.StringToBytes(msg.Signer) signerAddress, err := addrCodec.StringToBytes(msg.Signer)
@ -117,33 +119,34 @@ func (ms msgHandlers) WithdrawBond(c context.Context, msg *bond.MsgWithdrawBond)
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ eventManager := ms.k.EventService.EventManager(ctx)
sdk.NewEvent( if err := eventManager.EmitKV(
bond.EventTypeWithdrawBond, bond.EventTypeWithdrawBond,
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer), event.NewAttribute(bond.AttributeKeySigner, msg.Signer),
sdk.NewAttribute(bond.AttributeKeyBondId, msg.Id), event.NewAttribute(bond.AttributeKeyBondId, msg.Id),
sdk.NewAttribute(sdk.AttributeKeyAmount, msg.Coins.String()), event.NewAttribute(sdk.AttributeKeyAmount, msg.Coins.String()),
), ); err != nil {
sdk.NewEvent( return nil, errors.Wrapf(err, "failed to emit event: %s", bond.EventTypeWithdrawBond)
sdk.EventTypeMessage, }
sdk.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory), if err := eventManager.EmitKV(
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer), sdk.EventTypeMessage,
), event.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory),
}) event.NewAttribute(bond.AttributeKeySigner, msg.Signer),
); err != nil {
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "WithdrawBond") return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
}
return &bond.MsgWithdrawBondResponse{}, nil return &bond.MsgWithdrawBondResponse{}, nil
} }
// CancelBond implements bond.MsgServer. // CancelBond implements bond.MsgServer.
func (ms msgHandlers) CancelBond(c context.Context, msg *bond.MsgCancelBond) (*bond.MsgCancelBondResponse, error) { func (ms msgHandlers) CancelBond(ctx context.Context, msg *bond.MsgCancelBond) (*bond.MsgCancelBondResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) defer refundGas(ms.k.logger, "CancelBond")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
signerAddress, err := addrCodec.StringToBytes(msg.Signer) signerAddress, err := addrCodec.StringToBytes(msg.Signer)
@ -156,36 +159,35 @@ func (ms msgHandlers) CancelBond(c context.Context, msg *bond.MsgCancelBond) (*b
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ eventManager := ms.k.EventService.EventManager(ctx)
sdk.NewEvent( if err := eventManager.EmitKV(
bond.EventTypeCancelBond, bond.EventTypeCancelBond,
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer), event.NewAttribute(bond.AttributeKeySigner, msg.Signer),
sdk.NewAttribute(bond.AttributeKeyBondId, msg.Id), event.NewAttribute(bond.AttributeKeyBondId, msg.Id),
), ); err != nil {
sdk.NewEvent( return nil, errors.Wrapf(err, "failed to emit event: %s", bond.EventTypeCancelBond)
sdk.EventTypeMessage, }
sdk.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory), if err := eventManager.EmitKV(
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer), sdk.EventTypeMessage,
), event.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory),
}) event.NewAttribute(bond.AttributeKeySigner, msg.Signer),
); err != nil {
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "CancelBond") return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
}
return &bond.MsgCancelBondResponse{}, nil return &bond.MsgCancelBondResponse{}, nil
} }
// UpdateParams defines a method to perform updation of module params. // UpdateParams defines a method to perform updation of module params.
func (ms msgHandlers) UpdateParams(c context.Context, msg *bond.MsgUpdateParams) (*bond.MsgUpdateParamsResponse, error) { func (ms msgHandlers) UpdateParams(ctx context.Context, msg *bond.MsgUpdateParams) (*bond.MsgUpdateParamsResponse, error) {
if ms.k.authority != msg.Authority { if err := utils.CheckAuthorityAddress(ms.k.addressCodec, ms.k.authority, msg.Authority); err != nil {
return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.k.authority, msg.Authority) return nil, err
} }
if err := msg.Params.Validate(); err != nil { if err := msg.Params.Validate(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c)
if err := ms.k.SetParams(ctx, msg.Params); err != nil { if err := ms.k.SetParams(ctx, msg.Params); err != nil {
return nil, err return nil, err
} }

View File

@ -13,8 +13,8 @@ type queryHandlers struct {
k *Keeper k *Keeper
} }
// NewQueryHandlers returns an implementation of the module QueryServer. // NewQueryServerImpl returns an implementation of the module QueryServer.
func NewQueryHandlers(k *Keeper) bondtypes.QueryServer { func NewQueryServerImpl(k *Keeper) bondtypes.QueryServer {
return queryHandlers{k} return queryHandlers{k}
} }

View File

@ -1,8 +1,8 @@
package module package module
import ( import (
"cosmossdk.io/core/address"
"cosmossdk.io/core/appmodule" "cosmossdk.io/core/appmodule"
"cosmossdk.io/core/store"
"cosmossdk.io/depinject" "cosmossdk.io/depinject"
"cosmossdk.io/depinject/appconfig" "cosmossdk.io/depinject/appconfig"
"cosmossdk.io/log" "cosmossdk.io/log"
@ -10,9 +10,9 @@ import (
govtypes "cosmossdk.io/x/gov/types" govtypes "cosmossdk.io/x/gov/types"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
auth "github.com/cosmos/cosmos-sdk/x/auth/keeper" auth "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
modulev1 "git.vdb.to/cerc-io/laconicd/api/cerc/bond/module/v1" modulev1 "git.vdb.to/cerc-io/laconicd/api/cerc/bond/module/v1"
"git.vdb.to/cerc-io/laconicd/utils"
"git.vdb.to/cerc-io/laconicd/x/bond" "git.vdb.to/cerc-io/laconicd/x/bond"
"git.vdb.to/cerc-io/laconicd/x/bond/keeper" "git.vdb.to/cerc-io/laconicd/x/bond/keeper"
) )
@ -39,7 +39,7 @@ type ModuleInputs struct {
Env appmodule.Environment Env appmodule.Environment
Config *modulev1.Module Config *modulev1.Module
Cdc codec.Codec Cdc codec.Codec
StoreService store.KVStoreService AddressCodec address.Codec
AccountKeeper auth.AccountKeeper AccountKeeper auth.AccountKeeper
BankKeeper bank.Keeper BankKeeper bank.Keeper
@ -56,12 +56,8 @@ type ModuleOutputs struct {
func ProvideModule(in ModuleInputs) ModuleOutputs { func ProvideModule(in ModuleInputs) ModuleOutputs {
// default to governance authority if not provided // default to governance authority if not provided
authority := authtypes.NewModuleAddress(govtypes.ModuleName) authority := utils.AddressOrModuleAddress(in.Config.Authority, govtypes.ModuleName)
if in.Config.Authority != "" { k := keeper.NewKeeper(in.Env, in.Cdc, in.AddressCodec, in.AccountKeeper, in.BankKeeper, authority, in.Logger)
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}
k := keeper.NewKeeper(in.Env, in.Cdc, in.StoreService, in.AccountKeeper, in.BankKeeper, authority.String(), in.Logger)
m := NewAppModule(in.Cdc, k) m := NewAppModule(in.Cdc, k)
return ModuleOutputs{Module: m, Keeper: k} return ModuleOutputs{Module: m, Keeper: k}

View File

@ -6,7 +6,7 @@ import (
"fmt" "fmt"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
// "google.golang.org/grpc" // "google.golang.org/grpc"
appmodule "cosmossdk.io/core/appmodule/v2" appmodule "cosmossdk.io/core/appmodule/v2"
@ -17,17 +17,16 @@ import (
"github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/types/module"
"git.vdb.to/cerc-io/laconicd/x/bond" "git.vdb.to/cerc-io/laconicd/x/bond"
"git.vdb.to/cerc-io/laconicd/x/bond/client/cli"
"git.vdb.to/cerc-io/laconicd/x/bond/keeper" "git.vdb.to/cerc-io/laconicd/x/bond/keeper"
) )
var ( var (
_ appmodule.AppModule = AppModule{} _ appmodule.AppModule = AppModule{}
_ appmodule.HasGenesis = AppModule{}
_ appmodule.HasConsensusVersion = AppModule{} _ appmodule.HasConsensusVersion = AppModule{}
_ appmodule.HasGenesis = AppModule{}
_ appmodule.HasMsgHandlers = AppModule{}
_ appmodule.HasQueryHandlers = AppModule{}
_ appmodule.HasRegisterInterfaces = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{}
// _ appmodule.HasMsgHandlers = AppModule{}
_ appmodule.HasQueryHandlers = AppModule{}
_ module.HasGRPCGateway = AppModule{} _ module.HasGRPCGateway = AppModule{}
// _ module.HasServices = AppModule{} // _ module.HasServices = AppModule{}
@ -117,14 +116,6 @@ func (am AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error)
return am.cdc.MustMarshalJSON(gs), nil return am.cdc.MustMarshalJSON(gs), nil
} }
// // module.HasServices
// func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
// bond.RegisterMsgServer(registrar, keeper.NewHandlers(am.keeper))
// bond.RegisterQueryServer(registrar, keeper.NewQueryHandlers(am.keeper))
// return nil
// }
// module.HasInvariants // module.HasInvariants
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
@ -133,7 +124,7 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
// RegisterMsgHandlers registers the message handlers for the bond module. // RegisterMsgHandlers registers the message handlers for the bond module.
func (am AppModule) RegisterMsgHandlers(router appmodule.MsgRouter) { func (am AppModule) RegisterMsgHandlers(router appmodule.MsgRouter) {
handlers := keeper.NewHandlers(am.keeper) handlers := keeper.NewMsgServerImpl(am.keeper)
appmodule.RegisterMsgHandler(router, handlers.CreateBond) appmodule.RegisterMsgHandler(router, handlers.CreateBond)
appmodule.RegisterMsgHandler(router, handlers.RefillBond) appmodule.RegisterMsgHandler(router, handlers.RefillBond)
@ -144,7 +135,7 @@ func (am AppModule) RegisterMsgHandlers(router appmodule.MsgRouter) {
// RegisterQueryHandlers registers the query handlers for the bond module. // RegisterQueryHandlers registers the query handlers for the bond module.
func (am AppModule) RegisterQueryHandlers(router appmodule.QueryRouter) { func (am AppModule) RegisterQueryHandlers(router appmodule.QueryRouter) {
handlers := keeper.NewQueryHandlers(am.keeper) handlers := keeper.NewQueryServerImpl(am.keeper)
appmodule.RegisterMsgHandler(router, handlers.Params) appmodule.RegisterMsgHandler(router, handlers.Params)
appmodule.RegisterMsgHandler(router, handlers.Bonds) appmodule.RegisterMsgHandler(router, handlers.Bonds)
@ -152,15 +143,3 @@ func (am AppModule) RegisterQueryHandlers(router appmodule.QueryRouter) {
appmodule.RegisterMsgHandler(router, handlers.GetBondsByOwner) appmodule.RegisterMsgHandler(router, handlers.GetBondsByOwner)
appmodule.RegisterMsgHandler(router, handlers.GetBondModuleBalance) appmodule.RegisterMsgHandler(router, handlers.GetBondModuleBalance)
} }
// GetTxCmd returns the root tx command for the bank/v2 module.
// TODO: Remove & use autocli
func (AppModule) GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}
// GetQueryCmd returns the root query command for the bank/v2 module.
// TODO: Remove & use autocli
func (AppModule) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}

View File

@ -21,7 +21,7 @@ func (msg MsgCreateBond) ValidateBasic() error {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer) return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
} }
if len(msg.Coins) == 0 || !msg.Coins.IsValid() { if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.") return sdkerrors.ErrInvalidCoins
} }
return nil return nil
} }
@ -34,7 +34,7 @@ func (msg MsgRefillBond) ValidateBasic() error {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer) return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
} }
if len(msg.Coins) == 0 || !msg.Coins.IsValid() { if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.") return sdkerrors.ErrInvalidCoins
} }
return nil return nil
} }
@ -47,7 +47,7 @@ func (msg MsgWithdrawBond) ValidateBasic() error {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer) return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
} }
if len(msg.Coins) == 0 || !msg.Coins.IsValid() { if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.") return sdkerrors.ErrInvalidCoins
} }
return nil return nil
} }

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"cosmossdk.io/collections" "cosmossdk.io/collections"
"cosmossdk.io/core/address" "cosmossdk.io/core/address"
@ -14,6 +13,7 @@ import (
"cosmossdk.io/log" "cosmossdk.io/log"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@ -23,13 +23,12 @@ import (
type Keeper struct { type Keeper struct {
appmodule.Environment appmodule.Environment
cdc codec.BinaryCodec
addressCodec address.Codec addressCodec address.Codec
logger log.Logger logger log.Logger
// authority is the address capable of executing a MsgUpdateParams and other authority-gated message. // authority is the address capable of executing a MsgUpdateParams and other authority-gated message.
// typically, this should be the x/gov module account. // typically, this should be the x/gov module account.
authority string authority types.AccAddress
// state management // state management
Schema collections.Schema Schema collections.Schema
@ -39,19 +38,16 @@ type Keeper struct {
// NewKeeper creates a new Keeper instance // NewKeeper creates a new Keeper instance
func NewKeeper( func NewKeeper(
env appmodule.Environment,
cdc codec.BinaryCodec, cdc codec.BinaryCodec,
addressCodec address.Codec, addressCodec address.Codec,
storeService storetypes.KVStoreService, storeService storetypes.KVStoreService,
authority string, authority types.AccAddress,
logger log.Logger, logger log.Logger,
) *Keeper { ) *Keeper {
if _, err := addressCodec.StringToBytes(authority); err != nil {
panic(fmt.Errorf("invalid authority address: %w", err))
}
sb := collections.NewSchemaBuilder(storeService) sb := collections.NewSchemaBuilder(storeService)
k := Keeper{ k := Keeper{
cdc: cdc, Environment: env,
addressCodec: addressCodec, addressCodec: addressCodec,
logger: logger.With(log.ModuleKey, "x/"+onboardingTypes.ModuleName), logger: logger.With(log.ModuleKey, "x/"+onboardingTypes.ModuleName),
authority: authority, authority: authority,
@ -71,11 +67,6 @@ func NewKeeper(
return &k return &k
} }
// GetAuthority returns the module's authority.
func (k Keeper) GetAuthority() string {
return k.authority
}
func (k Keeper) OnboardParticipant( func (k Keeper) OnboardParticipant(
ctx context.Context, ctx context.Context,
msg *onboardingTypes.MsgOnboardParticipant, msg *onboardingTypes.MsgOnboardParticipant,

View File

@ -3,6 +3,8 @@ package keeper
import ( import (
"context" "context"
"cosmossdk.io/core/event"
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"git.vdb.to/cerc-io/laconicd/utils" "git.vdb.to/cerc-io/laconicd/utils"
@ -20,13 +22,13 @@ func NewMsgServerImpl(keeper *Keeper) onboarding.MsgServer {
return &msgServer{k: *keeper} return &msgServer{k: *keeper}
} }
func (ms msgServer) OnboardParticipant(c context.Context, msg *onboarding.MsgOnboardParticipant) (*onboarding.MsgOnboardParticipantResponse, error) { func (ms msgServer) OnboardParticipant(ctx context.Context, msg *onboarding.MsgOnboardParticipant) (*onboarding.MsgOnboardParticipantResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) defer refundGas(ms.k.logger, "OnboardParticipant")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
signerAddress, err := addrCodec.StringToBytes(msg.Participant) signerAddress, err := addrCodec.StringToBytes(msg.Participant)
@ -39,20 +41,20 @@ func (ms msgServer) OnboardParticipant(c context.Context, msg *onboarding.MsgOnb
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewEvent( onboarding.EventTypeOnboardParticipant,
onboarding.EventTypeOnboardParticipant, event.NewAttribute(onboarding.AttributeKeySigner, msg.Participant),
sdk.NewAttribute(onboarding.AttributeKeySigner, msg.Participant), event.NewAttribute(onboarding.AttributeKeyEthAddress, msg.EthPayload.Address),
sdk.NewAttribute(onboarding.AttributeKeyEthAddress, msg.EthPayload.Address), ); err != nil {
), return nil, errors.Wrapf(err, "failed to emit event: %s", onboarding.EventTypeOnboardParticipant)
sdk.NewEvent( }
sdk.EventTypeMessage, if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewAttribute(sdk.AttributeKeyModule, onboarding.AttributeValueCategory), sdk.EventTypeMessage,
sdk.NewAttribute(onboarding.AttributeKeySigner, msg.Participant), event.NewAttribute(sdk.AttributeKeyModule, onboarding.AttributeValueCategory),
), event.NewAttribute(onboarding.AttributeKeySigner, msg.Participant),
}) ); err != nil {
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
utils.LogTxGasConsumed(ctx, ms.k.logger, "OnboardParticipant") }
return &onboarding.MsgOnboardParticipantResponse{}, nil return &onboarding.MsgOnboardParticipantResponse{}, nil
} }

View File

@ -7,10 +7,11 @@ import (
"cosmossdk.io/depinject" "cosmossdk.io/depinject"
"cosmossdk.io/depinject/appconfig" "cosmossdk.io/depinject/appconfig"
"cosmossdk.io/log" "cosmossdk.io/log"
govtypes "cosmossdk.io/x/gov/types"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
modulev1 "git.vdb.to/cerc-io/laconicd/api/cerc/onboarding/module/v1" modulev1 "git.vdb.to/cerc-io/laconicd/api/cerc/onboarding/module/v1"
"git.vdb.to/cerc-io/laconicd/utils"
"git.vdb.to/cerc-io/laconicd/x/onboarding/keeper" "git.vdb.to/cerc-io/laconicd/x/onboarding/keeper"
) )
@ -32,6 +33,7 @@ func init() {
type ModuleInputs struct { type ModuleInputs struct {
depinject.In depinject.In
Env appmodule.Environment
Cdc codec.Codec Cdc codec.Codec
StoreService store.KVStoreService StoreService store.KVStoreService
AddressCodec address.Codec AddressCodec address.Codec
@ -49,12 +51,8 @@ type ModuleOutputs struct {
func ProvideModule(in ModuleInputs) ModuleOutputs { func ProvideModule(in ModuleInputs) ModuleOutputs {
// default to governance as authority if not provided // default to governance as authority if not provided
authority := authtypes.NewModuleAddress("gov") authority := utils.AddressOrModuleAddress(in.Config.Authority, govtypes.ModuleName)
if in.Config.Authority != "" { k := keeper.NewKeeper(in.Env, in.Cdc, in.AddressCodec, in.StoreService, authority, in.Logger)
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}
k := keeper.NewKeeper(in.Cdc, in.AddressCodec, in.StoreService, authority.String(), in.Logger)
m := NewAppModule(in.Cdc, k) m := NewAppModule(in.Cdc, k)
return ModuleOutputs{Module: m, Keeper: k} return ModuleOutputs{Module: m, Keeper: k}

View File

@ -10,12 +10,14 @@ import (
"cosmossdk.io/collections" "cosmossdk.io/collections"
"cosmossdk.io/collections/indexes" "cosmossdk.io/collections/indexes"
"cosmossdk.io/core/address"
"cosmossdk.io/core/appmodule" "cosmossdk.io/core/appmodule"
errorsmod "cosmossdk.io/errors" errorsmod "cosmossdk.io/errors"
"cosmossdk.io/log" "cosmossdk.io/log"
bank "cosmossdk.io/x/bank/keeper" bank "cosmossdk.io/x/bank/keeper"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/cosmos-sdk/types/query"
@ -95,10 +97,11 @@ func newNameRecordIndexes(sb *collections.SchemaBuilder) NameRecordsIndexes {
type Keeper struct { type Keeper struct {
appmodule.Environment appmodule.Environment
cdc codec.BinaryCodec cdc codec.BinaryCodec
logger log.Logger addressCodec address.Codec
logger log.Logger
authority string authority types.AccAddress
accountKeeper auth.AccountKeeper accountKeeper auth.AccountKeeper
bankKeeper bank.Keeper bankKeeper bank.Keeper
@ -120,18 +123,14 @@ type Keeper struct {
func NewKeeper( func NewKeeper(
env appmodule.Environment, env appmodule.Environment,
cdc codec.BinaryCodec, cdc codec.BinaryCodec,
addressCodec address.Codec,
accountKeeper auth.AccountKeeper, accountKeeper auth.AccountKeeper,
bankKeeper bank.Keeper, bankKeeper bank.Keeper,
bondKeeper *bondkeeper.Keeper, bondKeeper *bondkeeper.Keeper,
auctionKeeper *auctionkeeper.Keeper, auctionKeeper *auctionkeeper.Keeper,
authority string, authority types.AccAddress,
logger log.Logger, logger log.Logger,
) Keeper { ) Keeper {
// ensure that authority is a valid AccAddress
if _, err := accountKeeper.AddressCodec().StringToBytes(authority); err != nil {
panic("authority is not a valid acc address")
}
sb := collections.NewSchemaBuilder(env.KVStoreService) sb := collections.NewSchemaBuilder(env.KVStoreService)
k := Keeper{ k := Keeper{
Environment: env, Environment: env,
@ -182,11 +181,6 @@ func NewKeeper(
return k return k
} }
// GetAuthority returns the x/registry module's authority.
func (k Keeper) GetAuthority() string {
return k.authority
}
// SetParams sets the x/registry module parameters. // SetParams sets the x/registry module parameters.
func (k Keeper) SetParams(ctx context.Context, params registrytypes.Params) error { func (k Keeper) SetParams(ctx context.Context, params registrytypes.Params) error {
return k.Params.Set(ctx, params) return k.Params.Set(ctx, params)

View File

@ -3,8 +3,8 @@ package keeper
import ( import (
"context" "context"
errorsmod "cosmossdk.io/errors" "cosmossdk.io/core/event"
govtypes "cosmossdk.io/x/gov/types" "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"git.vdb.to/cerc-io/laconicd/utils" "git.vdb.to/cerc-io/laconicd/utils"
@ -22,13 +22,13 @@ func NewMsgServerImpl(keeper Keeper) registrytypes.MsgServer {
return &msgServer{k: keeper} return &msgServer{k: keeper}
} }
func (ms msgServer) SetRecord(c context.Context, msg *registrytypes.MsgSetRecord) (*registrytypes.MsgSetRecordResponse, error) { func (ms msgServer) SetRecord(ctx context.Context, msg *registrytypes.MsgSetRecord) (*registrytypes.MsgSetRecordResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) refundGas(ms.k.logger, "SetRecord")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
_, err := addrCodec.StringToBytes(msg.Signer) _, err := addrCodec.StringToBytes(msg.Signer)
@ -41,33 +41,33 @@ func (ms msgServer) SetRecord(c context.Context, msg *registrytypes.MsgSetRecord
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewEvent( registrytypes.EventTypeSetRecord,
registrytypes.EventTypeSetRecord, event.NewAttribute(registrytypes.AttributeKeySigner, msg.GetSigner()),
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.GetSigner()), event.NewAttribute(registrytypes.AttributeKeyBondId, msg.GetBondId()),
sdk.NewAttribute(registrytypes.AttributeKeyBondId, msg.GetBondId()), event.NewAttribute(registrytypes.AttributeKeyPayload, msg.Payload.Record.Id),
sdk.NewAttribute(registrytypes.AttributeKeyPayload, msg.Payload.Record.Id), ); err != nil {
), return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeSetRecord)
sdk.NewEvent( }
sdk.EventTypeMessage, if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory), sdk.EventTypeMessage,
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
), event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
}) ); err != nil {
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
utils.LogTxGasConsumed(ctx, ms.k.logger, "SetRecord") }
return &registrytypes.MsgSetRecordResponse{Id: record.Id}, nil return &registrytypes.MsgSetRecordResponse{Id: record.Id}, nil
} }
// nolint: all // nolint: all
func (ms msgServer) SetName(c context.Context, msg *registrytypes.MsgSetName) (*registrytypes.MsgSetNameResponse, error) { func (ms msgServer) SetName(ctx context.Context, msg *registrytypes.MsgSetName) (*registrytypes.MsgSetNameResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) defer refundGas(ms.k.logger, "SetName")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
_, err := addrCodec.StringToBytes(msg.Signer) _, err := addrCodec.StringToBytes(msg.Signer)
@ -80,32 +80,32 @@ func (ms msgServer) SetName(c context.Context, msg *registrytypes.MsgSetName) (*
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewEvent( registrytypes.EventTypeSetRecord,
registrytypes.EventTypeSetRecord, event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(registrytypes.AttributeKeyLRN, msg.Lrn),
sdk.NewAttribute(registrytypes.AttributeKeyLRN, msg.Lrn), event.NewAttribute(registrytypes.AttributeKeyCID, msg.Cid),
sdk.NewAttribute(registrytypes.AttributeKeyCID, msg.Cid), ); err != nil {
), return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeSetRecord)
sdk.NewEvent( }
sdk.EventTypeMessage, if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory), sdk.EventTypeMessage,
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
), event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
}) ); err != nil {
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
utils.LogTxGasConsumed(ctx, ms.k.logger, "SetName") }
return &registrytypes.MsgSetNameResponse{}, nil return &registrytypes.MsgSetNameResponse{}, nil
} }
func (ms msgServer) ReserveAuthority(c context.Context, msg *registrytypes.MsgReserveAuthority) (*registrytypes.MsgReserveAuthorityResponse, error) { func (ms msgServer) ReserveAuthority(ctx context.Context, msg *registrytypes.MsgReserveAuthority) (*registrytypes.MsgReserveAuthorityResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) defer refundGas(ms.k.logger, "ReserveAuthority")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
_, err := addrCodec.StringToBytes(msg.Signer) _, err := addrCodec.StringToBytes(msg.Signer)
@ -122,33 +122,33 @@ func (ms msgServer) ReserveAuthority(c context.Context, msg *registrytypes.MsgRe
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewEvent( registrytypes.EventTypeReserveAuthority,
registrytypes.EventTypeReserveAuthority, event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(registrytypes.AttributeKeyName, msg.Name),
sdk.NewAttribute(registrytypes.AttributeKeyName, msg.Name), event.NewAttribute(registrytypes.AttributeKeyOwner, msg.Owner),
sdk.NewAttribute(registrytypes.AttributeKeyOwner, msg.Owner), ); err != nil {
), return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeReserveAuthority)
sdk.NewEvent( }
sdk.EventTypeMessage, if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory), sdk.EventTypeMessage,
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
), event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
}) ); err != nil {
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
utils.LogTxGasConsumed(ctx, ms.k.logger, "ReserveAuthority") }
return &registrytypes.MsgReserveAuthorityResponse{}, nil return &registrytypes.MsgReserveAuthorityResponse{}, nil
} }
// nolint: all // nolint: all
func (ms msgServer) SetAuthorityBond(c context.Context, msg *registrytypes.MsgSetAuthorityBond) (*registrytypes.MsgSetAuthorityBondResponse, error) { func (ms msgServer) SetAuthorityBond(ctx context.Context, msg *registrytypes.MsgSetAuthorityBond) (*registrytypes.MsgSetAuthorityBondResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) defer refundGas(ms.k.logger, "SetAuthorityBond")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
_, err := addrCodec.StringToBytes(msg.Signer) _, err := addrCodec.StringToBytes(msg.Signer)
@ -161,32 +161,32 @@ func (ms msgServer) SetAuthorityBond(c context.Context, msg *registrytypes.MsgSe
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewEvent( registrytypes.EventTypeAuthorityBond,
registrytypes.EventTypeAuthorityBond, event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(registrytypes.AttributeKeyName, msg.Name),
sdk.NewAttribute(registrytypes.AttributeKeyName, msg.Name), event.NewAttribute(registrytypes.AttributeKeyBondId, msg.BondId),
sdk.NewAttribute(registrytypes.AttributeKeyBondId, msg.BondId), ); err != nil {
), return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeAuthorityBond)
sdk.NewEvent( }
sdk.EventTypeMessage, if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory), sdk.EventTypeMessage,
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
), event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
}) ); err != nil {
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
utils.LogTxGasConsumed(ctx, ms.k.logger, "SetAuthorityBond") }
return &registrytypes.MsgSetAuthorityBondResponse{}, nil return &registrytypes.MsgSetAuthorityBondResponse{}, nil
} }
func (ms msgServer) DeleteName(c context.Context, msg *registrytypes.MsgDeleteName) (*registrytypes.MsgDeleteNameResponse, error) { func (ms msgServer) DeleteName(ctx context.Context, msg *registrytypes.MsgDeleteName) (*registrytypes.MsgDeleteNameResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) defer refundGas(ms.k.logger, "DeleteName")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
_, err := addrCodec.StringToBytes(msg.Signer) _, err := addrCodec.StringToBytes(msg.Signer)
@ -199,31 +199,31 @@ func (ms msgServer) DeleteName(c context.Context, msg *registrytypes.MsgDeleteNa
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewEvent( registrytypes.EventTypeDeleteName,
registrytypes.EventTypeDeleteName, event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(registrytypes.AttributeKeyLRN, msg.Lrn),
sdk.NewAttribute(registrytypes.AttributeKeyLRN, msg.Lrn), ); err != nil {
), return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeDeleteName)
sdk.NewEvent( }
sdk.EventTypeMessage, if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory), sdk.EventTypeMessage,
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
), event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
}) ); err != nil {
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
utils.LogTxGasConsumed(ctx, ms.k.logger, "DeleteName") }
return &registrytypes.MsgDeleteNameResponse{}, nil return &registrytypes.MsgDeleteNameResponse{}, nil
} }
func (ms msgServer) RenewRecord(c context.Context, msg *registrytypes.MsgRenewRecord) (*registrytypes.MsgRenewRecordResponse, error) { func (ms msgServer) RenewRecord(ctx context.Context, msg *registrytypes.MsgRenewRecord) (*registrytypes.MsgRenewRecordResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) defer refundGas(ms.k.logger, "RenewRecord")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
_, err := addrCodec.StringToBytes(msg.Signer) _, err := addrCodec.StringToBytes(msg.Signer)
@ -231,37 +231,37 @@ func (ms msgServer) RenewRecord(c context.Context, msg *registrytypes.MsgRenewRe
return nil, err return nil, err
} }
err = ms.k.RenewRecord(ctx, *msg, ms.k.HeaderService.HeaderInfo(c).Time) err = ms.k.RenewRecord(ctx, *msg, ms.k.HeaderService.HeaderInfo(ctx).Time)
if err != nil { if err != nil {
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewEvent( registrytypes.EventTypeRenewRecord,
registrytypes.EventTypeRenewRecord, event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(registrytypes.AttributeKeyRecordId, msg.RecordId),
sdk.NewAttribute(registrytypes.AttributeKeyRecordId, msg.RecordId), ); err != nil {
), return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeRenewRecord)
sdk.NewEvent( }
sdk.EventTypeMessage, if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory), sdk.EventTypeMessage,
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
), event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
}) ); err != nil {
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
utils.LogTxGasConsumed(ctx, ms.k.logger, "RenewRecord") }
return &registrytypes.MsgRenewRecordResponse{}, nil return &registrytypes.MsgRenewRecordResponse{}, nil
} }
// nolint: all // nolint: all
func (ms msgServer) AssociateBond(c context.Context, msg *registrytypes.MsgAssociateBond) (*registrytypes.MsgAssociateBondResponse, error) { func (ms msgServer) AssociateBond(ctx context.Context, msg *registrytypes.MsgAssociateBond) (*registrytypes.MsgAssociateBondResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) defer refundGas(ms.k.logger, "AssociateBond")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
_, err := addrCodec.StringToBytes(msg.Signer) _, err := addrCodec.StringToBytes(msg.Signer)
@ -274,32 +274,32 @@ func (ms msgServer) AssociateBond(c context.Context, msg *registrytypes.MsgAssoc
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewEvent( registrytypes.EventTypeAssociateBond,
registrytypes.EventTypeAssociateBond, event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(registrytypes.AttributeKeyRecordId, msg.RecordId),
sdk.NewAttribute(registrytypes.AttributeKeyRecordId, msg.RecordId), event.NewAttribute(registrytypes.AttributeKeyBondId, msg.BondId),
sdk.NewAttribute(registrytypes.AttributeKeyBondId, msg.BondId), ); err != nil {
), return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeAssociateBond)
sdk.NewEvent( }
sdk.EventTypeMessage, if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory), sdk.EventTypeMessage,
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
), event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
}) ); err != nil {
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
utils.LogTxGasConsumed(ctx, ms.k.logger, "AssociateBond") }
return &registrytypes.MsgAssociateBondResponse{}, nil return &registrytypes.MsgAssociateBondResponse{}, nil
} }
func (ms msgServer) DissociateBond(c context.Context, msg *registrytypes.MsgDissociateBond) (*registrytypes.MsgDissociateBondResponse, error) { func (ms msgServer) DissociateBond(ctx context.Context, msg *registrytypes.MsgDissociateBond) (*registrytypes.MsgDissociateBondResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) defer refundGas(ms.k.logger, "DissociateBond")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
_, err := addrCodec.StringToBytes(msg.Signer) _, err := addrCodec.StringToBytes(msg.Signer)
@ -312,34 +312,34 @@ func (ms msgServer) DissociateBond(c context.Context, msg *registrytypes.MsgDiss
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewEvent( registrytypes.EventTypeDissociateBond,
registrytypes.EventTypeDissociateBond, event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(registrytypes.AttributeKeyRecordId, msg.RecordId),
sdk.NewAttribute(registrytypes.AttributeKeyRecordId, msg.RecordId), ); err != nil {
), return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeDissociateBond)
sdk.NewEvent( }
sdk.EventTypeMessage, if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory), sdk.EventTypeMessage,
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
), event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
}) ); err != nil {
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
utils.LogTxGasConsumed(ctx, ms.k.logger, "DissociateBond") }
return &registrytypes.MsgDissociateBondResponse{}, nil return &registrytypes.MsgDissociateBondResponse{}, nil
} }
func (ms msgServer) DissociateRecords( func (ms msgServer) DissociateRecords(
c context.Context, ctx context.Context,
msg *registrytypes.MsgDissociateRecords, msg *registrytypes.MsgDissociateRecords,
) (*registrytypes.MsgDissociateRecordsResponse, error) { ) (*registrytypes.MsgDissociateRecordsResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) defer refundGas(ms.k.logger, "DissociateRecords")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
_, err := addrCodec.StringToBytes(msg.Signer) _, err := addrCodec.StringToBytes(msg.Signer)
@ -352,31 +352,31 @@ func (ms msgServer) DissociateRecords(
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewEvent( registrytypes.EventTypeDissociateRecords,
registrytypes.EventTypeDissociateRecords, event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(registrytypes.AttributeKeyBondId, msg.BondId),
sdk.NewAttribute(registrytypes.AttributeKeyBondId, msg.BondId), ); err != nil {
), return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeDissociateRecords)
sdk.NewEvent( }
sdk.EventTypeMessage, if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory), sdk.EventTypeMessage,
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
), event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
}) ); err != nil {
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
utils.LogTxGasConsumed(ctx, ms.k.logger, "DissociateRecords") }
return &registrytypes.MsgDissociateRecordsResponse{}, nil return &registrytypes.MsgDissociateRecordsResponse{}, nil
} }
func (ms msgServer) ReassociateRecords(c context.Context, msg *registrytypes.MsgReassociateRecords) (*registrytypes.MsgReassociateRecordsResponse, error) { //nolint: all func (ms msgServer) ReassociateRecords(ctx context.Context, msg *registrytypes.MsgReassociateRecords) (*registrytypes.MsgReassociateRecordsResponse, error) { //nolint: all
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c) refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
ctx = *utils.CtxWithCustomKVGasConfig(&ctx) defer refundGas(ms.k.logger, "ReassociateRecords")
addrCodec := utils.NewAddressCodec() addrCodec := utils.NewAddressCodec()
_, err := addrCodec.StringToBytes(msg.Signer) _, err := addrCodec.StringToBytes(msg.Signer)
@ -389,37 +389,35 @@ func (ms msgServer) ReassociateRecords(c context.Context, msg *registrytypes.Msg
return nil, err return nil, err
} }
ctx.EventManager().EmitEvents(sdk.Events{ if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewEvent( registrytypes.EventTypeReassociateRecords,
registrytypes.EventTypeReassociateRecords, event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(registrytypes.AttributeKeyOldBondId, msg.OldBondId),
sdk.NewAttribute(registrytypes.AttributeKeyOldBondId, msg.OldBondId), event.NewAttribute(registrytypes.AttributeKeyNewBondId, msg.NewBondId),
sdk.NewAttribute(registrytypes.AttributeKeyNewBondId, msg.NewBondId), ); err != nil {
), return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeReassociateRecords)
sdk.NewEvent( }
sdk.EventTypeMessage, if err := ms.k.EventService.EventManager(ctx).EmitKV(
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory), sdk.EventTypeMessage,
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer), event.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
), event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
}) ); err != nil {
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
utils.LogTxGasConsumed(ctx, ms.k.logger, "ReassociateRecords") }
return &registrytypes.MsgReassociateRecordsResponse{}, nil return &registrytypes.MsgReassociateRecordsResponse{}, nil
} }
// UpdateParams defines a method to perform updation of module params. // UpdateParams defines a method to perform updation of module params.
func (ms msgServer) UpdateParams(c context.Context, msg *registrytypes.MsgUpdateParams) (*registrytypes.MsgUpdateParamsResponse, error) { func (ms msgServer) UpdateParams(ctx context.Context, msg *registrytypes.MsgUpdateParams) (*registrytypes.MsgUpdateParamsResponse, error) {
if ms.k.authority != msg.Authority { if err := utils.CheckAuthorityAddress(ms.k.addressCodec, ms.k.authority, msg.Authority); err != nil {
return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.k.authority, msg.Authority) return nil, err
} }
if err := msg.Params.Validate(); err != nil { if err := msg.Params.Validate(); err != nil {
return nil, err return nil, err
} }
ctx := sdk.UnwrapSDKContext(c)
if err := ms.k.SetParams(ctx, msg.Params); err != nil { if err := ms.k.SetParams(ctx, msg.Params); err != nil {
return nil, err return nil, err
} }

View File

@ -1,6 +1,7 @@
package module package module
import ( import (
"cosmossdk.io/core/address"
"cosmossdk.io/core/appmodule" "cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject" "cosmossdk.io/depinject"
"cosmossdk.io/depinject/appconfig" "cosmossdk.io/depinject/appconfig"
@ -9,9 +10,9 @@ import (
govtypes "cosmossdk.io/x/gov/types" govtypes "cosmossdk.io/x/gov/types"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
auth "github.com/cosmos/cosmos-sdk/x/auth/keeper" auth "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
modulev1 "git.vdb.to/cerc-io/laconicd/api/cerc/registry/module/v1" modulev1 "git.vdb.to/cerc-io/laconicd/api/cerc/registry/module/v1"
"git.vdb.to/cerc-io/laconicd/utils"
"git.vdb.to/cerc-io/laconicd/x/auction" "git.vdb.to/cerc-io/laconicd/x/auction"
auctionkeeper "git.vdb.to/cerc-io/laconicd/x/auction/keeper" auctionkeeper "git.vdb.to/cerc-io/laconicd/x/auction/keeper"
"git.vdb.to/cerc-io/laconicd/x/bond" "git.vdb.to/cerc-io/laconicd/x/bond"
@ -37,10 +38,11 @@ func init() {
type ModuleInputs struct { type ModuleInputs struct {
depinject.In depinject.In
Env appmodule.Environment Env appmodule.Environment
Config *modulev1.Module Config *modulev1.Module
Cdc codec.Codec Cdc codec.Codec
Logger log.Logger AddressCodec address.Codec
Logger log.Logger
AccountKeeper auth.AccountKeeper AccountKeeper auth.AccountKeeper
BankKeeper bank.Keeper BankKeeper bank.Keeper
@ -61,18 +63,16 @@ type ModuleOutputs struct {
func ProvideModule(in ModuleInputs) ModuleOutputs { func ProvideModule(in ModuleInputs) ModuleOutputs {
// default to governance authority if not provided // default to governance authority if not provided
authority := authtypes.NewModuleAddress(govtypes.ModuleName) authority := utils.AddressOrModuleAddress(in.Config.Authority, govtypes.ModuleName)
if in.Config.Authority != "" {
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}
k := keeper.NewKeeper( k := keeper.NewKeeper(
in.Env, in.Env,
in.Cdc, in.Cdc,
in.AddressCodec,
in.AccountKeeper, in.AccountKeeper,
in.BankKeeper, in.BankKeeper,
in.BondKeeper, in.BondKeeper,
in.AuctionKeeper, in.AuctionKeeper,
authority.String(), authority,
in.Logger, in.Logger,
) )
m := NewAppModule(in.Cdc, k) m := NewAppModule(in.Cdc, k)

View File

@ -6,7 +6,7 @@ import (
"fmt" "fmt"
"cosmossdk.io/client/v2/autocli" "cosmossdk.io/client/v2/autocli"
"cosmossdk.io/core/appmodule" appmodule "cosmossdk.io/core/appmodule/v2"
"cosmossdk.io/core/registry" "cosmossdk.io/core/registry"
"github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
@ -22,14 +22,16 @@ import (
var ( var (
_ appmodule.AppModule = AppModule{} _ appmodule.AppModule = AppModule{}
_ appmodule.HasConsensusVersion = AppModule{}
_ appmodule.HasEndBlocker = AppModule{} _ appmodule.HasEndBlocker = AppModule{}
_ appmodule.HasGenesis = AppModule{} _ appmodule.HasGenesis = AppModule{}
_ appmodule.HasConsensusVersion = AppModule{} _ appmodule.HasMsgHandlers = AppModule{}
_ appmodule.HasQueryHandlers = AppModule{}
_ appmodule.HasRegisterInterfaces = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{}
_ module.HasGRPCGateway = AppModule{} _ module.HasGRPCGateway = AppModule{}
_ module.HasServices = AppModule{} // _ module.HasServices = AppModule{}
_ module.HasInvariants = AppModule{} _ module.HasInvariants = AppModule{}
// _ module.HasAminoCodec = AppModule{} // TODO // _ module.HasAminoCodec = AppModule{} // TODO
_ autocli.HasCustomTxCommand = AppModule{} _ autocli.HasCustomTxCommand = AppModule{}
@ -115,13 +117,39 @@ func (am AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error)
return am.cdc.MustMarshalJSON(gs), nil return am.cdc.MustMarshalJSON(gs), nil
} }
// module.HasServices // HasMsgHandlers
// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries. func (am AppModule) RegisterMsgHandlers(router appmodule.MsgRouter) {
func (am AppModule) RegisterServices(cfg module.Configurator) { handlers := keeper.NewMsgServerImpl(am.keeper)
// Register servers
registrytypes.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) appmodule.RegisterMsgHandler(router, handlers.AssociateBond)
registrytypes.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper)) appmodule.RegisterMsgHandler(router, handlers.DeleteName)
appmodule.RegisterMsgHandler(router, handlers.DissociateBond)
appmodule.RegisterMsgHandler(router, handlers.DissociateRecords)
appmodule.RegisterMsgHandler(router, handlers.ReassociateRecords)
appmodule.RegisterMsgHandler(router, handlers.RenewRecord)
appmodule.RegisterMsgHandler(router, handlers.ReserveAuthority)
appmodule.RegisterMsgHandler(router, handlers.SetAuthorityBond)
appmodule.RegisterMsgHandler(router, handlers.SetName)
appmodule.RegisterMsgHandler(router, handlers.SetRecord)
appmodule.RegisterMsgHandler(router, handlers.UpdateParams)
}
// HasQueryHandlers
func (am AppModule) RegisterQueryHandlers(router appmodule.QueryRouter) {
handlers := keeper.NewQueryServerImpl(am.keeper)
appmodule.RegisterMsgHandler(router, handlers.Authorities)
appmodule.RegisterMsgHandler(router, handlers.GetRecord)
appmodule.RegisterMsgHandler(router, handlers.GetRecordsByBondId)
appmodule.RegisterMsgHandler(router, handlers.GetRegistryModuleBalance)
appmodule.RegisterMsgHandler(router, handlers.LookupLrn)
appmodule.RegisterMsgHandler(router, handlers.NameRecords)
appmodule.RegisterMsgHandler(router, handlers.Params)
appmodule.RegisterMsgHandler(router, handlers.Records)
appmodule.RegisterMsgHandler(router, handlers.ResolveLrn)
appmodule.RegisterMsgHandler(router, handlers.Whois)
} }
// appmodule.HasEndBlocker // appmodule.HasEndBlocker

View File

@ -19,18 +19,18 @@ func NewMsgSetRecord(payload Payload, bondId string, signer sdk.AccAddress) *Msg
func (msg MsgSetRecord) ValidateBasic() error { func (msg MsgSetRecord) ValidateBasic() error {
if len(msg.Signer) == 0 { if len(msg.Signer) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer) return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "empty signer address")
} }
owners := msg.Payload.Record.Owners owners := msg.Payload.Record.Owners
for _, owner := range owners { for _, owner := range owners {
if owner == "" { if owner == "" {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Record owner not set.") return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "record owner not set")
} }
} }
if len(msg.BondId) == 0 { if len(msg.BondId) == 0 {
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond Id is required.") return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "bond ID is required")
} }
return nil return nil
@ -38,11 +38,11 @@ func (msg MsgSetRecord) ValidateBasic() error {
func (msg MsgRenewRecord) ValidateBasic() error { func (msg MsgRenewRecord) ValidateBasic() error {
if len(msg.RecordId) == 0 { if len(msg.RecordId) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "record id is required.") return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "record ID is required")
} }
if len(msg.Signer) == 0 { if len(msg.Signer) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.") return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
} }
return nil return nil
@ -60,7 +60,7 @@ func NewMsgReserveAuthority(name string, signer sdk.AccAddress, owner sdk.AccAdd
// ValidateBasic Implements Msg. // ValidateBasic Implements Msg.
func (msg MsgReserveAuthority) ValidateBasic() error { func (msg MsgReserveAuthority) ValidateBasic() error {
if len(msg.Name) == 0 { if len(msg.Name) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "name is required.") return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "name is required")
} }
if len(msg.Signer) == 0 { if len(msg.Signer) == 0 {
@ -81,15 +81,15 @@ func NewMsgSetAuthorityBond(name string, bondID string, signer sdk.AccAddress) M
func (msg MsgSetAuthorityBond) ValidateBasic() error { func (msg MsgSetAuthorityBond) ValidateBasic() error {
if len(msg.Name) == 0 { if len(msg.Name) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "name is required.") return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "name is required")
} }
if len(msg.Signer) == 0 { if len(msg.Signer) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.") return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
} }
if len(msg.BondId) == 0 { if len(msg.BondId) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "bond id is required.") return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "bond id is required")
} }
return nil return nil
@ -107,11 +107,11 @@ func NewMsgSetName(lrn string, cid string, signer sdk.AccAddress) *MsgSetName {
// ValidateBasic Implements Msg. // ValidateBasic Implements Msg.
func (msg MsgSetName) ValidateBasic() error { func (msg MsgSetName) ValidateBasic() error {
if msg.Lrn == "" { if msg.Lrn == "" {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "LRN is required.") return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "LRN is required")
} }
if msg.Cid == "" { if msg.Cid == "" {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "CID is required.") return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "CID is required")
} }
if len(msg.Signer) == 0 { if len(msg.Signer) == 0 {
@ -123,16 +123,16 @@ func (msg MsgSetName) ValidateBasic() error {
func (msg MsgDeleteName) ValidateBasic() error { func (msg MsgDeleteName) ValidateBasic() error {
if len(msg.Lrn) == 0 { if len(msg.Lrn) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "lrn is required.") return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "lrn is required")
} }
if len(msg.Signer) == 0 { if len(msg.Signer) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.") return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
} }
_, err := url.Parse(msg.Lrn) _, err := url.Parse(msg.Lrn)
if err != nil { if err != nil {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid lrn.") return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid lrn")
} }
return nil return nil
@ -140,13 +140,13 @@ func (msg MsgDeleteName) ValidateBasic() error {
func (msg MsgAssociateBond) ValidateBasic() error { func (msg MsgAssociateBond) ValidateBasic() error {
if len(msg.RecordId) == 0 { if len(msg.RecordId) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "record id is required.") return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "record id is required")
} }
if len(msg.BondId) == 0 { if len(msg.BondId) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "bond id is required.") return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "bond id is required")
} }
if len(msg.Signer) == 0 { if len(msg.Signer) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.") return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
} }
return nil return nil
@ -154,10 +154,10 @@ func (msg MsgAssociateBond) ValidateBasic() error {
func (msg MsgDissociateBond) ValidateBasic() error { func (msg MsgDissociateBond) ValidateBasic() error {
if len(msg.RecordId) == 0 { if len(msg.RecordId) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "record id is required.") return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "record id is required")
} }
if len(msg.Signer) == 0 { if len(msg.Signer) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.") return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
} }
return nil return nil
@ -165,10 +165,10 @@ func (msg MsgDissociateBond) ValidateBasic() error {
func (msg MsgDissociateRecords) ValidateBasic() error { func (msg MsgDissociateRecords) ValidateBasic() error {
if len(msg.BondId) == 0 { if len(msg.BondId) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "bond id is required.") return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "bond id is required")
} }
if len(msg.Signer) == 0 { if len(msg.Signer) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.") return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
} }
return nil return nil
@ -176,13 +176,13 @@ func (msg MsgDissociateRecords) ValidateBasic() error {
func (msg MsgReassociateRecords) ValidateBasic() error { func (msg MsgReassociateRecords) ValidateBasic() error {
if len(msg.OldBondId) == 0 { if len(msg.OldBondId) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "old-bond-id is required.") return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "old-bond-id is required")
} }
if len(msg.NewBondId) == 0 { if len(msg.NewBondId) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "new-bond-id is required.") return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "new-bond-id is required")
} }
if len(msg.Signer) == 0 { if len(msg.Signer) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.") return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
} }
return nil return nil