From 9982cb8ed0d42c32d3becff7397202d0365901e8 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 27 Oct 2023 00:32:14 +0200 Subject: [PATCH 01/10] fix use await/promise for all the web3 call --- apps/remix-ide/src/blockchain/execution-context.js | 12 ++++-------- .../remix-ide/src/blockchain/providers/injected.ts | 14 +++++++++----- apps/remix-ide/src/blockchain/providers/vm.ts | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/apps/remix-ide/src/blockchain/execution-context.js b/apps/remix-ide/src/blockchain/execution-context.js index 85c68a2160..97f8e09d65 100644 --- a/apps/remix-ide/src/blockchain/execution-context.js +++ b/apps/remix-ide/src/blockchain/execution-context.js @@ -86,20 +86,16 @@ export class ExecutionContext { else if (id === 11155111) name = 'Sepolia' else name = 'Custom' - if (id === '1') { - web3.eth.getBlock(0, (error, block) => { - if (error) console.log('cant query first block') + if (id === 1) { + web3.eth.getBlock(0).then((block) => { if (block && block.hash !== this.mainNetGenesisHash) name = 'Custom' callback(err, { id, name, lastBlock: this.lastBlock, currentFork: this.currentFork }) - }) + }).catch((error) => callback(error)) } else { callback(err, { id, name, lastBlock: this.lastBlock, currentFork: this.currentFork }) } } - const res = web3.eth.net.getId(cb) - if(res && typeof res.then ==='function'){ - res.then(id=>cb(null,id)).catch(err=>cb(err)) - } + web3.eth.net.getId().then(id=>cb(null,parseInt(id))).catch(err=>cb(err)) } } diff --git a/apps/remix-ide/src/blockchain/providers/injected.ts b/apps/remix-ide/src/blockchain/providers/injected.ts index ce6ae9912b..76c211a0ff 100644 --- a/apps/remix-ide/src/blockchain/providers/injected.ts +++ b/apps/remix-ide/src/blockchain/providers/injected.ts @@ -10,12 +10,16 @@ export class InjectedProvider { } getAccounts (cb) { - return this.executionContext.web3().eth.getAccounts(cb) + return this.executionContext.web3().eth.getAccounts() + .then(accounts => cb(null, accounts)) + .catch(err => { + cb(err.message) + }) } newAccount (passwordPromptCb, cb) { passwordPromptCb((passphrase) => { - this.executionContext.web3().eth.personal.newAccount(passphrase, cb) + this.executionContext.web3().eth.personal.newAccount(passphrase).then((result) => cb(null, result)).catch(error => cb(error)) }) } @@ -29,16 +33,16 @@ export class InjectedProvider { } getGasPrice (cb) { - this.executionContext.web3().eth.getGasPrice(cb) + this.executionContext.web3().eth.getGasPrice().then((result => cb(null, result))) } signMessage (message, account, _passphrase, cb) { const messageHash = hashPersonalMessage(Buffer.from(message)) try { message = isHexString(message) ? message : Web3.utils.utf8ToHex(message) - this.executionContext.web3().eth.personal.sign(message, account, (error, signedData) => { + this.executionContext.web3().eth.personal.sign(message, account).then((error, signedData) => { cb(error, '0x' + messageHash.toString('hex'), signedData) - }) + }).catch((error => cb(error))) } catch (e) { cb(e.message) } diff --git a/apps/remix-ide/src/blockchain/providers/vm.ts b/apps/remix-ide/src/blockchain/providers/vm.ts index da6731d696..913bfad2a8 100644 --- a/apps/remix-ide/src/blockchain/providers/vm.ts +++ b/apps/remix-ide/src/blockchain/providers/vm.ts @@ -100,7 +100,7 @@ export class VMProvider { } getGasPrice (cb) { - this.web3.eth.getGasPrice(cb) + this.web3.eth.getGasPrice().then((result => cb(null, result))).catch((error) => cb(error)) } signMessage (message, account, _passphrase, cb) { From b57933faa74e9eb5ba7d5a2c671e1f81ab5b00b2 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 27 Oct 2023 00:32:35 +0200 Subject: [PATCH 02/10] fix return error message --- .../src/app/providers/injected-provider.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide/src/app/providers/injected-provider.tsx b/apps/remix-ide/src/app/providers/injected-provider.tsx index 1e2482fd6c..bed9707d7a 100644 --- a/apps/remix-ide/src/app/providers/injected-provider.tsx +++ b/apps/remix-ide/src/app/providers/injected-provider.tsx @@ -104,16 +104,23 @@ export abstract class InjectedProvider extends Plugin implements IProvider { if (error.data && error.data.originalError && error.data.originalError.data) { resolve({ jsonrpc: '2.0', - error: error.data.originalError.message, + error: { message: error.data.originalError.message }, errorData: error.data.originalError.data, id: data.id }) - } else + } else if (error.data && error.data.message) { resolve({ jsonrpc: '2.0', - error: error.data && error.data.message ? error.data.message : error.message, + error: { message: error.data && error.data.message }, id: data.id }) + } else { + resolve({ + jsonrpc: '2.0', + error: { message: error.message }, + id: data.id + }) + } } } } From 01c89554feecccdc1fa95b9e804c9efcff36dbe9 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 27 Oct 2023 00:33:01 +0200 Subject: [PATCH 03/10] fix missing param --- libs/remix-ui/run-tab/src/lib/actions/deploy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-ui/run-tab/src/lib/actions/deploy.ts b/libs/remix-ui/run-tab/src/lib/actions/deploy.ts index 3929f787b1..83a75a3085 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/deploy.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/deploy.ts @@ -124,7 +124,7 @@ export const continueHandler = (dispatch: React.Dispatch, gasEstimationProm dispatch(displayNotification('Gas estimation failed', gasEstimationPrompt(msg), 'Send Transaction', 'Cancel Transaction', () => { continueTxExecution() }, () => { - cancelCb() + cancelCb(error) })) } else { continueTxExecution() From 6a783b7e205fb5625e968b67b812f50fe6000b0b Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 27 Oct 2023 00:33:27 +0200 Subject: [PATCH 04/10] fix callback with error --- libs/remix-lib/src/execution/txRunnerWeb3.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/remix-lib/src/execution/txRunnerWeb3.ts b/libs/remix-lib/src/execution/txRunnerWeb3.ts index 78e13f2e2b..bd8aaad0ca 100644 --- a/libs/remix-lib/src/execution/txRunnerWeb3.ts +++ b/libs/remix-lib/src/execution/txRunnerWeb3.ts @@ -69,7 +69,7 @@ export class TxRunnerWeb3 { cb(null, res.transactionHash) } catch (e) { console.log(`Send transaction failed: ${e.message} . if you use an injected provider, please check it is properly unlocked. `) - cb(null, e.receipt.transactionHash) + cb(e, null) } }, () => { @@ -82,7 +82,7 @@ export class TxRunnerWeb3 { cb(null, res.transactionHash) } catch (e) { console.log(`Send transaction failed: ${e.message} . if you use an injected provider, please check it is properly unlocked. `) - cb(null, e.receipt.transactionHash) + cb(e, null) } } } @@ -143,7 +143,7 @@ export class TxRunnerWeb3 { }, (error) => { callback(error) }) - }) + }, callback) }) .catch(err => { if (err && err.message.indexOf('Invalid JSON RPC response') !== -1) { @@ -163,7 +163,7 @@ export class TxRunnerWeb3 { }, (error) => { callback(error) }) - }) + }, callback) }) }) } From e952b2a90b4344c02b737667e2a75e5c7a340cba Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 27 Oct 2023 00:33:40 +0200 Subject: [PATCH 05/10] default value --- libs/remix-lib/src/execution/txExecution.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-lib/src/execution/txExecution.ts b/libs/remix-lib/src/execution/txExecution.ts index 267eb4de47..cad6ddaf8e 100644 --- a/libs/remix-lib/src/execution/txExecution.ts +++ b/libs/remix-lib/src/execution/txExecution.ts @@ -81,7 +81,7 @@ export function checkError (execResult, compiledContracts) { } const exceptionError = execResult.errorMessage || '' const error = `Error occured: ${execResult.errorMessage}.\n` - let msg + let msg = '' if (exceptionError === errorCode.INVALID_OPCODE) { msg = '\t\n\tThe execution might have thrown.\n' ret.error = true From 6c7da10d937bce18b5fa7f31a85b97aaa07273ac Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 27 Oct 2023 00:34:00 +0200 Subject: [PATCH 06/10] get proper error msg --- apps/remix-ide/src/blockchain/blockchain.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/remix-ide/src/blockchain/blockchain.tsx b/apps/remix-ide/src/blockchain/blockchain.tsx index 3abd4ce1e2..cbd91b8218 100644 --- a/apps/remix-ide/src/blockchain/blockchain.tsx +++ b/apps/remix-ide/src/blockchain/blockchain.tsx @@ -962,11 +962,10 @@ export class Blockchain extends Plugin { cb(null, txResult, address, returnValue) } catch (error) { if (this.isInjectedWeb3()) { - let errorObj = error.replace('Returned error: ', '') - errorObj = JSON.parse(errorObj) - if (errorObj.errorData) { + let errorObj = error.replace('Returned error: ', '').replace('error: ', '') + if (errorObj) { const compiledContracts = await this.call('compilerArtefacts', 'getAllContractDatas') - const injectedError = txExecution.checkError({ errorMessage: errorObj.error, errorData: errorObj.errorData }, compiledContracts) + const injectedError = txExecution.checkError({ errorMessage: errorObj }, compiledContracts) cb(injectedError.message) } else cb(error) From deab86cd019c67536261df7c00bf2f489007625d Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 27 Oct 2023 00:34:20 +0200 Subject: [PATCH 07/10] should only return promise --- apps/remix-ide/src/app/udapp/run-tab.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide/src/app/udapp/run-tab.js b/apps/remix-ide/src/app/udapp/run-tab.js index 6352e9636f..4e51d3d839 100644 --- a/apps/remix-ide/src/app/udapp/run-tab.js +++ b/apps/remix-ide/src/app/udapp/run-tab.js @@ -133,9 +133,8 @@ export class RunTab extends ViewPlugin { } }, provider: { - - async sendAsync (payload) { - return udapp.call(name, 'sendAsync', payload) + sendAsync (payload) { + return udapp.call(name, 'sendAsync', payload) } } }) From 778df50e7323cadb45c09a15f04bcf8fcb93c5b2 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 30 Oct 2023 09:31:19 +0100 Subject: [PATCH 08/10] fix linting --- apps/remix-ide/src/app/udapp/run-tab.js | 2 +- apps/remix-ide/src/blockchain/blockchain.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide/src/app/udapp/run-tab.js b/apps/remix-ide/src/app/udapp/run-tab.js index 4e51d3d839..f387f1da90 100644 --- a/apps/remix-ide/src/app/udapp/run-tab.js +++ b/apps/remix-ide/src/app/udapp/run-tab.js @@ -134,7 +134,7 @@ export class RunTab extends ViewPlugin { }, provider: { sendAsync (payload) { - return udapp.call(name, 'sendAsync', payload) + return udapp.call(name, 'sendAsync', payload) } } }) diff --git a/apps/remix-ide/src/blockchain/blockchain.tsx b/apps/remix-ide/src/blockchain/blockchain.tsx index cbd91b8218..f1ee5daa90 100644 --- a/apps/remix-ide/src/blockchain/blockchain.tsx +++ b/apps/remix-ide/src/blockchain/blockchain.tsx @@ -962,7 +962,7 @@ export class Blockchain extends Plugin { cb(null, txResult, address, returnValue) } catch (error) { if (this.isInjectedWeb3()) { - let errorObj = error.replace('Returned error: ', '').replace('error: ', '') + const errorObj = error.replace('Returned error: ', '').replace('error: ', '') if (errorObj) { const compiledContracts = await this.call('compilerArtefacts', 'getAllContractDatas') const injectedError = txExecution.checkError({ errorMessage: errorObj }, compiledContracts) From 76933c4ef0cb8462d34f4876db563242cb4432bb Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 30 Oct 2023 09:31:46 +0100 Subject: [PATCH 09/10] do not send eror if receipt is available. --- libs/remix-lib/src/execution/txRunnerWeb3.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/remix-lib/src/execution/txRunnerWeb3.ts b/libs/remix-lib/src/execution/txRunnerWeb3.ts index bd8aaad0ca..0ddd2fdc3d 100644 --- a/libs/remix-lib/src/execution/txRunnerWeb3.ts +++ b/libs/remix-lib/src/execution/txRunnerWeb3.ts @@ -69,7 +69,10 @@ export class TxRunnerWeb3 { cb(null, res.transactionHash) } catch (e) { console.log(`Send transaction failed: ${e.message} . if you use an injected provider, please check it is properly unlocked. `) - cb(e, null) + // in case the receipt is available, we consider that only the execution failed but the transaction went through. + // So we don't consider this to be an error. + if (e.receipt) cb(null, e.receipt.transactionHash) + else cb(e, null) } }, () => { @@ -82,7 +85,10 @@ export class TxRunnerWeb3 { cb(null, res.transactionHash) } catch (e) { console.log(`Send transaction failed: ${e.message} . if you use an injected provider, please check it is properly unlocked. `) - cb(e, null) + // in case the receipt is available, we consider that only the execution failed but the transaction went through. + // So we don't consider this to be an error. + if (e.receipt) cb(null, e.receipt.transactionHash) + else cb(e, null) } } } From 074fbfa4a6a16e19a5df8122adb4fb68fb6c316e Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 31 Oct 2023 13:03:10 +0100 Subject: [PATCH 10/10] fix getting the innerData from injected provider --- .../src/app/providers/injected-provider.tsx | 7 ++-- apps/remix-ide/src/blockchain/blockchain.tsx | 35 ++++--------------- 2 files changed, 9 insertions(+), 33 deletions(-) diff --git a/apps/remix-ide/src/app/providers/injected-provider.tsx b/apps/remix-ide/src/app/providers/injected-provider.tsx index bed9707d7a..a4273e0f31 100644 --- a/apps/remix-ide/src/app/providers/injected-provider.tsx +++ b/apps/remix-ide/src/app/providers/injected-provider.tsx @@ -104,20 +104,19 @@ export abstract class InjectedProvider extends Plugin implements IProvider { if (error.data && error.data.originalError && error.data.originalError.data) { resolve({ jsonrpc: '2.0', - error: { message: error.data.originalError.message }, - errorData: error.data.originalError.data, + error: error.data.originalError, id: data.id }) } else if (error.data && error.data.message) { resolve({ jsonrpc: '2.0', - error: { message: error.data && error.data.message }, + error: error.data && error.data, id: data.id }) } else { resolve({ jsonrpc: '2.0', - error: { message: error.message }, + error, id: data.id }) } diff --git a/apps/remix-ide/src/blockchain/blockchain.tsx b/apps/remix-ide/src/blockchain/blockchain.tsx index f1ee5daa90..fa210bb8fb 100644 --- a/apps/remix-ide/src/blockchain/blockchain.tsx +++ b/apps/remix-ide/src/blockchain/blockchain.tsx @@ -853,16 +853,6 @@ export class Blockchain extends Plugin { try { this.txRunner.rawRun(tx, confirmationCb, continueCb, promptCb, async (error, result) => { if (error) { - if (typeof error !== 'string') { - if (error.message) error = error.message - else { - try { - error = 'error: ' + JSON.stringify(error) - } catch (e) { - console.log(e) - } - } - } return reject(error) } @@ -880,18 +870,7 @@ export class Blockchain extends Plugin { return resolve({result, tx}) }) } catch (err) { - let error = err - if (error && typeof error !== 'string') { - if (error.message) error = error.message - else { - try { - error = 'error: ' + JSON.stringify(error) - } catch (e) { - console.log(e) - } - } - } - return reject(error) + return reject(err) } }) } @@ -962,13 +941,11 @@ export class Blockchain extends Plugin { cb(null, txResult, address, returnValue) } catch (error) { if (this.isInjectedWeb3()) { - const errorObj = error.replace('Returned error: ', '').replace('error: ', '') - if (errorObj) { - const compiledContracts = await this.call('compilerArtefacts', 'getAllContractDatas') - const injectedError = txExecution.checkError({ errorMessage: errorObj }, compiledContracts) - cb(injectedError.message) - } else - cb(error) + const errorMessage = error.innerError ? error.innerError.message : error.message + const errorData = error.innerError ? error.innerError.data : error.data + const compiledContracts = await this.call('compilerArtefacts', 'getAllContractDatas') + const injectedError = txExecution.checkError({ errorMessage, errorData }, compiledContracts) + cb(injectedError.message) } else cb(error) }