Skip to content

Commit

Permalink
fix: Tag compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
rrr523 committed Dec 21, 2023
1 parent 7a652ff commit 02cb24c
Show file tree
Hide file tree
Showing 19 changed files with 26 additions and 390 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-steaks-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

fix: Tag Compatibility
14 changes: 0 additions & 14 deletions examples/nextjs/src/components/bucket/create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,6 @@ export const CreateBucket = () => {
primarySpAddress: spInfo.primarySpAddress,
},
paymentAddress: address,
// empty tags
tags: {
tags: [],
},

// with tags:
// tags: {
// tags: [
// {
// key: 'test',
// value: 'test',
// },
// ],
// },
},
{
// type: 'ECDSA',
Expand Down
47 changes: 1 addition & 46 deletions examples/nextjs/src/components/group/create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ export const CreateGroup = () => {
creator: address,
groupName: createGroupInfo.groupName,
extra: 'extra info',
tags: {
tags: [],
},
});

const simulateInfo = await createGroupTx.simulate({
Expand Down Expand Up @@ -61,49 +58,7 @@ export const CreateGroup = () => {
console.log(res);
}}
>
create group with empty tags
</button>

<button
onClick={async () => {
if (!address) return;

const createGroupTx = await client.group.createGroup({
creator: address,
groupName: createGroupInfo.groupName,
extra: 'extra info',
tags: {
tags: [
{
key: 'key',
value: 'value',
},
],
},
});

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

console.log(simulateInfo);

const res = await createGroupTx.broadcast({
denom: 'BNB',
gasLimit: Number(simulateInfo.gasLimit),
gasPrice: simulateInfo.gasPrice,
payer: address,
granter: '',
});

if (res.code === 0) {
alert('create group success');
}

console.log(res);
}}
>
create group with tags
create group
</button>
</div>
);
Expand Down
39 changes: 0 additions & 39 deletions examples/nextjs/src/components/group/update/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,45 +120,6 @@ export const GroupUpdate = () => {
>
updateGroupExtra
</button>
<br />
<button
onClick={async () => {
if (!address) return;

const resource = GRNToString(newGroupGRN(address, groupName));

const updateGroupTx = await client.storage.setTag({
operator: address,
resource,
tags: {
tags: [
{
key: 'x',
value: 'xx',
},
],
},
});

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

console.log(simulateInfo);

const res = await updateGroupTx.broadcast({
denom: 'BNB',
gasLimit: Number(simulateInfo.gasLimit),
gasPrice: simulateInfo.gasPrice,
payer: address,
granter: '',
});

console.log('res', res);
}}
>
update group tags
</button>
</div>
);
};
24 changes: 0 additions & 24 deletions examples/nextjs/src/components/object/create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,6 @@ export const CreateObject = () => {
redundancyType: 'REDUNDANCY_EC_TYPE',
contentLength: fileBytes.byteLength,
expectCheckSums: expectCheckSums,
// empty tags
// tags: {
// tags: [],
// },
tags: {
tags: [
{
key: 'test',
value: 'test',
},
],
},
},
{
type: 'EDDSA',
Expand Down Expand Up @@ -180,18 +168,6 @@ export const CreateObject = () => {
bucketName: createObjectInfo.bucketName,
objectName: createObjectInfo.objectName + '/',
creator: address,
// empty tags
// tags: {
// tags: [],
// },
tags: {
tags: [
{
key: 'test',
value: 'test',
},
],
},
},
{
type: 'EDDSA',
Expand Down
2 changes: 1 addition & 1 deletion packages/js-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
]
},
"dependencies": {
"@bnb-chain/greenfield-cosmos-types": "0.4.0-alpha.25",
"@bnb-chain/greenfield-cosmos-types": "0.4.0-alpha.23",
"@bnb-chain/greenfield-zk-crypto": "workspace:*",
"@cosmjs/proto-signing": "^0.32.0",
"@cosmjs/stargate": "^0.32.0",
Expand Down
10 changes: 1 addition & 9 deletions packages/js-sdk/src/api/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
MsgPutPolicy,
MsgUpdateBucketInfo,
} from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/tx';
import { ResourceTags } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/types';
import { bytesFromBase64 } from '@bnb-chain/greenfield-cosmos-types/helpers';
import { Headers } from 'cross-fetch';
import { bytesToUtf8, hexToBytes } from 'ethereum-cryptography/utils';
Expand Down Expand Up @@ -69,7 +68,7 @@ import {
import { AuthType, SpClient } from '../clients/spclient/spClient';
import { TxClient } from '../clients/txClient';
import { METHOD_GET, NORMAL_ERROR_CODE } from '../constants/http';
import { getMsgCreateBucketSDKTypeEIP712 } from '../messages/greenfield/storage/MsgCreateBucket';
import { MsgCreateBucketSDKTypeEIP712 } from '../messages/greenfield/storage/MsgCreateBucket';
import { MsgDeleteBucketSDKTypeEIP712 } from '../messages/greenfield/storage/MsgDeleteBucket';
import { MsgMigrateBucketSDKTypeEIP712 } from '../messages/greenfield/storage/MsgMigrateBucket';
import { MsgUpdateBucketInfoSDKTypeEIP712 } from '../messages/greenfield/storage/MsgUpdateBucketInfo';
Expand Down Expand Up @@ -213,7 +212,6 @@ export class Bucket implements IBucket {
spInfo,
duration,
paymentAddress,
tags,
} = params;

try {
Expand Down Expand Up @@ -242,7 +240,6 @@ export class Bucket implements IBucket {
},
charged_read_quota: chargedReadQuota,
payment_address: paymentAddress,
tags: tags,
});

const signHeaders = await this.spClient.signHeaders(reqMeta, authType);
Expand Down Expand Up @@ -274,10 +271,6 @@ export class Bucket implements IBucket {
}

private async createBucketTx(msg: MsgCreateBucket, signedMsg: CreateBucketApprovalResponse) {
const isTagsEmpty = msg?.tags?.tags?.length === 0;

const MsgCreateBucketSDKTypeEIP712 = getMsgCreateBucketSDKTypeEIP712(isTagsEmpty);

return await this.txClient.tx(
MsgCreateBucketTypeUrl,
msg.creator,
Expand Down Expand Up @@ -314,7 +307,6 @@ export class Bucket implements IBucket {
},
chargedReadQuota: Long.fromString(signedMsg.charged_read_quota),
paymentAddress: signedMsg.payment_address,
tags: ResourceTags.fromJSON(signedMsg.tags),
};

return await this.createBucketTx(msg, signedMsg);
Expand Down
6 changes: 1 addition & 5 deletions packages/js-sdk/src/api/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
} from '..';
import { RpcQueryClient } from '../clients/queryclient';
import { TxClient } from '../clients/txClient';
import { getMsgCreateGroupSDKTypeWithTagEIP712 } from '../messages/greenfield/storage/MsgCreateGroup';
import { MsgCreateGroupSDKTypeEIP712 } from '../messages/greenfield/storage/MsgCreateGroup';
import { MsgDeleteGroupSDKTypeEIP712 } from '../messages/greenfield/storage/MsgDeleteGroup';
import { MsgLeaveGroupSDKTypeEIP712 } from '../messages/greenfield/storage/MsgLeaveGroup';
import { MsgUpdateGroupExtraSDKTypeEIP712 } from '../messages/greenfield/storage/MsgUpdateGroupExtra';
Expand Down Expand Up @@ -111,10 +111,6 @@ export class Group implements IGroup {
private queryClient: RpcQueryClient = container.resolve(RpcQueryClient);

public async createGroup(msg: MsgCreateGroup) {
const isTagsEmpty = msg?.tags?.tags?.length === 0;

const MsgCreateGroupSDKTypeEIP712 = getMsgCreateGroupSDKTypeWithTagEIP712(isTagsEmpty);

return await this.txClient.tx(
MsgCreateGroupTypeUrl,
msg.creator,
Expand Down
11 changes: 1 addition & 10 deletions packages/js-sdk/src/api/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { getPutObjectMetaInfo } from '../clients/spclient/spApis/putObject';
import { TxClient } from '../clients/txClient';
import { METHOD_GET, NORMAL_ERROR_CODE } from '../constants/http';
import { MsgCancelCreateObjectSDKTypeEIP712 } from '../messages/greenfield/storage/MsgCancelCreateObject';
import { getMsgCreateObjectSDKTypeEIP712 } from '../messages/greenfield/storage/MsgCreateObject';
import { MsgCreateObjectSDKTypeEIP712 } from '../messages/greenfield/storage/MsgCreateObject';
import { MsgDeleteObjectSDKTypeEIP712 } from '../messages/greenfield/storage/MsgDeleteObject';
import { MsgUpdateObjectInfoSDKTypeEIP712 } from '../messages/greenfield/storage/MsgUpdateObjectInfo';
import { signSignatureByEddsa } from '../offchainauth';
Expand Down Expand Up @@ -88,7 +88,6 @@ import {
} from '../utils/s3';
import { Sp } from './sp';
import { Storage } from './storage';
import { ResourceTags } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/types';

export interface IObject {
getCreateObjectApproval(
Expand Down Expand Up @@ -198,7 +197,6 @@ export class Objects implements IObject {
redundancyType = 'REDUNDANCY_EC_TYPE',
contentLength,
expectCheckSums,
tags,
} = params;

try {
Expand Down Expand Up @@ -231,7 +229,6 @@ export class Objects implements IObject {
},
redundancy_type: redundancyType,
visibility,
tags,
});

const signHeaders = await this.spClient.signHeaders(reqMeta, authType);
Expand Down Expand Up @@ -271,10 +268,6 @@ export class Objects implements IObject {
}

private async createObjectTx(msg: MsgCreateObject, signedMsg: CreateObjectApprovalResponse) {
const isTagsEmpty = msg?.tags?.tags?.length === 0;

const MsgCreateObjectSDKTypeEIP712 = getMsgCreateObjectSDKTypeEIP712(isTagsEmpty);

return await this.txClient.tx(
MsgCreateObjectTypeUrl,
msg.creator,
Expand Down Expand Up @@ -313,7 +306,6 @@ export class Objects implements IObject {
sig: bytesFromBase64(signedMsg.primary_sp_approval.sig || ''),
globalVirtualGroupFamilyId: signedMsg.primary_sp_approval.global_virtual_group_family_id,
},
tags: ResourceTags.fromJSON(signedMsg.tags),
};

return await this.createObjectTx(msg, signedMsg);
Expand Down Expand Up @@ -629,7 +621,6 @@ export class Objects implements IObject {
'47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=',
],
creator: getApprovalParams.creator,
tags: getApprovalParams.tags,
};

return this.createObject(params, authType);
Expand Down
26 changes: 1 addition & 25 deletions packages/js-sdk/src/api/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,10 @@ import {
import {
MsgDeletePolicy,
MsgPutPolicy,
MsgSetTag,
} from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/tx';
import { container, delay, inject, injectable } from 'tsyringe';
import {
fromTimestamp,
MsgDeletePolicyTypeUrl,
MsgPutPolicyTypeUrl,
MsgSetTagTypeUrl,
TxResponse,
} from '..';
import { fromTimestamp, MsgDeletePolicyTypeUrl, MsgPutPolicyTypeUrl, TxResponse } from '..';
import { RpcQueryClient } from '../clients/queryclient';
import { getMsgSetTagSDKTypeEIP712 } from '@/messages/greenfield/storage/MsgSetTag';

export interface IStorage {
params(): Promise<QueryParamsResponse>;
Expand All @@ -40,8 +32,6 @@ export interface IStorage {

deletePolicy(msg: MsgDeletePolicy): Promise<TxResponse>;

setTag(msg: MsgSetTag): Promise<TxResponse>;

getPolicyForGroup(request: QueryPolicyForGroupRequest): Promise<QueryPolicyForGroupResponse>;

getQueryPolicyForAccount(
Expand Down Expand Up @@ -107,20 +97,6 @@ export class Storage implements IStorage {
);
}

public async setTag(msg: MsgSetTag) {
const isTagsEmpty = msg?.tags?.tags?.length === 0;

const MsgSetTagSDKTypeEIP712 = getMsgSetTagSDKTypeEIP712(isTagsEmpty);

return await this.txClient.tx(
MsgSetTagTypeUrl,
msg.operator,
MsgSetTagSDKTypeEIP712,
MsgSetTag.toSDK(msg),
MsgSetTag.encode(msg).finish(),
);
}

public async getPolicyForGroup(request: QueryPolicyForGroupRequest) {
const rpc = await this.queryClient.getStorageQueryClient();
return await rpc.QueryPolicyForGroup(request);
Expand Down
1 change: 0 additions & 1 deletion packages/js-sdk/src/constants/typeUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const MsgDeleteBucketTypeUrl = '/greenfield.storage.MsgDeleteBucket';
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 MsgLeaveGroupTypeUrl = '/greenfield.storage.MsgLeaveGroup';
export const MsgMirrorBucketTypeUrl = '/greenfield.storage.MsgMirrorBucket';
export const MsgMirrorGroupTypeUrl = '/greenfield.storage.MsgMirrorGroup';
Expand Down
Loading

0 comments on commit 02cb24c

Please sign in to comment.