@tari-project/tarijs-builders 0.12.1 → 0.12.2

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.
@@ -5,6 +5,7 @@ import { DownSubstates, UpSubstates, SubmitTransactionRequest, SimpleTransaction
5
5
  export declare function buildTransactionRequest(transaction: UnsignedTransactionV1, accountId: number, detectInputsUseUnversioned?: boolean): SubmitTransactionRequest;
6
6
  export declare function submitAndWaitForTransaction(signer: TariSigner, req: SubmitTransactionRequest): Promise<SimpleTransactionResult>;
7
7
  export declare function waitForTransactionResult(signer: TariSigner | TariUniverseSigner, transactionId: string): Promise<SimpleTransactionResult>;
8
+ /** @public */
8
9
  export declare function getAcceptResultSubstates(txResult: TransactionResult): {
9
10
  upSubstates: UpSubstates;
10
11
  downSubstates: DownSubstates;
@@ -16,7 +16,6 @@ export async function submitAndWaitForTransaction(signer, req) {
16
16
  }
17
17
  }
18
18
  export async function waitForTransactionResult(signer, transactionId) {
19
- // eslint-disable-next-line no-constant-condition
20
19
  while (true) {
21
20
  const resp = await signer.getTransactionResult(transactionId);
22
21
  const FINALIZED_STATUSES = [
@@ -29,6 +28,9 @@ export async function waitForTransactionResult(signer, transactionId) {
29
28
  if (resp.status == TransactionStatus.Rejected) {
30
29
  throw new Error(`Transaction rejected: ${JSON.stringify(resp.result)}`);
31
30
  }
31
+ if (!resp.result?.result) {
32
+ throw new Error(`Transaction finalized but the result is undefined`);
33
+ }
32
34
  if (FINALIZED_STATUSES.includes(resp.status)) {
33
35
  if (!resp.result) {
34
36
  throw new Error(`BUG: Transaction result is empty for transaction ID: ${transactionId}`);
@@ -38,16 +40,17 @@ export async function waitForTransactionResult(signer, transactionId) {
38
40
  await new Promise((resolve) => setTimeout(resolve, 500));
39
41
  }
40
42
  }
43
+ /** @public */
41
44
  export function getAcceptResultSubstates(txResult) {
45
+ if ("Reject" in txResult) {
46
+ throw new Error(`Transaction rejected: ${txResult.Reject}`);
47
+ }
42
48
  if ("Accept" in txResult) {
43
49
  return {
44
50
  upSubstates: txResult.Accept.up_substates,
45
51
  downSubstates: txResult.Accept.down_substates,
46
52
  };
47
53
  }
48
- if ("Reject" in txResult) {
49
- throw new Error(`Transaction rejected: ${txResult.Reject}`);
50
- }
51
54
  if ("AcceptFeeRejectRest" in txResult) {
52
55
  return {
53
56
  upSubstates: txResult.AcceptFeeRejectRest[0].up_substates,
@@ -5,6 +5,7 @@ import { NamedArg } from "../helpers";
5
5
  * This interface defines the constructor for a Transaction object.
6
6
  * It is used to create a new signed Transaction instance from an UnsignedTransaction and an array of TransactionSignatures.
7
7
  * The constructor takes an UnsignedTransaction and an array of TransactionSignatures as parameters.
8
+ * @public
8
9
  */
9
10
  export interface TransactionConstructor {
10
11
  /**
@@ -36,10 +36,10 @@ export class TransactionBuilder {
36
36
  });
37
37
  }
38
38
  callMethod(method, args) {
39
- const call = method.componentAddress ?
40
- { Address: method.componentAddress } :
41
- // NOTE: offset IDs are not supported for method calls
42
- { Workspace: this.getNamedId(method.fromWorkspace) };
39
+ const call = method.componentAddress
40
+ ? { Address: method.componentAddress }
41
+ : // NOTE: offset IDs are not supported for method calls
42
+ { Workspace: this.getNamedId(method.fromWorkspace) };
43
43
  const resolvedArgs = this.resolveArgs(args);
44
44
  return this.addInstruction({
45
45
  CallMethod: {
@@ -50,9 +50,7 @@ export class TransactionBuilder {
50
50
  });
51
51
  }
52
52
  createAccount(ownerPublicKey, workspaceBucket) {
53
- const workspace_id = workspaceBucket ?
54
- this.getOffsetIdFromWorkspaceName(workspaceBucket) :
55
- null;
53
+ const workspace_id = workspaceBucket ? this.getOffsetIdFromWorkspaceName(workspaceBucket) : null;
56
54
  return this.addInstruction({
57
55
  CreateAccount: {
58
56
  public_key_address: ownerPublicKey,
@@ -103,7 +101,7 @@ export class TransactionBuilder {
103
101
  * `PutLastInstructionOutputOnWorkspace: { key: Array<number> }`
104
102
  */
105
103
  saveVar(name) {
106
- let key = this.addNamedId(name);
104
+ const key = this.addNamedId(name);
107
105
  return this.addInstruction({
108
106
  PutLastInstructionOutputOnWorkspace: {
109
107
  key,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tari-project/tarijs-builders",
3
- "version": "0.12.1",
3
+ "version": "0.12.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -11,9 +11,9 @@
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
13
  "@tari-project/typescript-bindings": ">=1.14.0",
14
- "@tari-project/tari-signer": "^0.12.1",
15
- "@tari-project/tarijs-types": "^0.12.1",
16
- "@tari-project/tari-universe-signer": "^0.12.1"
14
+ "@tari-project/tari-signer": "^0.12.2",
15
+ "@tari-project/tarijs-types": "^0.12.2",
16
+ "@tari-project/tari-universe-signer": "^0.12.2"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/node": "^22.13.1",
@@ -25,6 +25,7 @@
25
25
  "main": "dist/index.js",
26
26
  "types": "dist/index.d.ts",
27
27
  "scripts": {
28
- "build": "tsc -b"
28
+ "build": "tsc -b",
29
+ "lint": "eslint src/"
29
30
  }
30
31
  }