From 541a7f7345f89da675b4407b2c7967fa38a1db47 Mon Sep 17 00:00:00 2001 From: rrr523 Date: Tue, 26 Dec 2023 10:49:18 +0800 Subject: [PATCH] feat: Sp Api types --- .changeset/chatty-steaks-joke.md | 5 +++ .../src/components/bucket/create/index.tsx | 25 ++++++++++- packages/js-sdk/src/types/sp/Common.ts | 42 +++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 .changeset/chatty-steaks-joke.md diff --git a/.changeset/chatty-steaks-joke.md b/.changeset/chatty-steaks-joke.md new file mode 100644 index 00000000..58024574 --- /dev/null +++ b/.changeset/chatty-steaks-joke.md @@ -0,0 +1,5 @@ +--- +'@bnb-chain/greenfield-js-sdk': patch +--- + +feat: Sp Api Types diff --git a/examples/nextjs/src/components/bucket/create/index.tsx b/examples/nextjs/src/components/bucket/create/index.tsx index 62d31c84..5254db43 100644 --- a/examples/nextjs/src/components/bucket/create/index.tsx +++ b/examples/nextjs/src/components/bucket/create/index.tsx @@ -1,5 +1,7 @@ import { client, selectSp } from '@/client'; import { getOffchainAuthKeys } from '@/utils/offchainAuth'; +import { GRNToString, newBucketGRN, newGroupGRN } from '@bnb-chain/greenfield-js-sdk'; +import { add } from 'lodash'; import { useState } from 'react'; import { useAccount } from 'wagmi'; @@ -58,13 +60,32 @@ export const CreateBucket = () => { }, ); - const simulateInfo = await createBucketTx.simulate({ + const setTagTx = await client.storage.setTag({ + operator: address, + resource: GRNToString(newBucketGRN(createBucketInfo.bucketName)), + tags: { + tags: [ + { + key: 'x', + value: 'xx', + }, + { + key: 'y', + value: 'yy', + }, + ], + }, + }); + + const tx = await client.txClient.multiTx([createBucketTx, setTagTx]); + + const simulateInfo = await tx.simulate({ denom: 'BNB', }); console.log('simulateInfo', simulateInfo); - const res = await createBucketTx.broadcast({ + const res = await tx.broadcast({ denom: 'BNB', gasLimit: Number(simulateInfo?.gasLimit), gasPrice: simulateInfo?.gasPrice || '5000000000', diff --git a/packages/js-sdk/src/types/sp/Common.ts b/packages/js-sdk/src/types/sp/Common.ts index 644b81a3..a8d083c3 100644 --- a/packages/js-sdk/src/types/sp/Common.ts +++ b/packages/js-sdk/src/types/sp/Common.ts @@ -42,6 +42,12 @@ export interface BucketInfo { PaymentAddress: string; SourceType: number; Visibility: number; + Tags: { + Tags: { + Key: string; + Value: string; + }[]; + }; } export interface StreamRecord { @@ -85,9 +91,20 @@ export interface ObjectInfo { RedundancyType: number; SourceType: number; Visibility: number; + Tags: { + Tags: { + Key: string; + Value: string; + }[]; + }; } export function formatBucketInfo(o: BucketInfo): BucketInfo { + let tags = o.Tags.Tags || []; + if (!Array.isArray(tags)) { + tags = [tags]; + } + return { ...o, // PrimarySpId: Number(item.BucketInfo.PrimarySpId), @@ -97,10 +114,18 @@ export function formatBucketInfo(o: BucketInfo): BucketInfo { GlobalVirtualGroupFamilyId: Number(o.GlobalVirtualGroupFamilyId), SourceType: Number(o.SourceType), Visibility: Number(o.Visibility), + Tags: { + Tags: tags, + }, }; } export function formatObjectInfo(o: ObjectInfo): ObjectInfo { + let tags = o.Tags.Tags || []; + if (!Array.isArray(tags)) { + tags = [tags]; + } + return { ...o, CreateAt: Number(o.CreateAt), @@ -111,6 +136,9 @@ export function formatObjectInfo(o: ObjectInfo): ObjectInfo { RedundancyType: Number(o.RedundancyType), SourceType: Number(o.SourceType), Visibility: Number(o.Visibility), + Tags: { + Tags: tags, + }, }; } @@ -140,13 +168,27 @@ export interface GroupInfo { SourceType: number; Id: number; Extra: string; + Tags: { + Tags: { + Key: string; + Value: string; + }[]; + }; } export function formatGroupInfo(o: GroupInfo): GroupInfo { + let tags = o.Tags.Tags || []; + if (!Array.isArray(tags)) { + tags = [tags]; + } + return { ...o, SourceType: Number(o.SourceType), Id: Number(o.Id), + Tags: { + Tags: tags, + }, }; }