@tari-project/tarijs 0.3.0 → 0.4.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/dist/index.d.ts +11 -10
- package/dist/index.js +10 -9
- package/dist/network.d.ts +8 -0
- package/dist/network.js +9 -0
- package/dist/templates/Account.d.ts +2 -2
- package/dist/templates/Pool.d.ts +1 -2
- package/dist/templates/Tariswap.d.ts +1 -2
- package/dist/templates/TemplateFactory.d.ts +1 -1
- package/dist/templates/TestFaucet.d.ts +1 -1
- package/package.json +20 -12
- package/README.md +0 -46
- package/dist/builders/helpers/index.d.ts +0 -2
- package/dist/builders/helpers/index.js +0 -2
- package/dist/builders/helpers/submitTransaction.d.ts +0 -13
- package/dist/builders/helpers/submitTransaction.js +0 -59
- package/dist/builders/helpers/workspace.d.ts +0 -23
- package/dist/builders/helpers/workspace.js +0 -29
- package/dist/builders/index.d.ts +0 -3
- package/dist/builders/index.js +0 -3
- package/dist/builders/transaction/TransactionBuilder.d.ts +0 -44
- package/dist/builders/transaction/TransactionBuilder.js +0 -164
- package/dist/builders/transaction/TransactionRequest.d.ts +0 -27
- package/dist/builders/transaction/TransactionRequest.js +0 -67
- package/dist/builders/transaction/index.d.ts +0 -2
- package/dist/builders/transaction/index.js +0 -2
- package/dist/builders/types/Amount.d.ts +0 -23
- package/dist/builders/types/Amount.js +0 -93
- package/dist/builders/types/Arg.d.ts +0 -1
- package/dist/builders/types/Arg.js +0 -1
- package/dist/builders/types/Builder.d.ts +0 -47
- package/dist/builders/types/Builder.js +0 -1
- package/dist/builders/types/ComponentAddress.d.ts +0 -1
- package/dist/builders/types/ComponentAddress.js +0 -1
- package/dist/builders/types/ConfidentialClaim.d.ts +0 -8
- package/dist/builders/types/ConfidentialClaim.js +0 -1
- package/dist/builders/types/ConfidentialOutput.d.ts +0 -8
- package/dist/builders/types/ConfidentialOutput.js +0 -1
- package/dist/builders/types/ConfidentialOutputStatement.d.ts +0 -9
- package/dist/builders/types/ConfidentialOutputStatement.js +0 -1
- package/dist/builders/types/ConfidentialStatement.d.ts +0 -8
- package/dist/builders/types/ConfidentialStatement.js +0 -1
- package/dist/builders/types/ConfidentialWithdrawProof.d.ts +0 -7
- package/dist/builders/types/ConfidentialWithdrawProof.js +0 -1
- package/dist/builders/types/ElgamalVerifiableBalance.d.ts +0 -4
- package/dist/builders/types/ElgamalVerifiableBalance.js +0 -1
- package/dist/builders/types/Epoch.d.ts +0 -1
- package/dist/builders/types/Epoch.js +0 -1
- package/dist/builders/types/FinalizeResult.d.ts +0 -20
- package/dist/builders/types/FinalizeResult.js +0 -1
- package/dist/builders/types/Instruction.d.ts +0 -56
- package/dist/builders/types/Instruction.js +0 -1
- package/dist/builders/types/ResourceAddress.d.ts +0 -1
- package/dist/builders/types/ResourceAddress.js +0 -2
- package/dist/builders/types/SubstateDiff.d.ts +0 -7
- package/dist/builders/types/SubstateDiff.js +0 -1
- package/dist/builders/types/SubstateRequirement.d.ts +0 -5
- package/dist/builders/types/SubstateRequirement.js +0 -1
- package/dist/builders/types/TemplateAddress.d.ts +0 -1
- package/dist/builders/types/TemplateAddress.js +0 -2
- package/dist/builders/types/Transaction.d.ts +0 -15
- package/dist/builders/types/Transaction.js +0 -1
- package/dist/builders/types/TransactionId.d.ts +0 -1
- package/dist/builders/types/TransactionId.js +0 -1
- package/dist/builders/types/TransactionResult.d.ts +0 -22
- package/dist/builders/types/TransactionResult.js +0 -10
- package/dist/builders/types/TransactionSignature.d.ts +0 -4
- package/dist/builders/types/TransactionSignature.js +0 -1
- package/dist/builders/types/UnsignedTransaction.d.ts +0 -12
- package/dist/builders/types/UnsignedTransaction.js +0 -1
- package/dist/builders/types/VersionedSubstateId.d.ts +0 -5
- package/dist/builders/types/VersionedSubstateId.js +0 -1
- package/dist/builders/types/ViewableBalanceProof.d.ts +0 -10
- package/dist/builders/types/ViewableBalanceProof.js +0 -2
- package/dist/builders/types/Workspace.d.ts +0 -3
- package/dist/builders/types/Workspace.js +0 -1
- package/dist/builders/types/index.d.ts +0 -24
- package/dist/builders/types/index.js +0 -2
- package/dist/providers/index.d.ts +0 -16
- package/dist/providers/index.js +0 -1
- package/dist/providers/metamask/index.d.ts +0 -30
- package/dist/providers/metamask/index.js +0 -168
- package/dist/providers/metamask/utils.d.ts +0 -38
- package/dist/providers/metamask/utils.js +0 -55
- package/dist/providers/tari_universe/index.d.ts +0 -3
- package/dist/providers/tari_universe/index.js +0 -3
- package/dist/providers/tari_universe/provider.d.ts +0 -23
- package/dist/providers/tari_universe/provider.js +0 -89
- package/dist/providers/tari_universe/types.d.ts +0 -30
- package/dist/providers/tari_universe/types.js +0 -1
- package/dist/providers/tari_universe/utils.d.ts +0 -2
- package/dist/providers/tari_universe/utils.js +0 -16
- package/dist/providers/types.d.ts +0 -66
- package/dist/providers/types.js +0 -10
- package/dist/providers/wallet_daemon/index.d.ts +0 -3
- package/dist/providers/wallet_daemon/index.js +0 -3
- package/dist/providers/wallet_daemon/provider.d.ts +0 -35
- package/dist/providers/wallet_daemon/provider.js +0 -173
- package/dist/providers/wallet_daemon/tari_permissions.d.ts +0 -216
- package/dist/providers/wallet_daemon/tari_permissions.js +0 -282
- package/dist/providers/wallet_daemon/webrtc.d.ts +0 -20
- package/dist/providers/wallet_daemon/webrtc.js +0 -201
- package/dist/providers/wallet_daemon/webrtc_transport.d.ts +0 -10
- package/dist/providers/wallet_daemon/webrtc_transport.js +0 -18
- package/dist/providers/walletconnect/index.d.ts +0 -23
- package/dist/providers/walletconnect/index.js +0 -217
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { TariProvider } from "
|
|
1
|
+
import { TariProvider } from "@tari-project/tari-provider";
|
|
2
2
|
import * as utils from "./utils";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { Network } from "./network";
|
|
4
|
+
import { Account, TransactionStatus, TransactionResult, SubmitTransactionResponse, SubmitTransactionRequest, VaultBalances, VaultData, TemplateDefinition, SubstateRequirement, Substate } from "@tari-project/tari-provider";
|
|
5
|
+
import { MetamaskTariProvider } from "@tari-project/metamask-provider";
|
|
5
6
|
import { MetaMaskInpageProvider } from "@metamask/providers";
|
|
6
|
-
import { WalletDaemonTariProvider, WalletDaemonParameters, TariPermissions } from "
|
|
7
|
-
import { TariUniverseProvider, TariUniverseProviderParameters } from "
|
|
8
|
-
import * as permissions from "
|
|
9
|
-
import { WalletConnectTariProvider } from "
|
|
10
|
-
import { TransactionBuilder, TransactionRequest, buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult, fromWorkspace, toWorkspace } from "
|
|
7
|
+
import { WalletDaemonTariProvider, WalletDaemonParameters, TariPermissions } from "@tari-project/wallet-daemon-provider";
|
|
8
|
+
import { TariUniverseProvider, TariUniverseProviderParameters } from "@tari-project/tari-universe-provider";
|
|
9
|
+
import * as permissions from "@tari-project/tari-permissions";
|
|
10
|
+
import { WalletConnectTariProvider } from "@tari-project/wallet-connect-provider";
|
|
11
|
+
import { TransactionBuilder, TransactionRequest, buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult, fromWorkspace, toWorkspace } from "@tari-project/tarijs-builders";
|
|
11
12
|
import * as templates from "./templates";
|
|
12
|
-
export * from "
|
|
13
|
-
export { utils, TariProvider, Account, TransactionStatus, TransactionResult, SubmitTransactionResponse, SubmitTransactionRequest, VaultBalances, VaultData, TemplateDefinition, SubstateRequirement, MetamaskTariProvider, WalletDaemonTariProvider, WalletDaemonParameters, TariUniverseProvider, TariUniverseProviderParameters, TariPermissions, MetaMaskInpageProvider, Substate, permissions, WalletConnectTariProvider, TransactionBuilder, TransactionRequest, buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult, fromWorkspace, toWorkspace, templates, };
|
|
13
|
+
export * from "@tari-project/tarijs-types";
|
|
14
|
+
export { utils, Network, TariProvider, Account, TransactionStatus, TransactionResult, SubmitTransactionResponse, SubmitTransactionRequest, VaultBalances, VaultData, TemplateDefinition, SubstateRequirement, MetamaskTariProvider, WalletDaemonTariProvider, WalletDaemonParameters, TariUniverseProvider, TariUniverseProviderParameters, TariPermissions, MetaMaskInpageProvider, Substate, permissions, WalletConnectTariProvider, TransactionBuilder, TransactionRequest, buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult, fromWorkspace, toWorkspace, templates, };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import * as utils from "./utils";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { Network } from "./network";
|
|
3
|
+
import { TransactionStatus, } from "@tari-project/tari-provider";
|
|
4
|
+
import { MetamaskTariProvider } from "@tari-project/metamask-provider";
|
|
4
5
|
import { MetaMaskInpageProvider } from "@metamask/providers";
|
|
5
|
-
import { WalletDaemonTariProvider, TariPermissions } from "
|
|
6
|
-
import { TariUniverseProvider } from "
|
|
7
|
-
import * as permissions from "
|
|
8
|
-
import { WalletConnectTariProvider } from "
|
|
9
|
-
import { TransactionBuilder, TransactionRequest, buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult, fromWorkspace, toWorkspace, } from "
|
|
6
|
+
import { WalletDaemonTariProvider, TariPermissions, } from "@tari-project/wallet-daemon-provider";
|
|
7
|
+
import { TariUniverseProvider } from "@tari-project/tari-universe-provider";
|
|
8
|
+
import * as permissions from "@tari-project/tari-permissions";
|
|
9
|
+
import { WalletConnectTariProvider } from "@tari-project/wallet-connect-provider";
|
|
10
|
+
import { TransactionBuilder, TransactionRequest, buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult, fromWorkspace, toWorkspace, } from "@tari-project/tarijs-builders";
|
|
10
11
|
import * as templates from "./templates";
|
|
11
|
-
export * from "
|
|
12
|
-
export { utils, TransactionStatus, MetamaskTariProvider, WalletDaemonTariProvider, TariUniverseProvider, TariPermissions, MetaMaskInpageProvider, permissions, WalletConnectTariProvider, TransactionBuilder, TransactionRequest, buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult, fromWorkspace, toWorkspace, templates, };
|
|
12
|
+
export * from "@tari-project/tarijs-types";
|
|
13
|
+
export { utils, Network, TransactionStatus, MetamaskTariProvider, WalletDaemonTariProvider, TariUniverseProvider, TariPermissions, MetaMaskInpageProvider, permissions, WalletConnectTariProvider, TransactionBuilder, TransactionRequest, buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult, fromWorkspace, toWorkspace, templates, };
|
package/dist/network.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export var Network;
|
|
2
|
+
(function (Network) {
|
|
3
|
+
Network[Network["MainNet"] = 0] = "MainNet";
|
|
4
|
+
Network[Network["StageNet"] = 1] = "StageNet";
|
|
5
|
+
Network[Network["NextNet"] = 2] = "NextNet";
|
|
6
|
+
Network[Network["LocalNet"] = 16] = "LocalNet";
|
|
7
|
+
Network[Network["Igor"] = 36] = "Igor";
|
|
8
|
+
Network[Network["Esmeralda"] = 38] = "Esmeralda";
|
|
9
|
+
})(Network || (Network = {}));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConfidentialWithdrawProof, NonFungibleId, ResourceAddress } from "@tari-project/typescript-bindings";
|
|
2
|
-
import { Amount } from "
|
|
3
|
-
import { TariMethodDefinition, WorkspaceArg } from "
|
|
2
|
+
import { Amount } from "@tari-project/tarijs-types";
|
|
3
|
+
import { TariMethodDefinition, WorkspaceArg } from "@tari-project/tarijs-builders";
|
|
4
4
|
import { TemplateFactory } from "./TemplateFactory";
|
|
5
5
|
/**
|
|
6
6
|
* Adds a fee instruction that calls the "take_fee" method on a component.
|
package/dist/templates/Pool.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { TariMethodDefinition } from "
|
|
2
|
-
import { WorkspaceArg } from "../builders/types/Workspace";
|
|
1
|
+
import { TariMethodDefinition, WorkspaceArg } from "@tari-project/tarijs-builders";
|
|
3
2
|
import { TemplateFactory } from "./TemplateFactory";
|
|
4
3
|
interface CreatePool extends TariMethodDefinition {
|
|
5
4
|
methodName: "create_pool";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Amount, ConfidentialWithdrawProof, ResourceAddress } from "
|
|
2
|
-
import { TariFunctionDefinition, TariMethodDefinition, WorkspaceArg } from "../builders/types";
|
|
1
|
+
import { Amount, ConfidentialWithdrawProof, ResourceAddress, TariFunctionDefinition, TariMethodDefinition, WorkspaceArg } from "@tari-project/tarijs-builders";
|
|
3
2
|
import { TemplateFactory } from "./TemplateFactory";
|
|
4
3
|
interface NewPoolFunction extends TariFunctionDefinition {
|
|
5
4
|
functionName: "new";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TariFunctionDefinition, TariMethodDefinition } from "
|
|
1
|
+
import { TariFunctionDefinition, TariMethodDefinition } from "@tari-project/tarijs-builders";
|
|
2
2
|
export declare abstract class TemplateFactory {
|
|
3
3
|
templateAddress: string;
|
|
4
4
|
constructor(templateAddress: string);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Amount, ConfidentialWithdrawProof, TariFunctionDefinition, TariMethodDefinition } from "
|
|
1
|
+
import { Amount, ConfidentialWithdrawProof, TariFunctionDefinition, TariMethodDefinition } from "@tari-project/tarijs-builders";
|
|
2
2
|
import { TemplateFactory } from "./TemplateFactory";
|
|
3
3
|
interface MintFunction extends TariFunctionDefinition {
|
|
4
4
|
functionName: "mint";
|
package/package.json
CHANGED
|
@@ -1,31 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/tarijs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
|
-
"scripts": {
|
|
10
|
-
"build": "tsc -b"
|
|
11
|
-
},
|
|
12
9
|
"keywords": [],
|
|
13
10
|
"author": "",
|
|
14
11
|
"license": "ISC",
|
|
15
12
|
"dependencies": {
|
|
16
13
|
"@metamask/providers": "^18.2.0",
|
|
17
|
-
"@tari-project/
|
|
18
|
-
"@tari-project/
|
|
19
|
-
"@
|
|
20
|
-
"@
|
|
14
|
+
"@tari-project/typescript-bindings": "^1.4.0",
|
|
15
|
+
"@tari-project/metamask-provider": "^0.4.0",
|
|
16
|
+
"@tari-project/tari-permissions": "^0.4.0",
|
|
17
|
+
"@tari-project/tari-provider": "^0.4.0",
|
|
18
|
+
"@tari-project/tari-universe-provider": "^0.4.0",
|
|
19
|
+
"@tari-project/tarijs-types": "^0.4.0",
|
|
20
|
+
"@tari-project/tarijs-builders": "^0.4.0",
|
|
21
|
+
"@tari-project/wallet-connect-provider": "^0.4.0",
|
|
22
|
+
"@tari-project/wallet-daemon-provider": "^0.4.0"
|
|
21
23
|
},
|
|
22
24
|
"devDependencies": {
|
|
23
|
-
"@types/node": "^
|
|
24
|
-
"typescript": "^5.0.4"
|
|
25
|
+
"@types/node": "^22.13.1",
|
|
26
|
+
"typescript": "^5.0.4",
|
|
27
|
+
"vite": "^6.1.0",
|
|
28
|
+
"vitest": "^3.0.4"
|
|
25
29
|
},
|
|
26
30
|
"files": [
|
|
27
31
|
"/dist"
|
|
28
32
|
],
|
|
29
33
|
"main": "dist/index.js",
|
|
30
|
-
"types": "dist/index.d.ts"
|
|
31
|
-
|
|
34
|
+
"types": "dist/index.d.ts",
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc -b",
|
|
37
|
+
"integration-tests": "vitest run integration-tests"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/README.md
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
# tari.js
|
|
2
|
-
|
|
3
|
-
This project provides a unified TypeScript library to connect and send requests to a Tari wallet. It's intended for web application developers that want to interact with a Tari wallet (connect, get substates, submit transactions, etc.).
|
|
4
|
-
|
|
5
|
-
Tari wallets supported:
|
|
6
|
-
* Tari Wallet Daemon
|
|
7
|
-
* MetaMask through the [tari-snap](https://github.com/tari-project/tari-snap)
|
|
8
|
-
|
|
9
|
-
An example site (under the `example` folder) contains a web project that allows the user to connect to any type of Tari wallet and perform common actions.
|
|
10
|
-
|
|
11
|
-
Please read the [TODO](TODO.md) file for upcoming features.
|
|
12
|
-
|
|
13
|
-
## Library building
|
|
14
|
-
|
|
15
|
-
You must have the [tari-dan](https://github.com/tari-project/tari-dan) repo cloned at the same folder level as this repo.
|
|
16
|
-
|
|
17
|
-
To build the library:
|
|
18
|
-
```shell
|
|
19
|
-
npm install
|
|
20
|
-
npm run build
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
The bundled files for deployment or publication will be located under the `dist` folder.
|
|
24
|
-
|
|
25
|
-
## Running the example site
|
|
26
|
-
|
|
27
|
-
To run the example site you will need to:
|
|
28
|
-
* Compile the library following the previous section.
|
|
29
|
-
* Have access to a Tari Wallet Daemon and to the Tari MetaMask Snap.
|
|
30
|
-
* Copy the `example/.env.example` file to `example/.env` and edit the correct environment variable values.
|
|
31
|
-
|
|
32
|
-
To run in development mode:
|
|
33
|
-
```shell
|
|
34
|
-
cd example
|
|
35
|
-
npm install
|
|
36
|
-
npm run dev
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
For building and distribution
|
|
40
|
-
```shell
|
|
41
|
-
cd example
|
|
42
|
-
npm install
|
|
43
|
-
npm run build
|
|
44
|
-
```
|
|
45
|
-
The distribution files will be under the `example/dist` folder.
|
|
46
|
-
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { TariProvider } from "../../providers";
|
|
2
|
-
import { TariUniverseProvider } from "../../providers/tari_universe";
|
|
3
|
-
import { SubmitTransactionRequest, SubstateRequirement } from "../../providers/types";
|
|
4
|
-
import { Transaction, TransactionResult } from "../types";
|
|
5
|
-
import { DownSubstates, UpSubstates } from "../types/SubstateDiff";
|
|
6
|
-
import { SubmitTxResult } from "../types/TransactionResult";
|
|
7
|
-
export declare function buildTransactionRequest(transaction: Transaction, accountId: number, requiredSubstates: SubstateRequirement[], inputRefs?: never[], isDryRun?: boolean): SubmitTransactionRequest;
|
|
8
|
-
export declare function submitAndWaitForTransaction(provider: TariProvider, req: SubmitTransactionRequest): Promise<SubmitTxResult>;
|
|
9
|
-
export declare function waitForTransactionResult(provider: TariProvider | TariUniverseProvider, transactionId: string): Promise<TransactionResult>;
|
|
10
|
-
export declare function getAcceptResultSubstates(txResult: TransactionResult): {
|
|
11
|
-
upSubstates: UpSubstates;
|
|
12
|
-
downSubstates: DownSubstates;
|
|
13
|
-
} | undefined;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { TransactionStatus } from "../types";
|
|
2
|
-
export function buildTransactionRequest(transaction, accountId, requiredSubstates, inputRefs = [], isDryRun = false) {
|
|
3
|
-
return {
|
|
4
|
-
//TODO refactor SubTxReq type to not use 'object[]' and types match
|
|
5
|
-
// https://github.com/tari-project/tari.js/issues/25
|
|
6
|
-
account_id: accountId,
|
|
7
|
-
instructions: transaction.instructions,
|
|
8
|
-
fee_instructions: transaction.feeInstructions,
|
|
9
|
-
inputs: transaction.inputs,
|
|
10
|
-
input_refs: inputRefs,
|
|
11
|
-
required_substates: requiredSubstates,
|
|
12
|
-
is_dry_run: isDryRun,
|
|
13
|
-
min_epoch: transaction.minEpoch ?? null,
|
|
14
|
-
max_epoch: transaction.maxEpoch ?? null,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export async function submitAndWaitForTransaction(provider, req) {
|
|
18
|
-
try {
|
|
19
|
-
const response = await provider.submitTransaction(req);
|
|
20
|
-
const result = await waitForTransactionResult(provider, response.transaction_id);
|
|
21
|
-
return {
|
|
22
|
-
response,
|
|
23
|
-
result,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
catch (e) {
|
|
27
|
-
throw new Error(`Transaction failed: ${e}`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export async function waitForTransactionResult(provider, transactionId) {
|
|
31
|
-
// eslint-disable-next-line no-constant-condition
|
|
32
|
-
while (true) {
|
|
33
|
-
const resp = await provider.getTransactionResult(transactionId);
|
|
34
|
-
const FINALIZED_STATUSES = [
|
|
35
|
-
TransactionStatus.Accepted,
|
|
36
|
-
TransactionStatus.Rejected,
|
|
37
|
-
TransactionStatus.InvalidTransaction,
|
|
38
|
-
TransactionStatus.OnlyFeeAccepted,
|
|
39
|
-
TransactionStatus.DryRun,
|
|
40
|
-
];
|
|
41
|
-
if (resp.status == TransactionStatus.Rejected) {
|
|
42
|
-
throw new Error(`Transaction rejected: ${JSON.stringify(resp.result)}`);
|
|
43
|
-
}
|
|
44
|
-
if (FINALIZED_STATUSES.includes(resp.status)) {
|
|
45
|
-
return resp; //TODO fix: type mismatch (https://github.com/tari-project/tari.js/issues/29)
|
|
46
|
-
}
|
|
47
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export function getAcceptResultSubstates(txResult) {
|
|
51
|
-
const result = txResult.result?.result;
|
|
52
|
-
if (result && isAccept(result)) {
|
|
53
|
-
return { upSubstates: result.Accept.up_substates, downSubstates: result.Accept.down_substates };
|
|
54
|
-
}
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
57
|
-
function isAccept(result) {
|
|
58
|
-
return "Accept" in result;
|
|
59
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { WorkspaceArg } from "../types";
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param key workspace name
|
|
5
|
-
* @returns encoded Uint8Array value
|
|
6
|
-
* @example
|
|
7
|
-
* key: "0" -> [ 48 ]
|
|
8
|
-
* key: "0.0" -> [ 48, 46, 48 ]
|
|
9
|
-
* key: "0.1" -> [ 48, 46, 49 ]
|
|
10
|
-
*
|
|
11
|
-
* key: "bucket" -> [ 98, 117, 99, 107, 101, 116 ]
|
|
12
|
-
* key: "bucket.0" -> [ 98, 117, 99, 107, 101, 116, 46, 48 ]
|
|
13
|
-
* key: "bucket.1" -> [ 98, 117, 99, 107, 101, 116, 46, 49 ]
|
|
14
|
-
*/
|
|
15
|
-
export declare function toWorkspace(key: string): number[];
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @param key workspace name
|
|
19
|
-
* @returns formatted Workspace data
|
|
20
|
-
* @example
|
|
21
|
-
* key: "bucket" -> { Workspace: [ 98, 117, 99, 107, 101, 116 ] }
|
|
22
|
-
*/
|
|
23
|
-
export declare function fromWorkspace(key: string): WorkspaceArg;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @param key workspace name
|
|
4
|
-
* @returns encoded Uint8Array value
|
|
5
|
-
* @example
|
|
6
|
-
* key: "0" -> [ 48 ]
|
|
7
|
-
* key: "0.0" -> [ 48, 46, 48 ]
|
|
8
|
-
* key: "0.1" -> [ 48, 46, 49 ]
|
|
9
|
-
*
|
|
10
|
-
* key: "bucket" -> [ 98, 117, 99, 107, 101, 116 ]
|
|
11
|
-
* key: "bucket.0" -> [ 98, 117, 99, 107, 101, 116, 46, 48 ]
|
|
12
|
-
* key: "bucket.1" -> [ 98, 117, 99, 107, 101, 116, 46, 49 ]
|
|
13
|
-
*/
|
|
14
|
-
export function toWorkspace(key) {
|
|
15
|
-
const encoder = new TextEncoder();
|
|
16
|
-
return Array.from(encoder.encode(key));
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* @param key workspace name
|
|
21
|
-
* @returns formatted Workspace data
|
|
22
|
-
* @example
|
|
23
|
-
* key: "bucket" -> { Workspace: [ 98, 117, 99, 107, 101, 116 ] }
|
|
24
|
-
*/
|
|
25
|
-
export function fromWorkspace(key) {
|
|
26
|
-
const encoder = new TextEncoder();
|
|
27
|
-
const encodedKey = encoder.encode(key);
|
|
28
|
-
return { Workspace: Array.from(encodedKey) };
|
|
29
|
-
}
|
package/dist/builders/index.d.ts
DELETED
package/dist/builders/index.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Builder, TariFunctionDefinition, TariMethodDefinition } from "../types/Builder";
|
|
2
|
-
import { ComponentAddress, ConfidentialClaim, ConfidentialWithdrawProof, Instruction, ResourceAddress, SubstateRequirement, Transaction, UnsignedTransaction } from "../types";
|
|
3
|
-
export declare class TransactionBuilder implements Builder {
|
|
4
|
-
private unsignedTransaction;
|
|
5
|
-
private signatures;
|
|
6
|
-
constructor();
|
|
7
|
-
callFunction<T extends TariFunctionDefinition>(func: T, args: Exclude<T["args"], undefined>): this;
|
|
8
|
-
callMethod<T extends TariMethodDefinition>(method: T, args: Exclude<T["args"], undefined>): this;
|
|
9
|
-
createAccount(ownerPublicKey: string, workspaceBucket?: string): this;
|
|
10
|
-
createProof(account: ComponentAddress, resourceAddress: ResourceAddress): this;
|
|
11
|
-
claimBurn(claim: ConfidentialClaim): this;
|
|
12
|
-
/**
|
|
13
|
-
* The `SaveVar` method replaces
|
|
14
|
-
* `PutLastInstructionOutputOnWorkspace: { key: Array<number> }`
|
|
15
|
-
* to make saving variables easier.
|
|
16
|
-
*/
|
|
17
|
-
saveVar(key: string): this;
|
|
18
|
-
/**
|
|
19
|
-
* Adds a fee instruction that calls the `take_fee` method on a component.
|
|
20
|
-
* This method must exist and return a Bucket with containing revealed confidential XTR resource.
|
|
21
|
-
* This allows the fee to originate from sources other than the transaction sender's account.
|
|
22
|
-
* The fee instruction will lock up the `max_fee` amount for the duration of the transaction.
|
|
23
|
-
*/
|
|
24
|
-
feeTransactionPayFromComponent(componentAddress: ComponentAddress, maxFee: string): this;
|
|
25
|
-
/**
|
|
26
|
-
* Adds a fee instruction that calls the `take_fee_confidential` method on a component.
|
|
27
|
-
* This method must exist and return a Bucket with containing revealed confidential XTR resource.
|
|
28
|
-
* This allows the fee to originate from sources other than the transaction sender's account.
|
|
29
|
-
*/
|
|
30
|
-
feeTransactionPayFromComponentConfidential(componentAddress: ComponentAddress, proof: ConfidentialWithdrawProof): this;
|
|
31
|
-
dropAllProofsInWorkspace(): this;
|
|
32
|
-
withUnsignedTransaction(unsignedTransaction: UnsignedTransaction): this;
|
|
33
|
-
withFeeInstructions(instructions: Instruction[]): this;
|
|
34
|
-
withFeeInstructionsBuilder(builder: (builder: TransactionBuilder) => TransactionBuilder): this;
|
|
35
|
-
addInstruction(instruction: Instruction): this;
|
|
36
|
-
addFeeInstruction(instruction: Instruction): this;
|
|
37
|
-
withInstructions(instructions: Instruction[]): this;
|
|
38
|
-
addInput(inputObject: SubstateRequirement): this;
|
|
39
|
-
withInputs(inputs: SubstateRequirement[]): this;
|
|
40
|
-
withMinEpoch(minEpoch: number): this;
|
|
41
|
-
withMaxEpoch(maxEpoch: number): this;
|
|
42
|
-
buildUnsignedTransaction(): UnsignedTransaction;
|
|
43
|
-
build(): Transaction;
|
|
44
|
-
}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
// Copyright 2024 The Tari Project
|
|
2
|
-
// SPDX-License-Identifier: BSD-3-Clause
|
|
3
|
-
import { toWorkspace } from "../helpers";
|
|
4
|
-
import { TransactionRequest } from "./TransactionRequest";
|
|
5
|
-
export class TransactionBuilder {
|
|
6
|
-
unsignedTransaction;
|
|
7
|
-
signatures;
|
|
8
|
-
constructor() {
|
|
9
|
-
this.unsignedTransaction = {
|
|
10
|
-
feeInstructions: [],
|
|
11
|
-
instructions: [],
|
|
12
|
-
inputs: [],
|
|
13
|
-
filledInputs: [],
|
|
14
|
-
minEpoch: undefined,
|
|
15
|
-
maxEpoch: undefined,
|
|
16
|
-
};
|
|
17
|
-
this.signatures = [];
|
|
18
|
-
}
|
|
19
|
-
callFunction(func, args) {
|
|
20
|
-
return this.addInstruction({
|
|
21
|
-
CallFunction: {
|
|
22
|
-
template_address: func.templateAddress,
|
|
23
|
-
function: func.functionName,
|
|
24
|
-
args,
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
callMethod(method, args) {
|
|
29
|
-
return this.addInstruction({
|
|
30
|
-
CallMethod: {
|
|
31
|
-
component_address: method.componentAddress,
|
|
32
|
-
method: method.methodName,
|
|
33
|
-
args,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
createAccount(ownerPublicKey, workspaceBucket) {
|
|
38
|
-
return this.addInstruction({
|
|
39
|
-
CreateAccount: {
|
|
40
|
-
owner_public_key: ownerPublicKey,
|
|
41
|
-
workspace_bucket: workspaceBucket ?? null,
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
createProof(account, resourceAddress) {
|
|
46
|
-
return this.addInstruction({
|
|
47
|
-
CallMethod: {
|
|
48
|
-
component_address: account,
|
|
49
|
-
method: "create_proof_for_resource",
|
|
50
|
-
args: [resourceAddress],
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
claimBurn(claim) {
|
|
55
|
-
return this.addInstruction({
|
|
56
|
-
ClaimBurn: {
|
|
57
|
-
claim,
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* The `SaveVar` method replaces
|
|
63
|
-
* `PutLastInstructionOutputOnWorkspace: { key: Array<number> }`
|
|
64
|
-
* to make saving variables easier.
|
|
65
|
-
*/
|
|
66
|
-
saveVar(key) {
|
|
67
|
-
return this.addInstruction({
|
|
68
|
-
PutLastInstructionOutputOnWorkspace: {
|
|
69
|
-
key: toWorkspace(key),
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Adds a fee instruction that calls the `take_fee` method on a component.
|
|
75
|
-
* This method must exist and return a Bucket with containing revealed confidential XTR resource.
|
|
76
|
-
* This allows the fee to originate from sources other than the transaction sender's account.
|
|
77
|
-
* The fee instruction will lock up the `max_fee` amount for the duration of the transaction.
|
|
78
|
-
*/
|
|
79
|
-
feeTransactionPayFromComponent(componentAddress, maxFee) {
|
|
80
|
-
return this.addFeeInstruction({
|
|
81
|
-
CallMethod: {
|
|
82
|
-
component_address: componentAddress,
|
|
83
|
-
method: "pay_fee",
|
|
84
|
-
args: [maxFee],
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Adds a fee instruction that calls the `take_fee_confidential` method on a component.
|
|
90
|
-
* This method must exist and return a Bucket with containing revealed confidential XTR resource.
|
|
91
|
-
* This allows the fee to originate from sources other than the transaction sender's account.
|
|
92
|
-
*/
|
|
93
|
-
feeTransactionPayFromComponentConfidential(componentAddress, proof) {
|
|
94
|
-
return this.addFeeInstruction({
|
|
95
|
-
CallMethod: {
|
|
96
|
-
component_address: componentAddress,
|
|
97
|
-
method: "pay_fee_confidential",
|
|
98
|
-
args: [proof],
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
dropAllProofsInWorkspace() {
|
|
103
|
-
return this.addInstruction("DropAllProofsInWorkspace");
|
|
104
|
-
}
|
|
105
|
-
withUnsignedTransaction(unsignedTransaction) {
|
|
106
|
-
this.unsignedTransaction = unsignedTransaction;
|
|
107
|
-
this.signatures = [];
|
|
108
|
-
return this;
|
|
109
|
-
}
|
|
110
|
-
withFeeInstructions(instructions) {
|
|
111
|
-
this.unsignedTransaction.feeInstructions = instructions;
|
|
112
|
-
this.signatures = [];
|
|
113
|
-
return this;
|
|
114
|
-
}
|
|
115
|
-
withFeeInstructionsBuilder(builder) {
|
|
116
|
-
const newBuilder = builder(new TransactionBuilder());
|
|
117
|
-
this.unsignedTransaction.feeInstructions = newBuilder.unsignedTransaction.instructions;
|
|
118
|
-
this.signatures = [];
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
addInstruction(instruction) {
|
|
122
|
-
this.unsignedTransaction.instructions.push(instruction);
|
|
123
|
-
this.signatures = [];
|
|
124
|
-
return this;
|
|
125
|
-
}
|
|
126
|
-
addFeeInstruction(instruction) {
|
|
127
|
-
this.unsignedTransaction.feeInstructions.push(instruction);
|
|
128
|
-
this.signatures = [];
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
|
-
withInstructions(instructions) {
|
|
132
|
-
this.unsignedTransaction.instructions.push(...instructions);
|
|
133
|
-
this.signatures = [];
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
136
|
-
addInput(inputObject) {
|
|
137
|
-
this.unsignedTransaction.inputs.push(inputObject);
|
|
138
|
-
this.signatures = [];
|
|
139
|
-
return this;
|
|
140
|
-
}
|
|
141
|
-
withInputs(inputs) {
|
|
142
|
-
this.unsignedTransaction.inputs.push(...inputs);
|
|
143
|
-
this.signatures = [];
|
|
144
|
-
return this;
|
|
145
|
-
}
|
|
146
|
-
withMinEpoch(minEpoch) {
|
|
147
|
-
this.unsignedTransaction.minEpoch = minEpoch;
|
|
148
|
-
// Reset the signatures as they are no longer valid
|
|
149
|
-
this.signatures = [];
|
|
150
|
-
return this;
|
|
151
|
-
}
|
|
152
|
-
withMaxEpoch(maxEpoch) {
|
|
153
|
-
this.unsignedTransaction.maxEpoch = maxEpoch;
|
|
154
|
-
// Reset the signatures as they are no longer valid
|
|
155
|
-
this.signatures = [];
|
|
156
|
-
return this;
|
|
157
|
-
}
|
|
158
|
-
buildUnsignedTransaction() {
|
|
159
|
-
return this.unsignedTransaction;
|
|
160
|
-
}
|
|
161
|
-
build() {
|
|
162
|
-
return new TransactionRequest(this.unsignedTransaction, this.signatures);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Epoch, Instruction, SubstateRequirement, Transaction, TransactionId, TransactionSignature, UnsignedTransaction, VersionedSubstateId } from "../types";
|
|
2
|
-
export declare class TransactionRequest implements Transaction {
|
|
3
|
-
id: TransactionId;
|
|
4
|
-
feeInstructions: Array<Instruction>;
|
|
5
|
-
instructions: Array<Instruction>;
|
|
6
|
-
inputs: Array<SubstateRequirement>;
|
|
7
|
-
signatures: Array<TransactionSignature>;
|
|
8
|
-
unsignedTransaction: UnsignedTransaction;
|
|
9
|
-
minEpoch?: Epoch;
|
|
10
|
-
maxEpoch?: Epoch;
|
|
11
|
-
filledInputs: VersionedSubstateId[];
|
|
12
|
-
constructor(unsignedTransaction: UnsignedTransaction, signatures: TransactionSignature[]);
|
|
13
|
-
private calculateHash;
|
|
14
|
-
withFilledInputs(filled_inputs: Array<VersionedSubstateId>): this;
|
|
15
|
-
getId(): TransactionId;
|
|
16
|
-
checkId(): boolean;
|
|
17
|
-
getUnsignedTransaction(): UnsignedTransaction;
|
|
18
|
-
getFeeInstructions(): Instruction[];
|
|
19
|
-
getInstructions(): Instruction[];
|
|
20
|
-
getSignatures(): TransactionSignature[];
|
|
21
|
-
getHash(): string;
|
|
22
|
-
getInputs(): SubstateRequirement[];
|
|
23
|
-
getFilledInputs(): VersionedSubstateId[];
|
|
24
|
-
getFilledInputsMut(): VersionedSubstateId[];
|
|
25
|
-
getMinEpoch(): Epoch | undefined;
|
|
26
|
-
getMaxEpoch(): Epoch | undefined;
|
|
27
|
-
}
|