[wip] laconic module fixes
- msg & query servers - clean up logging, errors - don't use sdk global config
This commit is contained in:
parent
72a93dec2f
commit
b55e05e4ec
@ -1,9 +1,5 @@
|
||||
package params
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
const (
|
||||
CoinUnit = "lnt"
|
||||
BaseCoinUnit = "alnt"
|
||||
@ -29,7 +25,6 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
SetAddressPrefixes()
|
||||
RegisterDenoms()
|
||||
}
|
||||
|
||||
@ -45,10 +40,3 @@ func RegisterDenoms() {
|
||||
// panic(err)
|
||||
// }
|
||||
}
|
||||
|
||||
func SetAddressPrefixes() {
|
||||
config := sdk.GetConfig()
|
||||
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
|
||||
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
|
||||
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ func (tf *TestFixture) Setup(t *testing.T) error {
|
||||
accountsModKeeper,
|
||||
maccPerms,
|
||||
utils.NewAddressCodec(),
|
||||
sdk.GetConfig().GetBech32AccountAddrPrefix(),
|
||||
params.Bech32PrefixAccAddr,
|
||||
authority.String(),
|
||||
)
|
||||
|
||||
|
@ -5,18 +5,17 @@ import (
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
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 {
|
||||
bech32codec address.Codec
|
||||
address.Codec
|
||||
}
|
||||
|
||||
func (ac addressCodec) StringToBytes(text string) ([]byte, error) {
|
||||
bz, err := ac.bech32codec.StringToBytes(text)
|
||||
bz, err := ac.Codec.StringToBytes(text)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -27,24 +26,28 @@ func (ac addressCodec) StringToBytes(text string) ([]byte, error) {
|
||||
return bz, nil
|
||||
}
|
||||
|
||||
func (ac addressCodec) BytesToString(bz []byte) (string, error) {
|
||||
return ac.bech32codec.BytesToString(bz)
|
||||
}
|
||||
|
||||
func NewAddressCodec() address.Codec {
|
||||
return addressCodec{
|
||||
bech32codec: addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
|
||||
Codec: addresscodec.NewBech32Codec(params.Bech32PrefixAccAddr),
|
||||
}
|
||||
}
|
||||
|
||||
func NewValAddressCodec() address.ValidatorAddressCodec {
|
||||
return addressCodec{
|
||||
bech32codec: addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
|
||||
Codec: addresscodec.NewBech32Codec(params.Bech32PrefixValAddr),
|
||||
}
|
||||
}
|
||||
|
||||
func NewConsAddressCodec() address.ConsensusAddressCodec {
|
||||
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
|
||||
}
|
||||
|
@ -3,12 +3,15 @@ package utils
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/core/gas"
|
||||
"cosmossdk.io/log"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
const RefundModuleGasDescriptor = "laconic module gas refund"
|
||||
|
||||
func CtxWithCustomKVGasConfig(ctx *sdk.Context) *sdk.Context {
|
||||
updatedCtx := ctx.WithKVGasConfig(storetypes.GasConfig{
|
||||
HasCost: 0,
|
||||
@ -23,7 +26,16 @@ func CtxWithCustomKVGasConfig(ctx *sdk.Context) *sdk.Context {
|
||||
return &updatedCtx
|
||||
}
|
||||
|
||||
func LogTxGasConsumed(ctx sdk.Context, logger log.Logger, tx string) {
|
||||
gasConsumed := ctx.GasMeter().GasConsumed()
|
||||
logger.Info("tx executed", "method", tx, "gas_consumed", fmt.Sprintf("%d", gasConsumed))
|
||||
func LogTxGasConsumed(gm gas.Meter, logger log.Logger, method string) {
|
||||
gasConsumed := gm.Consumed()
|
||||
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
38
utils/modules.go
Normal 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
|
||||
}
|
@ -5,12 +5,12 @@ import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
"cosmossdk.io/collections/indexes"
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"cosmossdk.io/log"
|
||||
@ -18,6 +18,7 @@ import (
|
||||
|
||||
bank "cosmossdk.io/x/bank/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
auth "github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||
@ -68,11 +69,11 @@ func newBidsIndexes(sb *collections.SchemaBuilder) BidsIndexes {
|
||||
|
||||
type Keeper struct {
|
||||
appmodule.Environment
|
||||
cdc codec.BinaryCodec
|
||||
logger log.Logger
|
||||
// addressCodec address.Codec //TODO
|
||||
cdc codec.BinaryCodec
|
||||
logger log.Logger
|
||||
addressCodec address.Codec
|
||||
|
||||
authority string
|
||||
authority types.AccAddress
|
||||
|
||||
// External keepers
|
||||
accountKeeper auth.AccountKeeper
|
||||
@ -96,20 +97,17 @@ type Keeper struct {
|
||||
func NewKeeper(
|
||||
env appmodule.Environment,
|
||||
cdc codec.BinaryCodec,
|
||||
addressCodec address.Codec,
|
||||
accountKeeper auth.AccountKeeper,
|
||||
bankKeeper bank.Keeper,
|
||||
authority string,
|
||||
authority types.AccAddress,
|
||||
logger log.Logger,
|
||||
) *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)
|
||||
k := Keeper{
|
||||
Environment: env,
|
||||
cdc: cdc,
|
||||
addressCodec: addressCodec,
|
||||
logger: logger.With(log.ModuleKey, "x/"+auctiontypes.ModuleName),
|
||||
authority: authority,
|
||||
accountKeeper: accountKeeper,
|
||||
@ -265,7 +263,7 @@ func (k Keeper) GetAuctionById(ctx context.Context, id string) (auctiontypes.Auc
|
||||
auction, err := k.Auctions.Get(ctx, id)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
@ -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))
|
||||
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 {
|
||||
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)
|
||||
@ -384,7 +382,7 @@ func (k Keeper) CommitBid(ctx context.Context, msg auctiontypes.MsgCommitBid) (*
|
||||
}
|
||||
|
||||
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()
|
||||
@ -442,7 +440,7 @@ func (k Keeper) RevealBid(ctx context.Context, msg auctiontypes.MsgRevealBid) (*
|
||||
if err != nil {
|
||||
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)
|
||||
@ -451,7 +449,7 @@ func (k Keeper) RevealBid(ctx context.Context, msg auctiontypes.MsgRevealBid) (*
|
||||
}
|
||||
|
||||
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()
|
||||
@ -466,7 +464,7 @@ func (k Keeper) RevealBid(ctx context.Context, msg auctiontypes.MsgRevealBid) (*
|
||||
}
|
||||
|
||||
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)
|
||||
@ -475,65 +473,65 @@ func (k Keeper) RevealBid(ctx context.Context, msg auctiontypes.MsgRevealBid) (*
|
||||
}
|
||||
|
||||
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)
|
||||
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)
|
||||
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 {
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Commit hash mismatch.")
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Commit hash mismatch")
|
||||
}
|
||||
|
||||
var reveal map[string]interface{}
|
||||
err = json.Unmarshal(revealBytes, &reveal)
|
||||
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)
|
||||
chainId, err := utils.GetAttributeAsString(reveal, "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")
|
||||
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")
|
||||
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 {
|
||||
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")
|
||||
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)
|
||||
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) {
|
||||
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) {
|
||||
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.
|
||||
@ -555,11 +553,6 @@ func (k Keeper) RevealBid(ctx context.Context, msg auctiontypes.MsgRevealBid) (*
|
||||
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.
|
||||
func (k Keeper) GetParams(ctx context.Context) (*auctiontypes.Params, error) {
|
||||
params, err := k.Params.Get(ctx)
|
||||
@ -610,7 +603,7 @@ func (k Keeper) processAuctionPhases(ctx context.Context) error {
|
||||
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.
|
||||
@ -620,7 +613,7 @@ func (k Keeper) processAuctionPhases(ctx context.Context) error {
|
||||
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.
|
||||
@ -651,7 +644,7 @@ func (k Keeper) deleteCompletedAuctions(ctx context.Context) error {
|
||||
}
|
||||
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
@ -662,7 +655,8 @@ func (k Keeper) deleteCompletedAuctions(ctx context.Context) error {
|
||||
|
||||
// Pick winner for vickrey auction
|
||||
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 secondHighestBid *auctiontypes.Bid
|
||||
@ -673,38 +667,38 @@ func (k Keeper) pickAuctionWinner(ctx context.Context, auction *auctiontypes.Auc
|
||||
}
|
||||
|
||||
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.
|
||||
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
|
||||
}
|
||||
|
||||
// Init highest bid.
|
||||
if highestBid == nil {
|
||||
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
|
||||
}
|
||||
|
||||
//nolint: all
|
||||
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
|
||||
highestBid = bid
|
||||
|
||||
k.logger.Info(fmt.Sprintf("Updated 1st bid %s %s", highestBid.BidderAddress, highestBid.BidAmount.String()))
|
||||
k.logger.Info(fmt.Sprintf("Updated 2nd bid %s %s", secondHighestBid.BidderAddress, secondHighestBid.BidAmount.String()))
|
||||
logger.Info("Updated 1st bid", "address", highestBid.BidderAddress, "amount", highestBid.BidAmount)
|
||||
logger.Info("Updated 2nd bid", "address", secondHighestBid.BidderAddress, "amount", secondHighestBid.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
|
||||
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 {
|
||||
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 {
|
||||
auction.WinningPrice = secondHighestBid.BidAmount
|
||||
}
|
||||
k.logger.Info(fmt.Sprintf("Auction %s winner %s.", auction.Id, auction.WinnerAddresses[0]))
|
||||
k.logger.Info(fmt.Sprintf("Auction %s winner bid %s.", auction.Id, auction.WinningBids[0].String()))
|
||||
k.logger.Info(fmt.Sprintf("Auction %s winning price %s.", auction.Id, auction.WinningPrice.String()))
|
||||
logger.Info("Auction winner chosen",
|
||||
"address", auction.WinnerAddresses[0],
|
||||
"bid", auction.WinningBids[0],
|
||||
"price", auction.WinningPrice)
|
||||
} 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 {
|
||||
@ -736,15 +731,15 @@ func (k Keeper) pickAuctionWinner(ctx context.Context, auction *auctiontypes.Auc
|
||||
for _, bid := range bids {
|
||||
bidderAddress, err := addrCodec.StringToBytes(bid.BidderAddress)
|
||||
if err != nil {
|
||||
k.logger.Error(fmt.Sprintf("Invalid bidderAddress address. %v", err))
|
||||
panic("Invalid bidder address.")
|
||||
logger.Error("Invalid bidderAddress address", "error", err)
|
||||
panic("Invalid bidder address")
|
||||
}
|
||||
|
||||
if bid.Status == auctiontypes.BidStatusRevealed {
|
||||
// Send reveal fee back to bidders that've revealed the bid.
|
||||
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, auctiontypes.ModuleName, bidderAddress, sdk.NewCoins(bid.RevealFee))
|
||||
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)
|
||||
}
|
||||
}
|
||||
@ -752,7 +747,7 @@ func (k Keeper) pickAuctionWinner(ctx context.Context, auction *auctiontypes.Auc
|
||||
// Send back locked bid amount to all bidders.
|
||||
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, auctiontypes.ModuleName, bidderAddress, sdk.NewCoins(bid.BidAmount))
|
||||
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)
|
||||
}
|
||||
}
|
||||
@ -761,22 +756,22 @@ func (k Keeper) pickAuctionWinner(ctx context.Context, auction *auctiontypes.Auc
|
||||
if len(auction.WinnerAddresses) != 0 {
|
||||
winnerAddress, err := addrCodec.StringToBytes(auction.WinnerAddresses[0])
|
||||
if err != nil {
|
||||
k.logger.Error(fmt.Sprintf("Invalid winner address. %v", err))
|
||||
panic("Invalid winner address.")
|
||||
logger.Error("Invalid winner address", "error", err)
|
||||
panic("Invalid winner address")
|
||||
}
|
||||
|
||||
// Take 2nd price from winner.
|
||||
sdkErr := k.bankKeeper.SendCoinsFromAccountToModule(ctx, winnerAddress, auctiontypes.ModuleName, sdk.NewCoins(auction.WinningPrice))
|
||||
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)
|
||||
}
|
||||
|
||||
// Burn anything over the min. bid amount.
|
||||
amountToBurn := auction.WinningPrice.Sub(auction.MinimumBid)
|
||||
if amountToBurn.IsNegative() {
|
||||
k.logger.Error("Auction coins to burn cannot be negative.")
|
||||
panic("Auction coins to burn cannot be negative.")
|
||||
logger.Error("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.
|
||||
@ -787,15 +782,15 @@ func (k Keeper) pickAuctionWinner(ctx context.Context, auction *auctiontypes.Auc
|
||||
sdk.NewCoins(amountToBurn),
|
||||
)
|
||||
if sdkErr != nil {
|
||||
k.logger.Error(fmt.Sprintf("Auction error burning coins: %v", sdkErr))
|
||||
logger.Error("Error burning coins", "error", sdkErr)
|
||||
panic(sdkErr)
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
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))
|
||||
}
|
||||
|
||||
@ -804,7 +799,8 @@ func (k Keeper) pickAuctionWinner(ctx context.Context, auction *auctiontypes.Auc
|
||||
|
||||
// Pick winner for provider auction
|
||||
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)
|
||||
if err != nil {
|
||||
@ -813,11 +809,11 @@ func (k Keeper) pickProviderAuctionWinners(ctx context.Context, auction *auction
|
||||
|
||||
revealedBids := make([]*auctiontypes.Bid, 0, len(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.
|
||||
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
|
||||
}
|
||||
|
||||
@ -858,11 +854,11 @@ func (k Keeper) pickProviderAuctionWinners(ctx context.Context, auction *auction
|
||||
auction.WinningPrice = winnerBids[len(winnerBids)-1].BidAmount
|
||||
|
||||
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 {
|
||||
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 {
|
||||
@ -874,15 +870,15 @@ func (k Keeper) pickProviderAuctionWinners(ctx context.Context, auction *auction
|
||||
for _, bid := range bids {
|
||||
bidderAddress, err := addrCodec.StringToBytes(bid.BidderAddress)
|
||||
if err != nil {
|
||||
k.logger.Error(fmt.Sprintf("Invalid bidderAddress address. %v", err))
|
||||
panic("Invalid bidder address.")
|
||||
logger.Error("Invalid bidderAddress address", "error", err)
|
||||
panic("Invalid bidder address")
|
||||
}
|
||||
|
||||
if bid.Status == auctiontypes.BidStatusRevealed {
|
||||
// Send reveal fee back to bidders that've revealed the bid.
|
||||
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, auctiontypes.ModuleName, bidderAddress, sdk.NewCoins(bid.RevealFee))
|
||||
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)
|
||||
}
|
||||
}
|
||||
@ -896,8 +892,8 @@ func (k Keeper) pickProviderAuctionWinners(ctx context.Context, auction *auction
|
||||
|
||||
ownerAccAddress, err := addrCodec.StringToBytes(auction.OwnerAddress)
|
||||
if err != nil {
|
||||
k.logger.Error(fmt.Sprintf("Invalid auction owner address. %v", err))
|
||||
panic("Invalid auction owner address.")
|
||||
logger.Error("Invalid auction owner address", "error", err)
|
||||
panic("Invalid auction owner address")
|
||||
}
|
||||
|
||||
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(
|
||||
@ -907,14 +903,13 @@ func (k Keeper) pickProviderAuctionWinners(ctx context.Context, auction *auction
|
||||
sdk.NewCoins(creatorLeftOverAmount),
|
||||
)
|
||||
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)
|
||||
}
|
||||
|
||||
// Notify other modules (hook).
|
||||
k.logger.Info(fmt.Sprintf("Auction %s notifying %d modules.", auction.Id, len(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))
|
||||
}
|
||||
|
||||
@ -928,20 +923,20 @@ func (k Keeper) ReleaseFunds(ctx context.Context, msg auctiontypes.MsgReleaseFun
|
||||
}
|
||||
|
||||
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.
|
||||
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 {
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction is not completed.")
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction is not completed")
|
||||
}
|
||||
|
||||
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
|
||||
@ -951,24 +946,25 @@ func (k Keeper) ReleaseFunds(ctx context.Context, msg auctiontypes.MsgReleaseFun
|
||||
}
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
logger := k.logger.With("id", auction.Id)
|
||||
|
||||
// Process winner accounts.
|
||||
for _, winnerAddress := range auction.WinnerAddresses {
|
||||
winnerAccAddress, err := addrCodec.StringToBytes(winnerAddress)
|
||||
for _, winner := range auction.WinnerAddresses {
|
||||
winnerAddress, err := addrCodec.StringToBytes(winner)
|
||||
if err != nil {
|
||||
k.logger.Error(fmt.Sprintf("Invalid winner address. %v", err))
|
||||
panic("Invalid winner address.")
|
||||
logger.Error("Invalid winner address", "error", err)
|
||||
panic("Invalid winner address")
|
||||
}
|
||||
|
||||
// Send winning price to winning bidders
|
||||
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(
|
||||
ctx,
|
||||
auctiontypes.ModuleName,
|
||||
winnerAccAddress,
|
||||
winnerAddress,
|
||||
sdk.NewCoins(auction.WinningPrice),
|
||||
)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package keeper
|
||||
import (
|
||||
"context"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
govtypes "cosmossdk.io/x/gov/types"
|
||||
"cosmossdk.io/core/event"
|
||||
"cosmossdk.io/errors"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"git.vdb.to/cerc-io/laconicd/utils"
|
||||
@ -22,9 +22,9 @@ func NewMsgServerImpl(keeper *Keeper) auctiontypes.MsgServer {
|
||||
return &msgServer{k: keeper}
|
||||
}
|
||||
|
||||
func (ms msgServer) CreateAuction(c context.Context, msg *auctiontypes.MsgCreateAuction) (*auctiontypes.MsgCreateAuctionResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
func (ms msgServer) CreateAuction(ctx context.Context, msg *auctiontypes.MsgCreateAuction) (*auctiontypes.MsgCreateAuctionResponse, error) {
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
defer refundGas(ms.k.logger, "CreateAuction")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
_, err := addrCodec.StringToBytes(msg.Signer)
|
||||
@ -37,34 +37,34 @@ func (ms msgServer) CreateAuction(c context.Context, msg *auctiontypes.MsgCreate
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
auctiontypes.EventTypeCreateAuction,
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyCommitsDuration, msg.CommitsDuration.String()),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyCommitFee, msg.CommitFee.String()),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyRevealFee, msg.RevealFee.String()),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyMinimumBid, msg.MinimumBid.String()),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeySigner, msg.Signer),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.logger, "CreateAuction")
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
auctiontypes.EventTypeCreateAuction,
|
||||
event.NewAttribute(auctiontypes.AttributeKeyCommitsDuration, msg.CommitsDuration.String()),
|
||||
event.NewAttribute(auctiontypes.AttributeKeyCommitFee, msg.CommitFee.String()),
|
||||
event.NewAttribute(auctiontypes.AttributeKeyRevealFee, msg.RevealFee.String()),
|
||||
event.NewAttribute(auctiontypes.AttributeKeyMinimumBid, msg.MinimumBid.String()),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", auctiontypes.EventTypeCreateAuction)
|
||||
}
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
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)
|
||||
}
|
||||
|
||||
return &auctiontypes.MsgCreateAuctionResponse{Auction: resp}, nil
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
defer refundGas(ms.k.logger, "CommitBid")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
_, err := addrCodec.StringToBytes(msg.Signer)
|
||||
@ -77,32 +77,32 @@ func (ms msgServer) CommitBid(c context.Context, msg *auctiontypes.MsgCommitBid)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
auctiontypes.EventTypeCommitBid,
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyAuctionId, msg.AuctionId),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyCommitHash, msg.CommitHash),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeySigner, msg.Signer),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.logger, "CommitBid")
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
auctiontypes.EventTypeCommitBid,
|
||||
event.NewAttribute(auctiontypes.AttributeKeyAuctionId, msg.AuctionId),
|
||||
event.NewAttribute(auctiontypes.AttributeKeyCommitHash, msg.CommitHash),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", auctiontypes.EventTypeCommitBid)
|
||||
}
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
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)
|
||||
}
|
||||
|
||||
return &auctiontypes.MsgCommitBidResponse{Bid: resp}, nil
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
defer refundGas(ms.k.logger, "RevealBid")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
_, err := addrCodec.StringToBytes(msg.Signer)
|
||||
@ -115,36 +115,34 @@ func (ms msgServer) RevealBid(c context.Context, msg *auctiontypes.MsgRevealBid)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
auctiontypes.EventTypeRevealBid,
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyAuctionId, msg.AuctionId),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyReveal, msg.Reveal),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeySigner, msg.Signer),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.logger, "RevealBid")
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
auctiontypes.EventTypeRevealBid,
|
||||
event.NewAttribute(auctiontypes.AttributeKeyAuctionId, msg.AuctionId),
|
||||
event.NewAttribute(auctiontypes.AttributeKeyReveal, msg.Reveal),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", auctiontypes.EventTypeRevealBid)
|
||||
}
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
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)
|
||||
}
|
||||
|
||||
return &auctiontypes.MsgRevealBidResponse{Auction: resp}, nil
|
||||
}
|
||||
|
||||
// UpdateParams defines a method to perform updation of module params.
|
||||
func (ms msgServer) UpdateParams(c context.Context, msg *auctiontypes.MsgUpdateParams) (*auctiontypes.MsgUpdateParamsResponse, error) {
|
||||
if ms.k.authority != msg.Authority {
|
||||
return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.k.authority, msg.Authority)
|
||||
func (ms msgServer) UpdateParams(ctx context.Context, msg *auctiontypes.MsgUpdateParams) (*auctiontypes.MsgUpdateParamsResponse, error) {
|
||||
if err := utils.CheckAuthorityAddress(ms.k.addressCodec, ms.k.authority, msg.Authority); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := msg.Params.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
if err := ms.k.SetParams(ctx, msg.Params); err != nil {
|
||||
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
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
defer refundGas(ms.k.logger, "ReleaseFunds")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
_, err := addrCodec.StringToBytes(msg.Signer)
|
||||
@ -172,19 +170,19 @@ func (ms msgServer) ReleaseFunds(c context.Context, msg *auctiontypes.MsgRelease
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
auctiontypes.EventTypeReleaseFunds,
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyAuctionId, msg.AuctionId),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeySigner, msg.Signer),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.logger, "ReleaseFunds")
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
auctiontypes.EventTypeReleaseFunds,
|
||||
event.NewAttribute(auctiontypes.AttributeKeyAuctionId, msg.AuctionId),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", auctiontypes.EventTypeReleaseFunds)
|
||||
}
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
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)
|
||||
}
|
||||
|
||||
return &auctiontypes.MsgReleaseFundsResponse{Auction: resp}, nil
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package module
|
||||
|
||||
import (
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/depinject/appconfig"
|
||||
@ -9,9 +10,9 @@ import (
|
||||
govtypes "cosmossdk.io/x/gov/types"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
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"
|
||||
"git.vdb.to/cerc-io/laconicd/utils"
|
||||
"git.vdb.to/cerc-io/laconicd/x/auction"
|
||||
"git.vdb.to/cerc-io/laconicd/x/auction/keeper"
|
||||
)
|
||||
@ -35,9 +36,10 @@ func init() {
|
||||
type ModuleInputs struct {
|
||||
depinject.In
|
||||
|
||||
Env appmodule.Environment
|
||||
Config *modulev1.Module
|
||||
Cdc codec.Codec
|
||||
Env appmodule.Environment
|
||||
Config *modulev1.Module
|
||||
Cdc codec.Codec
|
||||
AddressCodec address.Codec
|
||||
|
||||
AccountKeeper auth.AccountKeeper
|
||||
BankKeeper bank.Keeper
|
||||
@ -58,12 +60,9 @@ type ModuleOutputs struct {
|
||||
|
||||
func ProvideModule(in ModuleInputs) ModuleOutputs {
|
||||
// default to governance authority if not provided
|
||||
authority := authtypes.NewModuleAddress(govtypes.ModuleName)
|
||||
if in.Config.Authority != "" {
|
||||
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
|
||||
}
|
||||
authority := utils.AddressOrModuleAddress(in.Config.Authority, govtypes.ModuleName)
|
||||
|
||||
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)
|
||||
|
||||
return ModuleOutputs{Module: m, Keeper: k}
|
||||
|
@ -9,13 +9,14 @@ import (
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
"cosmossdk.io/collections/indexes"
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/core/store"
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"cosmossdk.io/log"
|
||||
|
||||
bank "cosmossdk.io/x/bank/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
auth "github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||
@ -45,10 +46,11 @@ func newBondIndexes(sb *collections.SchemaBuilder) BondsIndexes {
|
||||
|
||||
type Keeper struct {
|
||||
appmodule.Environment
|
||||
cdc codec.BinaryCodec
|
||||
logger log.Logger
|
||||
cdc codec.BinaryCodec
|
||||
addressCodec address.Codec
|
||||
logger log.Logger
|
||||
|
||||
authority string
|
||||
authority types.AccAddress
|
||||
|
||||
// External keepers
|
||||
accountKeeper auth.AccountKeeper
|
||||
@ -67,18 +69,13 @@ type Keeper struct {
|
||||
func NewKeeper(
|
||||
env appmodule.Environment,
|
||||
cdc codec.BinaryCodec,
|
||||
storeService store.KVStoreService,
|
||||
addressCodec address.Codec,
|
||||
accountKeeper auth.AccountKeeper,
|
||||
bankKeeper bank.Keeper,
|
||||
authority string,
|
||||
authority types.AccAddress,
|
||||
logger log.Logger,
|
||||
) *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(storeService)
|
||||
sb := collections.NewSchemaBuilder(env.KVStoreService)
|
||||
k := Keeper{
|
||||
Environment: env,
|
||||
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)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
@ -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}
|
||||
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.
|
||||
@ -245,7 +242,7 @@ func (k Keeper) RefillBond(ctx context.Context, id string, ownerAddress sdk.AccA
|
||||
if err != nil {
|
||||
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)
|
||||
@ -254,13 +251,13 @@ func (k Keeper) RefillBond(ctx context.Context, id string, ownerAddress sdk.AccA
|
||||
}
|
||||
|
||||
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.
|
||||
for _, coin := range coins {
|
||||
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...)
|
||||
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.
|
||||
@ -295,7 +292,7 @@ func (k Keeper) WithdrawBond(ctx context.Context, id string, ownerAddress sdk.Ac
|
||||
if err != nil {
|
||||
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)
|
||||
@ -304,12 +301,12 @@ func (k Keeper) WithdrawBond(ctx context.Context, id string, ownerAddress sdk.Ac
|
||||
}
|
||||
|
||||
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...)
|
||||
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.
|
||||
@ -333,7 +330,7 @@ func (k Keeper) CancelBond(ctx context.Context, id string, ownerAddress sdk.AccA
|
||||
if err != nil {
|
||||
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)
|
||||
@ -342,13 +339,13 @@ func (k Keeper) CancelBond(ctx context.Context, id string, ownerAddress sdk.AccA
|
||||
}
|
||||
|
||||
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.
|
||||
for _, usageKeeper := range k.usageKeepers {
|
||||
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
|
||||
}
|
||||
|
||||
// GetAuthority returns the x/bond module's authority.
|
||||
func (k Keeper) GetAuthority() string {
|
||||
return k.authority
|
||||
}
|
||||
|
||||
// GetParams gets the bond module's parameters.
|
||||
func (k Keeper) GetParams(ctx context.Context) (*bondtypes.Params, error) {
|
||||
params, err := k.Params.Get(ctx)
|
||||
@ -403,7 +395,7 @@ func (k Keeper) TransferRentToModuleAccount(ctx context.Context, id, moduleAccou
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found")
|
||||
}
|
||||
|
||||
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...)
|
||||
if isNeg {
|
||||
// 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.
|
||||
err = k.bankKeeper.SendCoinsFromModuleToModule(ctx, bondtypes.ModuleName, moduleAccount, rent)
|
||||
if err != nil {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Error transferring funds.")
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Error transferring funds")
|
||||
}
|
||||
|
||||
// Update bond balance.
|
||||
|
@ -3,8 +3,8 @@ package keeper
|
||||
import (
|
||||
"context"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
govtypes "cosmossdk.io/x/gov/types"
|
||||
"cosmossdk.io/core/event"
|
||||
"cosmossdk.io/errors"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"git.vdb.to/cerc-io/laconicd/utils"
|
||||
@ -15,57 +15,58 @@ type msgHandlers struct {
|
||||
k *Keeper
|
||||
}
|
||||
|
||||
// NewHandlers returns an implementation of the module MsgServer interface.
|
||||
func NewHandlers(keeper *Keeper) msgHandlers {
|
||||
// NewMsgServerImpl returns an implementation of the module MsgServer interface.
|
||||
func NewMsgServerImpl(keeper *Keeper) msgHandlers {
|
||||
return msgHandlers{k: keeper}
|
||||
}
|
||||
|
||||
func (ms msgHandlers) CreateBond(c context.Context, msg *bond.MsgCreateBond) (*bond.MsgCreateBondResponse, error) {
|
||||
panic("handlers.CreateBond is definitely called")
|
||||
func (ms msgHandlers) CreateBond(ctx context.Context, msg *bond.MsgCreateBond) (*bond.MsgCreateBondResponse, error) {
|
||||
ms.k.logger.Debug("handlers.CreateBond", "msg", msg)
|
||||
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
defer refundGas(ms.k.logger, "CreateBond")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
signerAddress, err := addrCodec.StringToBytes(msg.Signer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := ms.k.CreateBond(ctx, signerAddress, msg.Coins)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
bond.EventTypeCreateBond,
|
||||
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer),
|
||||
sdk.NewAttribute(sdk.AttributeKeyAmount, msg.Coins.String()),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory),
|
||||
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "CreateBond")
|
||||
eventManager := ms.k.EventService.EventManager(ctx)
|
||||
if err := eventManager.EmitKV(
|
||||
bond.EventTypeCreateBond,
|
||||
event.NewAttribute(bond.AttributeKeySigner, msg.Signer),
|
||||
event.NewAttribute(sdk.AttributeKeyAmount, msg.Coins.String()),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", bond.EventTypeCreateBond)
|
||||
}
|
||||
if err := eventManager.EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
event.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory),
|
||||
event.NewAttribute(bond.AttributeKeySigner, msg.Signer),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
|
||||
}
|
||||
|
||||
return &bond.MsgCreateBondResponse{Id: resp.Id}, nil
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
defer refundGas(ms.k.logger, "RefillBond")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
signerAddress, err := addrCodec.StringToBytes(msg.Signer)
|
||||
@ -78,33 +79,34 @@ func (ms msgHandlers) RefillBond(c context.Context, msg *bond.MsgRefillBond) (*b
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
bond.EventTypeRefillBond,
|
||||
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer),
|
||||
sdk.NewAttribute(bond.AttributeKeyBondId, msg.Id),
|
||||
sdk.NewAttribute(sdk.AttributeKeyAmount, msg.Coins.String()),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory),
|
||||
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "RefillBond")
|
||||
eventManager := ms.k.EventService.EventManager(ctx)
|
||||
if err := eventManager.EmitKV(
|
||||
bond.EventTypeRefillBond,
|
||||
event.NewAttribute(bond.AttributeKeySigner, msg.Signer),
|
||||
event.NewAttribute(bond.AttributeKeyBondId, msg.Id),
|
||||
event.NewAttribute(sdk.AttributeKeyAmount, msg.Coins.String()),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", bond.EventTypeRefillBond)
|
||||
}
|
||||
if err := eventManager.EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
event.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory),
|
||||
event.NewAttribute(bond.AttributeKeySigner, msg.Signer),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
|
||||
}
|
||||
|
||||
return &bond.MsgRefillBondResponse{}, nil
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
defer refundGas(ms.k.logger, "WithdrawBond")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
signerAddress, err := addrCodec.StringToBytes(msg.Signer)
|
||||
@ -117,33 +119,34 @@ func (ms msgHandlers) WithdrawBond(c context.Context, msg *bond.MsgWithdrawBond)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
bond.EventTypeWithdrawBond,
|
||||
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer),
|
||||
sdk.NewAttribute(bond.AttributeKeyBondId, msg.Id),
|
||||
sdk.NewAttribute(sdk.AttributeKeyAmount, msg.Coins.String()),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory),
|
||||
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "WithdrawBond")
|
||||
eventManager := ms.k.EventService.EventManager(ctx)
|
||||
if err := eventManager.EmitKV(
|
||||
bond.EventTypeWithdrawBond,
|
||||
event.NewAttribute(bond.AttributeKeySigner, msg.Signer),
|
||||
event.NewAttribute(bond.AttributeKeyBondId, msg.Id),
|
||||
event.NewAttribute(sdk.AttributeKeyAmount, msg.Coins.String()),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", bond.EventTypeWithdrawBond)
|
||||
}
|
||||
if err := eventManager.EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
event.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory),
|
||||
event.NewAttribute(bond.AttributeKeySigner, msg.Signer),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
|
||||
}
|
||||
|
||||
return &bond.MsgWithdrawBondResponse{}, nil
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
defer refundGas(ms.k.logger, "CancelBond")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
signerAddress, err := addrCodec.StringToBytes(msg.Signer)
|
||||
@ -156,36 +159,35 @@ func (ms msgHandlers) CancelBond(c context.Context, msg *bond.MsgCancelBond) (*b
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
bond.EventTypeCancelBond,
|
||||
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer),
|
||||
sdk.NewAttribute(bond.AttributeKeyBondId, msg.Id),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory),
|
||||
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.Logger(ctx), "CancelBond")
|
||||
eventManager := ms.k.EventService.EventManager(ctx)
|
||||
if err := eventManager.EmitKV(
|
||||
bond.EventTypeCancelBond,
|
||||
event.NewAttribute(bond.AttributeKeySigner, msg.Signer),
|
||||
event.NewAttribute(bond.AttributeKeyBondId, msg.Id),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", bond.EventTypeCancelBond)
|
||||
}
|
||||
if err := eventManager.EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
event.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory),
|
||||
event.NewAttribute(bond.AttributeKeySigner, msg.Signer),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", sdk.EventTypeMessage)
|
||||
}
|
||||
|
||||
return &bond.MsgCancelBondResponse{}, nil
|
||||
}
|
||||
|
||||
// UpdateParams defines a method to perform updation of module params.
|
||||
func (ms msgHandlers) UpdateParams(c context.Context, msg *bond.MsgUpdateParams) (*bond.MsgUpdateParamsResponse, error) {
|
||||
if ms.k.authority != msg.Authority {
|
||||
return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.k.authority, msg.Authority)
|
||||
func (ms msgHandlers) UpdateParams(ctx context.Context, msg *bond.MsgUpdateParams) (*bond.MsgUpdateParamsResponse, error) {
|
||||
if err := utils.CheckAuthorityAddress(ms.k.addressCodec, ms.k.authority, msg.Authority); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := msg.Params.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
if err := ms.k.SetParams(ctx, msg.Params); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ type queryHandlers struct {
|
||||
k *Keeper
|
||||
}
|
||||
|
||||
// NewQueryHandlers returns an implementation of the module QueryServer.
|
||||
func NewQueryHandlers(k *Keeper) bondtypes.QueryServer {
|
||||
// NewQueryServerImpl returns an implementation of the module QueryServer.
|
||||
func NewQueryServerImpl(k *Keeper) bondtypes.QueryServer {
|
||||
return queryHandlers{k}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package module
|
||||
|
||||
import (
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/core/store"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/depinject/appconfig"
|
||||
"cosmossdk.io/log"
|
||||
@ -10,9 +10,9 @@ import (
|
||||
govtypes "cosmossdk.io/x/gov/types"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
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"
|
||||
"git.vdb.to/cerc-io/laconicd/utils"
|
||||
"git.vdb.to/cerc-io/laconicd/x/bond"
|
||||
"git.vdb.to/cerc-io/laconicd/x/bond/keeper"
|
||||
)
|
||||
@ -39,7 +39,7 @@ type ModuleInputs struct {
|
||||
Env appmodule.Environment
|
||||
Config *modulev1.Module
|
||||
Cdc codec.Codec
|
||||
StoreService store.KVStoreService
|
||||
AddressCodec address.Codec
|
||||
|
||||
AccountKeeper auth.AccountKeeper
|
||||
BankKeeper bank.Keeper
|
||||
@ -56,12 +56,8 @@ type ModuleOutputs struct {
|
||||
|
||||
func ProvideModule(in ModuleInputs) ModuleOutputs {
|
||||
// default to governance authority if not provided
|
||||
authority := authtypes.NewModuleAddress(govtypes.ModuleName)
|
||||
if in.Config.Authority != "" {
|
||||
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
|
||||
}
|
||||
|
||||
k := keeper.NewKeeper(in.Env, in.Cdc, in.StoreService, in.AccountKeeper, in.BankKeeper, authority.String(), in.Logger)
|
||||
authority := utils.AddressOrModuleAddress(in.Config.Authority, govtypes.ModuleName)
|
||||
k := keeper.NewKeeper(in.Env, in.Cdc, in.AddressCodec, in.AccountKeeper, in.BankKeeper, authority, in.Logger)
|
||||
m := NewAppModule(in.Cdc, k)
|
||||
|
||||
return ModuleOutputs{Module: m, Keeper: k}
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
// "google.golang.org/grpc"
|
||||
|
||||
appmodule "cosmossdk.io/core/appmodule/v2"
|
||||
@ -17,17 +17,16 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
var (
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasGenesis = AppModule{}
|
||||
_ appmodule.HasConsensusVersion = AppModule{}
|
||||
_ appmodule.HasGenesis = AppModule{}
|
||||
_ appmodule.HasMsgHandlers = AppModule{}
|
||||
_ appmodule.HasQueryHandlers = AppModule{}
|
||||
_ appmodule.HasRegisterInterfaces = AppModule{}
|
||||
// _ appmodule.HasMsgHandlers = AppModule{}
|
||||
_ appmodule.HasQueryHandlers = AppModule{}
|
||||
|
||||
_ module.HasGRPCGateway = AppModule{}
|
||||
// _ module.HasServices = AppModule{}
|
||||
@ -117,14 +116,6 @@ func (am AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error)
|
||||
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
|
||||
|
||||
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.
|
||||
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.RefillBond)
|
||||
@ -144,7 +135,7 @@ func (am AppModule) RegisterMsgHandlers(router appmodule.MsgRouter) {
|
||||
|
||||
// RegisterQueryHandlers registers the query handlers for the bond module.
|
||||
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.Bonds)
|
||||
@ -152,15 +143,3 @@ func (am AppModule) RegisterQueryHandlers(router appmodule.QueryRouter) {
|
||||
appmodule.RegisterMsgHandler(router, handlers.GetBondsByOwner)
|
||||
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()
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ func (msg MsgCreateBond) ValidateBasic() error {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
|
||||
}
|
||||
if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
|
||||
return sdkerrors.ErrInvalidCoins
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -34,7 +34,7 @@ func (msg MsgRefillBond) ValidateBasic() error {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
|
||||
}
|
||||
if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
|
||||
return sdkerrors.ErrInvalidCoins
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -47,7 +47,7 @@ func (msg MsgWithdrawBond) ValidateBasic() error {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
|
||||
}
|
||||
if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
|
||||
return sdkerrors.ErrInvalidCoins
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
"cosmossdk.io/core/address"
|
||||
@ -14,6 +13,7 @@ import (
|
||||
"cosmossdk.io/log"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
||||
@ -23,13 +23,12 @@ import (
|
||||
|
||||
type Keeper struct {
|
||||
appmodule.Environment
|
||||
cdc codec.BinaryCodec
|
||||
addressCodec address.Codec
|
||||
logger log.Logger
|
||||
|
||||
// authority is the address capable of executing a MsgUpdateParams and other authority-gated message.
|
||||
// typically, this should be the x/gov module account.
|
||||
authority string
|
||||
authority types.AccAddress
|
||||
|
||||
// state management
|
||||
Schema collections.Schema
|
||||
@ -39,19 +38,16 @@ type Keeper struct {
|
||||
|
||||
// NewKeeper creates a new Keeper instance
|
||||
func NewKeeper(
|
||||
env appmodule.Environment,
|
||||
cdc codec.BinaryCodec,
|
||||
addressCodec address.Codec,
|
||||
storeService storetypes.KVStoreService,
|
||||
authority string,
|
||||
authority types.AccAddress,
|
||||
logger log.Logger,
|
||||
) *Keeper {
|
||||
if _, err := addressCodec.StringToBytes(authority); err != nil {
|
||||
panic(fmt.Errorf("invalid authority address: %w", err))
|
||||
}
|
||||
|
||||
sb := collections.NewSchemaBuilder(storeService)
|
||||
k := Keeper{
|
||||
cdc: cdc,
|
||||
Environment: env,
|
||||
addressCodec: addressCodec,
|
||||
logger: logger.With(log.ModuleKey, "x/"+onboardingTypes.ModuleName),
|
||||
authority: authority,
|
||||
@ -71,11 +67,6 @@ func NewKeeper(
|
||||
return &k
|
||||
}
|
||||
|
||||
// GetAuthority returns the module's authority.
|
||||
func (k Keeper) GetAuthority() string {
|
||||
return k.authority
|
||||
}
|
||||
|
||||
func (k Keeper) OnboardParticipant(
|
||||
ctx context.Context,
|
||||
msg *onboardingTypes.MsgOnboardParticipant,
|
||||
|
@ -3,6 +3,8 @@ package keeper
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cosmossdk.io/core/event"
|
||||
"cosmossdk.io/errors"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"git.vdb.to/cerc-io/laconicd/utils"
|
||||
@ -20,13 +22,13 @@ func NewMsgServerImpl(keeper *Keeper) onboarding.MsgServer {
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
defer refundGas(ms.k.logger, "OnboardParticipant")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
signerAddress, err := addrCodec.StringToBytes(msg.Participant)
|
||||
@ -39,20 +41,20 @@ func (ms msgServer) OnboardParticipant(c context.Context, msg *onboarding.MsgOnb
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
onboarding.EventTypeOnboardParticipant,
|
||||
sdk.NewAttribute(onboarding.AttributeKeySigner, msg.Participant),
|
||||
sdk.NewAttribute(onboarding.AttributeKeyEthAddress, msg.EthPayload.Address),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, onboarding.AttributeValueCategory),
|
||||
sdk.NewAttribute(onboarding.AttributeKeySigner, msg.Participant),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.logger, "OnboardParticipant")
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
onboarding.EventTypeOnboardParticipant,
|
||||
event.NewAttribute(onboarding.AttributeKeySigner, msg.Participant),
|
||||
event.NewAttribute(onboarding.AttributeKeyEthAddress, msg.EthPayload.Address),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", onboarding.EventTypeOnboardParticipant)
|
||||
}
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
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)
|
||||
}
|
||||
|
||||
return &onboarding.MsgOnboardParticipantResponse{}, nil
|
||||
}
|
||||
|
@ -7,10 +7,11 @@ import (
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/depinject/appconfig"
|
||||
"cosmossdk.io/log"
|
||||
govtypes "cosmossdk.io/x/gov/types"
|
||||
"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"
|
||||
"git.vdb.to/cerc-io/laconicd/utils"
|
||||
"git.vdb.to/cerc-io/laconicd/x/onboarding/keeper"
|
||||
)
|
||||
|
||||
@ -32,6 +33,7 @@ func init() {
|
||||
type ModuleInputs struct {
|
||||
depinject.In
|
||||
|
||||
Env appmodule.Environment
|
||||
Cdc codec.Codec
|
||||
StoreService store.KVStoreService
|
||||
AddressCodec address.Codec
|
||||
@ -49,12 +51,8 @@ type ModuleOutputs struct {
|
||||
|
||||
func ProvideModule(in ModuleInputs) ModuleOutputs {
|
||||
// default to governance as authority if not provided
|
||||
authority := authtypes.NewModuleAddress("gov")
|
||||
if in.Config.Authority != "" {
|
||||
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
|
||||
}
|
||||
|
||||
k := keeper.NewKeeper(in.Cdc, in.AddressCodec, in.StoreService, authority.String(), in.Logger)
|
||||
authority := utils.AddressOrModuleAddress(in.Config.Authority, govtypes.ModuleName)
|
||||
k := keeper.NewKeeper(in.Env, in.Cdc, in.AddressCodec, in.StoreService, authority, in.Logger)
|
||||
m := NewAppModule(in.Cdc, k)
|
||||
|
||||
return ModuleOutputs{Module: m, Keeper: k}
|
||||
|
@ -10,12 +10,14 @@ import (
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
"cosmossdk.io/collections/indexes"
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"cosmossdk.io/log"
|
||||
bank "cosmossdk.io/x/bank/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/codec/legacy"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/types/query"
|
||||
@ -95,10 +97,11 @@ func newNameRecordIndexes(sb *collections.SchemaBuilder) NameRecordsIndexes {
|
||||
|
||||
type Keeper struct {
|
||||
appmodule.Environment
|
||||
cdc codec.BinaryCodec
|
||||
logger log.Logger
|
||||
cdc codec.BinaryCodec
|
||||
addressCodec address.Codec
|
||||
logger log.Logger
|
||||
|
||||
authority string
|
||||
authority types.AccAddress
|
||||
|
||||
accountKeeper auth.AccountKeeper
|
||||
bankKeeper bank.Keeper
|
||||
@ -120,18 +123,14 @@ type Keeper struct {
|
||||
func NewKeeper(
|
||||
env appmodule.Environment,
|
||||
cdc codec.BinaryCodec,
|
||||
addressCodec address.Codec,
|
||||
accountKeeper auth.AccountKeeper,
|
||||
bankKeeper bank.Keeper,
|
||||
bondKeeper *bondkeeper.Keeper,
|
||||
auctionKeeper *auctionkeeper.Keeper,
|
||||
authority string,
|
||||
authority types.AccAddress,
|
||||
logger log.Logger,
|
||||
) 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)
|
||||
k := Keeper{
|
||||
Environment: env,
|
||||
@ -182,11 +181,6 @@ func NewKeeper(
|
||||
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.
|
||||
func (k Keeper) SetParams(ctx context.Context, params registrytypes.Params) error {
|
||||
return k.Params.Set(ctx, params)
|
||||
|
@ -3,8 +3,8 @@ package keeper
|
||||
import (
|
||||
"context"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
govtypes "cosmossdk.io/x/gov/types"
|
||||
"cosmossdk.io/core/event"
|
||||
"cosmossdk.io/errors"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"git.vdb.to/cerc-io/laconicd/utils"
|
||||
@ -22,13 +22,13 @@ func NewMsgServerImpl(keeper Keeper) registrytypes.MsgServer {
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
refundGas(ms.k.logger, "SetRecord")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
_, err := addrCodec.StringToBytes(msg.Signer)
|
||||
@ -41,33 +41,33 @@ func (ms msgServer) SetRecord(c context.Context, msg *registrytypes.MsgSetRecord
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
registrytypes.EventTypeSetRecord,
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.GetSigner()),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeyBondId, msg.GetBondId()),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeyPayload, msg.Payload.Record.Id),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.logger, "SetRecord")
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
registrytypes.EventTypeSetRecord,
|
||||
event.NewAttribute(registrytypes.AttributeKeySigner, msg.GetSigner()),
|
||||
event.NewAttribute(registrytypes.AttributeKeyBondId, msg.GetBondId()),
|
||||
event.NewAttribute(registrytypes.AttributeKeyPayload, msg.Payload.Record.Id),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeSetRecord)
|
||||
}
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
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)
|
||||
}
|
||||
|
||||
return ®istrytypes.MsgSetRecordResponse{Id: record.Id}, nil
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
defer refundGas(ms.k.logger, "SetName")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
_, err := addrCodec.StringToBytes(msg.Signer)
|
||||
@ -80,32 +80,32 @@ func (ms msgServer) SetName(c context.Context, msg *registrytypes.MsgSetName) (*
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
registrytypes.EventTypeSetRecord,
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeyLRN, msg.Lrn),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeyCID, msg.Cid),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.logger, "SetName")
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
registrytypes.EventTypeSetRecord,
|
||||
event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
event.NewAttribute(registrytypes.AttributeKeyLRN, msg.Lrn),
|
||||
event.NewAttribute(registrytypes.AttributeKeyCID, msg.Cid),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeSetRecord)
|
||||
}
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
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)
|
||||
}
|
||||
|
||||
return ®istrytypes.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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
defer refundGas(ms.k.logger, "ReserveAuthority")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
_, err := addrCodec.StringToBytes(msg.Signer)
|
||||
@ -122,33 +122,33 @@ func (ms msgServer) ReserveAuthority(c context.Context, msg *registrytypes.MsgRe
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
registrytypes.EventTypeReserveAuthority,
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeyName, msg.Name),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeyOwner, msg.Owner),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.logger, "ReserveAuthority")
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
registrytypes.EventTypeReserveAuthority,
|
||||
event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
event.NewAttribute(registrytypes.AttributeKeyName, msg.Name),
|
||||
event.NewAttribute(registrytypes.AttributeKeyOwner, msg.Owner),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeReserveAuthority)
|
||||
}
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
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)
|
||||
}
|
||||
|
||||
return ®istrytypes.MsgReserveAuthorityResponse{}, nil
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
defer refundGas(ms.k.logger, "SetAuthorityBond")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
_, err := addrCodec.StringToBytes(msg.Signer)
|
||||
@ -161,32 +161,32 @@ func (ms msgServer) SetAuthorityBond(c context.Context, msg *registrytypes.MsgSe
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
registrytypes.EventTypeAuthorityBond,
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeyName, msg.Name),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeyBondId, msg.BondId),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.logger, "SetAuthorityBond")
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
registrytypes.EventTypeAuthorityBond,
|
||||
event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
event.NewAttribute(registrytypes.AttributeKeyName, msg.Name),
|
||||
event.NewAttribute(registrytypes.AttributeKeyBondId, msg.BondId),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeAuthorityBond)
|
||||
}
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
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)
|
||||
}
|
||||
|
||||
return ®istrytypes.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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
defer refundGas(ms.k.logger, "DeleteName")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
_, err := addrCodec.StringToBytes(msg.Signer)
|
||||
@ -199,31 +199,31 @@ func (ms msgServer) DeleteName(c context.Context, msg *registrytypes.MsgDeleteNa
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
registrytypes.EventTypeDeleteName,
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeyLRN, msg.Lrn),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.logger, "DeleteName")
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
registrytypes.EventTypeDeleteName,
|
||||
event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
event.NewAttribute(registrytypes.AttributeKeyLRN, msg.Lrn),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeDeleteName)
|
||||
}
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
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)
|
||||
}
|
||||
|
||||
return ®istrytypes.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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
defer refundGas(ms.k.logger, "RenewRecord")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
_, err := addrCodec.StringToBytes(msg.Signer)
|
||||
@ -231,37 +231,37 @@ func (ms msgServer) RenewRecord(c context.Context, msg *registrytypes.MsgRenewRe
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
registrytypes.EventTypeRenewRecord,
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeyRecordId, msg.RecordId),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.logger, "RenewRecord")
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
registrytypes.EventTypeRenewRecord,
|
||||
event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
event.NewAttribute(registrytypes.AttributeKeyRecordId, msg.RecordId),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeRenewRecord)
|
||||
}
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
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)
|
||||
}
|
||||
|
||||
return ®istrytypes.MsgRenewRecordResponse{}, nil
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
defer refundGas(ms.k.logger, "AssociateBond")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
_, err := addrCodec.StringToBytes(msg.Signer)
|
||||
@ -274,32 +274,32 @@ func (ms msgServer) AssociateBond(c context.Context, msg *registrytypes.MsgAssoc
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
registrytypes.EventTypeAssociateBond,
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeyRecordId, msg.RecordId),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeyBondId, msg.BondId),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.logger, "AssociateBond")
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
registrytypes.EventTypeAssociateBond,
|
||||
event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
event.NewAttribute(registrytypes.AttributeKeyRecordId, msg.RecordId),
|
||||
event.NewAttribute(registrytypes.AttributeKeyBondId, msg.BondId),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeAssociateBond)
|
||||
}
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
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)
|
||||
}
|
||||
|
||||
return ®istrytypes.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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
defer refundGas(ms.k.logger, "DissociateBond")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
_, err := addrCodec.StringToBytes(msg.Signer)
|
||||
@ -312,34 +312,34 @@ func (ms msgServer) DissociateBond(c context.Context, msg *registrytypes.MsgDiss
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
registrytypes.EventTypeDissociateBond,
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeyRecordId, msg.RecordId),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.logger, "DissociateBond")
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
registrytypes.EventTypeDissociateBond,
|
||||
event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
event.NewAttribute(registrytypes.AttributeKeyRecordId, msg.RecordId),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeDissociateBond)
|
||||
}
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
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)
|
||||
}
|
||||
|
||||
return ®istrytypes.MsgDissociateBondResponse{}, nil
|
||||
}
|
||||
|
||||
func (ms msgServer) DissociateRecords(
|
||||
c context.Context,
|
||||
ctx context.Context,
|
||||
msg *registrytypes.MsgDissociateRecords,
|
||||
) (*registrytypes.MsgDissociateRecordsResponse, error) {
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
defer refundGas(ms.k.logger, "DissociateRecords")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
_, err := addrCodec.StringToBytes(msg.Signer)
|
||||
@ -352,31 +352,31 @@ func (ms msgServer) DissociateRecords(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
registrytypes.EventTypeDissociateRecords,
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeyBondId, msg.BondId),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.logger, "DissociateRecords")
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
registrytypes.EventTypeDissociateRecords,
|
||||
event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
event.NewAttribute(registrytypes.AttributeKeyBondId, msg.BondId),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeDissociateRecords)
|
||||
}
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
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)
|
||||
}
|
||||
|
||||
return ®istrytypes.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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
ctx = *utils.CtxWithCustomKVGasConfig(&ctx)
|
||||
refundGas := utils.TrackGasConsumption(ms.k.GasService.GasMeter(ctx))
|
||||
defer refundGas(ms.k.logger, "ReassociateRecords")
|
||||
|
||||
addrCodec := utils.NewAddressCodec()
|
||||
_, err := addrCodec.StringToBytes(msg.Signer)
|
||||
@ -389,37 +389,35 @@ func (ms msgServer) ReassociateRecords(c context.Context, msg *registrytypes.Msg
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
registrytypes.EventTypeReassociateRecords,
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeyOldBondId, msg.OldBondId),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeyNewBondId, msg.NewBondId),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, registrytypes.AttributeValueCategory),
|
||||
sdk.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
),
|
||||
})
|
||||
|
||||
utils.LogTxGasConsumed(ctx, ms.k.logger, "ReassociateRecords")
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
registrytypes.EventTypeReassociateRecords,
|
||||
event.NewAttribute(registrytypes.AttributeKeySigner, msg.Signer),
|
||||
event.NewAttribute(registrytypes.AttributeKeyOldBondId, msg.OldBondId),
|
||||
event.NewAttribute(registrytypes.AttributeKeyNewBondId, msg.NewBondId),
|
||||
); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to emit event: %s", registrytypes.EventTypeReassociateRecords)
|
||||
}
|
||||
if err := ms.k.EventService.EventManager(ctx).EmitKV(
|
||||
sdk.EventTypeMessage,
|
||||
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)
|
||||
}
|
||||
|
||||
return ®istrytypes.MsgReassociateRecordsResponse{}, nil
|
||||
}
|
||||
|
||||
// UpdateParams defines a method to perform updation of module params.
|
||||
func (ms msgServer) UpdateParams(c context.Context, msg *registrytypes.MsgUpdateParams) (*registrytypes.MsgUpdateParamsResponse, error) {
|
||||
if ms.k.authority != msg.Authority {
|
||||
return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.k.authority, msg.Authority)
|
||||
func (ms msgServer) UpdateParams(ctx context.Context, msg *registrytypes.MsgUpdateParams) (*registrytypes.MsgUpdateParamsResponse, error) {
|
||||
if err := utils.CheckAuthorityAddress(ms.k.addressCodec, ms.k.authority, msg.Authority); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := msg.Params.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
if err := ms.k.SetParams(ctx, msg.Params); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package module
|
||||
|
||||
import (
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/depinject/appconfig"
|
||||
@ -9,9 +10,9 @@ import (
|
||||
govtypes "cosmossdk.io/x/gov/types"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
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"
|
||||
"git.vdb.to/cerc-io/laconicd/utils"
|
||||
"git.vdb.to/cerc-io/laconicd/x/auction"
|
||||
auctionkeeper "git.vdb.to/cerc-io/laconicd/x/auction/keeper"
|
||||
"git.vdb.to/cerc-io/laconicd/x/bond"
|
||||
@ -37,10 +38,11 @@ func init() {
|
||||
type ModuleInputs struct {
|
||||
depinject.In
|
||||
|
||||
Env appmodule.Environment
|
||||
Config *modulev1.Module
|
||||
Cdc codec.Codec
|
||||
Logger log.Logger
|
||||
Env appmodule.Environment
|
||||
Config *modulev1.Module
|
||||
Cdc codec.Codec
|
||||
AddressCodec address.Codec
|
||||
Logger log.Logger
|
||||
|
||||
AccountKeeper auth.AccountKeeper
|
||||
BankKeeper bank.Keeper
|
||||
@ -61,18 +63,16 @@ type ModuleOutputs struct {
|
||||
|
||||
func ProvideModule(in ModuleInputs) ModuleOutputs {
|
||||
// default to governance authority if not provided
|
||||
authority := authtypes.NewModuleAddress(govtypes.ModuleName)
|
||||
if in.Config.Authority != "" {
|
||||
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
|
||||
}
|
||||
authority := utils.AddressOrModuleAddress(in.Config.Authority, govtypes.ModuleName)
|
||||
k := keeper.NewKeeper(
|
||||
in.Env,
|
||||
in.Cdc,
|
||||
in.AddressCodec,
|
||||
in.AccountKeeper,
|
||||
in.BankKeeper,
|
||||
in.BondKeeper,
|
||||
in.AuctionKeeper,
|
||||
authority.String(),
|
||||
authority,
|
||||
in.Logger,
|
||||
)
|
||||
m := NewAppModule(in.Cdc, k)
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/client/v2/autocli"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
appmodule "cosmossdk.io/core/appmodule/v2"
|
||||
"cosmossdk.io/core/registry"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
@ -22,14 +22,16 @@ import (
|
||||
|
||||
var (
|
||||
_ appmodule.AppModule = AppModule{}
|
||||
_ appmodule.HasConsensusVersion = AppModule{}
|
||||
_ appmodule.HasEndBlocker = AppModule{}
|
||||
_ appmodule.HasGenesis = AppModule{}
|
||||
_ appmodule.HasConsensusVersion = AppModule{}
|
||||
_ appmodule.HasMsgHandlers = AppModule{}
|
||||
_ appmodule.HasQueryHandlers = AppModule{}
|
||||
_ appmodule.HasRegisterInterfaces = AppModule{}
|
||||
|
||||
_ module.HasGRPCGateway = AppModule{}
|
||||
_ module.HasServices = AppModule{}
|
||||
_ module.HasInvariants = AppModule{}
|
||||
// _ module.HasServices = AppModule{}
|
||||
_ module.HasInvariants = AppModule{}
|
||||
// _ module.HasAminoCodec = AppModule{} // TODO
|
||||
|
||||
_ autocli.HasCustomTxCommand = AppModule{}
|
||||
@ -115,13 +117,39 @@ func (am AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error)
|
||||
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) RegisterServices(cfg module.Configurator) {
|
||||
// Register servers
|
||||
registrytypes.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
||||
registrytypes.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper))
|
||||
func (am AppModule) RegisterMsgHandlers(router appmodule.MsgRouter) {
|
||||
handlers := keeper.NewMsgServerImpl(am.keeper)
|
||||
|
||||
appmodule.RegisterMsgHandler(router, handlers.AssociateBond)
|
||||
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
|
||||
|
@ -19,18 +19,18 @@ func NewMsgSetRecord(payload Payload, bondId string, signer sdk.AccAddress) *Msg
|
||||
|
||||
func (msg MsgSetRecord) ValidateBasic() error {
|
||||
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
|
||||
for _, owner := range owners {
|
||||
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 {
|
||||
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond Id is required.")
|
||||
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "bond ID is required")
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -38,11 +38,11 @@ func (msg MsgSetRecord) ValidateBasic() error {
|
||||
|
||||
func (msg MsgRenewRecord) ValidateBasic() error {
|
||||
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 {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -60,7 +60,7 @@ func NewMsgReserveAuthority(name string, signer sdk.AccAddress, owner sdk.AccAdd
|
||||
// ValidateBasic Implements Msg.
|
||||
func (msg MsgReserveAuthority) ValidateBasic() error {
|
||||
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 {
|
||||
@ -81,15 +81,15 @@ func NewMsgSetAuthorityBond(name string, bondID string, signer sdk.AccAddress) M
|
||||
|
||||
func (msg MsgSetAuthorityBond) ValidateBasic() error {
|
||||
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 {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
|
||||
}
|
||||
|
||||
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
|
||||
@ -107,11 +107,11 @@ func NewMsgSetName(lrn string, cid string, signer sdk.AccAddress) *MsgSetName {
|
||||
// ValidateBasic Implements Msg.
|
||||
func (msg MsgSetName) ValidateBasic() error {
|
||||
if msg.Lrn == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "LRN is required.")
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "LRN is required")
|
||||
}
|
||||
|
||||
if msg.Cid == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "CID is required.")
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "CID is required")
|
||||
}
|
||||
|
||||
if len(msg.Signer) == 0 {
|
||||
@ -123,16 +123,16 @@ func (msg MsgSetName) ValidateBasic() error {
|
||||
|
||||
func (msg MsgDeleteName) ValidateBasic() error {
|
||||
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 {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
|
||||
}
|
||||
|
||||
_, err := url.Parse(msg.Lrn)
|
||||
if err != nil {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid lrn.")
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid lrn")
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -140,13 +140,13 @@ func (msg MsgDeleteName) ValidateBasic() error {
|
||||
|
||||
func (msg MsgAssociateBond) ValidateBasic() error {
|
||||
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 {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "bond id is required.")
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "bond id is required")
|
||||
}
|
||||
if len(msg.Signer) == 0 {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -154,10 +154,10 @@ func (msg MsgAssociateBond) ValidateBasic() error {
|
||||
|
||||
func (msg MsgDissociateBond) ValidateBasic() error {
|
||||
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 {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -165,10 +165,10 @@ func (msg MsgDissociateBond) ValidateBasic() error {
|
||||
|
||||
func (msg MsgDissociateRecords) ValidateBasic() error {
|
||||
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 {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -176,13 +176,13 @@ func (msg MsgDissociateRecords) ValidateBasic() error {
|
||||
|
||||
func (msg MsgReassociateRecords) ValidateBasic() error {
|
||||
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 {
|
||||
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 {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user