@tari-project/tarijs 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/TODO.md +2 -6
- package/docusaurus/tari-docs/docs/index.md +10 -5
- package/docusaurus/tari-docs/docs/installation.md +1 -1
- package/docusaurus/tari-docs/docs/providers/_category_.json +2 -2
- package/docusaurus/tari-docs/docs/providers/indexer-provider.md +32 -0
- package/docusaurus/tari-docs/docs/signers/_category_.json +8 -0
- package/docusaurus/tari-docs/docs/{providers → signers}/tari-universe.md +5 -5
- package/docusaurus/tari-docs/docs/{providers → signers}/wallet-connect.md +6 -7
- package/docusaurus/tari-docs/docs/{providers → signers}/wallet-daemon.md +7 -7
- package/docusaurus/tari-docs/docs/wallet/_category_.json +1 -1
- package/docusaurus/tari-docs/docs/wallet/list-substates.md +2 -3
- package/docusaurus/tari-docs/package.json +1 -1
- package/docusaurus/tari-docs/tsconfig.json +3 -1
- package/package.json +1 -1
- package/packages/builders/package.json +3 -3
- package/packages/builders/src/helpers/submitTransaction.ts +8 -8
- package/packages/builders/tsconfig.json +2 -4
- package/packages/indexer_provider/package.json +31 -0
- package/packages/indexer_provider/src/index.ts +2 -0
- package/packages/indexer_provider/src/provider.ts +105 -0
- package/packages/indexer_provider/src/transports/IndexerProviderClient.ts +144 -0
- package/packages/indexer_provider/src/transports/fetch.ts +46 -0
- package/packages/indexer_provider/src/transports/index.ts +3 -0
- package/packages/indexer_provider/src/transports/rpc.ts +19 -0
- package/packages/indexer_provider/tsconfig.json +22 -0
- package/packages/metamask_signer/moon.yml +55 -0
- package/packages/{metamask_provider → metamask_signer}/package.json +3 -3
- package/packages/{metamask_provider → metamask_signer}/src/index.ts +11 -6
- package/packages/metamask_signer/tsconfig.json +19 -0
- package/packages/tari_permissions/package.json +2 -3
- package/packages/tari_permissions/src/helpers.ts +33 -0
- package/packages/tari_permissions/src/index.ts +2 -1
- package/packages/tari_permissions/src/tari_permissions.ts +59 -42
- package/packages/tari_provider/package.json +1 -1
- package/packages/tari_provider/src/TariProvider.ts +6 -21
- package/packages/tari_provider/src/index.ts +1 -2
- package/packages/tari_provider/src/types.ts +36 -24
- package/packages/tari_signer/moon.yml +55 -0
- package/packages/tari_signer/package.json +28 -0
- package/packages/tari_signer/src/TariSigner.ts +35 -0
- package/packages/tari_signer/src/index.ts +2 -0
- package/packages/tari_signer/src/types.ts +84 -0
- package/packages/{metamask_provider → tari_signer}/tsconfig.json +0 -3
- package/packages/tari_universe/package.json +3 -3
- package/packages/tari_universe/src/index.ts +1 -1
- package/packages/tari_universe/src/{provider.ts → signer.ts} +29 -15
- package/packages/tari_universe/src/types.ts +15 -10
- package/packages/tari_universe/src/utils.ts +8 -8
- package/packages/tari_universe/tsconfig.json +2 -4
- package/packages/tarijs/integration-tests/wallet_daemon/json_rpc_provider.spec.ts +44 -44
- package/packages/tarijs/package.json +8 -6
- package/packages/tarijs/src/index.ts +28 -15
- package/packages/tarijs/tsconfig.json +7 -1
- package/packages/tarijs_types/package.json +1 -1
- package/packages/tarijs_types/src/helpers/index.ts +62 -0
- package/packages/tarijs_types/src/index.ts +12 -1
- package/packages/wallet_daemon/package.json +4 -3
- package/packages/wallet_daemon/src/index.ts +1 -1
- package/packages/wallet_daemon/src/{provider.ts → signer.ts} +45 -47
- package/packages/wallet_daemon/tsconfig.json +4 -1
- package/packages/walletconnect/package.json +4 -3
- package/packages/walletconnect/src/index.ts +42 -43
- package/packages/walletconnect/tsconfig.json +4 -1
- package/pnpm-workspace.yaml +3 -3
- package/tsconfig.json +8 -2
- /package/packages/{metamask_provider → indexer_provider}/moon.yml +0 -0
- /package/packages/{metamask_provider → metamask_signer}/src/utils.ts +0 -0
package/TODO.md
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
# TODO
|
|
2
2
|
|
|
3
|
-
- In the wallet provider interface:
|
|
4
|
-
- Full TypeScript class definitions for transaction requests (instructions, etc.).
|
|
5
|
-
- Common return types for both types of wallets.
|
|
6
|
-
- Implement `getSubstate` method for the Tari Wallet Daemon provider.
|
|
7
|
-
- Add account balance to `getAccountData` method for the Tari Wallet Daemon provider.
|
|
8
3
|
- For the example site:
|
|
9
|
-
- The button should indicate when a connection was established.
|
|
10
4
|
- The `TariConnect` button could be made into a reusable React component, ready to be imported by any web.
|
|
11
5
|
- Typescript-bindings
|
|
12
6
|
- [Types refactor and cleanup](https://github.com/tari-project/tari.js/issues/29)
|
|
7
|
+
- Other
|
|
8
|
+
- Configure prettier to not change entire file while saving
|
|
@@ -7,10 +7,15 @@ slug: /
|
|
|
7
7
|
|
|
8
8
|
This is the documentation of `tari.js` library, which enables interaction with Tari L2 (Ootle) wallet using TypeScript or JavaScript.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
### Note
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* Tari Metamask provider
|
|
12
|
+
> This documentation covers version **v0.5.0**.
|
|
13
|
+
>
|
|
14
|
+
> The biggest difference between version 0.4.0 and 0.5.0 is the _Signer_ and _Provider_ split. Learn more in the [Tari Provider](./providers/indexer-provider.md) and [Tari Signer](./signers/wallet-connect.md) sections.
|
|
16
15
|
|
|
16
|
+
At its core, `TariSigner` is an abstract interface implemented by multiple concrete signers. To access a wallet, you need to create an instance of one of these signers:
|
|
17
|
+
|
|
18
|
+
- [Tari WalletConnect signer](./signers/wallet-connect.md)
|
|
19
|
+
- [Tari Universe signer](./signers/tari-universe.md)
|
|
20
|
+
- [Tari Wallet Daemon signer](./signers/wallet-daemon.md)
|
|
21
|
+
- Tari Metamask signer
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"label": "Providers",
|
|
3
|
-
"position":
|
|
3
|
+
"position": 1,
|
|
4
4
|
"link": {
|
|
5
5
|
"type": "generated-index",
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "A Provider provides a connection to the blockchain, whch can be used to query its current state, but only the public one."
|
|
7
7
|
}
|
|
8
8
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 1
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Indexer Provider
|
|
6
|
+
|
|
7
|
+
This provider is designed to provide connection to the blockchain, whch can be used to query its current state, but only the public one.
|
|
8
|
+
|
|
9
|
+
## Install required dependencies
|
|
10
|
+
|
|
11
|
+
```bash npm2yarn
|
|
12
|
+
npm install @tari-project/tari-universe-signer @tari-project/tari-permissions
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Establish the connection
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { TariPermissions } from "@tari-project/tari-permissions";
|
|
19
|
+
import { TariUniverseSigner } from "@tari-project/tari-universe-signer";
|
|
20
|
+
|
|
21
|
+
const permissions = new TariPermissions().addPermission("Admin");
|
|
22
|
+
const optionalPermissions = new TariPermissions();
|
|
23
|
+
const indexerJrpcUrl = "http://127.0.0.1:12006/json_rpc";
|
|
24
|
+
|
|
25
|
+
const params: IndexerProviderParameters = {
|
|
26
|
+
indexerJrpcUrl: indexerJrpcUrl,
|
|
27
|
+
permissions: requiredPermissions,
|
|
28
|
+
optionalPermissions: optionalPermissions,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const provider = await IndexerProvider.build(params);
|
|
32
|
+
```
|
|
@@ -2,25 +2,25 @@
|
|
|
2
2
|
sidebar_position: 2
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
# Tari Universe
|
|
5
|
+
# Tari Universe signer
|
|
6
6
|
|
|
7
|
-
This
|
|
7
|
+
This signer is designed for building Tari Universe apps.
|
|
8
8
|
|
|
9
9
|
## Install required dependencies
|
|
10
10
|
|
|
11
11
|
```bash npm2yarn
|
|
12
|
-
npm install @tari-project/tari-universe-
|
|
12
|
+
npm install @tari-project/tari-universe-signer @tari-project/tari-permissions
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Establish the connection
|
|
16
16
|
|
|
17
17
|
```js
|
|
18
18
|
import { TariPermissions } from "@tari-project/tari-permissions";
|
|
19
|
-
import {
|
|
19
|
+
import { TariUniverseSigner } from "@tari-project/tari-universe-signer";
|
|
20
20
|
|
|
21
21
|
const permissions = new TariPermissions().addPermission("Admin");
|
|
22
22
|
const optionalPermissions = new TariPermissions();
|
|
23
|
-
const
|
|
23
|
+
const signer = new TariUniverseSigner({
|
|
24
24
|
permissions,
|
|
25
25
|
optionalPermissions,
|
|
26
26
|
});
|
|
@@ -2,18 +2,17 @@
|
|
|
2
2
|
sidebar_position: 1
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
# WalletConnect provider
|
|
5
|
+
# WalletConnect signer
|
|
7
6
|
|
|
8
7
|
[WalletConnect](https://walletconnect.network/) is an open-source protocol that lets users connect their cryptocurrency wallets to decentralized applications (dApps) in a secure way. It uses QR codes or deep linking to establish a connection between the wallet and the dApp, allowing users to interact with dApps without exposing their private keys.
|
|
9
8
|
|
|
10
9
|
## Install required dependencies
|
|
11
10
|
|
|
12
11
|
```bash npm2yarn
|
|
13
|
-
npm install @tari-project/wallet-connect-
|
|
12
|
+
npm install @tari-project/wallet-connect-signer
|
|
14
13
|
```
|
|
15
14
|
|
|
16
|
-
`WalletConnect`
|
|
15
|
+
`WalletConnect` signer is browser only. This means it requires user interaction.
|
|
17
16
|
|
|
18
17
|
Establishing connection requires multiple steps.
|
|
19
18
|
|
|
@@ -24,11 +23,11 @@ Obtain a WalletConnect Project ID by registering your project on the WalletConne
|
|
|
24
23
|
## Request a connection and display wallet connect dialog
|
|
25
24
|
|
|
26
25
|
```js
|
|
27
|
-
import {
|
|
26
|
+
import { WalletConnectTariSigner } from "@tari-project/wallet-connect-signer";
|
|
28
27
|
|
|
29
28
|
const projectId = "1825b9dd9c17b5a33063ae91cbc48a6e";
|
|
30
|
-
const
|
|
31
|
-
await
|
|
29
|
+
const signer = new WalletConnectTariSigner(projectId);
|
|
30
|
+
await signer.connect();
|
|
32
31
|
```
|
|
33
32
|
|
|
34
33
|
You should see `WalletConnect` dialog:
|
|
@@ -2,31 +2,31 @@
|
|
|
2
2
|
sidebar_position: 3
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
# Wallet daemon
|
|
5
|
+
# Wallet daemon signer
|
|
6
6
|
|
|
7
|
-
This is the only
|
|
7
|
+
This is the only signer that works in both Node.js and browser environments. It enables a direct connection to a wallet via JSON-RPC.
|
|
8
8
|
|
|
9
9
|
## Install required dependencies
|
|
10
10
|
|
|
11
11
|
```bash npm2yarn
|
|
12
|
-
npm install @tari-project/wallet-daemon-
|
|
12
|
+
npm install @tari-project/wallet-daemon-signer @tari-project/tari-permissions
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Establish and test the connection
|
|
16
16
|
|
|
17
17
|
```js
|
|
18
18
|
import { TariPermissions } from "@tari-project/tari-permissions";
|
|
19
|
-
import {
|
|
19
|
+
import { WalletDaemonTariSigner } from "@tari-project/wallet-daemon-signer";
|
|
20
20
|
|
|
21
21
|
const permissions = new TariPermissions().addPermission("Admin");
|
|
22
22
|
const serverUrl = "http://127.0.0.1:12010/json_rpc";
|
|
23
|
-
const
|
|
23
|
+
const signer = await WalletDaemonTariSigner.buildFetchProvider({
|
|
24
24
|
permissions,
|
|
25
25
|
serverUrl,
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
// Test connection
|
|
29
|
-
const account = await
|
|
29
|
+
const account = await signer.getAccount();
|
|
30
30
|
console.log(`Account address: ${account.address}`);
|
|
31
31
|
```
|
|
32
32
|
|
|
@@ -34,4 +34,4 @@ If the connection is successful, it should output an account address similar to
|
|
|
34
34
|
|
|
35
35
|
```txt
|
|
36
36
|
Account id: component_24b679b98056c7ca7e3d9f9266fec928c7f29d35e7aec546ed69f532aff40710
|
|
37
|
-
```
|
|
37
|
+
```
|
|
@@ -7,7 +7,7 @@ sidebar_position: 3
|
|
|
7
7
|
In the Tari network, substates are discrete units of state within the Tari Digital Assets Network. Each substate encapsulates a specific piece of data—such as ownership records, smart contract states, or asset balances.
|
|
8
8
|
Substates follow a create-spend lifecycle, meaning they are created, referenced, and eventually consumed or modified according to network rules.
|
|
9
9
|
|
|
10
|
-
You can query substates using the `listSubstates` method of a `
|
|
10
|
+
You can query substates using the `listSubstates` method of a `TariSigner`.
|
|
11
11
|
|
|
12
12
|
```ts
|
|
13
13
|
listSubstates(
|
|
@@ -18,7 +18,6 @@ listSubstates(
|
|
|
18
18
|
): Promise<ListSubstatesResponse>;
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
|
|
22
21
|
## List by template
|
|
23
22
|
|
|
24
23
|
```js
|
|
@@ -66,4 +65,4 @@ Output:
|
|
|
66
65
|
}
|
|
67
66
|
]
|
|
68
67
|
}
|
|
69
|
-
```
|
|
68
|
+
```
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
// This file is not used in compilation. It is here just for a nice editor experience.
|
|
3
|
+
// "composite" added to resolve the ts error: "Referenced project '/docusaurus/tari-docs' must have setting "composite": true
|
|
3
4
|
"extends": "@docusaurus/tsconfig",
|
|
4
5
|
"compilerOptions": {
|
|
5
|
-
"baseUrl": "."
|
|
6
|
+
"baseUrl": ".",
|
|
7
|
+
"composite": true
|
|
6
8
|
},
|
|
7
9
|
"exclude": [".docusaurus", "build"]
|
|
8
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/tarijs-builders",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"author": "",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@tari-project/tari-
|
|
17
|
-
"@tari-project/tari-universe-
|
|
16
|
+
"@tari-project/tari-signer": "workspace:^",
|
|
17
|
+
"@tari-project/tari-universe-signer": "workspace:^",
|
|
18
18
|
"@tari-project/tarijs-types": "workspace:^",
|
|
19
19
|
"@tari-project/typescript-bindings": "catalog:"
|
|
20
20
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { TariUniverseSigner } from "@tari-project/tari-universe-signer";
|
|
2
|
+
import { TariSigner, SubmitTransactionRequest, SubstateRequirement } from "@tari-project/tari-signer";
|
|
3
3
|
import {
|
|
4
4
|
Transaction,
|
|
5
5
|
TransactionResult,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
UpSubstates,
|
|
9
9
|
FinalizeResultStatus,
|
|
10
10
|
TxResultAccept,
|
|
11
|
-
SubmitTxResult
|
|
11
|
+
SubmitTxResult,
|
|
12
12
|
} from "@tari-project/tarijs-types";
|
|
13
13
|
|
|
14
14
|
export function buildTransactionRequest(
|
|
@@ -40,12 +40,12 @@ export function buildTransactionRequest(
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export async function submitAndWaitForTransaction(
|
|
43
|
-
|
|
43
|
+
signer: TariSigner,
|
|
44
44
|
req: SubmitTransactionRequest,
|
|
45
45
|
): Promise<SubmitTxResult> {
|
|
46
46
|
try {
|
|
47
|
-
const response = await
|
|
48
|
-
const result = await waitForTransactionResult(
|
|
47
|
+
const response = await signer.submitTransaction(req);
|
|
48
|
+
const result = await waitForTransactionResult(signer, response.transaction_id);
|
|
49
49
|
|
|
50
50
|
return {
|
|
51
51
|
response,
|
|
@@ -57,12 +57,12 @@ export async function submitAndWaitForTransaction(
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
export async function waitForTransactionResult(
|
|
60
|
-
|
|
60
|
+
signer: TariSigner | TariUniverseSigner,
|
|
61
61
|
transactionId: string,
|
|
62
62
|
): Promise<TransactionResult> {
|
|
63
63
|
// eslint-disable-next-line no-constant-condition
|
|
64
64
|
while (true) {
|
|
65
|
-
const resp = await
|
|
65
|
+
const resp = await signer.getTransactionResult(transactionId);
|
|
66
66
|
const FINALIZED_STATUSES = [
|
|
67
67
|
TransactionStatus.Accepted,
|
|
68
68
|
TransactionStatus.Rejected,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tari-project/indexer-provider",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc -b"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@tari-project/tari-permissions": "workspace:^",
|
|
17
|
+
"@tari-project/tari-provider": "workspace:^",
|
|
18
|
+
"@tari-project/tarijs-types": "workspace:^",
|
|
19
|
+
"@tari-project/typescript-bindings": "catalog:",
|
|
20
|
+
"@tari-project/wallet_jrpc_client": "catalog:"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "catalog:",
|
|
24
|
+
"typescript": "catalog:"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"/dist"
|
|
28
|
+
],
|
|
29
|
+
"main": "dist/index.js",
|
|
30
|
+
"types": "dist/index.d.ts"
|
|
31
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GetSubstateRequest,
|
|
3
|
+
ListSubstatesRequest,
|
|
4
|
+
ListSubstatesResponse,
|
|
5
|
+
Substate,
|
|
6
|
+
TariProvider,
|
|
7
|
+
TransactionResult,
|
|
8
|
+
} from "@tari-project/tari-provider";
|
|
9
|
+
import { TariPermissions } from "@tari-project/tari-permissions";
|
|
10
|
+
import { IndexerProviderClient } from "./transports";
|
|
11
|
+
import {
|
|
12
|
+
GetTemplateDefinitionResponse,
|
|
13
|
+
ListTemplatesResponse,
|
|
14
|
+
stringToSubstateId,
|
|
15
|
+
substateIdToString,
|
|
16
|
+
SubstatesListRequest,
|
|
17
|
+
} from "@tari-project/typescript-bindings";
|
|
18
|
+
import { convertStringToTransactionStatus } from "@tari-project/tarijs-types";
|
|
19
|
+
|
|
20
|
+
export interface IndexerProviderParameters {
|
|
21
|
+
indexerJrpcUrl: string;
|
|
22
|
+
permissions: TariPermissions;
|
|
23
|
+
optionalPermissions?: TariPermissions;
|
|
24
|
+
onConnection?: () => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class IndexerProvider implements TariProvider {
|
|
28
|
+
public providerName = "IndexerProvider";
|
|
29
|
+
client: IndexerProviderClient;
|
|
30
|
+
params: IndexerProviderParameters;
|
|
31
|
+
|
|
32
|
+
private constructor(params: IndexerProviderParameters, connection: IndexerProviderClient) {
|
|
33
|
+
this.params = params;
|
|
34
|
+
this.client = connection;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static async build(params: IndexerProviderParameters) {
|
|
38
|
+
const client = IndexerProviderClient.usingFetchTransport(params.indexerJrpcUrl);
|
|
39
|
+
await client.getIdentity();
|
|
40
|
+
params.onConnection?.();
|
|
41
|
+
return new IndexerProvider(params, client);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public isConnected(): boolean {
|
|
45
|
+
return this.client.isConnected();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public async listSubstates({
|
|
49
|
+
filter_by_template,
|
|
50
|
+
filter_by_type,
|
|
51
|
+
limit,
|
|
52
|
+
offset,
|
|
53
|
+
}: ListSubstatesRequest): Promise<ListSubstatesResponse> {
|
|
54
|
+
const resp = await this.client.listSubstates({
|
|
55
|
+
filter_by_template,
|
|
56
|
+
filter_by_type,
|
|
57
|
+
limit,
|
|
58
|
+
offset,
|
|
59
|
+
} as SubstatesListRequest);
|
|
60
|
+
|
|
61
|
+
const substates = resp.substates.map((s) => ({
|
|
62
|
+
substate_id: typeof s.substate_id === "string" ? s.substate_id : substateIdToString(s.substate_id),
|
|
63
|
+
module_name: s.module_name,
|
|
64
|
+
version: s.version,
|
|
65
|
+
template_address: s.template_address,
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
return { substates };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public async getSubstate({ substate_address, version }: GetSubstateRequest): Promise<Substate> {
|
|
72
|
+
const resp = await this.client.getSubstate({
|
|
73
|
+
address: stringToSubstateId(substate_address),
|
|
74
|
+
version: version ?? null,
|
|
75
|
+
local_search_only: false,
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
address: {
|
|
79
|
+
substate_id: substateIdToString(resp.address),
|
|
80
|
+
version: resp.version,
|
|
81
|
+
},
|
|
82
|
+
value: resp.substate,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public async listTemplates(limit: number = 0): Promise<ListTemplatesResponse> {
|
|
87
|
+
const resp = await this.client.listTemplates({ limit });
|
|
88
|
+
return resp;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public async getTransactionResult(transactionId: string): Promise<TransactionResult> {
|
|
92
|
+
const resp = await this.client.getTransactionResult({ transaction_id: transactionId });
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
transaction_id: transactionId,
|
|
96
|
+
status: convertStringToTransactionStatus(resp.status),
|
|
97
|
+
result: resp.result,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public async getTemplateDefinition(template_address: string): Promise<GetTemplateDefinitionResponse> {
|
|
102
|
+
let resp = await this.client.getTemplateDefinition({ template_address });
|
|
103
|
+
return resp;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GetEpochManagerStatsResponse,
|
|
3
|
+
GetNonFungibleCollectionsResponse,
|
|
4
|
+
GetNonFungibleCountRequest,
|
|
5
|
+
GetNonFungibleCountResponse,
|
|
6
|
+
GetNonFungiblesRequest,
|
|
7
|
+
GetNonFungiblesResponse,
|
|
8
|
+
GetRelatedTransactionsRequest,
|
|
9
|
+
GetRelatedTransactionsResponse,
|
|
10
|
+
GetTemplateDefinitionRequest,
|
|
11
|
+
GetTemplateDefinitionResponse,
|
|
12
|
+
IndexerGetIdentityResponse,
|
|
13
|
+
IndexerGetSubstateRequest,
|
|
14
|
+
IndexerGetSubstateResponse,
|
|
15
|
+
IndexerSubmitTransactionRequest,
|
|
16
|
+
IndexerSubmitTransactionResponse,
|
|
17
|
+
InspectSubstateRequest,
|
|
18
|
+
InspectSubstateResponse,
|
|
19
|
+
ListTemplatesRequest,
|
|
20
|
+
ListTemplatesResponse,
|
|
21
|
+
SubstatesListRequest,
|
|
22
|
+
SubstatesListResponse,
|
|
23
|
+
TransactionGetResultRequest,
|
|
24
|
+
TransactionGetResultResponse,
|
|
25
|
+
TransactionWaitResultRequest,
|
|
26
|
+
TransactionWaitResultResponse,
|
|
27
|
+
} from "@tari-project/typescript-bindings";
|
|
28
|
+
import { FetchRpcTransport, RpcTransport } from "./rpc";
|
|
29
|
+
|
|
30
|
+
export class IndexerProviderClient {
|
|
31
|
+
private token: string | null;
|
|
32
|
+
private transport: RpcTransport;
|
|
33
|
+
private id: number;
|
|
34
|
+
private connected: boolean;
|
|
35
|
+
|
|
36
|
+
constructor(transport: RpcTransport) {
|
|
37
|
+
this.token = null;
|
|
38
|
+
this.transport = transport;
|
|
39
|
+
this.id = 0;
|
|
40
|
+
this.connected = false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public static new(transport: RpcTransport): IndexerProviderClient {
|
|
44
|
+
return new IndexerProviderClient(transport);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public static usingFetchTransport(url: string): IndexerProviderClient {
|
|
48
|
+
return IndexerProviderClient.new(FetchRpcTransport.new(url));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getTransport() {
|
|
52
|
+
return this.transport;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public isAuthenticated() {
|
|
56
|
+
return this.token !== null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public isConnected() {
|
|
60
|
+
return this.connected;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public setToken(token: string) {
|
|
64
|
+
this.token = token;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public submitTransaction(params: IndexerSubmitTransactionRequest): Promise<IndexerSubmitTransactionResponse> {
|
|
68
|
+
return this.__invokeRpc("submit_transaction", params);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public inspectSubstate(params: InspectSubstateRequest): Promise<InspectSubstateResponse> {
|
|
72
|
+
return this.__invokeRpc("inspect_substate", params);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public getSubstate(params: IndexerGetSubstateRequest): Promise<IndexerGetSubstateResponse> {
|
|
76
|
+
return this.__invokeRpc("get_substate", params);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public listSubstates(params: SubstatesListRequest): Promise<SubstatesListResponse> {
|
|
80
|
+
return this.__invokeRpc("list_substates", params);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public listTemplates(params: ListTemplatesRequest): Promise<ListTemplatesResponse> {
|
|
84
|
+
return this.__invokeRpc("list_templates", params);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public getTemplateDefinition(params: GetTemplateDefinitionRequest): Promise<GetTemplateDefinitionResponse> {
|
|
88
|
+
return this.__invokeRpc("get_template_definition", params);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public getTransactionResult(params: TransactionGetResultRequest): Promise<TransactionGetResultResponse> {
|
|
92
|
+
return this.__invokeRpc("get_transaction_result", params);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public getSubstateTransactions(params: GetRelatedTransactionsRequest): Promise<GetRelatedTransactionsResponse> {
|
|
96
|
+
return this.__invokeRpc("get_substate_transactions", params);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public getNonFungibles(params: GetNonFungiblesRequest): Promise<GetNonFungiblesResponse> {
|
|
100
|
+
return this.__invokeRpc("get_non_fungibles", params);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public getNonFungibleCollections(): Promise<GetNonFungibleCollectionsResponse> {
|
|
104
|
+
return this.__invokeRpc("get_non_fungible_collections");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public getNonFungibleCount(params: GetNonFungibleCountRequest): Promise<GetNonFungibleCountResponse> {
|
|
108
|
+
return this.__invokeRpc("get_non_fungible_count", params);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public getEpochManagerStats(): Promise<GetEpochManagerStatsResponse> {
|
|
112
|
+
return this.__invokeRpc("get_epoch_manager_stats");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public waitForTransactionResult(params: TransactionWaitResultRequest): Promise<TransactionWaitResultResponse> {
|
|
116
|
+
return this.__invokeRpc("transactions.wait_result", params);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public async getIdentity(): Promise<IndexerGetIdentityResponse | undefined> {
|
|
120
|
+
try {
|
|
121
|
+
const res: IndexerGetIdentityResponse = await this.__invokeRpc("get_identity");
|
|
122
|
+
this.connected = !!res.public_key;
|
|
123
|
+
return res;
|
|
124
|
+
} catch (e) {
|
|
125
|
+
console.error("Failed to get Indexer identity:", e);
|
|
126
|
+
this.connected = false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async __invokeRpc(method: string, params: object | null = null) {
|
|
131
|
+
const id = this.id++;
|
|
132
|
+
const response = await this.transport.sendRequest<any>(
|
|
133
|
+
{
|
|
134
|
+
method,
|
|
135
|
+
jsonrpc: "2.0",
|
|
136
|
+
id: id,
|
|
137
|
+
params: params || {},
|
|
138
|
+
},
|
|
139
|
+
{ token: this.token ?? undefined, timeout_millis: undefined },
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
return response;
|
|
143
|
+
}
|
|
144
|
+
}
|