Skip to content

Commit

Permalink
chore: add sp price related cli and refine cli and comments (#501)
Browse files Browse the repository at this point in the history
* refine cli and comments

* add sp price cli

* add sp price instruction
  • Loading branch information
alexgao001 authored Oct 13, 2023
1 parent 2adf79e commit c83cab9
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 35 deletions.
2 changes: 1 addition & 1 deletion proto/greenfield/permission/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ enum PrincipalType {
PRINCIPAL_TYPE_GNFD_GROUP = 2;
}

// Principal define the roles that can grant permissions. Currently, it can be account or group.
// Principal define the roles that can be grant permissions to. Currently, it can be account or group.
message Principal {
PrincipalType type = 1;
// When the type is an account, its value is sdk.AccAddress().String();
Expand Down
10 changes: 5 additions & 5 deletions proto/greenfield/storage/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ message MsgRejectSealObjectResponse {}
message MsgCopyObject {
option (cosmos.msg.v1.signer) = "operator";

// operator defines the account address of the operator who has the CopyObject permission of the object to be deleted.
// operator defines the account address of the operator who has the CopyObject permission.
string operator = 1;

// src_bucket_name defines the name of the bucket where the object to be copied is located
Expand Down Expand Up @@ -423,7 +423,7 @@ message MsgPutPolicy {
// operator defines the granter who grant the permission to another principal
string operator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// Principal defines the roles that can grant permissions. Currently, it can be account or group.
// Principal defines the roles that can be grant permissions to. Currently, it can be account or group.
permission.Principal principal = 2;

// resource defines a greenfield standard resource name that can be generated by GRN structure
Expand Down Expand Up @@ -472,7 +472,7 @@ message MsgDeletePolicyResponse {
message MsgMirrorObject {
option (cosmos.msg.v1.signer) = "operator";

// operator defines the account address of the operator who has the DeleteObject permission of the object to be deleted.
// operator defines the account address of the object owner.
string operator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// id defines the unique u256 for object.
Expand All @@ -497,7 +497,7 @@ message MsgMirrorObjectResponse {}
message MsgMirrorBucket {
option (cosmos.msg.v1.signer) = "operator";

// creator defines the account address of the grantee who has the DeleteBucket permission of the bucket to be deleted.
// operator defines the account address of the bucket owner.
string operator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// id defines the unique u256 for bucket.
Expand Down Expand Up @@ -538,7 +538,7 @@ message MsgMirrorBucketResponse {}
message MsgMirrorGroup {
option (cosmos.msg.v1.signer) = "operator";

// operator defines the account address of the operator who is the owner of the group
// operator defines the account address of the group owner.
string operator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// id defines the unique u256 for group.
Expand Down
32 changes: 16 additions & 16 deletions swagger/static/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4828,8 +4828,8 @@ paths:
when the type is a group, its value is
math.Uint().String()
description: >-
Principal define the roles that can grant permissions.
Currently, it can be account or group.
Principal define the roles that can be grant permissions
to. Currently, it can be account or group.
resource_type:
title: >-
resource_type defines the type of resource that grants
Expand Down Expand Up @@ -5022,8 +5022,8 @@ paths:
when the type is a group, its value is
math.Uint().String()
description: >-
Principal define the roles that can grant permissions.
Currently, it can be account or group.
Principal define the roles that can be grant permissions
to. Currently, it can be account or group.
resource_type:
title: >-
resource_type defines the type of resource that grants
Expand Down Expand Up @@ -5220,8 +5220,8 @@ paths:
when the type is a group, its value is
math.Uint().String()
description: >-
Principal define the roles that can grant permissions.
Currently, it can be account or group.
Principal define the roles that can be grant permissions
to. Currently, it can be account or group.
resource_type:
title: >-
resource_type defines the type of resource that grants
Expand Down Expand Up @@ -33672,8 +33672,8 @@ definitions:

when the type is a group, its value is math.Uint().String()
description: >-
Principal define the roles that can grant permissions. Currently, it
can be account or group.
Principal define the roles that can be grant permissions to.
Currently, it can be account or group.
resource_type:
title: resource_type defines the type of resource that grants permission for
type: string
Expand Down Expand Up @@ -33800,8 +33800,8 @@ definitions:
When the type is an account, its value is sdk.AccAddress().String();
when the type is a group, its value is math.Uint().String()
description: >-
Principal define the roles that can grant permissions. Currently, it can
be account or group.
Principal define the roles that can be grant permissions to. Currently, it
can be account or group.
greenfield.permission.PrincipalType:
type: string
enum:
Expand Down Expand Up @@ -35407,8 +35407,8 @@ definitions:

when the type is a group, its value is math.Uint().String()
description: >-
Principal define the roles that can grant permissions. Currently,
it can be account or group.
Principal define the roles that can be grant permissions to.
Currently, it can be account or group.
resource_type:
title: >-
resource_type defines the type of resource that grants permission
Expand Down Expand Up @@ -35559,8 +35559,8 @@ definitions:

when the type is a group, its value is math.Uint().String()
description: >-
Principal define the roles that can grant permissions. Currently,
it can be account or group.
Principal define the roles that can be grant permissions to.
Currently, it can be account or group.
resource_type:
title: >-
resource_type defines the type of resource that grants permission
Expand Down Expand Up @@ -35711,8 +35711,8 @@ definitions:

when the type is a group, its value is math.Uint().String()
description: >-
Principal define the roles that can grant permissions. Currently,
it can be account or group.
Principal define the roles that can be grant permissions to.
Currently, it can be account or group.
resource_type:
title: >-
resource_type defines the type of resource that grants permission
Expand Down
2 changes: 1 addition & 1 deletion x/permission/types/common.pb.go

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

59 changes: 59 additions & 0 deletions x/sp/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func GetQueryCmd() *cobra.Command {
CmdStorageProvider(),
CmdStorageProviderByOperatorAddress(),
CmdMaintenanceRecordsBySPOperatorAddress(),
CmdStorageProviderPrice(),
CmdStorageProviderGlobalPrice(),
)

// this line is used by starport scaffolding # 1
Expand Down Expand Up @@ -174,3 +176,60 @@ func CmdMaintenanceRecordsBySPOperatorAddress() *cobra.Command {

return cmd
}

func CmdStorageProviderPrice() *cobra.Command {
cmd := &cobra.Command{
Use: "price [sp-address]",
Short: "Query storage provider prices, including read, store price and free quota",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
spAddr, err := sdk.AccAddressFromHexUnsafe(args[0])
if err != nil {
return err
}

clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
res, err := types.NewQueryClient(clientCtx).
QuerySpStoragePrice(cmd.Context(), &types.QuerySpStoragePriceRequest{
SpAddr: spAddr.String(),
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

func CmdStorageProviderGlobalPrice() *cobra.Command {
cmd := &cobra.Command{
Use: "global-price [timestamp]",
Short: "Query the global price at a specific time(in unix), return latest price price if timestamp is 0",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
ts, err := strconv.ParseInt(args[0], 10, 64)
if err != nil {
return err
}
res, err := types.NewQueryClient(clientCtx).
QueryGlobalSpStorePriceByTime(cmd.Context(), &types.QueryGlobalSpStorePriceByTimeRequest{
Timestamp: ts,
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
65 changes: 61 additions & 4 deletions x/sp/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"fmt"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -37,6 +38,7 @@ func GetTxCmd() *cobra.Command {
CmdEditStorageProvider(),
CmdGrantDepositAuthorization(),
CmdUpdateStorageProviderStatus(),
CmdUpdateStorageProviderStoragePrice(),
)

// this line is used by starport scaffolding # 1
Expand Down Expand Up @@ -258,7 +260,7 @@ func CmdEditStorageProvider() *cobra.Command {
}

flags.AddTxFlagsToCmd(cmd)
cmd.Flags().String(FlagEndpoint, types.DoNotModifyDesc, "The storage provider's endpoint")
cmd.Flags().String(FlagEndpoint, "", "The storage provider's endpoint")
// DescriptionEdit
cmd.Flags().String(FlagEditMoniker, types.DoNotModifyDesc, "The storage provider's name")
cmd.Flags().String(FlagIdentity, types.DoNotModifyDesc, "The (optional) identity signature (ex. UPort or Keybase)")
Expand All @@ -278,8 +280,8 @@ func CmdEditStorageProvider() *cobra.Command {
func CmdDeposit() *cobra.Command {
cmd := &cobra.Command{
Use: "deposit [sp-address] [fund-address] [value]",
Short: "Deposit tokens for an active proposal",
Args: cobra.ExactArgs(2),
Short: "SP stake tokens from funding account",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) (err error) {

clientCtx, err := client.GetClientTxContext(cmd)
Expand Down Expand Up @@ -672,7 +674,7 @@ func BuildCreateStorageProviderMsg(config TxCreateStorageProviderConfig, txBldr

func CmdUpdateStorageProviderStatus() *cobra.Command {
cmd := &cobra.Command{
Use: "update-status [sp-address] [new-status] --duration",
Use: "update-status [sp-address] [new-status] [flags]",
Short: "Update status of a storage provider",
Long: strings.TrimSpace(
fmt.Sprintf(`update the storage provider status between STATUS_IN_SERVICE and STATUS_IN_MAINTENANCE, need to provide the maintenance duration in second if status is to STATUS_IN_MAINTENANCE.
Expand Down Expand Up @@ -715,3 +717,58 @@ Examples:
cmd.Flags().Int64(FlagDuration, 0, "maintenance duration requested by a SP")
return cmd
}

func CmdUpdateStorageProviderStoragePrice() *cobra.Command {
cmd := &cobra.Command{
Use: "update-price [sp-address] [read-price] [store-price] [free-read-quota]",
Short: "Update prices and free read quota of a storage provider, all prices in BNB wei",
Long: strings.TrimSpace(
fmt.Sprintf(`update the storage provider read, store price and free read quota, if there is no change to a specific value, the current value should also be provided.
The unit of price is a decimal, which indicates wei BNB per byte per second.
E.g. the price is 0.02183945725, means approximately $0.018 / GB / Month.
(0.02183945725 * (30 * 86400) * (1024 * 1024 * 1024) * 300 / 10 ** 18 ≈ 0.018, assume the BNB price is 300 USD)
The free-read-quota unit is bytes, for 1GB free quota, it is 1073741824.
Examples:
$ %s tx %s update-price 0x... 0.1469890427 0.02183945725 1073741824
`, version.AppName, types.ModuleName),
),
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
spAddress, err := sdk.AccAddressFromHexUnsafe(args[0])
if err != nil {
return err
}
readPrice, err := sdk.NewDecFromStr(args[1])
if err != nil {
return err
}
storePrice, err := sdk.NewDecFromStr(args[2])
if err != nil {
return err
}
quota, err := strconv.ParseUint(args[3], 10, 64)
if err != nil {
return err
}
msg := types.MsgUpdateSpStoragePrice{
SpAddress: spAddress.String(),
ReadPrice: readPrice,
StorePrice: storePrice,
FreeReadQuota: quota,
}
if err = msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
9 changes: 6 additions & 3 deletions x/storage/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ func CmdDeleteObject() *cobra.Command {

func CmdUpdateObjectInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "update-object-info [bucket-name] [object-name] [visibility]",
Use: "update-object-info [bucket-name] [object-name] [flags]",
Short: "Update the meta of object, Currently only support: Visibility",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
Expand Down Expand Up @@ -521,7 +521,7 @@ func CmdDiscontinueObject() *cobra.Command {
func CmdCreateGroup() *cobra.Command {
cmd := &cobra.Command{
Use: "create-group [group-name]",
Short: "Create a new group with optional members, split member addresses by ','",
Short: "Create a new group without group members",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argGroupName := args[0]
Expand Down Expand Up @@ -661,7 +661,7 @@ func CmdUpdateGroupMember() *cobra.Command {
}

var memberAddrsToDelete []sdk.AccAddress
if len(argMemberToDelete) == 0 {
if len(argMemberToDelete) != 0 {
membersToDelete := strings.Split(argMemberToDelete, ",")
for _, member := range membersToDelete {
if len(member) > 0 {
Expand Down Expand Up @@ -924,6 +924,7 @@ func CmdMirrorBucket() *cobra.Command {

cmd.Flags().String(FlagBucketId, "", "Id of the bucket to mirror")
cmd.Flags().String(FlagBucketName, "", "Name of the bucket to mirror")
cmd.Flags().String(FlagDestChainId, "", "the destination chain id")
flags.AddTxFlagsToCmd(cmd)

return cmd
Expand Down Expand Up @@ -1019,6 +1020,7 @@ func CmdMirrorObject() *cobra.Command {
cmd.Flags().String(FlagObjectId, "", "Id of the object to mirror")
cmd.Flags().String(FlagObjectName, "", "Name of the object to mirror")
cmd.Flags().String(FlagBucketName, "", "Name of the bucket that the object belongs to")
cmd.Flags().String(FlagDestChainId, "", "the destination chain id")
flags.AddTxFlagsToCmd(cmd)

return cmd
Expand Down Expand Up @@ -1078,6 +1080,7 @@ func CmdMirrorGroup() *cobra.Command {

cmd.Flags().String(FlagGroupId, "", "Id of the group to mirror")
cmd.Flags().String(FlagGroupName, "", "Name of the group to mirror")
cmd.Flags().String(FlagDestChainId, "", "the destination chain id")
flags.AddTxFlagsToCmd(cmd)

return cmd
Expand Down
Loading

0 comments on commit c83cab9

Please sign in to comment.