From d20681def866992bafd30e008c8c036ad3e4696e Mon Sep 17 00:00:00 2001
From: rk <59029880+rrr523@users.noreply.github.com>
Date: Fri, 15 Dec 2023 22:00:01 +0800
Subject: [PATCH] docs: Bucket Api (#421)
---
doc-site/docs/api/bucket.mdx | 122 +++++++++++++++++++++++++----
doc-site/docs/api/object.mdx | 8 +-
doc-site/docs/client/tx-client.mdx | 16 +---
3 files changed, 113 insertions(+), 33 deletions(-)
diff --git a/doc-site/docs/api/bucket.mdx b/doc-site/docs/api/bucket.mdx
index b3e7a457..436a36bc 100644
--- a/doc-site/docs/api/bucket.mdx
+++ b/doc-site/docs/api/bucket.mdx
@@ -3,6 +3,8 @@ id: bucket
title: 'Bucket'
---
+import Tabs from '@theme/Tabs';
+import TabItem from '@theme/TabItem';
import ApiTypes from '../../src/components/snippers/api-types.tsx';
import Tx from '../../src/components/snippers/tx.mdx';
@@ -21,7 +23,11 @@ for creating bucket and sends the createBucket transaction to the Greenfield.
| paymentAddress | payment address |
| authType | [AuthType](/client/sp-client#authtype) |
-```jsx title="example"
+
+
+
+
+```jsx
const tx = await client.bucket.createBucket(
{
bucketName: 'bucket_name',
@@ -33,15 +39,44 @@ const tx = await client.bucket.createBucket(
},
paymentAddress: address,
},
+ // highlight-start
{
type: 'EDDSA',
domain: window.location.origin,
seed: offChainData.seedString,
address,
},
+ // highlight-end
+);
+```
+
+
+
+
+```js
+const createBucketTx = await client.bucket.createBucket(
+ {
+ bucketName: bucketName,
+ creator: ACCOUNT_ADDRESS,
+ visibility: 'VISIBILITY_TYPE_PUBLIC_READ',
+ chargedReadQuota: '0',
+ spInfo: {
+ primarySpAddress: spInfo.primarySpAddress,
+ },
+ paymentAddress: ACCOUNT_ADDRESS,
+ },
+ // highlight-start
+ {
+ type: 'ECDSA',
+ privateKey: ACCOUNT_PRIVATEKEY,
+ },
+ // highlight-end
);
```
+
+
+
## deleteBucket
Send DeleteBucket msg to greenfield chain and return txn hash.
@@ -51,7 +86,7 @@ Send DeleteBucket msg to greenfield chain and return txn hash.
| bucketName | The name of the bucket to be deleted |
| operator | operator account address |
-```jsx title="example"
+```jsx title="Browser | Nodejs"
const tx = await client.bucket.deleteBucket({
bucketName: bucketName,
operator: address,
@@ -71,7 +106,7 @@ Delete the bucket policy of the principal.
| principalAddr | Principal define the roles that can grant permissions |
| principalType | PrincipalType refers to the identity type of system users or entities. |
-```jsx title="example"
+```jsx title="Browser | Nodejs"
const tx = await client.bucket.deleteBucketPolicy(
address,
bucketName,
@@ -90,7 +125,7 @@ This API is used to get bucket meta by bucket name.
| ---------- | ----------- |
| bucketName | bucket name |
-```jsx title="example"
+```jsx title="Browser | Nodejs"
const bucketInfo = await client.bucket.getBucketMeta({
bucketName,
});
@@ -100,7 +135,7 @@ const bucketInfo = await client.bucket.getBucketMeta({
Get the bucket policy info of the user specified by principalAddr.
-```jsx title="example"
+```jsx title="Browser | Nodejs"
import { GRNToString, newBucketGRN } from '@bnb-chain/greenfield-js-sdk';
await client.bucket.getBucketPolicy({
resource: GRNToString(newBucketGRN(bucketName)),
@@ -117,20 +152,45 @@ Query the quota info of the specific bucket of current month.
| bucketName | bucket name |
| authType | [AuthType](/client/sp-client#authtype) |
-```jsx title="example"
-await client.bucket.getBucketReadQuota(
+
+
+
+```jsx
+const tx = await client.bucket.getBucketReadQuota(
{
bucketName,
},
+ // highlight-start
{
type: 'EDDSA',
seed: offChainData.seedString,
domain: window.location.origin,
address,
},
+ // highlight-end
+);
+```
+
+
+
+
+```js
+const tx = await client.bucket.getBucketReadQuota(
+ {
+ bucketName,
+ },
+ // highlight-start
+ {
+ type: 'ECDSA',
+ privateKey: ACCOUNT_PRIVATEKEY,
+ },
+ // highlight-end
);
```
+
+
+
## headBucket
query the bucketInfo on chain, return the bucket info if exists.
@@ -139,7 +199,7 @@ query the bucketInfo on chain, return the bucket info if exists.
| ---------- | ----------- |
| bucketName | bucket name |
-```jsx title="example"
+```jsx title="Browser | Nodejs"
const bucketInfo = await client.bucket.headBucket(bucketName);
```
@@ -149,7 +209,7 @@ const bucketInfo = await client.bucket.headBucket(bucketName);
| -------- | ----------- |
| bucketId | bucket id |
-```jsx title="example"
+```jsx title="Browser | Nodejs"
const bucketInfo = await client.bucket.headBucketById(bucketId);
```
@@ -161,7 +221,7 @@ Queries a bucket extra info (with gvg bindings and price time) with specify name
| ---------- | ----------- |
| bucketName | bucket name |
-```jsx title="example"
+```jsx title="Browser | Nodejs"
const bucketInfo = await client.bucket.headBucketExtra(bucketName);
```
@@ -176,23 +236,51 @@ List the download record info of the specific bucket of the current month.
| bucketName | bucket name |
| authType | [AuthType](/client/sp-client#authtype) |
-```jsx title="example"
-await client.bucket.listBucketReadRecords(
+
+
+
+```jsx
+const tx = await client.bucket.listBucketReadRecords(
{
bucketName,
startTimeStamp,
endTimeStamp,
maxRecords: 1000,
},
+ // highlight-start
{
type: 'EDDSA',
domain: window.location.origin,
seed: offChainData.seedString,
address,
},
+ // highlight-end
+);
+```
+
+
+
+
+```js
+const tx = await client.bucket.listBucketReadRecords(
+ {
+ bucketName,
+ startTimeStamp,
+ endTimeStamp,
+ maxRecords: 1000,
+ },
+ // highlight-start
+ {
+ type: 'ECDSA',
+ privateKey: ACCOUNT_PRIVATEKEY,
+ },
+ // highlight-end
);
```
+
+
+
## listBuckets
Lists the bucket info of the user.
@@ -201,7 +289,7 @@ Lists the bucket info of the user.
| ------- | ------------ |
| address | user account |
-```jsx title="example"
+```jsx title="Browser | Nodejs"
const res = await client.bucket.listBuckets({
address,
});
@@ -215,7 +303,7 @@ Lists the bucket info of the user.
| ------ | ---------------- |
| ids | bucket ids array |
-```jsx title="example"
+```jsx title="Browser | Nodejs"
await client.bucket.listBucketsByIds({
ids: ['1', '2'],
});
@@ -229,7 +317,7 @@ List bucket info by payment account.
| -------------- | ----------------------- |
| paymentAccount | payment account address |
-```jsx title="example"
+```jsx title="Browser | Nodejs"
const res = await client.bucket.listBucketsByPaymentAccount({
paymentAccount: '0x00...',
});
@@ -245,7 +333,7 @@ Apply bucket policy to the principal, return the txn hash.
| statements | Policies outline the specific details of permissions, including the Effect, ActionList, and Resources. |
| principal | Indicates the marshaled principal content of greenfield permission types, users can generate it by NewPrincipalWithAccount or NewPrincipalWithGroupId method. |
-```jsx title="example"
+```jsx title="Browser | Nodejs"
import { GRNToString, newBucketGRN, PermissionTypes } from '@bnb-chain/greenfield-js-sdk';
const statement: PermissionTypes.Statement = {
effect: PermissionTypes.Effect.EFFECT_ALLOW,
@@ -277,7 +365,7 @@ the MsgUpdateBucketInfo msg to greenfield to update the meta.
| paymentAddress | payment address |
| chargedReadQuota | defines the traffic quota that you read from primary sp |
-```jsx title="example"
+```jsx title="Browser | Nodejs"
await client.bucket.updateBucketInfo({
bucketName: bucketName,
operator: address,
diff --git a/doc-site/docs/api/object.mdx b/doc-site/docs/api/object.mdx
index 79947cca..a6ef0e40 100644
--- a/doc-site/docs/api/object.mdx
+++ b/doc-site/docs/api/object.mdx
@@ -31,7 +31,7 @@ Send create empty object txn to greenfield chain.
| creator | the creator of object |
| authType | [AuthType](/client/sp-client#authtype) |
-
+
```jsx
@@ -92,7 +92,7 @@ Get approval of creating object and send createObject txn to greenfield chain.
| contentLength | file content length |
| expectCheckSums | file's expectCheckSums |
-
+
```jsx
@@ -201,7 +201,7 @@ Download s3 object payload and return the related object info.
| bucketName | bucket name |
| objectName | object name |
-
+
```jsx
@@ -411,7 +411,7 @@ Uploading the object to bucket.
| txnHash | [createObject](#createobject) 's hash |
| authType | [AuthType](/client/sp-client#authtype) |
-
+
```jsx
diff --git a/doc-site/docs/client/tx-client.mdx b/doc-site/docs/client/tx-client.mdx
index bb55f0b7..7bd9e843 100644
--- a/doc-site/docs/client/tx-client.mdx
+++ b/doc-site/docs/client/tx-client.mdx
@@ -54,26 +54,17 @@ const broadcastRes = await transferTx.broadcast({
gasPrice: simulateInfo.gasPrice,
payer: '0x0000000000000000000000000000000000000001',
granter: '',
-});
-```
-
-:::tip
-
-If you want to use others wallet, you can set `signTypedDataCallback`:
-
-```js
-// trustwallet:
-const broadcastRes = await transferTx.broadcast({
- // ...
+ // highlight-start
+ // If you want to use others wallet(such as trustwallet), you can set `signTypedDataCallback`:
signTypedDataCallback: async (addr: string, message: string) => {
return await window.trustwallet.request({
method: 'eth_signTypedData_v4',
params: [addr, message],
});
},
+ // highlight-end
});
```
-:::
@@ -92,6 +83,7 @@ const broadcastRes = await transferTx.broadcast({
// highlight-end
});
```
+