four-flap-meme-sdk 1.3.13 → 1.3.14
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.
|
@@ -38,8 +38,8 @@ export declare class NonceManager {
|
|
|
38
38
|
*/
|
|
39
39
|
getTempCachedNonce(address: string): number | undefined;
|
|
40
40
|
/**
|
|
41
|
-
* ✅ 批量获取多个不同地址的 nonce
|
|
42
|
-
*
|
|
41
|
+
* ✅ 批量获取多个不同地址的 nonce(真正的单次 JSON-RPC 批量请求)
|
|
42
|
+
* 使用 provider.send 发送批量请求,N 个地址只需 1 次网络往返
|
|
43
43
|
* @param wallets 钱包数组
|
|
44
44
|
* @returns nonce 数组(顺序与 wallets 对应)
|
|
45
45
|
*/
|
|
@@ -72,8 +72,8 @@ export class NonceManager {
|
|
|
72
72
|
return this.tempNonceCache.get(address.toLowerCase());
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
|
-
* ✅ 批量获取多个不同地址的 nonce
|
|
76
|
-
*
|
|
75
|
+
* ✅ 批量获取多个不同地址的 nonce(真正的单次 JSON-RPC 批量请求)
|
|
76
|
+
* 使用 provider.send 发送批量请求,N 个地址只需 1 次网络往返
|
|
77
77
|
* @param wallets 钱包数组
|
|
78
78
|
* @returns nonce 数组(顺序与 wallets 对应)
|
|
79
79
|
*/
|
|
@@ -94,11 +94,32 @@ export class NonceManager {
|
|
|
94
94
|
needQuery.push({ index: i, address: addresses[i] });
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
//
|
|
97
|
+
// 如果有需要查询的地址,使用真正的 JSON-RPC 批量请求
|
|
98
98
|
if (needQuery.length > 0) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
let queryResults;
|
|
100
|
+
try {
|
|
101
|
+
// ✅ 使用 JSON-RPC 批量请求(单次网络往返)
|
|
102
|
+
const batchRequests = needQuery.map(({ address }, idx) => ({
|
|
103
|
+
method: 'eth_getTransactionCount',
|
|
104
|
+
params: [address, 'latest'],
|
|
105
|
+
id: idx + 1,
|
|
106
|
+
jsonrpc: '2.0'
|
|
107
|
+
}));
|
|
108
|
+
// 通过 provider._send 发送批量请求(ethers v6 内部方法)
|
|
109
|
+
const rawResults = await this.provider._send(batchRequests);
|
|
110
|
+
// 解析结果
|
|
111
|
+
queryResults = rawResults.map((r) => {
|
|
112
|
+
if (r.result) {
|
|
113
|
+
return parseInt(r.result, 16);
|
|
114
|
+
}
|
|
115
|
+
return 0;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// 如果批量请求失败,回退到 Promise.all
|
|
120
|
+
const queryPromises = needQuery.map(({ address }) => this.provider.getTransactionCount(address, 'latest'));
|
|
121
|
+
queryResults = await Promise.all(queryPromises);
|
|
122
|
+
}
|
|
102
123
|
// 填充结果并更新缓存
|
|
103
124
|
for (let i = 0; i < needQuery.length; i++) {
|
|
104
125
|
const { index, address } = needQuery[i];
|