@tari-project/tarijs 0.6.0 → 0.9.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/.github/PULL_REQUEST_TEMPLATE.md +2 -12
- package/Dockerfile +2 -2
- package/README.md +1 -1
- package/docusaurus/tari-docs/docs/provider-vs-signer.md +27 -0
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/build-execute-request.md +0 -2
- package/docusaurus/tari-docs/docs/wallet/submit-transaction/transaction-builder/inputs.md +0 -1
- package/docusaurus/tari-docs/package-lock.json +17964 -0
- package/docusaurus/tari-docs/package.json +2 -2
- package/package.json +1 -1
- package/packages/builders/package.json +3 -2
- package/packages/builders/src/helpers/index.ts +1 -1
- package/packages/builders/src/helpers/submitTransaction.ts +26 -31
- package/packages/builders/src/helpers/workspace.ts +32 -15
- package/packages/builders/src/index.ts +1 -2
- package/packages/builders/src/transaction/TransactionBuilder.ts +105 -38
- package/packages/builders/src/transaction/TransactionRequest.ts +30 -38
- package/packages/indexer_provider/package.json +1 -1
- package/packages/metamask_signer/package.json +1 -1
- package/packages/metamask_signer/src/index.ts +12 -19
- package/packages/tari_permissions/package.json +1 -1
- package/packages/tari_permissions/src/tari_permissions.ts +1 -17
- package/packages/tari_provider/package.json +1 -1
- package/packages/tari_signer/package.json +1 -1
- package/packages/tari_universe/package.json +1 -1
- package/packages/tarijs/package.json +1 -1
- package/packages/tarijs/src/index.ts +0 -8
- package/packages/tarijs/test/integration-tests/wallet_daemon/json_rpc_provider.spec.ts +74 -44
- package/packages/tarijs_types/package.json +1 -1
- package/packages/tarijs_types/src/SubstateDiff.ts +0 -4
- package/packages/tarijs_types/src/SubstateType.ts +1 -1
- package/packages/tarijs_types/src/TransactionResult.ts +2 -8
- package/packages/tarijs_types/src/TransactionStatus.ts +7 -7
- package/packages/tarijs_types/src/helpers/txResult.ts +8 -11
- package/packages/tarijs_types/src/index.ts +1 -16
- package/packages/tarijs_types/src/signer.ts +6 -11
- package/packages/wallet_daemon/package.json +1 -1
- package/packages/wallet_daemon/src/signer.ts +12 -25
- package/packages/wallet_daemon/src/webrtc.ts +3 -3
- package/packages/walletconnect/package.json +1 -1
- package/packages/walletconnect/src/index.ts +14 -28
- package/pnpm-workspace.yaml +2 -2
- package/scripts/check_versions.sh +2 -2
- package/scripts/set_package_versions.sh +39 -0
- package/packages/tarijs_types/src/FinalizeResult.ts +0 -17
- package/packages/tarijs_types/src/Instruction.ts +0 -36
- package/packages/tarijs_types/src/SubstateRequirement.ts +0 -6
- package/packages/tarijs_types/src/Transaction.ts +0 -16
- package/packages/tarijs_types/src/UnsignedTransaction.ts +0 -14
- package/packages/tarijs_types/src/VersionedSubstateId.ts +0 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tari-docs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"private": true,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"docusaurus": "docusaurus",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"typecheck": "tsc"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@docusaurus/core": "3.7.0",
|
|
18
|
+
"@docusaurus/core": "^3.7.0",
|
|
19
19
|
"@docusaurus/preset-classic": "3.7.0",
|
|
20
20
|
"@docusaurus/remark-plugin-npm2yarn": "^3.7.0",
|
|
21
21
|
"@mdx-js/react": "^3.0.0",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/tarijs-builders",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@tari-project/tari-signer": "workspace:^",
|
|
17
17
|
"@tari-project/tari-universe-signer": "workspace:^",
|
|
18
|
-
"@tari-project/tarijs-types": "workspace:^"
|
|
18
|
+
"@tari-project/tarijs-types": "workspace:^",
|
|
19
|
+
"@tari-project/typescript-bindings": "catalog:"
|
|
19
20
|
},
|
|
20
21
|
"devDependencies": {
|
|
21
22
|
"@types/node": "catalog:",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { buildTransactionRequest, submitAndWaitForTransaction, waitForTransactionResult } from "./submitTransaction";
|
|
2
|
-
export {
|
|
2
|
+
export { parseWorkspaceStringKey, NamedArg } from "./workspace";
|
|
@@ -1,40 +1,28 @@
|
|
|
1
1
|
import { TariUniverseSigner } from "@tari-project/tari-universe-signer";
|
|
2
2
|
import { TariSigner } from "@tari-project/tari-signer";
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
ComponentAddress,
|
|
5
|
+
substateIdToString,
|
|
5
6
|
TransactionResult,
|
|
6
|
-
|
|
7
|
+
UnsignedTransactionV1,
|
|
8
|
+
} from "@tari-project/typescript-bindings";
|
|
9
|
+
import {
|
|
7
10
|
DownSubstates,
|
|
8
11
|
UpSubstates,
|
|
9
|
-
|
|
10
|
-
ReqSubstate,
|
|
12
|
+
getSubstateValueFromUpSubstates,
|
|
11
13
|
SubmitTransactionRequest,
|
|
12
|
-
|
|
14
|
+
TransactionStatus,
|
|
13
15
|
} from "@tari-project/tarijs-types";
|
|
14
|
-
import {
|
|
16
|
+
import { SubmitTxResult } from "@tari-project/tarijs-types/dist/TransactionResult";
|
|
15
17
|
|
|
16
18
|
export function buildTransactionRequest(
|
|
17
|
-
transaction:
|
|
19
|
+
transaction: UnsignedTransactionV1,
|
|
18
20
|
accountId: number,
|
|
19
|
-
requiredSubstates: ReqSubstate[],
|
|
20
|
-
inputRefs = [],
|
|
21
|
-
isDryRun = false,
|
|
22
|
-
network = 0,
|
|
23
|
-
isSealSignerAuthorized = true,
|
|
24
21
|
detectInputsUseUnversioned = true,
|
|
25
22
|
): SubmitTransactionRequest {
|
|
26
23
|
return {
|
|
27
|
-
|
|
24
|
+
transaction,
|
|
28
25
|
account_id: accountId,
|
|
29
|
-
instructions: transaction.instructions as object[],
|
|
30
|
-
fee_instructions: transaction.feeInstructions as object[],
|
|
31
|
-
inputs: transaction.inputs,
|
|
32
|
-
input_refs: inputRefs as object[],
|
|
33
|
-
required_substates: requiredSubstates,
|
|
34
|
-
is_dry_run: isDryRun,
|
|
35
|
-
min_epoch: transaction.minEpoch ?? null,
|
|
36
|
-
max_epoch: transaction.maxEpoch ?? null,
|
|
37
|
-
is_seal_signer_authorized: isSealSignerAuthorized,
|
|
38
26
|
detect_inputs_use_unversioned: detectInputsUseUnversioned,
|
|
39
27
|
};
|
|
40
28
|
}
|
|
@@ -95,7 +83,7 @@ export async function waitForTransactionResult(
|
|
|
95
83
|
throw new Error(`Transaction rejected: ${JSON.stringify(resp.result)}`);
|
|
96
84
|
}
|
|
97
85
|
if (FINALIZED_STATUSES.includes(resp.status)) {
|
|
98
|
-
return resp
|
|
86
|
+
return resp.result?.result!;
|
|
99
87
|
}
|
|
100
88
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
101
89
|
}
|
|
@@ -105,16 +93,23 @@ export function getAcceptResultSubstates(txResult: TransactionResult): {
|
|
|
105
93
|
upSubstates: UpSubstates;
|
|
106
94
|
downSubstates: DownSubstates;
|
|
107
95
|
} {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (result && txResultCheck.isAcceptFeeRejectRest(result)) {
|
|
96
|
+
if ("Accept" in txResult) {
|
|
111
97
|
return {
|
|
112
|
-
upSubstates:
|
|
113
|
-
downSubstates:
|
|
98
|
+
upSubstates: txResult.Accept.up_substates,
|
|
99
|
+
downSubstates: txResult.Accept.down_substates,
|
|
114
100
|
};
|
|
115
101
|
}
|
|
116
|
-
|
|
117
|
-
|
|
102
|
+
|
|
103
|
+
if ("Reject" in txResult) {
|
|
104
|
+
throw new Error(`Transaction rejected: ${txResult.Reject}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if ("AcceptFeeRejectRest" in txResult) {
|
|
108
|
+
return {
|
|
109
|
+
upSubstates: txResult.AcceptFeeRejectRest[0].up_substates,
|
|
110
|
+
downSubstates: txResult.AcceptFeeRejectRest[0].down_substates,
|
|
111
|
+
};
|
|
118
112
|
}
|
|
119
|
-
|
|
113
|
+
|
|
114
|
+
throw new Error(`Unexpected transaction result: ${JSON.stringify(txResult)}`);
|
|
120
115
|
}
|
|
@@ -1,25 +1,42 @@
|
|
|
1
|
-
import { WorkspaceArg } from "@tari-project/tarijs-types";
|
|
1
|
+
import { TransactionArg, WorkspaceArg } from "@tari-project/tarijs-types";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* key: "bucket" -> "6275636b6574"
|
|
9
|
-
* key: "bucket.0" -> "6275636b65742e30"
|
|
10
|
-
* key: "bucket.1" -> "6275636b65742e31"
|
|
4
|
+
* A parsed workspace key string into an object with name and optional offset.
|
|
5
|
+
* Examples:
|
|
6
|
+
* "bucket" -> { name: "bucket", offset: undefined }
|
|
7
|
+
* "bucket.0" -> { name: "bucket", offset: 0 }
|
|
11
8
|
*/
|
|
12
|
-
export
|
|
13
|
-
|
|
9
|
+
export interface ParsedBuildersWorkspaceKey {
|
|
10
|
+
name: string;
|
|
11
|
+
offset: number | null;
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
/**
|
|
17
15
|
*
|
|
18
|
-
* @param key workspace name
|
|
19
|
-
* @returns
|
|
16
|
+
* @param key workspace name. Offsets can be specified with a dot notation, e.g. "bucket.0"
|
|
17
|
+
* @returns Parsed workspace key object
|
|
20
18
|
* @example
|
|
21
|
-
* key: "bucket"
|
|
19
|
+
* key: "bucket" -> { name: "bucket", offset: undefined }
|
|
20
|
+
* key: "bucket.0" -> { name: "bucket", offset: 0 }
|
|
21
|
+
* key: "bucket.1" -> { name: "bucket", offset: 1 }
|
|
22
22
|
*/
|
|
23
|
-
export function
|
|
24
|
-
|
|
23
|
+
export function parseWorkspaceStringKey(key: string): ParsedBuildersWorkspaceKey {
|
|
24
|
+
const parts = key.split(".");
|
|
25
|
+
if (parts.length > 2) {
|
|
26
|
+
throw new Error("Invalid workspace key format. Only one dot is allowed.");
|
|
27
|
+
}
|
|
28
|
+
const name = parts[0];
|
|
29
|
+
const offset = parts[1] ? parseInt(parts[1], 10) : null;
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
name,
|
|
33
|
+
offset,
|
|
34
|
+
};
|
|
25
35
|
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Either a literal Transaction Arg or a named workspace argument.
|
|
39
|
+
* Named workspace arguments are used to refer to a workspace by name,
|
|
40
|
+
* and are converted to numeric IDs by the TransactionBuilder.
|
|
41
|
+
*/
|
|
42
|
+
export type NamedArg = { Workspace: string } | TransactionArg;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// Copyright 2024 The Tari Project
|
|
2
2
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
3
|
-
import { toWorkspace } from "../helpers";
|
|
4
3
|
|
|
5
4
|
import { TransactionRequest } from "./TransactionRequest";
|
|
5
|
+
import { TransactionArg } from "@tari-project/tarijs-types";
|
|
6
6
|
import {
|
|
7
|
+
Amount,
|
|
7
8
|
ComponentAddress,
|
|
8
9
|
ConfidentialClaim,
|
|
9
10
|
ConfidentialWithdrawProof,
|
|
@@ -14,24 +15,28 @@ import {
|
|
|
14
15
|
TransactionSignature,
|
|
15
16
|
UnsignedTransaction,
|
|
16
17
|
PublishedTemplateAddress,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} from "@tari-project/
|
|
18
|
+
WorkspaceOffsetId,
|
|
19
|
+
UnsignedTransactionV1, AllocatableAddressType,
|
|
20
|
+
} from "@tari-project/typescript-bindings";
|
|
21
|
+
import { parseWorkspaceStringKey } from "../helpers";
|
|
22
|
+
import { NamedArg } from "../helpers/workspace";
|
|
20
23
|
|
|
21
24
|
export interface TransactionConstructor {
|
|
22
|
-
new
|
|
25
|
+
new(unsignedTransaction: UnsignedTransaction, signatures: TransactionSignature[]): Transaction;
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
export interface TariFunctionDefinition {
|
|
26
29
|
functionName: string;
|
|
27
|
-
args?:
|
|
30
|
+
args?: NamedArg[];
|
|
28
31
|
templateAddress: PublishedTemplateAddress;
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
export interface TariMethodDefinition {
|
|
32
35
|
methodName: string;
|
|
33
36
|
args?: TransactionArg[];
|
|
34
|
-
componentAddress:
|
|
37
|
+
// These are mutually exclusive i.e. either componentAddress or fromWorkspace (TODO: define this properly in typescript)
|
|
38
|
+
componentAddress?: ComponentAddress;
|
|
39
|
+
fromWorkspace?: string,
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
export interface TariCreateAccountDefinition {
|
|
@@ -75,7 +80,7 @@ export interface Builder {
|
|
|
75
80
|
|
|
76
81
|
withFeeInstructionsBuilder(builder: (builder: TransactionBuilder) => this): this;
|
|
77
82
|
|
|
78
|
-
withUnsignedTransaction(unsignedTransaction:
|
|
83
|
+
withUnsignedTransaction(unsignedTransaction: UnsignedTransactionV1): this;
|
|
79
84
|
|
|
80
85
|
feeTransactionPayFromComponent(componentAddress: ComponentAddress, maxFee: string): this;
|
|
81
86
|
|
|
@@ -84,52 +89,70 @@ export interface Builder {
|
|
|
84
89
|
proof: ConfidentialWithdrawProof,
|
|
85
90
|
): this;
|
|
86
91
|
|
|
87
|
-
buildUnsignedTransaction():
|
|
92
|
+
buildUnsignedTransaction(): UnsignedTransactionV1;
|
|
88
93
|
|
|
89
94
|
build(): Transaction;
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
export class TransactionBuilder implements Builder {
|
|
93
|
-
private unsignedTransaction:
|
|
98
|
+
private unsignedTransaction: UnsignedTransactionV1;
|
|
94
99
|
private signatures: TransactionSignature[];
|
|
100
|
+
private allocatedIds: Map<string, number>;
|
|
101
|
+
private current_id: number;
|
|
95
102
|
|
|
96
|
-
constructor() {
|
|
103
|
+
constructor(network: number) {
|
|
97
104
|
this.unsignedTransaction = {
|
|
98
|
-
|
|
105
|
+
network,
|
|
106
|
+
fee_instructions: [],
|
|
99
107
|
instructions: [],
|
|
100
108
|
inputs: [],
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
109
|
+
min_epoch: null,
|
|
110
|
+
max_epoch: null,
|
|
111
|
+
dry_run: false,
|
|
112
|
+
is_seal_signer_authorized: false
|
|
104
113
|
};
|
|
105
114
|
this.signatures = [];
|
|
115
|
+
this.allocatedIds = new Map();
|
|
116
|
+
this.current_id = 0;
|
|
106
117
|
}
|
|
107
118
|
|
|
108
119
|
public callFunction<T extends TariFunctionDefinition>(func: T, args: Exclude<T["args"], undefined>): this {
|
|
120
|
+
const resolvedArgs = this.resolveArgs(args);
|
|
109
121
|
return this.addInstruction({
|
|
110
122
|
CallFunction: {
|
|
111
|
-
|
|
123
|
+
address: func.templateAddress,
|
|
112
124
|
function: func.functionName,
|
|
113
|
-
args,
|
|
125
|
+
args: resolvedArgs,
|
|
114
126
|
},
|
|
115
127
|
});
|
|
116
128
|
}
|
|
117
129
|
|
|
118
130
|
public callMethod<T extends TariMethodDefinition>(method: T, args: Exclude<T["args"], undefined>): this {
|
|
131
|
+
const call = method.componentAddress ?
|
|
132
|
+
{ Address: method.componentAddress } :
|
|
133
|
+
// NOTE: offset IDs are not supported for method calls
|
|
134
|
+
{ Workspace: this.getNamedId(method.fromWorkspace!)! };
|
|
135
|
+
const resolvedArgs = this.resolveArgs(args);
|
|
119
136
|
return this.addInstruction({
|
|
120
137
|
CallMethod: {
|
|
121
|
-
|
|
138
|
+
call,
|
|
122
139
|
method: method.methodName,
|
|
123
|
-
args,
|
|
140
|
+
args: resolvedArgs,
|
|
124
141
|
},
|
|
125
142
|
});
|
|
126
143
|
}
|
|
127
144
|
|
|
128
145
|
public createAccount(ownerPublicKey: string, workspaceBucket?: string): this {
|
|
146
|
+
const workspace_id = workspaceBucket ?
|
|
147
|
+
this.getOffsetIdFromWorkspaceName(workspaceBucket) :
|
|
148
|
+
null;
|
|
149
|
+
|
|
129
150
|
return this.addInstruction({
|
|
130
151
|
CreateAccount: {
|
|
131
|
-
|
|
132
|
-
|
|
152
|
+
public_key_address: ownerPublicKey,
|
|
153
|
+
owner_rule: null, // Custom owner rule is not set by default
|
|
154
|
+
access_rules: null, // Custom access rules are not set by default
|
|
155
|
+
workspace_id,
|
|
133
156
|
},
|
|
134
157
|
});
|
|
135
158
|
}
|
|
@@ -137,7 +160,7 @@ export class TransactionBuilder implements Builder {
|
|
|
137
160
|
public createProof(account: ComponentAddress, resourceAddress: ResourceAddress): this {
|
|
138
161
|
return this.addInstruction({
|
|
139
162
|
CallMethod: {
|
|
140
|
-
|
|
163
|
+
call: {Address: account},
|
|
141
164
|
method: "create_proof_for_resource",
|
|
142
165
|
args: [resourceAddress],
|
|
143
166
|
},
|
|
@@ -152,11 +175,23 @@ export class TransactionBuilder implements Builder {
|
|
|
152
175
|
});
|
|
153
176
|
}
|
|
154
177
|
|
|
155
|
-
public allocateAddress(
|
|
178
|
+
public allocateAddress(allocatableType: AllocatableAddressType, workspaceId: string): this {
|
|
179
|
+
const workspace_id = this.addNamedId(workspaceId);
|
|
156
180
|
return this.addInstruction({
|
|
157
181
|
AllocateAddress: {
|
|
158
|
-
|
|
159
|
-
workspace_id
|
|
182
|
+
allocatable_type: allocatableType,
|
|
183
|
+
workspace_id,
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public assertBucketContains(workspaceName: string, resource_address: ResourceAddress, min_amount: Amount): this {
|
|
189
|
+
const key = this.getOffsetIdFromWorkspaceName(workspaceName);
|
|
190
|
+
return this.addInstruction({
|
|
191
|
+
AssertBucketContains: {
|
|
192
|
+
key,
|
|
193
|
+
resource_address,
|
|
194
|
+
min_amount,
|
|
160
195
|
},
|
|
161
196
|
});
|
|
162
197
|
}
|
|
@@ -166,10 +201,11 @@ export class TransactionBuilder implements Builder {
|
|
|
166
201
|
* `PutLastInstructionOutputOnWorkspace: { key: Array<number> }`
|
|
167
202
|
* to make saving variables easier.
|
|
168
203
|
*/
|
|
169
|
-
public saveVar(
|
|
204
|
+
public saveVar(name: string): this {
|
|
205
|
+
let key = this.addNamedId(name);
|
|
170
206
|
return this.addInstruction({
|
|
171
207
|
PutLastInstructionOutputOnWorkspace: {
|
|
172
|
-
key
|
|
208
|
+
key,
|
|
173
209
|
},
|
|
174
210
|
});
|
|
175
211
|
}
|
|
@@ -183,7 +219,7 @@ export class TransactionBuilder implements Builder {
|
|
|
183
219
|
public feeTransactionPayFromComponent(componentAddress: ComponentAddress, maxFee: string): this {
|
|
184
220
|
return this.addFeeInstruction({
|
|
185
221
|
CallMethod: {
|
|
186
|
-
|
|
222
|
+
call: {Address: componentAddress},
|
|
187
223
|
method: "pay_fee",
|
|
188
224
|
args: [maxFee],
|
|
189
225
|
},
|
|
@@ -201,7 +237,7 @@ export class TransactionBuilder implements Builder {
|
|
|
201
237
|
): this {
|
|
202
238
|
return this.addFeeInstruction({
|
|
203
239
|
CallMethod: {
|
|
204
|
-
|
|
240
|
+
call: { Address: componentAddress },
|
|
205
241
|
method: "pay_fee_confidential",
|
|
206
242
|
args: [proof],
|
|
207
243
|
},
|
|
@@ -212,21 +248,21 @@ export class TransactionBuilder implements Builder {
|
|
|
212
248
|
return this.addInstruction("DropAllProofsInWorkspace");
|
|
213
249
|
}
|
|
214
250
|
|
|
215
|
-
public withUnsignedTransaction(unsignedTransaction:
|
|
251
|
+
public withUnsignedTransaction(unsignedTransaction: UnsignedTransactionV1): this {
|
|
216
252
|
this.unsignedTransaction = unsignedTransaction;
|
|
217
253
|
this.signatures = [];
|
|
218
254
|
return this;
|
|
219
255
|
}
|
|
220
256
|
|
|
221
257
|
public withFeeInstructions(instructions: Instruction[]): this {
|
|
222
|
-
this.unsignedTransaction.
|
|
258
|
+
this.unsignedTransaction.fee_instructions = instructions;
|
|
223
259
|
this.signatures = [];
|
|
224
260
|
return this;
|
|
225
261
|
}
|
|
226
262
|
|
|
227
263
|
public withFeeInstructionsBuilder(builder: (builder: TransactionBuilder) => TransactionBuilder): this {
|
|
228
|
-
const newBuilder = builder(new TransactionBuilder());
|
|
229
|
-
this.unsignedTransaction.
|
|
264
|
+
const newBuilder = builder(new TransactionBuilder(this.unsignedTransaction.network));
|
|
265
|
+
this.unsignedTransaction.fee_instructions = newBuilder.unsignedTransaction.instructions;
|
|
230
266
|
this.signatures = [];
|
|
231
267
|
return this;
|
|
232
268
|
}
|
|
@@ -238,7 +274,7 @@ export class TransactionBuilder implements Builder {
|
|
|
238
274
|
}
|
|
239
275
|
|
|
240
276
|
public addFeeInstruction(instruction: Instruction): this {
|
|
241
|
-
this.unsignedTransaction.
|
|
277
|
+
this.unsignedTransaction.fee_instructions.push(instruction);
|
|
242
278
|
this.signatures = [];
|
|
243
279
|
return this;
|
|
244
280
|
}
|
|
@@ -262,24 +298,55 @@ export class TransactionBuilder implements Builder {
|
|
|
262
298
|
}
|
|
263
299
|
|
|
264
300
|
public withMinEpoch(minEpoch: number): this {
|
|
265
|
-
this.unsignedTransaction.
|
|
301
|
+
this.unsignedTransaction.min_epoch = minEpoch;
|
|
266
302
|
// Reset the signatures as they are no longer valid
|
|
267
303
|
this.signatures = [];
|
|
268
304
|
return this;
|
|
269
305
|
}
|
|
270
306
|
|
|
271
307
|
public withMaxEpoch(maxEpoch: number): this {
|
|
272
|
-
this.unsignedTransaction.
|
|
308
|
+
this.unsignedTransaction.max_epoch = maxEpoch;
|
|
273
309
|
// Reset the signatures as they are no longer valid
|
|
274
310
|
this.signatures = [];
|
|
275
311
|
return this;
|
|
276
312
|
}
|
|
277
313
|
|
|
278
|
-
public buildUnsignedTransaction():
|
|
314
|
+
public buildUnsignedTransaction(): UnsignedTransactionV1 {
|
|
279
315
|
return this.unsignedTransaction;
|
|
280
316
|
}
|
|
281
317
|
|
|
282
318
|
public build(): Transaction {
|
|
283
|
-
return new TransactionRequest(this.
|
|
319
|
+
return new TransactionRequest(this.buildUnsignedTransaction(), this.signatures);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
private addNamedId(name: string): number {
|
|
323
|
+
const id = this.current_id;
|
|
324
|
+
this.allocatedIds.set(name, id);
|
|
325
|
+
this.current_id += 1;
|
|
326
|
+
return id;
|
|
284
327
|
}
|
|
328
|
+
|
|
329
|
+
private getNamedId(name: string): number | undefined {
|
|
330
|
+
return this.allocatedIds.get(name);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
private getOffsetIdFromWorkspaceName(name: string): WorkspaceOffsetId {
|
|
334
|
+
const parsed = parseWorkspaceStringKey(name);
|
|
335
|
+
const id = this.getNamedId(parsed.name);
|
|
336
|
+
if (id === undefined) {
|
|
337
|
+
throw new Error(`No workspace with name ${parsed.name} found`);
|
|
338
|
+
}
|
|
339
|
+
return { id, offset: parsed.offset };
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
private resolveArgs(args: NamedArg[]): TransactionArg[] {
|
|
343
|
+
return args.map((arg) => {
|
|
344
|
+
if (typeof arg === "object" && "Workspace" in arg) {
|
|
345
|
+
const workspaceId = this.getOffsetIdFromWorkspaceName(arg.Workspace);
|
|
346
|
+
return { Workspace: workspaceId };
|
|
347
|
+
}
|
|
348
|
+
return arg;
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
|
|
285
352
|
}
|
|
@@ -3,74 +3,66 @@ import {
|
|
|
3
3
|
Instruction,
|
|
4
4
|
SubstateRequirement,
|
|
5
5
|
Transaction,
|
|
6
|
+
UnsignedTransactionV1,
|
|
6
7
|
TransactionSignature,
|
|
7
|
-
UnsignedTransaction,
|
|
8
8
|
VersionedSubstateId,
|
|
9
|
-
|
|
9
|
+
TransactionV1,
|
|
10
|
+
} from "@tari-project/typescript-bindings";
|
|
11
|
+
|
|
10
12
|
|
|
11
13
|
///TODO this implementation is not fully done, see:
|
|
12
|
-
/// https://github.com/tari-project/tari-
|
|
14
|
+
/// https://github.com/tari-project/tari-ootle/blob/development/dan_layer/transaction/src/transaction.rs
|
|
13
15
|
export class TransactionRequest implements Transaction {
|
|
14
16
|
id: string;
|
|
15
|
-
|
|
16
|
-
instructions: Array<Instruction>;
|
|
17
|
-
inputs: Array<SubstateRequirement>;
|
|
18
|
-
signatures: Array<TransactionSignature>;
|
|
19
|
-
unsignedTransaction: UnsignedTransaction;
|
|
20
|
-
minEpoch?: Epoch;
|
|
21
|
-
maxEpoch?: Epoch;
|
|
22
|
-
filledInputs: VersionedSubstateId[];
|
|
17
|
+
V1: TransactionV1;
|
|
23
18
|
|
|
24
|
-
constructor(unsignedTransaction:
|
|
19
|
+
constructor(unsignedTransaction: UnsignedTransactionV1, signatures: TransactionSignature[]) {
|
|
25
20
|
this.id = "";
|
|
26
|
-
this.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
this.V1 = {
|
|
22
|
+
body: {
|
|
23
|
+
transaction: unsignedTransaction,
|
|
24
|
+
signatures,
|
|
25
|
+
},
|
|
26
|
+
seal_signature: {
|
|
27
|
+
public_key: "",
|
|
28
|
+
signature: {
|
|
29
|
+
public_nonce: "",
|
|
30
|
+
signature: "",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
withFilledInputs(filled_inputs: Array<VersionedSubstateId>): this {
|
|
37
37
|
return { ...this, filled_inputs };
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
getUnsignedTransaction():
|
|
41
|
-
return this.
|
|
40
|
+
getUnsignedTransaction(): UnsignedTransactionV1 {
|
|
41
|
+
return this.V1.body.transaction;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
getFeeInstructions(): Instruction[] {
|
|
45
|
-
return this.
|
|
45
|
+
return this.V1.body.transaction.fee_instructions;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
getInstructions(): Instruction[] {
|
|
49
|
-
return this.instructions;
|
|
49
|
+
return this.V1.body.transaction.instructions;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
getSignatures(): TransactionSignature[] {
|
|
53
|
-
return this.signatures;
|
|
53
|
+
return this.V1.body.signatures;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
getInputs(): SubstateRequirement[] {
|
|
57
|
-
return this.inputs;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
getFilledInputs(): VersionedSubstateId[] {
|
|
61
|
-
return this.filledInputs;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
getFilledInputsMut(): VersionedSubstateId[] {
|
|
65
|
-
return this.filledInputs;
|
|
57
|
+
return this.V1.body.transaction.inputs;
|
|
66
58
|
}
|
|
67
59
|
|
|
68
|
-
getMinEpoch(): Epoch |
|
|
69
|
-
return this.
|
|
60
|
+
getMinEpoch(): Epoch | null {
|
|
61
|
+
return this.V1.body.transaction.min_epoch;
|
|
70
62
|
}
|
|
71
63
|
|
|
72
|
-
getMaxEpoch(): Epoch |
|
|
73
|
-
return this.
|
|
64
|
+
getMaxEpoch(): Epoch | null {
|
|
65
|
+
return this.V1.body.transaction.max_epoch;
|
|
74
66
|
}
|
|
75
67
|
|
|
76
68
|
setId(id: string): void {
|