mirror of https://github.com/status-im/web3.js.git
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
var formatters = require('./formatters');
|
|
var utils = require('./../utils/utils');
|
|
var Method = require('./method');
|
|
var Property = require('./property');
|
|
|
|
// TODO: refactor, so the input params are not altered.
|
|
// it's necessary to make same 'extension' work with multiple providers
|
|
var extend = function (web3) {
|
|
var ex = function (extension) {
|
|
|
|
var extendedObject;
|
|
if (extension.property) {
|
|
if (!web3[extension.property]) {
|
|
web3[extension.property] = {};
|
|
}
|
|
extendedObject = web3[extension.property];
|
|
} else {
|
|
extendedObject = web3;
|
|
}
|
|
|
|
if (extension.methods) {
|
|
extension.methods.forEach(function (method) {
|
|
method.attachToObject(extendedObject);
|
|
method.setRequestManager(web3._requestManager);
|
|
});
|
|
}
|
|
|
|
if (extension.properties) {
|
|
extension.properties.forEach(function (property) {
|
|
property.attachToObject(extendedObject);
|
|
property.setRequestManager(web3._requestManager);
|
|
});
|
|
}
|
|
};
|
|
|
|
ex.formatters = formatters;
|
|
ex.utils = utils;
|
|
ex.Method = Method;
|
|
ex.Property = Property;
|
|
|
|
return ex;
|
|
};
|
|
|
|
|
|
|
|
module.exports = extend;
|
|
|