Skip to content

Commit

Permalink
refactor(plan): Remove and add some logical judgments
Browse files Browse the repository at this point in the history
  • Loading branch information
sheldonleedev committed Jun 17, 2024
1 parent c8314e4 commit 3eb49f8
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ func NewLorenzoApp(
app.AccountKeeper,
app.BankKeeper,
app.EvmKeeper,
app.AgentKeeper,
)

transferStack := ibctransfer.NewIBCModule(app.TransferKeeper)
Expand Down
2 changes: 1 addition & 1 deletion proto/lorenzo/plan/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ message QueryPlansResponse {

// PlanRequest is the request type for the Query.Plan RPC method.
message QueryPlanRequest {
// id is the unique identifier of the agent
// id is the unique identifier of the plan
uint64 id = 1;
}

Expand Down
4 changes: 2 additions & 2 deletions proto/lorenzo/plan/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ message MsgUpdateParamsResponse {
message MsgUpgradeYAT {
option (cosmos.msg.v1.signer) = "authority";

// implementation is the new erc20 contract address
// implementation is the new yat logic contract address
string implementation = 1;

// authority is the address of the governance account.
Expand Down Expand Up @@ -98,7 +98,7 @@ message MsgCreatePlan {

// MsgCreatePlanResponse is the response type for the Msg/CreatePlan RPC method.
message MsgCreatePlanResponse {
// id is the unique identifier of the agent
// id is the unique identifier of the plan
uint64 id = 1;
}

Expand Down
5 changes: 2 additions & 3 deletions x/plan/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ func (k Keeper) EndBlocker(ctx sdk.Context) {
logger := k.Logger(ctx)
params := k.GetParams(ctx)

// deploy a new beacon contract if the current block height is 1
// TODO:
if ctx.BlockHeight() <= 1 || len(params.Beacon) == 0 {
// deploy a new beacon contract if the current beacon contract is empty
if len(params.Beacon) == 0 {
// deploy a new beacon proxy contract & deploy a new plan logic contract
// 1. deploy a new plan logic contract
logicAddr, err := k.DeployYATLogicContract(ctx)
Expand Down
4 changes: 4 additions & 0 deletions x/plan/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type Keeper struct {
accountKeeper types.AccountKeeper
bankKeeper bankkeeper.Keeper
evmKeeper types.EVMKeeper

agentKeeper types.AgentKeeper
}

func NewKeeper(
Expand All @@ -33,6 +35,7 @@ func NewKeeper(
ak types.AccountKeeper,
bk bankkeeper.Keeper,
evmKeeper types.EVMKeeper,
agentKeeper types.AgentKeeper,
) *Keeper {
return &Keeper{
authority: authority,
Expand All @@ -41,6 +44,7 @@ func NewKeeper(
accountKeeper: ak,
bankKeeper: bk,
evmKeeper: evmKeeper,
agentKeeper: agentKeeper,
}
}

Expand Down
4 changes: 4 additions & 0 deletions x/plan/keeper/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (

func (k Keeper) AddPlan(ctx sdk.Context, plan types.Plan) (types.Plan, error) {
// todo: check if the agent not exists
_, agentFound := k.agentKeeper.GetAgent(ctx, plan.AgentId)
if !agentFound {
return types.Plan{}, types.ErrAgentNotFound
}

// generate the next plan ID
planId := k.GetNextNumber(ctx)
Expand Down
1 change: 1 addition & 0 deletions x/plan/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ var (
ErrInvalidClaimsType = errorsmod.Register(ModuleName, 8, "invalid claims type")
ErrBeaconNotSet = errorsmod.Register(ModuleName, 9, "beacon not set")
ErrVMExecution = errorsmod.Register(ModuleName, 10, "VM execution failed")
ErrAgentNotFound = errorsmod.Register(ModuleName, 11, "agent not found")
)
7 changes: 7 additions & 0 deletions x/plan/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/evmos/ethermint/x/evm/statedb"
evmtypes "github.com/evmos/ethermint/x/evm/types"

agenttypes "github.com/Lorenzo-Protocol/lorenzo/x/agent/types"
)

// AccountKeeper defines the expected interface needed to retrieve account info.
Expand All @@ -30,3 +32,8 @@ type EVMKeeper interface {
ApplyMessage(ctx sdk.Context, msg core.Message, tracer vm.EVMLogger, commit bool) (*evmtypes.MsgEthereumTxResponse, error)
ChainID() *big.Int
}

// AgentKeeper defines the expected interface needed to retrieve agent info.
type AgentKeeper interface {
GetAgent(ctx sdk.Context, id uint64) (agenttypes.Agent, bool)
}
2 changes: 1 addition & 1 deletion x/plan/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions x/plan/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3eb49f8

Please sign in to comment.