@metamask-previews/transaction-controller 10.0.0-preview.2f7e793 → 10.0.0-preview.76bc0ab
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/dist/EtherscanRemoteTransactionSource.d.ts +3 -3
- package/dist/EtherscanRemoteTransactionSource.d.ts.map +1 -1
- package/dist/EtherscanRemoteTransactionSource.js +47 -24
- package/dist/EtherscanRemoteTransactionSource.js.map +1 -1
- package/dist/IncomingTransactionHelper.d.ts.map +1 -1
- package/dist/IncomingTransactionHelper.js +24 -18
- package/dist/IncomingTransactionHelper.js.map +1 -1
- package/dist/TransactionController.d.ts +71 -25
- package/dist/TransactionController.d.ts.map +1 -1
- package/dist/TransactionController.js +217 -106
- package/dist/TransactionController.js.map +1 -1
- package/dist/constants.d.ts +0 -19
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +0 -19
- package/dist/constants.js.map +1 -1
- package/dist/etherscan.d.ts +5 -6
- package/dist/etherscan.d.ts.map +1 -1
- package/dist/etherscan.js +6 -17
- package/dist/etherscan.js.map +1 -1
- package/dist/external-transactions.js +5 -5
- package/dist/external-transactions.js.map +1 -1
- package/dist/history.d.ts +15 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +75 -0
- package/dist/history.js.map +1 -0
- package/dist/logger.d.ts +6 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +8 -0
- package/dist/logger.js.map +1 -0
- package/dist/types.d.ts +108 -23
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +16 -18
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +44 -48
- package/dist/utils.js.map +1 -1
- package/package.json +3 -1
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG;IACvB,OAAO,EAAE,KA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Ae,CAAC,EAAE;QAC3B,MAAM,EAAE,iBAAiB;QACzB,SAAS,EAAE,GAAG,0CAAkC,SAAS;KAC1D;IACD,CAAC,iBAAS,CAAC,SAAS,CAAC,EAAE;QACrB,MAAM,EAAE,cAAc;QACtB,SAAS,EAAE,0CAAkC;KAC9C;IACD,CAAC,iBAAS,CAAC,iBAAiB,CAAC,EAAE;QAC7B,MAAM,EAAE,cAAc;QACtB,SAAS,EAAE,GAAG,0CAAkC,UAAU;KAC3D;IACD,CAAC,iBAAS,CAAC,MAAM,CAAC,EAAE;QAClB,MAAM,EAAE,aAAa;QACrB,SAAS,EAAE,0CAAkC;KAC9C;IACD,CAAC,iBAAS,CAAC,cAAc,CAAC,EAAE;QAC1B,MAAM,EAAE,aAAa;QACrB,SAAS,EAAE,GAAG,0CAAkC,UAAU;KAC3D;IACD,CAAC,iBAAS,CAAC,QAAQ,CAAC,EAAE;QACpB,MAAM,EAAE,aAAa;QACrB,SAAS,EAAE,GAAG,0CAAkC,WAAW;KAC5D;IACD,CAAC,iBAAS,CAAC,gBAAgB,CAAC,EAAE;QAC5B,MAAM,EAAE,aAAa;QACrB,SAAS,EAAE,GAAG,0CAAkC,WAAW;KAC5D;IACD,CAAC,iBAAS,CAAC,SAAS,CAAC,EAAE;QACrB,MAAM,EAAE,aAAa;QACrB,SAAS,EAAE,GAAG,0CAAkC,YAAY;KAC7D;IACD,CAAC,iBAAS,CAAC,MAAM,CAAC,EAAE;QAClB,MAAM,EAAE,eAAe;QACvB,SAAS,EAAE,GAAG,0CAAkC,SAAS;KAC1D;CACF,CAAC","sourcesContent":["export const CHAIN_IDS = {\n MAINNET: '0x1',\n GOERLI: '0x5',\n BSC: '0x38',\n BSC_TESTNET: '0x61',\n OPTIMISM: '0xa',\n OPTIMISM_TESTNET: '0x1a4',\n POLYGON: '0x89',\n POLYGON_TESTNET: '0x13881',\n AVALANCHE: '0xa86a',\n AVALANCHE_TESTNET: '0xa869',\n FANTOM: '0xfa',\n FANTOM_TESTNET: '0xfa2',\n SEPOLIA: '0xaa36a7',\n LINEA_GOERLI: '0xe704',\n LINEA_MAINNET: '0xe708',\n MOONBEAM: '0x504',\n MOONBEAM_TESTNET: '0x507',\n MOONRIVER: '0x505',\n GNOSIS: '0x64',\n} as const;\n\nexport const DEFAULT_ETHERSCAN_DOMAIN = 'etherscan.io';\nexport const DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX = 'api';\n\nexport const ETHERSCAN_SUPPORTED_NETWORKS = {\n [CHAIN_IDS.GOERLI]: {\n domain: DEFAULT_ETHERSCAN_DOMAIN,\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-goerli`,\n },\n [CHAIN_IDS.MAINNET]: {\n domain: DEFAULT_ETHERSCAN_DOMAIN,\n subdomain: DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX,\n },\n [CHAIN_IDS.SEPOLIA]: {\n domain: DEFAULT_ETHERSCAN_DOMAIN,\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-sepolia`,\n },\n [CHAIN_IDS.LINEA_GOERLI]: {\n domain: 'lineascan.build',\n subdomain: 'goerli',\n },\n [CHAIN_IDS.LINEA_MAINNET]: {\n domain: 'lineascan.build',\n subdomain: DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX,\n },\n [CHAIN_IDS.BSC]: {\n domain: 'bscscan.com',\n subdomain: DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX,\n },\n [CHAIN_IDS.BSC_TESTNET]: {\n domain: 'bscscan.com',\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-testnet`,\n },\n [CHAIN_IDS.OPTIMISM]: {\n domain: DEFAULT_ETHERSCAN_DOMAIN,\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-optimistic`,\n },\n [CHAIN_IDS.OPTIMISM_TESTNET]: {\n domain: DEFAULT_ETHERSCAN_DOMAIN,\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-goerli-optimistic`,\n },\n [CHAIN_IDS.POLYGON]: {\n domain: 'polygonscan.com',\n subdomain: DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX,\n },\n [CHAIN_IDS.POLYGON_TESTNET]: {\n domain: 'polygonscan.com',\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-mumbai`,\n },\n [CHAIN_IDS.AVALANCHE]: {\n domain: 'snowtrace.io',\n subdomain: DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX,\n },\n [CHAIN_IDS.AVALANCHE_TESTNET]: {\n domain: 'snowtrace.io',\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-testnet`,\n },\n [CHAIN_IDS.FANTOM]: {\n domain: 'ftmscan.com',\n subdomain: DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX,\n },\n [CHAIN_IDS.FANTOM_TESTNET]: {\n domain: 'ftmscan.com',\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-testnet`,\n },\n [CHAIN_IDS.MOONBEAM]: {\n domain: 'moonscan.io',\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-moonbeam`,\n },\n [CHAIN_IDS.MOONBEAM_TESTNET]: {\n domain: 'moonscan.io',\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-moonbase`,\n },\n [CHAIN_IDS.MOONRIVER]: {\n domain: 'moonscan.io',\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-moonriver`,\n },\n [CHAIN_IDS.GNOSIS]: {\n domain: 'gnosisscan.io',\n subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-gnosis`,\n },\n};\n"]}
|
package/dist/etherscan.d.ts
CHANGED
|
@@ -29,11 +29,12 @@ export interface EtherscanTokenTransactionMeta extends EtherscanTransactionMetaB
|
|
|
29
29
|
tokenSymbol: string;
|
|
30
30
|
}
|
|
31
31
|
export interface EtherscanTransactionResponse<T extends EtherscanTransactionMetaBase> {
|
|
32
|
-
|
|
32
|
+
status: '0' | '1';
|
|
33
|
+
message?: string;
|
|
34
|
+
result: string | T[];
|
|
33
35
|
}
|
|
34
36
|
export interface EtherscanTransactionRequest {
|
|
35
37
|
address: string;
|
|
36
|
-
apiKey?: string;
|
|
37
38
|
chainId: Hex;
|
|
38
39
|
fromBlock?: number;
|
|
39
40
|
limit?: number;
|
|
@@ -43,23 +44,21 @@ export interface EtherscanTransactionRequest {
|
|
|
43
44
|
*
|
|
44
45
|
* @param request - Configuration required to fetch transactions.
|
|
45
46
|
* @param request.address - Address to retrieve transactions for.
|
|
46
|
-
* @param request.apiKey - Etherscan API key.
|
|
47
47
|
* @param request.chainId - Current chain ID used to determine subdomain and domain.
|
|
48
48
|
* @param request.fromBlock - Block number to start fetching transactions from.
|
|
49
49
|
* @param request.limit - Number of transactions to retrieve.
|
|
50
50
|
* @returns An Etherscan response object containing the request status and an array of token transaction data.
|
|
51
51
|
*/
|
|
52
|
-
export declare function fetchEtherscanTransactions({ address,
|
|
52
|
+
export declare function fetchEtherscanTransactions({ address, chainId, fromBlock, limit, }: EtherscanTransactionRequest): Promise<EtherscanTransactionResponse<EtherscanTransactionMeta>>;
|
|
53
53
|
/**
|
|
54
54
|
* Retrieves token transaction data from Etherscan.
|
|
55
55
|
*
|
|
56
56
|
* @param request - Configuration required to fetch token transactions.
|
|
57
57
|
* @param request.address - Address to retrieve token transactions for.
|
|
58
|
-
* @param request.apiKey - Etherscan API key.
|
|
59
58
|
* @param request.chainId - Current chain ID used to determine subdomain and domain.
|
|
60
59
|
* @param request.fromBlock - Block number to start fetching token transactions from.
|
|
61
60
|
* @param request.limit - Number of token transactions to retrieve.
|
|
62
61
|
* @returns An Etherscan response object containing the request status and an array of token transaction data.
|
|
63
62
|
*/
|
|
64
|
-
export declare function fetchEtherscanTokenTransactions({ address,
|
|
63
|
+
export declare function fetchEtherscanTokenTransactions({ address, chainId, fromBlock, limit, }: EtherscanTransactionRequest): Promise<EtherscanTransactionResponse<EtherscanTokenTransactionMeta>>;
|
|
65
64
|
//# sourceMappingURL=etherscan.d.ts.map
|
package/dist/etherscan.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"etherscan.d.ts","sourceRoot":"","sources":["../src/etherscan.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"etherscan.d.ts","sourceRoot":"","sources":["../src/etherscan.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAK3C,MAAM,WAAW,4BAA4B;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,wBAAyB,SAAQ,4BAA4B;IAC5E,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,6BACf,SAAQ,4BAA4B;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,4BAA4B,CAC3C,CAAC,SAAS,4BAA4B;IAEtC,MAAM,EAAE,GAAG,GAAG,GAAG,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,GAAG,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;GASG;AACH,wBAAsB,0BAA0B,CAAC,EAC/C,OAAO,EACP,OAAO,EACP,SAAS,EACT,KAAK,GACN,EAAE,2BAA2B,GAAG,OAAO,CACtC,4BAA4B,CAAC,wBAAwB,CAAC,CACvD,CAOA;AAED;;;;;;;;;GASG;AACH,wBAAsB,+BAA+B,CAAC,EACpD,OAAO,EACP,OAAO,EACP,SAAS,EACT,KAAK,GACN,EAAE,2BAA2B,GAAG,OAAO,CACtC,4BAA4B,CAAC,6BAA6B,CAAC,CAC5D,CAOA"}
|
package/dist/etherscan.js
CHANGED
|
@@ -12,22 +12,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.fetchEtherscanTokenTransactions = exports.fetchEtherscanTransactions = void 0;
|
|
13
13
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
14
14
|
const constants_1 = require("./constants");
|
|
15
|
+
const logger_1 = require("./logger");
|
|
15
16
|
/**
|
|
16
17
|
* Retrieves transaction data from Etherscan.
|
|
17
18
|
*
|
|
18
19
|
* @param request - Configuration required to fetch transactions.
|
|
19
20
|
* @param request.address - Address to retrieve transactions for.
|
|
20
|
-
* @param request.apiKey - Etherscan API key.
|
|
21
21
|
* @param request.chainId - Current chain ID used to determine subdomain and domain.
|
|
22
22
|
* @param request.fromBlock - Block number to start fetching transactions from.
|
|
23
23
|
* @param request.limit - Number of transactions to retrieve.
|
|
24
24
|
* @returns An Etherscan response object containing the request status and an array of token transaction data.
|
|
25
25
|
*/
|
|
26
|
-
function fetchEtherscanTransactions({ address,
|
|
26
|
+
function fetchEtherscanTransactions({ address, chainId, fromBlock, limit, }) {
|
|
27
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
28
|
return yield fetchTransactions('txlist', {
|
|
29
29
|
address,
|
|
30
|
-
apiKey,
|
|
31
30
|
chainId,
|
|
32
31
|
fromBlock,
|
|
33
32
|
limit,
|
|
@@ -40,17 +39,15 @@ exports.fetchEtherscanTransactions = fetchEtherscanTransactions;
|
|
|
40
39
|
*
|
|
41
40
|
* @param request - Configuration required to fetch token transactions.
|
|
42
41
|
* @param request.address - Address to retrieve token transactions for.
|
|
43
|
-
* @param request.apiKey - Etherscan API key.
|
|
44
42
|
* @param request.chainId - Current chain ID used to determine subdomain and domain.
|
|
45
43
|
* @param request.fromBlock - Block number to start fetching token transactions from.
|
|
46
44
|
* @param request.limit - Number of token transactions to retrieve.
|
|
47
45
|
* @returns An Etherscan response object containing the request status and an array of token transaction data.
|
|
48
46
|
*/
|
|
49
|
-
function fetchEtherscanTokenTransactions({ address,
|
|
47
|
+
function fetchEtherscanTokenTransactions({ address, chainId, fromBlock, limit, }) {
|
|
50
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
49
|
return yield fetchTransactions('tokentx', {
|
|
52
50
|
address,
|
|
53
|
-
apiKey,
|
|
54
51
|
chainId,
|
|
55
52
|
fromBlock,
|
|
56
53
|
limit,
|
|
@@ -64,28 +61,24 @@ exports.fetchEtherscanTokenTransactions = fetchEtherscanTokenTransactions;
|
|
|
64
61
|
* @param action - The Etherscan endpoint to use.
|
|
65
62
|
* @param options - Options bag.
|
|
66
63
|
* @param options.address - Address to retrieve transactions for.
|
|
67
|
-
* @param options.apiKey - Etherscan API key.
|
|
68
64
|
* @param options.chainId - Current chain ID used to determine subdomain and domain.
|
|
69
65
|
* @param options.fromBlock - Block number to start fetching transactions from.
|
|
70
66
|
* @param options.limit - Number of transactions to retrieve.
|
|
71
67
|
* @returns An object containing the request status and an array of transaction data.
|
|
72
68
|
*/
|
|
73
|
-
function fetchTransactions(action, { address,
|
|
69
|
+
function fetchTransactions(action, { address, chainId, fromBlock, limit, }) {
|
|
74
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
71
|
const urlParams = {
|
|
76
72
|
module: 'account',
|
|
77
73
|
address,
|
|
78
74
|
startBlock: fromBlock === null || fromBlock === void 0 ? void 0 : fromBlock.toString(),
|
|
79
|
-
apikey: apiKey,
|
|
80
75
|
offset: limit === null || limit === void 0 ? void 0 : limit.toString(),
|
|
81
76
|
sort: 'desc',
|
|
82
77
|
};
|
|
83
78
|
const etherscanTxUrl = getEtherscanApiUrl(chainId, Object.assign(Object.assign({}, urlParams), { action }));
|
|
79
|
+
(0, logger_1.incomingTransactionsLogger)('Sending Etherscan request', etherscanTxUrl);
|
|
84
80
|
const response = (yield (0, controller_utils_1.handleFetch)(etherscanTxUrl));
|
|
85
|
-
|
|
86
|
-
throw new Error(`Etherscan request failed - ${response.result}`);
|
|
87
|
-
}
|
|
88
|
-
return { result: response.result };
|
|
81
|
+
return response;
|
|
89
82
|
});
|
|
90
83
|
}
|
|
91
84
|
/**
|
|
@@ -102,10 +95,6 @@ function getEtherscanApiUrl(chainId, urlParams) {
|
|
|
102
95
|
}
|
|
103
96
|
const apiUrl = `https://${networkInfo.subdomain}.${networkInfo.domain}`;
|
|
104
97
|
let url = `${apiUrl}/api?`;
|
|
105
|
-
// We only support API keys for the Etherscan domain
|
|
106
|
-
if (networkInfo.domain !== constants_1.DEFAULT_ETHERSCAN_DOMAIN) {
|
|
107
|
-
urlParams.apikey = undefined;
|
|
108
|
-
}
|
|
109
98
|
// eslint-disable-next-line guard-for-in
|
|
110
99
|
for (const paramKey in urlParams) {
|
|
111
100
|
const value = urlParams[paramKey];
|
package/dist/etherscan.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"etherscan.js","sourceRoot":"","sources":["../src/etherscan.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAAyD;AAGzD,
|
|
1
|
+
{"version":3,"file":"etherscan.js","sourceRoot":"","sources":["../src/etherscan.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAAyD;AAGzD,2CAA2D;AAC3D,qCAA6D;AAkD7D;;;;;;;;;GASG;AACH,SAAsB,0BAA0B,CAAC,EAC/C,OAAO,EACP,OAAO,EACP,SAAS,EACT,KAAK,GACuB;;QAG5B,OAAO,MAAM,iBAAiB,CAAC,QAAQ,EAAE;YACvC,OAAO;YACP,OAAO;YACP,SAAS;YACT,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CAAA;AAdD,gEAcC;AAED;;;;;;;;;GASG;AACH,SAAsB,+BAA+B,CAAC,EACpD,OAAO,EACP,OAAO,EACP,SAAS,EACT,KAAK,GACuB;;QAG5B,OAAO,MAAM,iBAAiB,CAAC,SAAS,EAAE;YACxC,OAAO;YACP,OAAO;YACP,SAAS;YACT,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CAAA;AAdD,0EAcC;AAED;;;;;;;;;;GAUG;AACH,SAAe,iBAAiB,CAC9B,MAAc,EACd,EACE,OAAO,EACP,OAAO,EACP,SAAS,EACT,KAAK,GAMN;;QAED,MAAM,SAAS,GAAG;YAChB,MAAM,EAAE,SAAS;YACjB,OAAO;YACP,UAAU,EAAE,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,QAAQ,EAAE;YACjC,MAAM,EAAE,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,EAAE;YACzB,IAAI,EAAE,MAAM;SACb,CAAC;QAEF,MAAM,cAAc,GAAG,kBAAkB,CAAC,OAAO,kCAC5C,SAAS,KACZ,MAAM,IACN,CAAC;QAEH,IAAA,mCAAG,EAAC,2BAA2B,EAAE,cAAc,CAAC,CAAC;QAEjD,MAAM,QAAQ,GAAG,CAAC,MAAM,IAAA,8BAAW,EACjC,cAAc,CACf,CAAoC,CAAC;QAEtC,OAAO,QAAQ,CAAC;IAClB,CAAC;CAAA;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CACzB,OAAY,EACZ,SAA6C;IAI7C,MAAM,WAAW,GAAG,wCAA4B,CAAC,OAA2B,CAAC,CAAC;IAE9E,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,6CAA6C,OAAO,EAAE,CAAC,CAAC;KACzE;IAED,MAAM,MAAM,GAAG,WAAW,WAAW,CAAC,SAAS,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;IACxE,IAAI,GAAG,GAAG,GAAG,MAAM,OAAO,CAAC;IAE3B,wCAAwC;IACxC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;QAChC,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;QAElC,IAAI,CAAC,KAAK,EAAE;YACV,SAAS;SACV;QAED,GAAG,IAAI,GAAG,QAAQ,IAAI,KAAK,GAAG,CAAC;KAChC;IAED,GAAG,IAAI,mBAAmB,CAAC;IAE3B,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { ETHERSCAN_SUPPORTED_NETWORKS } from './constants';\nimport { incomingTransactionsLogger as log } from './logger';\n\nexport interface EtherscanTransactionMetaBase {\n blockNumber: string;\n blockHash: string;\n confirmations: string;\n contractAddress: string;\n cumulativeGasUsed: string;\n from: string;\n gas: string;\n gasPrice: string;\n gasUsed: string;\n hash: string;\n nonce: string;\n timeStamp: string;\n to: string;\n transactionIndex: string;\n value: string;\n}\n\nexport interface EtherscanTransactionMeta extends EtherscanTransactionMetaBase {\n functionName: string;\n input: string;\n isError: string;\n methodId: string;\n txreceipt_status: string;\n}\n\nexport interface EtherscanTokenTransactionMeta\n extends EtherscanTransactionMetaBase {\n tokenDecimal: string;\n tokenName: string;\n tokenSymbol: string;\n}\n\nexport interface EtherscanTransactionResponse<\n T extends EtherscanTransactionMetaBase,\n> {\n status: '0' | '1';\n message?: string;\n result: string | T[];\n}\n\nexport interface EtherscanTransactionRequest {\n address: string;\n chainId: Hex;\n fromBlock?: number;\n limit?: number;\n}\n\n/**\n * Retrieves transaction data from Etherscan.\n *\n * @param request - Configuration required to fetch transactions.\n * @param request.address - Address to retrieve transactions for.\n * @param request.chainId - Current chain ID used to determine subdomain and domain.\n * @param request.fromBlock - Block number to start fetching transactions from.\n * @param request.limit - Number of transactions to retrieve.\n * @returns An Etherscan response object containing the request status and an array of token transaction data.\n */\nexport async function fetchEtherscanTransactions({\n address,\n chainId,\n fromBlock,\n limit,\n}: EtherscanTransactionRequest): Promise<\n EtherscanTransactionResponse<EtherscanTransactionMeta>\n> {\n return await fetchTransactions('txlist', {\n address,\n chainId,\n fromBlock,\n limit,\n });\n}\n\n/**\n * Retrieves token transaction data from Etherscan.\n *\n * @param request - Configuration required to fetch token transactions.\n * @param request.address - Address to retrieve token transactions for.\n * @param request.chainId - Current chain ID used to determine subdomain and domain.\n * @param request.fromBlock - Block number to start fetching token transactions from.\n * @param request.limit - Number of token transactions to retrieve.\n * @returns An Etherscan response object containing the request status and an array of token transaction data.\n */\nexport async function fetchEtherscanTokenTransactions({\n address,\n chainId,\n fromBlock,\n limit,\n}: EtherscanTransactionRequest): Promise<\n EtherscanTransactionResponse<EtherscanTokenTransactionMeta>\n> {\n return await fetchTransactions('tokentx', {\n address,\n chainId,\n fromBlock,\n limit,\n });\n}\n\n/**\n * Retrieves transaction data from Etherscan from a specific endpoint.\n *\n * @param action - The Etherscan endpoint to use.\n * @param options - Options bag.\n * @param options.address - Address to retrieve transactions for.\n * @param options.chainId - Current chain ID used to determine subdomain and domain.\n * @param options.fromBlock - Block number to start fetching transactions from.\n * @param options.limit - Number of transactions to retrieve.\n * @returns An object containing the request status and an array of transaction data.\n */\nasync function fetchTransactions<T extends EtherscanTransactionMetaBase>(\n action: string,\n {\n address,\n chainId,\n fromBlock,\n limit,\n }: {\n address: string;\n chainId: Hex;\n fromBlock?: number;\n limit?: number;\n },\n): Promise<EtherscanTransactionResponse<T>> {\n const urlParams = {\n module: 'account',\n address,\n startBlock: fromBlock?.toString(),\n offset: limit?.toString(),\n sort: 'desc',\n };\n\n const etherscanTxUrl = getEtherscanApiUrl(chainId, {\n ...urlParams,\n action,\n });\n\n log('Sending Etherscan request', etherscanTxUrl);\n\n const response = (await handleFetch(\n etherscanTxUrl,\n )) as EtherscanTransactionResponse<T>;\n\n return response;\n}\n\n/**\n * Return a URL that can be used to fetch data from Etherscan.\n *\n * @param chainId - Current chain ID used to determine subdomain and domain.\n * @param urlParams - The parameters used to construct the URL.\n * @returns URL to access Etherscan data.\n */\nfunction getEtherscanApiUrl(\n chainId: Hex,\n urlParams: Record<string, string | undefined>,\n): string {\n type SupportedChainId = keyof typeof ETHERSCAN_SUPPORTED_NETWORKS;\n\n const networkInfo = ETHERSCAN_SUPPORTED_NETWORKS[chainId as SupportedChainId];\n\n if (!networkInfo) {\n throw new Error(`Etherscan does not support chain with ID: ${chainId}`);\n }\n\n const apiUrl = `https://${networkInfo.subdomain}.${networkInfo.domain}`;\n let url = `${apiUrl}/api?`;\n\n // eslint-disable-next-line guard-for-in\n for (const paramKey in urlParams) {\n const value = urlParams[paramKey];\n\n if (!value) {\n continue;\n }\n\n url += `${paramKey}=${value}&`;\n }\n\n url += 'tag=latest&page=1';\n\n return url;\n}\n"]}
|
|
@@ -12,21 +12,21 @@ const types_1 = require("./types");
|
|
|
12
12
|
* @param pendingTxs - The submitted transactions in controller state.
|
|
13
13
|
*/
|
|
14
14
|
function validateConfirmedExternalTransaction(transactionMeta, confirmedTxs, pendingTxs) {
|
|
15
|
-
if (!transactionMeta || !transactionMeta.
|
|
16
|
-
throw eth_rpc_errors_1.ethErrors.rpc.invalidParams('"transactionMeta" or "transactionMeta.
|
|
15
|
+
if (!transactionMeta || !transactionMeta.txParams) {
|
|
16
|
+
throw eth_rpc_errors_1.ethErrors.rpc.invalidParams('"transactionMeta" or "transactionMeta.txParams" is missing');
|
|
17
17
|
}
|
|
18
18
|
if (transactionMeta.status !== types_1.TransactionStatus.confirmed) {
|
|
19
19
|
throw eth_rpc_errors_1.ethErrors.rpc.invalidParams('External transaction status should be "confirmed"');
|
|
20
20
|
}
|
|
21
|
-
const externalTxNonce = transactionMeta.
|
|
21
|
+
const externalTxNonce = transactionMeta.txParams.nonce;
|
|
22
22
|
if (pendingTxs && pendingTxs.length > 0) {
|
|
23
|
-
const foundPendingTxByNonce = pendingTxs.find((tx) => { var _a; return ((_a = tx.
|
|
23
|
+
const foundPendingTxByNonce = pendingTxs.find((tx) => { var _a; return ((_a = tx.txParams) === null || _a === void 0 ? void 0 : _a.nonce) === externalTxNonce; });
|
|
24
24
|
if (foundPendingTxByNonce) {
|
|
25
25
|
throw eth_rpc_errors_1.ethErrors.rpc.invalidParams('External transaction nonce should not be in pending txs');
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
if (confirmedTxs && confirmedTxs.length > 0) {
|
|
29
|
-
const foundConfirmedTxByNonce = confirmedTxs.find((tx) => { var _a; return ((_a = tx.
|
|
29
|
+
const foundConfirmedTxByNonce = confirmedTxs.find((tx) => { var _a; return ((_a = tx.txParams) === null || _a === void 0 ? void 0 : _a.nonce) === externalTxNonce; });
|
|
30
30
|
if (foundConfirmedTxByNonce) {
|
|
31
31
|
throw eth_rpc_errors_1.ethErrors.rpc.invalidParams('External transaction nonce should not be in confirmed txs');
|
|
32
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-transactions.js","sourceRoot":"","sources":["../src/external-transactions.ts"],"names":[],"mappings":";;;AAAA,oGAAoG;AACpG,mDAA2C;AAE3C,mCAA4C;AAG5C;;;;;;GAMG;AACH,SAAgB,oCAAoC,CAClD,eAAiC,EACjC,YAAgC,EAChC,UAA8B;IAE9B,IAAI,CAAC,eAAe,IAAI,CAAC,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ACH,CAAC;AAvCD,oFAuCC","sourcesContent":["// These utility functions are exclusively used by `confirmExternalTransaction` method in controller\nimport { ethErrors } from 'eth-rpc-errors';\n\nimport { TransactionStatus } from './types';\nimport type { TransactionMeta } from './types';\n\n/**\n * Validates the external provided transaction meta.\n *\n * @param transactionMeta - The transaction meta to validate.\n * @param confirmedTxs - The confirmed transactions in controller state.\n * @param pendingTxs - The submitted transactions in controller state.\n */\nexport function validateConfirmedExternalTransaction(\n transactionMeta?: TransactionMeta,\n confirmedTxs?: TransactionMeta[],\n pendingTxs?: TransactionMeta[],\n) {\n if (!transactionMeta || !transactionMeta.txParams) {\n throw ethErrors.rpc.invalidParams(\n '\"transactionMeta\" or \"transactionMeta.txParams\" is missing',\n );\n }\n\n if (transactionMeta.status !== TransactionStatus.confirmed) {\n throw ethErrors.rpc.invalidParams(\n 'External transaction status should be \"confirmed\"',\n );\n }\n\n const externalTxNonce = transactionMeta.txParams.nonce;\n if (pendingTxs && pendingTxs.length > 0) {\n const foundPendingTxByNonce = pendingTxs.find(\n (tx) => tx.txParams?.nonce === externalTxNonce,\n );\n if (foundPendingTxByNonce) {\n throw ethErrors.rpc.invalidParams(\n 'External transaction nonce should not be in pending txs',\n );\n }\n }\n\n if (confirmedTxs && confirmedTxs.length > 0) {\n const foundConfirmedTxByNonce = confirmedTxs.find(\n (tx) => tx.txParams?.nonce === externalTxNonce,\n );\n if (foundConfirmedTxByNonce) {\n throw ethErrors.rpc.invalidParams(\n 'External transaction nonce should not be in confirmed txs',\n );\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TransactionMeta } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Add initial history snapshot to the provided transactionMeta history.
|
|
4
|
+
*
|
|
5
|
+
* @param transactionMeta - TransactionMeta to add initial history snapshot to.
|
|
6
|
+
*/
|
|
7
|
+
export declare function addInitialHistorySnapshot(transactionMeta: TransactionMeta): void;
|
|
8
|
+
/**
|
|
9
|
+
* Compares and adds history entry to the provided transactionMeta history.
|
|
10
|
+
*
|
|
11
|
+
* @param transactionMeta - TransactionMeta to add history entry to.
|
|
12
|
+
* @param note - Note to add to history entry.
|
|
13
|
+
*/
|
|
14
|
+
export declare function updateTransactionHistory(transactionMeta: TransactionMeta, note: string): void;
|
|
15
|
+
//# sourceMappingURL=history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAGV,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,eAAe,EAAE,eAAe,QAGzE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,eAAe,EAAE,eAAe,EAChC,IAAI,EAAE,MAAM,GACX,IAAI,CAWN"}
|
package/dist/history.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.updateTransactionHistory = exports.addInitialHistorySnapshot = void 0;
|
|
7
|
+
const fast_json_patch_1 = __importDefault(require("fast-json-patch"));
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
9
|
+
/**
|
|
10
|
+
* Add initial history snapshot to the provided transactionMeta history.
|
|
11
|
+
*
|
|
12
|
+
* @param transactionMeta - TransactionMeta to add initial history snapshot to.
|
|
13
|
+
*/
|
|
14
|
+
function addInitialHistorySnapshot(transactionMeta) {
|
|
15
|
+
const snapshot = snapshotFromTransactionMeta(transactionMeta);
|
|
16
|
+
transactionMeta.history = [snapshot];
|
|
17
|
+
}
|
|
18
|
+
exports.addInitialHistorySnapshot = addInitialHistorySnapshot;
|
|
19
|
+
/**
|
|
20
|
+
* Compares and adds history entry to the provided transactionMeta history.
|
|
21
|
+
*
|
|
22
|
+
* @param transactionMeta - TransactionMeta to add history entry to.
|
|
23
|
+
* @param note - Note to add to history entry.
|
|
24
|
+
*/
|
|
25
|
+
function updateTransactionHistory(transactionMeta, note) {
|
|
26
|
+
var _a;
|
|
27
|
+
const currentState = snapshotFromTransactionMeta(transactionMeta);
|
|
28
|
+
const previousState = replayHistory(transactionMeta.history);
|
|
29
|
+
const historyEntry = generateHistoryEntry(previousState, currentState, note);
|
|
30
|
+
if (historyEntry.length) {
|
|
31
|
+
(_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.history) === null || _a === void 0 ? void 0 : _a.push(historyEntry);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.updateTransactionHistory = updateTransactionHistory;
|
|
35
|
+
/**
|
|
36
|
+
* Generates a history entry from the previous and new transaction metadata.
|
|
37
|
+
*
|
|
38
|
+
* @param previousState - The previous transaction metadata.
|
|
39
|
+
* @param currentState - The new transaction metadata.
|
|
40
|
+
* @param note - A note for the transaction metada update.
|
|
41
|
+
* @returns An array of history operation.
|
|
42
|
+
*/
|
|
43
|
+
function generateHistoryEntry(previousState, currentState, note) {
|
|
44
|
+
const historyOperationsEntry = fast_json_patch_1.default.compare(previousState, currentState);
|
|
45
|
+
// Add a note to the first operation, since it breaks if we append it to the entry
|
|
46
|
+
if (historyOperationsEntry[0]) {
|
|
47
|
+
if (note) {
|
|
48
|
+
historyOperationsEntry[0].note = note;
|
|
49
|
+
}
|
|
50
|
+
historyOperationsEntry[0].timestamp = Date.now();
|
|
51
|
+
}
|
|
52
|
+
return historyOperationsEntry;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Recovers previous transactionMeta from passed history array.
|
|
56
|
+
*
|
|
57
|
+
* @param transactionHistory - The transaction metadata to replay.
|
|
58
|
+
* @returns The transaction metadata.
|
|
59
|
+
*/
|
|
60
|
+
function replayHistory(transactionHistory) {
|
|
61
|
+
const shortHistory = (0, lodash_1.cloneDeep)(transactionHistory);
|
|
62
|
+
return shortHistory.reduce((val, entry) => fast_json_patch_1.default.applyPatch(val, entry).newDocument);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Clone the transaction meta data without the history property.
|
|
66
|
+
*
|
|
67
|
+
* @param transactionMeta - The transaction metadata to snapshot.
|
|
68
|
+
* @returns A deep clone of transaction metadata without history property.
|
|
69
|
+
*/
|
|
70
|
+
function snapshotFromTransactionMeta(transactionMeta) {
|
|
71
|
+
const snapshot = Object.assign({}, transactionMeta);
|
|
72
|
+
delete snapshot.history;
|
|
73
|
+
return (0, lodash_1.cloneDeep)(snapshot);
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":";;;;;;AAAA,sEAAyC;AACzC,mCAAmC;AAQnC;;;;GAIG;AACH,SAAgB,yBAAyB,CAAC,eAAgC;IACxE,MAAM,QAAQ,GAAG,2BAA2B,CAAC,eAAe,CAAC,CAAC;IAC9D,eAAe,CAAC,OAAO,GAAG,CAAC,QAAQ,CAAC,CAAC;AACvC,CAAC;AAHD,8DAGC;AAED;;;;;GAKG;AACH,SAAgB,wBAAwB,CACtC,eAAgC,EAChC,IAAY;;IAEZ,MAAM,YAAY,GAAG,2BAA2B,CAAC,eAAe,CAAC,CAAC;IAClE,MAAM,aAAa,GAAG,aAAa,CACjC,eAAe,CAAC,OAA6B,CAC9C,CAAC;IAEF,MAAM,YAAY,GAAG,oBAAoB,CAAC,aAAa,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;IAE7E,IAAI,YAAY,CAAC,MAAM,EAAE;QACvB,MAAA,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,OAAO,0CAAE,IAAI,CAAC,YAAY,CAAC,CAAC;KAC9C;AACH,CAAC;AAdD,4DAcC;AAED;;;;;;;GAOG;AACH,SAAS,oBAAoB,CAC3B,aAAkB,EAClB,YAA6B,EAC7B,IAAY;IAEZ,MAAM,sBAAsB,GAAG,yBAAU,CAAC,OAAO,CAC/C,aAAa,EACb,YAAY,CACc,CAAC;IAC7B,kFAAkF;IAClF,IAAI,sBAAsB,CAAC,CAAC,CAAC,EAAE;QAC7B,IAAI,IAAI,EAAE;YACR,sBAAsB,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC;SACvC;QACD,sBAAsB,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;KAClD;IACD,OAAO,sBAAsB,CAAC;AAChC,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CACpB,kBAAsC;IAEtC,MAAM,YAAY,GAAG,IAAA,kBAAS,EAAC,kBAAkB,CAAC,CAAC;IACnD,OAAO,YAAY,CAAC,MAAM,CACxB,CAAC,GAAG,EAAE,KAAU,EAAE,EAAE,CAAC,yBAAU,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,WAAW,CAChD,CAAC;AACvB,CAAC;AAED;;;;;GAKG;AACH,SAAS,2BAA2B,CAClC,eAAgC;IAEhC,MAAM,QAAQ,qBAAQ,eAAe,CAAE,CAAC;IACxC,OAAO,QAAQ,CAAC,OAAO,CAAC;IACxB,OAAO,IAAA,kBAAS,EAAC,QAAQ,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import jsonDiffer from 'fast-json-patch';\nimport { cloneDeep } from 'lodash';\n\nimport type {\n TransactionHistory,\n TransactionHistoryEntry,\n TransactionMeta,\n} from './types';\n\n/**\n * Add initial history snapshot to the provided transactionMeta history.\n *\n * @param transactionMeta - TransactionMeta to add initial history snapshot to.\n */\nexport function addInitialHistorySnapshot(transactionMeta: TransactionMeta) {\n const snapshot = snapshotFromTransactionMeta(transactionMeta);\n transactionMeta.history = [snapshot];\n}\n\n/**\n * Compares and adds history entry to the provided transactionMeta history.\n *\n * @param transactionMeta - TransactionMeta to add history entry to.\n * @param note - Note to add to history entry.\n */\nexport function updateTransactionHistory(\n transactionMeta: TransactionMeta,\n note: string,\n): void {\n const currentState = snapshotFromTransactionMeta(transactionMeta);\n const previousState = replayHistory(\n transactionMeta.history as TransactionHistory,\n );\n\n const historyEntry = generateHistoryEntry(previousState, currentState, note);\n\n if (historyEntry.length) {\n transactionMeta?.history?.push(historyEntry);\n }\n}\n\n/**\n * Generates a history entry from the previous and new transaction metadata.\n *\n * @param previousState - The previous transaction metadata.\n * @param currentState - The new transaction metadata.\n * @param note - A note for the transaction metada update.\n * @returns An array of history operation.\n */\nfunction generateHistoryEntry(\n previousState: any,\n currentState: TransactionMeta,\n note: string,\n): TransactionHistoryEntry {\n const historyOperationsEntry = jsonDiffer.compare(\n previousState,\n currentState,\n ) as TransactionHistoryEntry;\n // Add a note to the first operation, since it breaks if we append it to the entry\n if (historyOperationsEntry[0]) {\n if (note) {\n historyOperationsEntry[0].note = note;\n }\n historyOperationsEntry[0].timestamp = Date.now();\n }\n return historyOperationsEntry;\n}\n\n/**\n * Recovers previous transactionMeta from passed history array.\n *\n * @param transactionHistory - The transaction metadata to replay.\n * @returns The transaction metadata.\n */\nfunction replayHistory(\n transactionHistory: TransactionHistory,\n): TransactionMeta {\n const shortHistory = cloneDeep(transactionHistory);\n return shortHistory.reduce(\n (val, entry: any) => jsonDiffer.applyPatch(val, entry).newDocument,\n ) as TransactionMeta;\n}\n\n/**\n * Clone the transaction meta data without the history property.\n *\n * @param transactionMeta - The transaction metadata to snapshot.\n * @returns A deep clone of transaction metadata without history property.\n */\nfunction snapshotFromTransactionMeta(\n transactionMeta: TransactionMeta,\n): TransactionMeta {\n const snapshot = { ...transactionMeta };\n delete snapshot.history;\n return cloneDeep(snapshot);\n}\n"]}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="debug" />
|
|
2
|
+
import { createModuleLogger } from '@metamask/utils';
|
|
3
|
+
export declare const projectLogger: import("debug").Debugger;
|
|
4
|
+
export declare const incomingTransactionsLogger: import("debug").Debugger;
|
|
5
|
+
export { createModuleLogger };
|
|
6
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAAA,OAAO,EAAuB,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1E,eAAO,MAAM,aAAa,0BAAgD,CAAC;AAE3E,eAAO,MAAM,0BAA0B,0BAGtC,CAAC;AAEF,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createModuleLogger = exports.incomingTransactionsLogger = exports.projectLogger = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
Object.defineProperty(exports, "createModuleLogger", { enumerable: true, get: function () { return utils_1.createModuleLogger; } });
|
|
6
|
+
exports.projectLogger = (0, utils_1.createProjectLogger)('transaction-controller');
|
|
7
|
+
exports.incomingTransactionsLogger = (0, utils_1.createModuleLogger)(exports.projectLogger, 'incoming-transactions');
|
|
8
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;AAAA,2CAA0E;AASjE,mGATqB,0BAAkB,OASrB;AAPd,QAAA,aAAa,GAAG,IAAA,2BAAmB,EAAC,wBAAwB,CAAC,CAAC;AAE9D,QAAA,0BAA0B,GAAG,IAAA,0BAAkB,EAC1D,qBAAa,EACb,uBAAuB,CACxB,CAAC","sourcesContent":["import { createProjectLogger, createModuleLogger } from '@metamask/utils';\n\nexport const projectLogger = createProjectLogger('transaction-controller');\n\nexport const incomingTransactionsLogger = createModuleLogger(\n projectLogger,\n 'incoming-transactions',\n);\n\nexport { createModuleLogger };\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Hex } from '@metamask/utils';
|
|
2
|
+
import type { Operation } from 'fast-json-patch';
|
|
2
3
|
/**
|
|
3
4
|
* Representation of transaction metadata.
|
|
4
5
|
*/
|
|
@@ -31,11 +32,15 @@ declare type TransactionMetaBase = {
|
|
|
31
32
|
/**
|
|
32
33
|
* Network code as per EIP-155 for this transaction.
|
|
33
34
|
*/
|
|
34
|
-
chainId
|
|
35
|
+
chainId: Hex;
|
|
35
36
|
/**
|
|
36
37
|
* Gas values provided by the dApp.
|
|
37
38
|
*/
|
|
38
39
|
dappSuggestedGasFees?: DappSuggestedGasFees;
|
|
40
|
+
/**
|
|
41
|
+
* The default estimate for gas.
|
|
42
|
+
*/
|
|
43
|
+
defaultGasEstimates?: string;
|
|
39
44
|
/**
|
|
40
45
|
* String to indicate what device the transaction was confirmed on.
|
|
41
46
|
*/
|
|
@@ -44,10 +49,22 @@ declare type TransactionMetaBase = {
|
|
|
44
49
|
* The estimated base fee of the transaction.
|
|
45
50
|
*/
|
|
46
51
|
estimatedBaseFee?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Which estimate level that the API suggested.
|
|
54
|
+
*/
|
|
55
|
+
estimateSuggested?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Which estimate level was used
|
|
58
|
+
*/
|
|
59
|
+
estimateUsed?: string;
|
|
47
60
|
/**
|
|
48
61
|
* A hex string of the transaction hash, used to identify the transaction on the network.
|
|
49
62
|
*/
|
|
50
63
|
hash?: string;
|
|
64
|
+
/**
|
|
65
|
+
* A history of mutations to TransactionMeta.
|
|
66
|
+
*/
|
|
67
|
+
history?: TransactionHistory;
|
|
51
68
|
/**
|
|
52
69
|
* Generated UUID associated with this transaction.
|
|
53
70
|
*/
|
|
@@ -57,9 +74,11 @@ declare type TransactionMetaBase = {
|
|
|
57
74
|
*/
|
|
58
75
|
isTransfer?: boolean;
|
|
59
76
|
/**
|
|
60
|
-
* Network code as per EIP-155 for this transaction
|
|
77
|
+
* Network code as per EIP-155 for this transaction
|
|
78
|
+
*
|
|
79
|
+
* @deprecated Use `chainId` instead.
|
|
61
80
|
*/
|
|
62
|
-
networkID?: string;
|
|
81
|
+
readonly networkID?: string;
|
|
63
82
|
/**
|
|
64
83
|
* Origin this transaction was sent from.
|
|
65
84
|
*/
|
|
@@ -68,6 +87,10 @@ declare type TransactionMetaBase = {
|
|
|
68
87
|
* The original gas estimation of the transaction.
|
|
69
88
|
*/
|
|
70
89
|
originalGasEstimate?: string;
|
|
90
|
+
/**
|
|
91
|
+
* The transaction's 'r' value as a hex string.
|
|
92
|
+
*/
|
|
93
|
+
r?: string;
|
|
71
94
|
/**
|
|
72
95
|
* Hex representation of the underlying transaction.
|
|
73
96
|
*/
|
|
@@ -80,6 +103,19 @@ declare type TransactionMetaBase = {
|
|
|
80
103
|
* When the transaction is dropped, this is the replacement transaction ID.
|
|
81
104
|
*/
|
|
82
105
|
replacedById?: string;
|
|
106
|
+
/**
|
|
107
|
+
* The transaction's 's' value as a hex string.
|
|
108
|
+
*/
|
|
109
|
+
s?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Response from security validator.
|
|
112
|
+
*/
|
|
113
|
+
securityAlertResponse?: Record<string, unknown>;
|
|
114
|
+
/**
|
|
115
|
+
* An array of entries that describe the user's journey through the send flow.
|
|
116
|
+
* This is purely attached to state logs for troubleshooting and support.
|
|
117
|
+
*/
|
|
118
|
+
sendFlowHistory?: SendFlowHistoryEntry[];
|
|
83
119
|
/**
|
|
84
120
|
* The time the transaction was submitted to the network, in Unix epoch time (ms).
|
|
85
121
|
*/
|
|
@@ -92,10 +128,6 @@ declare type TransactionMetaBase = {
|
|
|
92
128
|
* Whether transaction recipient is a smart contract.
|
|
93
129
|
*/
|
|
94
130
|
toSmartContract?: boolean;
|
|
95
|
-
/**
|
|
96
|
-
* Underlying Transaction object.
|
|
97
|
-
*/
|
|
98
|
-
transaction: Transaction;
|
|
99
131
|
/**
|
|
100
132
|
* Additional transfer information.
|
|
101
133
|
*/
|
|
@@ -104,18 +136,40 @@ declare type TransactionMetaBase = {
|
|
|
104
136
|
decimals: number;
|
|
105
137
|
symbol: string;
|
|
106
138
|
};
|
|
139
|
+
/**
|
|
140
|
+
* Underlying Transaction object.
|
|
141
|
+
*/
|
|
142
|
+
txParams: TransactionParams;
|
|
107
143
|
/**
|
|
108
144
|
* Transaction receipt.
|
|
109
145
|
*/
|
|
110
146
|
txReceipt?: TransactionReceipt;
|
|
147
|
+
/**
|
|
148
|
+
* The transaction's 'v' value as a hex string.
|
|
149
|
+
*/
|
|
150
|
+
v?: string;
|
|
151
|
+
/**
|
|
152
|
+
* The gas limit supplied by user.
|
|
153
|
+
*/
|
|
154
|
+
userEditedGasLimit?: boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Estimate level user selected.
|
|
157
|
+
*/
|
|
158
|
+
userFeeLevel?: string;
|
|
111
159
|
/**
|
|
112
160
|
* Whether the transaction is verified on the blockchain.
|
|
113
161
|
*/
|
|
114
162
|
verifiedOnBlockchain?: boolean;
|
|
163
|
+
};
|
|
164
|
+
export declare type SendFlowHistoryEntry = {
|
|
115
165
|
/**
|
|
116
|
-
*
|
|
166
|
+
* String to indicate user interaction information.
|
|
117
167
|
*/
|
|
118
|
-
|
|
168
|
+
entry: string;
|
|
169
|
+
/**
|
|
170
|
+
* Timestamp associated with this entry.
|
|
171
|
+
*/
|
|
172
|
+
timestamp: number;
|
|
119
173
|
};
|
|
120
174
|
/**
|
|
121
175
|
* The status of the transaction. Each status represents the state of the transaction internally
|
|
@@ -144,7 +198,7 @@ export declare enum WalletDevice {
|
|
|
144
198
|
/**
|
|
145
199
|
* Standard data concerning a transaction to be processed by the blockchain.
|
|
146
200
|
*/
|
|
147
|
-
export interface
|
|
201
|
+
export interface TransactionParams {
|
|
148
202
|
/**
|
|
149
203
|
* Network ID as per EIP-155.
|
|
150
204
|
*/
|
|
@@ -166,11 +220,15 @@ export interface Transaction {
|
|
|
166
220
|
*/
|
|
167
221
|
from: string;
|
|
168
222
|
/**
|
|
169
|
-
*
|
|
223
|
+
* same as gasLimit?
|
|
170
224
|
*/
|
|
171
225
|
gas?: string;
|
|
172
226
|
/**
|
|
173
|
-
*
|
|
227
|
+
* Maxmimum number of units of gas to use for this transaction.
|
|
228
|
+
*/
|
|
229
|
+
gasLimit?: string;
|
|
230
|
+
/**
|
|
231
|
+
* Price per gas for legacy txs
|
|
174
232
|
*/
|
|
175
233
|
gasPrice?: string;
|
|
176
234
|
/**
|
|
@@ -178,11 +236,12 @@ export interface Transaction {
|
|
|
178
236
|
*/
|
|
179
237
|
gasUsed?: string;
|
|
180
238
|
/**
|
|
181
|
-
* Maximum
|
|
239
|
+
* Maximum amount per gas to pay for the transaction, including the priority
|
|
240
|
+
* fee.
|
|
182
241
|
*/
|
|
183
242
|
maxFeePerGas?: string;
|
|
184
243
|
/**
|
|
185
|
-
* Maximum
|
|
244
|
+
* Maximum amount per gas to give to validator as incentive.
|
|
186
245
|
*/
|
|
187
246
|
maxPriorityFeePerGas?: string;
|
|
188
247
|
/**
|
|
@@ -256,18 +315,10 @@ export interface RemoteTransactionSourceRequest {
|
|
|
256
315
|
* The address of the account to fetch transactions for.
|
|
257
316
|
*/
|
|
258
317
|
address: string;
|
|
259
|
-
/**
|
|
260
|
-
* API key if required by the remote source.
|
|
261
|
-
*/
|
|
262
|
-
apiKey?: string;
|
|
263
318
|
/**
|
|
264
319
|
* The chainId of the current network.
|
|
265
320
|
*/
|
|
266
321
|
currentChainId: Hex;
|
|
267
|
-
/**
|
|
268
|
-
* The networkId of the current network.
|
|
269
|
-
*/
|
|
270
|
-
currentNetworkId: string;
|
|
271
322
|
/**
|
|
272
323
|
* Block number to start fetching transactions from.
|
|
273
324
|
*/
|
|
@@ -282,7 +333,19 @@ export interface RemoteTransactionSourceRequest {
|
|
|
282
333
|
* Used by the IncomingTransactionHelper to retrieve remote transaction data.
|
|
283
334
|
*/
|
|
284
335
|
export interface RemoteTransactionSource {
|
|
285
|
-
|
|
336
|
+
/**
|
|
337
|
+
* @param chainId - The chainId of the current network.
|
|
338
|
+
* @returns Whether the remote transaction source supports the specified network.
|
|
339
|
+
*/
|
|
340
|
+
isSupportedNetwork: (chainId: Hex) => boolean;
|
|
341
|
+
/**
|
|
342
|
+
* @returns An array of additional keys to use when caching the last fetched block number.
|
|
343
|
+
*/
|
|
344
|
+
getLastBlockVariations?: () => string[];
|
|
345
|
+
/**
|
|
346
|
+
* @param request - A request object containing data such as the address and chain ID.
|
|
347
|
+
* @returns An array of transaction metadata for the retrieved transactions.
|
|
348
|
+
*/
|
|
286
349
|
fetchTransactions: (request: RemoteTransactionSourceRequest) => Promise<TransactionMeta[]>;
|
|
287
350
|
}
|
|
288
351
|
/**
|
|
@@ -294,5 +357,27 @@ export interface DappSuggestedGasFees {
|
|
|
294
357
|
maxFeePerGas?: string;
|
|
295
358
|
maxPriorityFeePerGas?: string;
|
|
296
359
|
}
|
|
360
|
+
/**
|
|
361
|
+
* A transaction history operation that includes a note and timestamp.
|
|
362
|
+
*/
|
|
363
|
+
declare type ExtendedHistoryOperation = Operation & {
|
|
364
|
+
note?: string;
|
|
365
|
+
timestamp?: number;
|
|
366
|
+
};
|
|
367
|
+
/**
|
|
368
|
+
* A transaction history entry that includes the ExtendedHistoryOperation as the first element.
|
|
369
|
+
*/
|
|
370
|
+
export declare type TransactionHistoryEntry = [
|
|
371
|
+
ExtendedHistoryOperation,
|
|
372
|
+
...Operation[]
|
|
373
|
+
];
|
|
374
|
+
/**
|
|
375
|
+
* A transaction history that includes the transaction meta as the first element.
|
|
376
|
+
* And the rest of the elements are the operation arrays that were applied to the transaction meta.
|
|
377
|
+
*/
|
|
378
|
+
export declare type TransactionHistory = [
|
|
379
|
+
TransactionMeta,
|
|
380
|
+
...TransactionHistoryEntry[]
|
|
381
|
+
];
|
|
297
382
|
export {};
|
|
298
383
|
//# sourceMappingURL=types.d.ts.map
|