Skip to content

Commit

Permalink
feat: MsgSetBucketFlowRateLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
rrr523 committed Apr 24, 2024
1 parent bc1e2f9 commit 1a4f409
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/js-sdk/src/api/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
MsgDeletePolicy,
MsgMigrateBucket,
MsgPutPolicy,
MsgSetBucketFlowRateLimit,
MsgToggleSPAsDelegatedAgent,
MsgUpdateBucketInfo,
} from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/tx';
Expand All @@ -43,6 +44,7 @@ import {
MsgCreateBucketTypeUrl,
MsgDeleteBucketTypeUrl,
MsgMigrateBucketTypeUrl,
MsgSetBucketFlowRateLimitTypeUrl,
MsgToggleSPAsDelegatedAgentTypeUrl,
MsgUpdateBucketInfoTypeUrl,
newBucketGRN,
Expand Down Expand Up @@ -101,6 +103,8 @@ import { decodeObjectFromHexString } from '../utils/encoding';
import { Sp } from './sp';
import { Storage } from './storage';
import { VirtualGroup } from './virtualGroup';
import { Payment } from './payment';
import { MsgSetBucketFlowRateLimitSDKTypeEIP712 } from '@/messages/greenfield/storage/MsgDeleteBucket2';

export interface IBucket {
/**
Expand Down Expand Up @@ -187,6 +191,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 +210,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);
});
});
});

0 comments on commit 1a4f409

Please sign in to comment.