Skip to content

Commit

Permalink
Feat/new tag (#461)
Browse files Browse the repository at this point in the history
* Fix/sp tag type (#444)

* fix: Sp types

* fix: Sp types

(cherry picked from commit eb75e4d)

* fix: Tag compatibility (#443)

(cherry picked from commit 7a2e9d2)

* feat: Upgrade cosmos type to 0.4.0 alpha 30

* chore: Update feegranet example

* feat: Add SetTag API
  • Loading branch information
rrr523 authored Dec 25, 2023
1 parent a70b231 commit 865be47
Show file tree
Hide file tree
Showing 22 changed files with 814 additions and 621 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-melons-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': minor
---

feat: Add SetTag API
5 changes: 5 additions & 0 deletions .changeset/twelve-mice-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

feat: Upgrade cosmos types to 0.4.0-alpha.30
2 changes: 1 addition & 1 deletion examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"lint": "next lint"
},
"dependencies": {
"@bnb-chain/greenfield-cosmos-types": "0.4.0-alpha.25",
"@bnb-chain/greenfield-cosmos-types": "0.4.0-alpha.30",
"@bnb-chain/greenfield-js-sdk": "workspace:*",
"@bnb-chain/reed-solomon": "workspace:*",
"@cosmjs/encoding": "^0.32.0",
Expand Down
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
11 changes: 5 additions & 6 deletions examples/nextjs/src/components/feegrant/createObj.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Wallet } from '@ethersproject/wallet';
import { ChangeEvent, useState } from 'react';
import { parseEther } from 'viem';
import { useAccount } from 'wagmi';
import { ReedSolomon } from '@bnb-chain/reed-solomon';

/**
* fee grant for creat object
Expand Down Expand Up @@ -124,11 +125,9 @@ export const CreateObj = () => {

console.log('temp account', granteeAddr, privateKey);

const rs = new ReedSolomon();
const fileBytes = await file.arrayBuffer();
const hashResult = await (window as any).FileHandle.getCheckSums(
new Uint8Array(fileBytes),
);
const { contentLength, expectCheckSums } = hashResult;
const expectCheckSums = rs.encode(new Uint8Array(fileBytes));

const createObjectTx = await client.object.createObject(
{
Expand All @@ -137,13 +136,13 @@ export const CreateObj = () => {
objectName: objectName,
visibility: 'VISIBILITY_TYPE_PUBLIC_READ',
redundancyType: 'REDUNDANCY_EC_TYPE',
contentLength,
contentLength: fileBytes.byteLength,
expectCheckSums,
fileType: file.type,
},
{
type: 'ECDSA',
privateKey: ACCOUNT_PRIVATEKEY,
privateKey: privateKey,
},
);

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
6 changes: 4 additions & 2 deletions examples/nextjs/src/components/group/update/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { client } from '@/client';
import { GRNToString, newBucketGRN, newGroupGRN, toTimestamp } from '@bnb-chain/greenfield-js-sdk';
import { GRNToString, newGroupGRN, toTimestamp } from '@bnb-chain/greenfield-js-sdk';
import { useState } from 'react';
import { zeroAddress } from 'viem';
import { useAccount } from 'wagmi';

export const GroupUpdate = () => {
Expand Down Expand Up @@ -130,6 +129,9 @@ export const GroupUpdate = () => {
const updateGroupTx = await client.storage.setTag({
operator: address,
resource,
// tags: {
// tags: [],
// },
tags: {
tags: [
{
Expand Down
12 changes: 0 additions & 12 deletions examples/nextjs/src/components/object/create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,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
6 changes: 0 additions & 6 deletions examples/nextjs/src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ export default function Document() {
<Main />
<NextScript />
</body>
<script src="https://unpkg.com/@bnb-chain/[email protected]/dist/browser/umd/index.js"></script>
<script
dangerouslySetInnerHTML={{
__html: `window.__PUBLIC_FILE_HANDLE_WASM_PATH__ = 'https://unpkg.com/@bnb-chain/[email protected]/dist/node/file-handle.wasm'`,
}}
></script>
</Html>
);
}
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.30",
"@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
11 changes: 7 additions & 4 deletions packages/js-sdk/src/api/crosschain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
QuerySendSequenceRequest,
QuerySendSequenceResponse,
} from '@bnb-chain/greenfield-cosmos-types/cosmos/crosschain/v1/query';
import { QueryInturnRelayerResponse } from '@bnb-chain/greenfield-cosmos-types/cosmos/oracle/v1/query';
import {
QueryInturnRelayerRequest,
QueryInturnRelayerResponse,
} from '@bnb-chain/greenfield-cosmos-types/cosmos/oracle/v1/query';
import { MsgClaim } from '@bnb-chain/greenfield-cosmos-types/cosmos/oracle/v1/tx';
import { QueryParamsResponse } from '@bnb-chain/greenfield-cosmos-types/greenfield/bridge/query';
import { MsgTransferOut } from '@bnb-chain/greenfield-cosmos-types/greenfield/bridge/tx';
Expand Down Expand Up @@ -58,7 +61,7 @@ export interface ICrossChain {
/**
* gets the in-turn relayer bls public key and its relay interval
*/
getInturnRelayer(): Promise<QueryInturnRelayerResponse>;
getInturnRelayer(request: QueryInturnRelayerRequest): Promise<QueryInturnRelayerResponse>;

getCrosschainPackage(
request: QueryCrossChainPackageRequest,
Expand Down Expand Up @@ -117,9 +120,9 @@ export class CrossChain implements ICrossChain {
return await rpc.ReceiveSequence(request);
}

public async getInturnRelayer() {
public async getInturnRelayer(request: QueryInturnRelayerRequest) {
const rpc = await this.queryClient.getOracleQueryClient();
return await rpc.InturnRelayer();
return await rpc.InturnRelayer(request);
}

public async getCrosschainPackage(request: QueryCrossChainPackageRequest) {
Expand Down
1 change: 1 addition & 0 deletions packages/js-sdk/src/api/feegrant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class FeeGrant implements IFeeGrant {
{
...MsgGrantAllowance.toSDK(grantAllowance),
allowance: {
// @ts-ignore
type: grantAllowance.allowance?.typeUrl,
value: base64FromBytes(arrayify('0x' + encodeToHex(JSON.stringify(marshal)))),
// TODO: @roshan next version should return hex string
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 @@ -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 Expand Up @@ -155,7 +151,7 @@ export class Group implements IGroup {
members_to_add: msg.membersToAdd.map((x) => {
return {
member: x.member,
expiration_time: fromTimestamp(x.expirationTime),
expiration_time: x.expirationTime && fromTimestamp(x.expirationTime),
};
}),
},
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
Loading

0 comments on commit 865be47

Please sign in to comment.