Skip to content

Commit

Permalink
feat: Add toggleSpAsDelegatedAgent API
Browse files Browse the repository at this point in the history
  • Loading branch information
rrr523 committed Mar 19, 2024
1 parent 8d91b2a commit a056afa
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-moles-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

feat: bucket toggleSpAsDelegatedAgent API
5 changes: 5 additions & 0 deletions examples/nextjs/src/components/bucket/update/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export const UpdateBucket = () => {
onClick={async () => {
if (!address) return;

// const toggleSpAsDelegatedAgentTx = await client.bucket.toggleSpAsDelegatedAgent({
// bucketName: 'foo',
// operator: address,
// });

const updateBucketTx = await client.bucket.updateBucketInfo({
bucketName: bucketName,
operator: address,
Expand Down
21 changes: 21 additions & 0 deletions packages/js-sdk/src/api/bucket.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MsgToggleSPAsDelegatedAgentSDKTypeEIP712 } from '@/messages/greenfield/storage/MsgToggleSpAsDelegatedAgent';
import { assertAuthType, assertStringRequire } from '@/utils/asserts/params';
import { UInt64Value } from '@bnb-chain/greenfield-cosmos-types/greenfield/common/wrapper';
import {
Expand All @@ -22,6 +23,7 @@ import {
MsgDeletePolicy,
MsgMigrateBucket,
MsgPutPolicy,
MsgToggleSPAsDelegatedAgent,
MsgUpdateBucketInfo,
} from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/tx';
import { PickVGFStrategy } from '@bnb-chain/greenfield-cosmos-types/greenfield/virtualgroup/common';
Expand All @@ -35,6 +37,7 @@ import {
MsgCreateBucketTypeUrl,
MsgDeleteBucketTypeUrl,
MsgMigrateBucketTypeUrl,
MsgToggleSPAsDelegatedAgentTypeUrl,
MsgUpdateBucketInfoTypeUrl,
newBucketGRN,
TxResponse,
Expand Down Expand Up @@ -112,6 +115,8 @@ export interface IBucket {
principalType: keyof typeof PrincipalType,
): Promise<TxResponse>;

toggleSpAsDelegatedAgent(msg: MsgToggleSPAsDelegatedAgent): Promise<TxResponse>;

getBucketMeta(params: GetBucketMetaRequest): Promise<SpResponse<GetBucketMetaResponse>>;

getBucketPolicy(request: QueryPolicyForAccountRequest): Promise<QueryPolicyForAccountResponse>;
Expand Down Expand Up @@ -248,6 +253,22 @@ export class Bucket implements IBucket {
);
}

public async toggleSpAsDelegatedAgent(msg: MsgToggleSPAsDelegatedAgent) {
const { bucketInfo } = await this.headBucket(msg.bucketName);

if (!bucketInfo) {
throw new Error(`Bucket ${msg.bucketName} not found`);
}

return await this.txClient.tx(
MsgToggleSPAsDelegatedAgentTypeUrl,
msg.operator,
MsgToggleSPAsDelegatedAgentSDKTypeEIP712,
MsgToggleSPAsDelegatedAgent.toSDK(msg),
MsgToggleSPAsDelegatedAgent.encode(msg).finish(),
);
}

public async headBucket(bucketName: string) {
const rpc = await this.queryClient.getStorageQueryClient();
return await rpc.HeadBucket({
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 @@ -20,6 +20,7 @@ export const MsgDeleteGroupTypeUrl = '/greenfield.storage.MsgDeleteGroup';
export const MsgDeleteObjectTypeUrl = '/greenfield.storage.MsgDeleteObject';
export const MsgDeletePolicyTypeUrl = '/greenfield.storage.MsgDeletePolicy';
export const MsgSetTagTypeUrl = '/greenfield.storage.MsgSetTag';
export const MsgToggleSPAsDelegatedAgentTypeUrl = '/greenfield.storage.MsgToggleSPAsDelegatedAgent';
export const MsgLeaveGroupTypeUrl = '/greenfield.storage.MsgLeaveGroup';
export const MsgMirrorBucketTypeUrl = '/greenfield.storage.MsgMirrorBucket';
export const MsgMirrorGroupTypeUrl = '/greenfield.storage.MsgMirrorGroup';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const MsgToggleSPAsDelegatedAgentSDKTypeEIP712 = {
Msg1: [
{
name: 'bucket_name',
type: 'string',
},
{
name: 'operator',
type: 'string',
},
{
name: 'type',
type: 'string',
},
],
};

0 comments on commit a056afa

Please sign in to comment.