@metamask/transaction-controller 52.1.0 → 52.3.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/CHANGELOG.md +55 -4
- package/dist/TransactionController.cjs +111 -28
- package/dist/TransactionController.cjs.map +1 -1
- package/dist/TransactionController.d.cts +33 -5
- package/dist/TransactionController.d.cts.map +1 -1
- package/dist/TransactionController.d.mts +33 -5
- package/dist/TransactionController.d.mts.map +1 -1
- package/dist/TransactionController.mjs +114 -31
- package/dist/TransactionController.mjs.map +1 -1
- package/dist/constants.cjs +1 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +1 -0
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +1 -0
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +1 -0
- package/dist/constants.mjs.map +1 -1
- package/dist/gas-flows/DefaultGasFeeFlow.cjs +1 -3
- package/dist/gas-flows/DefaultGasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/DefaultGasFeeFlow.d.cts +2 -2
- package/dist/gas-flows/DefaultGasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/DefaultGasFeeFlow.d.mts +2 -2
- package/dist/gas-flows/DefaultGasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/DefaultGasFeeFlow.mjs +1 -3
- package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.cjs +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.d.cts +5 -1
- package/dist/gas-flows/LineaGasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.d.mts +5 -1
- package/dist/gas-flows/LineaGasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.mjs +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts +5 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts +5 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs +1 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/OracleLayer1GasFeeFlow.d.cts +5 -1
- package/dist/gas-flows/OracleLayer1GasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts +5 -1
- package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/OracleLayer1GasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.cjs +123 -0
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.cjs.map +1 -0
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.cts +28 -0
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.cts.map +1 -0
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.mts +28 -0
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.mts.map +1 -0
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.mjs +118 -0
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.mjs.map +1 -0
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs +1 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts +5 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts +5 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs +1 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/TestGasFeeFlow.cjs +1 -1
- package/dist/gas-flows/TestGasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/TestGasFeeFlow.d.cts +2 -2
- package/dist/gas-flows/TestGasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/TestGasFeeFlow.d.mts +2 -2
- package/dist/gas-flows/TestGasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/TestGasFeeFlow.mjs +1 -1
- package/dist/gas-flows/TestGasFeeFlow.mjs.map +1 -1
- package/dist/helpers/GasFeePoller.cjs +11 -8
- package/dist/helpers/GasFeePoller.cjs.map +1 -1
- package/dist/helpers/GasFeePoller.d.cts +6 -5
- package/dist/helpers/GasFeePoller.d.cts.map +1 -1
- package/dist/helpers/GasFeePoller.d.mts +6 -5
- package/dist/helpers/GasFeePoller.d.mts.map +1 -1
- package/dist/helpers/GasFeePoller.mjs +11 -8
- package/dist/helpers/GasFeePoller.mjs.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.cjs +2 -1
- package/dist/helpers/IncomingTransactionHelper.cjs.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.d.cts.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.d.mts.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.mjs +2 -1
- package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -1
- package/dist/helpers/PendingTransactionTracker.cjs +6 -2
- package/dist/helpers/PendingTransactionTracker.cjs.map +1 -1
- package/dist/helpers/PendingTransactionTracker.d.cts +5 -2
- package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -1
- package/dist/helpers/PendingTransactionTracker.d.mts +5 -2
- package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -1
- package/dist/helpers/PendingTransactionTracker.mjs +6 -2
- package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
- package/dist/helpers/TransactionPoller.cjs +12 -8
- package/dist/helpers/TransactionPoller.cjs.map +1 -1
- package/dist/helpers/TransactionPoller.d.cts +7 -3
- package/dist/helpers/TransactionPoller.d.cts.map +1 -1
- package/dist/helpers/TransactionPoller.d.mts +7 -3
- package/dist/helpers/TransactionPoller.d.mts.map +1 -1
- package/dist/helpers/TransactionPoller.mjs +11 -7
- package/dist/helpers/TransactionPoller.mjs.map +1 -1
- package/dist/hooks/CollectPublishHook.cjs +84 -0
- package/dist/hooks/CollectPublishHook.cjs.map +1 -0
- package/dist/hooks/CollectPublishHook.d.cts +29 -0
- package/dist/hooks/CollectPublishHook.d.cts.map +1 -0
- package/dist/hooks/CollectPublishHook.d.mts +29 -0
- package/dist/hooks/CollectPublishHook.d.mts.map +1 -0
- package/dist/hooks/CollectPublishHook.mjs +80 -0
- package/dist/hooks/CollectPublishHook.mjs.map +1 -0
- package/dist/hooks/ExtraTransactionsPublishHook.cjs +90 -0
- package/dist/hooks/ExtraTransactionsPublishHook.cjs.map +1 -0
- package/dist/hooks/ExtraTransactionsPublishHook.d.cts +18 -0
- package/dist/hooks/ExtraTransactionsPublishHook.d.cts.map +1 -0
- package/dist/hooks/ExtraTransactionsPublishHook.d.mts +18 -0
- package/dist/hooks/ExtraTransactionsPublishHook.d.mts.map +1 -0
- package/dist/hooks/ExtraTransactionsPublishHook.mjs +86 -0
- package/dist/hooks/ExtraTransactionsPublishHook.mjs.map +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +161 -7
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +161 -7
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/batch.cjs +142 -1
- package/dist/utils/batch.cjs.map +1 -1
- package/dist/utils/batch.d.cts +7 -1
- package/dist/utils/batch.d.cts.map +1 -1
- package/dist/utils/batch.d.mts +7 -1
- package/dist/utils/batch.d.mts.map +1 -1
- package/dist/utils/batch.mjs +142 -1
- package/dist/utils/batch.mjs.map +1 -1
- package/dist/utils/eip7702.cjs +12 -0
- package/dist/utils/eip7702.cjs.map +1 -1
- package/dist/utils/eip7702.d.cts.map +1 -1
- package/dist/utils/eip7702.d.mts.map +1 -1
- package/dist/utils/eip7702.mjs +12 -0
- package/dist/utils/eip7702.mjs.map +1 -1
- package/dist/utils/feature-flags.cjs +39 -2
- package/dist/utils/feature-flags.cjs.map +1 -1
- package/dist/utils/feature-flags.d.cts +49 -0
- package/dist/utils/feature-flags.d.cts.map +1 -1
- package/dist/utils/feature-flags.d.mts +49 -0
- package/dist/utils/feature-flags.d.mts.map +1 -1
- package/dist/utils/feature-flags.mjs +36 -1
- package/dist/utils/feature-flags.mjs.map +1 -1
- package/dist/utils/gas-fees.cjs +21 -3
- package/dist/utils/gas-fees.cjs.map +1 -1
- package/dist/utils/gas-fees.d.cts +14 -0
- package/dist/utils/gas-fees.d.cts.map +1 -1
- package/dist/utils/gas-fees.d.mts +14 -0
- package/dist/utils/gas-fees.d.mts.map +1 -1
- package/dist/utils/gas-fees.mjs +19 -2
- package/dist/utils/gas-fees.mjs.map +1 -1
- package/dist/utils/gas-flow.cjs +3 -2
- package/dist/utils/gas-flow.cjs.map +1 -1
- package/dist/utils/gas-flow.d.cts +3 -1
- package/dist/utils/gas-flow.d.cts.map +1 -1
- package/dist/utils/gas-flow.d.mts +3 -1
- package/dist/utils/gas-flow.d.mts.map +1 -1
- package/dist/utils/gas-flow.mjs +3 -2
- package/dist/utils/gas-flow.mjs.map +1 -1
- package/dist/utils/gas.cjs +7 -3
- package/dist/utils/gas.cjs.map +1 -1
- package/dist/utils/gas.mjs +7 -3
- package/dist/utils/gas.mjs.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.cjs +9 -4
- package/dist/utils/layer1-gas-fee-flow.cjs.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.d.cts +4 -1
- package/dist/utils/layer1-gas-fee-flow.d.cts.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.d.mts +4 -1
- package/dist/utils/layer1-gas-fee-flow.d.mts.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.mjs +9 -4
- package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -1
- package/dist/utils/nonce.cjs +3 -3
- package/dist/utils/nonce.cjs.map +1 -1
- package/dist/utils/nonce.d.cts +2 -2
- package/dist/utils/nonce.d.cts.map +1 -1
- package/dist/utils/nonce.d.mts +2 -2
- package/dist/utils/nonce.d.mts.map +1 -1
- package/dist/utils/nonce.mjs +3 -3
- package/dist/utils/nonce.mjs.map +1 -1
- package/dist/utils/simulation-api.cjs.map +1 -1
- package/dist/utils/simulation-api.d.cts +37 -0
- package/dist/utils/simulation-api.d.cts.map +1 -1
- package/dist/utils/simulation-api.d.mts +37 -0
- package/dist/utils/simulation-api.d.mts.map +1 -1
- package/dist/utils/simulation-api.mjs.map +1 -1
- package/dist/utils/simulation.cjs +63 -9
- package/dist/utils/simulation.cjs.map +1 -1
- package/dist/utils/simulation.d.cts +7 -2
- package/dist/utils/simulation.d.cts.map +1 -1
- package/dist/utils/simulation.d.mts +7 -2
- package/dist/utils/simulation.d.mts.map +1 -1
- package/dist/utils/simulation.mjs +63 -9
- package/dist/utils/simulation.mjs.map +1 -1
- package/dist/utils/utils.cjs +23 -1
- package/dist/utils/utils.cjs.map +1 -1
- package/dist/utils/utils.d.cts +8 -0
- package/dist/utils/utils.d.cts.map +1 -1
- package/dist/utils/utils.d.mts +8 -0
- package/dist/utils/utils.d.mts.map +1 -1
- package/dist/utils/utils.mjs +22 -1
- package/dist/utils/utils.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionPoller.d.cts","sourceRoot":"","sources":["../../src/helpers/TransactionPoller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,qCAAqC;
|
|
1
|
+
{"version":3,"file":"TransactionPoller.d.cts","sourceRoot":"","sources":["../../src/helpers/TransactionPoller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,qCAAqC;AACjE,OAAO,EAAsB,KAAK,GAAG,EAAE,wBAAwB;AAI/D,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAiB;AAKhD;;;;GAIG;AACH,qBAAa,iBAAiB;;gBAmBhB,EACV,YAAY,EACZ,OAAO,EACP,SAAS,GACV,EAAE;QACD,YAAY,EAAE,YAAY,CAAC;QAC3B,OAAO,EAAE,GAAG,CAAC;QACb,SAAS,EAAE,8BAA8B,CAAC;KAC3C;IAMD;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,CAAC,iBAAiB,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC;IAa5D;;;OAGG;IACH,IAAI;IAgBJ;;;;;;OAMG;IACH,sBAAsB,CAAC,mBAAmB,EAAE,eAAe,EAAE;CA6F9D"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BlockTracker } from "@metamask/network-controller";
|
|
2
|
+
import { type Hex } from "@metamask/utils";
|
|
3
|
+
import type { TransactionControllerMessenger } from "../TransactionController.mjs";
|
|
2
4
|
import type { TransactionMeta } from "../types.mjs";
|
|
3
|
-
export declare const ACCELERATED_COUNT_MAX = 10;
|
|
4
|
-
export declare const ACCELERATED_INTERVAL: number;
|
|
5
5
|
/**
|
|
6
6
|
* Helper class to orchestrate when to poll pending transactions.
|
|
7
7
|
* Initially starts polling via a timeout chain every 2 seconds up to 5 times.
|
|
@@ -9,7 +9,11 @@ export declare const ACCELERATED_INTERVAL: number;
|
|
|
9
9
|
*/
|
|
10
10
|
export declare class TransactionPoller {
|
|
11
11
|
#private;
|
|
12
|
-
constructor(blockTracker:
|
|
12
|
+
constructor({ blockTracker, chainId, messenger, }: {
|
|
13
|
+
blockTracker: BlockTracker;
|
|
14
|
+
chainId: Hex;
|
|
15
|
+
messenger: TransactionControllerMessenger;
|
|
16
|
+
});
|
|
13
17
|
/**
|
|
14
18
|
* Start the poller with a listener that will be called on every interval.
|
|
15
19
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionPoller.d.mts","sourceRoot":"","sources":["../../src/helpers/TransactionPoller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,qCAAqC;
|
|
1
|
+
{"version":3,"file":"TransactionPoller.d.mts","sourceRoot":"","sources":["../../src/helpers/TransactionPoller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,qCAAqC;AACjE,OAAO,EAAsB,KAAK,GAAG,EAAE,wBAAwB;AAI/D,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAiB;AAKhD;;;;GAIG;AACH,qBAAa,iBAAiB;;gBAmBhB,EACV,YAAY,EACZ,OAAO,EACP,SAAS,GACV,EAAE;QACD,YAAY,EAAE,YAAY,CAAC;QAC3B,OAAO,EAAE,GAAG,CAAC;QACb,SAAS,EAAE,8BAA8B,CAAC;KAC3C;IAMD;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,CAAC,iBAAiB,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC;IAa5D;;;OAGG;IACH,IAAI;IAgBJ;;;;;;OAMG;IACH,sBAAsB,CAAC,mBAAmB,EAAE,eAAe,EAAE;CA6F9D"}
|
|
@@ -9,13 +9,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _TransactionPoller_instances, _TransactionPoller_acceleratedCount, _TransactionPoller_blockTracker, _TransactionPoller_blockTrackerListener, _TransactionPoller_listener, _TransactionPoller_pendingTransactions, _TransactionPoller_running, _TransactionPoller_timeout, _TransactionPoller_queue, _TransactionPoller_interval, _TransactionPoller_stopTimeout, _TransactionPoller_stopBlockTracker;
|
|
12
|
+
var _TransactionPoller_instances, _TransactionPoller_acceleratedCount, _TransactionPoller_blockTracker, _TransactionPoller_chainId, _TransactionPoller_messenger, _TransactionPoller_blockTrackerListener, _TransactionPoller_listener, _TransactionPoller_pendingTransactions, _TransactionPoller_running, _TransactionPoller_timeout, _TransactionPoller_queue, _TransactionPoller_interval, _TransactionPoller_stopTimeout, _TransactionPoller_stopBlockTracker;
|
|
13
13
|
import { createModuleLogger } from "@metamask/utils";
|
|
14
14
|
import $lodash from "lodash";
|
|
15
15
|
const { isEqual } = $lodash;
|
|
16
16
|
import { projectLogger } from "../logger.mjs";
|
|
17
|
-
|
|
18
|
-
export const ACCELERATED_INTERVAL = 1000 * 3; // 3 Seconds
|
|
17
|
+
import { getAcceleratedPollingParams } from "../utils/feature-flags.mjs";
|
|
19
18
|
const log = createModuleLogger(projectLogger, 'transaction-poller');
|
|
20
19
|
/**
|
|
21
20
|
* Helper class to orchestrate when to poll pending transactions.
|
|
@@ -23,16 +22,20 @@ const log = createModuleLogger(projectLogger, 'transaction-poller');
|
|
|
23
22
|
* Following that, it will poll on every new block via the block tracker.
|
|
24
23
|
*/
|
|
25
24
|
export class TransactionPoller {
|
|
26
|
-
constructor(blockTracker) {
|
|
25
|
+
constructor({ blockTracker, chainId, messenger, }) {
|
|
27
26
|
_TransactionPoller_instances.add(this);
|
|
28
27
|
_TransactionPoller_acceleratedCount.set(this, 0);
|
|
29
28
|
_TransactionPoller_blockTracker.set(this, void 0);
|
|
29
|
+
_TransactionPoller_chainId.set(this, void 0);
|
|
30
|
+
_TransactionPoller_messenger.set(this, void 0);
|
|
30
31
|
_TransactionPoller_blockTrackerListener.set(this, void 0);
|
|
31
32
|
_TransactionPoller_listener.set(this, void 0);
|
|
32
33
|
_TransactionPoller_pendingTransactions.set(this, void 0);
|
|
33
34
|
_TransactionPoller_running.set(this, false);
|
|
34
35
|
_TransactionPoller_timeout.set(this, void 0);
|
|
35
36
|
__classPrivateFieldSet(this, _TransactionPoller_blockTracker, blockTracker, "f");
|
|
37
|
+
__classPrivateFieldSet(this, _TransactionPoller_chainId, chainId, "f");
|
|
38
|
+
__classPrivateFieldSet(this, _TransactionPoller_messenger, messenger, "f");
|
|
36
39
|
}
|
|
37
40
|
/**
|
|
38
41
|
* Start the poller with a listener that will be called on every interval.
|
|
@@ -87,11 +90,12 @@ export class TransactionPoller {
|
|
|
87
90
|
}
|
|
88
91
|
}
|
|
89
92
|
}
|
|
90
|
-
_TransactionPoller_acceleratedCount = new WeakMap(), _TransactionPoller_blockTracker = new WeakMap(), _TransactionPoller_blockTrackerListener = new WeakMap(), _TransactionPoller_listener = new WeakMap(), _TransactionPoller_pendingTransactions = new WeakMap(), _TransactionPoller_running = new WeakMap(), _TransactionPoller_timeout = new WeakMap(), _TransactionPoller_instances = new WeakSet(), _TransactionPoller_queue = function _TransactionPoller_queue() {
|
|
93
|
+
_TransactionPoller_acceleratedCount = new WeakMap(), _TransactionPoller_blockTracker = new WeakMap(), _TransactionPoller_chainId = new WeakMap(), _TransactionPoller_messenger = new WeakMap(), _TransactionPoller_blockTrackerListener = new WeakMap(), _TransactionPoller_listener = new WeakMap(), _TransactionPoller_pendingTransactions = new WeakMap(), _TransactionPoller_running = new WeakMap(), _TransactionPoller_timeout = new WeakMap(), _TransactionPoller_instances = new WeakSet(), _TransactionPoller_queue = function _TransactionPoller_queue() {
|
|
91
94
|
if (!__classPrivateFieldGet(this, _TransactionPoller_running, "f")) {
|
|
92
95
|
return;
|
|
93
96
|
}
|
|
94
|
-
|
|
97
|
+
const { countMax, intervalMs } = getAcceleratedPollingParams(__classPrivateFieldGet(this, _TransactionPoller_chainId, "f"), __classPrivateFieldGet(this, _TransactionPoller_messenger, "f"));
|
|
98
|
+
if (__classPrivateFieldGet(this, _TransactionPoller_acceleratedCount, "f") >= countMax) {
|
|
95
99
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
96
100
|
__classPrivateFieldSet(this, _TransactionPoller_blockTrackerListener, (latestBlockNumber) => __classPrivateFieldGet(this, _TransactionPoller_instances, "m", _TransactionPoller_interval).call(this, false, latestBlockNumber), "f");
|
|
97
101
|
__classPrivateFieldGet(this, _TransactionPoller_blockTracker, "f").on('latest', __classPrivateFieldGet(this, _TransactionPoller_blockTrackerListener, "f"));
|
|
@@ -103,7 +107,7 @@ _TransactionPoller_acceleratedCount = new WeakMap(), _TransactionPoller_blockTra
|
|
|
103
107
|
__classPrivateFieldSet(this, _TransactionPoller_timeout, setTimeout(async () => {
|
|
104
108
|
await __classPrivateFieldGet(this, _TransactionPoller_instances, "m", _TransactionPoller_interval).call(this, true);
|
|
105
109
|
__classPrivateFieldGet(this, _TransactionPoller_instances, "m", _TransactionPoller_queue).call(this);
|
|
106
|
-
},
|
|
110
|
+
}, intervalMs), "f");
|
|
107
111
|
}, _TransactionPoller_interval = async function _TransactionPoller_interval(isAccelerated, latestBlockNumber) {
|
|
108
112
|
if (isAccelerated) {
|
|
109
113
|
log('Accelerated interval', __classPrivateFieldGet(this, _TransactionPoller_acceleratedCount, "f") + 1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionPoller.mjs","sourceRoot":"","sources":["../../src/helpers/TransactionPoller.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"TransactionPoller.mjs","sourceRoot":"","sources":["../../src/helpers/TransactionPoller.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,uBAAA,IAAI,uCAAc,CAAC,cAAc,CAAC,QAAQ,EAAE,uBAAA,IAAI,+CAAsB,CAAC,CAAC;IACxE,uBAAA,IAAI,2CAAyB,SAAS,MAAA,CAAC;AACzC,CAAC","sourcesContent":["import type { BlockTracker } from '@metamask/network-controller';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\nimport { isEqual } from 'lodash';\n\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type { TransactionMeta } from '../types';\nimport { getAcceleratedPollingParams } from '../utils/feature-flags';\n\nconst log = createModuleLogger(projectLogger, 'transaction-poller');\n\n/**\n * Helper class to orchestrate when to poll pending transactions.\n * Initially starts polling via a timeout chain every 2 seconds up to 5 times.\n * Following that, it will poll on every new block via the block tracker.\n */\nexport class TransactionPoller {\n #acceleratedCount = 0;\n\n readonly #blockTracker: BlockTracker;\n\n readonly #chainId: Hex;\n\n readonly #messenger: TransactionControllerMessenger;\n\n #blockTrackerListener?: (latestBlockNumber: string) => void;\n\n #listener?: (latestBlockNumber: string) => Promise<void>;\n\n #pendingTransactions?: TransactionMeta[];\n\n #running = false;\n\n #timeout?: NodeJS.Timeout;\n\n constructor({\n blockTracker,\n chainId,\n messenger,\n }: {\n blockTracker: BlockTracker;\n chainId: Hex;\n messenger: TransactionControllerMessenger;\n }) {\n this.#blockTracker = blockTracker;\n this.#chainId = chainId;\n this.#messenger = messenger;\n }\n\n /**\n * Start the poller with a listener that will be called on every interval.\n *\n * @param listener - The listener to call on every interval.\n */\n start(listener: (latestBlockNumber: string) => Promise<void>) {\n if (this.#running) {\n return;\n }\n\n this.#listener = listener;\n this.#running = true;\n\n this.#queue();\n\n log('Started');\n }\n\n /**\n * Stop the poller.\n * Remove all timeouts and block tracker listeners.\n */\n stop() {\n if (!this.#running) {\n return;\n }\n\n this.#running = false;\n this.#listener = undefined;\n this.#acceleratedCount = 0;\n this.#pendingTransactions = undefined;\n\n this.#stopTimeout();\n this.#stopBlockTracker();\n\n log('Stopped');\n }\n\n /**\n * Notify the poller of the pending transactions being monitored.\n * This will reset to the accelerated polling and reset the count\n * when new transactions are added or removed.\n *\n * @param pendingTransactions - The pending transactions to poll.\n */\n setPendingTransactions(pendingTransactions: TransactionMeta[]) {\n const currentPendingTransactionIds = (this.#pendingTransactions ?? []).map(\n (tx) => tx.id,\n );\n\n this.#pendingTransactions = pendingTransactions;\n\n const newPendingTransactionIds = pendingTransactions.map((tx) => tx.id);\n\n const hasUpdatedIds = !isEqual(\n currentPendingTransactionIds,\n newPendingTransactionIds,\n );\n\n if (!this.#running || !hasUpdatedIds) {\n return;\n }\n\n log('Detected new pending transactions', newPendingTransactionIds);\n\n this.#acceleratedCount = 0;\n\n if (this.#blockTrackerListener) {\n this.#stopBlockTracker();\n this.#queue();\n }\n }\n\n #queue() {\n if (!this.#running) {\n return;\n }\n\n const { countMax, intervalMs } = getAcceleratedPollingParams(\n this.#chainId,\n this.#messenger,\n );\n\n if (this.#acceleratedCount >= countMax) {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#blockTrackerListener = (latestBlockNumber) =>\n this.#interval(false, latestBlockNumber);\n\n this.#blockTracker.on('latest', this.#blockTrackerListener);\n\n log('Added block tracker listener');\n\n return;\n }\n\n this.#stopTimeout();\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#timeout = setTimeout(async () => {\n await this.#interval(true);\n this.#queue();\n }, intervalMs);\n }\n\n async #interval(isAccelerated: boolean, latestBlockNumber?: string) {\n if (isAccelerated) {\n log('Accelerated interval', this.#acceleratedCount + 1);\n } else {\n log('Block tracker interval', latestBlockNumber);\n }\n\n const latestBlockNumberFinal =\n latestBlockNumber ?? (await this.#blockTracker.getLatestBlock());\n\n await this.#listener?.(latestBlockNumberFinal);\n\n if (isAccelerated && this.#running) {\n this.#acceleratedCount += 1;\n }\n }\n\n #stopTimeout() {\n if (!this.#timeout) {\n return;\n }\n\n clearTimeout(this.#timeout);\n this.#timeout = undefined;\n }\n\n #stopBlockTracker() {\n if (!this.#blockTrackerListener) {\n return;\n }\n\n this.#blockTracker.removeListener('latest', this.#blockTrackerListener);\n this.#blockTrackerListener = undefined;\n }\n}\n"]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _CollectPublishHook_instances, _CollectPublishHook_publishPromises, _CollectPublishHook_signedTransactions, _CollectPublishHook_transactionCount, _CollectPublishHook_readyPromise, _CollectPublishHook_hook;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CollectPublishHook = void 0;
|
|
16
|
+
const utils_1 = require("@metamask/utils");
|
|
17
|
+
const logger_1 = require("../logger.cjs");
|
|
18
|
+
const log = (0, utils_1.createModuleLogger)(logger_1.projectLogger, 'collect-publish-hook');
|
|
19
|
+
/**
|
|
20
|
+
* Custom publish logic that collects multiple signed transactions until a specific number is reached.
|
|
21
|
+
* Used by batch transactions to publish multiple transactions at once.
|
|
22
|
+
*/
|
|
23
|
+
class CollectPublishHook {
|
|
24
|
+
constructor(transactionCount) {
|
|
25
|
+
_CollectPublishHook_instances.add(this);
|
|
26
|
+
_CollectPublishHook_publishPromises.set(this, void 0);
|
|
27
|
+
_CollectPublishHook_signedTransactions.set(this, void 0);
|
|
28
|
+
_CollectPublishHook_transactionCount.set(this, void 0);
|
|
29
|
+
_CollectPublishHook_readyPromise.set(this, void 0);
|
|
30
|
+
__classPrivateFieldSet(this, _CollectPublishHook_publishPromises, [], "f");
|
|
31
|
+
__classPrivateFieldSet(this, _CollectPublishHook_readyPromise, (0, utils_1.createDeferredPromise)(), "f");
|
|
32
|
+
__classPrivateFieldSet(this, _CollectPublishHook_signedTransactions, [], "f");
|
|
33
|
+
__classPrivateFieldSet(this, _CollectPublishHook_transactionCount, transactionCount, "f");
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @returns The publish hook function to be passed to `addTransaction`.
|
|
37
|
+
*/
|
|
38
|
+
getHook() {
|
|
39
|
+
return __classPrivateFieldGet(this, _CollectPublishHook_instances, "m", _CollectPublishHook_hook).bind(this);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @returns A promise that resolves when all transactions are signed.
|
|
43
|
+
*/
|
|
44
|
+
ready() {
|
|
45
|
+
return __classPrivateFieldGet(this, _CollectPublishHook_readyPromise, "f").promise;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Resolve all publish promises with the provided transaction hashes.
|
|
49
|
+
*
|
|
50
|
+
* @param transactionHashes - The transaction hashes to pass to the original publish promises.
|
|
51
|
+
*/
|
|
52
|
+
success(transactionHashes) {
|
|
53
|
+
log('Success', { transactionHashes });
|
|
54
|
+
if (transactionHashes.length !== __classPrivateFieldGet(this, _CollectPublishHook_transactionCount, "f")) {
|
|
55
|
+
throw new Error('Transaction hash count mismatch');
|
|
56
|
+
}
|
|
57
|
+
for (let i = 0; i < __classPrivateFieldGet(this, _CollectPublishHook_publishPromises, "f").length; i++) {
|
|
58
|
+
const publishPromise = __classPrivateFieldGet(this, _CollectPublishHook_publishPromises, "f")[i];
|
|
59
|
+
const transactionHash = transactionHashes[i];
|
|
60
|
+
publishPromise.resolve({ transactionHash });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
error(error) {
|
|
64
|
+
log('Error', { error });
|
|
65
|
+
for (const publishPromise of __classPrivateFieldGet(this, _CollectPublishHook_publishPromises, "f")) {
|
|
66
|
+
publishPromise.reject(error);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.CollectPublishHook = CollectPublishHook;
|
|
71
|
+
_CollectPublishHook_publishPromises = new WeakMap(), _CollectPublishHook_signedTransactions = new WeakMap(), _CollectPublishHook_transactionCount = new WeakMap(), _CollectPublishHook_readyPromise = new WeakMap(), _CollectPublishHook_instances = new WeakSet(), _CollectPublishHook_hook = function _CollectPublishHook_hook(transactionMeta, signedTx) {
|
|
72
|
+
__classPrivateFieldGet(this, _CollectPublishHook_signedTransactions, "f").push(signedTx);
|
|
73
|
+
log('Processing transaction', { transactionMeta, signedTx });
|
|
74
|
+
const publishPromise = (0, utils_1.createDeferredPromise)();
|
|
75
|
+
__classPrivateFieldGet(this, _CollectPublishHook_publishPromises, "f").push(publishPromise);
|
|
76
|
+
if (__classPrivateFieldGet(this, _CollectPublishHook_signedTransactions, "f").length === __classPrivateFieldGet(this, _CollectPublishHook_transactionCount, "f")) {
|
|
77
|
+
log('All transactions signed');
|
|
78
|
+
__classPrivateFieldGet(this, _CollectPublishHook_readyPromise, "f").resolve({
|
|
79
|
+
signedTransactions: __classPrivateFieldGet(this, _CollectPublishHook_signedTransactions, "f"),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return publishPromise.promise;
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=CollectPublishHook.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CollectPublishHook.cjs","sourceRoot":"","sources":["../../src/hooks/CollectPublishHook.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Ac;QAClB,GAAG,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAExB,KAAK,MAAM,cAAc,IAAI,uBAAA,IAAI,2CAAiB,EAAE;YAClD,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SAC9B;IACH,CAAC;CAwBF;AAhFD,gDAgFC;iUArBG,eAAgC,EAChC,QAAgB;IAEhB,uBAAA,IAAI,8CAAoB,CAAC,IAAI,CAAC,QAAe,CAAC,CAAC;IAE/C,GAAG,CAAC,wBAAwB,EAAE,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,CAAC;IAE7D,MAAM,cAAc,GAAG,IAAA,6BAAqB,GAAqB,CAAC;IAElE,uBAAA,IAAI,2CAAiB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAE3C,IAAI,uBAAA,IAAI,8CAAoB,CAAC,MAAM,KAAK,uBAAA,IAAI,4CAAkB,EAAE;QAC9D,GAAG,CAAC,yBAAyB,CAAC,CAAC;QAE/B,uBAAA,IAAI,wCAAc,CAAC,OAAO,CAAC;YACzB,kBAAkB,EAAE,uBAAA,IAAI,8CAAoB;SAC7C,CAAC,CAAC;KACJ;IAED,OAAO,cAAc,CAAC,OAAO,CAAC;AAChC,CAAC","sourcesContent":["import type { DeferredPromise, Hex } from '@metamask/utils';\nimport { createDeferredPromise, createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type { PublishHook, PublishHookResult, TransactionMeta } from '../types';\n\nconst log = createModuleLogger(projectLogger, 'collect-publish-hook');\n\nexport type CollectPublishHookResult = {\n signedTransactions: Hex[];\n};\n\n/**\n * Custom publish logic that collects multiple signed transactions until a specific number is reached.\n * Used by batch transactions to publish multiple transactions at once.\n */\nexport class CollectPublishHook {\n readonly #publishPromises: DeferredPromise<PublishHookResult>[];\n\n readonly #signedTransactions: Hex[];\n\n readonly #transactionCount: number;\n\n readonly #readyPromise: DeferredPromise<CollectPublishHookResult>;\n\n constructor(transactionCount: number) {\n this.#publishPromises = [];\n this.#readyPromise = createDeferredPromise();\n this.#signedTransactions = [];\n this.#transactionCount = transactionCount;\n }\n\n /**\n * @returns The publish hook function to be passed to `addTransaction`.\n */\n getHook(): PublishHook {\n return this.#hook.bind(this);\n }\n\n /**\n * @returns A promise that resolves when all transactions are signed.\n */\n ready(): Promise<CollectPublishHookResult> {\n return this.#readyPromise.promise;\n }\n\n /**\n * Resolve all publish promises with the provided transaction hashes.\n *\n * @param transactionHashes - The transaction hashes to pass to the original publish promises.\n */\n success(transactionHashes: Hex[]) {\n log('Success', { transactionHashes });\n\n if (transactionHashes.length !== this.#transactionCount) {\n throw new Error('Transaction hash count mismatch');\n }\n\n for (let i = 0; i < this.#publishPromises.length; i++) {\n const publishPromise = this.#publishPromises[i];\n const transactionHash = transactionHashes[i];\n\n publishPromise.resolve({ transactionHash });\n }\n }\n\n error(error: unknown) {\n log('Error', { error });\n\n for (const publishPromise of this.#publishPromises) {\n publishPromise.reject(error);\n }\n }\n\n #hook(\n transactionMeta: TransactionMeta,\n signedTx: string,\n ): Promise<PublishHookResult> {\n this.#signedTransactions.push(signedTx as Hex);\n\n log('Processing transaction', { transactionMeta, signedTx });\n\n const publishPromise = createDeferredPromise<PublishHookResult>();\n\n this.#publishPromises.push(publishPromise);\n\n if (this.#signedTransactions.length === this.#transactionCount) {\n log('All transactions signed');\n\n this.#readyPromise.resolve({\n signedTransactions: this.#signedTransactions,\n });\n }\n\n return publishPromise.promise;\n }\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Hex } from "@metamask/utils";
|
|
2
|
+
import type { PublishHook } from "../types.cjs";
|
|
3
|
+
export type CollectPublishHookResult = {
|
|
4
|
+
signedTransactions: Hex[];
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Custom publish logic that collects multiple signed transactions until a specific number is reached.
|
|
8
|
+
* Used by batch transactions to publish multiple transactions at once.
|
|
9
|
+
*/
|
|
10
|
+
export declare class CollectPublishHook {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(transactionCount: number);
|
|
13
|
+
/**
|
|
14
|
+
* @returns The publish hook function to be passed to `addTransaction`.
|
|
15
|
+
*/
|
|
16
|
+
getHook(): PublishHook;
|
|
17
|
+
/**
|
|
18
|
+
* @returns A promise that resolves when all transactions are signed.
|
|
19
|
+
*/
|
|
20
|
+
ready(): Promise<CollectPublishHookResult>;
|
|
21
|
+
/**
|
|
22
|
+
* Resolve all publish promises with the provided transaction hashes.
|
|
23
|
+
*
|
|
24
|
+
* @param transactionHashes - The transaction hashes to pass to the original publish promises.
|
|
25
|
+
*/
|
|
26
|
+
success(transactionHashes: Hex[]): void;
|
|
27
|
+
error(error: unknown): void;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=CollectPublishHook.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CollectPublishHook.d.cts","sourceRoot":"","sources":["../../src/hooks/CollectPublishHook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,GAAG,EAAE,wBAAwB;AAI5D,OAAO,KAAK,EAAE,WAAW,EAAsC,qBAAiB;AAIhF,MAAM,MAAM,wBAAwB,GAAG;IACrC,kBAAkB,EAAE,GAAG,EAAE,CAAC;CAC3B,CAAC;AAEF;;;GAGG;AACH,qBAAa,kBAAkB;;gBASjB,gBAAgB,EAAE,MAAM;IAOpC;;OAEG;IACH,OAAO,IAAI,WAAW;IAItB;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,wBAAwB,CAAC;IAI1C;;;;OAIG;IACH,OAAO,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAehC,KAAK,CAAC,KAAK,EAAE,OAAO;CA8BrB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Hex } from "@metamask/utils";
|
|
2
|
+
import type { PublishHook } from "../types.mjs";
|
|
3
|
+
export type CollectPublishHookResult = {
|
|
4
|
+
signedTransactions: Hex[];
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Custom publish logic that collects multiple signed transactions until a specific number is reached.
|
|
8
|
+
* Used by batch transactions to publish multiple transactions at once.
|
|
9
|
+
*/
|
|
10
|
+
export declare class CollectPublishHook {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(transactionCount: number);
|
|
13
|
+
/**
|
|
14
|
+
* @returns The publish hook function to be passed to `addTransaction`.
|
|
15
|
+
*/
|
|
16
|
+
getHook(): PublishHook;
|
|
17
|
+
/**
|
|
18
|
+
* @returns A promise that resolves when all transactions are signed.
|
|
19
|
+
*/
|
|
20
|
+
ready(): Promise<CollectPublishHookResult>;
|
|
21
|
+
/**
|
|
22
|
+
* Resolve all publish promises with the provided transaction hashes.
|
|
23
|
+
*
|
|
24
|
+
* @param transactionHashes - The transaction hashes to pass to the original publish promises.
|
|
25
|
+
*/
|
|
26
|
+
success(transactionHashes: Hex[]): void;
|
|
27
|
+
error(error: unknown): void;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=CollectPublishHook.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CollectPublishHook.d.mts","sourceRoot":"","sources":["../../src/hooks/CollectPublishHook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,GAAG,EAAE,wBAAwB;AAI5D,OAAO,KAAK,EAAE,WAAW,EAAsC,qBAAiB;AAIhF,MAAM,MAAM,wBAAwB,GAAG;IACrC,kBAAkB,EAAE,GAAG,EAAE,CAAC;CAC3B,CAAC;AAEF;;;GAGG;AACH,qBAAa,kBAAkB;;gBASjB,gBAAgB,EAAE,MAAM;IAOpC;;OAEG;IACH,OAAO,IAAI,WAAW;IAItB;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,wBAAwB,CAAC;IAI1C;;;;OAIG;IACH,OAAO,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAehC,KAAK,CAAC,KAAK,EAAE,OAAO;CA8BrB"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _CollectPublishHook_instances, _CollectPublishHook_publishPromises, _CollectPublishHook_signedTransactions, _CollectPublishHook_transactionCount, _CollectPublishHook_readyPromise, _CollectPublishHook_hook;
|
|
13
|
+
import { createDeferredPromise, createModuleLogger } from "@metamask/utils";
|
|
14
|
+
import { projectLogger } from "../logger.mjs";
|
|
15
|
+
const log = createModuleLogger(projectLogger, 'collect-publish-hook');
|
|
16
|
+
/**
|
|
17
|
+
* Custom publish logic that collects multiple signed transactions until a specific number is reached.
|
|
18
|
+
* Used by batch transactions to publish multiple transactions at once.
|
|
19
|
+
*/
|
|
20
|
+
export class CollectPublishHook {
|
|
21
|
+
constructor(transactionCount) {
|
|
22
|
+
_CollectPublishHook_instances.add(this);
|
|
23
|
+
_CollectPublishHook_publishPromises.set(this, void 0);
|
|
24
|
+
_CollectPublishHook_signedTransactions.set(this, void 0);
|
|
25
|
+
_CollectPublishHook_transactionCount.set(this, void 0);
|
|
26
|
+
_CollectPublishHook_readyPromise.set(this, void 0);
|
|
27
|
+
__classPrivateFieldSet(this, _CollectPublishHook_publishPromises, [], "f");
|
|
28
|
+
__classPrivateFieldSet(this, _CollectPublishHook_readyPromise, createDeferredPromise(), "f");
|
|
29
|
+
__classPrivateFieldSet(this, _CollectPublishHook_signedTransactions, [], "f");
|
|
30
|
+
__classPrivateFieldSet(this, _CollectPublishHook_transactionCount, transactionCount, "f");
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @returns The publish hook function to be passed to `addTransaction`.
|
|
34
|
+
*/
|
|
35
|
+
getHook() {
|
|
36
|
+
return __classPrivateFieldGet(this, _CollectPublishHook_instances, "m", _CollectPublishHook_hook).bind(this);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @returns A promise that resolves when all transactions are signed.
|
|
40
|
+
*/
|
|
41
|
+
ready() {
|
|
42
|
+
return __classPrivateFieldGet(this, _CollectPublishHook_readyPromise, "f").promise;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Resolve all publish promises with the provided transaction hashes.
|
|
46
|
+
*
|
|
47
|
+
* @param transactionHashes - The transaction hashes to pass to the original publish promises.
|
|
48
|
+
*/
|
|
49
|
+
success(transactionHashes) {
|
|
50
|
+
log('Success', { transactionHashes });
|
|
51
|
+
if (transactionHashes.length !== __classPrivateFieldGet(this, _CollectPublishHook_transactionCount, "f")) {
|
|
52
|
+
throw new Error('Transaction hash count mismatch');
|
|
53
|
+
}
|
|
54
|
+
for (let i = 0; i < __classPrivateFieldGet(this, _CollectPublishHook_publishPromises, "f").length; i++) {
|
|
55
|
+
const publishPromise = __classPrivateFieldGet(this, _CollectPublishHook_publishPromises, "f")[i];
|
|
56
|
+
const transactionHash = transactionHashes[i];
|
|
57
|
+
publishPromise.resolve({ transactionHash });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
error(error) {
|
|
61
|
+
log('Error', { error });
|
|
62
|
+
for (const publishPromise of __classPrivateFieldGet(this, _CollectPublishHook_publishPromises, "f")) {
|
|
63
|
+
publishPromise.reject(error);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
_CollectPublishHook_publishPromises = new WeakMap(), _CollectPublishHook_signedTransactions = new WeakMap(), _CollectPublishHook_transactionCount = new WeakMap(), _CollectPublishHook_readyPromise = new WeakMap(), _CollectPublishHook_instances = new WeakSet(), _CollectPublishHook_hook = function _CollectPublishHook_hook(transactionMeta, signedTx) {
|
|
68
|
+
__classPrivateFieldGet(this, _CollectPublishHook_signedTransactions, "f").push(signedTx);
|
|
69
|
+
log('Processing transaction', { transactionMeta, signedTx });
|
|
70
|
+
const publishPromise = createDeferredPromise();
|
|
71
|
+
__classPrivateFieldGet(this, _CollectPublishHook_publishPromises, "f").push(publishPromise);
|
|
72
|
+
if (__classPrivateFieldGet(this, _CollectPublishHook_signedTransactions, "f").length === __classPrivateFieldGet(this, _CollectPublishHook_transactionCount, "f")) {
|
|
73
|
+
log('All transactions signed');
|
|
74
|
+
__classPrivateFieldGet(this, _CollectPublishHook_readyPromise, "f").resolve({
|
|
75
|
+
signedTransactions: __classPrivateFieldGet(this, _CollectPublishHook_signedTransactions, "f"),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return publishPromise.promise;
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=CollectPublishHook.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CollectPublishHook.mjs","sourceRoot":"","sources":["../../src/hooks/CollectPublishHook.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,wBAAwB;AAE5E,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAG1C,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,sBAAsB,CAAC,CAAC;AAMtE;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IAS7B,YAAY,gBAAwB;;QAR3B,sDAAuD;QAEvD,yDAA2B;QAE3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8CAAoB,CAAC,IAAI,CAAC,QAAe,CAAC,CAAC;IAE/C,GAAG,CAAC,wBAAwB,EAAE,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,CAAC;IAE7D,MAAM,cAAc,GAAG,qBAAqB,EAAqB,CAAC;IAElE,uBAAA,IAAI,2CAAiB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAE3C,IAAI,uBAAA,IAAI,8CAAoB,CAAC,MAAM,KAAK,uBAAA,IAAI,4CAAkB,EAAE;QAC9D,GAAG,CAAC,yBAAyB,CAAC,CAAC;QAE/B,uBAAA,IAAI,wCAAc,CAAC,OAAO,CAAC;YACzB,kBAAkB,EAAE,uBAAA,IAAI,8CAAoB;SAC7C,CAAC,CAAC;KACJ;IAED,OAAO,cAAc,CAAC,OAAO,CAAC;AAChC,CAAC","sourcesContent":["import type { DeferredPromise, Hex } from '@metamask/utils';\nimport { createDeferredPromise, createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type { PublishHook, PublishHookResult, TransactionMeta } from '../types';\n\nconst log = createModuleLogger(projectLogger, 'collect-publish-hook');\n\nexport type CollectPublishHookResult = {\n signedTransactions: Hex[];\n};\n\n/**\n * Custom publish logic that collects multiple signed transactions until a specific number is reached.\n * Used by batch transactions to publish multiple transactions at once.\n */\nexport class CollectPublishHook {\n readonly #publishPromises: DeferredPromise<PublishHookResult>[];\n\n readonly #signedTransactions: Hex[];\n\n readonly #transactionCount: number;\n\n readonly #readyPromise: DeferredPromise<CollectPublishHookResult>;\n\n constructor(transactionCount: number) {\n this.#publishPromises = [];\n this.#readyPromise = createDeferredPromise();\n this.#signedTransactions = [];\n this.#transactionCount = transactionCount;\n }\n\n /**\n * @returns The publish hook function to be passed to `addTransaction`.\n */\n getHook(): PublishHook {\n return this.#hook.bind(this);\n }\n\n /**\n * @returns A promise that resolves when all transactions are signed.\n */\n ready(): Promise<CollectPublishHookResult> {\n return this.#readyPromise.promise;\n }\n\n /**\n * Resolve all publish promises with the provided transaction hashes.\n *\n * @param transactionHashes - The transaction hashes to pass to the original publish promises.\n */\n success(transactionHashes: Hex[]) {\n log('Success', { transactionHashes });\n\n if (transactionHashes.length !== this.#transactionCount) {\n throw new Error('Transaction hash count mismatch');\n }\n\n for (let i = 0; i < this.#publishPromises.length; i++) {\n const publishPromise = this.#publishPromises[i];\n const transactionHash = transactionHashes[i];\n\n publishPromise.resolve({ transactionHash });\n }\n }\n\n error(error: unknown) {\n log('Error', { error });\n\n for (const publishPromise of this.#publishPromises) {\n publishPromise.reject(error);\n }\n }\n\n #hook(\n transactionMeta: TransactionMeta,\n signedTx: string,\n ): Promise<PublishHookResult> {\n this.#signedTransactions.push(signedTx as Hex);\n\n log('Processing transaction', { transactionMeta, signedTx });\n\n const publishPromise = createDeferredPromise<PublishHookResult>();\n\n this.#publishPromises.push(publishPromise);\n\n if (this.#signedTransactions.length === this.#transactionCount) {\n log('All transactions signed');\n\n this.#readyPromise.resolve({\n signedTransactions: this.#signedTransactions,\n });\n }\n\n return publishPromise.promise;\n }\n}\n"]}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _ExtraTransactionsPublishHook_instances, _ExtraTransactionsPublishHook_addTransactionBatch, _ExtraTransactionsPublishHook_transactions, _ExtraTransactionsPublishHook_hook;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ExtraTransactionsPublishHook = void 0;
|
|
16
|
+
const utils_1 = require("@metamask/utils");
|
|
17
|
+
const logger_1 = require("../logger.cjs");
|
|
18
|
+
const log = (0, utils_1.createModuleLogger)(logger_1.projectLogger, 'extra-transactions-publish-hook');
|
|
19
|
+
/**
|
|
20
|
+
* Custom publish logic that also publishes additional transactions in an batch.
|
|
21
|
+
* Requires the batch to be successful to resolve.
|
|
22
|
+
*/
|
|
23
|
+
class ExtraTransactionsPublishHook {
|
|
24
|
+
constructor({ addTransactionBatch, transactions, }) {
|
|
25
|
+
_ExtraTransactionsPublishHook_instances.add(this);
|
|
26
|
+
_ExtraTransactionsPublishHook_addTransactionBatch.set(this, void 0);
|
|
27
|
+
_ExtraTransactionsPublishHook_transactions.set(this, void 0);
|
|
28
|
+
__classPrivateFieldSet(this, _ExtraTransactionsPublishHook_addTransactionBatch, addTransactionBatch, "f");
|
|
29
|
+
__classPrivateFieldSet(this, _ExtraTransactionsPublishHook_transactions, transactions, "f");
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @returns The publish hook function.
|
|
33
|
+
*/
|
|
34
|
+
getHook() {
|
|
35
|
+
return __classPrivateFieldGet(this, _ExtraTransactionsPublishHook_instances, "m", _ExtraTransactionsPublishHook_hook).bind(this);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.ExtraTransactionsPublishHook = ExtraTransactionsPublishHook;
|
|
39
|
+
_ExtraTransactionsPublishHook_addTransactionBatch = new WeakMap(), _ExtraTransactionsPublishHook_transactions = new WeakMap(), _ExtraTransactionsPublishHook_instances = new WeakSet(), _ExtraTransactionsPublishHook_hook = async function _ExtraTransactionsPublishHook_hook(transactionMeta, signedTx) {
|
|
40
|
+
log('Publishing transaction as batch', { transactionMeta, signedTx });
|
|
41
|
+
const { id, networkClientId, txParams } = transactionMeta;
|
|
42
|
+
const from = txParams.from;
|
|
43
|
+
const to = txParams.to;
|
|
44
|
+
const data = txParams.data;
|
|
45
|
+
const value = txParams.value;
|
|
46
|
+
const gas = txParams.gas;
|
|
47
|
+
const maxFeePerGas = txParams.maxFeePerGas;
|
|
48
|
+
const maxPriorityFeePerGas = txParams.maxPriorityFeePerGas;
|
|
49
|
+
const signedTransaction = signedTx;
|
|
50
|
+
const resultPromise = (0, utils_1.createDeferredPromise)();
|
|
51
|
+
const onPublish = ({ transactionHash }) => {
|
|
52
|
+
resultPromise.resolve({ transactionHash });
|
|
53
|
+
};
|
|
54
|
+
const firstParams = {
|
|
55
|
+
data,
|
|
56
|
+
gas,
|
|
57
|
+
maxFeePerGas,
|
|
58
|
+
maxPriorityFeePerGas,
|
|
59
|
+
to,
|
|
60
|
+
value,
|
|
61
|
+
};
|
|
62
|
+
const firstTransaction = {
|
|
63
|
+
existingTransaction: {
|
|
64
|
+
id,
|
|
65
|
+
onPublish,
|
|
66
|
+
signedTransaction,
|
|
67
|
+
},
|
|
68
|
+
params: firstParams,
|
|
69
|
+
};
|
|
70
|
+
const extraTransactions = __classPrivateFieldGet(this, _ExtraTransactionsPublishHook_transactions, "f").map((transaction) => ({
|
|
71
|
+
params: transaction,
|
|
72
|
+
}));
|
|
73
|
+
const transactions = [
|
|
74
|
+
firstTransaction,
|
|
75
|
+
...extraTransactions,
|
|
76
|
+
];
|
|
77
|
+
log('Adding transaction batch', {
|
|
78
|
+
from,
|
|
79
|
+
networkClientId,
|
|
80
|
+
transactions,
|
|
81
|
+
});
|
|
82
|
+
await __classPrivateFieldGet(this, _ExtraTransactionsPublishHook_addTransactionBatch, "f").call(this, {
|
|
83
|
+
from,
|
|
84
|
+
networkClientId,
|
|
85
|
+
transactions,
|
|
86
|
+
useHook: true,
|
|
87
|
+
});
|
|
88
|
+
return resultPromise.promise;
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=ExtraTransactionsPublishHook.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtraTransactionsPublishHook.cjs","sourceRoot":"","sources":["../../src/hooks/ExtraTransactionsPublishHook.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAIyB;AAGzB,0CAA0C;AAS1C,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAC5B,sBAAa,EACb,iCAAiC,CAClC,CAAC;AAEF;;;GAGG;AACH,MAAa,4BAA4B;IAKvC,YAAY,EACV,mBAAmB,EACnB,YAAY,GAIb;;QAVQ,oEAAmE;QAEnE,6DAAwC;QAS/C,uBAAA,IAAI,qDAAwB,mBAAmB,MAAA,CAAC;QAChD,uBAAA,IAAI,8CAAiB,YAAY,MAAA,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,uBAAA,IAAI,mFAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;CAoEF;AAzFD,oEAyFC;6NAlEC,KAAK,6CACH,eAAgC,EAChC,QAAgB;IAEhB,GAAG,CAAC,iCAAiC,EAAE,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,CAAC;IAEtE,MAAM,EAAE,EAAE,EAAE,eAAe,EAAE,QAAQ,EAAE,GAAG,eAAe,CAAC;IAC1D,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAW,CAAC;IAClC,MAAM,EAAE,GAAG,QAAQ,CAAC,EAAqB,CAAC;IAC1C,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAuB,CAAC;IAC9C,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAwB,CAAC;IAChD,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAsB,CAAC;IAC5C,MAAM,YAAY,GAAG,QAAQ,CAAC,YAA+B,CAAC;IAC9D,MAAM,oBAAoB,GAAG,QAAQ,CAAC,oBAEzB,CAAC;IACd,MAAM,iBAAiB,GAAG,QAAe,CAAC;IAC1C,MAAM,aAAa,GAAG,IAAA,6BAAqB,GAAqB,CAAC;IAEjE,MAAM,SAAS,GAAG,CAAC,EAAE,eAAe,EAAgC,EAAE,EAAE;QACtE,aAAa,CAAC,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC;IAC7C,CAAC,CAAC;IAEF,MAAM,WAAW,GAA2B;QAC1C,IAAI;QACJ,GAAG;QACH,YAAY;QACZ,oBAAoB;QACpB,EAAE;QACF,KAAK;KACN,CAAC;IAEF,MAAM,gBAAgB,GAAkC;QACtD,mBAAmB,EAAE;YACnB,EAAE;YACF,SAAS;YACT,iBAAiB;SAClB;QACD,MAAM,EAAE,WAAW;KACpB,CAAC;IAEF,MAAM,iBAAiB,GACrB,uBAAA,IAAI,kDAAc,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACvC,MAAM,EAAE,WAAW;KACpB,CAAC,CAAC,CAAC;IAEN,MAAM,YAAY,GAAoC;QACpD,gBAAgB;QAChB,GAAG,iBAAiB;KACrB,CAAC;IAEF,GAAG,CAAC,0BAA0B,EAAE;QAC9B,IAAI;QACJ,eAAe;QACf,YAAY;KACb,CAAC,CAAC;IAEH,MAAM,uBAAA,IAAI,yDAAqB,MAAzB,IAAI,EAAsB;QAC9B,IAAI;QACJ,eAAe;QACf,YAAY;QACZ,OAAO,EAAE,IAAI;KACd,CAAC,CAAC;IAEH,OAAO,aAAa,CAAC,OAAO,CAAC;AAC/B,CAAC","sourcesContent":["import {\n createDeferredPromise,\n createModuleLogger,\n type Hex,\n} from '@metamask/utils';\n\nimport type { TransactionController } from '..';\nimport { projectLogger } from '../logger';\nimport type {\n BatchTransactionParams,\n PublishHook,\n PublishHookResult,\n TransactionBatchSingleRequest,\n TransactionMeta,\n} from '../types';\n\nconst log = createModuleLogger(\n projectLogger,\n 'extra-transactions-publish-hook',\n);\n\n/**\n * Custom publish logic that also publishes additional transactions in an batch.\n * Requires the batch to be successful to resolve.\n */\nexport class ExtraTransactionsPublishHook {\n readonly #addTransactionBatch: TransactionController['addTransactionBatch'];\n\n readonly #transactions: BatchTransactionParams[];\n\n constructor({\n addTransactionBatch,\n transactions,\n }: {\n addTransactionBatch: TransactionController['addTransactionBatch'];\n transactions: BatchTransactionParams[];\n }) {\n this.#addTransactionBatch = addTransactionBatch;\n this.#transactions = transactions;\n }\n\n /**\n * @returns The publish hook function.\n */\n getHook(): PublishHook {\n return this.#hook.bind(this);\n }\n\n async #hook(\n transactionMeta: TransactionMeta,\n signedTx: string,\n ): Promise<PublishHookResult> {\n log('Publishing transaction as batch', { transactionMeta, signedTx });\n\n const { id, networkClientId, txParams } = transactionMeta;\n const from = txParams.from as Hex;\n const to = txParams.to as Hex | undefined;\n const data = txParams.data as Hex | undefined;\n const value = txParams.value as Hex | undefined;\n const gas = txParams.gas as Hex | undefined;\n const maxFeePerGas = txParams.maxFeePerGas as Hex | undefined;\n const maxPriorityFeePerGas = txParams.maxPriorityFeePerGas as\n | Hex\n | undefined;\n const signedTransaction = signedTx as Hex;\n const resultPromise = createDeferredPromise<PublishHookResult>();\n\n const onPublish = ({ transactionHash }: { transactionHash?: string }) => {\n resultPromise.resolve({ transactionHash });\n };\n\n const firstParams: BatchTransactionParams = {\n data,\n gas,\n maxFeePerGas,\n maxPriorityFeePerGas,\n to,\n value,\n };\n\n const firstTransaction: TransactionBatchSingleRequest = {\n existingTransaction: {\n id,\n onPublish,\n signedTransaction,\n },\n params: firstParams,\n };\n\n const extraTransactions: TransactionBatchSingleRequest[] =\n this.#transactions.map((transaction) => ({\n params: transaction,\n }));\n\n const transactions: TransactionBatchSingleRequest[] = [\n firstTransaction,\n ...extraTransactions,\n ];\n\n log('Adding transaction batch', {\n from,\n networkClientId,\n transactions,\n });\n\n await this.#addTransactionBatch({\n from,\n networkClientId,\n transactions,\n useHook: true,\n });\n\n return resultPromise.promise;\n }\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TransactionController } from "../index.cjs";
|
|
2
|
+
import type { BatchTransactionParams, PublishHook } from "../types.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* Custom publish logic that also publishes additional transactions in an batch.
|
|
5
|
+
* Requires the batch to be successful to resolve.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ExtraTransactionsPublishHook {
|
|
8
|
+
#private;
|
|
9
|
+
constructor({ addTransactionBatch, transactions, }: {
|
|
10
|
+
addTransactionBatch: TransactionController['addTransactionBatch'];
|
|
11
|
+
transactions: BatchTransactionParams[];
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* @returns The publish hook function.
|
|
15
|
+
*/
|
|
16
|
+
getHook(): PublishHook;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=ExtraTransactionsPublishHook.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtraTransactionsPublishHook.d.cts","sourceRoot":"","sources":["../../src/hooks/ExtraTransactionsPublishHook.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAW;AAEhD,OAAO,KAAK,EACV,sBAAsB,EACtB,WAAW,EAIZ,qBAAiB;AAOlB;;;GAGG;AACH,qBAAa,4BAA4B;;gBAK3B,EACV,mBAAmB,EACnB,YAAY,GACb,EAAE;QACD,mBAAmB,EAAE,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;QAClE,YAAY,EAAE,sBAAsB,EAAE,CAAC;KACxC;IAKD;;OAEG;IACH,OAAO,IAAI,WAAW;CAsEvB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TransactionController } from "../index.mjs";
|
|
2
|
+
import type { BatchTransactionParams, PublishHook } from "../types.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Custom publish logic that also publishes additional transactions in an batch.
|
|
5
|
+
* Requires the batch to be successful to resolve.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ExtraTransactionsPublishHook {
|
|
8
|
+
#private;
|
|
9
|
+
constructor({ addTransactionBatch, transactions, }: {
|
|
10
|
+
addTransactionBatch: TransactionController['addTransactionBatch'];
|
|
11
|
+
transactions: BatchTransactionParams[];
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* @returns The publish hook function.
|
|
15
|
+
*/
|
|
16
|
+
getHook(): PublishHook;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=ExtraTransactionsPublishHook.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtraTransactionsPublishHook.d.mts","sourceRoot":"","sources":["../../src/hooks/ExtraTransactionsPublishHook.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAW;AAEhD,OAAO,KAAK,EACV,sBAAsB,EACtB,WAAW,EAIZ,qBAAiB;AAOlB;;;GAGG;AACH,qBAAa,4BAA4B;;gBAK3B,EACV,mBAAmB,EACnB,YAAY,GACb,EAAE;QACD,mBAAmB,EAAE,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;QAClE,YAAY,EAAE,sBAAsB,EAAE,CAAC;KACxC;IAKD;;OAEG;IACH,OAAO,IAAI,WAAW;CAsEvB"}
|