Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions x/medianode/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ func GetCmdRegisterMediaNode() *cobra.Command {
Example: fmt.Sprintf(
"$ %s tx medianode register"+
"--url=https://mymedianode.com"+
"--moniker=my-node"+
"--node-moniker=my-node"+
"--description=mydescription"+
"--contact=contact@mynode.com"+
"--hardware-specs=<hardwarespecs>"+
"--price-per-hour=<amount> "+
"--deposit=<amount> "+
"--from=<key-name> "+
"--chain-id=<chain-id> "+
"--fees=<fee>",
Expand Down Expand Up @@ -142,7 +143,7 @@ func GetCmdUpdateMediaNode() *cobra.Command {
Long: "Update an existing media node's information, hardware specs, and price\n",
Example: fmt.Sprintf(
"$ %s tx medianode update [medianode-id] "+
"--moniker=<name> "+
"--node-moniker=<name> "+
"--description=<description> "+
"--contact=<contact> "+
"--hardware-specs=<specs> "+
Expand Down Expand Up @@ -232,7 +233,7 @@ func GetCmdLeaseMediaNode() *cobra.Command {
Short: "leases a media node",
Long: "leases a media node with the specified URL and lease hours\n",
Example: fmt.Sprintf(
"$ %s tx medianode lease [medianode-id] --lease-hours=<no-of-hours> --amount=<amount> "+
"$ %s tx medianode lease [medianode-id] --lease-hours=<no-of-hours> --lease-amount=<amount> "+
"--from=<key-name> "+
"--chain-id=<chain-id> "+
"--fees=<fee>",
Expand Down Expand Up @@ -283,7 +284,7 @@ func GetCmdExtendLease() *cobra.Command {
Short: "extends a lease for a media node",
Long: "extends an active lease for a media node with the specified ID and additional lease hours\n",
Example: fmt.Sprintf(
"$ %s tx medianode extend-lease [medianode-id] --additional-hours=<no-of-hours> --amount=<amount> "+
"$ %s tx medianode extend-lease [medianode-id] --additional-hours=<no-of-hours> --lease-amount=<amount> "+
"--from=<key-name> "+
"--chain-id=<chain-id> "+
"--fees=<fee>",
Expand Down Expand Up @@ -334,7 +335,7 @@ func GetCmdDepositMediaNode() *cobra.Command {
Short: "deposits an amount for a media node",
Long: "deposits an amount for a media node with the specified URL and deposit amount\n",
Example: fmt.Sprintf(
"$ %s tx medianode deposit [medianode-id] --amount=<amount> "+
"$ %s tx medianode deposit [medianode-id] --deposit=<amount> "+
"--from=<key-name> "+
"--chain-id=<chain-id> "+
"--fees=<fee>",
Expand Down
6 changes: 5 additions & 1 deletion x/medianode/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,12 @@ func (k Keeper) DepositMediaNode(ctx sdk.Context, mediaNodeId string, amount sdk
minDeposit := k.GetMinDeposit(ctx)
initialDepositPerc := k.GetInitialDepositPercentage(ctx)
minInitialDeposit := sdk.NewCoin(minDeposit.Denom, sdkmath.LegacyNewDecFromInt(minDeposit.Amount).Mul(initialDepositPerc).TruncateInt())

if amount.Denom != minDeposit.Denom {
return types.MediaNode{}, sdk.Coin{}, errorsmod.Wrapf(types.ErrInvalidDeposit, "invalid deposit denom; expected %s, got %s", minDeposit.Denom, amount.Denom)
}
if !amount.IsGTE(minInitialDeposit) {
return types.MediaNode{}, sdk.Coin{}, errorsmod.Wrapf(types.ErrInsufficientDeposit, "%s of deposit is required", minInitialDeposit.String())
return types.MediaNode{}, sdk.Coin{}, errorsmod.Wrapf(types.ErrInsufficientDeposit, "deposit must be at least %s", minInitialDeposit.String())
}

// Create a deposit object
Expand Down
23 changes: 10 additions & 13 deletions x/medianode/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ func (m msgServer) RegisterMediaNode(goCtx context.Context, msg *types.MsgRegist
minDeposit := m.Keeper.GetMinDeposit(ctx)
initialDepositPerc := m.Keeper.GetInitialDepositPercentage(ctx)
minInitialDeposit := sdk.NewCoin(minDeposit.Denom, sdkmath.LegacyNewDecFromInt(minDeposit.Amount).Mul(initialDepositPerc).TruncateInt())
if msg.Deposit.Denom != minDeposit.Denom {
return nil, errorsmod.Wrapf(types.ErrInvalidDeposit, "invalid deposit denom; expected %s, got %s", minDeposit.Denom, msg.Deposit.Denom)
}
if !msg.Deposit.IsGTE(minInitialDeposit) {
return nil, errorsmod.Wrapf(types.ErrInsufficientDeposit, "%s of initial deposit is reqquired", minInitialDeposit.String())
return nil, errorsmod.Wrapf(types.ErrInsufficientDeposit, "initial deposit must be at least %s", minInitialDeposit.String())
}

// Create and store the media node
Expand Down Expand Up @@ -86,16 +89,13 @@ func (m msgServer) LeaseMediaNode(goCtx context.Context, msg *types.MsgLeaseMedi
}

params := m.Keeper.GetParams(ctx)
if msg.LeaseHours < params.MinimumLeaseHours {
return nil, errorsmod.Wrapf(types.ErrInvalidLeaseHours, "minimum of %d lease hours required", params.MinimumLeaseHours)
}
if msg.LeaseHours > params.MaximumLeaseHours {
return nil, errorsmod.Wrapf(types.ErrInvalidLeaseHours, "maximum of %d lease hours allowed", params.MaximumLeaseHours)
if msg.LeaseHours < params.MinimumLeaseHours || msg.LeaseHours > params.MaximumLeaseHours {
return nil, errorsmod.Wrapf(types.ErrInvalidLeaseHours, "lease hours must be between %d and %d", params.MinimumLeaseHours, params.MaximumLeaseHours)
}

mediaNode, found := m.Keeper.GetMediaNode(ctx, msg.MediaNodeId)
if !found {
return nil, errorsmod.Wrapf(types.ErrMediaNodeDoesNotExist, "not found")
return nil, errorsmod.Wrapf(types.ErrMediaNodeDoesNotExist, "media node %s does not exist", msg.MediaNodeId)
}
if mediaNode.Status != types.STATUS_ACTIVE {
return nil, errorsmod.Wrapf(types.ErrLeaseNotAllowed, "only active medianodes are allowed to lease")
Expand Down Expand Up @@ -131,16 +131,13 @@ func (m msgServer) ExtendLease(goCtx context.Context, msg *types.MsgExtendLease)
}

params := m.Keeper.GetParams(ctx)
if msg.LeaseHours < params.MinimumLeaseHours {
return nil, errorsmod.Wrapf(types.ErrInvalidLeaseHours, "minimum of %d lease hours required", params.MinimumLeaseHours)
}
if msg.LeaseHours > params.MaximumLeaseHours {
return nil, errorsmod.Wrapf(types.ErrInvalidLeaseHours, "maximum of %d lease hours allowed", params.MaximumLeaseHours)
if msg.LeaseHours < params.MinimumLeaseHours || msg.LeaseHours > params.MaximumLeaseHours {
return nil, errorsmod.Wrapf(types.ErrInvalidLeaseHours, "lease hours must be between %d and %d", params.MinimumLeaseHours, params.MaximumLeaseHours)
}

mediaNodeLease, found := m.Keeper.GetMediaNodeLease(ctx, msg.MediaNodeId)
if !found {
return nil, errorsmod.Wrapf(types.ErrLeaseNotFound, "not found")
return nil, errorsmod.Wrapf(types.ErrLeaseNotFound, "lease not found")
}

expectedLeaseAmount := sdk.NewCoin(mediaNodeLease.PricePerHour.Denom, mediaNodeLease.PricePerHour.Amount.Mul(sdkmath.NewIntFromUint64((msg.LeaseHours))))
Expand Down
3 changes: 3 additions & 0 deletions x/medianode/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func (msg MsgRegisterMediaNode) ValidateBasic() error {
if msg.PricePerHour.Denom != params.BondDenom {
return errorsmod.Wrap(ErrInvalidLeaseAmount, "invalid denom for price per hour only uflix is supported")
}
if err := msg.Deposit.Validate(); err != nil {
return errorsmod.Wrap(ErrInvalidDeposit, "invalid deposit amount")
}
if msg.PricePerHour.Amount.IsZero() {
return errorsmod.Wrap(ErrInvalidLeaseAmount, "price per hour must be positive")
}
Expand Down
Loading