@tari-project/tarijs-builders 0.4.0
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.
- package/LICENSE +29 -0
- package/dist/helpers/index.d.ts +2 -0
- package/dist/helpers/index.js +2 -0
- package/dist/helpers/submitTransaction.d.ts +10 -0
- package/dist/helpers/submitTransaction.js +62 -0
- package/dist/helpers/workspace.d.ts +23 -0
- package/dist/helpers/workspace.js +29 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/transaction/TransactionBuilder.d.ts +86 -0
- package/dist/transaction/TransactionBuilder.js +164 -0
- package/dist/transaction/TransactionRequest.d.ts +27 -0
- package/dist/transaction/TransactionRequest.js +67 -0
- package/dist/transaction/index.d.ts +2 -0
- package/dist/transaction/index.js +2 -0
- package/package.json +30 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023, The Tari Developer Community
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,10 @@
|
|
|
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>;
|
|
7
|
+
export declare function getAcceptResultSubstates(txResult: TransactionResult): {
|
|
8
|
+
upSubstates: UpSubstates;
|
|
9
|
+
downSubstates: DownSubstates;
|
|
10
|
+
} | undefined;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { TransactionStatus } from "@tari-project/tarijs-types";
|
|
2
|
+
export function buildTransactionRequest(transaction, accountId, requiredSubstates, inputRefs = [], isDryRun = false, network = 0, isSealSignerAuthorized = true, detectInputsUseUnversioned = true) {
|
|
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
|
+
network,
|
|
7
|
+
account_id: accountId,
|
|
8
|
+
instructions: transaction.instructions,
|
|
9
|
+
fee_instructions: transaction.feeInstructions,
|
|
10
|
+
inputs: transaction.inputs,
|
|
11
|
+
input_refs: inputRefs,
|
|
12
|
+
required_substates: requiredSubstates,
|
|
13
|
+
is_dry_run: isDryRun,
|
|
14
|
+
min_epoch: transaction.minEpoch ?? null,
|
|
15
|
+
max_epoch: transaction.maxEpoch ?? null,
|
|
16
|
+
is_seal_signer_authorized: isSealSignerAuthorized,
|
|
17
|
+
detect_inputs_use_unversioned: detectInputsUseUnversioned,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export async function submitAndWaitForTransaction(provider, req) {
|
|
21
|
+
try {
|
|
22
|
+
const response = await provider.submitTransaction(req);
|
|
23
|
+
const result = await waitForTransactionResult(provider, response.transaction_id);
|
|
24
|
+
return {
|
|
25
|
+
response,
|
|
26
|
+
result,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
throw new Error(`Transaction failed: ${e}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export async function waitForTransactionResult(provider, transactionId) {
|
|
34
|
+
// eslint-disable-next-line no-constant-condition
|
|
35
|
+
while (true) {
|
|
36
|
+
const resp = await provider.getTransactionResult(transactionId);
|
|
37
|
+
const FINALIZED_STATUSES = [
|
|
38
|
+
TransactionStatus.Accepted,
|
|
39
|
+
TransactionStatus.Rejected,
|
|
40
|
+
TransactionStatus.InvalidTransaction,
|
|
41
|
+
TransactionStatus.OnlyFeeAccepted,
|
|
42
|
+
TransactionStatus.DryRun,
|
|
43
|
+
];
|
|
44
|
+
if (resp.status == TransactionStatus.Rejected) {
|
|
45
|
+
throw new Error(`Transaction rejected: ${JSON.stringify(resp.result)}`);
|
|
46
|
+
}
|
|
47
|
+
if (FINALIZED_STATUSES.includes(resp.status)) {
|
|
48
|
+
return resp; //TODO fix: type mismatch (https://github.com/tari-project/tari.js/issues/29)
|
|
49
|
+
}
|
|
50
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function getAcceptResultSubstates(txResult) {
|
|
54
|
+
const result = txResult.result?.result;
|
|
55
|
+
if (result && isAccept(result)) {
|
|
56
|
+
return { upSubstates: result.Accept.up_substates, downSubstates: result.Accept.down_substates };
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
function isAccept(result) {
|
|
61
|
+
return "Accept" in result;
|
|
62
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { WorkspaceArg } from "@tari-project/tarijs-types";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param key workspace name
|
|
5
|
+
* @returns encoded Uint8Array value
|
|
6
|
+
* @example
|
|
7
|
+
* key: "0" -> [ 48 ]
|
|
8
|
+
* key: "0.0" -> [ 48, 46, 48 ]
|
|
9
|
+
* key: "0.1" -> [ 48, 46, 49 ]
|
|
10
|
+
*
|
|
11
|
+
* key: "bucket" -> [ 98, 117, 99, 107, 101, 116 ]
|
|
12
|
+
* key: "bucket.0" -> [ 98, 117, 99, 107, 101, 116, 46, 48 ]
|
|
13
|
+
* key: "bucket.1" -> [ 98, 117, 99, 107, 101, 116, 46, 49 ]
|
|
14
|
+
*/
|
|
15
|
+
export declare function toWorkspace(key: string): number[];
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param key workspace name
|
|
19
|
+
* @returns formatted Workspace data
|
|
20
|
+
* @example
|
|
21
|
+
* key: "bucket" -> { Workspace: [ 98, 117, 99, 107, 101, 116 ] }
|
|
22
|
+
*/
|
|
23
|
+
export declare function fromWorkspace(key: string): WorkspaceArg;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param key workspace name
|
|
4
|
+
* @returns encoded Uint8Array value
|
|
5
|
+
* @example
|
|
6
|
+
* key: "0" -> [ 48 ]
|
|
7
|
+
* key: "0.0" -> [ 48, 46, 48 ]
|
|
8
|
+
* key: "0.1" -> [ 48, 46, 49 ]
|
|
9
|
+
*
|
|
10
|
+
* key: "bucket" -> [ 98, 117, 99, 107, 101, 116 ]
|
|
11
|
+
* key: "bucket.0" -> [ 98, 117, 99, 107, 101, 116, 46, 48 ]
|
|
12
|
+
* key: "bucket.1" -> [ 98, 117, 99, 107, 101, 116, 46, 49 ]
|
|
13
|
+
*/
|
|
14
|
+
export function toWorkspace(key) {
|
|
15
|
+
const encoder = new TextEncoder();
|
|
16
|
+
return Array.from(encoder.encode(key));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param key workspace name
|
|
21
|
+
* @returns formatted Workspace data
|
|
22
|
+
* @example
|
|
23
|
+
* key: "bucket" -> { Workspace: [ 98, 117, 99, 107, 101, 116 ] }
|
|
24
|
+
*/
|
|
25
|
+
export function fromWorkspace(key) {
|
|
26
|
+
const encoder = new TextEncoder();
|
|
27
|
+
const encodedKey = encoder.encode(key);
|
|
28
|
+
return { Workspace: Array.from(encodedKey) };
|
|
29
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export * from "@tari-project/tarijs-types";
|
|
2
|
+
export { TransactionBuilder, TransactionRequest, TariMethodDefinition, TariFunctionDefinition } from "./transaction";
|
|
3
|
+
export { buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult, fromWorkspace, toWorkspace, } from "./helpers";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { ComponentAddress, ConfidentialClaim, ConfidentialWithdrawProof, Instruction, ResourceAddress, SubstateRequirement, Transaction, TransactionSignature, UnsignedTransaction, TemplateAddress, Arg } from "@tari-project/tarijs-types";
|
|
2
|
+
export interface TransactionConstructor {
|
|
3
|
+
new (unsignedTransaction: UnsignedTransaction, signatures: TransactionSignature[]): Transaction;
|
|
4
|
+
}
|
|
5
|
+
export interface TariFunctionDefinition {
|
|
6
|
+
functionName: string;
|
|
7
|
+
args?: Arg[];
|
|
8
|
+
templateAddress: TemplateAddress;
|
|
9
|
+
}
|
|
10
|
+
export interface TariMethodDefinition {
|
|
11
|
+
methodName: string;
|
|
12
|
+
args?: Arg[];
|
|
13
|
+
componentAddress: ComponentAddress;
|
|
14
|
+
}
|
|
15
|
+
export interface TariCreateAccountDefinition {
|
|
16
|
+
methodName: string;
|
|
17
|
+
args?: {
|
|
18
|
+
ownerPublicKey: string;
|
|
19
|
+
workspaceBucket?: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface Builder {
|
|
23
|
+
callFunction<T extends TariFunctionDefinition>(func: T, args: Exclude<T["args"], undefined>): this;
|
|
24
|
+
callMethod<T extends TariMethodDefinition>(method: T, args: Exclude<T["args"], undefined>): this;
|
|
25
|
+
createAccount(ownerPublicKey: string, workspaceBucket?: string): this;
|
|
26
|
+
createProof(account: ComponentAddress, resourceAddress: ResourceAddress): this;
|
|
27
|
+
saveVar(key: string): this;
|
|
28
|
+
dropAllProofsInWorkspace(): this;
|
|
29
|
+
claimBurn(claim: ConfidentialClaim): this;
|
|
30
|
+
addInput(inputObject: SubstateRequirement): this;
|
|
31
|
+
addInstruction(instruction: Instruction): this;
|
|
32
|
+
addFeeInstruction(instruction: Instruction): this;
|
|
33
|
+
withMinEpoch(minEpoch: number): this;
|
|
34
|
+
withMaxEpoch(maxEpoch: number): this;
|
|
35
|
+
withInputs(inputs: SubstateRequirement[]): this;
|
|
36
|
+
withInstructions(instructions: Instruction[]): this;
|
|
37
|
+
withFeeInstructions(instructions: Instruction[]): this;
|
|
38
|
+
withFeeInstructionsBuilder(builder: (builder: TransactionBuilder) => this): this;
|
|
39
|
+
withUnsignedTransaction(unsignedTransaction: UnsignedTransaction): this;
|
|
40
|
+
feeTransactionPayFromComponent(componentAddress: ComponentAddress, maxFee: string): this;
|
|
41
|
+
feeTransactionPayFromComponentConfidential(componentAddress: ComponentAddress, proof: ConfidentialWithdrawProof): this;
|
|
42
|
+
buildUnsignedTransaction(): UnsignedTransaction;
|
|
43
|
+
build(): Transaction;
|
|
44
|
+
}
|
|
45
|
+
export declare class TransactionBuilder implements Builder {
|
|
46
|
+
private unsignedTransaction;
|
|
47
|
+
private signatures;
|
|
48
|
+
constructor();
|
|
49
|
+
callFunction<T extends TariFunctionDefinition>(func: T, args: Exclude<T["args"], undefined>): this;
|
|
50
|
+
callMethod<T extends TariMethodDefinition>(method: T, args: Exclude<T["args"], undefined>): this;
|
|
51
|
+
createAccount(ownerPublicKey: string, workspaceBucket?: string): this;
|
|
52
|
+
createProof(account: ComponentAddress, resourceAddress: ResourceAddress): this;
|
|
53
|
+
claimBurn(claim: ConfidentialClaim): this;
|
|
54
|
+
/**
|
|
55
|
+
* The `SaveVar` method replaces
|
|
56
|
+
* `PutLastInstructionOutputOnWorkspace: { key: Array<number> }`
|
|
57
|
+
* to make saving variables easier.
|
|
58
|
+
*/
|
|
59
|
+
saveVar(key: string): this;
|
|
60
|
+
/**
|
|
61
|
+
* Adds a fee instruction that calls the `take_fee` method on a component.
|
|
62
|
+
* This method must exist and return a Bucket with containing revealed confidential XTR resource.
|
|
63
|
+
* This allows the fee to originate from sources other than the transaction sender's account.
|
|
64
|
+
* The fee instruction will lock up the `max_fee` amount for the duration of the transaction.
|
|
65
|
+
*/
|
|
66
|
+
feeTransactionPayFromComponent(componentAddress: ComponentAddress, maxFee: string): this;
|
|
67
|
+
/**
|
|
68
|
+
* Adds a fee instruction that calls the `take_fee_confidential` method on a component.
|
|
69
|
+
* This method must exist and return a Bucket with containing revealed confidential XTR resource.
|
|
70
|
+
* This allows the fee to originate from sources other than the transaction sender's account.
|
|
71
|
+
*/
|
|
72
|
+
feeTransactionPayFromComponentConfidential(componentAddress: ComponentAddress, proof: ConfidentialWithdrawProof): this;
|
|
73
|
+
dropAllProofsInWorkspace(): this;
|
|
74
|
+
withUnsignedTransaction(unsignedTransaction: UnsignedTransaction): this;
|
|
75
|
+
withFeeInstructions(instructions: Instruction[]): this;
|
|
76
|
+
withFeeInstructionsBuilder(builder: (builder: TransactionBuilder) => TransactionBuilder): this;
|
|
77
|
+
addInstruction(instruction: Instruction): this;
|
|
78
|
+
addFeeInstruction(instruction: Instruction): this;
|
|
79
|
+
withInstructions(instructions: Instruction[]): this;
|
|
80
|
+
addInput(inputObject: SubstateRequirement): this;
|
|
81
|
+
withInputs(inputs: SubstateRequirement[]): this;
|
|
82
|
+
withMinEpoch(minEpoch: number): this;
|
|
83
|
+
withMaxEpoch(maxEpoch: number): this;
|
|
84
|
+
buildUnsignedTransaction(): UnsignedTransaction;
|
|
85
|
+
build(): Transaction;
|
|
86
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Copyright 2024 The Tari Project
|
|
2
|
+
// SPDX-License-Identifier: BSD-3-Clause
|
|
3
|
+
import { toWorkspace } from "../helpers";
|
|
4
|
+
import { TransactionRequest } from "./TransactionRequest";
|
|
5
|
+
export class TransactionBuilder {
|
|
6
|
+
unsignedTransaction;
|
|
7
|
+
signatures;
|
|
8
|
+
constructor() {
|
|
9
|
+
this.unsignedTransaction = {
|
|
10
|
+
feeInstructions: [],
|
|
11
|
+
instructions: [],
|
|
12
|
+
inputs: [],
|
|
13
|
+
filledInputs: [],
|
|
14
|
+
minEpoch: undefined,
|
|
15
|
+
maxEpoch: undefined,
|
|
16
|
+
};
|
|
17
|
+
this.signatures = [];
|
|
18
|
+
}
|
|
19
|
+
callFunction(func, args) {
|
|
20
|
+
return this.addInstruction({
|
|
21
|
+
CallFunction: {
|
|
22
|
+
template_address: func.templateAddress,
|
|
23
|
+
function: func.functionName,
|
|
24
|
+
args,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
callMethod(method, args) {
|
|
29
|
+
return this.addInstruction({
|
|
30
|
+
CallMethod: {
|
|
31
|
+
component_address: method.componentAddress,
|
|
32
|
+
method: method.methodName,
|
|
33
|
+
args,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
createAccount(ownerPublicKey, workspaceBucket) {
|
|
38
|
+
return this.addInstruction({
|
|
39
|
+
CreateAccount: {
|
|
40
|
+
owner_public_key: ownerPublicKey,
|
|
41
|
+
workspace_bucket: workspaceBucket ?? null,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
createProof(account, resourceAddress) {
|
|
46
|
+
return this.addInstruction({
|
|
47
|
+
CallMethod: {
|
|
48
|
+
component_address: account,
|
|
49
|
+
method: "create_proof_for_resource",
|
|
50
|
+
args: [resourceAddress],
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
claimBurn(claim) {
|
|
55
|
+
return this.addInstruction({
|
|
56
|
+
ClaimBurn: {
|
|
57
|
+
claim,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The `SaveVar` method replaces
|
|
63
|
+
* `PutLastInstructionOutputOnWorkspace: { key: Array<number> }`
|
|
64
|
+
* to make saving variables easier.
|
|
65
|
+
*/
|
|
66
|
+
saveVar(key) {
|
|
67
|
+
return this.addInstruction({
|
|
68
|
+
PutLastInstructionOutputOnWorkspace: {
|
|
69
|
+
key: toWorkspace(key),
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Adds a fee instruction that calls the `take_fee` method on a component.
|
|
75
|
+
* This method must exist and return a Bucket with containing revealed confidential XTR resource.
|
|
76
|
+
* This allows the fee to originate from sources other than the transaction sender's account.
|
|
77
|
+
* The fee instruction will lock up the `max_fee` amount for the duration of the transaction.
|
|
78
|
+
*/
|
|
79
|
+
feeTransactionPayFromComponent(componentAddress, maxFee) {
|
|
80
|
+
return this.addFeeInstruction({
|
|
81
|
+
CallMethod: {
|
|
82
|
+
component_address: componentAddress,
|
|
83
|
+
method: "pay_fee",
|
|
84
|
+
args: [maxFee],
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Adds a fee instruction that calls the `take_fee_confidential` method on a component.
|
|
90
|
+
* This method must exist and return a Bucket with containing revealed confidential XTR resource.
|
|
91
|
+
* This allows the fee to originate from sources other than the transaction sender's account.
|
|
92
|
+
*/
|
|
93
|
+
feeTransactionPayFromComponentConfidential(componentAddress, proof) {
|
|
94
|
+
return this.addFeeInstruction({
|
|
95
|
+
CallMethod: {
|
|
96
|
+
component_address: componentAddress,
|
|
97
|
+
method: "pay_fee_confidential",
|
|
98
|
+
args: [proof],
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
dropAllProofsInWorkspace() {
|
|
103
|
+
return this.addInstruction("DropAllProofsInWorkspace");
|
|
104
|
+
}
|
|
105
|
+
withUnsignedTransaction(unsignedTransaction) {
|
|
106
|
+
this.unsignedTransaction = unsignedTransaction;
|
|
107
|
+
this.signatures = [];
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
withFeeInstructions(instructions) {
|
|
111
|
+
this.unsignedTransaction.feeInstructions = instructions;
|
|
112
|
+
this.signatures = [];
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
withFeeInstructionsBuilder(builder) {
|
|
116
|
+
const newBuilder = builder(new TransactionBuilder());
|
|
117
|
+
this.unsignedTransaction.feeInstructions = newBuilder.unsignedTransaction.instructions;
|
|
118
|
+
this.signatures = [];
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
addInstruction(instruction) {
|
|
122
|
+
this.unsignedTransaction.instructions.push(instruction);
|
|
123
|
+
this.signatures = [];
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
addFeeInstruction(instruction) {
|
|
127
|
+
this.unsignedTransaction.feeInstructions.push(instruction);
|
|
128
|
+
this.signatures = [];
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
withInstructions(instructions) {
|
|
132
|
+
this.unsignedTransaction.instructions.push(...instructions);
|
|
133
|
+
this.signatures = [];
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
addInput(inputObject) {
|
|
137
|
+
this.unsignedTransaction.inputs.push(inputObject);
|
|
138
|
+
this.signatures = [];
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
withInputs(inputs) {
|
|
142
|
+
this.unsignedTransaction.inputs.push(...inputs);
|
|
143
|
+
this.signatures = [];
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
withMinEpoch(minEpoch) {
|
|
147
|
+
this.unsignedTransaction.minEpoch = minEpoch;
|
|
148
|
+
// Reset the signatures as they are no longer valid
|
|
149
|
+
this.signatures = [];
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
withMaxEpoch(maxEpoch) {
|
|
153
|
+
this.unsignedTransaction.maxEpoch = maxEpoch;
|
|
154
|
+
// Reset the signatures as they are no longer valid
|
|
155
|
+
this.signatures = [];
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
buildUnsignedTransaction() {
|
|
159
|
+
return this.unsignedTransaction;
|
|
160
|
+
}
|
|
161
|
+
build() {
|
|
162
|
+
return new TransactionRequest(this.unsignedTransaction, this.signatures);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Epoch, Instruction, SubstateRequirement, Transaction, TransactionId, TransactionSignature, UnsignedTransaction, VersionedSubstateId } from "@tari-project/tarijs-types";
|
|
2
|
+
export declare class TransactionRequest implements Transaction {
|
|
3
|
+
id: TransactionId;
|
|
4
|
+
feeInstructions: Array<Instruction>;
|
|
5
|
+
instructions: Array<Instruction>;
|
|
6
|
+
inputs: Array<SubstateRequirement>;
|
|
7
|
+
signatures: Array<TransactionSignature>;
|
|
8
|
+
unsignedTransaction: UnsignedTransaction;
|
|
9
|
+
minEpoch?: Epoch;
|
|
10
|
+
maxEpoch?: Epoch;
|
|
11
|
+
filledInputs: VersionedSubstateId[];
|
|
12
|
+
constructor(unsignedTransaction: UnsignedTransaction, signatures: TransactionSignature[]);
|
|
13
|
+
private calculateHash;
|
|
14
|
+
withFilledInputs(filled_inputs: Array<VersionedSubstateId>): this;
|
|
15
|
+
getId(): TransactionId;
|
|
16
|
+
checkId(): boolean;
|
|
17
|
+
getUnsignedTransaction(): UnsignedTransaction;
|
|
18
|
+
getFeeInstructions(): Instruction[];
|
|
19
|
+
getInstructions(): Instruction[];
|
|
20
|
+
getSignatures(): TransactionSignature[];
|
|
21
|
+
getHash(): string;
|
|
22
|
+
getInputs(): SubstateRequirement[];
|
|
23
|
+
getFilledInputs(): VersionedSubstateId[];
|
|
24
|
+
getFilledInputsMut(): VersionedSubstateId[];
|
|
25
|
+
getMinEpoch(): Epoch | undefined;
|
|
26
|
+
getMaxEpoch(): Epoch | undefined;
|
|
27
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
///TODO this implementation is not fully done, see:
|
|
2
|
+
/// https://github.com/tari-project/tari-dan/blob/development/dan_layer/transaction/src/transaction.rs
|
|
3
|
+
export class TransactionRequest {
|
|
4
|
+
id;
|
|
5
|
+
feeInstructions;
|
|
6
|
+
instructions;
|
|
7
|
+
inputs;
|
|
8
|
+
signatures;
|
|
9
|
+
unsignedTransaction;
|
|
10
|
+
minEpoch;
|
|
11
|
+
maxEpoch;
|
|
12
|
+
filledInputs;
|
|
13
|
+
constructor(unsignedTransaction, signatures) {
|
|
14
|
+
this.id = this.calculateHash();
|
|
15
|
+
this.feeInstructions = unsignedTransaction.feeInstructions;
|
|
16
|
+
this.instructions = unsignedTransaction.instructions;
|
|
17
|
+
this.inputs = unsignedTransaction.inputs;
|
|
18
|
+
this.signatures = signatures;
|
|
19
|
+
this.minEpoch = unsignedTransaction.minEpoch;
|
|
20
|
+
this.maxEpoch = unsignedTransaction.maxEpoch;
|
|
21
|
+
// Inputs filled by some authority. These are not part of the transaction hash nor the signature
|
|
22
|
+
this.filledInputs = [];
|
|
23
|
+
}
|
|
24
|
+
calculateHash() {
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
withFilledInputs(filled_inputs) {
|
|
28
|
+
return { ...this, filled_inputs };
|
|
29
|
+
}
|
|
30
|
+
getId() {
|
|
31
|
+
return this.id;
|
|
32
|
+
}
|
|
33
|
+
checkId() {
|
|
34
|
+
const id = this.calculateHash();
|
|
35
|
+
return id === this.id;
|
|
36
|
+
}
|
|
37
|
+
getUnsignedTransaction() {
|
|
38
|
+
return this.unsignedTransaction;
|
|
39
|
+
}
|
|
40
|
+
getFeeInstructions() {
|
|
41
|
+
return this.feeInstructions;
|
|
42
|
+
}
|
|
43
|
+
getInstructions() {
|
|
44
|
+
return this.instructions;
|
|
45
|
+
}
|
|
46
|
+
getSignatures() {
|
|
47
|
+
return this.signatures;
|
|
48
|
+
}
|
|
49
|
+
getHash() {
|
|
50
|
+
return this.id;
|
|
51
|
+
}
|
|
52
|
+
getInputs() {
|
|
53
|
+
return this.inputs;
|
|
54
|
+
}
|
|
55
|
+
getFilledInputs() {
|
|
56
|
+
return this.filledInputs;
|
|
57
|
+
}
|
|
58
|
+
getFilledInputsMut() {
|
|
59
|
+
return this.filledInputs;
|
|
60
|
+
}
|
|
61
|
+
getMinEpoch() {
|
|
62
|
+
return this.minEpoch;
|
|
63
|
+
}
|
|
64
|
+
getMaxEpoch() {
|
|
65
|
+
return this.maxEpoch;
|
|
66
|
+
}
|
|
67
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tari-project/tarijs-builders",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "ISC",
|
|
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"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^22.13.1",
|
|
20
|
+
"typescript": "^5.0.4"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"/dist"
|
|
24
|
+
],
|
|
25
|
+
"main": "dist/index.js",
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -b"
|
|
29
|
+
}
|
|
30
|
+
}
|