Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add SetBucketFlowRateLimit #233

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
55 changes: 55 additions & 0 deletions client/api_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strings"
"time"

sdkmath "cosmossdk.io/math"
ctypes "github.com/cometbft/cometbft/rpc/core/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx"
Expand Down Expand Up @@ -56,6 +57,8 @@ type IBucketClient interface {
CancelMigrateBucket(ctx context.Context, bucketName string, opts types.CancelMigrateBucketOptions) (string, error)
GetBucketMigrationProgress(ctx context.Context, bucketName string, destSP uint32) (types.MigrationProgress, error)
ListBucketsByPaymentAccount(ctx context.Context, paymentAccount string, opts types.ListBucketsByPaymentAccountOptions) (types.ListBucketsByPaymentAccountResult, error)
SetBucketFlowRateLimit(ctx context.Context, bucketName string, paymentAddr, bucketOwner sdk.AccAddress, flowRateLimit sdkmath.Int, opt types.UpdatePaymentOption) (string, error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpdatePaymentOption -> SetBucketFlowRateLimitOption

GetPaymentAccountFlowRateLimit(ctx context.Context, paymentAddr, bucketOwner sdk.AccAddress, bucketName string) (*storageTypes.QueryPaymentAccountBucketFlowRateLimitResponse, error)
}

// GetCreateBucketApproval - Send create bucket approval request to SP and returns the signature info for the approval of preCreating resources.
Expand Down Expand Up @@ -271,6 +274,58 @@ func (c *Client) UpdateBucketPaymentAddr(ctx context.Context, bucketName string,
return c.sendTxn(ctx, updateBucketMsg, opt.TxOpts)
}

// SetBucketFlowRateLimit - Set the flow rate limit of the bucket. It will send the MsgSetBucketFlowRateLimit msg to greenfield to update the meta.
//
// - ctx: Context variables for the current API call.
//
// - bucketName: The name of the bucket to be updated.
//
// - paymentAddr: The payment address from which deduct the cost of bucket storage or quota.
//
// - bucketOwner: The owner of the bucket.
//
// - flowRateLimit: The flow rate limit of the bucket.
//
// - opt: The Options for customizing the transaction.
//
// - ret1: Transaction hash return from blockchain.
//
// - ret2: Return error if update flow rate limit failed, otherwise return nil.
func (c *Client) SetBucketFlowRateLimit(ctx context.Context, bucketName string,
paymentAddr, bucketOwner sdk.AccAddress, flowRateLimit sdkmath.Int, opt types.UpdatePaymentOption,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpdatePaymentOption -> SetBucketFlowRateLimitOption

) (string, error) {
updateBucketMsg := storageTypes.NewMsgSetBucketFlowRateLimit(c.MustGetDefaultAccount().GetAddress(), bucketOwner, paymentAddr, bucketName, flowRateLimit)
return c.sendTxn(ctx, updateBucketMsg, opt.TxOpts)
}

// GetPaymentAccountFlowRateLimit - Get the flow rate limit of the bucket.
//
// - ctx: Context variables for the current API call.
//
// - paymentAddr: The payment address from which deduct the cost of bucket storage or quota.
//
// - bucketOwner: The owner of the bucket.
//
// - bucketName: The name of the bucket.
//
// - ret1: The flow rate limit of the bucket.
//
// - ret2: Return error if get flow rate limit failed, otherwise return nil.
func (c *Client) GetPaymentAccountFlowRateLimit(ctx context.Context, paymentAddr, bucketOwner sdk.AccAddress, bucketName string) (*storageTypes.QueryPaymentAccountBucketFlowRateLimitResponse, error) {
queryFlowRateLimit := storageTypes.QueryPaymentAccountBucketFlowRateLimitRequest{
PaymentAccount: paymentAddr.String(),
BucketOwner: bucketOwner.String(),
BucketName: bucketName,
}

queryFlowRateLimitResp, err := c.chainClient.QueryPaymentAccountBucketFlowRateLimit(ctx, &queryFlowRateLimit)
if err != nil {
return nil, err
}

return queryFlowRateLimitResp, nil
}

// UpdateBucketInfo - Update the bucket meta on chain, including read quota, payment address or visibility. It will send the MsgUpdateBucketInfo msg to greenfield to update the meta.
//
// - ctx: Context variables for the current API call.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,5 @@ replace (
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v1.5.1-0.20240318023627-97f1fb45ef8c
github.com/cosmos/iavl => github.com/bnb-chain/greenfield-iavl v0.20.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/wercker/journalhook => github.com/wercker/journalhook v0.0.0-20230927020745-64542ffa4117
)
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ github.com/wealdtech/go-eth2-util v1.6.3 h1:2INPeOR35x5LdFFpSzyw954WzTD+DFyHe3yK
github.com/wealdtech/go-eth2-util v1.6.3/go.mod h1:0hFMj/qtio288oZFHmAbCnPQ9OB3c4WFzs5NVPKTY4k=
github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4 v1.1.3/go.mod h1:qiIimacW5NhVRy8o+YxWo9YrecXqDAKKbL0+sOa0SJ4=
github.com/wealdtech/go-eth2-wallet-types/v2 v2.8.2/go.mod h1:k6kmiKWSWBTd4OxFifTEkPaBLhZspnO2KFD5XJY9nqg=
github.com/wercker/journalhook v0.0.0-20180428041537-5d0a5ae867b3/go.mod h1:XCsSkdKK4gwBMNrOCZWww0pX6AOt+2gYc5Z6jBRrNVg=
github.com/wercker/journalhook v0.0.0-20230927020745-64542ffa4117/go.mod h1:XCsSkdKK4gwBMNrOCZWww0pX6AOt+2gYc5Z6jBRrNVg=
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc=
github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM=
github.com/whyrusleeping/mdns v0.0.0-20190826153040-b9b60ed33aa9/go.mod h1:j4l84WPFclQPj320J9gp0XwNKBb3U0zt5CBqjPp22G4=
Expand Down
5 changes: 5 additions & 0 deletions types/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ type UpdatePaymentOption struct {
TxOpts *gnfdsdktypes.TxOption // TxOpts defines the options to customize a transaction.
}

// SetBucketFlowRateLimitOption indicates the metadata to construct `SetBucketFlowRateLimit` msg.
type SetBucketFlowRateLimitOption struct {
TxOpts *gnfdsdktypes.TxOption // TxOpts defines the options to customize a transaction.
}

// UpdateBucketOptions indicates the metadata to construct `UpdateBucketInfo` msg of storage module.
type UpdateBucketOptions struct {
Visibility storageTypes.VisibilityType // Visibility defines the bucket public status.
Expand Down
Loading