@tari-project/tarijs-builders 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.
@@ -7,4 +7,4 @@ export declare function waitForTransactionResult(signer: TariSigner | TariUniver
7
7
  export declare function getAcceptResultSubstates(txResult: TransactionResult): {
8
8
  upSubstates: UpSubstates;
9
9
  downSubstates: DownSubstates;
10
- } | undefined;
10
+ };
@@ -1,4 +1,5 @@
1
1
  import { TransactionStatus, } from "@tari-project/tarijs-types";
2
+ import { getSubstateValueFromUpSubstates, substateIdToString, txResultCheck } from "@tari-project/tarijs-types";
2
3
  export function buildTransactionRequest(transaction, accountId, requiredSubstates, inputRefs = [], isDryRun = false, network = 0, isSealSignerAuthorized = true, detectInputsUseUnversioned = true) {
3
4
  return {
4
5
  network,
@@ -19,9 +20,27 @@ export async function submitAndWaitForTransaction(signer, req) {
19
20
  try {
20
21
  const response = await signer.submitTransaction(req);
21
22
  const result = await waitForTransactionResult(signer, response.transaction_id);
23
+ const { upSubstates, downSubstates } = getAcceptResultSubstates(result);
24
+ const newComponents = getSubstateValueFromUpSubstates("Component", upSubstates);
25
+ function getComponentForTemplate(templateAddress) {
26
+ for (const [substateId, substate] of upSubstates) {
27
+ if ("Component" in substate.substate) {
28
+ const templateAddr = substate.substate.Component.template_address;
29
+ const templateString = typeof templateAddr === "string" ? templateAddr : new TextDecoder().decode(templateAddr);
30
+ if (templateAddress === templateString) {
31
+ return substateIdToString(substateId);
32
+ }
33
+ }
34
+ }
35
+ return null;
36
+ }
22
37
  return {
23
38
  response,
24
39
  result,
40
+ upSubstates,
41
+ downSubstates,
42
+ newComponents,
43
+ getComponentForTemplate,
25
44
  };
26
45
  }
27
46
  catch (e) {
@@ -50,11 +69,14 @@ export async function waitForTransactionResult(signer, transactionId) {
50
69
  }
51
70
  export function getAcceptResultSubstates(txResult) {
52
71
  const result = txResult.result?.result;
53
- if (result && isAccept(result)) {
72
+ if (result && txResultCheck.isAcceptFeeRejectRest(result)) {
73
+ return {
74
+ upSubstates: result.AcceptFeeRejectRest[0].up_substates,
75
+ downSubstates: result.AcceptFeeRejectRest[0].down_substates,
76
+ };
77
+ }
78
+ if (result && txResultCheck.isAccept(result)) {
54
79
  return { upSubstates: result.Accept.up_substates, downSubstates: result.Accept.down_substates };
55
80
  }
56
- return undefined;
57
- }
58
- function isAccept(result) {
59
- return "Accept" in result;
81
+ return { upSubstates: [], downSubstates: [] };
60
82
  }
package/package.json CHANGED
@@ -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": {
@@ -11,8 +11,8 @@
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
13
  "@tari-project/tari-signer": "^0.5.3",
14
- "@tari-project/tarijs-types": "^0.5.3",
15
- "@tari-project/tari-universe-signer": "^0.5.3"
14
+ "@tari-project/tarijs-types": "^0.5.4",
15
+ "@tari-project/tari-universe-signer": "^0.5.4"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@types/node": "^22.13.1",