Merge branch 'bunsenstraat-patch-6' of https://github.com/ethereum/remix-project into indexdbpackupdate
commit
d72ba2065f
@ -1,76 +0,0 @@ |
|||||||
'use strict' |
|
||||||
import { Transaction as Tx } from '@ethereumjs/tx' |
|
||||||
import { Block } from '@ethereumjs/block' |
|
||||||
import { BN, bufferToHex, Address } from 'ethereumjs-util' |
|
||||||
import { vm as remixlibVM } from '@remix-project/remix-lib' |
|
||||||
import VM from '@ethereumjs/vm' |
|
||||||
import Common from '@ethereumjs/common' |
|
||||||
|
|
||||||
export function sendTx (vm, from, to, value, data, cb?) { |
|
||||||
cb = cb || (() => {}) |
|
||||||
return new Promise ((resolve, reject) => { |
|
||||||
var tx = new Tx({ |
|
||||||
nonce: new BN(from.nonce++), |
|
||||||
// gasPrice: new BN(1),
|
|
||||||
gasLimit: new BN(3000000, 10), |
|
||||||
to: to, |
|
||||||
value: new BN(value, 10), |
|
||||||
data: Buffer.from(data, 'hex') |
|
||||||
}) |
|
||||||
tx = tx.sign(from.privateKey) |
|
||||||
|
|
||||||
var block = Block.fromBlockData({ |
|
||||||
header: { |
|
||||||
timestamp: new Date().getTime() / 1000 | 0, |
|
||||||
number: 0 |
|
||||||
} |
|
||||||
}) // still using default common
|
|
||||||
|
|
||||||
try { |
|
||||||
vm.runTx({block: block, tx: tx, skipBalance: true, skipNonce: true}).then(function (result) { |
|
||||||
setTimeout(() => { |
|
||||||
const hash = bufferToHex(tx.hash()) |
|
||||||
cb(null, { hash, result }) |
|
||||||
resolve({ hash, result }) |
|
||||||
}, 500) |
|
||||||
}).catch((error) => { |
|
||||||
console.error(error) |
|
||||||
cb(error) |
|
||||||
reject(error) |
|
||||||
}) |
|
||||||
} catch (e) { |
|
||||||
console.error(e) |
|
||||||
} |
|
||||||
}) |
|
||||||
} |
|
||||||
|
|
||||||
async function createVm (hardfork) { |
|
||||||
const common = new Common({ chain: 'mainnet', hardfork }) |
|
||||||
const vm = new VM({ common })
|
|
||||||
await vm.init() |
|
||||||
return { vm, stateManager: vm.stateManager } |
|
||||||
} |
|
||||||
|
|
||||||
/* |
|
||||||
Init VM / Send Transaction |
|
||||||
*/ |
|
||||||
export async function initVM (st, privateKey) { |
|
||||||
var VM = await createVm('berlin') |
|
||||||
const vm = VM.vm |
|
||||||
|
|
||||||
var address = Address.fromPrivateKey(privateKey) |
|
||||||
|
|
||||||
try { |
|
||||||
let account = await vm.stateManager.getAccount(address) |
|
||||||
account.balance = new BN('f00000000000000001', 16) |
|
||||||
await vm.stateManager.putAccount(address, account) |
|
||||||
} catch (error) { |
|
||||||
console.log(error) |
|
||||||
} |
|
||||||
|
|
||||||
var web3Provider = new remixlibVM.Web3VMProvider() |
|
||||||
web3Provider.setVM(vm) |
|
||||||
vm.web3 = web3Provider |
|
||||||
return vm |
|
||||||
} |
|
||||||
|
|
@ -1,63 +1,44 @@ |
|||||||
'use strict' |
'use strict' |
||||||
import { Block } from '@ethereumjs/block' |
import { Block } from '@ethereumjs/block' |
||||||
|
import { Transaction } from '@ethereumjs/tx' |
||||||
import VM from '@ethereumjs/vm' |
import VM from '@ethereumjs/vm' |
||||||
|
import { rlp, keccak, bufferToHex } from 'ethereumjs-util' |
||||||
|
import { extendWeb3 } from '../src/init'
|
||||||
var utileth = require('ethereumjs-util') |
var utileth = require('ethereumjs-util') |
||||||
var Tx = require('@ethereumjs/tx').Transaction |
var Tx = require('@ethereumjs/tx').Transaction |
||||||
var BN = require('ethereumjs-util').BN |
var BN = require('ethereumjs-util').BN |
||||||
var remixLib = require('@remix-project/remix-lib') |
var remixLib = require('@remix-project/remix-lib') |
||||||
|
const { Provider, extend } = require('@remix-project/remix-simulator') |
||||||
|
const Web3 = require('web3') |
||||||
|
|
||||||
function sendTx (vm, from, to, value, data, cb) { |
|
||||||
var tx = new Tx({ |
|
||||||
nonce: new BN(from.nonce++), |
|
||||||
// gasPrice: new BN(1),
|
|
||||||
gasLimit: new BN(3000000, 10), |
|
||||||
to: to, |
|
||||||
value: new BN(value, 10), |
|
||||||
data: Buffer.from(data, 'hex') |
|
||||||
}) |
|
||||||
tx = tx.sign(from.privateKey) |
|
||||||
|
|
||||||
var block = Block.fromBlockData({ |
async function getWeb3 () { |
||||||
header: { |
const remixSimulatorProvider = new Provider({ fork: 'berlin' }) |
||||||
timestamp: new Date().getTime() / 1000 | 0, |
await remixSimulatorProvider.init() |
||||||
number: 0 |
await remixSimulatorProvider.Accounts.resetAccounts() |
||||||
} |
const web3 = new Web3(remixSimulatorProvider) |
||||||
}) // still using default common
|
extendWeb3(web3) |
||||||
vm.runTx({block: block, tx: tx, skipBalance: true, skipNonce: true}).then(function (result) { |
return web3 |
||||||
setTimeout(() => { |
|
||||||
cb(null, utileth.bufferToHex(tx.hash())) |
|
||||||
}, 500) |
|
||||||
}).catch((error) => { |
|
||||||
console.error(error) |
|
||||||
cb(error) |
|
||||||
}) |
|
||||||
} |
} |
||||||
|
|
||||||
/* |
async function sendTx (web3, from, to, value, data, cb) { |
||||||
Init VM / Send Transaction |
|
||||||
*/ |
|
||||||
async function initVM (privateKey) { |
|
||||||
var address = utileth.Address.fromPrivateKey(privateKey) |
|
||||||
var vm = new VM({ |
|
||||||
activatePrecompiles: true |
|
||||||
}) |
|
||||||
await vm.init() |
|
||||||
|
|
||||||
try { |
try { |
||||||
let account = await vm.stateManager.getAccount(address) |
cb = cb || (() => {}) |
||||||
account.balance = new BN('f00000000000000001', 16) |
const receipt = await web3.eth.sendTransaction({ |
||||||
await vm.stateManager.putAccount(address, account) |
from: utileth.Address.fromPrivateKey(from.privateKey).toString('hex'), |
||||||
} catch (error) { |
to, |
||||||
console.log(error) |
value, |
||||||
}
|
data, |
||||||
|
gas: 7000000 |
||||||
var web3Provider = new remixLib.vm.Web3VMProvider() |
}) |
||||||
web3Provider.setVM(vm) |
cb(null, receipt.transactionHash) |
||||||
vm.web3 = web3Provider |
return receipt.transactionHash |
||||||
return vm |
} catch (e) { |
||||||
|
cb(e) |
||||||
|
} |
||||||
} |
} |
||||||
|
|
||||||
module.exports = { |
module.exports = { |
||||||
sendTx: sendTx, |
sendTx, |
||||||
initVM: initVM |
getWeb3 |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue