@tari-project/tarijs 0.5.3 → 0.5.4

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.
@@ -16,10 +16,6 @@ npm install @tari-project/wallet-connect-signer
16
16
 
17
17
  Establishing connection requires multiple steps.
18
18
 
19
- ## Obtain WalletConnect Project ID
20
-
21
- Obtain a WalletConnect Project ID by registering your project on the WalletConnect Cloud. This ID is then used to connect your dApp to the WalletConnect infrastructure, facilitating communication between the dApp and user wallets.
22
-
23
19
  ## Request a connection and display wallet connect dialog
24
20
 
25
21
  ```js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tari-project/tarijs",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "keywords": [],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tari-project/tarijs-builders",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -6,12 +6,12 @@ import {
6
6
  TransactionStatus,
7
7
  DownSubstates,
8
8
  UpSubstates,
9
- FinalizeResultStatus,
10
- TxResultAccept,
11
9
  SubmitTxResult,
12
10
  ReqSubstate,
13
11
  SubmitTransactionRequest,
12
+ ComponentAddress,
14
13
  } from "@tari-project/tarijs-types";
14
+ import { getSubstateValueFromUpSubstates, substateIdToString, txResultCheck } from "@tari-project/tarijs-types";
15
15
 
16
16
  export function buildTransactionRequest(
17
17
  transaction: Transaction,
@@ -46,10 +46,30 @@ export async function submitAndWaitForTransaction(
46
46
  try {
47
47
  const response = await signer.submitTransaction(req);
48
48
  const result = await waitForTransactionResult(signer, response.transaction_id);
49
+ const { upSubstates, downSubstates } = getAcceptResultSubstates(result);
50
+ const newComponents = getSubstateValueFromUpSubstates("Component", upSubstates);
51
+
52
+ function getComponentForTemplate(templateAddress: string): ComponentAddress | null {
53
+ for (const [substateId, substate] of upSubstates) {
54
+ if ("Component" in substate.substate) {
55
+ const templateAddr = substate.substate.Component.template_address;
56
+ const templateString =
57
+ typeof templateAddr === "string" ? templateAddr : new TextDecoder().decode(templateAddr);
58
+ if (templateAddress === templateString) {
59
+ return substateIdToString(substateId);
60
+ }
61
+ }
62
+ }
63
+ return null;
64
+ }
49
65
 
50
66
  return {
51
67
  response,
52
68
  result,
69
+ upSubstates,
70
+ downSubstates,
71
+ newComponents,
72
+ getComponentForTemplate,
53
73
  };
54
74
  } catch (e) {
55
75
  throw new Error(`Transaction failed: ${e}`);
@@ -81,17 +101,20 @@ export async function waitForTransactionResult(
81
101
  }
82
102
  }
83
103
 
84
- export function getAcceptResultSubstates(
85
- txResult: TransactionResult,
86
- ): { upSubstates: UpSubstates; downSubstates: DownSubstates } | undefined {
104
+ export function getAcceptResultSubstates(txResult: TransactionResult): {
105
+ upSubstates: UpSubstates;
106
+ downSubstates: DownSubstates;
107
+ } {
87
108
  const result = txResult.result?.result;
88
109
 
89
- if (result && isAccept(result)) {
110
+ if (result && txResultCheck.isAcceptFeeRejectRest(result)) {
111
+ return {
112
+ upSubstates: result.AcceptFeeRejectRest[0].up_substates,
113
+ downSubstates: result.AcceptFeeRejectRest[0].down_substates,
114
+ };
115
+ }
116
+ if (result && txResultCheck.isAccept(result)) {
90
117
  return { upSubstates: result.Accept.up_substates, downSubstates: result.Accept.down_substates };
91
118
  }
92
- return undefined;
93
- }
94
-
95
- function isAccept(result: FinalizeResultStatus): result is TxResultAccept {
96
- return "Accept" in result;
119
+ return { upSubstates: [], downSubstates: [] };
97
120
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tari-project/tari-universe-signer",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -75,7 +75,7 @@ export class TariUniverseSigner implements TariSigner {
75
75
  });
76
76
  }
77
77
 
78
- public async createFreeTestCoins(): Promise<void> {
78
+ public async createFreeTestCoins(): Promise<AccountData> {
79
79
  return this.sendRequest({ methodName: "createFreeTestCoins", args: [] });
80
80
  }
81
81
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tari-project/tarijs-all",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tari-project/tarijs-types",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -1,5 +1,7 @@
1
1
  import { TransactionStatus } from "./TransactionStatus";
2
2
  import { FinalizeResult } from "./FinalizeResult";
3
+ import { DownSubstates, UpSubstates } from "./SubstateDiff";
4
+ import { ComponentAddress } from "@tari-project/typescript-bindings";
3
5
 
4
6
  export type SubmitTransactionResponse = {
5
7
  transaction_id: string;
@@ -8,6 +10,10 @@ export type SubmitTransactionResponse = {
8
10
  export interface SubmitTxResult {
9
11
  response: SubmitTransactionResponse;
10
12
  result: TransactionResult;
13
+ upSubstates: UpSubstates;
14
+ downSubstates: DownSubstates;
15
+ newComponents: UpSubstates;
16
+ getComponentForTemplate(templateAddress: string): ComponentAddress | null;
11
17
  }
12
18
 
13
19
  export type TransactionResult = {
@@ -15,3 +21,9 @@ export type TransactionResult = {
15
21
  status: TransactionStatus;
16
22
  result: FinalizeResult | null;
17
23
  };
24
+
25
+ export type TransactionResultResponse = {
26
+ transaction_id: string;
27
+ status: TransactionStatus;
28
+ result: FinalizeResult | null;
29
+ };
@@ -1,6 +1,7 @@
1
1
  import { NonFungibleId, NonFungibleToken, ResourceAddress } from "@tari-project/typescript-bindings";
2
2
  import { TransactionStatus } from "../TransactionStatus";
3
3
  export { fromHexString, toHexString } from "./hexString";
4
+ export { txResultCheck, getSubstateValueFromUpSubstates, getComponentsForTemplate } from "./txResult";
4
5
  export { BinaryTag, CborValue, convertTaggedValue, getCborValueByPath, parseCbor } from "./cbor";
5
6
  export {
6
7
  substateIdToString,
@@ -0,0 +1,75 @@
1
+ import {
2
+ SubstateDiff,
3
+ VaultId,
4
+ Vault,
5
+ SubstateId,
6
+ SubstateValue,
7
+ ResourceContainer,
8
+ ResourceAddress,
9
+ Amount,
10
+ RejectReason,
11
+ substateIdToString,
12
+ ComponentAddress,
13
+ } from "@tari-project/typescript-bindings";
14
+ import { FinalizeResultStatus } from "../FinalizeResult";
15
+ import { UpSubstates } from "../SubstateDiff";
16
+
17
+ function isOfType<T extends object>(obj: T, key: keyof T): boolean {
18
+ return obj !== null && typeof obj === "object" && key in obj;
19
+ }
20
+
21
+ export const txResultCheck = {
22
+ isAccept: (result: FinalizeResultStatus): result is { Accept: SubstateDiff } => {
23
+ return "Accept" in result;
24
+ },
25
+
26
+ isVaultId: (substateId: SubstateId): substateId is { Vault: VaultId } => {
27
+ return isOfType(substateId, "Vault" as keyof SubstateId);
28
+ },
29
+
30
+ isVaultSubstate: (substate: SubstateValue): substate is { Vault: Vault } => {
31
+ return "Vault" in substate;
32
+ },
33
+
34
+ isFungible: (
35
+ resourceContainer: ResourceContainer,
36
+ ): resourceContainer is { Fungible: { address: ResourceAddress; amount: Amount; locked_amount: Amount } } => {
37
+ return "Fungible" in resourceContainer;
38
+ },
39
+
40
+ isReject: (result: FinalizeResultStatus): result is { Reject: RejectReason } => {
41
+ return "Reject" in result;
42
+ },
43
+ isAcceptFeeRejectRest: (
44
+ result: FinalizeResultStatus,
45
+ ): result is { AcceptFeeRejectRest: [SubstateDiff, RejectReason] } => {
46
+ return "AcceptFeeRejectRest" in result;
47
+ },
48
+ };
49
+
50
+ export function getSubstateValueFromUpSubstates(
51
+ substateType: keyof SubstateValue | string,
52
+ upSubstates: UpSubstates,
53
+ ): UpSubstates {
54
+ const components: UpSubstates = [];
55
+ for (const [substateId, substate] of upSubstates) {
56
+ if (substateType in substate.substate) {
57
+ components.push([substateId, substate]);
58
+ }
59
+ }
60
+ return components;
61
+ }
62
+
63
+ export function getComponentsForTemplate(templateAddress: string, upSubstates: UpSubstates): ComponentAddress[] | null {
64
+ const components: ComponentAddress[] = [];
65
+ const templateAddressBytes = new TextEncoder().encode(templateAddress);
66
+ for (const [substateId, substate] of upSubstates) {
67
+ if ("Component" in substate.substate) {
68
+ const componentHeader = substate.substate.Component;
69
+ if (componentHeader.template_address === templateAddressBytes) {
70
+ components.push(substateIdToString(substateId));
71
+ }
72
+ }
73
+ }
74
+ return components;
75
+ }
@@ -16,7 +16,12 @@ export { Instruction } from "./Instruction";
16
16
  export { Transaction } from "./Transaction";
17
17
  export { SubstateDiff, DownSubstates, UpSubstates } from "./SubstateDiff";
18
18
  export { SubstateRequirement } from "./SubstateRequirement";
19
- export { TransactionResult, SubmitTxResult, SubmitTransactionResponse } from "./TransactionResult";
19
+ export {
20
+ TransactionResult,
21
+ SubmitTxResult,
22
+ SubmitTransactionResponse,
23
+ TransactionResultResponse,
24
+ } from "./TransactionResult";
20
25
  export { TransactionSignature } from "./TransactionSignature";
21
26
  export { TransactionStatus } from "./TransactionStatus";
22
27
  export { UnsignedTransaction } from "./UnsignedTransaction";
@@ -57,6 +62,9 @@ export {
57
62
  convertTaggedValue,
58
63
  getCborValueByPath,
59
64
  parseCbor,
65
+ getSubstateValueFromUpSubstates,
66
+ getComponentsForTemplate,
67
+ txResultCheck,
60
68
  BinaryTag,
61
69
  CborValue,
62
70
  } from "./helpers";
@@ -8,8 +8,8 @@ catalog:
8
8
  vitest: ^3.0.4
9
9
  vite: ^6.1.0
10
10
  "@types/node": ^22.13.1
11
- "@tari-project/typescript-bindings": ^1.5.1
12
- "@tari-project/wallet_jrpc_client": ^1.5.1
11
+ "@tari-project/typescript-bindings": ^1.5.2
12
+ "@tari-project/wallet_jrpc_client": ^1.5.2
13
13
  "@metamask/providers": ^18.2.0
14
14
  "@walletconnect/universal-provider": ^2.13.3
15
15
  "@walletconnect/modal": ^2.6.2