Skip to content

Commit

Permalink
docs: Bucket Api (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
rrr523 authored Dec 15, 2023
1 parent 8626132 commit d20681d
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 33 deletions.
122 changes: 105 additions & 17 deletions doc-site/docs/api/bucket.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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"

<Tabs groupId="example">
<TabItem value="Browser" label="Browser">

```jsx
const tx = await client.bucket.createBucket(
{
bucketName: 'bucket_name',
Expand All @@ -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
);
```

</TabItem>
<TabItem value="Nodejs" label="Nodejs">

```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
);
```

</TabItem>
</Tabs>

## deleteBucket <ApiTypes type="Tx" />

Send DeleteBucket msg to greenfield chain and return txn hash.
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
});
Expand All @@ -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)),
Expand All @@ -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(
<Tabs groupId="example">
<TabItem value="Browser" label="Browser">

```jsx
const tx = await client.bucket.getBucketReadQuota(
{
bucketName,
},
// highlight-start
{
type: 'EDDSA',
seed: offChainData.seedString,
domain: window.location.origin,
address,
},
// highlight-end
);
```

</TabItem>
<TabItem value="Nodejs" label="Nodejs">

```js
const tx = await client.bucket.getBucketReadQuota(
{
bucketName,
},
// highlight-start
{
type: 'ECDSA',
privateKey: ACCOUNT_PRIVATEKEY,
},
// highlight-end
);
```

</TabItem>
</Tabs>

## headBucket <ApiTypes type="Query" />

query the bucketInfo on chain, return the bucket info if exists.
Expand All @@ -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);
```

Expand All @@ -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);
```

Expand All @@ -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);
```

Expand All @@ -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(
<Tabs groupId="example">
<TabItem value="Browser" label="Browser">

```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
);
```

</TabItem>
<TabItem value="Nodejs" label="Nodejs">

```js
const tx = await client.bucket.listBucketReadRecords(
{
bucketName,
startTimeStamp,
endTimeStamp,
maxRecords: 1000,
},
// highlight-start
{
type: 'ECDSA',
privateKey: ACCOUNT_PRIVATEKEY,
},
// highlight-end
);
```

</TabItem>
</Tabs>

## listBuckets <ApiTypes type="Storage Provider" />

Lists the bucket info of the user.
Expand All @@ -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,
});
Expand All @@ -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'],
});
Expand All @@ -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...',
});
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions doc-site/docs/api/object.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Send create empty object txn to greenfield chain.
| creator | the creator of object |
| authType | [AuthType](/client/sp-client#authtype) |

<Tabs>
<Tabs groupId="example">
<TabItem value="Browser" label="Browser">

```jsx
Expand Down Expand Up @@ -92,7 +92,7 @@ Get approval of creating object and send createObject txn to greenfield chain.
| contentLength | file content length |
| expectCheckSums | file's expectCheckSums |

<Tabs>
<Tabs groupId="example">
<TabItem value="Browser" label="Browser">

```jsx
Expand Down Expand Up @@ -201,7 +201,7 @@ Download s3 object payload and return the related object info.
| bucketName | bucket name |
| objectName | object name |

<Tabs>
<Tabs groupId="example">
<TabItem value="Browser" label="Browser">

```jsx
Expand Down Expand Up @@ -411,7 +411,7 @@ Uploading the object to bucket.
| txnHash | [createObject](#createobject) 's hash |
| authType | [AuthType](/client/sp-client#authtype) |

<Tabs>
<Tabs groupId="example">
<TabItem value="Browser" label="Browser">

```jsx
Expand Down
16 changes: 4 additions & 12 deletions doc-site/docs/client/tx-client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
```
:::

</TabItem>
<TabItem value="Nodejs" label="Nodejs">
Expand All @@ -92,6 +83,7 @@ const broadcastRes = await transferTx.broadcast({
// highlight-end
});
```

</TabItem>
</Tabs>

Expand Down

0 comments on commit d20681d

Please sign in to comment.