@tari-project/tarijs-builders 0.4.0 → 0.5.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.
@@ -1,9 +1,9 @@
1
- import { TariUniverseProvider } from "@tari-project/tari-universe-provider";
2
- import { TariProvider, SubmitTransactionRequest, SubstateRequirement } from "@tari-project/tari-provider";
3
- import { Transaction, TransactionResult, DownSubstates, UpSubstates, SubmitTxResult } from "@tari-project/tarijs-types";
4
- export declare function buildTransactionRequest(transaction: Transaction, accountId: number, requiredSubstates: SubstateRequirement[], inputRefs?: never[], isDryRun?: boolean, network?: number, isSealSignerAuthorized?: boolean, detectInputsUseUnversioned?: boolean): SubmitTransactionRequest;
5
- export declare function submitAndWaitForTransaction(provider: TariProvider, req: SubmitTransactionRequest): Promise<SubmitTxResult>;
6
- export declare function waitForTransactionResult(provider: TariProvider | TariUniverseProvider, transactionId: string): Promise<TransactionResult>;
1
+ import { TariUniverseSigner } from "@tari-project/tari-universe-signer";
2
+ import { TariSigner } from "@tari-project/tari-signer";
3
+ import { Transaction, TransactionResult, DownSubstates, UpSubstates, SubmitTxResult, ReqSubstate, SubmitTransactionRequest } from "@tari-project/tarijs-types";
4
+ export declare function buildTransactionRequest(transaction: Transaction, accountId: number, requiredSubstates: ReqSubstate[], inputRefs?: never[], isDryRun?: boolean, network?: number, isSealSignerAuthorized?: boolean, detectInputsUseUnversioned?: boolean): SubmitTransactionRequest;
5
+ export declare function submitAndWaitForTransaction(signer: TariSigner, req: SubmitTransactionRequest): Promise<SubmitTxResult>;
6
+ export declare function waitForTransactionResult(signer: TariSigner | TariUniverseSigner, transactionId: string): Promise<TransactionResult>;
7
7
  export declare function getAcceptResultSubstates(txResult: TransactionResult): {
8
8
  upSubstates: UpSubstates;
9
9
  downSubstates: DownSubstates;
@@ -1,8 +1,6 @@
1
- import { TransactionStatus } from "@tari-project/tarijs-types";
1
+ import { TransactionStatus, } from "@tari-project/tarijs-types";
2
2
  export function buildTransactionRequest(transaction, accountId, requiredSubstates, inputRefs = [], isDryRun = false, network = 0, isSealSignerAuthorized = true, detectInputsUseUnversioned = true) {
3
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
4
  network,
7
5
  account_id: accountId,
8
6
  instructions: transaction.instructions,
@@ -17,10 +15,10 @@ export function buildTransactionRequest(transaction, accountId, requiredSubstate
17
15
  detect_inputs_use_unversioned: detectInputsUseUnversioned,
18
16
  };
19
17
  }
20
- export async function submitAndWaitForTransaction(provider, req) {
18
+ export async function submitAndWaitForTransaction(signer, req) {
21
19
  try {
22
- const response = await provider.submitTransaction(req);
23
- const result = await waitForTransactionResult(provider, response.transaction_id);
20
+ const response = await signer.submitTransaction(req);
21
+ const result = await waitForTransactionResult(signer, response.transaction_id);
24
22
  return {
25
23
  response,
26
24
  result,
@@ -30,10 +28,10 @@ export async function submitAndWaitForTransaction(provider, req) {
30
28
  throw new Error(`Transaction failed: ${e}`);
31
29
  }
32
30
  }
33
- export async function waitForTransactionResult(provider, transactionId) {
31
+ export async function waitForTransactionResult(signer, transactionId) {
34
32
  // eslint-disable-next-line no-constant-condition
35
33
  while (true) {
36
- const resp = await provider.getTransactionResult(transactionId);
34
+ const resp = await signer.getTransactionResult(transactionId);
37
35
  const FINALIZED_STATUSES = [
38
36
  TransactionStatus.Accepted,
39
37
  TransactionStatus.Rejected,
@@ -45,7 +43,7 @@ export async function waitForTransactionResult(provider, transactionId) {
45
43
  throw new Error(`Transaction rejected: ${JSON.stringify(resp.result)}`);
46
44
  }
47
45
  if (FINALIZED_STATUSES.includes(resp.status)) {
48
- return resp; //TODO fix: type mismatch (https://github.com/tari-project/tari.js/issues/29)
46
+ return resp;
49
47
  }
50
48
  await new Promise((resolve) => setTimeout(resolve, 1000));
51
49
  }
@@ -1,15 +1,15 @@
1
- import { ComponentAddress, ConfidentialClaim, ConfidentialWithdrawProof, Instruction, ResourceAddress, SubstateRequirement, Transaction, TransactionSignature, UnsignedTransaction, TemplateAddress, Arg } from "@tari-project/tarijs-types";
1
+ import { ComponentAddress, ConfidentialClaim, ConfidentialWithdrawProof, Instruction, ResourceAddress, SubstateRequirement, Transaction, TransactionSignature, UnsignedTransaction, PublishedTemplateAddress, TransactionArg } from "@tari-project/tarijs-types";
2
2
  export interface TransactionConstructor {
3
3
  new (unsignedTransaction: UnsignedTransaction, signatures: TransactionSignature[]): Transaction;
4
4
  }
5
5
  export interface TariFunctionDefinition {
6
6
  functionName: string;
7
- args?: Arg[];
8
- templateAddress: TemplateAddress;
7
+ args?: TransactionArg[];
8
+ templateAddress: PublishedTemplateAddress;
9
9
  }
10
10
  export interface TariMethodDefinition {
11
11
  methodName: string;
12
- args?: Arg[];
12
+ args?: TransactionArg[];
13
13
  componentAddress: ComponentAddress;
14
14
  }
15
15
  export interface TariCreateAccountDefinition {
@@ -1,6 +1,6 @@
1
- import { Epoch, Instruction, SubstateRequirement, Transaction, TransactionId, TransactionSignature, UnsignedTransaction, VersionedSubstateId } from "@tari-project/tarijs-types";
1
+ import { Epoch, Instruction, SubstateRequirement, Transaction, TransactionSignature, UnsignedTransaction, VersionedSubstateId } from "@tari-project/tarijs-types";
2
2
  export declare class TransactionRequest implements Transaction {
3
- id: TransactionId;
3
+ id: string;
4
4
  feeInstructions: Array<Instruction>;
5
5
  instructions: Array<Instruction>;
6
6
  inputs: Array<SubstateRequirement>;
@@ -10,18 +10,16 @@ export declare class TransactionRequest implements Transaction {
10
10
  maxEpoch?: Epoch;
11
11
  filledInputs: VersionedSubstateId[];
12
12
  constructor(unsignedTransaction: UnsignedTransaction, signatures: TransactionSignature[]);
13
- private calculateHash;
14
13
  withFilledInputs(filled_inputs: Array<VersionedSubstateId>): this;
15
- getId(): TransactionId;
16
- checkId(): boolean;
17
14
  getUnsignedTransaction(): UnsignedTransaction;
18
15
  getFeeInstructions(): Instruction[];
19
16
  getInstructions(): Instruction[];
20
17
  getSignatures(): TransactionSignature[];
21
- getHash(): string;
22
18
  getInputs(): SubstateRequirement[];
23
19
  getFilledInputs(): VersionedSubstateId[];
24
20
  getFilledInputsMut(): VersionedSubstateId[];
25
21
  getMinEpoch(): Epoch | undefined;
26
22
  getMaxEpoch(): Epoch | undefined;
23
+ setId(id: string): void;
24
+ getId(): string;
27
25
  }
@@ -11,7 +11,7 @@ export class TransactionRequest {
11
11
  maxEpoch;
12
12
  filledInputs;
13
13
  constructor(unsignedTransaction, signatures) {
14
- this.id = this.calculateHash();
14
+ this.id = "";
15
15
  this.feeInstructions = unsignedTransaction.feeInstructions;
16
16
  this.instructions = unsignedTransaction.instructions;
17
17
  this.inputs = unsignedTransaction.inputs;
@@ -21,19 +21,9 @@ export class TransactionRequest {
21
21
  // Inputs filled by some authority. These are not part of the transaction hash nor the signature
22
22
  this.filledInputs = [];
23
23
  }
24
- calculateHash() {
25
- return "";
26
- }
27
24
  withFilledInputs(filled_inputs) {
28
25
  return { ...this, filled_inputs };
29
26
  }
30
- getId() {
31
- return this.id;
32
- }
33
- checkId() {
34
- const id = this.calculateHash();
35
- return id === this.id;
36
- }
37
27
  getUnsignedTransaction() {
38
28
  return this.unsignedTransaction;
39
29
  }
@@ -46,9 +36,6 @@ export class TransactionRequest {
46
36
  getSignatures() {
47
37
  return this.signatures;
48
38
  }
49
- getHash() {
50
- return this.id;
51
- }
52
39
  getInputs() {
53
40
  return this.inputs;
54
41
  }
@@ -64,4 +51,10 @@ export class TransactionRequest {
64
51
  getMaxEpoch() {
65
52
  return this.maxEpoch;
66
53
  }
54
+ setId(id) {
55
+ this.id = id;
56
+ }
57
+ getId() {
58
+ return this.id;
59
+ }
67
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tari-project/tarijs-builders",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -10,10 +10,9 @@
10
10
  "author": "",
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
- "@tari-project/typescript-bindings": "^1.4.0",
14
- "@tari-project/tari-universe-provider": "^0.4.0",
15
- "@tari-project/tari-provider": "^0.4.0",
16
- "@tari-project/tarijs-types": "^0.4.0"
13
+ "@tari-project/tari-signer": "^0.5.1",
14
+ "@tari-project/tari-universe-signer": "^0.5.1",
15
+ "@tari-project/tarijs-types": "^0.5.1"
17
16
  },
18
17
  "devDependencies": {
19
18
  "@types/node": "^22.13.1",