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: MsgSetBucketFlowRateLimit #531

Merged
merged 3 commits into from
Apr 29, 2024
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
5 changes: 5 additions & 0 deletions .changeset/rich-jars-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bnb-chain/greenfield-js-sdk": patch
---

feat: MsgSetBucketFlowRateLimit
22 changes: 20 additions & 2 deletions packages/js-sdk/src/api/bucket.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {
MsgToggleSPAsDelegatedAgentSDKTypeEIP712,
MsgCreateBucketSDKTypeEIP712,
MsgDeleteBucketSDKTypeEIP712,
MsgMigrateBucketSDKTypeEIP712,
MsgToggleSPAsDelegatedAgentSDKTypeEIP712,
MsgUpdateBucketInfoSDKTypeEIP712,
} from '@/messages/greenfield';
import { MsgSetBucketFlowRateLimitSDKTypeEIP712 } from '@/messages/greenfield/storage/MsgSetBucketFlowRateLimit';
import { assertAuthType, assertStringRequire } from '@/utils/asserts/params';
import { UInt64Value } from '@bnb-chain/greenfield-cosmos-types/greenfield/common/wrapper';
import {
Expand All @@ -29,6 +30,7 @@ import {
MsgDeletePolicy,
MsgMigrateBucket,
MsgPutPolicy,
MsgSetBucketFlowRateLimit,
MsgToggleSPAsDelegatedAgent,
MsgUpdateBucketInfo,
} from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/tx';
Expand All @@ -43,10 +45,11 @@ import {
MsgCreateBucketTypeUrl,
MsgDeleteBucketTypeUrl,
MsgMigrateBucketTypeUrl,
MsgSetBucketFlowRateLimitTypeUrl,
MsgToggleSPAsDelegatedAgentTypeUrl,
MsgUpdateBucketInfoTypeUrl,
newBucketGRN,
TxResponse,
newBucketGRN,
} from '..';
import { RpcQueryClient } from '../clients/queryclient';
import { HTTPHeaderUserAddress } from '../clients/spclient/auth';
Expand Down Expand Up @@ -187,6 +190,11 @@ export interface IBucket {
updateBucketInfo(
srcMsg: Omit<MsgUpdateBucketInfo, 'chargedReadQuota'> & { chargedReadQuota?: string },
): Promise<TxResponse>;

/**
* Get the flow rate limit of the bucket.
*/
setPaymentAccountFlowRateLimit(msg: MsgSetBucketFlowRateLimit): Promise<TxResponse>;
}

@injectable()
Expand All @@ -201,6 +209,16 @@ export class Bucket implements IBucket {
private queryClient = container.resolve(RpcQueryClient);
private spClient = container.resolve(SpClient);

public async setPaymentAccountFlowRateLimit(msg: MsgSetBucketFlowRateLimit) {
return await this.txClient.tx(
MsgSetBucketFlowRateLimitTypeUrl,
msg.operator,
MsgSetBucketFlowRateLimitSDKTypeEIP712,
MsgSetBucketFlowRateLimit.toSDK(msg),
MsgSetBucketFlowRateLimit.encode(msg).finish(),
);
}

public async createBucket(msg: MsgCreateBucket) {
assertStringRequire(msg.primarySpAddress, 'Primary sp address is missing');
assertStringRequire(msg.creator, 'Empty creator address');
Expand Down
1 change: 1 addition & 0 deletions packages/js-sdk/src/constants/typeUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const AllowedMsgAllowanceTypeUrl = '/cosmos.feegrant.v1beta1.AllowedMsgAl
export const MsgEditValidatorTypeUrl = '/cosmos.staking.v1beta1.MsgEditValidator';
export const MsgCreateValidatorTypeUrl = '/cosmos.staking.v1beta1.MsgCreateValidator';
export const MsgVoteTypeUrl = '/cosmos.gov.v1.MsgVote';
export const MsgSetBucketFlowRateLimitTypeUrl = '/greenfield.storage.MsgSetBucketFlowRateLimit';
export const MsgSubmitProposalTypeUrl = '/cosmos.gov.v1.MsgSubmitProposal';
export const MsgWithdrawDelegatorRewardTypeUrl =
'/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export const MsgSetBucketFlowRateLimitSDKTypeEIP712 = {
Msg1: [
{
name: 'bucket_name',
type: 'string',
},
{
name: 'bucket_owner',
type: 'string',
},
{
name: 'flow_rate_limit',
type: 'string',
},
{
name: 'operator',
type: 'string',
},
{
name: 'payment_address',
type: 'string',
},
{
name: 'type',
type: 'string',
},
],
};
30 changes: 30 additions & 0 deletions packages/js-sdk/tests/storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, expect, test } from '@jest/globals';
import { bytesFromBase64, Long, RedundancyType, VisibilityType } from '../src';
import { ACCOUNT_ADDRESS, ACCOUNT_PRIVATEKEY } from './env';
import { client, generateString, selectSp } from './utils';
import { Account } from '../src/api/account';

const BUCKET_NAME = generateString(10);
const OBJECT_NAME = generateString(10);
Expand Down Expand Up @@ -151,4 +152,33 @@ describe('storageTx', () => {
expect(res.code).toEqual(0);
}, 300000);
});

describe('payment', () => {
test('setPaymentAccountFlowRateLimit', async () => {
const tx = await client.bucket.setPaymentAccountFlowRateLimit({
bucketName: 'dfg',
bucketOwner: ACCOUNT_ADDRESS,
operator: ACCOUNT_ADDRESS,
paymentAddress: ACCOUNT_ADDRESS,
flowRateLimit: '1000',
});

const simulateInfo = await tx.simulate({
denom: 'BNB',
});

expect(simulateInfo).not.toBeNull();

const res = await tx.broadcast({
denom: 'BNB',
gasLimit: Number(simulateInfo?.gasLimit),
gasPrice: simulateInfo?.gasPrice || '5000000000',
payer: ACCOUNT_ADDRESS,
granter: '',
privateKey: ACCOUNT_PRIVATEKEY,
});

expect(res.code).toEqual(0);
});
});
});
Loading