hermes-swap 0.6.0 → 0.6.1
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/cjs/aggregator.cjs +29 -3
- package/dist/esm/aggregator.mjs +57 -12
- package/package.json +1 -1
package/dist/cjs/aggregator.cjs
CHANGED
|
@@ -897,7 +897,7 @@ var _Aggregator = class {
|
|
|
897
897
|
() => _Aggregator.traceLog(chain, "log", `广播${label} OK, txHash=${txHash}, 耗时=${Date.now() - sendTs}ms`),
|
|
898
898
|
(err) => {
|
|
899
899
|
const msg = (err == null ? void 0 : err.message) ?? String(err);
|
|
900
|
-
if (msg.includes("already known") || msg.includes("nonce too low") || msg.includes("ALREADY_EXISTS")) {
|
|
900
|
+
if (msg.includes("already known") || msg.includes("nonce too low") || msg.includes("ALREADY_EXISTS") || msg.includes("nonce has already been used")) {
|
|
901
901
|
_Aggregator.traceLog(chain, "log", `广播${label} already known, txHash=${txHash}, 耗时=${Date.now() - sendTs}ms`);
|
|
902
902
|
} else {
|
|
903
903
|
_Aggregator.traceLog(chain, "warn", `广播${label} 失败: ${msg}, txHash=${txHash}, 耗时=${Date.now() - sendTs}ms`);
|
|
@@ -907,8 +907,34 @@ var _Aggregator = class {
|
|
|
907
907
|
};
|
|
908
908
|
const mainSendTs = Date.now();
|
|
909
909
|
extraUrls.forEach((url, i) => broadcastToExtra(url, i));
|
|
910
|
-
|
|
911
|
-
|
|
910
|
+
let txResponse;
|
|
911
|
+
try {
|
|
912
|
+
txResponse = await provider.broadcastTransaction(signedTx);
|
|
913
|
+
_Aggregator.traceLog(chain, "log", `广播主RPC已发送, txHash=${txHash}, 耗时=${Date.now() - mainSendTs}ms`);
|
|
914
|
+
} catch (err) {
|
|
915
|
+
const msg = (err == null ? void 0 : err.message) ?? String(err);
|
|
916
|
+
if (msg.includes("already known") || msg.includes("nonce too low") || msg.includes("ALREADY_EXISTS") || msg.includes("nonce has already been used")) {
|
|
917
|
+
_Aggregator.traceLog(chain, "log", `广播主RPC already known (可能额外RPC已上链), txHash=${txHash}, 耗时=${Date.now() - mainSendTs}ms, 开始轮询receipt`);
|
|
918
|
+
const existingReceipt = await provider.getTransactionReceipt(txHash);
|
|
919
|
+
if (existingReceipt) {
|
|
920
|
+
_Aggregator.traceLog(chain, "log", `交易已上链, txHash=${txHash}, blockNumber=${existingReceipt.blockNumber}`);
|
|
921
|
+
const blockTs2 = await this.getBlockTimestampStr(provider, existingReceipt.blockNumber);
|
|
922
|
+
_Aggregator.traceLog(
|
|
923
|
+
chain,
|
|
924
|
+
"log",
|
|
925
|
+
`多RPC广播上链确认, txHash=${existingReceipt.hash}, blockNumber=${existingReceipt.blockNumber}, 出块时间=${blockTs2}, gasUsed=${existingReceipt.gasUsed}, 总耗时=${Date.now() - mainSendTs}ms`
|
|
926
|
+
);
|
|
927
|
+
return existingReceipt;
|
|
928
|
+
}
|
|
929
|
+
txResponse = await provider.getTransaction(txHash);
|
|
930
|
+
if (!txResponse) {
|
|
931
|
+
throw new Error(`Transaction not found after broadcast error: ${txHash}`);
|
|
932
|
+
}
|
|
933
|
+
} else {
|
|
934
|
+
_Aggregator.traceLog(chain, "error", `广播主RPC失败: ${msg}, txHash=${txHash}, 耗时=${Date.now() - mainSendTs}ms`);
|
|
935
|
+
throw err;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
912
938
|
const receipt = await txResponse.wait();
|
|
913
939
|
if (!receipt)
|
|
914
940
|
throw new Error(`Transaction receipt is null: ${txHash}`);
|
package/dist/esm/aggregator.mjs
CHANGED
|
@@ -1818,7 +1818,7 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
1818
1818
|
value: function () {
|
|
1819
1819
|
var _sendContractTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(chain, contract, method, args, txReq) {
|
|
1820
1820
|
var _method;
|
|
1821
|
-
var extraUrls, _ref5, sendTs, _txResponse, _receipt, singleProvider, _blockTs, wallet, populated, network, signedTx, txHash, provider, currentBlock, broadcastToExtra, mainSendTs, txResponse, receipt, blockTs;
|
|
1821
|
+
var extraUrls, _ref5, sendTs, _txResponse, _receipt, singleProvider, _blockTs, wallet, populated, network, signedTx, txHash, provider, currentBlock, broadcastToExtra, mainSendTs, txResponse, _err$message2, msg, existingReceipt, _blockTs2, receipt, blockTs;
|
|
1822
1822
|
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1823
1823
|
while (1) switch (_context16.prev = _context16.next) {
|
|
1824
1824
|
case 0:
|
|
@@ -1877,7 +1877,7 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
1877
1877
|
}, function (err) {
|
|
1878
1878
|
var _err$message;
|
|
1879
1879
|
var msg = (_err$message = err === null || err === void 0 ? void 0 : err.message) !== null && _err$message !== void 0 ? _err$message : String(err);
|
|
1880
|
-
if (msg.includes('already known') || msg.includes('nonce too low') || msg.includes('ALREADY_EXISTS')) {
|
|
1880
|
+
if (msg.includes('already known') || msg.includes('nonce too low') || msg.includes('ALREADY_EXISTS') || msg.includes('nonce has already been used')) {
|
|
1881
1881
|
Aggregator.traceLog(chain, 'log', "\u5E7F\u64AD".concat(label, " already known, txHash=").concat(txHash, ", \u8017\u65F6=").concat(Date.now() - sendTs, "ms"));
|
|
1882
1882
|
} else {
|
|
1883
1883
|
Aggregator.traceLog(chain, 'warn', "\u5E7F\u64AD".concat(label, " \u5931\u8D25: ").concat(msg, ", txHash=").concat(txHash, ", \u8017\u65F6=").concat(Date.now() - sendTs, "ms"));
|
|
@@ -1888,32 +1888,77 @@ var Aggregator = /*#__PURE__*/function () {
|
|
|
1888
1888
|
extraUrls.forEach(function (url, i) {
|
|
1889
1889
|
return broadcastToExtra(url, i);
|
|
1890
1890
|
});
|
|
1891
|
-
_context16.
|
|
1891
|
+
_context16.prev = 38;
|
|
1892
|
+
_context16.next = 41;
|
|
1892
1893
|
return provider.broadcastTransaction(signedTx);
|
|
1893
|
-
case
|
|
1894
|
+
case 41:
|
|
1894
1895
|
txResponse = _context16.sent;
|
|
1895
1896
|
Aggregator.traceLog(chain, 'log', "\u5E7F\u64AD\u4E3BRPC\u5DF2\u53D1\u9001, txHash=".concat(txHash, ", \u8017\u65F6=").concat(Date.now() - mainSendTs, "ms"));
|
|
1896
|
-
_context16.next =
|
|
1897
|
+
_context16.next = 69;
|
|
1898
|
+
break;
|
|
1899
|
+
case 45:
|
|
1900
|
+
_context16.prev = 45;
|
|
1901
|
+
_context16.t0 = _context16["catch"](38);
|
|
1902
|
+
msg = (_err$message2 = _context16.t0 === null || _context16.t0 === void 0 ? void 0 : _context16.t0.message) !== null && _err$message2 !== void 0 ? _err$message2 : String(_context16.t0);
|
|
1903
|
+
if (!(msg.includes('already known') || msg.includes('nonce too low') || msg.includes('ALREADY_EXISTS') || msg.includes('nonce has already been used'))) {
|
|
1904
|
+
_context16.next = 67;
|
|
1905
|
+
break;
|
|
1906
|
+
}
|
|
1907
|
+
Aggregator.traceLog(chain, 'log', "\u5E7F\u64AD\u4E3BRPC already known (\u53EF\u80FD\u989D\u5916RPC\u5DF2\u4E0A\u94FE), txHash=".concat(txHash, ", \u8017\u65F6=").concat(Date.now() - mainSendTs, "ms, \u5F00\u59CB\u8F6E\u8BE2receipt"));
|
|
1908
|
+
// 先尝试直接获取 receipt,如果交易已上链
|
|
1909
|
+
_context16.next = 52;
|
|
1910
|
+
return provider.getTransactionReceipt(txHash);
|
|
1911
|
+
case 52:
|
|
1912
|
+
existingReceipt = _context16.sent;
|
|
1913
|
+
if (!existingReceipt) {
|
|
1914
|
+
_context16.next = 60;
|
|
1915
|
+
break;
|
|
1916
|
+
}
|
|
1917
|
+
Aggregator.traceLog(chain, 'log', "\u4EA4\u6613\u5DF2\u4E0A\u94FE, txHash=".concat(txHash, ", blockNumber=").concat(existingReceipt.blockNumber));
|
|
1918
|
+
_context16.next = 57;
|
|
1919
|
+
return this.getBlockTimestampStr(provider, existingReceipt.blockNumber);
|
|
1920
|
+
case 57:
|
|
1921
|
+
_blockTs2 = _context16.sent;
|
|
1922
|
+
Aggregator.traceLog(chain, 'log', "\u591ARPC\u5E7F\u64AD\u4E0A\u94FE\u786E\u8BA4, txHash=".concat(existingReceipt.hash, ", blockNumber=").concat(existingReceipt.blockNumber, ", \u51FA\u5757\u65F6\u95F4=").concat(_blockTs2, ", gasUsed=").concat(existingReceipt.gasUsed, ", ") + "\u603B\u8017\u65F6=".concat(Date.now() - mainSendTs, "ms"));
|
|
1923
|
+
return _context16.abrupt("return", existingReceipt);
|
|
1924
|
+
case 60:
|
|
1925
|
+
_context16.next = 62;
|
|
1926
|
+
return provider.getTransaction(txHash);
|
|
1927
|
+
case 62:
|
|
1928
|
+
txResponse = _context16.sent;
|
|
1929
|
+
if (txResponse) {
|
|
1930
|
+
_context16.next = 65;
|
|
1931
|
+
break;
|
|
1932
|
+
}
|
|
1933
|
+
throw new Error("Transaction not found after broadcast error: ".concat(txHash));
|
|
1934
|
+
case 65:
|
|
1935
|
+
_context16.next = 69;
|
|
1936
|
+
break;
|
|
1937
|
+
case 67:
|
|
1938
|
+
Aggregator.traceLog(chain, 'error', "\u5E7F\u64AD\u4E3BRPC\u5931\u8D25: ".concat(msg, ", txHash=").concat(txHash, ", \u8017\u65F6=").concat(Date.now() - mainSendTs, "ms"));
|
|
1939
|
+
throw _context16.t0;
|
|
1940
|
+
case 69:
|
|
1941
|
+
_context16.next = 71;
|
|
1897
1942
|
return txResponse.wait();
|
|
1898
|
-
case
|
|
1943
|
+
case 71:
|
|
1899
1944
|
receipt = _context16.sent;
|
|
1900
1945
|
if (receipt) {
|
|
1901
|
-
_context16.next =
|
|
1946
|
+
_context16.next = 74;
|
|
1902
1947
|
break;
|
|
1903
1948
|
}
|
|
1904
1949
|
throw new Error("Transaction receipt is null: ".concat(txHash));
|
|
1905
|
-
case
|
|
1906
|
-
_context16.next =
|
|
1950
|
+
case 74:
|
|
1951
|
+
_context16.next = 76;
|
|
1907
1952
|
return this.getBlockTimestampStr(provider, receipt.blockNumber);
|
|
1908
|
-
case
|
|
1953
|
+
case 76:
|
|
1909
1954
|
blockTs = _context16.sent;
|
|
1910
1955
|
Aggregator.traceLog(chain, 'log', "\u591ARPC\u5E7F\u64AD\u4E0A\u94FE\u786E\u8BA4, txHash=".concat(receipt.hash, ", blockNumber=").concat(receipt.blockNumber, ", \u51FA\u5757\u65F6\u95F4=").concat(blockTs, ", gasUsed=").concat(receipt.gasUsed, ", ") + "\u603B\u8017\u65F6=".concat(Date.now() - mainSendTs, "ms"));
|
|
1911
1956
|
return _context16.abrupt("return", receipt);
|
|
1912
|
-
case
|
|
1957
|
+
case 79:
|
|
1913
1958
|
case "end":
|
|
1914
1959
|
return _context16.stop();
|
|
1915
1960
|
}
|
|
1916
|
-
}, _callee16, this);
|
|
1961
|
+
}, _callee16, this, [[38, 45]]);
|
|
1917
1962
|
}));
|
|
1918
1963
|
function sendContractTx(_x31, _x32, _x33, _x34, _x35) {
|
|
1919
1964
|
return _sendContractTx.apply(this, arguments);
|