Merge pull request #3530 from ethereum/fix_vm_mode

fix creating vm acount
pull/5370/head
Aniket 2 years ago committed by GitHub
commit 8419bb424e
  1. 12
      apps/remix-ide/src/blockchain/providers/vm.js
  2. 30
      apps/remix-ide/src/blockchain/providers/worker-vm.ts
  3. 14
      libs/remix-ui/run-tab/src/lib/components/account.tsx

@ -7,6 +7,7 @@ class VMProvider {
this.executionContext = executionContext this.executionContext = executionContext
this.worker = null this.worker = null
this.provider = null this.provider = null
this.newAccountCallback = {}
} }
getAccounts (cb) { getAccounts (cb) {
@ -49,6 +50,11 @@ class VMProvider {
} else { } else {
reject(new Error(msg.data.error)) reject(new Error(msg.data.error))
} }
} 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']})
@ -59,13 +65,15 @@ class VMProvider {
// can be removed later when we update the API // can be removed later when we update the API
createVMAccount (newAccount) { createVMAccount (newAccount) {
const { privateKey, balance } = 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') const privKey = Buffer.from(privateKey, 'hex')
return '0x' + privateToAddress(privKey).toString('hex') return '0x' + privateToAddress(privKey).toString('hex')
} }
newAccount (_passwordPromptCb, cb) { newAccount (_passwordPromptCb, cb) {
this.RemixSimulatorProvider.Accounts.newAccount(cb) const stamp = Date.now()
this.newAccountCallback[stamp] = cb
this.worker.postMessage({ cmd: 'newAccount', stamp })
} }
async getBalanceInEther (address) { async getBalanceInEther (address) {

@ -41,6 +41,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 break
} }
} }

@ -37,6 +37,20 @@ export function AccountUI (props: AccountProps) {
}) })
break 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': case 'web3':
if (!props.personalMode) { if (!props.personalMode) {
setPlusOpt({ setPlusOpt({

Loading…
Cancel
Save