Skip to content

Commit

Permalink
docs(defi-loan): missing ErrInvalidSigner (#4428)
Browse files Browse the repository at this point in the history
* defi loan tutorial: add ErrInvalidSigner

* defi loan tutorial: remove ErrInvalidSigner and update

* update

---------

Co-authored-by: Julien Robert <[email protected]>
  • Loading branch information
chen4903 and julienrbrt authored Nov 28, 2024
1 parent 8df271b commit 37ac324
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion docs/versioned_docs/version-v28/02-guide/05-loan.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Notice the `--no-module` flag, in the next step we make sure the `bank` dependen

2. **Create a Module:**


Create a new "loan" module that is based on the standard Cosmos SDK `bank` module.

```bash
Expand Down Expand Up @@ -384,7 +385,33 @@ func (k msgServer) LiquidateLoan(goCtx context.Context, msg *types.MsgLiquidateL
}
```

Add the custom errors `ErrWrongLoanState` and `ErrDeadline`:
```go title="x/loan/keeper/msg_update_params.go"
package keeper

import (
"context"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"

"loan/x/loan/types"
)

func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if k.GetAuthority() != req.Authority {
return nil, errorsmod.Wrapf(types.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority)
}

ctx := sdk.UnwrapSDKContext(goCtx)
if err := k.SetParams(ctx, req.Params); err != nil {
return nil, err
}

return &types.MsgUpdateParamsResponse{}, nil
}
```

Add the errors `ErrInvalidSigner`, `ErrWrongLoanState` and `ErrDeadline`:

```go title="x/loan/types/errors.go"
package types
Expand All @@ -394,6 +421,7 @@ import (
)

var (
ErrInvalidSigner = sdkerrors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message")
ErrWrongLoanState = sdkerrors.Register(ModuleName, 2, "wrong loan state")
ErrDeadline = sdkerrors.Register(ModuleName, 3, "deadline")
)
Expand Down

0 comments on commit 37ac324

Please sign in to comment.