|
|
@ -7,6 +7,7 @@ const extend = require('xtend') |
|
|
|
const EthStore = require('eth-store') |
|
|
|
const EthStore = require('eth-store') |
|
|
|
const PortStream = require('./lib/port-stream.js') |
|
|
|
const PortStream = require('./lib/port-stream.js') |
|
|
|
const MetaMaskProvider = require('web3-provider-engine/zero.js') |
|
|
|
const MetaMaskProvider = require('web3-provider-engine/zero.js') |
|
|
|
|
|
|
|
const EtherscanProvider = require('web3-provider-engine/subproviders/etherscan') |
|
|
|
const IdentityStore = require('./lib/idStore') |
|
|
|
const IdentityStore = require('./lib/idStore') |
|
|
|
const createTxNotification = require('./lib/tx-notification.js') |
|
|
|
const createTxNotification = require('./lib/tx-notification.js') |
|
|
|
const configManager = require('./lib/config-manager-singleton') |
|
|
|
const configManager = require('./lib/config-manager-singleton') |
|
|
@ -36,8 +37,9 @@ function handleEthRpcRequestStream(stream){ |
|
|
|
// state and network
|
|
|
|
// state and network
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var providerConfig = configManager.getProvider() |
|
|
|
var idStore = new IdentityStore() |
|
|
|
var idStore = new IdentityStore() |
|
|
|
var zeroClient = MetaMaskProvider({ |
|
|
|
var providerOpts = { |
|
|
|
rpcUrl: configManager.getCurrentRpcAddress(), |
|
|
|
rpcUrl: configManager.getCurrentRpcAddress(), |
|
|
|
getAccounts: function(cb){ |
|
|
|
getAccounts: function(cb){ |
|
|
|
var selectedAddress = idStore.getSelectedAddress() |
|
|
|
var selectedAddress = idStore.getSelectedAddress() |
|
|
@ -46,14 +48,23 @@ var zeroClient = MetaMaskProvider({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
approveTransaction: addUnconfirmedTx, |
|
|
|
approveTransaction: addUnconfirmedTx, |
|
|
|
signTransaction: idStore.signTransaction.bind(idStore), |
|
|
|
signTransaction: idStore.signTransaction.bind(idStore), |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
var provider |
|
|
|
|
|
|
|
switch (providerConfig.type) { |
|
|
|
|
|
|
|
case 'rpc': |
|
|
|
|
|
|
|
provider = MetaMaskProvider(providerOpts) |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
case 'etherscan': |
|
|
|
|
|
|
|
provider = EtherscanProvider(providerOpts) |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// log new blocks
|
|
|
|
// log new blocks
|
|
|
|
zeroClient.on('block', function(block){ |
|
|
|
provider.on('block', function(block){ |
|
|
|
console.log('BLOCK CHANGED:', '#'+block.number.toString('hex'), '0x'+block.hash.toString('hex')) |
|
|
|
console.log('BLOCK CHANGED:', '#'+block.number.toString('hex'), '0x'+block.hash.toString('hex')) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
var ethStore = new EthStore(zeroClient) |
|
|
|
var ethStore = new EthStore(provider) |
|
|
|
idStore.setStore(ethStore) |
|
|
|
idStore.setStore(ethStore) |
|
|
|
|
|
|
|
|
|
|
|
function getState(){ |
|
|
|
function getState(){ |
|
|
@ -68,7 +79,7 @@ function getState(){ |
|
|
|
// handle rpc requests
|
|
|
|
// handle rpc requests
|
|
|
|
function onRpcRequest(remoteStream, payload){ |
|
|
|
function onRpcRequest(remoteStream, payload){ |
|
|
|
// console.log('MetaMaskPlugin - incoming payload:', payload)
|
|
|
|
// console.log('MetaMaskPlugin - incoming payload:', payload)
|
|
|
|
zeroClient.sendAsync(payload, function onPayloadHandled(err, response){ |
|
|
|
provider.sendAsync(payload, function onPayloadHandled(err, response){ |
|
|
|
// provider engine errors are included in response objects
|
|
|
|
// provider engine errors are included in response objects
|
|
|
|
if (!payload.isMetamaskInternal) console.log('MetaMaskPlugin - RPC complete:', payload, '->', response) |
|
|
|
if (!payload.isMetamaskInternal) console.log('MetaMaskPlugin - RPC complete:', payload, '->', response) |
|
|
|
try { |
|
|
|
try { |
|
|
@ -111,6 +122,7 @@ function linkDnode(stream){ |
|
|
|
var connection = Dnode({ |
|
|
|
var connection = Dnode({ |
|
|
|
getState: function(cb){ cb(null, getState()) }, |
|
|
|
getState: function(cb){ cb(null, getState()) }, |
|
|
|
setRpcTarget: setRpcTarget, |
|
|
|
setRpcTarget: setRpcTarget, |
|
|
|
|
|
|
|
useEtherscanProvider: useEtherscanProvider, |
|
|
|
// forward directly to idStore
|
|
|
|
// forward directly to idStore
|
|
|
|
createNewVault: idStore.createNewVault.bind(idStore), |
|
|
|
createNewVault: idStore.createNewVault.bind(idStore), |
|
|
|
recoverFromSeed: idStore.recoverFromSeed.bind(idStore), |
|
|
|
recoverFromSeed: idStore.recoverFromSeed.bind(idStore), |
|
|
@ -179,6 +191,11 @@ function setRpcTarget(rpcTarget){ |
|
|
|
chrome.runtime.reload() |
|
|
|
chrome.runtime.reload() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function useEtherscanProvider() { |
|
|
|
|
|
|
|
configManager.useEtherscanProvider() |
|
|
|
|
|
|
|
chrome.runtime.reload() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// util
|
|
|
|
// util
|
|
|
|
|
|
|
|
|
|
|
|
function jsonParseStream(){ |
|
|
|
function jsonParseStream(){ |
|
|
|