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: { provider: {
async sendAsync (payload, callback) { async sendAsync (payload) {
try { return udapp.call(name, 'sendAsync', payload)
const result = await udapp.call(name, 'sendAsync', payload)
callback(null, result)
} catch (e) {
callback(e)
}
} }
} }
}) })

@ -156,7 +156,7 @@ export class ExecutionContext {
try { try {
const block = await web3.eth.getBlock('latest') 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 // 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 this.lastBlock = block
try { try {
this.currentFork = execution.forkAt(await web3.eth.net.getId(), block.number) this.currentFork = execution.forkAt(await web3.eth.net.getId(), block.number)

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

@ -15,9 +15,9 @@ export class NodeProvider {
getAccounts (cb) { getAccounts (cb) {
if (this.config.get('settings/personal-mode')) { 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) { newAccount (passwordPromptCb, cb) {
@ -25,7 +25,7 @@ export class NodeProvider {
return cb('Not running in personal mode') return cb('Not running in personal mode')
} }
passwordPromptCb((passphrase) => { 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) { 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) { signMessage (message, account, passphrase, cb) {

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

Loading…
Cancel
Save