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')
const LogsManager = require('./logsManager.js')
declare let ethereum: any;
let web3
if (typeof window !== 'undefined' && typeof window['ethereum'] !== 'undefined') {
var injectedProvider = window['ethereum']
......
'use strict'
import { Transaction } from 'ethereumjs-tx'
import { Block } from 'ethereumjs-block'
import { BN } from 'ethereumjs-util'
import { BN, bufferToHex } from 'ethereumjs-util'
import { ExecutionContext } from './execution-context'
const EventManager = require('../eventManager')
......
'use strict'
const Web3 = require('web3')
import Web3 from 'web3'
module.exports = {
loadWeb3: function (url) {
if (!url) url = 'http://localhost:8545'
const web3 = new Web3()
web3.setProvider(new web3.providers.HttpProvider(url))
this.extend(web3)
return web3
},
export function loadWeb3 (url = 'http://localhost:8545') {
const web3 = new Web3()
web3.setProvider(new Web3.providers.HttpProvider(url))
this.extend(web3)
return web3
}
extendWeb3: function (web3) {
this.extend(web3)
},
export function extendWeb3 (web3) {
this.extend(web3)
}
setProvider: function (web3, url) {
web3.setProvider(new web3.providers.HttpProvider(url))
},
export function setProvider (web3, url) {
web3.setProvider(new web3.providers.HttpProvider(url))
}
web3DebugNode: function (network) {
if (web3DebugNodes[network]) {
return this.loadWeb3(web3DebugNodes[network])
}
return null
},
export function web3DebugNode (network) {
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'
}
if (web3DebugNodes[network]) {
return this.loadWeb3(web3DebugNodes[network])
}
return null
}
extend: function (web3) {
export function extend (web3) {
if (!web3.extend) {
return
}
......@@ -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 () {
this.eth = {}
this.debug = {}
this.eth.getCode = (address, cb) => { return this.getCode(address, cb) }
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': ''}
}
export class dummyProvider {
eth
debug
providers
currentProvider
constructor() {
this.eth = {}
this.debug = {}
this.eth.getCode = (address, cb) => { return this.getCode(address, cb) }
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) {
cb(null, '')
}
getCode (address, cb) {
cb(null, '')
}
dummyProvider.prototype.setProvider = function (provider) {}
setProvider (provider) {}
dummyProvider.prototype.traceTransaction = function (txHash, options, cb) {
if (cb) {
cb(null, {})
traceTransaction (txHash, options, cb) {
if (cb) {
cb(null, {})
}
return {}
}
return {}
}
dummyProvider.prototype.storageRangeAt = function (blockNumber, txIndex, address, start, end, maxLength, cb) {
if (cb) {
cb(null, {})
storageRangeAt (blockNumber, txIndex, address, start, end, maxLength, cb) {
if (cb) {
cb(null, {})
}
return {}
}
return {}
}
dummyProvider.prototype.getBlockNumber = function (cb) { cb(null, '') }
getBlockNumber (cb) { cb(null, '') }
dummyProvider.prototype.getTransaction = function (txHash, cb) {
if (cb) {
cb(null, {})
getTransaction (txHash, cb) {
if (cb) {
cb(null, {})
}
return {}
}
return {}
}
dummyProvider.prototype.getTransactionFromBlock = function (blockNumber, txIndex, cb) {
if (cb) {
cb(null, {})
getTransactionFromBlock (blockNumber, txIndex, cb) {
if (cb) {
cb(null, {})
}
return {}
}
return {}
}
module.exports = dummyProvider
const Web3VMProvider = require('./web3VmProvider')
const init = require('../init')
import { Web3VmProvider } from './web3VmProvider'
import { loadWeb3, extendWeb3 } from '../init'
function Web3Providers () {
this.modes = {}
}
export class Web3Providers {
Web3Providers.prototype.addProvider = function (type, obj) {
if (type === 'INTERNAL') {
const web3 = init.loadWeb3()
this.addWeb3(type, web3)
} else if (type === 'vm') {
this.addVM(type, obj)
} else {
init.extendWeb3(obj)
this.addWeb3(type, obj)
modes
constructor() {
this.modes = {}
}
}
Web3Providers.prototype.get = function (type, cb) {
if (this.modes[type]) {
return cb(null, this.modes[type])
addProvider (type, obj) {
if (type === 'INTERNAL') {
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) {
this.modes[type] = web3
}
get (type, cb) {
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) {
const vmProvider = new Web3VMProvider()
vmProvider.setVM(vm)
this.modes[type] = vmProvider
}
addWeb3 (type, web3) {
this.modes[type] = web3
}
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