@aptos-labs/ts-sdk 7.3.0 → 7.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 +43 -43
- package/README.md +19 -20
- package/dist/api/account/abstraction.d.ts +10 -0
- package/dist/api/account/abstraction.d.ts.map +1 -1
- package/dist/api/account/abstraction.js +19 -6
- package/dist/api/account/abstraction.js.map +1 -1
- package/dist/api/ans.d.ts +9 -0
- package/dist/api/ans.d.ts.map +1 -1
- package/dist/api/ans.js +5 -0
- package/dist/api/ans.js.map +1 -1
- package/dist/api/coin.d.ts +2 -0
- package/dist/api/coin.d.ts.map +1 -1
- package/dist/api/coin.js +1 -0
- package/dist/api/coin.js.map +1 -1
- package/dist/api/digitalAsset.d.ts +30 -0
- package/dist/api/digitalAsset.d.ts.map +1 -1
- package/dist/api/digitalAsset.js +15 -0
- package/dist/api/digitalAsset.js.map +1 -1
- package/dist/api/fungibleAsset.d.ts +4 -0
- package/dist/api/fungibleAsset.d.ts.map +1 -1
- package/dist/api/fungibleAsset.js +2 -0
- package/dist/api/fungibleAsset.js.map +1 -1
- package/dist/api/keyless.d.ts +38 -1
- package/dist/api/keyless.d.ts.map +1 -1
- package/dist/api/keyless.js +29 -1
- package/dist/api/keyless.js.map +1 -1
- package/dist/api/transaction.d.ts +41 -1
- package/dist/api/transaction.d.ts.map +1 -1
- package/dist/api/transaction.js +42 -2
- package/dist/api/transaction.js.map +1 -1
- package/dist/api/transactionSubmission/build.d.ts +7 -5
- package/dist/api/transactionSubmission/build.d.ts.map +1 -1
- package/dist/api/transactionSubmission/build.js +13 -5
- package/dist/api/transactionSubmission/build.js.map +1 -1
- package/dist/api/transactionSubmission/simulate.d.ts +7 -3
- package/dist/api/transactionSubmission/simulate.d.ts.map +1 -1
- package/dist/api/transactionSubmission/simulate.js +7 -3
- package/dist/api/transactionSubmission/simulate.js.map +1 -1
- package/dist/bcs/serializable/moveStructs.d.ts +72 -28
- package/dist/bcs/serializable/moveStructs.d.ts.map +1 -1
- package/dist/bcs/serializable/moveStructs.js +76 -28
- package/dist/bcs/serializable/moveStructs.js.map +1 -1
- package/dist/functions/keyless.d.ts +1 -1
- package/dist/functions/keyless.d.ts.map +1 -1
- package/dist/functions/keyless.js +1 -1
- package/dist/functions/keyless.js.map +1 -1
- package/dist/functions/transaction.d.ts +1 -1
- package/dist/functions/transaction.d.ts.map +1 -1
- package/dist/functions/transaction.js +1 -1
- package/dist/functions/transaction.js.map +1 -1
- package/dist/internal/abstraction.d.ts +35 -0
- package/dist/internal/abstraction.d.ts.map +1 -1
- package/dist/internal/abstraction.js +38 -3
- package/dist/internal/abstraction.js.map +1 -1
- package/dist/internal/account.d.ts +6 -0
- package/dist/internal/account.d.ts.map +1 -1
- package/dist/internal/account.js +55 -37
- package/dist/internal/account.js.map +1 -1
- package/dist/internal/ans.d.ts +11 -0
- package/dist/internal/ans.d.ts.map +1 -1
- package/dist/internal/ans.js +18 -6
- package/dist/internal/ans.js.map +1 -1
- package/dist/internal/coin.d.ts +2 -0
- package/dist/internal/coin.d.ts.map +1 -1
- package/dist/internal/coin.js +3 -1
- package/dist/internal/coin.js.map +1 -1
- package/dist/internal/digitalAsset.d.ts +30 -0
- package/dist/internal/digitalAsset.d.ts.map +1 -1
- package/dist/internal/digitalAsset.js +45 -15
- package/dist/internal/digitalAsset.js.map +1 -1
- package/dist/internal/fungibleAsset.d.ts +4 -0
- package/dist/internal/fungibleAsset.d.ts.map +1 -1
- package/dist/internal/fungibleAsset.js +6 -2
- package/dist/internal/fungibleAsset.js.map +1 -1
- package/dist/internal/keyless.d.ts +39 -1
- package/dist/internal/keyless.d.ts.map +1 -1
- package/dist/internal/keyless.js +71 -13
- package/dist/internal/keyless.js.map +1 -1
- package/dist/internal/transaction.d.ts +24 -1
- package/dist/internal/transaction.d.ts.map +1 -1
- package/dist/internal/transaction.js +125 -4
- package/dist/internal/transaction.js.map +1 -1
- package/dist/internal/transactionSubmission.d.ts +2 -0
- package/dist/internal/transactionSubmission.d.ts.map +1 -1
- package/dist/internal/transactionSubmission.js +3 -1
- package/dist/internal/transactionSubmission.js.map +1 -1
- package/dist/transactions/management/transactionWorker.d.ts +10 -6
- package/dist/transactions/management/transactionWorker.d.ts.map +1 -1
- package/dist/transactions/management/transactionWorker.js +28 -24
- package/dist/transactions/management/transactionWorker.js.map +1 -1
- package/dist/transactions/transactionBuilder/index.d.ts +1 -0
- package/dist/transactions/transactionBuilder/index.d.ts.map +1 -1
- package/dist/transactions/transactionBuilder/index.js +1 -0
- package/dist/transactions/transactionBuilder/index.js.map +1 -1
- package/dist/transactions/transactionBuilder/scriptAbi.d.ts +10 -0
- package/dist/transactions/transactionBuilder/scriptAbi.d.ts.map +1 -0
- package/dist/transactions/transactionBuilder/scriptAbi.js +863 -0
- package/dist/transactions/transactionBuilder/scriptAbi.js.map +1 -0
- package/dist/transactions/transactionBuilder/transactionBuilder.d.ts.map +1 -1
- package/dist/transactions/transactionBuilder/transactionBuilder.js +65 -1
- package/dist/transactions/transactionBuilder/transactionBuilder.js.map +1 -1
- package/dist/transactions/types.d.ts +9 -4
- package/dist/transactions/types.d.ts.map +1 -1
- package/dist/types/keyless.d.ts +2 -2
- package/dist/types/keyless.d.ts.map +1 -1
- package/dist/types/types.d.ts +2 -2
- package/dist/types/types.d.ts.map +1 -1
- package/dist/utils/const.d.ts +11 -0
- package/dist/utils/const.d.ts.map +1 -1
- package/dist/utils/const.js +11 -0
- package/dist/utils/const.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +26 -25
- package/src/api/account/abstraction.ts +23 -6
- package/src/api/ans.ts +9 -0
- package/src/api/coin.ts +2 -0
- package/src/api/digitalAsset.ts +30 -0
- package/src/api/fungibleAsset.ts +4 -0
- package/src/api/keyless.ts +39 -1
- package/src/api/transaction.ts +48 -1
- package/src/api/transactionSubmission/build.ts +16 -6
- package/src/api/transactionSubmission/simulate.ts +7 -3
- package/src/bcs/serializable/moveStructs.ts +80 -28
- package/src/functions/keyless.ts +1 -0
- package/src/functions/transaction.ts +1 -0
- package/src/internal/abstraction.ts +41 -3
- package/src/internal/account.ts +60 -38
- package/src/internal/ans.ts +24 -6
- package/src/internal/coin.ts +4 -1
- package/src/internal/digitalAsset.ts +60 -9
- package/src/internal/fungibleAsset.ts +8 -2
- package/src/internal/keyless.ts +91 -14
- package/src/internal/transaction.ts +154 -4
- package/src/internal/transactionSubmission.ts +4 -1
- package/src/transactions/management/transactionWorker.ts +35 -23
- package/src/transactions/transactionBuilder/index.ts +1 -0
- package/src/transactions/transactionBuilder/scriptAbi.ts +1145 -0
- package/src/transactions/transactionBuilder/transactionBuilder.ts +91 -6
- package/src/transactions/types.ts +10 -4
- package/src/types/keyless.ts +2 -2
- package/src/types/types.ts +2 -2
- package/src/utils/const.ts +12 -0
- package/src/version.ts +1 -1
|
@@ -19,14 +19,18 @@ import {
|
|
|
19
19
|
type HexInput,
|
|
20
20
|
type PaginationArgs,
|
|
21
21
|
type TransactionResponse,
|
|
22
|
+
type WriteSetChange,
|
|
23
|
+
type WriteSetChangeDeleteTableItem,
|
|
24
|
+
type WriteSetChangeWriteTableItem,
|
|
22
25
|
WaitForTransactionOptions,
|
|
23
26
|
CommittedTransactionResponse,
|
|
24
27
|
Block,
|
|
25
28
|
} from "../types/index.js";
|
|
26
|
-
import { DEFAULT_TXN_TIMEOUT_SEC, ProcessorType } from "../utils/const.js";
|
|
29
|
+
import { DEFAULT_INDEXER_SYNC_TIMEOUT_SEC, DEFAULT_TXN_TIMEOUT_SEC, ProcessorType } from "../utils/const.js";
|
|
27
30
|
import { sleep } from "../utils/helpers.js";
|
|
28
31
|
import { memoizeAsync } from "../utils/memoize.js";
|
|
29
32
|
import { getIndexerLastSuccessVersion, getProcessorStatus } from "./general.js";
|
|
33
|
+
import { getTableItemsData, getTableItemsMetadata } from "./table.js";
|
|
30
34
|
|
|
31
35
|
/**
|
|
32
36
|
* Retrieve a list of transactions based on the specified options.
|
|
@@ -313,29 +317,34 @@ export async function waitForTransaction(args: {
|
|
|
313
317
|
}
|
|
314
318
|
|
|
315
319
|
/**
|
|
316
|
-
* Waits for the indexer to sync up to the specified ledger version.
|
|
320
|
+
* Waits for the indexer to sync up to the specified ledger version.
|
|
317
321
|
*
|
|
318
322
|
* @param args - The arguments for the function.
|
|
319
323
|
* @param args.aptosConfig - The configuration object for Aptos.
|
|
320
324
|
* @param args.minimumLedgerVersion - The minimum ledger version that the indexer should sync to.
|
|
321
325
|
* @param args.processorType - (Optional) The type of processor to check the last success version from.
|
|
326
|
+
* @param args.timeoutMilliseconds - (Optional) How long to wait before throwing. Defaults to 10 seconds.
|
|
322
327
|
* @group Implementation
|
|
323
328
|
*/
|
|
324
329
|
export async function waitForIndexer(args: {
|
|
325
330
|
aptosConfig: AptosConfig;
|
|
326
331
|
minimumLedgerVersion: AnyNumber;
|
|
327
332
|
processorType?: ProcessorType;
|
|
333
|
+
timeoutMilliseconds?: number;
|
|
328
334
|
}): Promise<void> {
|
|
329
335
|
const { aptosConfig, processorType } = args;
|
|
330
336
|
const minimumLedgerVersion = BigInt(args.minimumLedgerVersion);
|
|
331
|
-
const timeoutMilliseconds =
|
|
337
|
+
const timeoutMilliseconds = args.timeoutMilliseconds ?? DEFAULT_INDEXER_SYNC_TIMEOUT_SEC * 1000;
|
|
332
338
|
const startTime = Date.now();
|
|
333
339
|
let indexerVersion = BigInt(-1);
|
|
334
340
|
|
|
335
341
|
while (indexerVersion < minimumLedgerVersion) {
|
|
336
342
|
// check for timeout
|
|
337
343
|
if (Date.now() - startTime > timeoutMilliseconds) {
|
|
338
|
-
throw new Error(
|
|
344
|
+
throw new Error(
|
|
345
|
+
`waitForLastSuccessIndexerVersionSync timeout after ${timeoutMilliseconds}ms: indexer at version ${indexerVersion}, needed ${minimumLedgerVersion}. ` +
|
|
346
|
+
`If this is a faucet/fundAccount call, you can skip the wait with { waitForIndexer: false }.`,
|
|
347
|
+
);
|
|
339
348
|
}
|
|
340
349
|
|
|
341
350
|
if (processorType === undefined) {
|
|
@@ -400,6 +409,147 @@ export class FailedTransactionError extends Error {
|
|
|
400
409
|
}
|
|
401
410
|
}
|
|
402
411
|
|
|
412
|
+
function isWriteTableItemChange(change: WriteSetChange): change is WriteSetChangeWriteTableItem {
|
|
413
|
+
return change.type === "write_table_item";
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function isDeleteTableItemChange(change: WriteSetChange): change is WriteSetChangeDeleteTableItem {
|
|
417
|
+
return change.type === "delete_table_item";
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function isTableItemChange(
|
|
421
|
+
change: WriteSetChange,
|
|
422
|
+
): change is WriteSetChangeWriteTableItem | WriteSetChangeDeleteTableItem {
|
|
423
|
+
return isWriteTableItemChange(change) || isDeleteTableItemChange(change);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const INDEXER_PAGE_SIZE = 100;
|
|
427
|
+
|
|
428
|
+
async function getTransactionTableItems(args: { aptosConfig: AptosConfig; transactionVersion: string }) {
|
|
429
|
+
const { aptosConfig, transactionVersion } = args;
|
|
430
|
+
const tableItems = [];
|
|
431
|
+
|
|
432
|
+
for (let offset = 0; ; offset += INDEXER_PAGE_SIZE) {
|
|
433
|
+
const page = await getTableItemsData({
|
|
434
|
+
aptosConfig,
|
|
435
|
+
options: {
|
|
436
|
+
where: {
|
|
437
|
+
transaction_version: { _eq: transactionVersion },
|
|
438
|
+
},
|
|
439
|
+
orderBy: [{ write_set_change_index: "asc" }],
|
|
440
|
+
offset,
|
|
441
|
+
limit: INDEXER_PAGE_SIZE,
|
|
442
|
+
},
|
|
443
|
+
});
|
|
444
|
+
tableItems.push(...page);
|
|
445
|
+
|
|
446
|
+
if (page.length < INDEXER_PAGE_SIZE) {
|
|
447
|
+
return tableItems;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
async function getTableMetadataForHandles(args: { aptosConfig: AptosConfig; handles: string[] }) {
|
|
453
|
+
const { aptosConfig, handles } = args;
|
|
454
|
+
const tableMetadata = [];
|
|
455
|
+
|
|
456
|
+
for (let offset = 0; offset < handles.length; offset += INDEXER_PAGE_SIZE) {
|
|
457
|
+
const pageHandles = handles.slice(offset, offset + INDEXER_PAGE_SIZE);
|
|
458
|
+
const page = await getTableItemsMetadata({
|
|
459
|
+
aptosConfig,
|
|
460
|
+
options: {
|
|
461
|
+
where: {
|
|
462
|
+
handle: { _in: pageHandles },
|
|
463
|
+
},
|
|
464
|
+
limit: INDEXER_PAGE_SIZE,
|
|
465
|
+
},
|
|
466
|
+
});
|
|
467
|
+
tableMetadata.push(...page);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
return tableMetadata;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Populates missing decoded data on a committed transaction's table item changes.
|
|
475
|
+
*
|
|
476
|
+
* Fullnodes generally return `null` for table item `data` because decoding requires
|
|
477
|
+
* table metadata. This function retrieves the decoded rows and metadata from the
|
|
478
|
+
* indexer, matches them by write-set change index, and mutates the supplied
|
|
479
|
+
* transaction with the available decoded data.
|
|
480
|
+
*
|
|
481
|
+
* Already-decoded changes are preserved. If the indexer has no matching row or
|
|
482
|
+
* metadata for a change, that change is left unchanged.
|
|
483
|
+
*
|
|
484
|
+
* @param args - The arguments for enriching the transaction.
|
|
485
|
+
* @param args.aptosConfig - The configuration for the Aptos indexer.
|
|
486
|
+
* @param args.transaction - The committed transaction to enrich.
|
|
487
|
+
* @returns The supplied transaction with available table item data populated.
|
|
488
|
+
* @group Implementation
|
|
489
|
+
*/
|
|
490
|
+
export async function enrichTransactionWithTableItemData<T extends CommittedTransactionResponse>(args: {
|
|
491
|
+
aptosConfig: AptosConfig;
|
|
492
|
+
transaction: T;
|
|
493
|
+
}): Promise<T> {
|
|
494
|
+
const { aptosConfig, transaction } = args;
|
|
495
|
+
const missingTableItemChanges = transaction.changes
|
|
496
|
+
.filter(isTableItemChange)
|
|
497
|
+
.filter((change) => change.data === null || change.data === undefined);
|
|
498
|
+
|
|
499
|
+
if (missingTableItemChanges.length === 0) {
|
|
500
|
+
return transaction;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
const handles = [...new Set(missingTableItemChanges.map((change) => change.handle))];
|
|
504
|
+
await waitForIndexer({
|
|
505
|
+
aptosConfig,
|
|
506
|
+
minimumLedgerVersion: BigInt(transaction.version),
|
|
507
|
+
processorType: ProcessorType.DEFAULT,
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
const [tableItems, tableMetadata] = await Promise.all([
|
|
511
|
+
getTransactionTableItems({
|
|
512
|
+
aptosConfig,
|
|
513
|
+
transactionVersion: transaction.version,
|
|
514
|
+
}),
|
|
515
|
+
getTableMetadataForHandles({
|
|
516
|
+
aptosConfig,
|
|
517
|
+
handles,
|
|
518
|
+
}),
|
|
519
|
+
]);
|
|
520
|
+
|
|
521
|
+
const itemsByChangeIndex = new Map(tableItems.map((item) => [Number(item.write_set_change_index), item] as const));
|
|
522
|
+
const metadataByHandle = new Map(tableMetadata.map((metadata) => [metadata.handle, metadata] as const));
|
|
523
|
+
|
|
524
|
+
transaction.changes.forEach((change, changeIndex) => {
|
|
525
|
+
if (!isTableItemChange(change) || (change.data !== null && change.data !== undefined)) {
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const item = itemsByChangeIndex.get(changeIndex);
|
|
530
|
+
const metadata = metadataByHandle.get(change.handle);
|
|
531
|
+
if (item === undefined || metadata === undefined) {
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
if (isWriteTableItemChange(change)) {
|
|
536
|
+
change.data = {
|
|
537
|
+
key: item.decoded_key,
|
|
538
|
+
key_type: metadata.key_type,
|
|
539
|
+
value: item.decoded_value,
|
|
540
|
+
value_type: metadata.value_type,
|
|
541
|
+
};
|
|
542
|
+
} else {
|
|
543
|
+
change.data = {
|
|
544
|
+
key: item.decoded_key,
|
|
545
|
+
key_type: metadata.key_type,
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
return transaction;
|
|
551
|
+
}
|
|
552
|
+
|
|
403
553
|
/**
|
|
404
554
|
* Retrieves a block from the Aptos blockchain by its ledger version.
|
|
405
555
|
* This function allows you to obtain detailed information about a specific block, including its transactions if requested.
|
|
@@ -510,6 +510,7 @@ function getPackagePublishAbi(): EntryFunctionABI {
|
|
|
510
510
|
* @param args.account - The address of the account sending the transaction.
|
|
511
511
|
* @param args.metadataBytes - The metadata associated with the package, represented as hexadecimal input.
|
|
512
512
|
* @param args.moduleBytecode - An array of module bytecode, each represented as hexadecimal input.
|
|
513
|
+
* @param args.withFeePayer - Whether to build a sponsored transaction.
|
|
513
514
|
* @param args.options - Optional parameters for generating the transaction.
|
|
514
515
|
* @group Implementation
|
|
515
516
|
*/
|
|
@@ -518,15 +519,17 @@ export async function publicPackageTransaction(args: {
|
|
|
518
519
|
account: AccountAddressInput;
|
|
519
520
|
metadataBytes: HexInput;
|
|
520
521
|
moduleBytecode: Array<HexInput>;
|
|
522
|
+
withFeePayer?: boolean;
|
|
521
523
|
options?: InputGenerateTransactionOptions;
|
|
522
524
|
}): Promise<SimpleTransaction> {
|
|
523
|
-
const { aptosConfig, account, metadataBytes, moduleBytecode, options } = args;
|
|
525
|
+
const { aptosConfig, account, metadataBytes, moduleBytecode, withFeePayer, options } = args;
|
|
524
526
|
|
|
525
527
|
const totalByteCode = moduleBytecode.map((bytecode) => MoveVector.U8(bytecode));
|
|
526
528
|
|
|
527
529
|
return generateTransaction({
|
|
528
530
|
aptosConfig,
|
|
529
531
|
sender: AccountAddress.from(account),
|
|
532
|
+
withFeePayer,
|
|
530
533
|
data: {
|
|
531
534
|
function: "0x1::code::publish_package_txn",
|
|
532
535
|
functionArguments: [MoveVector.U8(metadataBytes), new MoveVector(totalByteCode)],
|
|
@@ -157,6 +157,35 @@ export class TransactionWorker extends EventEmitter<TransactionWorkerEvents> {
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Emits the submission result as soon as the pending transaction settles.
|
|
162
|
+
* @private
|
|
163
|
+
*/
|
|
164
|
+
private trackTransactionSubmission(
|
|
165
|
+
pendingTransaction: Promise<PendingTransactionResponse>,
|
|
166
|
+
sequenceNumber: bigint,
|
|
167
|
+
): void {
|
|
168
|
+
const notification = pendingTransaction.then(
|
|
169
|
+
(transaction) => {
|
|
170
|
+
this.addToTransactionHistory(this.sentTransactions, [transaction.hash, sequenceNumber, null]);
|
|
171
|
+
this.emit(TransactionWorkerEventsEnum.TransactionSent, {
|
|
172
|
+
message: `transaction hash ${transaction.hash} has been committed to chain`,
|
|
173
|
+
transactionHash: transaction.hash,
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
(error) => {
|
|
177
|
+
this.addToTransactionHistory(this.sentTransactions, ["rejected", sequenceNumber, error]);
|
|
178
|
+
this.emit(TransactionWorkerEventsEnum.TransactionSendFailed, {
|
|
179
|
+
message: `failed to commit transaction ${this.sentTransactions.length} with error ${error}`,
|
|
180
|
+
error,
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
);
|
|
184
|
+
// Event listeners are user-provided and must not create an unhandled rejection
|
|
185
|
+
// in this detached notification chain.
|
|
186
|
+
notification.catch(() => {});
|
|
187
|
+
}
|
|
188
|
+
|
|
160
189
|
/**
|
|
161
190
|
* Initializes a new instance of the class, providing a framework for receiving payloads to be processed.
|
|
162
191
|
*
|
|
@@ -196,6 +225,8 @@ export class TransactionWorker extends EventEmitter<TransactionWorkerEvents> {
|
|
|
196
225
|
* This function continues to submit transactions until there are no more to process.
|
|
197
226
|
*
|
|
198
227
|
* @throws {Error} Throws an error if the transaction submission fails.
|
|
228
|
+
* @event TransactionWorkerEventsEnum.TransactionSent - Emitted when a transaction is sent to the chain.
|
|
229
|
+
* @event TransactionWorkerEventsEnum.TransactionSendFailed - Emitted when a transaction fails to send.
|
|
199
230
|
* @group Implementation
|
|
200
231
|
* @category Transactions
|
|
201
232
|
*/
|
|
@@ -211,6 +242,7 @@ export class TransactionWorker extends EventEmitter<TransactionWorkerEvents> {
|
|
|
211
242
|
transaction,
|
|
212
243
|
signer: this.account,
|
|
213
244
|
});
|
|
245
|
+
this.trackTransactionSubmission(pendingTransaction, sequenceNumber);
|
|
214
246
|
await this.outstandingTransactions.enqueue([pendingTransaction, sequenceNumber]);
|
|
215
247
|
}
|
|
216
248
|
} catch (error: any) {
|
|
@@ -222,14 +254,11 @@ export class TransactionWorker extends EventEmitter<TransactionWorkerEvents> {
|
|
|
222
254
|
}
|
|
223
255
|
|
|
224
256
|
/**
|
|
225
|
-
* Reads the outstanding transaction queue and
|
|
226
|
-
* This function processes each transaction, checking their status and emitting events based on whether they were successfully
|
|
227
|
-
* sent or failed.
|
|
257
|
+
* Reads the outstanding transaction queue and checks each successfully submitted transaction's execution status.
|
|
228
258
|
*
|
|
229
259
|
* @throws {Error} Throws an error if the process execution fails.
|
|
230
|
-
* @event TransactionWorkerEventsEnum.
|
|
231
|
-
* @event TransactionWorkerEventsEnum.
|
|
232
|
-
* reason.
|
|
260
|
+
* @event TransactionWorkerEventsEnum.TransactionExecuted - Emitted when a transaction executes successfully.
|
|
261
|
+
* @event TransactionWorkerEventsEnum.TransactionExecutionFailed - Emitted when a transaction fails during execution.
|
|
233
262
|
* @event TransactionWorkerEventsEnum.ExecutionFinish - Emitted when the execution of transactions is complete.
|
|
234
263
|
* @group Implementation
|
|
235
264
|
* @category Transactions
|
|
@@ -257,25 +286,8 @@ export class TransactionWorker extends EventEmitter<TransactionWorkerEvents> {
|
|
|
257
286
|
const sentTransaction = sentTransactions[i];
|
|
258
287
|
sequenceNumber = sequenceNumbers[i];
|
|
259
288
|
if (sentTransaction.status === promiseFulfilledStatus) {
|
|
260
|
-
// transaction sent to chain
|
|
261
|
-
this.addToTransactionHistory(this.sentTransactions, [sentTransaction.value.hash, sequenceNumber, null]);
|
|
262
289
|
// check sent transaction execution
|
|
263
|
-
this.emit(TransactionWorkerEventsEnum.TransactionSent, {
|
|
264
|
-
message: `transaction hash ${sentTransaction.value.hash} has been committed to chain`,
|
|
265
|
-
transactionHash: sentTransaction.value.hash,
|
|
266
|
-
});
|
|
267
290
|
await this.checkTransaction(sentTransaction, sequenceNumber);
|
|
268
|
-
} else {
|
|
269
|
-
// send transaction failed
|
|
270
|
-
this.addToTransactionHistory(this.sentTransactions, [
|
|
271
|
-
sentTransaction.status,
|
|
272
|
-
sequenceNumber,
|
|
273
|
-
sentTransaction.reason,
|
|
274
|
-
]);
|
|
275
|
-
this.emit(TransactionWorkerEventsEnum.TransactionSendFailed, {
|
|
276
|
-
message: `failed to commit transaction ${this.sentTransactions.length} with error ${sentTransaction.reason}`,
|
|
277
|
-
error: sentTransaction.reason,
|
|
278
|
-
});
|
|
279
291
|
}
|
|
280
292
|
}
|
|
281
293
|
this.emit(TransactionWorkerEventsEnum.ExecutionFinish, {
|