aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts/lib')
-rw-r--r--app/scripts/lib/auto-faucet.js4
-rw-r--r--app/scripts/lib/auto-reload.js15
-rw-r--r--app/scripts/lib/config-manager.js115
-rw-r--r--app/scripts/lib/ensnare.js10
-rw-r--r--app/scripts/lib/id-management.js35
-rw-r--r--app/scripts/lib/idStore.js89
-rw-r--r--app/scripts/lib/inpage-provider.js29
-rw-r--r--app/scripts/lib/local-message-stream.js19
-rw-r--r--app/scripts/lib/message-manager.js20
-rw-r--r--app/scripts/lib/notifications.js41
-rw-r--r--app/scripts/lib/obj-multiplex.js13
-rw-r--r--app/scripts/lib/port-stream.js15
-rw-r--r--app/scripts/lib/remote-store.js34
-rw-r--r--app/scripts/lib/stream-utils.js17
14 files changed, 217 insertions, 239 deletions
diff --git a/app/scripts/lib/auto-faucet.js b/app/scripts/lib/auto-faucet.js
index b347add44..59cf0ec20 100644
--- a/app/scripts/lib/auto-faucet.js
+++ b/app/scripts/lib/auto-faucet.js
@@ -1,11 +1,9 @@
var uri = 'https://faucet.metamask.io/'
-module.exports = function(address) {
-
+module.exports = function (address) {
var http = new XMLHttpRequest()
var data = address
http.open('POST', uri, true)
http.setRequestHeader('Content-type', 'application/rawdata')
http.send(data)
-
}
diff --git a/app/scripts/lib/auto-reload.js b/app/scripts/lib/auto-reload.js
index 95a744b2c..b45f02009 100644
--- a/app/scripts/lib/auto-reload.js
+++ b/app/scripts/lib/auto-reload.js
@@ -3,13 +3,11 @@ const ensnare = require('./ensnare.js')
module.exports = setupDappAutoReload
-
-function setupDappAutoReload(web3, controlStream){
-
+function setupDappAutoReload (web3, controlStream) {
// export web3 as a global, checking for usage
var pageIsUsingWeb3 = false
var resetWasRequested = false
- global.web3 = ensnare(web3, once(function(){
+ global.web3 = ensnare(web3, once(function () {
// if web3 usage happened after a reset request, trigger reset late
if (resetWasRequested) return triggerReset()
// mark web3 as used
@@ -19,7 +17,7 @@ function setupDappAutoReload(web3, controlStream){
}))
// listen for reset requests from metamask
- controlStream.once('data', function(){
+ controlStream.once('data', function () {
resetWasRequested = true
// ignore if web3 was not used
if (!pageIsUsingWeb3) return
@@ -28,10 +26,9 @@ function setupDappAutoReload(web3, controlStream){
})
// reload the page
- function triggerReset(){
- setTimeout(function(){
+ function triggerReset () {
+ setTimeout(function () {
global.location.reload()
}, 500)
}
-
-} \ No newline at end of file
+}
diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js
index 24571748f..a3ff0bdfb 100644
--- a/app/scripts/lib/config-manager.js
+++ b/app/scripts/lib/config-manager.js
@@ -7,7 +7,6 @@ const STORAGE_KEY = 'metamask-config'
const TESTNET_RPC = MetamaskConfig.network.testnet
const MAINNET_RPC = MetamaskConfig.network.mainnet
-
/* The config-manager is a convenience object
* wrapping a pojo-migrator.
*
@@ -16,7 +15,7 @@ const MAINNET_RPC = MetamaskConfig.network.mainnet
* particular portions of the state.
*/
module.exports = ConfigManager
-function ConfigManager() {
+function ConfigManager () {
// ConfigManager is observable and will emit updates
this._subs = []
@@ -26,7 +25,7 @@ function ConfigManager() {
* getData(), which returns the app-consumable data object
* saveData(), which persists the app-consumable data object.
*/
- this.migrator = new Migrator({
+ this.migrator = new Migrator({
// Migrations must start at version 1 or later.
// They are objects with a `version` number
@@ -41,20 +40,20 @@ function ConfigManager() {
loadData: loadData,
// How to persist migrated config.
- setData: function(data) {
+ setData: function (data) {
window.localStorage[STORAGE_KEY] = JSON.stringify(data)
},
})
}
-ConfigManager.prototype.setConfig = function(config) {
+ConfigManager.prototype.setConfig = function (config) {
var data = this.migrator.getData()
data.config = config
this.setData(data)
this._emitUpdates(config)
}
-ConfigManager.prototype.getConfig = function() {
+ConfigManager.prototype.getConfig = function () {
var data = this.migrator.getData()
if ('config' in data) {
return data.config
@@ -62,12 +61,12 @@ ConfigManager.prototype.getConfig = function() {
return {
provider: {
type: 'testnet',
- }
+ },
}
}
}
-ConfigManager.prototype.setRpcTarget = function(rpcUrl) {
+ConfigManager.prototype.setRpcTarget = function (rpcUrl) {
var config = this.getConfig()
config.provider = {
type: 'rpc',
@@ -76,7 +75,7 @@ ConfigManager.prototype.setRpcTarget = function(rpcUrl) {
this.setConfig(config)
}
-ConfigManager.prototype.setProviderType = function(type) {
+ConfigManager.prototype.setProviderType = function (type) {
var config = this.getConfig()
config.provider = {
type: type,
@@ -84,7 +83,7 @@ ConfigManager.prototype.setProviderType = function(type) {
this.setConfig(config)
}
-ConfigManager.prototype.useEtherscanProvider = function() {
+ConfigManager.prototype.useEtherscanProvider = function () {
var config = this.getConfig()
config.provider = {
type: 'etherscan',
@@ -92,75 +91,75 @@ ConfigManager.prototype.useEtherscanProvider = function() {
this.setConfig(config)
}
-ConfigManager.prototype.getProvider = function() {
+ConfigManager.prototype.getProvider = function () {
var config = this.getConfig()
return config.provider
}
-ConfigManager.prototype.setData = function(data) {
+ConfigManager.prototype.setData = function (data) {
this.migrator.saveData(data)
}
-ConfigManager.prototype.getData = function() {
+ConfigManager.prototype.getData = function () {
return this.migrator.getData()
}
-ConfigManager.prototype.setWallet = function(wallet) {
+ConfigManager.prototype.setWallet = function (wallet) {
var data = this.migrator.getData()
data.wallet = wallet
this.setData(data)
}
-ConfigManager.prototype.getSelectedAccount = function() {
+ConfigManager.prototype.getSelectedAccount = function () {
var config = this.getConfig()
return config.selectedAccount
}
-ConfigManager.prototype.setSelectedAccount = function(address) {
+ConfigManager.prototype.setSelectedAccount = function (address) {
var config = this.getConfig()
config.selectedAccount = address
this.setConfig(config)
}
-ConfigManager.prototype.getWallet = function() {
+ConfigManager.prototype.getWallet = function () {
return this.migrator.getData().wallet
}
// Takes a boolean
-ConfigManager.prototype.setShowSeedWords = function(should) {
+ConfigManager.prototype.setShowSeedWords = function (should) {
var data = this.migrator.getData()
data.showSeedWords = should
this.setData(data)
}
-ConfigManager.prototype.getShouldShowSeedWords = function() {
+ConfigManager.prototype.getShouldShowSeedWords = function () {
var data = this.migrator.getData()
return data.showSeedWords
}
-ConfigManager.prototype.getCurrentRpcAddress = function() {
+ConfigManager.prototype.getCurrentRpcAddress = function () {
var provider = this.getProvider()
if (!provider) return null
- switch (provider.type) {
+ switch (provider.type) {
- case 'mainnet':
- return MAINNET_RPC
+ case 'mainnet':
+ return MAINNET_RPC
- case 'testnet':
- return TESTNET_RPC
+ case 'testnet':
+ return TESTNET_RPC
- default:
- return provider && provider.rpcTarget ? provider.rpcTarget : TESTNET_RPC
- }
+ default:
+ return provider && provider.rpcTarget ? provider.rpcTarget : TESTNET_RPC
+ }
}
-ConfigManager.prototype.clearWallet = function() {
+ConfigManager.prototype.clearWallet = function () {
var data = this.getConfig()
delete data.wallet
this.setData(data)
}
-ConfigManager.prototype.setData = function(data) {
+ConfigManager.prototype.setData = function (data) {
this.migrator.saveData(data)
}
@@ -168,7 +167,7 @@ ConfigManager.prototype.setData = function(data) {
// Tx
//
-ConfigManager.prototype.getTxList = function() {
+ConfigManager.prototype.getTxList = function () {
var data = this.migrator.getData()
if (data.transactions !== undefined) {
return data.transactions
@@ -177,45 +176,45 @@ ConfigManager.prototype.getTxList = function() {
}
}
-ConfigManager.prototype.unconfirmedTxs = function() {
+ConfigManager.prototype.unconfirmedTxs = function () {
var transactions = this.getTxList()
return transactions.filter(tx => tx.status === 'unconfirmed')
.reduce((result, tx) => { result[tx.id] = tx; return result }, {})
}
-ConfigManager.prototype._saveTxList = function(txList) {
+ConfigManager.prototype._saveTxList = function (txList) {
var data = this.migrator.getData()
data.transactions = txList
this.setData(data)
}
-ConfigManager.prototype.addTx = function(tx) {
+ConfigManager.prototype.addTx = function (tx) {
var transactions = this.getTxList()
transactions.push(tx)
this._saveTxList(transactions)
}
-ConfigManager.prototype.getTx = function(txId) {
+ConfigManager.prototype.getTx = function (txId) {
var transactions = this.getTxList()
var matching = transactions.filter(tx => tx.id === txId)
return matching.length > 0 ? matching[0] : null
}
-ConfigManager.prototype.confirmTx = function(txId) {
+ConfigManager.prototype.confirmTx = function (txId) {
this._setTxStatus(txId, 'confirmed')
}
-ConfigManager.prototype.rejectTx = function(txId) {
+ConfigManager.prototype.rejectTx = function (txId) {
this._setTxStatus(txId, 'rejected')
}
-ConfigManager.prototype._setTxStatus = function(txId, status) {
+ConfigManager.prototype._setTxStatus = function (txId, status) {
var tx = this.getTx(txId)
tx.status = status
this.updateTx(tx)
}
-ConfigManager.prototype.updateTx = function(tx) {
+ConfigManager.prototype.updateTx = function (tx) {
var transactions = this.getTxList()
var found, index
transactions.forEach((otherTx, i) => {
@@ -232,19 +231,19 @@ ConfigManager.prototype.updateTx = function(tx) {
// wallet nickname methods
-ConfigManager.prototype.getWalletNicknames = function() {
+ConfigManager.prototype.getWalletNicknames = function () {
var data = this.getData()
- let nicknames = ('walletNicknames' in data) ? data.walletNicknames : {}
+ const nicknames = ('walletNicknames' in data) ? data.walletNicknames : {}
return nicknames
}
-ConfigManager.prototype.nicknameForWallet = function(account) {
- let nicknames = this.getWalletNicknames()
+ConfigManager.prototype.nicknameForWallet = function (account) {
+ const nicknames = this.getWalletNicknames()
return nicknames[account]
}
-ConfigManager.prototype.setNicknameForWallet = function(account, nickname) {
- let nicknames = this.getWalletNicknames()
+ConfigManager.prototype.setNicknameForWallet = function (account, nickname) {
+ const nicknames = this.getWalletNicknames()
nicknames[account] = nickname
var data = this.getData()
data.walletNicknames = nicknames
@@ -253,37 +252,35 @@ ConfigManager.prototype.setNicknameForWallet = function(account, nickname) {
// observable
-ConfigManager.prototype.subscribe = function(fn){
+ConfigManager.prototype.subscribe = function (fn) {
this._subs.push(fn)
var unsubscribe = this.unsubscribe.bind(this, fn)
return unsubscribe
}
-ConfigManager.prototype.unsubscribe = function(fn){
+ConfigManager.prototype.unsubscribe = function (fn) {
var index = this._subs.indexOf(fn)
if (index !== -1) this._subs.splice(index, 1)
}
-ConfigManager.prototype._emitUpdates = function(state){
- this._subs.forEach(function(handler){
+ConfigManager.prototype._emitUpdates = function (state) {
+ this._subs.forEach(function (handler) {
handler(state)
})
}
-ConfigManager.prototype.setConfirmed = function(confirmed) {
+ConfigManager.prototype.setConfirmed = function (confirmed) {
var data = this.getData()
data.isConfirmed = confirmed
this.setData(data)
}
-ConfigManager.prototype.getConfirmed = function() {
+ConfigManager.prototype.getConfirmed = function () {
var data = this.getData()
return ('isConfirmed' in data) && data.isConfirmed
}
-
-function loadData() {
-
+function loadData () {
var oldData = getOldStyleData()
var newData
try {
@@ -298,14 +295,14 @@ function loadData() {
config: {
provider: {
type: 'testnet',
- }
- }
- }
- }, oldData ? oldData : null, newData ? newData : null)
+ },
+ },
+ },
+ }, oldData || null, newData || null)
return data
}
-function getOldStyleData() {
+function getOldStyleData () {
var config, wallet, seedWords
var result = {
diff --git a/app/scripts/lib/ensnare.js b/app/scripts/lib/ensnare.js
index b70330a5a..6100f7c79 100644
--- a/app/scripts/lib/ensnare.js
+++ b/app/scripts/lib/ensnare.js
@@ -1,21 +1,21 @@
module.exports = ensnare
// creates a proxy object that calls cb everytime the obj's properties/fns are accessed
-function ensnare(obj, cb){
+function ensnare (obj, cb) {
var proxy = {}
- Object.keys(obj).forEach(function(key){
+ Object.keys(obj).forEach(function (key) {
var val = obj[key]
switch (typeof val) {
case 'function':
- proxy[key] = function(){
+ proxy[key] = function () {
cb()
val.apply(obj, arguments)
}
return
default:
Object.defineProperty(proxy, key, {
- get: function(){ cb(); return obj[key] },
- set: function(val){ cb(); return obj[key] = val },
+ get: function () { cb(); return obj[key] },
+ set: function (val) { cb(); obj[key] = val; return val },
})
return
}
diff --git a/app/scripts/lib/id-management.js b/app/scripts/lib/id-management.js
index 5de1f438f..4e18bc8a9 100644
--- a/app/scripts/lib/id-management.js
+++ b/app/scripts/lib/id-management.js
@@ -4,19 +4,18 @@ const configManager = require('./config-manager-singleton')
module.exports = IdManagement
-
-function IdManagement(opts) {
+function IdManagement (opts) {
if (!opts) opts = {}
this.keyStore = opts.keyStore
this.derivedKey = opts.derivedKey
this.hdPathString = "m/44'/60'/0'/0"
- this.getAddresses = function(){
- return keyStore.getAddresses(this.hdPathString).map(function(address){ return '0x'+address })
+ this.getAddresses = function () {
+ return keyStore.getAddresses(this.hdPathString).map(function (address) { return '0x' + address })
}
- this.signTx = function(txParams){
+ this.signTx = function (txParams) {
// normalize values
txParams.to = ethUtil.addHexPrefix(txParams.to)
txParams.from = ethUtil.addHexPrefix(txParams.from)
@@ -44,32 +43,32 @@ function IdManagement(opts) {
this.signMsg = function (address, message) {
// sign message
- var privKeyHex = this.exportPrivateKey(address);
- var privKey = ethUtil.toBuffer(privKeyHex);
- var msgSig = ethUtil.ecsign(new Buffer(message.replace('0x',''), 'hex'), privKey);
- var rawMsgSig = ethUtil.bufferToHex(concatSig(msgSig.v, msgSig.r, msgSig.s));
- return rawMsgSig;
- };
+ var privKeyHex = this.exportPrivateKey(address)
+ var privKey = ethUtil.toBuffer(privKeyHex)
+ var msgSig = ethUtil.ecsign(new Buffer(message.replace('0x', ''), 'hex'), privKey)
+ var rawMsgSig = ethUtil.bufferToHex(concatSig(msgSig.v, msgSig.r, msgSig.s))
+ return rawMsgSig
+ }
- this.getSeed = function(){
+ this.getSeed = function () {
return this.keyStore.getSeed(this.derivedKey)
}
- this.exportPrivateKey = function(address) {
+ this.exportPrivateKey = function (address) {
var privKeyHex = ethUtil.addHexPrefix(this.keyStore.exportPrivateKey(address, this.derivedKey, this.hdPathString))
return privKeyHex
}
}
-function pad_with_zeroes(number, length){
- var my_string = '' + number;
+function pad_with_zeroes (number, length) {
+ var my_string = '' + number
while (my_string.length < length) {
- my_string = '0' + my_string;
+ my_string = '0' + my_string
}
- return my_string;
+ return my_string
}
-function concatSig(v, r, s) {
+function concatSig (v, r, s) {
r = pad_with_zeroes(ethUtil.fromSigned(r), 64)
s = pad_with_zeroes(ethUtil.fromSigned(s), 64)
r = ethUtil.stripHexPrefix(r.toString('hex'))
diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js
index 8c736eac9..7fd2eeb01 100644
--- a/app/scripts/lib/idStore.js
+++ b/app/scripts/lib/idStore.js
@@ -15,12 +15,10 @@ const messageManager = require('./message-manager')
const DEFAULT_RPC = 'https://testrpc.metamask.io/'
const IdManagement = require('./id-management')
-
module.exports = IdentityStore
-
inherits(IdentityStore, EventEmitter)
-function IdentityStore(opts = {}) {
+function IdentityStore (opts = {}) {
EventEmitter.call(this)
// we just use the ethStore to auto-add accounts
@@ -46,7 +44,7 @@ function IdentityStore(opts = {}) {
// public
//
-IdentityStore.prototype.createNewVault = function(password, entropy, cb){
+IdentityStore.prototype.createNewVault = function (password, entropy, cb) {
delete this._keyStore
configManager.clearWallet()
this._createIdmgmt(password, null, entropy, (err) => {
@@ -62,14 +60,14 @@ IdentityStore.prototype.createNewVault = function(password, entropy, cb){
})
}
-IdentityStore.prototype.recoverSeed = function(cb){
+IdentityStore.prototype.recoverSeed = function (cb) {
configManager.setShowSeedWords(true)
if (!this._idmgmt) return cb(new Error('Unauthenticated. Please sign in.'))
var seedWords = this._idmgmt.getSeed()
cb(null, seedWords)
}
-IdentityStore.prototype.recoverFromSeed = function(password, seed, cb){
+IdentityStore.prototype.recoverFromSeed = function (password, seed, cb) {
this._createIdmgmt(password, seed, null, (err) => {
if (err) return cb(err)
@@ -79,16 +77,16 @@ IdentityStore.prototype.recoverFromSeed = function(password, seed, cb){
})
}
-IdentityStore.prototype.setStore = function(store){
+IdentityStore.prototype.setStore = function (store) {
this._ethStore = store
}
-IdentityStore.prototype.clearSeedWordCache = function(cb) {
+IdentityStore.prototype.clearSeedWordCache = function (cb) {
configManager.setShowSeedWords(false)
cb(null, configManager.getSelectedAccount())
}
-IdentityStore.prototype.getState = function(){
+IdentityStore.prototype.getState = function () {
var seedWords = this.getSeedIfUnlocked()
var wallet = configManager.getWallet()
return clone(extend(this._currentState, {
@@ -104,7 +102,7 @@ IdentityStore.prototype.getState = function(){
}))
}
-IdentityStore.prototype.getSeedIfUnlocked = function() {
+IdentityStore.prototype.getSeedIfUnlocked = function () {
var showSeed = configManager.getShouldShowSeedWords()
var idmgmt = this._idmgmt
var shouldShow = showSeed && !!idmgmt
@@ -112,11 +110,11 @@ IdentityStore.prototype.getSeedIfUnlocked = function() {
return seedWords
}
-IdentityStore.prototype.getSelectedAddress = function(){
+IdentityStore.prototype.getSelectedAddress = function () {
return configManager.getSelectedAccount()
}
-IdentityStore.prototype.setSelectedAddress = function(address, cb){
+IdentityStore.prototype.setSelectedAddress = function (address, cb) {
if (!address) {
var addresses = this._getAddresses()
address = addresses[0]
@@ -126,7 +124,7 @@ IdentityStore.prototype.setSelectedAddress = function(address, cb){
if (cb) return cb(null, address)
}
-IdentityStore.prototype.revealAccount = function(cb) {
+IdentityStore.prototype.revealAccount = function (cb) {
let addresses = this._getAddresses()
const derivedKey = this._idmgmt.derivedKey
const keyStore = this._keyStore
@@ -141,8 +139,7 @@ IdentityStore.prototype.revealAccount = function(cb) {
cb(null)
}
-IdentityStore.prototype.getNetwork = function(err) {
-
+IdentityStore.prototype.getNetwork = function (err) {
if (err) {
this._currentState.network = 'loading'
this._didUpdate()
@@ -160,13 +157,13 @@ IdentityStore.prototype.getNetwork = function(err) {
})
}
-IdentityStore.prototype.setLocked = function(cb){
+IdentityStore.prototype.setLocked = function (cb) {
delete this._keyStore
delete this._idmgmt
cb()
}
-IdentityStore.prototype.submitPassword = function(password, cb){
+IdentityStore.prototype.submitPassword = function (password, cb) {
this.tryPassword(password, (err) => {
if (err) return cb(err)
// load identities before returning...
@@ -175,7 +172,7 @@ IdentityStore.prototype.submitPassword = function(password, cb){
})
}
-IdentityStore.prototype.exportAccount = function(address, cb) {
+IdentityStore.prototype.exportAccount = function (address, cb) {
var privateKey = this._idmgmt.exportPrivateKey(address)
cb(null, privateKey)
}
@@ -185,7 +182,7 @@ IdentityStore.prototype.exportAccount = function(address, cb) {
//
// comes from dapp via zero-client hooked-wallet provider
-IdentityStore.prototype.addUnconfirmedTransaction = function(txParams, onTxDoneCb, cb){
+IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDoneCb, cb) {
var self = this
// create txData obj with parameters and meta data
var time = (new Date()).getTime()
@@ -208,13 +205,13 @@ IdentityStore.prototype.addUnconfirmedTransaction = function(txParams, onTxDoneC
// perform static analyis on the target contract code
var provider = self._ethStore._query.currentProvider
if (txParams.to) {
- provider.sendAsync({ id: 1, method: 'eth_getCode', params: [txParams.to, 'latest'] }, function(err, res){
+ provider.sendAsync({ id: 1, method: 'eth_getCode', params: [txParams.to, 'latest'] }, function (err, res) {
if (err) return didComplete(err)
if (res.error) return didComplete(res.error)
var code = ethUtil.toBuffer(res.result)
if (code !== '0x') {
var ops = ethBinToOps(code)
- var containsDelegateCall = ops.some((op)=>op.name === 'DELEGATECALL')
+ var containsDelegateCall = ops.some((op) => op.name === 'DELEGATECALL')
txData.containsDelegateCall = containsDelegateCall
didComplete()
} else {
@@ -225,18 +222,17 @@ IdentityStore.prototype.addUnconfirmedTransaction = function(txParams, onTxDoneC
didComplete()
}
- function didComplete(err){
+ function didComplete (err) {
if (err) return cb(err)
// signal update
self._didUpdate()
// signal completion of add tx
cb(null, txData)
}
-
}
// comes from metamask ui
-IdentityStore.prototype.approveTransaction = function(txId, cb){
+IdentityStore.prototype.approveTransaction = function (txId, cb) {
var txData = configManager.getTx(txId)
var approvalCb = this._unconfTxCbs[txId] || noop
@@ -250,7 +246,7 @@ IdentityStore.prototype.approveTransaction = function(txId, cb){
}
// comes from metamask ui
-IdentityStore.prototype.cancelTransaction = function(txId){
+IdentityStore.prototype.cancelTransaction = function (txId) {
var txData = configManager.getTx(txId)
var approvalCb = this._unconfTxCbs[txId] || noop
@@ -263,7 +259,7 @@ IdentityStore.prototype.cancelTransaction = function(txId){
}
// performs the actual signing, no autofill of params
-IdentityStore.prototype.signTransaction = function(txParams, cb){
+IdentityStore.prototype.signTransaction = function (txParams, cb) {
try {
console.log('signing tx...', txParams)
var rawTx = this._idmgmt.signTx(txParams)
@@ -278,8 +274,7 @@ IdentityStore.prototype.signTransaction = function(txParams, cb){
//
// comes from dapp via zero-client hooked-wallet provider
-IdentityStore.prototype.addUnconfirmedMessage = function(msgParams, cb){
-
+IdentityStore.prototype.addUnconfirmedMessage = function (msgParams, cb) {
// create txData obj with parameters and meta data
var time = (new Date()).getTime()
var msgId = createId()
@@ -303,7 +298,7 @@ IdentityStore.prototype.addUnconfirmedMessage = function(msgParams, cb){
}
// comes from metamask ui
-IdentityStore.prototype.approveMessage = function(msgId, cb){
+IdentityStore.prototype.approveMessage = function (msgId, cb) {
var msgData = messageManager.getMsg(msgId)
var approvalCb = this._unconfMsgCbs[msgId] || noop
@@ -317,7 +312,7 @@ IdentityStore.prototype.approveMessage = function(msgId, cb){
}
// comes from metamask ui
-IdentityStore.prototype.cancelMessage = function(msgId){
+IdentityStore.prototype.cancelMessage = function (msgId) {
var txData = messageManager.getMsg(msgId)
var approvalCb = this._unconfMsgCbs[msgId] || noop
@@ -330,7 +325,7 @@ IdentityStore.prototype.cancelMessage = function(msgId){
}
// performs the actual signing, no autofill of params
-IdentityStore.prototype.signMessage = function(msgParams, cb){
+IdentityStore.prototype.signMessage = function (msgParams, cb) {
try {
console.log('signing msg...', msgParams.data)
var rawMsg = this._idmgmt.signMsg(msgParams.from, msgParams.data)
@@ -351,17 +346,17 @@ IdentityStore.prototype.signMessage = function(msgParams, cb){
// private
//
-IdentityStore.prototype._didUpdate = function(){
+IdentityStore.prototype._didUpdate = function () {
this.emit('update', this.getState())
}
-IdentityStore.prototype._isUnlocked = function(){
+IdentityStore.prototype._isUnlocked = function () {
var result = Boolean(this._keyStore) && Boolean(this._idmgmt)
return result
}
// load identities from keyStoreet
-IdentityStore.prototype._loadIdentities = function(){
+IdentityStore.prototype._loadIdentities = function () {
if (!this._isUnlocked()) throw new Error('not unlocked')
var addresses = this._getAddresses()
@@ -369,7 +364,7 @@ IdentityStore.prototype._loadIdentities = function(){
// // add to ethStore
this._ethStore.addAccount(address)
// add to identities
- const defaultLabel = 'Wallet ' + (i+1)
+ const defaultLabel = 'Wallet ' + (i + 1)
const nickname = configManager.nicknameForWallet(address)
var identity = {
name: nickname || defaultLabel,
@@ -381,7 +376,7 @@ IdentityStore.prototype._loadIdentities = function(){
this._didUpdate()
}
-IdentityStore.prototype.saveAccountLabel = function(account, label, cb) {
+IdentityStore.prototype.saveAccountLabel = function (account, label, cb) {
configManager.setNicknameForWallet(account, label)
this._loadIdentities()
cb(null, label)
@@ -393,7 +388,7 @@ IdentityStore.prototype.saveAccountLabel = function(account, label, cb) {
// The UI will have to check the balance to know.
// If there is no balance and it mayBeFauceting,
// then it is in fact fauceting.
-IdentityStore.prototype._mayBeFauceting = function(i) {
+IdentityStore.prototype._mayBeFauceting = function (i) {
var config = configManager.getProvider()
if (i === 0 &&
config.type === 'rpc' &&
@@ -407,11 +402,11 @@ IdentityStore.prototype._mayBeFauceting = function(i) {
// keyStore managment - unlocking + deserialization
//
-IdentityStore.prototype.tryPassword = function(password, cb){
+IdentityStore.prototype.tryPassword = function (password, cb) {
this._createIdmgmt(password, null, null, cb)
}
-IdentityStore.prototype._createIdmgmt = function(password, seed, entropy, cb){
+IdentityStore.prototype._createIdmgmt = function (password, seed, entropy, cb) {
var keyStore = null
LightwalletKeyStore.deriveKeyFromPassword(password, (err, derivedKey) => {
if (err) return cb(err)
@@ -446,9 +441,9 @@ IdentityStore.prototype._createIdmgmt = function(password, seed, entropy, cb){
})
}
-IdentityStore.prototype._restoreFromSeed = function(password, seed, derivedKey) {
+IdentityStore.prototype._restoreFromSeed = function (password, seed, derivedKey) {
var keyStore = new LightwalletKeyStore(seed, derivedKey, this.hdPathString)
- keyStore.addHdDerivationPath(this.hdPathString, derivedKey, {curve: 'secp256k1', purpose: 'sign'});
+ keyStore.addHdDerivationPath(this.hdPathString, derivedKey, {curve: 'secp256k1', purpose: 'sign'})
keyStore.setDefaultHdDerivationPath(this.hdPathString)
keyStore.generateNewAddress(derivedKey, 3)
@@ -457,10 +452,10 @@ IdentityStore.prototype._restoreFromSeed = function(password, seed, derivedKey)
return keyStore
}
-IdentityStore.prototype._createFirstWallet = function(entropy, derivedKey) {
+IdentityStore.prototype._createFirstWallet = function (entropy, derivedKey) {
var secretSeed = LightwalletKeyStore.generateRandomSeed(entropy)
var keyStore = new LightwalletKeyStore(secretSeed, derivedKey, this.hdPathString)
- keyStore.addHdDerivationPath(this.hdPathString, derivedKey, {curve: 'secp256k1', purpose: 'sign'});
+ keyStore.addHdDerivationPath(this.hdPathString, derivedKey, {curve: 'secp256k1', purpose: 'sign'})
keyStore.setDefaultHdDerivationPath(this.hdPathString)
keyStore.generateNewAddress(derivedKey, 3)
@@ -470,15 +465,15 @@ IdentityStore.prototype._createFirstWallet = function(entropy, derivedKey) {
}
// get addresses and normalize address hexString
-IdentityStore.prototype._getAddresses = function() {
- return this._keyStore.getAddresses(this.hdPathString).map((address) => { return '0x'+address })
+IdentityStore.prototype._getAddresses = function () {
+ return this._keyStore.getAddresses(this.hdPathString).map((address) => { return '0x' + address })
}
-IdentityStore.prototype._autoFaucet = function() {
+IdentityStore.prototype._autoFaucet = function () {
var addresses = this._getAddresses()
autoFaucet(addresses[0])
}
// util
-function noop(){}
+function noop () {}
diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js
index 70b0d80dd..afb07ca16 100644
--- a/app/scripts/lib/inpage-provider.js
+++ b/app/scripts/lib/inpage-provider.js
@@ -7,13 +7,12 @@ const MetamaskConfig = require('../config.js')
module.exports = MetamaskInpageProvider
-
-function MetamaskInpageProvider(connectionStream){
+function MetamaskInpageProvider (connectionStream) {
const self = this
- // setup connectionStream multiplexing
+ // setup connectionStream multiplexing
var multiStream = ObjectMultiplex()
- Streams.pipe(connectionStream, multiStream, connectionStream, function(err){
+ Streams.pipe(connectionStream, multiStream, connectionStream, function (err) {
console.warn('MetamaskInpageProvider - lost connection to MetaMask')
if (err) throw err
})
@@ -22,7 +21,7 @@ function MetamaskInpageProvider(connectionStream){
// subscribe to metamask public config
var publicConfigStore = remoteStoreWithLocalStorageCache('MetaMask-Config')
var storeStream = publicConfigStore.createStream()
- Streams.pipe(storeStream, multiStream.createStream('publicConfig'), storeStream, function(err){
+ Streams.pipe(storeStream, multiStream.createStream('publicConfig'), storeStream, function (err) {
console.warn('MetamaskInpageProvider - lost connection to MetaMask publicConfig')
if (err) throw err
})
@@ -31,13 +30,13 @@ function MetamaskInpageProvider(connectionStream){
// connect to sync provider
self.syncProvider = createSyncProvider(publicConfigStore.get('provider'))
// subscribe to publicConfig to update the syncProvider on change
- publicConfigStore.subscribe(function(state){
+ publicConfigStore.subscribe(function (state) {
self.syncProvider = createSyncProvider(state.provider)
})
// connect to async provider
var asyncProvider = new StreamProvider()
- Streams.pipe(asyncProvider, multiStream.createStream('provider'), asyncProvider, function(err){
+ Streams.pipe(asyncProvider, multiStream.createStream('provider'), asyncProvider, function (err) {
console.warn('MetamaskInpageProvider - lost connection to MetaMask provider')
if (err) throw err
})
@@ -47,7 +46,7 @@ function MetamaskInpageProvider(connectionStream){
self.sendAsync = asyncProvider.sendAsync.bind(asyncProvider)
}
-MetamaskInpageProvider.prototype.send = function(payload){
+MetamaskInpageProvider.prototype.send = function (payload) {
const self = this
var result = null
@@ -79,24 +78,24 @@ MetamaskInpageProvider.prototype.send = function(payload){
}
}
-MetamaskInpageProvider.prototype.sendAsync = function(){
+MetamaskInpageProvider.prototype.sendAsync = function () {
throw new Error('MetamaskInpageProvider - sendAsync not overwritten')
}
-MetamaskInpageProvider.prototype.isConnected = function(){
+MetamaskInpageProvider.prototype.isConnected = function () {
return true
}
// util
-function createSyncProvider(providerConfig){
+function createSyncProvider (providerConfig) {
providerConfig = providerConfig || {}
var syncProviderUrl = undefined
if (providerConfig.rpcTarget) {
syncProviderUrl = providerConfig.rpcTarget
} else {
- switch(providerConfig.type) {
+ switch (providerConfig.type) {
case 'testnet':
syncProviderUrl = MetamaskConfig.network.testnet
break
@@ -110,14 +109,14 @@ function createSyncProvider(providerConfig){
return new HttpProvider(syncProviderUrl)
}
-function remoteStoreWithLocalStorageCache(storageKey){
+function remoteStoreWithLocalStorageCache (storageKey) {
// read local cache
var initState = JSON.parse(localStorage[storageKey] || '{}')
var store = new RemoteStore(initState)
// cache the latest state locally
- store.subscribe(function(state){
+ store.subscribe(function (state) {
localStorage[storageKey] = JSON.stringify(state)
})
return store
-} \ No newline at end of file
+}
diff --git a/app/scripts/lib/local-message-stream.js b/app/scripts/lib/local-message-stream.js
index 76fedd9df..821e51046 100644
--- a/app/scripts/lib/local-message-stream.js
+++ b/app/scripts/lib/local-message-stream.js
@@ -3,10 +3,9 @@ const inherits = require('util').inherits
module.exports = LocalMessageDuplexStream
-
inherits(LocalMessageDuplexStream, Duplex)
-function LocalMessageDuplexStream(opts){
+function LocalMessageDuplexStream (opts) {
Duplex.call(this, {
objectMode: true,
})
@@ -21,19 +20,19 @@ function LocalMessageDuplexStream(opts){
// private
-LocalMessageDuplexStream.prototype._onMessage = function(event){
+LocalMessageDuplexStream.prototype._onMessage = function (event) {
var msg = event.data
// console.log('LocalMessageDuplexStream ('+this._name+') - heard message...', event)
// validate message
- if (event.origin !== location.origin) return //console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (event.origin !== location.origin) ')
- if (typeof msg !== 'object') return //console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (typeof msg !== "object") ')
- if (msg.target !== this._name) return //console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (msg.target !== this._name) ', msg.target, this._name)
- if (!msg.data) return //console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (!msg.data) ')
+ if (event.origin !== location.origin) return // console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (event.origin !== location.origin) ')
+ if (typeof msg !== 'object') return // console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (typeof msg !== "object") ')
+ if (msg.target !== this._name) return // console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (msg.target !== this._name) ', msg.target, this._name)
+ if (!msg.data) return // console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (!msg.data) ')
// console.log('LocalMessageDuplexStream ('+this._name+') - accepted', msg.data)
// forward message
try {
this.push(msg.data)
- } catch(err) {
+ } catch (err) {
this.emit('error', err)
}
}
@@ -42,7 +41,7 @@ LocalMessageDuplexStream.prototype._onMessage = function(event){
LocalMessageDuplexStream.prototype._read = noop
-LocalMessageDuplexStream.prototype._write = function(data, encoding, cb){
+LocalMessageDuplexStream.prototype._write = function (data, encoding, cb) {
// console.log('LocalMessageDuplexStream ('+this._name+') - sending message...')
var message = {
target: this._target,
@@ -54,4 +53,4 @@ LocalMessageDuplexStream.prototype._write = function(data, encoding, cb){
// util
-function noop(){} \ No newline at end of file
+function noop () {}
diff --git a/app/scripts/lib/message-manager.js b/app/scripts/lib/message-manager.js
index 91edb7759..b609b820e 100644
--- a/app/scripts/lib/message-manager.js
+++ b/app/scripts/lib/message-manager.js
@@ -1,50 +1,50 @@
module.exports = new MessageManager()
-function MessageManager(opts) {
+function MessageManager (opts) {
this.messages = []
}
-MessageManager.prototype.getMsgList = function() {
+MessageManager.prototype.getMsgList = function () {
return this.messages
}
-MessageManager.prototype.unconfirmedMsgs = function() {
+MessageManager.prototype.unconfirmedMsgs = function () {
var messages = this.getMsgList()
return messages.filter(msg => msg.status === 'unconfirmed')
.reduce((result, msg) => { result[msg.id] = msg; return result }, {})
}
-MessageManager.prototype._saveMsgList = function(msgList) {
+MessageManager.prototype._saveMsgList = function (msgList) {
this.messages = msgList
}
-MessageManager.prototype.addMsg = function(msg) {
+MessageManager.prototype.addMsg = function (msg) {
var messages = this.getMsgList()
messages.push(msg)
this._saveMsgList(messages)
}
-MessageManager.prototype.getMsg = function(msgId) {
+MessageManager.prototype.getMsg = function (msgId) {
var messages = this.getMsgList()
var matching = messages.filter(msg => msg.id === msgId)
return matching.length > 0 ? matching[0] : null
}
-MessageManager.prototype.confirmMsg = function(msgId) {
+MessageManager.prototype.confirmMsg = function (msgId) {
this._setMsgStatus(msgId, 'confirmed')
}
-MessageManager.prototype.rejectMsg = function(msgId) {
+MessageManager.prototype.rejectMsg = function (msgId) {
this._setMsgStatus(msgId, 'rejected')
}
-MessageManager.prototype._setMsgStatus = function(msgId, status) {
+MessageManager.prototype._setMsgStatus = function (msgId, status) {
var msg = this.getMsg(msgId)
if (msg) msg.status = status
this.updateMsg(msg)
}
-MessageManager.prototype.updateMsg = function(msg) {
+MessageManager.prototype.updateMsg = function (msg) {
var messages = this.getMsgList()
var found, index
messages.forEach((otherMsg, i) => {
diff --git a/app/scripts/lib/notifications.js b/app/scripts/lib/notifications.js
index 90edaea12..af2dc2054 100644
--- a/app/scripts/lib/notifications.js
+++ b/app/scripts/lib/notifications.js
@@ -10,13 +10,12 @@ module.exports = {
setupListeners()
-function setupListeners(){
-
+function setupListeners () {
// guard for chrome bug https://github.com/MetaMask/metamask-plugin/issues/236
if (!chrome.notifications) return console.error('Chrome notifications API missing...')
// notification button press
- chrome.notifications.onButtonClicked.addListener(function(notificationId, buttonIndex){
+ chrome.notifications.onButtonClicked.addListener(function (notificationId, buttonIndex) {
var handlers = notificationHandlers[notificationId]
if (buttonIndex === 0) {
handlers.confirm()
@@ -27,14 +26,13 @@ function setupListeners(){
})
// notification teardown
- chrome.notifications.onClosed.addListener(function(notificationId){
+ chrome.notifications.onClosed.addListener(function (notificationId) {
delete notificationHandlers[notificationId]
})
-
}
// creation helper
-function createUnlockRequestNotification(opts){
+function createUnlockRequestNotification (opts) {
// guard for chrome bug https://github.com/MetaMask/metamask-plugin/issues/236
if (!chrome.notifications) return console.error('Chrome notifications API missing...')
var message = 'An Ethereum app has requested a signature. Please unlock your account.'
@@ -46,18 +44,17 @@ function createUnlockRequestNotification(opts){
title: opts.title,
message: message,
})
-
}
-function createTxNotification(opts){
+function createTxNotification (opts) {
// guard for chrome bug https://github.com/MetaMask/metamask-plugin/issues/236
if (!chrome.notifications) return console.error('Chrome notifications API missing...')
var message = [
- 'Submitted by '+opts.txParams.origin,
- 'to: '+uiUtils.addressSummary(opts.txParams.to),
- 'from: '+uiUtils.addressSummary(opts.txParams.from),
- 'value: '+uiUtils.formatBalance(opts.txParams.value),
- 'data: '+uiUtils.dataSize(opts.txParams.data),
+ 'Submitted by ' + opts.txParams.origin,
+ 'to: ' + uiUtils.addressSummary(opts.txParams.to),
+ 'from: ' + uiUtils.addressSummary(opts.txParams.from),
+ 'value: ' + uiUtils.formatBalance(opts.txParams.value),
+ 'data: ' + uiUtils.dataSize(opts.txParams.data),
].join('\n')
var id = createId()
@@ -69,9 +66,9 @@ function createTxNotification(opts){
message: message,
buttons: [{
title: 'confirm',
- },{
+ }, {
title: 'cancel',
- }]
+ }],
})
notificationHandlers[id] = {
confirm: opts.confirm,
@@ -79,13 +76,13 @@ function createTxNotification(opts){
}
}
-function createMsgNotification(opts){
+function createMsgNotification (opts) {
// guard for chrome bug https://github.com/MetaMask/metamask-plugin/issues/236
if (!chrome.notifications) return console.error('Chrome notifications API missing...')
var message = [
- 'Submitted by '+opts.msgParams.origin,
- 'to be signed by: '+uiUtils.addressSummary(opts.msgParams.from),
- 'message:\n'+opts.msgParams.data,
+ 'Submitted by ' + opts.msgParams.origin,
+ 'to be signed by: ' + uiUtils.addressSummary(opts.msgParams.from),
+ 'message:\n' + opts.msgParams.data,
].join('\n')
var id = createId()
@@ -97,12 +94,12 @@ function createMsgNotification(opts){
message: message,
buttons: [{
title: 'confirm',
- },{
+ }, {
title: 'cancel',
- }]
+ }],
})
notificationHandlers[id] = {
confirm: opts.confirm,
cancel: opts.cancel,
}
-} \ No newline at end of file
+}
diff --git a/app/scripts/lib/obj-multiplex.js b/app/scripts/lib/obj-multiplex.js
index ad1d914f8..f54ff7653 100644
--- a/app/scripts/lib/obj-multiplex.js
+++ b/app/scripts/lib/obj-multiplex.js
@@ -2,11 +2,10 @@ const through = require('through2')
module.exports = ObjectMultiplex
-
-function ObjectMultiplex(opts){
+function ObjectMultiplex (opts) {
opts = opts || {}
// create multiplexer
- var mx = through.obj(function(chunk, enc, cb) {
+ var mx = through.obj(function (chunk, enc, cb) {
var name = chunk.name
var data = chunk.data
var substream = mx.streams[name]
@@ -19,19 +18,19 @@ function ObjectMultiplex(opts){
})
mx.streams = {}
// create substreams
- mx.createStream = function(name) {
- var substream = mx.streams[name] = through.obj(function(chunk, enc, cb) {
+ mx.createStream = function (name) {
+ var substream = mx.streams[name] = through.obj(function (chunk, enc, cb) {
mx.push({
name: name,
data: chunk,
})
return cb()
})
- mx.on('end', function() {
+ mx.on('end', function () {
return substream.emit('end')
})
if (opts.error) {
- mx.on('error', function() {
+ mx.on('error', function () {
return substream.emit('error')
})
}
diff --git a/app/scripts/lib/port-stream.js b/app/scripts/lib/port-stream.js
index 2644741fc..1889e3c04 100644
--- a/app/scripts/lib/port-stream.js
+++ b/app/scripts/lib/port-stream.js
@@ -3,10 +3,9 @@ const inherits = require('util').inherits
module.exports = PortDuplexStream
-
inherits(PortDuplexStream, Duplex)
-function PortDuplexStream(port){
+function PortDuplexStream (port) {
Duplex.call(this, {
objectMode: true,
})
@@ -17,7 +16,7 @@ function PortDuplexStream(port){
// private
-PortDuplexStream.prototype._onMessage = function(msg){
+PortDuplexStream.prototype._onMessage = function (msg) {
if (Buffer.isBuffer(msg)) {
delete msg._isBuffer
var data = new Buffer(msg)
@@ -29,11 +28,11 @@ PortDuplexStream.prototype._onMessage = function(msg){
}
}
-PortDuplexStream.prototype._onDisconnect = function(){
+PortDuplexStream.prototype._onDisconnect = function () {
try {
// this.end()
this.emit('close')
- } catch(err){
+ } catch (err) {
this.emit('error', err)
}
}
@@ -42,7 +41,7 @@ PortDuplexStream.prototype._onDisconnect = function(){
PortDuplexStream.prototype._read = noop
-PortDuplexStream.prototype._write = function(msg, encoding, cb){
+PortDuplexStream.prototype._write = function (msg, encoding, cb) {
try {
if (Buffer.isBuffer(msg)) {
var data = msg.toJSON()
@@ -54,7 +53,7 @@ PortDuplexStream.prototype._write = function(msg, encoding, cb){
this._port.postMessage(msg)
}
cb()
- } catch(err){
+ } catch (err) {
console.error(err)
// this.emit('error', err)
cb(new Error('PortDuplexStream - disconnected'))
@@ -63,4 +62,4 @@ PortDuplexStream.prototype._write = function(msg, encoding, cb){
// util
-function noop(){} \ No newline at end of file
+function noop () {}
diff --git a/app/scripts/lib/remote-store.js b/app/scripts/lib/remote-store.js
index 2dbdde811..fbfab7bad 100644
--- a/app/scripts/lib/remote-store.js
+++ b/app/scripts/lib/remote-store.js
@@ -6,32 +6,32 @@ module.exports = {
RemoteStore: RemoteStore,
}
-function BaseStore(initState){
+function BaseStore (initState) {
this._state = initState || {}
this._subs = []
}
-BaseStore.prototype.set = function(key, value){
+BaseStore.prototype.set = function (key, value) {
throw Error('Not implemented.')
}
-BaseStore.prototype.get = function(key){
+BaseStore.prototype.get = function (key) {
return this._state[key]
}
-BaseStore.prototype.subscribe = function(fn){
+BaseStore.prototype.subscribe = function (fn) {
this._subs.push(fn)
var unsubscribe = this.unsubscribe.bind(this, fn)
return unsubscribe
}
-BaseStore.prototype.unsubscribe = function(fn){
+BaseStore.prototype.unsubscribe = function (fn) {
var index = this._subs.indexOf(fn)
if (index !== -1) this._subs.splice(index, 1)
}
-BaseStore.prototype._emitUpdates = function(state){
- this._subs.forEach(function(handler){
+BaseStore.prototype._emitUpdates = function (state) {
+ this._subs.forEach(function (handler) {
handler(state)
})
}
@@ -41,16 +41,16 @@ BaseStore.prototype._emitUpdates = function(state){
//
inherits(HostStore, BaseStore)
-function HostStore(initState, opts){
+function HostStore (initState, opts) {
BaseStore.call(this, initState)
}
-HostStore.prototype.set = function(key, value){
+HostStore.prototype.set = function (key, value) {
this._state[key] = value
process.nextTick(this._emitUpdates.bind(this, this._state))
}
-HostStore.prototype.createStream = function(){
+HostStore.prototype.createStream = function () {
var dnode = Dnode({
// update: this._didUpdate.bind(this),
})
@@ -58,8 +58,8 @@ HostStore.prototype.createStream = function(){
return dnode
}
-HostStore.prototype._didConnect = function(remote){
- this.subscribe(function(state){
+HostStore.prototype._didConnect = function (remote) {
+ this.subscribe(function (state) {
remote.update(state)
})
remote.update(this._state)
@@ -70,16 +70,16 @@ HostStore.prototype._didConnect = function(remote){
//
inherits(RemoteStore, BaseStore)
-function RemoteStore(initState, opts){
+function RemoteStore (initState, opts) {
BaseStore.call(this, initState)
this._remote = null
}
-RemoteStore.prototype.set = function(key, value){
+RemoteStore.prototype.set = function (key, value) {
this._remote.set(key, value)
}
-RemoteStore.prototype.createStream = function(){
+RemoteStore.prototype.createStream = function () {
var dnode = Dnode({
update: this._didUpdate.bind(this),
})
@@ -87,11 +87,11 @@ RemoteStore.prototype.createStream = function(){
return dnode
}
-RemoteStore.prototype._didConnect = function(remote){
+RemoteStore.prototype._didConnect = function (remote) {
this._remote = remote
}
-RemoteStore.prototype._didUpdate = function(state){
+RemoteStore.prototype._didUpdate = function (state) {
this._state = state
this._emitUpdates(state)
}
diff --git a/app/scripts/lib/stream-utils.js b/app/scripts/lib/stream-utils.js
index ca245ca9a..1b7b89d14 100644
--- a/app/scripts/lib/stream-utils.js
+++ b/app/scripts/lib/stream-utils.js
@@ -1,36 +1,35 @@
const Through = require('through2')
const ObjectMultiplex = require('./obj-multiplex')
-
module.exports = {
jsonParseStream: jsonParseStream,
jsonStringifyStream: jsonStringifyStream,
setupMultiplex: setupMultiplex,
}
-function jsonParseStream(){
- return Through.obj(function(serialized, encoding, cb){
+function jsonParseStream () {
+ return Through.obj(function (serialized, encoding, cb) {
this.push(JSON.parse(serialized))
cb()
})
}
-function jsonStringifyStream(){
- return Through.obj(function(obj, encoding, cb){
+function jsonStringifyStream () {
+ return Through.obj(function (obj, encoding, cb) {
this.push(JSON.stringify(obj))
cb()
})
}
-function setupMultiplex(connectionStream){
+function setupMultiplex (connectionStream) {
var mx = ObjectMultiplex()
connectionStream.pipe(mx).pipe(connectionStream)
- mx.on('error', function(err) {
+ mx.on('error', function (err) {
console.error(err)
})
- connectionStream.on('error', function(err) {
+ connectionStream.on('error', function (err) {
console.error(err)
mx.destroy()
})
return mx
-} \ No newline at end of file
+}