@tari-project/tarijs 0.11.0 → 0.12.1

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.
Files changed (39) hide show
  1. package/docusaurus/tari-docs/package.json +4 -4
  2. package/eslint.config.mjs +9 -0
  3. package/examples/vite-typescript-react/src/App.tsx +1 -1
  4. package/package.json +15 -2
  5. package/packages/builders/package.json +1 -1
  6. package/packages/builders/src/helpers/submitTransaction.ts +10 -35
  7. package/packages/builders/src/transaction/TransactionBuilder.ts +223 -17
  8. package/packages/indexer_provider/package.json +1 -1
  9. package/packages/metamask_signer/package.json +1 -1
  10. package/packages/metamask_signer/src/index.ts +1 -1
  11. package/packages/permissions/package.json +1 -1
  12. package/packages/react-mui-connect-button/package.json +1 -1
  13. package/packages/tari_provider/package.json +1 -1
  14. package/packages/tari_provider/src/TariProvider.ts +6 -1
  15. package/packages/tari_signer/package.json +1 -1
  16. package/packages/tari_universe/package.json +1 -1
  17. package/packages/tarijs/package.json +1 -1
  18. package/packages/tarijs/src/index.ts +27 -49
  19. package/packages/tarijs/src/templates/Account.ts +7 -4
  20. package/packages/tarijs/test/integration-tests/.env +1 -1
  21. package/packages/tarijs/test/integration-tests/wallet_daemon/json_rpc_provider.spec.ts +112 -73
  22. package/packages/tarijs/tsconfig.json +2 -2
  23. package/packages/tarijs/vitest.config.ts +2 -1
  24. package/packages/tarijs_types/package.json +3 -2
  25. package/packages/tarijs_types/src/Account.ts +68 -0
  26. package/packages/tarijs_types/src/Amount.ts +5 -1
  27. package/packages/tarijs_types/src/TransactionResult.ts +1 -8
  28. package/packages/tarijs_types/src/consts.ts +3 -0
  29. package/packages/tarijs_types/src/helpers/index.ts +4 -0
  30. package/packages/tarijs_types/src/helpers/simpleResult.ts +345 -0
  31. package/packages/tarijs_types/src/helpers/txResult.ts +1 -2
  32. package/packages/tarijs_types/src/index.ts +8 -0
  33. package/packages/tarijs_types/src/signer.ts +1 -1
  34. package/packages/wallet_daemon/package.json +1 -1
  35. package/packages/wallet_daemon/src/signer.ts +7 -2
  36. package/packages/walletconnect/package.json +1 -1
  37. package/packages/walletconnect/src/index.ts +2 -2
  38. package/pnpm-workspace.yaml +1 -1
  39. package/typedoc.json +10 -0
@@ -1,8 +1,8 @@
1
- import { MetaMaskInpageProvider } from "@metamask/providers";
2
- import { TariSigner } from "@tari-project/tari-signer";
3
- import { TariProvider } from "@tari-project/tari-provider";
4
- import { MetamaskTariSigner } from "@tari-project/metamask-signer";
5
- import {
1
+ export { MetaMaskInpageProvider } from "@metamask/providers";
2
+ export { TariSigner } from "@tari-project/tari-signer";
3
+ export { TariProvider } from "@tari-project/tari-provider";
4
+ export { MetamaskTariSigner } from "@tari-project/metamask-signer";
5
+ export {
6
6
  WalletDaemonTariSigner,
7
7
  WalletDaemonParameters,
8
8
  WalletDaemonFetchParameters,
@@ -10,16 +10,16 @@ import {
10
10
  TariPermissions,
11
11
  WalletDaemonTariProvider,
12
12
  } from "@tari-project/wallet-daemon-signer";
13
- import { TariUniverseSigner, TariUniverseSignerParameters } from "@tari-project/tari-universe-signer";
14
- import { WalletConnectTariSigner } from "@tari-project/wallet-connect-signer";
15
- import {
13
+ export { TariUniverseSigner, TariUniverseSignerParameters } from "@tari-project/tari-universe-signer";
14
+ export { WalletConnectTariSigner } from "@tari-project/wallet-connect-signer";
15
+ export {
16
16
  TransactionBuilder,
17
17
  TransactionRequest,
18
18
  buildTransactionRequest,
19
19
  submitAndWaitForTransaction,
20
20
  waitForTransactionResult,
21
21
  } from "@tari-project/tarijs-builders";
22
- import {
22
+ export {
23
23
  convertStringToTransactionStatus,
24
24
  convertHexStringToU256Array,
25
25
  convertU256ToHexString,
@@ -39,50 +39,28 @@ import {
39
39
  parseCbor,
40
40
  getCborValueByPath,
41
41
  } from "@tari-project/tarijs-types";
42
- import { IndexerProvider, IndexerProviderParameters } from "@tari-project/indexer-provider";
42
+ export { IndexerProvider, IndexerProviderParameters } from "@tari-project/indexer-provider";
43
+ export {
44
+ Amount,
45
+ BuiltInAccount,
46
+ VaultSubstate,
47
+ TransactionArg,
48
+ ConfidentialClaim,
49
+ ConfidentialOutput,
50
+ ConfidentialWithdrawProof,
51
+ SubstateType,
52
+ SimpleTransactionResult,
53
+ SimpleSubstateDiff,
54
+ AnySubstate,
55
+ DownSubstate,
56
+ UpSubstate,
57
+ TransactionSignature,
58
+ } from "@tari-project/tarijs-types";
59
+
43
60
  import * as templates from "./templates";
44
61
  import * as permissions from "@tari-project/tari-permissions";
45
62
 
46
- export * from "@tari-project/tarijs-types";
47
63
  export {
48
64
  permissions,
49
65
  templates,
50
- Network,
51
- TariSigner,
52
- TariProvider,
53
- AccountData,
54
- TransactionStatus,
55
- GetTransactionResultResponse,
56
- SubmitTransactionRequest,
57
- VaultBalances,
58
- VaultData,
59
- TemplateDefinition,
60
- MetamaskTariSigner,
61
- WalletDaemonTariSigner,
62
- WalletDaemonTariProvider,
63
- WalletDaemonParameters,
64
- WalletDaemonFetchParameters,
65
- WalletDaemonBaseParameters,
66
- TariUniverseSigner,
67
- TariUniverseSignerParameters,
68
- TariPermissions,
69
- MetaMaskInpageProvider,
70
- Substate,
71
- WalletConnectTariSigner,
72
- TransactionBuilder,
73
- TransactionRequest,
74
- IndexerProvider,
75
- IndexerProviderParameters,
76
- convertStringToTransactionStatus,
77
- buildTransactionRequest,
78
- submitAndWaitForTransaction,
79
- waitForTransactionResult,
80
- convertHexStringToU256Array,
81
- convertU256ToHexString,
82
- createNftAddressFromResource,
83
- createNftAddressFromToken,
84
- parseCbor,
85
- getCborValueByPath,
86
- fromHexString,
87
- toHexString,
88
66
  };
@@ -1,10 +1,10 @@
1
1
  import { ConfidentialWithdrawProof, NonFungibleId, ResourceAddress } from "@tari-project/typescript-bindings";
2
2
  import { Amount } from "@tari-project/tarijs-types";
3
- import { TariMethodDefinition, WorkspaceArg } from "@tari-project/tarijs-builders";
3
+ import { TariMethodDefinition, WorkspaceArg } from "@tari-project/tarijs-builders";
4
4
  import { TemplateFactory } from "./TemplateFactory";
5
5
 
6
6
  /**
7
- * Adds a fee instruction that calls the "take_fee" method on a component.
7
+ * Adds a fee instruction that calls the "pay_fee" method on a component.
8
8
  * This method must exist and return a Bucket with containing revealed confidential XTR resource.
9
9
  * This allows the fee to originate from sources other than the transaction sender's account.
10
10
  * The fee instruction will lock up the "max_fee" amount for the duration of the transaction.
@@ -16,8 +16,9 @@ interface PayFeeMethod extends TariMethodDefinition {
16
16
  methodName: "pay_fee";
17
17
  args?: [Amount];
18
18
  }
19
+
19
20
  // /**
20
- // * Adds a fee instruction that calls the "take_fee_confidential" method on a component.
21
+ // * Adds a fee instruction that calls the "pay_fee_confidential" method on a component.
21
22
  // * This method must exist and return a Bucket with containing revealed confidential XTR resource.
22
23
  // * This allows the fee to originate from sources other than the transaction sender's account.
23
24
  // * @param componentAddress
@@ -81,7 +82,9 @@ export class AccountTemplate extends TemplateFactory {
81
82
  this._initMethods();
82
83
  }
83
84
 
84
- protected _initFunctions(): void {}
85
+ protected _initFunctions(): void {
86
+ }
87
+
85
88
  protected _initMethods(): void {
86
89
  this.deposit = this._defineMethod<DepositMethod>("deposit");
87
90
  this.withdraw = this._defineMethod<WithdrawMethod>("withdraw");
@@ -1 +1 @@
1
- WALLET_DAEMON_JSON_RPC_URL=http://127.0.0.1:9000/json_rpc
1
+ WALLET_DAEMON_JSON_RPC_URL=http://127.0.0.1:12008/json_rpc
@@ -1,18 +1,15 @@
1
1
  import { assert, describe, expect, it } from "vitest";
2
-
3
2
  import {
4
- Amount,
5
- buildTransactionRequest,
6
- Network,
7
- submitAndWaitForTransaction,
8
- SubmitTransactionRequest,
9
3
  TariPermissions,
10
4
  TransactionBuilder,
11
- TransactionStatus,
12
- waitForTransactionResult,
13
5
  WalletDaemonTariSigner,
6
+ Amount, Network, SubmitTransactionRequest, TransactionStatus,
7
+ submitAndWaitForTransaction,
8
+ buildTransactionRequest,
9
+ waitForTransactionResult,
14
10
  } from "../../../src";
15
- import { Instruction, SubstateId } from "@tari-project/typescript-bindings";
11
+ import { Instruction } from "@tari-project/typescript-bindings";
12
+ import { XTR } from "@tari-project/tarijs-types";
16
13
 
17
14
  function buildSigner(): Promise<WalletDaemonTariSigner> {
18
15
  const permissions = new TariPermissions().addPermission("Admin");
@@ -81,10 +78,14 @@ describe("WalletDaemonTariSigner", () => {
81
78
  const signer = await buildSigner();
82
79
 
83
80
  const id = "d5f5a26e7272b1bba7bed331179e555e28c40d92ba3cde1e9ba2b4316e50f486";
84
- const txResult = await signer.getTransactionResult(id);
85
- expect(txResult).toMatchObject({
86
- transaction_id: id,
87
- });
81
+ try {
82
+ const txResult = await signer.getTransactionResult(id);
83
+ expect(txResult).toMatchObject({
84
+ transaction_id: id,
85
+ });
86
+ } catch (e) {
87
+ console.warn("Skipping getTransactionResult test, transaction not found", e);
88
+ }
88
89
  });
89
90
  });
90
91
 
@@ -98,7 +99,7 @@ describe("WalletDaemonTariSigner", () => {
98
99
  const fee_instructions = [
99
100
  {
100
101
  CallMethod: {
101
- component_address: account.address,
102
+ call: { Address: account.address },
102
103
  method: "pay_fee",
103
104
  args: [`Amount(${fee})`],
104
105
  },
@@ -157,34 +158,80 @@ describe("WalletDaemonTariSigner", () => {
157
158
  expect(txResult.status).toEqual(TransactionStatus.DryRun);
158
159
  });
159
160
 
160
- it("submits a transaction, that uses workspaces", async () => {
161
- const workspaceId = "bucket";
161
+
162
+ it("creates an account", async () => {
162
163
  const signer = await buildSigner();
163
164
  const account = await signer.getAccount();
164
- const xtrAddress = account.resources[0].resource_address;
165
+ const nextKey = await signer.newTransactionKey();
165
166
 
166
- const fee = new Amount(2000);
167
- const network = Network.LocalNet;
168
- const builder = new TransactionBuilder(network);
169
- builder.feeTransactionPayFromComponent(account.address, fee.getStringValue());
167
+ const fee = Amount.of(2000);
168
+ const transaction1 = TransactionBuilder
169
+ .new(Network.LocalNet)
170
+ .feeTransactionPayFromComponent(account.address, fee)
171
+ .createAccount(nextKey)
172
+ .buildUnsignedTransaction();
170
173
 
171
- builder.callMethod(
172
- {
173
- componentAddress: account.address,
174
- methodName: "withdraw",
175
- },
176
- [xtrAddress, 10],
174
+ const submitTransactionRequest1 = buildTransactionRequest(
175
+ transaction1,
176
+ account.account_id,
177
177
  );
178
- builder.saveVar(workspaceId);
179
- builder.callMethod(
180
- {
181
- componentAddress: account.address,
182
- methodName: "deposit",
183
- },
184
- [workspaceId],
178
+
179
+ const txResult1 = await submitAndWaitForTransaction(signer, submitTransactionRequest1);
180
+ expect(txResult1.status).toBe(TransactionStatus.Accepted);
181
+ const newAccountId = txResult1.getResultingAccounts()[0].substate_id;
182
+
183
+ const transaction = TransactionBuilder
184
+ .new(Network.LocalNet)
185
+ .feeTransactionPayFromComponent(account.address, fee)
186
+ .callMethod({ componentAddress: account.address, methodName: "withdraw" }, [XTR, 10])
187
+ .saveVar("bucket")
188
+ .callMethod(
189
+ { componentAddress: newAccountId, methodName: "deposit" },
190
+ [{ Workspace: "bucket" }],
191
+ )
192
+ .buildUnsignedTransaction();
193
+
194
+ const submitTransactionRequest = buildTransactionRequest(
195
+ transaction,
196
+ account.account_id,
185
197
  );
186
- builder.addInput({ substate_id: { Component: account.address }, version: null });
187
- const transaction = builder.buildUnsignedTransaction();
198
+
199
+ const txResult = await submitAndWaitForTransaction(signer, submitTransactionRequest);
200
+ const vaults = txResult.getResultingVaults();
201
+ expect(vaults.length).toBe(2); // Original vault + new vault
202
+ // Find the vault not in the fee account
203
+ const vault = vaults.find((v) => !account.vaults.some((av) => v.id == av.vault_id));
204
+ expect(vault).toBeDefined();
205
+ expect(vault!.balance.value).toBe(BigInt(10));
206
+ });
207
+
208
+ it("submits a transaction, that uses workspaces", async () => {
209
+ const signer = await buildSigner();
210
+ const account = await signer.getAccount();
211
+ const xtrAddress = account.vaults[0].resource_address;
212
+
213
+ const fee = new Amount(2000);
214
+ const network = Network.LocalNet;
215
+ const transaction = TransactionBuilder
216
+ .new(network)
217
+ .feeTransactionPayFromComponent(account.address, fee)
218
+ .callMethod(
219
+ {
220
+ componentAddress: account.address,
221
+ methodName: "withdraw",
222
+ },
223
+ [xtrAddress, 10],
224
+ )
225
+ .saveVar("bucket")
226
+ .callMethod(
227
+ {
228
+ componentAddress: account.address,
229
+ methodName: "deposit",
230
+ },
231
+ [{ Workspace: "bucket" }],
232
+ )
233
+ .addInput({ substate_id: account.address, version: null })
234
+ .buildUnsignedTransaction();
188
235
 
189
236
  const submitTransactionRequest = buildTransactionRequest(
190
237
  transaction,
@@ -192,7 +239,7 @@ describe("WalletDaemonTariSigner", () => {
192
239
  );
193
240
 
194
241
  const txResult = await submitAndWaitForTransaction(signer, submitTransactionRequest);
195
- expect(txResult.result.status).toBe(TransactionStatus.Accepted);
242
+ expect(txResult.status).toBe(TransactionStatus.Accepted);
196
243
  });
197
244
  });
198
245
 
@@ -216,7 +263,7 @@ describe("WalletDaemonTariSigner", () => {
216
263
  expect(accountBalances.balances.length).toBeGreaterThan(0);
217
264
 
218
265
  expect(accountBalances.balances[0]).toMatchObject({
219
- balance: expect.any(Number),
266
+ balance: expect.any(String),
220
267
  resource_address: expect.any(String),
221
268
  resource_type: expect.any(String),
222
269
  token_symbol: expect.any(String),
@@ -271,7 +318,11 @@ describe("WalletDaemonTariSigner", () => {
271
318
  });
272
319
 
273
320
  const substateWithTemplate = substates.find((substate) => substate.template_address);
274
- assert(substateWithTemplate, "No substate with template found");
321
+ if (!substateWithTemplate) {
322
+ // This depends on a certain setup - so if we dont have this precondition, we skip the test
323
+ console.warn("No substate with template found, skipping test");
324
+ return;
325
+ }
275
326
 
276
327
  const templateAddress = substateWithTemplate.template_address;
277
328
  const { substates: filteredSubstates } = await signer.listSubstates({
@@ -302,32 +353,22 @@ describe("WalletDaemonTariSigner", () => {
302
353
  const signer = await buildSigner();
303
354
  const account = await signer.getAccount();
304
355
 
305
- const fee = new Amount(2000);
306
- const builder = new TransactionBuilder();
307
- builder.feeTransactionPayFromComponent(account.address, fee.getStringValue());
308
- builder.allocateAddress("Component", "id-1");
309
- const transaction = builder.build();
356
+ const fee = Amount.of(2000);
357
+ const transaction = TransactionBuilder.new(Network.LocalNet)
358
+ .feeTransactionPayFromComponent(account.address, fee)
359
+ .allocateAddress("Component", "id-1")
360
+ .buildUnsignedTransaction();
310
361
 
311
- const isDryRun = false;
312
- const inputRefs = undefined;
313
- const network = Network.LocalNet;
314
- const requiredSubstates = [{ substate_id: account.address }];
315
362
  const submitTransactionRequest = buildTransactionRequest(
316
363
  transaction,
317
364
  account.account_id,
318
- requiredSubstates,
319
- inputRefs,
320
- isDryRun,
321
- network,
322
365
  );
323
366
 
324
367
  const txResult = await submitAndWaitForTransaction(signer, submitTransactionRequest);
325
368
 
326
- expect(txResult.result.status).toBe(TransactionStatus.OnlyFeeAccepted);
369
+ expect(txResult.status).toBe(TransactionStatus.OnlyFeeAccepted);
327
370
 
328
- const executionResult = txResult.result.result?.result;
329
- const reason =
330
- executionResult && "AcceptFeeRejectRest" in executionResult && executionResult.AcceptFeeRejectRest[1];
371
+ const reason = txResult.anyRejectReason.unwrap();
331
372
  const failure = reason && typeof reason === "object" && "ExecutionFailure" in reason && reason.ExecutionFailure;
332
373
  expect(failure).toEqual("1 dangling address allocations remain after transaction execution");
333
374
  });
@@ -339,33 +380,31 @@ describe("WalletDaemonTariSigner", () => {
339
380
  const account = await signer.getAccount();
340
381
 
341
382
  const fee = new Amount(2000);
342
- const builder = new TransactionBuilder();
343
- builder.feeTransactionPayFromComponent(account.address, fee.getStringValue());
344
- builder.assertBucketContains("not_exist", "resource_0000000000000000000000000000000000000000000000000000000000000000", Amount.newAmount(1));
345
- const transaction = builder.build();
383
+ const transaction = TransactionBuilder.new(Network.LocalNet)
384
+ .feeTransactionPayFromComponent(account.address, fee)
385
+ // Have to use add instruction to submit the transaction since this error is caught by the builder
386
+ // .assertBucketContains("not_exist", "resource_0000000000000000000000000000000000000000000000000000000000000000", Amount.of(1))
387
+ .addInstruction({
388
+ AssertBucketContains: {
389
+ key: { id: 123, offset: null },
390
+ resource_address: "resource_0000000000000000000000000000000000000000000000000000000000000000",
391
+ min_amount: 1,
392
+ },
393
+ })
394
+ .buildUnsignedTransaction();
346
395
 
347
- const isDryRun = false;
348
- const inputRefs = undefined;
349
- const network = Network.LocalNet;
350
- const requiredSubstates = [{ substate_id: account.address }];
351
396
  const submitTransactionRequest = buildTransactionRequest(
352
397
  transaction,
353
398
  account.account_id,
354
- requiredSubstates,
355
- inputRefs,
356
- isDryRun,
357
- network,
358
399
  );
359
400
 
360
401
  const txResult = await submitAndWaitForTransaction(signer, submitTransactionRequest);
361
402
 
362
- expect(txResult.result.status).toBe(TransactionStatus.OnlyFeeAccepted);
403
+ expect(txResult.status).toBe(TransactionStatus.OnlyFeeAccepted);
363
404
 
364
- const executionResult = txResult.result.result?.result;
365
- const reason =
366
- executionResult && "AcceptFeeRejectRest" in executionResult && executionResult.AcceptFeeRejectRest[1];
405
+ const reason = txResult.anyRejectReason.unwrap();
367
406
  const failure = reason && typeof reason === "object" && "ExecutionFailure" in reason && reason.ExecutionFailure;
368
- expect(failure).toContain("Item at id 0 does not exist on the workspace");
407
+ expect(failure).toContain("Item at id 123 does not exist on the workspace (existing ids: [])");
369
408
  });
370
409
  });
371
410
  });
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
- "module": "ES2020",
5
- "target": "ESNext",
4
+ "module": "ES2022",
5
+ "target": "ES2022",
6
6
  "moduleResolution": "Bundler",
7
7
  "outDir": "./dist",
8
8
  "rootDir": "./src"
@@ -4,6 +4,7 @@ import { loadEnv } from "vite";
4
4
  export default defineConfig({
5
5
  root: ".",
6
6
  test: {
7
- env: loadEnv("", "./integration-tests/", ""),
7
+ // Not sure why this doesnt work
8
+ env: loadEnv("", process.cwd() + "/test/integration-tests/", ""),
8
9
  },
9
10
  });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tari-project/tarijs-types",
3
- "version": "0.11.0",
3
+ "version": "0.12.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -13,7 +13,8 @@
13
13
  "author": "The Tari Community",
14
14
  "license": "ISC",
15
15
  "dependencies": {
16
- "@tari-project/typescript-bindings": "catalog:"
16
+ "@tari-project/typescript-bindings": "catalog:",
17
+ "@thames/monads": "^0.7.0"
17
18
  },
18
19
  "devDependencies": {
19
20
  "@types/node": "catalog:",
@@ -0,0 +1,68 @@
1
+ import { BigAmount, ResourceAddress, ResourceType, Vault, VaultId } from "@tari-project/typescript-bindings";
2
+
3
+ export interface BuiltInAccount {
4
+ vaults: Record<ResourceAddress, VaultSubstate>;
5
+ }
6
+
7
+ export class VaultSubstate {
8
+ private vaultId: VaultId;
9
+ private vault: Vault;
10
+
11
+ constructor(vaultId: VaultId, vault: Vault) {
12
+ this.vaultId = vaultId;
13
+ this.vault = vault;
14
+ }
15
+
16
+ public static new(vaultId: VaultId, vault: Vault): VaultSubstate {
17
+ return new VaultSubstate(vaultId, vault);
18
+ }
19
+
20
+ public get id(): VaultId {
21
+ return this.vaultId;
22
+ }
23
+
24
+ public get rawVault(): Vault {
25
+ return this.vault;
26
+ }
27
+
28
+ public get resourceType(): ResourceType {
29
+ if ("Fungible" in this.vault.resource_container) {
30
+ return "Fungible";
31
+ }
32
+ if ("NonFungible" in this.vault.resource_container) {
33
+ return "NonFungible";
34
+ }
35
+ if ("Confidential" in this.vault.resource_container) {
36
+ return "Confidential";
37
+ }
38
+ throw new Error("Unknown resource type in vault");
39
+ }
40
+
41
+ public get balance(): BigAmount {
42
+ if ("Fungible" in this.vault.resource_container) {
43
+ return BigAmount.from(this.vault.resource_container.Fungible.amount);
44
+ }
45
+ if ("NonFungible" in this.vault.resource_container) {
46
+ return BigAmount.from(this.vault.resource_container.NonFungible.token_ids.length);
47
+ }
48
+ if ("Confidential" in this.vault.resource_container) {
49
+ return BigAmount.from(this.vault.resource_container.Confidential.revealed_amount);
50
+ }
51
+ throw new Error("Unknown resource type in vault");
52
+ }
53
+
54
+ public get resourceAddress(): ResourceAddress {
55
+ if ("Fungible" in this.vault.resource_container) {
56
+ return this.vault.resource_container.Fungible.address;
57
+ }
58
+ if ("NonFungible" in this.vault.resource_container) {
59
+ return this.vault.resource_container.NonFungible.address;
60
+ }
61
+ if ("Confidential" in this.vault.resource_container) {
62
+ return this.vault.resource_container.Confidential.address;
63
+ }
64
+ throw new Error("Unknown resource type in vault");
65
+ }
66
+
67
+ // TODO: add other quality of life helpers e.g balances
68
+ }
@@ -7,7 +7,7 @@ export class Amount {
7
7
 
8
8
  public static readonly MAX: Amount = new Amount(Number.MAX_SAFE_INTEGER);
9
9
 
10
- public static newAmount(amount: number): Amount {
10
+ public static of(amount: number): Amount {
11
11
  return new Amount(amount);
12
12
  }
13
13
 
@@ -110,4 +110,8 @@ export class Amount {
110
110
  }
111
111
  return this.value as number;
112
112
  }
113
+
114
+ public toJSON(): number {
115
+ return this.value;
116
+ }
113
117
  }
@@ -1,6 +1,5 @@
1
- import { TransactionStatus } from "./TransactionStatus";
2
1
  import { DownSubstates, UpSubstates } from "./SubstateDiff";
3
- import { ComponentAddress, FinalizeResult, TransactionResult } from "@tari-project/typescript-bindings";
2
+ import { ComponentAddress, TransactionResult } from "@tari-project/typescript-bindings";
4
3
 
5
4
  export type SubmitTransactionResponse = {
6
5
  transaction_id: string;
@@ -15,9 +14,3 @@ export interface SubmitTxResult {
15
14
 
16
15
  getComponentForTemplate(templateAddress: string): ComponentAddress | null;
17
16
  }
18
-
19
- export type TransactionResultResponse = {
20
- transaction_id: string;
21
- status: TransactionStatus;
22
- result: FinalizeResult | null;
23
- };
@@ -0,0 +1,3 @@
1
+ export const ACCOUNT_TEMPLATE_ADDRESS = "0000000000000000000000000000000000000000000000000000000000000000";
2
+ export const TARI_RESOURCE = "resource_0101010101010101010101010101010101010101010101010101010101010101";
3
+ export const XTR = TARI_RESOURCE;
@@ -1,8 +1,12 @@
1
1
  import { NonFungibleId, NonFungibleToken, ResourceAddress } from "@tari-project/typescript-bindings";
2
2
  import { TransactionStatus } from "../TransactionStatus";
3
+
3
4
  export { fromHexString, toHexString } from "./hexString";
4
5
  export { txResultCheck, getSubstateValueFromUpSubstates, getComponentsForTemplate } from "./txResult";
5
6
  export { BinaryTag, CborValue, convertTaggedValue, getCborValueByPath, parseCbor } from "./cbor";
7
+ export {
8
+ SimpleSubstateDiff, SimpleTransactionResult, AnySubstate, UpSubstate, DownSubstate, splitOnce,
9
+ } from "./simpleResult";
6
10
  export {
7
11
  substateIdToString,
8
12
  stringToSubstateId,