This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const Rx = require('rx'); | |
module.exports = function addFilterObservableToWeb3(web3) { | |
web3.eth.filterObservable = function(_options) { | |
const filter = web3.eth.filter(_options); | |
return Rx.Observable.create(function(observer) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Promise = require("bluebird"); | |
/** | |
* @param {!Object.<function.<Promise.<Any>>>} promiseObject. Each key maps to a function | |
* that returns a promise. | |
* @returns {!Promise.<Object.<Any>>} The results of the promises passed to the function. | |
*/ | |
module.exports = function sequentialPromiseNamed(promiseObject) { | |
const result = Object.keys(promiseObject).reduce( | |
(reduced, key) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Promise = require("bluebird"); | |
/** | |
* @param {!Array.<function.Promise.<Any>>} promiseArray. | |
* @returns {!Promise.<Array.<Any>>} The results of the promises passed to the function. | |
*/ | |
module.exports = function sequentialPromise(promiseArray) { | |
const result = promiseArray.reduce( | |
(reduced, promise, index) => { | |
reduced.results.push(undefined); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
promisify: function (web3) { | |
// Pipes values from a Web3 callback. | |
var callbackToResolve = function (resolve, reject) { | |
return function (error, value) { | |
if (error) { | |
reject(error); | |
} else { | |
resolve(value); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Rx = require('rx'); | |
module.exports = { | |
rxify: function (web3) { | |
// List synchronous functions masquerading as values. | |
var syncGetters = { | |
db: [], | |
eth: [ "accounts", "blockNumber", "coinbase", "gasPrice", "hashrate", | |
"mining", "protocolVersion", "syncing" ], | |
net: [ "listening", "peerCount" ], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getEventsPromise= function (myFilter, count, timeOut) { | |
timeOut = timeOut ? timeOut : 30000; | |
var promise = new Promise(function (resolve, reject) { | |
count = (typeof count !== "undefined") ? count : 1; | |
var results = []; | |
var toClear = setTimeout(function () { | |
reject("Timed out"); | |
}, timeOut); | |
myFilter.watch(function (error, result) { | |
if (error) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
web3.eth.filter("pending").watch(function() { | |
if (eth.mining) return; | |
console.log(new Date() + "-- Transactions detected, so starting mining."); | |
miner.start(1); | |
}); | |
web3.eth.filter('latest', function(error, result) { | |
console.log(new Date() + "-- Got latest, so stopping mining"); | |
miner.stop(); | |
if (txpool.status.pending > 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
/** | |
* @param {!Function.<!Promise>} action. | |
* @param {!Number | !string | !BigNumber} gasToUse. | |
* @returns {!Promise} which throws unless it hit a valid error. | |
*/ | |
module.exports = function expectedExceptionPromise(action, gasToUse) { | |
return new Promise(function (resolve, reject) { | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
web3.eth.getFirstAccountPromise = function () { | |
// https://gist.github.com/xavierlepretre/ed82f210df0f9300493d5ca79893806a | |
return web3.eth.getAccountsPromise() | |
.then(function (accounts) { | |
if (accounts.length > 0) { | |
return accounts[0]; | |
} else if (typeof(mist) !== "undefined") { | |
// https://gist.github.com/xavierlepretre/ee456323b2544dd4da22cd5fa6d2894c | |
return mist.requestAccountPromise(); | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof(mist) !== "undefined") { | |
mist.requestAccountPromise = function () { | |
return new Promise (function (resolve, reject) { | |
mist.requestAccount(function(e, account) { | |
if(e != null) { | |
reject(e); | |
} else { | |
resolve(account); | |
} | |
}); |
NewerOlder