From f51183f2c748a66f44feb49541614a8ed254554c Mon Sep 17 00:00:00 2001 From: tornadocontrib Date: Tue, 8 Oct 2024 14:00:50 +0000 Subject: [PATCH] Improve relayer client --- dist/cli.js | 46 ++++++++++++++++++++++++++-------------------- package.json | 2 +- src/program.ts | 2 +- yarn.lock | 4 ++-- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/dist/cli.js b/dist/cli.js index 396df28..6ce7678 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -178695,19 +178695,19 @@ class TornadoBrowserProvider extends BrowserProvider { } getSigner(address) { return __async$g(this, null, function* () { - var _a, _b, _c, _d, _e, _f, _g, _h, _i; + var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j; const signerAddress = (yield __superGet$2(TornadoBrowserProvider.prototype, this, "getSigner").call(this, address)).address; - if (((_a = this.options) == null ? void 0 : _a.webChainId) && ((_b = this.options) == null ? void 0 : _b.connectWallet) && Number(yield __superGet$2(TornadoBrowserProvider.prototype, this, "send").call(this, "eth_chainId", [])) !== Number((_c = this.options) == null ? void 0 : _c.webChainId)) { - yield this.options.connectWallet(); + if (((_a = this.options) == null ? void 0 : _a.netId) && ((_b = this.options) == null ? void 0 : _b.connectWallet) && Number(yield __superGet$2(TornadoBrowserProvider.prototype, this, "send").call(this, "net_version", [])) !== ((_c = this.options) == null ? void 0 : _c.netId)) { + yield this.options.connectWallet((_d = this.options) == null ? void 0 : _d.netId); } - if ((_d = this.options) == null ? void 0 : _d.handleNetworkChanges) { - (_e = window == null ? void 0 : window.ethereum) == null ? void 0 : _e.on("chainChanged", this.options.handleNetworkChanges); + if ((_e = this.options) == null ? void 0 : _e.handleNetworkChanges) { + (_f = window == null ? void 0 : window.ethereum) == null ? void 0 : _f.on("chainChanged", this.options.handleNetworkChanges); } - if ((_f = this.options) == null ? void 0 : _f.handleAccountChanges) { - (_g = window == null ? void 0 : window.ethereum) == null ? void 0 : _g.on("accountsChanged", this.options.handleAccountChanges); + if ((_g = this.options) == null ? void 0 : _g.handleAccountChanges) { + (_h = window == null ? void 0 : window.ethereum) == null ? void 0 : _h.on("accountsChanged", this.options.handleAccountChanges); } - if ((_h = this.options) == null ? void 0 : _h.handleAccountDisconnect) { - (_i = window == null ? void 0 : window.ethereum) == null ? void 0 : _i.on("disconnect", this.options.handleAccountDisconnect); + if ((_i = this.options) == null ? void 0 : _i.handleAccountDisconnect) { + (_j = window == null ? void 0 : window.ethereum) == null ? void 0 : _j.on("disconnect", this.options.handleAccountDisconnect); } return new TornadoRpcSigner(this, signerAddress, this.options); }); @@ -181023,7 +181023,7 @@ class RelayerClient { url, relayerAddress }) { - var _a, _b; + var _a; if (!url && hostname) { url = `https://${!hostname.endsWith("/") ? hostname + "/" : hostname}`; } else if (url && !url.endsWith("/")) { @@ -181035,8 +181035,8 @@ class RelayerClient { headers: { "Content-Type": "application/json, application/x-www-form-urlencoded" }, - timeout: ((_a = this.fetchDataOptions) == null ? void 0 : _a.torPort) ? 1e4 : 3e3, - maxRetry: ((_b = this.fetchDataOptions) == null ? void 0 : _b.torPort) ? 2 : 0 + timeout: 6e4, + maxRetry: ((_a = this.fetchDataOptions) == null ? void 0 : _a.torPort) ? 2 : 0 })); const statusValidator = dist_ajv.compile(getStatusSchema(this.netId, this.config, this.tovarish)); if (!statusValidator(rawStatus)) { @@ -181803,14 +181803,14 @@ function getTovarishNetworks(registryService, relayers) { return __async$c(this, null, function* () { yield Promise.all( relayers.filter((r) => r.tovarishHost).map((relayer) => __async$c(this, null, function* () { - var _a, _b; + var _a; try { relayer.tovarishNetworks = yield fetchData(relayer.tovarishHost, __spreadProps$1(__spreadValues$2({}, registryService.fetchDataOptions), { headers: { "Content-Type": "application/json" }, - timeout: ((_a = registryService.fetchDataOptions) == null ? void 0 : _a.torPort) ? 1e4 : 3e3, - maxRetry: ((_b = registryService.fetchDataOptions) == null ? void 0 : _b.torPort) ? 2 : 0 + timeout: 6e4, + maxRetry: ((_a = registryService.fetchDataOptions) == null ? void 0 : _a.torPort) ? 2 : 0 })); } catch (e) { relayer.tovarishNetworks = []; @@ -181964,10 +181964,13 @@ class BaseRegistryService extends BaseEventsService { } }).filter((r) => r); yield getTovarishNetworks(this, relayers); + const allRelayers = [...staticRelayers, ...relayers]; + const tovarishRelayers = allRelayers.filter((r) => r.tovarishHost); + const classicRelayers = allRelayers.filter((r) => !r.tovarishHost); return { lastBlock, timestamp, - relayers: [...staticRelayers, ...relayers] + relayers: [...tovarishRelayers, ...classicRelayers] }; }); } @@ -182149,14 +182152,16 @@ function loadRemoteEvents(_0) { return __async$a(this, arguments, function* ({ staticUrl, instanceName, - deployedBlock + deployedBlock, + zipDigest }) { var _a; try { const zipName = `${instanceName}.json`.toLowerCase(); const events = yield downloadZip({ staticUrl, - zipName + zipName, + zipDigest }); if (!Array.isArray(events)) { const errStr = `Invalid events from ${staticUrl}/${zipName}`; @@ -182197,7 +182202,8 @@ class DBTornadoService extends BaseTornadoService { return yield loadRemoteEvents({ staticUrl: this.staticUrl, instanceName: this.getInstanceName(), - deployedBlock: this.deployedBlock + deployedBlock: this.deployedBlock, + zipDigest: this.zipDigest }); }); } @@ -187965,7 +187971,7 @@ Connected with Tovarish Relayer ${(_a = tovarishClient.selectedRelayer) == null root: tree.root, nullifierHex, recipient, - relayer: !walletWithdrawal ? rewardAccount : ZeroAddress, + relayer: relayer2, fee: fee2, refund: refund2, nullifier, diff --git a/package.json b/package.json index 26be788..e9c4c11 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "optionalDependencies": {}, "devDependencies": { "@colors/colors": "^1.6.0", - "@tornado/core": "git+https://git.tornado.ws/tornadocontrib/tornado-core.git#58b31101259245dad8ac6152829ca7bc7ac7f091", + "@tornado/core": "git+https://git.tornado.ws/tornadocontrib/tornado-core.git#0ebd4d175f4a7f8f0f339091cbec4dc4a7e8ad3a", "@typechain/ethers-v6": "^0.5.1", "@types/figlet": "^1.5.8", "@typescript-eslint/eslint-plugin": "^8.7.0", diff --git a/src/program.ts b/src/program.ts index d608314..341b7c1 100644 --- a/src/program.ts +++ b/src/program.ts @@ -1170,7 +1170,7 @@ export function tornadoProgram() { root: tree.root, nullifierHex, recipient, - relayer: !walletWithdrawal ? (rewardAccount as string) : ZeroAddress, + relayer, fee, refund, nullifier, diff --git a/yarn.lock b/yarn.lock index 61453de..08deb6b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -786,9 +786,9 @@ "@openzeppelin/contracts-v3" "npm:@openzeppelin/contracts@3.2.0-rc.0" ethers "^6.4.0" -"@tornado/core@git+https://git.tornado.ws/tornadocontrib/tornado-core.git#58b31101259245dad8ac6152829ca7bc7ac7f091": +"@tornado/core@git+https://git.tornado.ws/tornadocontrib/tornado-core.git#0ebd4d175f4a7f8f0f339091cbec4dc4a7e8ad3a": version "1.0.19" - resolved "git+https://git.tornado.ws/tornadocontrib/tornado-core.git#58b31101259245dad8ac6152829ca7bc7ac7f091" + resolved "git+https://git.tornado.ws/tornadocontrib/tornado-core.git#0ebd4d175f4a7f8f0f339091cbec4dc4a7e8ad3a" dependencies: "@metamask/eth-sig-util" "^7.0.3" "@tornado/contracts" "^1.0.1"