blob: 45da06dcd157e0946c5f41418e2f994924f16b8e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
const ProviderEngine = require('web3-provider-engine')
const CacheSubprovider = require('web3-provider-engine/subproviders/cache.js')
const FixtureSubprovider = require('web3-provider-engine/subproviders/fixture.js')
const FilterSubprovider = require('web3-provider-engine/subproviders/filters.js')
const VmSubprovider = require('web3-provider-engine/subproviders/vm.js')
const HookedWalletSubprovider = require('web3-provider-engine/subproviders/hooked-wallet.js')
const RpcSubprovider = require('web3-provider-engine/subproviders/rpc.js')
module.exports = metamaskProvider
function metamaskProvider(opts){
var engine = new ProviderEngine()
// cache layer
engine.addProvider(new CacheSubprovider())
// static results
engine.addProvider(new FixtureSubprovider({
web3_clientVersion: 'MetaMask-ProviderEngine/v0.0.0/javascript',
net_listening: true,
eth_hashrate: '0x0',
eth_mining: false,
eth_syncing: true,
}))
// filters
engine.addProvider(new FilterSubprovider())
// vm
engine.addProvider(new VmSubprovider())
// id mgmt
engine.addProvider(new HookedWalletSubprovider({
getAccounts: opts.getAccounts,
signTransaction: opts.signTransaction,
}))
// data source
engine.addProvider(new RpcSubprovider({
rpcUrl: opts.rpcUrl,
}))
// log new blocks
engine.on('block', function(block){
// console.log('================================')
console.log('BLOCK CHANGED:', '#'+block.number.toString('hex'), '0x'+block.hash.toString('hex'))
// console.log('================================')
})
// start polling for blocks
engine.start()
return engine
}
|