@thru/thru-sdk 0.1.19 → 0.1.21
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/README.md +19 -0
- package/dist/{chunk-PH7P5EEU.js → chunk-SHMREHP5.js} +13 -9
- package/dist/chunk-SHMREHP5.js.map +1 -0
- package/dist/client.d.ts +2 -1
- package/dist/client.js +3 -2
- package/dist/client.js.map +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/sdk.d.ts +3 -3
- package/dist/sdk.js +1 -1
- package/dist/{transactions-BzD9hYlc.d.ts → transactions-CLezIeXO.d.ts} +20 -18
- package/package.json +7 -3
- package/buf.gen.yaml +0 -12
- package/buf.lock +0 -9
- package/buf.yaml +0 -15
- package/dist/chunk-PH7P5EEU.js.map +0 -1
- package/proto/thru/common/v1/consensus.proto +0 -73
- package/proto/thru/common/v1/errors.proto +0 -65
- package/proto/thru/common/v1/filters.proto +0 -60
- package/proto/thru/common/v1/pagination.proto +0 -45
- package/proto/thru/core/v1/account.proto +0 -137
- package/proto/thru/core/v1/block.proto +0 -80
- package/proto/thru/core/v1/state.proto +0 -35
- package/proto/thru/core/v1/transaction.proto +0 -136
- package/proto/thru/core/v1/types.proto +0 -50
- package/proto/thru/services/v1/command_service.proto +0 -70
- package/proto/thru/services/v1/query_service.proto +0 -344
- package/proto/thru/services/v1/streaming_service.proto +0 -126
- package/thru-ts-client-sdk/__tests__/helpers/test-utils.ts +0 -228
- package/thru-ts-client-sdk/client.ts +0 -10
- package/thru-ts-client-sdk/core/__tests__/bound-client.test.ts +0 -354
- package/thru-ts-client-sdk/core/__tests__/client.test.ts +0 -53
- package/thru-ts-client-sdk/core/bound-client.ts +0 -156
- package/thru-ts-client-sdk/core/client.ts +0 -38
- package/thru-ts-client-sdk/defaults.ts +0 -26
- package/thru-ts-client-sdk/modules/__tests__/accounts.test.ts +0 -406
- package/thru-ts-client-sdk/modules/__tests__/blocks.test.ts +0 -199
- package/thru-ts-client-sdk/modules/__tests__/events.test.ts +0 -74
- package/thru-ts-client-sdk/modules/__tests__/height.test.ts +0 -39
- package/thru-ts-client-sdk/modules/__tests__/helpers.test.ts +0 -288
- package/thru-ts-client-sdk/modules/__tests__/keys.test.ts +0 -55
- package/thru-ts-client-sdk/modules/__tests__/proofs.test.ts +0 -119
- package/thru-ts-client-sdk/modules/__tests__/streaming.test.ts +0 -152
- package/thru-ts-client-sdk/modules/__tests__/transactions.test.ts +0 -730
- package/thru-ts-client-sdk/modules/__tests__/version.test.ts +0 -40
- package/thru-ts-client-sdk/modules/accounts.ts +0 -141
- package/thru-ts-client-sdk/modules/blocks.ts +0 -75
- package/thru-ts-client-sdk/modules/events.ts +0 -20
- package/thru-ts-client-sdk/modules/height.ts +0 -9
- package/thru-ts-client-sdk/modules/helpers.ts +0 -131
- package/thru-ts-client-sdk/modules/keys.ts +0 -29
- package/thru-ts-client-sdk/modules/proofs.ts +0 -20
- package/thru-ts-client-sdk/modules/streaming.ts +0 -133
- package/thru-ts-client-sdk/modules/transactions.ts +0 -374
- package/thru-ts-client-sdk/modules/version.ts +0 -10
- package/thru-ts-client-sdk/proto/buf/validate/validate_pb.ts +0 -4761
- package/thru-ts-client-sdk/proto/google/api/annotations_pb.ts +0 -39
- package/thru-ts-client-sdk/proto/google/api/client_pb.ts +0 -953
- package/thru-ts-client-sdk/proto/google/api/field_behavior_pb.ts +0 -157
- package/thru-ts-client-sdk/proto/google/api/http_pb.ts +0 -474
- package/thru-ts-client-sdk/proto/google/api/launch_stage_pb.ts +0 -118
- package/thru-ts-client-sdk/proto/thru/common/v1/consensus_pb.ts +0 -162
- package/thru-ts-client-sdk/proto/thru/common/v1/errors_pb.ts +0 -129
- package/thru-ts-client-sdk/proto/thru/common/v1/filters_pb.ts +0 -129
- package/thru-ts-client-sdk/proto/thru/common/v1/pagination_pb.ts +0 -79
- package/thru-ts-client-sdk/proto/thru/core/v1/account_pb.ts +0 -359
- package/thru-ts-client-sdk/proto/thru/core/v1/block_pb.ts +0 -259
- package/thru-ts-client-sdk/proto/thru/core/v1/state_pb.ts +0 -103
- package/thru-ts-client-sdk/proto/thru/core/v1/transaction_pb.ts +0 -528
- package/thru-ts-client-sdk/proto/thru/core/v1/types_pb.ts +0 -100
- package/thru-ts-client-sdk/proto/thru/services/v1/command_service_pb.ts +0 -146
- package/thru-ts-client-sdk/proto/thru/services/v1/query_service_pb.ts +0 -819
- package/thru-ts-client-sdk/proto/thru/services/v1/streaming_service_pb.ts +0 -390
- package/thru-ts-client-sdk/sdk.ts +0 -42
- package/thru-ts-client-sdk/test-scripts/counter.ts +0 -469
- package/thru-ts-client-sdk/test-scripts/create-account.ts +0 -74
- package/thru-ts-client-sdk/test-scripts/get-height.ts +0 -52
- package/thru-ts-client-sdk/transactions/Transaction.ts +0 -240
- package/thru-ts-client-sdk/transactions/TransactionBuilder.ts +0 -53
- package/thru-ts-client-sdk/transactions/__tests__/TransactionBuilder.test.ts +0 -411
- package/thru-ts-client-sdk/transactions/__tests__/utils.test.ts +0 -214
- package/thru-ts-client-sdk/transactions/index.ts +0 -3
- package/thru-ts-client-sdk/transactions/types.ts +0 -74
- package/thru-ts-client-sdk/transactions/utils.ts +0 -132
- package/thru-ts-client-sdk/types/types.ts +0 -8
- package/thru-ts-client-sdk/utils/utils.ts +0 -27
- package/tsconfig.json +0 -9
- package/tsup.config.ts +0 -14
- package/vitest.config.ts +0 -31
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
import { create } from "@bufbuild/protobuf";
|
|
2
|
-
|
|
3
|
-
import type { ThruClientContext } from "../core/client";
|
|
4
|
-
import {
|
|
5
|
-
DEFAULT_COMPUTE_UNITS,
|
|
6
|
-
DEFAULT_EXPIRY_AFTER,
|
|
7
|
-
DEFAULT_FEE,
|
|
8
|
-
DEFAULT_MEMORY_UNITS,
|
|
9
|
-
DEFAULT_MIN_CONSENSUS,
|
|
10
|
-
DEFAULT_STATE_UNITS,
|
|
11
|
-
DEFAULT_TRANSACTION_VIEW,
|
|
12
|
-
DEFAULT_VERSION_CONTEXT,
|
|
13
|
-
} from "../defaults";
|
|
14
|
-
import type { ConsensusStatus, VersionContext } from "../proto/thru/common/v1/consensus_pb";
|
|
15
|
-
import type { Filter } from "../proto/thru/common/v1/filters_pb";
|
|
16
|
-
import type { PageRequest } from "../proto/thru/common/v1/pagination_pb";
|
|
17
|
-
import { AccountView } from "../proto/thru/core/v1/account_pb";
|
|
18
|
-
import { Transaction as CoreTransaction, RawTransaction, TransactionView } from "../proto/thru/core/v1/transaction_pb";
|
|
19
|
-
import {
|
|
20
|
-
BatchSendTransactionsRequestSchema,
|
|
21
|
-
type BatchSendTransactionsResponse,
|
|
22
|
-
SendTransactionRequestSchema,
|
|
23
|
-
} from "../proto/thru/services/v1/command_service_pb";
|
|
24
|
-
import {
|
|
25
|
-
GetRawTransactionRequestSchema,
|
|
26
|
-
GetTransactionRequestSchema,
|
|
27
|
-
GetTransactionStatusRequestSchema,
|
|
28
|
-
ListTransactionsForAccountRequestSchema,
|
|
29
|
-
type ListTransactionsForAccountResponse,
|
|
30
|
-
TransactionStatus,
|
|
31
|
-
} from "../proto/thru/services/v1/query_service_pb";
|
|
32
|
-
import {
|
|
33
|
-
type BuildTransactionParams,
|
|
34
|
-
Transaction as LocalTransaction,
|
|
35
|
-
type OptionalProofs,
|
|
36
|
-
type ProgramIdentifier,
|
|
37
|
-
type SignedTransactionResult,
|
|
38
|
-
type TransactionAccountsInput,
|
|
39
|
-
TransactionBuilder,
|
|
40
|
-
type TransactionBuilderContext,
|
|
41
|
-
type TransactionHeaderInput,
|
|
42
|
-
} from "../transactions";
|
|
43
|
-
import { parseAccountIdentifier, parseInstructionData, resolveProgramIdentifier } from "../transactions/utils";
|
|
44
|
-
import { toSignature } from "./helpers";
|
|
45
|
-
|
|
46
|
-
import { BytesLike, encodeSignature } from "@thru/helpers";
|
|
47
|
-
import { getAccount } from "./accounts";
|
|
48
|
-
import { getBlockHeight } from "./height";
|
|
49
|
-
import { toPubkey } from "./helpers";
|
|
50
|
-
|
|
51
|
-
export interface TransactionFeePayerConfig {
|
|
52
|
-
publicKey: BytesLike;
|
|
53
|
-
privateKey?: Uint8Array;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface TransactionAccountsConfig {
|
|
57
|
-
readWrite?: BytesLike[];
|
|
58
|
-
readOnly?: BytesLike[];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface TransactionHeaderConfig {
|
|
62
|
-
fee?: bigint;
|
|
63
|
-
nonce?: bigint;
|
|
64
|
-
startSlot?: bigint;
|
|
65
|
-
expiryAfter?: number;
|
|
66
|
-
computeUnits?: number;
|
|
67
|
-
stateUnits?: number;
|
|
68
|
-
memoryUnits?: number;
|
|
69
|
-
flags?: number;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Instruction data can be either:
|
|
73
|
-
* - A Uint8Array directly
|
|
74
|
-
* - A function that takes a TransactionBuilderContext and returns a Uint8Array
|
|
75
|
-
*/
|
|
76
|
-
export type InstructionData = Uint8Array | ((context: TransactionBuilderContext) => Uint8Array);
|
|
77
|
-
|
|
78
|
-
export interface BuildTransactionOptions {
|
|
79
|
-
feePayer: TransactionFeePayerConfig;
|
|
80
|
-
program: ProgramIdentifier;
|
|
81
|
-
header?: TransactionHeaderConfig;
|
|
82
|
-
accounts?: TransactionAccountsConfig;
|
|
83
|
-
instructionData?: InstructionData | BytesLike;
|
|
84
|
-
feePayerStateProof?: Uint8Array;
|
|
85
|
-
feePayerAccountMetaRaw?: Uint8Array;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export interface BuildAndSignTransactionOptions extends BuildTransactionOptions {
|
|
89
|
-
feePayer: TransactionFeePayerConfig & { privateKey: Uint8Array };
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export interface TransactionQueryOptions {
|
|
93
|
-
view?: TransactionView;
|
|
94
|
-
versionContext?: VersionContext;
|
|
95
|
-
minConsensus?: ConsensusStatus;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export interface RawTransactionQueryOptions {
|
|
99
|
-
versionContext?: VersionContext;
|
|
100
|
-
minConsensus?: ConsensusStatus;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export interface ListTransactionsForAccountOptions {
|
|
104
|
-
filter?: Filter;
|
|
105
|
-
page?: PageRequest;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export async function getTransaction(
|
|
109
|
-
ctx: ThruClientContext,
|
|
110
|
-
signature: BytesLike,
|
|
111
|
-
options: TransactionQueryOptions = {},
|
|
112
|
-
): Promise<CoreTransaction> {
|
|
113
|
-
const request = create(GetTransactionRequestSchema, {
|
|
114
|
-
signature: toSignature(signature),
|
|
115
|
-
view: options.view ?? DEFAULT_TRANSACTION_VIEW,
|
|
116
|
-
versionContext: options.versionContext ?? DEFAULT_VERSION_CONTEXT,
|
|
117
|
-
minConsensus: options.minConsensus ?? DEFAULT_MIN_CONSENSUS,
|
|
118
|
-
});
|
|
119
|
-
return ctx.query.getTransaction(request);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export async function getRawTransaction(
|
|
123
|
-
ctx: ThruClientContext,
|
|
124
|
-
signature: BytesLike,
|
|
125
|
-
options: RawTransactionQueryOptions = {},
|
|
126
|
-
): Promise<RawTransaction> {
|
|
127
|
-
const request = create(GetRawTransactionRequestSchema, {
|
|
128
|
-
signature: toSignature(signature),
|
|
129
|
-
versionContext: options.versionContext ?? DEFAULT_VERSION_CONTEXT,
|
|
130
|
-
minConsensus: options.minConsensus ?? DEFAULT_MIN_CONSENSUS,
|
|
131
|
-
});
|
|
132
|
-
return ctx.query.getRawTransaction(request);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export async function getTransactionStatus(ctx: ThruClientContext, signature: BytesLike): Promise<TransactionStatus> {
|
|
136
|
-
const request = create(GetTransactionStatusRequestSchema, {
|
|
137
|
-
signature: toSignature(signature),
|
|
138
|
-
});
|
|
139
|
-
return ctx.query.getTransactionStatus(request);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export async function listTransactionsForAccount(
|
|
143
|
-
ctx: ThruClientContext,
|
|
144
|
-
account: BytesLike,
|
|
145
|
-
options: ListTransactionsForAccountOptions = {},
|
|
146
|
-
): Promise<ListTransactionsForAccountResponse> {
|
|
147
|
-
const request = create(ListTransactionsForAccountRequestSchema, {
|
|
148
|
-
account: toPubkey(account, "account"),
|
|
149
|
-
filter: options.filter,
|
|
150
|
-
page: options.page,
|
|
151
|
-
});
|
|
152
|
-
return ctx.query.listTransactionsForAccount(request);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export async function buildTransaction(
|
|
156
|
-
ctx: ThruClientContext,
|
|
157
|
-
options: BuildTransactionOptions,
|
|
158
|
-
): Promise<LocalTransaction> {
|
|
159
|
-
const builder = createTransactionBuilder();
|
|
160
|
-
const params = await createBuildParams(ctx, options);
|
|
161
|
-
return builder.build(params);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export async function buildAndSignTransaction(
|
|
165
|
-
ctx: ThruClientContext,
|
|
166
|
-
options: BuildAndSignTransactionOptions,
|
|
167
|
-
): Promise<SignedTransactionResult> {
|
|
168
|
-
const builder = createTransactionBuilder();
|
|
169
|
-
const params = await createBuildParams(ctx, options);
|
|
170
|
-
if (!params.feePayer.privateKey) {
|
|
171
|
-
throw new Error("Fee payer private key is required to sign the transaction");
|
|
172
|
-
}
|
|
173
|
-
return builder.buildAndSign(params);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export async function sendTransaction(
|
|
177
|
-
ctx: ThruClientContext,
|
|
178
|
-
transaction: LocalTransaction | Uint8Array,
|
|
179
|
-
): Promise<string> {
|
|
180
|
-
const raw = transaction instanceof Uint8Array ? transaction : transaction.toWire();
|
|
181
|
-
return sendRawTransaction(ctx, raw);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export interface BatchSendTransactionsOptions {
|
|
185
|
-
numRetries?: number;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export async function batchSendTransactions(
|
|
189
|
-
ctx: ThruClientContext,
|
|
190
|
-
transactions: (LocalTransaction | Uint8Array)[],
|
|
191
|
-
options: BatchSendTransactionsOptions = {},
|
|
192
|
-
): Promise<BatchSendTransactionsResponse> {
|
|
193
|
-
const rawTransactions = transactions.map((tx) =>
|
|
194
|
-
tx instanceof Uint8Array ? tx : tx.toWire(),
|
|
195
|
-
);
|
|
196
|
-
const request = create(BatchSendTransactionsRequestSchema, {
|
|
197
|
-
rawTransactions,
|
|
198
|
-
numRetries: options.numRetries ?? 0,
|
|
199
|
-
});
|
|
200
|
-
return ctx.command.batchSendTransactions(request);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
async function sendRawTransaction(ctx: ThruClientContext, rawTransaction: Uint8Array): Promise<string> {
|
|
204
|
-
const request = create(SendTransactionRequestSchema, { rawTransaction });
|
|
205
|
-
const response = await ctx.command.sendTransaction(request);
|
|
206
|
-
if (!response.signature?.value) {
|
|
207
|
-
throw new Error("No signature returned from sendTransaction");
|
|
208
|
-
}
|
|
209
|
-
return encodeSignature(response.signature.value);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function createTransactionBuilder(): TransactionBuilder {
|
|
213
|
-
return new TransactionBuilder();
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
async function createBuildParams(
|
|
217
|
-
ctx: ThruClientContext,
|
|
218
|
-
options: BuildTransactionOptions,
|
|
219
|
-
): Promise<BuildTransactionParams> {
|
|
220
|
-
const feePayerPublicKey = parseAccountIdentifier(options.feePayer.publicKey, "feePayer.publicKey");
|
|
221
|
-
const program = resolveProgramIdentifier(options.program);
|
|
222
|
-
const header = await createTransactionHeader(ctx, options.header ?? {}, feePayerPublicKey);
|
|
223
|
-
const accounts = parseAccounts(options.accounts);
|
|
224
|
-
|
|
225
|
-
// Create context for function resolution
|
|
226
|
-
const context = createBuilderContext(feePayerPublicKey, program, accounts);
|
|
227
|
-
|
|
228
|
-
// Resolve instruction data (functions get resolved here)
|
|
229
|
-
const instructionData = resolveInstructionData(options.instructionData, context);
|
|
230
|
-
const proofs = createProofs(options);
|
|
231
|
-
|
|
232
|
-
return {
|
|
233
|
-
feePayer: {
|
|
234
|
-
publicKey: feePayerPublicKey,
|
|
235
|
-
privateKey: options.feePayer.privateKey,
|
|
236
|
-
},
|
|
237
|
-
program: options.program,
|
|
238
|
-
header,
|
|
239
|
-
accounts,
|
|
240
|
-
instructionData,
|
|
241
|
-
proofs,
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
async function createTransactionHeader(
|
|
246
|
-
ctx: ThruClientContext,
|
|
247
|
-
header: TransactionHeaderConfig,
|
|
248
|
-
feePayerPublicKey: Uint8Array,
|
|
249
|
-
): Promise<TransactionHeaderInput> {
|
|
250
|
-
const nonce = header.nonce ?? (await fetchFeePayerNonce(ctx, feePayerPublicKey));
|
|
251
|
-
const startSlot = header.startSlot ?? (await fetchFinalizedSlot(ctx));
|
|
252
|
-
return {
|
|
253
|
-
fee: header.fee ?? DEFAULT_FEE,
|
|
254
|
-
nonce,
|
|
255
|
-
startSlot,
|
|
256
|
-
expiryAfter: header.expiryAfter ?? DEFAULT_EXPIRY_AFTER,
|
|
257
|
-
computeUnits: header.computeUnits ?? DEFAULT_COMPUTE_UNITS,
|
|
258
|
-
stateUnits: header.stateUnits ?? DEFAULT_STATE_UNITS,
|
|
259
|
-
memoryUnits: header.memoryUnits ?? DEFAULT_MEMORY_UNITS,
|
|
260
|
-
flags: header.flags,
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function parseAccounts(accounts?: TransactionAccountsConfig): TransactionAccountsInput | undefined {
|
|
265
|
-
if (!accounts) {
|
|
266
|
-
return undefined;
|
|
267
|
-
}
|
|
268
|
-
const readWrite = accounts.readWrite?.map((value, index) =>
|
|
269
|
-
parseAccountIdentifier(value, `accounts.readWrite[${index}]`),
|
|
270
|
-
);
|
|
271
|
-
const readOnly = accounts.readOnly?.map((value, index) =>
|
|
272
|
-
parseAccountIdentifier(value, `accounts.readOnly[${index}]`),
|
|
273
|
-
);
|
|
274
|
-
|
|
275
|
-
const result: TransactionAccountsInput = {};
|
|
276
|
-
if (readWrite && readWrite.length > 0) {
|
|
277
|
-
result.readWriteAccounts = readWrite;
|
|
278
|
-
}
|
|
279
|
-
if (readOnly && readOnly.length > 0) {
|
|
280
|
-
result.readOnlyAccounts = readOnly;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
if (!result.readWriteAccounts && !result.readOnlyAccounts) {
|
|
284
|
-
return undefined;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return result;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
function createBuilderContext(
|
|
291
|
-
feePayer: Uint8Array,
|
|
292
|
-
program: Uint8Array,
|
|
293
|
-
accounts?: TransactionAccountsInput,
|
|
294
|
-
): TransactionBuilderContext {
|
|
295
|
-
// Build accounts array in transaction order: [feePayer, program, ...readWrite, ...readOnly]
|
|
296
|
-
const allAccounts: Uint8Array[] = [
|
|
297
|
-
feePayer,
|
|
298
|
-
program,
|
|
299
|
-
...(accounts?.readWriteAccounts ?? []),
|
|
300
|
-
...(accounts?.readOnlyAccounts ?? []),
|
|
301
|
-
];
|
|
302
|
-
|
|
303
|
-
// Helper to compare two account addresses
|
|
304
|
-
const accountsEqual = (a: Uint8Array, b: Uint8Array): boolean => {
|
|
305
|
-
if (a.length !== 32 || b.length !== 32) {
|
|
306
|
-
return false;
|
|
307
|
-
}
|
|
308
|
-
for (let i = 0; i < 32; i++) {
|
|
309
|
-
if (a[i] !== b[i]) {
|
|
310
|
-
return false;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
return true;
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
const getAccountIndex = (pubkey: Uint8Array): number => {
|
|
317
|
-
for (let i = 0; i < allAccounts.length; i++) {
|
|
318
|
-
if (accountsEqual(allAccounts[i], pubkey)) {
|
|
319
|
-
return i;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
throw new Error("Account not found in transaction accounts");
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
return { accounts: allAccounts, getAccountIndex };
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
function resolveInstructionData(
|
|
329
|
-
value: InstructionData | BytesLike | undefined,
|
|
330
|
-
context: TransactionBuilderContext,
|
|
331
|
-
): BytesLike | undefined {
|
|
332
|
-
if (value === undefined) {
|
|
333
|
-
return undefined;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
// If it's a function, resolve it with the context
|
|
337
|
-
if (typeof value === "function") {
|
|
338
|
-
return value(context);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
// If it's already a Uint8Array, pass it through
|
|
342
|
-
if (value instanceof Uint8Array) {
|
|
343
|
-
return value;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
// Otherwise, parse BytesLike (string) to Uint8Array
|
|
347
|
-
return parseInstructionData(value);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
function createProofs(options: BuildTransactionOptions): OptionalProofs | undefined {
|
|
351
|
-
const proofs: OptionalProofs = {};
|
|
352
|
-
if (options.feePayerStateProof) {
|
|
353
|
-
proofs.feePayerStateProof = options.feePayerStateProof;
|
|
354
|
-
}
|
|
355
|
-
if (options.feePayerAccountMetaRaw) {
|
|
356
|
-
proofs.feePayerAccountMetaRaw = options.feePayerAccountMetaRaw;
|
|
357
|
-
}
|
|
358
|
-
const hasProofs = Boolean(proofs.feePayerStateProof || proofs.feePayerAccountMetaRaw);
|
|
359
|
-
return hasProofs ? proofs : undefined;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
async function fetchFeePayerNonce(ctx: ThruClientContext, feePayer: Uint8Array): Promise<bigint> {
|
|
363
|
-
const account = await getAccount(ctx, feePayer, { view: AccountView.FULL });
|
|
364
|
-
const nonce = account.meta?.nonce;
|
|
365
|
-
if (nonce === undefined) {
|
|
366
|
-
throw new Error("Fee payer account nonce is unavailable");
|
|
367
|
-
}
|
|
368
|
-
return nonce;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
async function fetchFinalizedSlot(ctx: ThruClientContext): Promise<bigint> {
|
|
372
|
-
const height = await getBlockHeight(ctx);
|
|
373
|
-
return height.finalized;
|
|
374
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { create } from "@bufbuild/protobuf";
|
|
2
|
-
|
|
3
|
-
import type { ThruClientContext } from "../core/client";
|
|
4
|
-
import { GetVersionRequestSchema, type GetVersionResponse } from "../proto/thru/services/v1/query_service_pb";
|
|
5
|
-
|
|
6
|
-
export function getVersion(ctx: ThruClientContext): Promise<GetVersionResponse> {
|
|
7
|
-
const request = create(GetVersionRequestSchema, {});
|
|
8
|
-
return ctx.query.getVersion(request);
|
|
9
|
-
}
|
|
10
|
-
|