@tari-project/tarijs-builders 0.11.0 → 0.12.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.
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { TariUniverseSigner } from "@tari-project/tari-universe-signer";
|
|
2
2
|
import { TariSigner } from "@tari-project/tari-signer";
|
|
3
3
|
import { TransactionResult, UnsignedTransactionV1 } from "@tari-project/typescript-bindings";
|
|
4
|
-
import { DownSubstates, UpSubstates, SubmitTransactionRequest } from "@tari-project/tarijs-types";
|
|
5
|
-
import { SubmitTxResult } from "@tari-project/tarijs-types/dist/TransactionResult";
|
|
4
|
+
import { DownSubstates, UpSubstates, SubmitTransactionRequest, SimpleTransactionResult } from "@tari-project/tarijs-types";
|
|
6
5
|
export declare function buildTransactionRequest(transaction: UnsignedTransactionV1, accountId: number, detectInputsUseUnversioned?: boolean): SubmitTransactionRequest;
|
|
7
|
-
export declare function submitAndWaitForTransaction(signer: TariSigner, req: SubmitTransactionRequest): Promise<
|
|
8
|
-
export declare function waitForTransactionResult(signer: TariSigner | TariUniverseSigner, transactionId: string): Promise<
|
|
6
|
+
export declare function submitAndWaitForTransaction(signer: TariSigner, req: SubmitTransactionRequest): Promise<SimpleTransactionResult>;
|
|
7
|
+
export declare function waitForTransactionResult(signer: TariSigner | TariUniverseSigner, transactionId: string): Promise<SimpleTransactionResult>;
|
|
9
8
|
export declare function getAcceptResultSubstates(txResult: TransactionResult): {
|
|
10
9
|
upSubstates: UpSubstates;
|
|
11
10
|
downSubstates: DownSubstates;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getSubstateValueFromUpSubstates, TransactionStatus, } from "@tari-project/tarijs-types";
|
|
1
|
+
import { TransactionStatus, SimpleTransactionResult, } from "@tari-project/tarijs-types";
|
|
3
2
|
export function buildTransactionRequest(transaction, accountId, detectInputsUseUnversioned = true) {
|
|
4
3
|
return {
|
|
5
4
|
transaction,
|
|
@@ -10,29 +9,7 @@ export function buildTransactionRequest(transaction, accountId, detectInputsUseU
|
|
|
10
9
|
export async function submitAndWaitForTransaction(signer, req) {
|
|
11
10
|
try {
|
|
12
11
|
const response = await signer.submitTransaction(req);
|
|
13
|
-
|
|
14
|
-
const { upSubstates, downSubstates } = getAcceptResultSubstates(result);
|
|
15
|
-
const newComponents = getSubstateValueFromUpSubstates("Component", upSubstates);
|
|
16
|
-
function getComponentForTemplate(templateAddress) {
|
|
17
|
-
for (const [substateId, substate] of upSubstates) {
|
|
18
|
-
if ("Component" in substate.substate) {
|
|
19
|
-
const templateAddr = substate.substate.Component.template_address;
|
|
20
|
-
const templateString = typeof templateAddr === "string" ? templateAddr : new TextDecoder().decode(templateAddr);
|
|
21
|
-
if (templateAddress === templateString) {
|
|
22
|
-
return substateIdToString(substateId);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
return {
|
|
29
|
-
response,
|
|
30
|
-
result,
|
|
31
|
-
upSubstates,
|
|
32
|
-
downSubstates,
|
|
33
|
-
newComponents,
|
|
34
|
-
getComponentForTemplate,
|
|
35
|
-
};
|
|
12
|
+
return await waitForTransactionResult(signer, response.transaction_id);
|
|
36
13
|
}
|
|
37
14
|
catch (e) {
|
|
38
15
|
throw new Error(`Transaction failed: ${e}`);
|
|
@@ -53,9 +30,12 @@ export async function waitForTransactionResult(signer, transactionId) {
|
|
|
53
30
|
throw new Error(`Transaction rejected: ${JSON.stringify(resp.result)}`);
|
|
54
31
|
}
|
|
55
32
|
if (FINALIZED_STATUSES.includes(resp.status)) {
|
|
56
|
-
|
|
33
|
+
if (!resp.result) {
|
|
34
|
+
throw new Error(`BUG: Transaction result is empty for transaction ID: ${transactionId}`);
|
|
35
|
+
}
|
|
36
|
+
return SimpleTransactionResult.fromResponse(resp);
|
|
57
37
|
}
|
|
58
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
38
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
59
39
|
}
|
|
60
40
|
}
|
|
61
41
|
export function getAcceptResultSubstates(txResult) {
|
|
@@ -1,39 +1,240 @@
|
|
|
1
|
-
import { TransactionArg } from "@tari-project/tarijs-types";
|
|
2
|
-
import {
|
|
3
|
-
import { NamedArg } from "../helpers
|
|
1
|
+
import { Amount, Network, TransactionArg } from "@tari-project/tarijs-types";
|
|
2
|
+
import { ComponentAddress, ConfidentialClaim, ConfidentialWithdrawProof, Instruction, ResourceAddress, SubstateRequirement, Transaction, TransactionSignature, UnsignedTransaction, PublishedTemplateAddress, UnsignedTransactionV1, AllocatableAddressType } from "@tari-project/typescript-bindings";
|
|
3
|
+
import { NamedArg } from "../helpers";
|
|
4
|
+
/**
|
|
5
|
+
* This interface defines the constructor for a Transaction object.
|
|
6
|
+
* It is used to create a new signed Transaction instance from an UnsignedTransaction and an array of TransactionSignatures.
|
|
7
|
+
* The constructor takes an UnsignedTransaction and an array of TransactionSignatures as parameters.
|
|
8
|
+
*/
|
|
4
9
|
export interface TransactionConstructor {
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new {@link Transaction} instance.
|
|
12
|
+
*
|
|
13
|
+
* @param unsignedTransaction - The UnsignedTransaction to create the Transaction from.
|
|
14
|
+
* @param signatures - An array of {@link TransactionSignature} objects, each containing:
|
|
15
|
+
* - `public_key`: A string representing a valid 32-byte Ristretto255 public key.
|
|
16
|
+
* - `signature`: An object containing:
|
|
17
|
+
* - `public_nonce`: A string representing the public nonce part of the Schnorr signature.
|
|
18
|
+
* - **NOTE:** Must be a valid 32-byte Ristretto255 public key, serialized as a hex string.
|
|
19
|
+
* - `signature`: A string representing the actual Schnorr signature scalar.
|
|
20
|
+
* - **NOTE:** Must be a valid 32-byte Schnorr signature scalar, serialized as a hex string.
|
|
21
|
+
*
|
|
22
|
+
* All fields must be validly encoded, canonical Ristretto255 public keys or Schnorr signature components in the correct format and length.
|
|
23
|
+
* Any deviation (e.g., wrong length, invalid encoding) will result in errors or failed signature verification.
|
|
24
|
+
*
|
|
25
|
+
* @returns A new Transaction instance.
|
|
26
|
+
*/
|
|
5
27
|
new (unsignedTransaction: UnsignedTransaction, signatures: TransactionSignature[]): Transaction;
|
|
6
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Defines a function that can be invoked on a published template in the Tari network.
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
7
33
|
export interface TariFunctionDefinition {
|
|
34
|
+
/**
|
|
35
|
+
* The name of the function to call. Should match the function defined in the published template.
|
|
36
|
+
*/
|
|
8
37
|
functionName: string;
|
|
38
|
+
/**
|
|
39
|
+
* The arguments to pass to the function. Optional.
|
|
40
|
+
*
|
|
41
|
+
* Each argument is a {@link NamedArg}, which represents either a literal value or a reference to a workspace variable.
|
|
42
|
+
*
|
|
43
|
+
* @see NamedArg for full structure and usage.
|
|
44
|
+
*/
|
|
9
45
|
args?: NamedArg[];
|
|
46
|
+
/**
|
|
47
|
+
* The unique address ({@link PublishedTemplateAddress}) of the published template (as a 64-character hexadecimal string, optionally prefixed by "template_").
|
|
48
|
+
*/
|
|
10
49
|
templateAddress: PublishedTemplateAddress;
|
|
11
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Defines a method that can be invoked on a component in the Tari network.
|
|
53
|
+
*/
|
|
12
54
|
export interface TariMethodDefinition {
|
|
55
|
+
/**
|
|
56
|
+
* The name of the method to call on the component.
|
|
57
|
+
*/
|
|
13
58
|
methodName: string;
|
|
59
|
+
/**
|
|
60
|
+
* Array of {@link TransactionArg} representing the arguments to pass to the method.
|
|
61
|
+
* These can be either literal values or references to workspace variables.
|
|
62
|
+
*/
|
|
14
63
|
args?: TransactionArg[];
|
|
64
|
+
/**
|
|
65
|
+
* The address of the component to call the method on.
|
|
66
|
+
*
|
|
67
|
+
* @remarks
|
|
68
|
+
* - Format: a 64-character hexadecimal string (representing 32 bytes), optionally prefixed by `"component_"`.
|
|
69
|
+
* - Must correspond to a valid, existing component on the Tari network.
|
|
70
|
+
* - Mutually exclusive with {@link TariMethodDefinition.fromWorkspace}.
|
|
71
|
+
* - If not provided, the method will be called on the component in the current workspace.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* "component_0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
|
|
75
|
+
*/
|
|
15
76
|
componentAddress?: ComponentAddress;
|
|
77
|
+
/**
|
|
78
|
+
* The workspace from which to call the method.
|
|
79
|
+
*
|
|
80
|
+
* @remarks
|
|
81
|
+
* - Mutually exclusive with {@link TariMethodDefinition.componentAddress}.
|
|
82
|
+
* - If provided, the method will be called on the component in the specified workspace.
|
|
83
|
+
* - The workspace must be defined in the current transaction context.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* "my_workspace"
|
|
87
|
+
*/
|
|
16
88
|
fromWorkspace?: string;
|
|
17
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Defines the interface for a Transaction Builder that allows constructing and signing transactions in the Tari network.
|
|
92
|
+
* This interface provides methods to add instructions, inputs, and other components to a transaction and then build a signed or unsigned transaction.
|
|
93
|
+
* The methods are chained together to allow for a fluent API style of transaction construction.
|
|
94
|
+
* The Builder interface is implemented by the {@link TransactionBuilder} class.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* // Usage:
|
|
98
|
+
* const builder: Builder = new TransactionBuilder();
|
|
99
|
+
* builder
|
|
100
|
+
* .createAccount(ownerPublicKey)
|
|
101
|
+
* .addInput(input)
|
|
102
|
+
* .withMinEpoch(5)
|
|
103
|
+
* .buildUnsignedTransaction();
|
|
104
|
+
*/
|
|
18
105
|
export interface Builder {
|
|
106
|
+
/**
|
|
107
|
+
* Adds a function call to the transaction, allowing the developer to invoke a function on a published template. This implements {@link TariFunctionDefinition}
|
|
108
|
+
* @param func - The function definition to call, which includes the function name, arguments, and template address.
|
|
109
|
+
* @param args - The arguments to pass to the function. These should be provided as an array of {@link NamedArg} objects. Optional.
|
|
110
|
+
* @returns The current instance of the Builder, allowing for method chaining.
|
|
111
|
+
*/
|
|
19
112
|
callFunction<T extends TariFunctionDefinition>(func: T, args: Exclude<T["args"], undefined>): this;
|
|
113
|
+
/**
|
|
114
|
+
* Adds a method call to the transaction, allowing the developer to invoke a method on a component. This implements {@link TariMethodDefinition}
|
|
115
|
+
* @param method - The method definition to call, which includes the method name, arguments, and component address.
|
|
116
|
+
* @param args - The arguments to pass to the method. These should be provided as an array of {@link TransactionArg} objects. Optional.
|
|
117
|
+
* @returns The current instance of the Builder, allowing for method chaining.
|
|
118
|
+
*/
|
|
20
119
|
callMethod<T extends TariMethodDefinition>(method: T, args: Exclude<T["args"], undefined>): this;
|
|
120
|
+
/**
|
|
121
|
+
* Adds an instruction to create a new account in the Tari Network to the transaction.
|
|
122
|
+
* @param ownerPublicKey - The public key of the account owner, represented as a 64-character hexadecimal string.
|
|
123
|
+
* @param workspaceBucket - An optional workspace bucket name to associate with the account. If provided, it will be used to create a workspace for the account. Allows for referencing the account elsewhere in the transaction without requiring it's address.
|
|
124
|
+
* @returns The current instance of the Builder, allowing for method chaining.
|
|
125
|
+
* @example
|
|
126
|
+
*/
|
|
21
127
|
createAccount(ownerPublicKey: string, workspaceBucket?: string): this;
|
|
128
|
+
/**
|
|
129
|
+
* Creates an internal proof that can be used to prove ownership of a resource in a component's account.
|
|
130
|
+
* @param account - The address of the component account that owns the resource. represented as a 64-character hexadecimal string, prepended with "component_".
|
|
131
|
+
* @param resourceAddress - The address of the resource to create a proof for, represented as a 64-character hexadecimal string, prepended with "resource_".
|
|
132
|
+
* @returns The current instance of the Builder, allowing for method chaining.
|
|
133
|
+
*/
|
|
22
134
|
createProof(account: ComponentAddress, resourceAddress: ResourceAddress): this;
|
|
135
|
+
/**
|
|
136
|
+
* Creates a variable in the workspace to store the output of the last instruction, which can be used later in the transaction.
|
|
137
|
+
* @param key - The name of the variable to save the last instruction's output to.
|
|
138
|
+
* @returns The current instance of the Builder, allowing for method chaining.
|
|
139
|
+
* @remarks
|
|
140
|
+
* Must be used after an instruction that produces an output, such as a function call or method call, and before any subsequent instructions that may use the saved variable.
|
|
141
|
+
*/
|
|
23
142
|
saveVar(key: string): this;
|
|
143
|
+
/**
|
|
144
|
+
* Calls a method to remove all proofs in the current workspace.
|
|
145
|
+
* @returns The current instance of the Builder, allowing for method chaining.
|
|
146
|
+
* @remarks
|
|
147
|
+
* Any proof references saved in the workspace via saveVar will be removed, invalidating any subsequent instructions that call on the variable.
|
|
148
|
+
*/
|
|
24
149
|
dropAllProofsInWorkspace(): this;
|
|
150
|
+
/**
|
|
151
|
+
* Adds a `ClaimBurn` instruction to the transaction, allowing the user to claim a previously burned confidential output.
|
|
152
|
+
*
|
|
153
|
+
* @param claim - A {@link ConfidentialClaim} object containing cryptographic proofs that authorize the claim. This includes the burn output address, ownership proof, range proof, and optional withdraw proof.
|
|
154
|
+
* @returns The current instance of the Builder, enabling method chaining.
|
|
155
|
+
* @remarks
|
|
156
|
+
* - The `ConfidentialClaim` must be constructed off-chain using valid cryptographic data.
|
|
157
|
+
* - If `withdraw_proof` is required by the burn process, it must be included.
|
|
158
|
+
* - This method should be used only when recovering burned confidential resources.
|
|
159
|
+
*/
|
|
25
160
|
claimBurn(claim: ConfidentialClaim): this;
|
|
26
161
|
addInput(inputObject: SubstateRequirement): this;
|
|
162
|
+
/** Adds a raw instruction to the transaction.
|
|
163
|
+
*
|
|
164
|
+
* @param instruction - A fully-formed {@link Instruction} object, such as `CreateAccount`, `CallMethod`, `ClaimBurn`, etc.
|
|
165
|
+
*
|
|
166
|
+
* @returns The current instance of the Builder for method chaining.
|
|
167
|
+
*
|
|
168
|
+
* @remarks
|
|
169
|
+
* This method allows advanced or low-level access to the instruction set used in the Tari transaction engine.
|
|
170
|
+
* It should typically be used when:
|
|
171
|
+
* - A specific instruction is not exposed via a dedicated builder method (e.g. `EmitLog`, `ClaimValidatorFees`)
|
|
172
|
+
* - You need to construct instructions dynamically at runtime (e.g. from config files or user input)
|
|
173
|
+
* - You require more control over optional fields not exposed in convenience methods (e.g. custom `owner_rule`)
|
|
174
|
+
* - You are working with experimental or less-common instructions
|
|
175
|
+
*
|
|
176
|
+
* For common operations like creating accounts or calling methods, prefer high-level builder methods
|
|
177
|
+
* such as `createAccount()` or `callMethod()` for better readability and type safety.
|
|
178
|
+
*/
|
|
27
179
|
addInstruction(instruction: Instruction): this;
|
|
28
180
|
addFeeInstruction(instruction: Instruction): this;
|
|
181
|
+
/**
|
|
182
|
+
* Allows for the addition of a condition to the transaction that requires the minimum epoch in which the transaction can be executed. Transaction fails if executed before this epoch.
|
|
183
|
+
* @param minEpoch - The minimum epoch in which the transaction can be executed. If not set, the transaction can be executed in any epoch.
|
|
184
|
+
* @returns The current instance of the Builder, allowing for method chaining.
|
|
185
|
+
*/
|
|
29
186
|
withMinEpoch(minEpoch: number): this;
|
|
187
|
+
/**
|
|
188
|
+
* Allows for the addition of a condition to the transaction that requires the maximum epoch in which the transaction can be executed. Transaction fails if executed after this epoch.
|
|
189
|
+
* @param maxEpoch - The maximum epoch in which the transaction can be executed. If not set, the transaction can be executed in any epoch.
|
|
190
|
+
* @returns The current instance of the Builder, allowing for method chaining.
|
|
191
|
+
*/
|
|
30
192
|
withMaxEpoch(maxEpoch: number): this;
|
|
193
|
+
/**
|
|
194
|
+
* Adds a substate requirement to the transaction, which is used to specify the inputs required for the transaction.
|
|
195
|
+
* @param inputs - An array of {@link SubstateRequirement} objects that define the inputs required for the transaction, consisting of substate IDs and optional versions. Typically, null version is used to indicate that any version of the substate is acceptable.
|
|
196
|
+
* @returns The current instance of the Builder, allowing for method
|
|
197
|
+
*/
|
|
31
198
|
withInputs(inputs: SubstateRequirement[]): this;
|
|
199
|
+
/**
|
|
200
|
+
* Similar to {@link addInstruction}, but allows for adding multiple instructions at once.
|
|
201
|
+
* @param instructions - An array of {@link Instruction} objects to add to the transaction. These instructions will be executed in the order they are added.
|
|
202
|
+
* @returns The current instance of the Builder, allowing for method chaining.
|
|
203
|
+
*/
|
|
32
204
|
withInstructions(instructions: Instruction[]): this;
|
|
205
|
+
/**
|
|
206
|
+
* Similar to {@link addFeeInstruction}, but allows for adding multiple fee instructions at once.
|
|
207
|
+
* This is useful for complex transactions that require multiple fee instructions.
|
|
208
|
+
* @param instructions - An array of {@link Instruction} objects to add as fee instructions. These instructions will be executed in the order they are added.
|
|
209
|
+
* @returns The current instance of the Builder, allowing for method chaining.
|
|
210
|
+
*/
|
|
33
211
|
withFeeInstructions(instructions: Instruction[]): this;
|
|
34
212
|
withFeeInstructionsBuilder(builder: (builder: TransactionBuilder) => this): this;
|
|
213
|
+
/**
|
|
214
|
+
* Allows for setting an existing unsigned transaction to build upon. This is useful for modifying or extending an existing unsigned transaction.
|
|
215
|
+
* @param unsignedTransaction - An {@link UnsignedTransactionV1} object representing the base transaction to build upon.
|
|
216
|
+
* @returns The current instance of the Builder, allowing for method chaining.
|
|
217
|
+
* @remarks
|
|
218
|
+
* Using withUnsignedTransaction() overwrites the builder’s current unsigned transaction state with the provided one.
|
|
219
|
+
* Useful in cases where the unsigned transaction has been (partially) constructed already.
|
|
220
|
+
*/
|
|
35
221
|
withUnsignedTransaction(unsignedTransaction: UnsignedTransactionV1): this;
|
|
36
|
-
|
|
222
|
+
/**
|
|
223
|
+
* Adds a method for specifying the component (typically an Account) that pays the transaction fee.
|
|
224
|
+
*
|
|
225
|
+
* @param componentAddress
|
|
226
|
+
* @param maxFee
|
|
227
|
+
* @remarks
|
|
228
|
+
* - The component must have a method `pay_fee` that calls `vault.pay_fee` with enough revealed confidential XTR.
|
|
229
|
+
* - Calls to vault.pay_fee lock up the `maxFee` amount for the duration of the transaction.
|
|
230
|
+
*/
|
|
231
|
+
feeTransactionPayFromComponent(componentAddress: ComponentAddress, maxFee: Amount): this;
|
|
232
|
+
/**
|
|
233
|
+
* Similar to {@link feeTransactionPayFromComponent}, but allows for paying the transaction fee using a confidential withdraw proof.
|
|
234
|
+
*
|
|
235
|
+
* @param componentAddress - The address of the component from which to pay the fee, represented as a 64-character hexadecimal string, optionally prefixed by "component_".
|
|
236
|
+
* @param proof - A {@link ConfidentialWithdrawProof} object containing the necessary cryptographic proofs to authorize the fee payment.
|
|
237
|
+
*/
|
|
37
238
|
feeTransactionPayFromComponentConfidential(componentAddress: ComponentAddress, proof: ConfidentialWithdrawProof): this;
|
|
38
239
|
buildUnsignedTransaction(): UnsignedTransactionV1;
|
|
39
240
|
build(): Transaction;
|
|
@@ -43,7 +244,8 @@ export declare class TransactionBuilder implements Builder {
|
|
|
43
244
|
private signatures;
|
|
44
245
|
private allocatedIds;
|
|
45
246
|
private current_id;
|
|
46
|
-
constructor(network: number);
|
|
247
|
+
constructor(network: Network | number);
|
|
248
|
+
static new(network: Network | number): TransactionBuilder;
|
|
47
249
|
callFunction<T extends TariFunctionDefinition>(func: T, args: Exclude<T["args"], undefined>): this;
|
|
48
250
|
callMethod<T extends TariMethodDefinition>(method: T, args: Exclude<T["args"], undefined>): this;
|
|
49
251
|
createAccount(ownerPublicKey: string, workspaceBucket?: string): this;
|
|
@@ -52,20 +254,20 @@ export declare class TransactionBuilder implements Builder {
|
|
|
52
254
|
allocateAddress(allocatableType: AllocatableAddressType, workspaceId: string): this;
|
|
53
255
|
assertBucketContains(workspaceName: string, resource_address: ResourceAddress, min_amount: Amount): this;
|
|
54
256
|
/**
|
|
55
|
-
*
|
|
257
|
+
* Puts the last instruction output into the workspace. These can be used as arguments subsequent instructions using `{Workspace: "my_name"}`.
|
|
258
|
+
* Alias to the `PutLastInstructionOutputOnWorkspace` instruction.
|
|
56
259
|
* `PutLastInstructionOutputOnWorkspace: { key: Array<number> }`
|
|
57
|
-
* to make saving variables easier.
|
|
58
260
|
*/
|
|
59
261
|
saveVar(name: string): this;
|
|
60
262
|
/**
|
|
61
|
-
* Adds a fee instruction that calls the `
|
|
62
|
-
* This method must
|
|
63
|
-
*
|
|
64
|
-
*
|
|
263
|
+
* Adds a fee instruction that calls the `pay_fee` method on a component (usually an Account).
|
|
264
|
+
* This method must call `vault.pay_fee` with a revealed confidential XTR resource.
|
|
265
|
+
* Calls to pay_fee lock up the `max_fee` amount for the duration of the transaction. Any remaining amount is
|
|
266
|
+
* returned to the component's vault.
|
|
65
267
|
*/
|
|
66
|
-
feeTransactionPayFromComponent(componentAddress: ComponentAddress, maxFee:
|
|
268
|
+
feeTransactionPayFromComponent(componentAddress: ComponentAddress, maxFee: Amount): this;
|
|
67
269
|
/**
|
|
68
|
-
* Adds a fee instruction that calls the `
|
|
270
|
+
* Adds a fee instruction that calls the `pay_fee_confidential` method on a component.
|
|
69
271
|
* This method must exist and return a Bucket with containing revealed confidential XTR resource.
|
|
70
272
|
* This allows the fee to originate from sources other than the transaction sender's account.
|
|
71
273
|
*/
|
|
@@ -22,6 +22,9 @@ export class TransactionBuilder {
|
|
|
22
22
|
this.allocatedIds = new Map();
|
|
23
23
|
this.current_id = 0;
|
|
24
24
|
}
|
|
25
|
+
static new(network) {
|
|
26
|
+
return new TransactionBuilder(network);
|
|
27
|
+
}
|
|
25
28
|
callFunction(func, args) {
|
|
26
29
|
const resolvedArgs = this.resolveArgs(args);
|
|
27
30
|
return this.addInstruction({
|
|
@@ -90,14 +93,14 @@ export class TransactionBuilder {
|
|
|
90
93
|
AssertBucketContains: {
|
|
91
94
|
key,
|
|
92
95
|
resource_address,
|
|
93
|
-
min_amount,
|
|
96
|
+
min_amount: min_amount.getValue(),
|
|
94
97
|
},
|
|
95
98
|
});
|
|
96
99
|
}
|
|
97
100
|
/**
|
|
98
|
-
*
|
|
101
|
+
* Puts the last instruction output into the workspace. These can be used as arguments subsequent instructions using `{Workspace: "my_name"}`.
|
|
102
|
+
* Alias to the `PutLastInstructionOutputOnWorkspace` instruction.
|
|
99
103
|
* `PutLastInstructionOutputOnWorkspace: { key: Array<number> }`
|
|
100
|
-
* to make saving variables easier.
|
|
101
104
|
*/
|
|
102
105
|
saveVar(name) {
|
|
103
106
|
let key = this.addNamedId(name);
|
|
@@ -108,22 +111,23 @@ export class TransactionBuilder {
|
|
|
108
111
|
});
|
|
109
112
|
}
|
|
110
113
|
/**
|
|
111
|
-
* Adds a fee instruction that calls the `
|
|
112
|
-
* This method must
|
|
113
|
-
*
|
|
114
|
-
*
|
|
114
|
+
* Adds a fee instruction that calls the `pay_fee` method on a component (usually an Account).
|
|
115
|
+
* This method must call `vault.pay_fee` with a revealed confidential XTR resource.
|
|
116
|
+
* Calls to pay_fee lock up the `max_fee` amount for the duration of the transaction. Any remaining amount is
|
|
117
|
+
* returned to the component's vault.
|
|
115
118
|
*/
|
|
116
119
|
feeTransactionPayFromComponent(componentAddress, maxFee) {
|
|
117
120
|
return this.addFeeInstruction({
|
|
118
121
|
CallMethod: {
|
|
119
122
|
call: { Address: componentAddress },
|
|
120
123
|
method: "pay_fee",
|
|
121
|
-
|
|
124
|
+
// @ts-ignore TODO: once bindings are updated, remove ts-ignore
|
|
125
|
+
args: [maxFee.getValue()],
|
|
122
126
|
},
|
|
123
127
|
});
|
|
124
128
|
}
|
|
125
129
|
/**
|
|
126
|
-
* Adds a fee instruction that calls the `
|
|
130
|
+
* Adds a fee instruction that calls the `pay_fee_confidential` method on a component.
|
|
127
131
|
* This method must exist and return a Bucket with containing revealed confidential XTR resource.
|
|
128
132
|
* This allows the fee to originate from sources other than the transaction sender's account.
|
|
129
133
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/tarijs-builders",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
"author": "The Tari Community",
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@tari-project/typescript-bindings": ">=1.
|
|
14
|
-
"@tari-project/
|
|
15
|
-
"@tari-project/
|
|
16
|
-
"@tari-project/tari-universe-signer": "^0.
|
|
13
|
+
"@tari-project/typescript-bindings": ">=1.14.0",
|
|
14
|
+
"@tari-project/tari-signer": "^0.12.0",
|
|
15
|
+
"@tari-project/tarijs-types": "^0.12.0",
|
|
16
|
+
"@tari-project/tari-universe-signer": "^0.12.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/node": "^22.13.1",
|