pull/5370/head
Oleksii Kosynskyi 1 year ago
parent dc868707d5
commit a5ca9c0017
  1. 9
      apps/remix-ide/src/app/udapp/run-tab.js
  2. 2
      apps/remix-ide/src/blockchain/execution-context.js
  3. 12
      apps/remix-ide/src/blockchain/providers/injected.ts
  4. 8
      apps/remix-ide/src/blockchain/providers/node.ts
  5. 19
      apps/remix-ide/src/blockchain/providers/vm.ts

@ -119,13 +119,8 @@ export class RunTab extends ViewPlugin {
}
},
provider: {
async sendAsync (payload, callback) {
try {
const result = await udapp.call(name, 'sendAsync', payload)
callback(null, result)
} catch (e) {
callback(e)
}
async sendAsync (payload) {
return udapp.call(name, 'sendAsync', payload)
}
}
})

@ -156,7 +156,7 @@ export class ExecutionContext {
try {
const block = await web3.eth.getBlock('latest')
// we can't use the blockGasLimit cause the next blocks could have a lower limit : https://github.com/ethereum/remix/issues/506
this.blockGasLimit = (block && block.gasLimit) ? Math.floor(block.gasLimit - (5 * block.gasLimit) / 1024) : this.blockGasLimitDefault
this.blockGasLimit = (block && block.gasLimit) ? Math.floor(web3.utils.toNumber(block.gasLimit) - (5 * web3.utils.toNumber(block.gasLimit) / 1024)) : web3.utils.toNumber(this.blockGasLimitDefault)
this.lastBlock = block
try {
this.currentFork = execution.forkAt(await web3.eth.net.getId(), block.number)

@ -10,12 +10,12 @@ export class InjectedProvider {
}
getAccounts (cb) {
return this.executionContext.web3().eth.getAccounts(cb)
return this.executionContext.web3().eth.getAccounts().then(res => cb(null, res)).catch(err => cb(err))
}
newAccount (passwordPromptCb, cb) {
passwordPromptCb((passphrase) => {
this.executionContext.web3().eth.personal.newAccount(passphrase, cb)
this.executionContext.web3().eth.personal.newAccount(passphrase).then(res => cb(null, res)).catch(err => cb(err))
})
}
@ -29,15 +29,15 @@ export class InjectedProvider {
}
getGasPrice (cb) {
this.executionContext.web3().eth.getGasPrice(cb)
this.executionContext.web3().eth.getGasPrice().then(res => cb(null, res)).catch(err => cb(err))
}
signMessage (message, account, _passphrase, cb) {
const messageHash = hashPersonalMessage(Buffer.from(message))
try {
this.executionContext.web3().eth.personal.sign(message, account, (error, signedData) => {
cb(error, '0x' + messageHash.toString('hex'), signedData)
})
this.executionContext.web3().eth.personal.sign(message, account)
.then(signedData=>cb(null, '0x' + messageHash.toString('hex'), signedData))
.catch(error=>cb(error, '0x' + messageHash.toString('hex')))
} catch (e) {
cb(e.message)
}

@ -15,9 +15,9 @@ export class NodeProvider {
getAccounts (cb) {
if (this.config.get('settings/personal-mode')) {
return this.executionContext.web3().eth.personal.getAccounts(cb)
return this.executionContext.web3().eth.personal.getAccounts().then(res => cb(null, res)).catch(err => cb(err))
}
return this.executionContext.web3().eth.getAccounts(cb)
return this.executionContext.web3().eth.getAccounts().then(res => cb(null, res)).catch(err => cb(err))
}
newAccount (passwordPromptCb, cb) {
@ -25,7 +25,7 @@ export class NodeProvider {
return cb('Not running in personal mode')
}
passwordPromptCb((passphrase) => {
this.executionContext.web3().eth.personal.newAccount(passphrase, cb)
this.executionContext.web3().eth.personal.newAccount(passphrase).then(res => cb(null, res)).catch(err => cb(err))
})
}
@ -39,7 +39,7 @@ export class NodeProvider {
}
getGasPrice (cb) {
this.executionContext.web3().eth.getGasPrice(cb)
this.executionContext.web3().eth.getGasPrice().then(res => cb(null, res)).catch(err => cb(err))
}
signMessage (message, account, passphrase, cb) {

@ -1,5 +1,5 @@
import Web3, { FMT_BYTES, FMT_NUMBER, LegacySendAsyncProvider } from 'web3'
import { fromWei, toBigInt } from 'web3-utils'
import Web3, { LegacySendAsyncProvider } from 'web3'
import { fromWei } from 'web3-utils'
import { privateToAddress, hashPersonalMessage } from '@ethereumjs/util'
import { extend, JSONRPCRequestPayload, JSONRPCResponseCallback } from '@remix-project/remix-simulator'
import { ExecutionContext } from '../execution-context'
@ -22,12 +22,7 @@ export class VMProvider {
}
getAccounts (cb) {
this.web3.eth.getAccounts()
.then(accounts => cb(null, accounts))
.catch(err => {
console.log('err',err)
cb('No accounts?')
})
this.web3.eth.getAccounts().then(accounts => cb(null, accounts)).catch(err => cb('No accounts?'))
}
async resetEnvironment () {
@ -46,8 +41,6 @@ export class VMProvider {
if (!msg.data.error) {
this.provider = {
sendAsync: (query, callback) => {
console.log('query',query)
console.log('callback',callback)
const stamp = Date.now() + incr
incr++
stamps[stamp] = callback
@ -88,12 +81,12 @@ export class VMProvider {
}
async getBalanceInEther (address) {
const balance = await this.web3.eth.getBalance(address, undefined, { number: FMT_NUMBER.HEX, bytes: FMT_BYTES.HEX })
return fromWei(toBigInt(balance).toString(10), 'ether')
const balance = await this.web3.eth.getBalance(address)
return fromWei(balance.toString(10), 'ether')
}
getGasPrice (cb) {
this.web3.eth.getGasPrice(cb)
this.web3.eth.getGasPrice().then(res => cb(null, res)).catch(err => cb(err))
}
signMessage (message, account, _passphrase, cb) {

Loading…
Cancel
Save