-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
436 additions
and
39 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
You should have received a copy of the GNU Lesser General Public License | ||
along with web3.js. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
/** | ||
/** | ||
* @file formatters.js | ||
* @author Marek Kotewicz <[email protected]> | ||
* @author Fabian Vogelsteller <[email protected]> | ||
|
@@ -81,7 +81,7 @@ var inputCallFormatter = function (options){ | |
options[key] = utils.fromDecimal(options[key]); | ||
}); | ||
|
||
return options; | ||
return options; | ||
}; | ||
|
||
/** | ||
|
@@ -106,12 +106,12 @@ var inputTransactionFormatter = function (options){ | |
options[key] = utils.fromDecimal(options[key]); | ||
}); | ||
|
||
return options; | ||
return options; | ||
}; | ||
|
||
/** | ||
* Formats the output of a transaction to its proper values | ||
* | ||
* | ||
* @method outputTransactionFormatter | ||
* @param {Object} tx | ||
* @returns {Object} | ||
|
@@ -130,7 +130,7 @@ var outputTransactionFormatter = function (tx){ | |
|
||
/** | ||
* Formats the output of a transaction receipt to its proper values | ||
* | ||
* | ||
* @method outputTransactionReceiptFormatter | ||
* @param {Object} receipt | ||
* @returns {Object} | ||
|
@@ -156,7 +156,7 @@ var outputTransactionReceiptFormatter = function (receipt){ | |
* Formats the output of a block to its proper values | ||
* | ||
* @method outputBlockFormatter | ||
* @param {Object} block | ||
* @param {Object} block | ||
* @returns {Object} | ||
*/ | ||
var outputBlockFormatter = function(block) { | ||
|
@@ -184,7 +184,7 @@ var outputBlockFormatter = function(block) { | |
|
||
/** | ||
* Formats the input of a log | ||
* | ||
* | ||
* @method inputLogFormatter | ||
* @param {Object} log object | ||
* @returns {Object} log | ||
|
@@ -214,12 +214,15 @@ var inputLogFormatter = function(options) { | |
if(options.address && !utils.isAddress(options.address)) | ||
throw new Error('The given address is not valid!'); | ||
|
||
// if(options.address) | ||
// options.address = options.address.toLowerCase(); | ||
|
||
return options; | ||
}; | ||
|
||
/** | ||
* Formats the output of a log | ||
* | ||
* | ||
* @method outputLogFormatter | ||
* @param {Object} log object | ||
* @returns {Object} log | ||
|
@@ -260,7 +263,7 @@ var inputPostFormatter = function(post) { | |
return (topic.indexOf('0x') === 0) ? topic : utils.fromUtf8(topic); | ||
}); | ||
|
||
return post; | ||
return post; | ||
}; | ||
|
||
/** | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
You should have received a copy of the GNU Lesser General Public License | ||
along with web3.js. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
/** | ||
/** | ||
* @file requestmanager.js | ||
* @author Jeffrey Wilcke <[email protected]> | ||
* @author Marek Kotewicz <[email protected]> | ||
|
@@ -70,11 +70,13 @@ RequestManager.prototype.send = function (data) { | |
* @param {Function} callback | ||
*/ | ||
RequestManager.prototype.sendAsync = function (data, callback) { | ||
callback = callback || function(){}; | ||
|
||
if (!this.provider) { | ||
return callback(errors.InvalidProvider()); | ||
} | ||
var payload = Jsonrpc.getInstance().toPayload(data.method, data.params); | ||
this.provider.sendAsync(payload, function (err, result) { | ||
this.provider.sendAsync(payload, function (err, result) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
|
@@ -110,7 +112,7 @@ RequestManager.prototype.sendBatch = function (data, callback) { | |
} | ||
|
||
callback(err, results); | ||
}); | ||
}); | ||
}; | ||
|
||
|
||
|
@@ -119,9 +121,11 @@ RequestManager.prototype.sendBatch = function (data, callback) { | |
* | ||
* @method addSubscription | ||
* @param {String} id the subscription id | ||
* @param {String} name the subscription name | ||
* @param {String} type the subscription namespace (eth, personal, etc) | ||
* @param {Function} callback the callback to call for incoming notifications | ||
*/ | ||
RequestManager.prototype.addSubscription = function (name, type, id, callback) { | ||
RequestManager.prototype.addSubscription = function (id, name, type, callback) { | ||
if(this.provider.on) { | ||
this.subscriptions[id] = { | ||
callback: callback, | ||
|
@@ -149,16 +153,10 @@ RequestManager.prototype.removeSubscription = function (id, callback) { | |
this.sendAsync({ | ||
method: this.subscriptions[id].type + '_unsubscribe', | ||
params: [id] | ||
}, function(err, result){ | ||
|
||
if(!err) { | ||
delete _this.subscriptions[id]; | ||
} | ||
|
||
if(utils.isFunction(callback)) | ||
callback(err, result); | ||
}); | ||
}, callback); | ||
|
||
// remove subscription | ||
delete _this.subscriptions[id]; | ||
} | ||
}; | ||
|
||
|
@@ -179,10 +177,16 @@ RequestManager.prototype.setProvider = function (p) { | |
|
||
// listen to incoming notifications | ||
if(this.provider && this.provider.on) { | ||
this.provider.on('notification', function(err, result){ | ||
this.provider.on('notification', function requestManagerNotification(err, result){ | ||
if(!err) { | ||
if(_this.subscriptions[result.params.subscription] && _this.subscriptions[result.params.subscription].callback) | ||
_this.subscriptions[result.params.subscription].callback(null, result.params.result); | ||
} else { | ||
|
||
Object.keys(_this.subscriptions).forEach(function(id){ | ||
if(_this.subscriptions[id].callback) | ||
_this.subscriptions[id].callback(err); | ||
}); | ||
} | ||
}); | ||
} | ||
|
Oops, something went wrong.