From 03886a418b5055b3fe097cad05ab879a42af7b8d Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 24 Jun 2024 23:30:46 -0700 Subject: [PATCH] Solana and EVM - Support lightMode flag from core --- CHANGELOG.md | 2 ++ package.json | 2 +- src/ethereum/EthereumEngine.ts | 2 ++ src/ethereum/EthereumNetwork.ts | 26 +++++++++++++++++++------- src/solana/SolanaEngine.ts | 17 +++++++++++++---- yarn.lock | 8 ++++---- 6 files changed, 41 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b0008e74..a87374643 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,11 @@ ## Unreleased +- added: (Solana/Ethereum) Add optional `lightMode` support to disable transaction query - added: Add optional `testPrivateKeys` function to `parseUriCommon` - changed: (Zcash) Updated address explorer - changed: (Tron) Special case the `usdt-trc20` uri prefix +- changed: Upgrade edge-core-js to v2.9.0 - fixed: Prevent fatal error reporting for missing txlist json file - fixed: (Zcash) Use additional insufficient funds check before sending amount to synchronizer diff --git a/package.json b/package.json index 2e3479b8a..baae2b246 100644 --- a/package.json +++ b/package.json @@ -135,7 +135,7 @@ "chai": "^4.2.0", "clipanion": "^4.0.0-rc.2", "crypto-browserify": "^3.12.0", - "edge-core-js": "^2.5.0", + "edge-core-js": "^2.9.0", "esbuild-loader": "^2.20.0", "eslint": "^8.19.0", "eslint-config-standard-kit": "0.15.1", diff --git a/src/ethereum/EthereumEngine.ts b/src/ethereum/EthereumEngine.ts index 397f187af..fb654ef51 100644 --- a/src/ethereum/EthereumEngine.ts +++ b/src/ethereum/EthereumEngine.ts @@ -95,6 +95,7 @@ export class EthereumEngine extends CurrencyEngine< SafeEthWalletInfo > { otherData!: EthereumWalletOtherData + lightMode: boolean initOptions: EthereumInitOptions networkInfo: EthereumNetworkInfo ethNetwork: EthereumNetwork @@ -113,6 +114,7 @@ export class EthereumEngine extends CurrencyEngine< currencyInfo: EdgeCurrencyInfo ) { super(env, tools, walletInfo, opts) + this.lightMode = opts.lightMode ?? false this.initOptions = initOptions this.networkInfo = env.networkInfo this.ethNetwork = new EthereumNetwork(this) diff --git a/src/ethereum/EthereumNetwork.ts b/src/ethereum/EthereumNetwork.ts index 57b90e7e0..6135d692f 100644 --- a/src/ethereum/EthereumNetwork.ts +++ b/src/ethereum/EthereumNetwork.ts @@ -377,14 +377,26 @@ export class EthereumNetwork { // Send an empty tokenTxs network update if no network adapters // qualify for 'fetchTxs': - if (this.qualifyNetworkAdapters('fetchTxs').length === 0) { + if ( + this.qualifyNetworkAdapters('fetchTxs').length === 0 || + this.ethEngine.lightMode + ) { + const tokenTxs: { + [currencyCode: string]: EdgeTransactionsBlockHeightTuple + } = { + [this.ethEngine.currencyInfo.currencyCode]: { + blockHeight: params.startBlock, + edgeTransactions: [] + } + } + for (const token of Object.values(this.ethEngine.allTokensMap)) { + tokenTxs[token.currencyCode] = { + blockHeight: params.startBlock, + edgeTransactions: [] + } + } return { - tokenTxs: { - [this.ethEngine.currencyInfo.currencyCode]: { - blockHeight: params.startBlock, - edgeTransactions: [] - } - }, + tokenTxs, server: 'none' } } diff --git a/src/solana/SolanaEngine.ts b/src/solana/SolanaEngine.ts index 1c52bcca0..8e036f1c1 100644 --- a/src/solana/SolanaEngine.ts +++ b/src/solana/SolanaEngine.ts @@ -74,6 +74,7 @@ export class SolanaEngine extends CurrencyEngine< SolanaTools, SafeSolanaWalletInfo > { + lightMode: boolean networkInfo: SolanaNetworkInfo base58PublicKey: string feePerSignature: string @@ -90,9 +91,10 @@ export class SolanaEngine extends CurrencyEngine< env: PluginEnvironment, tools: SolanaTools, walletInfo: SafeSolanaWalletInfo, - opts: any // EdgeCurrencyEngineOptions + opts: EdgeCurrencyEngineOptions ) { super(env, tools, walletInfo, opts) + this.lightMode = opts.lightMode ?? false this.networkInfo = env.networkInfo this.chainCode = tools.currencyInfo.currencyCode this.fetchCors = getFetchCors(env.io) @@ -547,9 +549,16 @@ export class SolanaEngine extends CurrencyEngine< this.queryBlockhash().catch(() => {}) this.addToLoop('queryBalance', ACCOUNT_POLL_MILLISECONDS).catch(() => {}) - this.addToLoop('queryTransactions', TRANSACTION_POLL_MILLISECONDS).catch( - () => {} - ) + if (this.lightMode) { + this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode] = 1 + for (const edgeToken of Object.values(this.allTokensMap)) { + this.tokenCheckTransactionsStatus[edgeToken.currencyCode] = 1 + } + } else { + this.addToLoop('queryTransactions', TRANSACTION_POLL_MILLISECONDS).catch( + () => {} + ) + } await super.startEngine() } diff --git a/yarn.lock b/yarn.lock index b354a05af..7fb43854d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3987,10 +3987,10 @@ ed25519@0.0.4: bindings "^1.2.1" nan "^2.0.9" -edge-core-js@^2.5.0: - version "2.5.0" - resolved "https://registry.yarnpkg.com/edge-core-js/-/edge-core-js-2.5.0.tgz#9dc013c4f59a7a3fb1c88880eb600c4ef3e44e4f" - integrity sha512-sY0lJDIECanLx/muNGRXz3BUcfd3c76gCFA2BZu/4coE2O5o5GK4QnNB64uKPw6XBNrLfDhP1IcrclHDDgcOUQ== +edge-core-js@^2.9.0: + version "2.9.0" + resolved "https://registry.yarnpkg.com/edge-core-js/-/edge-core-js-2.9.0.tgz#99a73c9b7903637f3551ef8cfb771e821193145c" + integrity sha512-hRxiJSe0NZtiokb4zmDr4fFnAspGN6i8dsVqRfOGeOzyJwm/1yo0K1lx70A1pkXHmNIrsirrp80wPcmLVSvl+Q== dependencies: aes-js "^3.1.0" base-x "^4.0.0"