Commit 34bc1cd6 authored by aniket-engg's avatar aniket-engg Committed by Aniket

providers, init, util, txRunner

parent 142d6478
...@@ -9,6 +9,7 @@ const Web3VMProvider = require('../web3Provider/web3VmProvider') ...@@ -9,6 +9,7 @@ const Web3VMProvider = require('../web3Provider/web3VmProvider')
const LogsManager = require('./logsManager.js') const LogsManager = require('./logsManager.js')
declare let ethereum: any;
let web3 let web3
if (typeof window !== 'undefined' && typeof window['ethereum'] !== 'undefined') { if (typeof window !== 'undefined' && typeof window['ethereum'] !== 'undefined') {
var injectedProvider = window['ethereum'] var injectedProvider = window['ethereum']
......
'use strict' 'use strict'
import { Transaction } from 'ethereumjs-tx' import { Transaction } from 'ethereumjs-tx'
import { Block } from 'ethereumjs-block' import { Block } from 'ethereumjs-block'
import { BN } from 'ethereumjs-util' import { BN, bufferToHex } from 'ethereumjs-util'
import { ExecutionContext } from './execution-context' import { ExecutionContext } from './execution-context'
const EventManager = require('../eventManager') const EventManager = require('../eventManager')
......
'use strict' 'use strict'
const Web3 = require('web3') import Web3 from 'web3'
module.exports = { export function loadWeb3 (url = 'http://localhost:8545') {
loadWeb3: function (url) { const web3 = new Web3()
if (!url) url = 'http://localhost:8545' web3.setProvider(new Web3.providers.HttpProvider(url))
const web3 = new Web3() this.extend(web3)
web3.setProvider(new web3.providers.HttpProvider(url)) return web3
this.extend(web3) }
return web3
},
extendWeb3: function (web3) { export function extendWeb3 (web3) {
this.extend(web3) this.extend(web3)
}, }
setProvider: function (web3, url) { export function setProvider (web3, url) {
web3.setProvider(new web3.providers.HttpProvider(url)) web3.setProvider(new web3.providers.HttpProvider(url))
}, }
web3DebugNode: function (network) { export function web3DebugNode (network) {
if (web3DebugNodes[network]) { const web3DebugNodes = {
return this.loadWeb3(web3DebugNodes[network]) 'Main': 'https://gethmainnet.komputing.org',
} 'Rinkeby': 'https://remix-rinkeby.ethdevops.io',
return null 'Ropsten': 'https://remix-ropsten.ethdevops.io',
}, 'Goerli': 'https://remix-goerli.ethdevops.io',
'Kovan': 'https://remix-kovan.ethdevops.io'
}
if (web3DebugNodes[network]) {
return this.loadWeb3(web3DebugNodes[network])
}
return null
}
extend: function (web3) { export function extend (web3) {
if (!web3.extend) { if (!web3.extend) {
return return
} }
...@@ -65,12 +70,3 @@ module.exports = { ...@@ -65,12 +70,3 @@ module.exports = {
}) })
} }
} }
}
const web3DebugNodes = {
'Main': 'https://gethmainnet.komputing.org',
'Rinkeby': 'https://remix-rinkeby.ethdevops.io',
'Ropsten': 'https://remix-ropsten.ethdevops.io',
'Goerli': 'https://remix-goerli.ethdevops.io',
'Kovan': 'https://remix-kovan.ethdevops.io'
}
This diff is collapsed.
function dummyProvider () { export class dummyProvider {
this.eth = {} eth
this.debug = {} debug
this.eth.getCode = (address, cb) => { return this.getCode(address, cb) } providers
this.eth.getTransaction = (hash, cb) => { return this.getTransaction(hash, cb) } currentProvider
this.eth.getTransactionFromBlock = (blockNumber, txIndex, cb) => { return this.getTransactionFromBlock(blockNumber, txIndex, cb) }
this.eth.getBlockNumber = (cb) => { return this.getBlockNumber(cb) } constructor() {
this.debug.traceTransaction = (hash, options, cb) => { return this.traceTransaction(hash, options, cb) } this.eth = {}
this.debug.storageRangeAt = (blockNumber, txIndex, address, start, end, maxLength, cb) => { return this.storageRangeAt(blockNumber, txIndex, address, start, end, maxLength, cb) } this.debug = {}
this.providers = { 'HttpProvider': function (url) {} } this.eth.getCode = (address, cb) => { return this.getCode(address, cb) }
this.currentProvider = {'host': ''} this.eth.getTransaction = (hash, cb) => { return this.getTransaction(hash, cb) }
} this.eth.getTransactionFromBlock = (blockNumber, txIndex, cb) => { return this.getTransactionFromBlock(blockNumber, txIndex, cb) }
this.eth.getBlockNumber = (cb) => { return this.getBlockNumber(cb) }
this.debug.traceTransaction = (hash, options, cb) => { return this.traceTransaction(hash, options, cb) }
this.debug.storageRangeAt = (blockNumber, txIndex, address, start, end, maxLength, cb) => { return this.storageRangeAt(blockNumber, txIndex, address, start, end, maxLength, cb) }
this.providers = { 'HttpProvider': function (url) {} }
this.currentProvider = {'host': ''}
}
dummyProvider.prototype.getCode = function (address, cb) { getCode (address, cb) {
cb(null, '') cb(null, '')
} }
dummyProvider.prototype.setProvider = function (provider) {} setProvider (provider) {}
dummyProvider.prototype.traceTransaction = function (txHash, options, cb) { traceTransaction (txHash, options, cb) {
if (cb) { if (cb) {
cb(null, {}) cb(null, {})
}
return {}
} }
return {}
}
dummyProvider.prototype.storageRangeAt = function (blockNumber, txIndex, address, start, end, maxLength, cb) { storageRangeAt (blockNumber, txIndex, address, start, end, maxLength, cb) {
if (cb) { if (cb) {
cb(null, {}) cb(null, {})
}
return {}
} }
return {}
}
dummyProvider.prototype.getBlockNumber = function (cb) { cb(null, '') } getBlockNumber (cb) { cb(null, '') }
dummyProvider.prototype.getTransaction = function (txHash, cb) { getTransaction (txHash, cb) {
if (cb) { if (cb) {
cb(null, {}) cb(null, {})
}
return {}
} }
return {}
}
dummyProvider.prototype.getTransactionFromBlock = function (blockNumber, txIndex, cb) { getTransactionFromBlock (blockNumber, txIndex, cb) {
if (cb) { if (cb) {
cb(null, {}) cb(null, {})
}
return {}
} }
return {}
} }
module.exports = dummyProvider
const Web3VMProvider = require('./web3VmProvider') import { Web3VmProvider } from './web3VmProvider'
const init = require('../init') import { loadWeb3, extendWeb3 } from '../init'
function Web3Providers () { export class Web3Providers {
this.modes = {}
}
Web3Providers.prototype.addProvider = function (type, obj) { modes
if (type === 'INTERNAL') { constructor() {
const web3 = init.loadWeb3() this.modes = {}
this.addWeb3(type, web3)
} else if (type === 'vm') {
this.addVM(type, obj)
} else {
init.extendWeb3(obj)
this.addWeb3(type, obj)
} }
}
Web3Providers.prototype.get = function (type, cb) { addProvider (type, obj) {
if (this.modes[type]) { if (type === 'INTERNAL') {
return cb(null, this.modes[type]) const web3 = loadWeb3()
this.addWeb3(type, web3)
} else if (type === 'vm') {
this.addVM(type, obj)
} else {
extendWeb3(obj)
this.addWeb3(type, obj)
}
} }
cb('error: this provider has not been setup (' + type + ')', null)
}
Web3Providers.prototype.addWeb3 = function (type, web3) { get (type, cb) {
this.modes[type] = web3 if (this.modes[type]) {
} return cb(null, this.modes[type])
}
cb('error: this provider has not been setup (' + type + ')', null)
}
Web3Providers.prototype.addVM = function (type, vm) { addWeb3 (type, web3) {
const vmProvider = new Web3VMProvider() this.modes[type] = web3
vmProvider.setVM(vm) }
this.modes[type] = vmProvider
}
module.exports = Web3Providers addVM (type, vm) {
const vmProvider = new Web3VmProvider()
vmProvider.setVM(vm)
this.modes[type] = vmProvider
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment