From 3a17d97ad3c56a9b0427c5a44f79ba9ab15f7f4b Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 15 Mar 2023 12:41:36 +0100 Subject: [PATCH 1/2] fix creating vm acount --- apps/remix-ide/src/blockchain/providers/vm.js | 12 +++++-- .../src/blockchain/providers/worker-vm.ts | 32 ++++++++++++++++++- .../run-tab/src/lib/components/account.tsx | 14 ++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide/src/blockchain/providers/vm.js b/apps/remix-ide/src/blockchain/providers/vm.js index a4a600bbf8..2f9322deef 100644 --- a/apps/remix-ide/src/blockchain/providers/vm.js +++ b/apps/remix-ide/src/blockchain/providers/vm.js @@ -7,6 +7,7 @@ class VMProvider { this.executionContext = executionContext this.worker = null this.provider = null + this.newAccountCallback = {} } getAccounts (cb) { @@ -44,6 +45,11 @@ class VMProvider { this.accounts = {} this.executionContext.setWeb3(this.executionContext.getProvider(), this.web3) } + } else if (msg.data.cmd === 'newAccountResult') { + if (this.newAccountCallback[msg.data.stamp]) { + this.newAccountCallback[msg.data.stamp](msg.data.error, msg.data.result) + delete this.newAccountCallback[msg.data.stamp] + } } }) @@ -54,13 +60,15 @@ class VMProvider { // can be removed later when we update the API createVMAccount (newAccount) { const { privateKey, balance } = newAccount - this.RemixSimulatorProvider.Accounts._addAccount(privateKey, balance) + this.worker.postMessage({ cmd: 'addAccount', privateKey: privateKey, balance }) const privKey = Buffer.from(privateKey, 'hex') return '0x' + privateToAddress(privKey).toString('hex') } newAccount (_passwordPromptCb, cb) { - this.RemixSimulatorProvider.Accounts.newAccount(cb) + const stamp = Date.now() + this.newAccountCallback[stamp] = cb + this.worker.postMessage({ cmd: 'newAccount', stamp }) } getBalanceInEther (address, cb) { diff --git a/apps/remix-ide/src/blockchain/providers/worker-vm.ts b/apps/remix-ide/src/blockchain/providers/worker-vm.ts index 7473e6ce37..b261cda864 100644 --- a/apps/remix-ide/src/blockchain/providers/worker-vm.ts +++ b/apps/remix-ide/src/blockchain/providers/worker-vm.ts @@ -42,6 +42,36 @@ self.onmessage = (e: MessageEvent) => { } break - } + } + case 'addAccount': + { + if (provider) { + provider.Accounts._addAccount(data.privateKey, data.balance) + } + + break + } + case 'newAccount': + { + if (provider) { + provider.Accounts.newAccount((error, address: string) => { + if (error) { + self.postMessage({ + cmd: 'newAccountResult', + error, + stamp: data.stamp + }) + } else { + self.postMessage({ + cmd: 'newAccountResult', + result: address, + stamp: data.stamp + }) + } + }) + } + + break + } } } diff --git a/libs/remix-ui/run-tab/src/lib/components/account.tsx b/libs/remix-ui/run-tab/src/lib/components/account.tsx index 34c994977e..4687927fe1 100644 --- a/libs/remix-ui/run-tab/src/lib/components/account.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/account.tsx @@ -37,6 +37,20 @@ export function AccountUI (props: AccountProps) { }) break + case 'vm-london': + setPlusOpt({ + classList: '', + title: 'Create a new account' + }) + break + + case 'vm-berlin': + setPlusOpt({ + classList: '', + title: 'Create a new account' + }) + break + case 'web3': if (!props.personalMode) { setPlusOpt({ From 9e1b0fce53351b1f0e7a599d8c44180baefa62a2 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 23 Mar 2023 12:46:42 +0530 Subject: [PATCH 2/2] fix build --- apps/remix-ide/src/blockchain/providers/vm.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide/src/blockchain/providers/vm.js b/apps/remix-ide/src/blockchain/providers/vm.js index 6a6a862bca..be007d97da 100644 --- a/apps/remix-ide/src/blockchain/providers/vm.js +++ b/apps/remix-ide/src/blockchain/providers/vm.js @@ -50,15 +50,15 @@ class VMProvider { } else { reject(new Error(msg.data.error)) } - } - } else if (msg.data.cmd === 'newAccountResult') { + } else if (msg.data.cmd === 'newAccountResult') { if (this.newAccountCallback[msg.data.stamp]) { this.newAccountCallback[msg.data.stamp](msg.data.error, msg.data.result) delete this.newAccountCallback[msg.data.stamp] } } }) - this.worker.postMessage({ cmd: 'init', fork: this.executionContext.getCurrentFork(), nodeUrl: provider?.options['nodeUrl'], blockNumber: provider?.options['blockNumber']}) + this.worker.postMessage({ cmd: 'init', fork: this.executionContext.getCurrentFork(), nodeUrl: provider?.options['nodeUrl'], blockNumber: provider?.options['blockNumber']}) + }) } // TODO: is still here because of the plugin API