rename methods to getAPIMethods
This commit is contained in:
parent
fd8ee3ba9d
commit
9108b0f695
@ -104,9 +104,9 @@ $ tail -f ~/.bitcoin/debug.log
|
|||||||
Bitcoind.js has a module system where additional information can be indexed and queried from
|
Bitcoind.js has a module system where additional information can be indexed and queried from
|
||||||
the blockchain. One built-in module is the address module which exposes the API methods for getting balances and outputs.
|
the blockchain. One built-in module is the address module which exposes the API methods for getting balances and outputs.
|
||||||
|
|
||||||
### Writing a module
|
### Writing a Module
|
||||||
|
|
||||||
A new module can be created by inheriting from `BitcoindJS.Module`, implementing the methods() and blockHandler() methods, and any additional methods for querying the data. Here is an example:
|
A new module can be created by inheriting from `BitcoindJS.Module`, implementing the methods `blockHandler()` and `getAPIMethods()`, and any additional methods for querying the data. Here is an example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var inherits = require('util').inherits;
|
var inherits = require('util').inherits;
|
||||||
@ -152,7 +152,7 @@ MyModule.prototype.blockHandler = function(block, add, callback) {
|
|||||||
* the API methods to expose
|
* the API methods to expose
|
||||||
* @return {Array} return array of methods
|
* @return {Array} return array of methods
|
||||||
*/
|
*/
|
||||||
MyModule.prototype.methods = function() {
|
MyModule.prototype.getAPIMethods = function() {
|
||||||
return [
|
return [
|
||||||
['getData', this, this.getData, 1]
|
['getData', this, this.getData, 1]
|
||||||
];
|
];
|
||||||
|
|||||||
@ -215,7 +215,7 @@ DB.prototype.getAPIMethods = function() {
|
|||||||
];
|
];
|
||||||
|
|
||||||
for(var i = 0; i < this.modules.length; i++) {
|
for(var i = 0; i < this.modules.length; i++) {
|
||||||
methods = methods.concat(this.modules[i]['methods'].call(this.modules[i]));
|
methods = methods.concat(this.modules[i]['getAPIMethods'].call(this.modules[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return methods;
|
return methods;
|
||||||
|
|||||||
@ -19,7 +19,7 @@ Module.prototype.blockHandler = function(block, add, callback) {
|
|||||||
* the API methods to expose
|
* the API methods to expose
|
||||||
* @return {Array} return array of methods
|
* @return {Array} return array of methods
|
||||||
*/
|
*/
|
||||||
Module.prototype.methods = function() {
|
Module.prototype.getAPIMethods = function() {
|
||||||
// Example:
|
// Example:
|
||||||
// return [
|
// return [
|
||||||
// ['getData', this, this.getData, 1]
|
// ['getData', this, this.getData, 1]
|
||||||
|
|||||||
@ -20,7 +20,7 @@ AddressModule.PREFIXES = {
|
|||||||
OUTPUTS: 'outs'
|
OUTPUTS: 'outs'
|
||||||
};
|
};
|
||||||
|
|
||||||
AddressModule.prototype.methods = function() {
|
AddressModule.prototype.getAPIMethods = function() {
|
||||||
return [
|
return [
|
||||||
['getBalance', this, this.getBalance, 2],
|
['getBalance', this, this.getBalance, 2],
|
||||||
['getOutputs', this, this.getOutputs, 2],
|
['getOutputs', this, this.getOutputs, 2],
|
||||||
|
|||||||
@ -265,12 +265,12 @@ describe('Bitcoin DB', function() {
|
|||||||
var db = new DB({store: memdown});
|
var db = new DB({store: memdown});
|
||||||
db.modules = [];
|
db.modules = [];
|
||||||
var methods = db.getAPIMethods();
|
var methods = db.getAPIMethods();
|
||||||
methods.length.should.equal(1);
|
methods.length.should.equal(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should also return modules methods', function() {
|
it('should also return modules API methods', function() {
|
||||||
var module1 = {
|
var module1 = {
|
||||||
methods: function() {
|
getAPIMethods: function() {
|
||||||
return [
|
return [
|
||||||
['module1-one', module1, module1, 2],
|
['module1-one', module1, module1, 2],
|
||||||
['module1-two', module1, module1, 2]
|
['module1-two', module1, module1, 2]
|
||||||
@ -278,7 +278,7 @@ describe('Bitcoin DB', function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
var module2 = {
|
var module2 = {
|
||||||
methods: function() {
|
getAPIMethods: function() {
|
||||||
return [
|
return [
|
||||||
['moudle2-one', module2, module2, 1]
|
['moudle2-one', module2, module2, 1]
|
||||||
];
|
];
|
||||||
@ -289,7 +289,7 @@ describe('Bitcoin DB', function() {
|
|||||||
db.modules = [module1, module2];
|
db.modules = [module1, module2];
|
||||||
|
|
||||||
var methods = db.getAPIMethods();
|
var methods = db.getAPIMethods();
|
||||||
methods.length.should.equal(4);
|
methods.length.should.equal(5);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -13,10 +13,10 @@ var errors = bitcoindjs.errors;
|
|||||||
|
|
||||||
describe('AddressModule', function() {
|
describe('AddressModule', function() {
|
||||||
|
|
||||||
describe('#methods', function() {
|
describe('#getAPIMethods', function() {
|
||||||
it('should return the correct methods', function() {
|
it('should return the correct methods', function() {
|
||||||
var am = new AddressModule({});
|
var am = new AddressModule({});
|
||||||
var methods = am.methods();
|
var methods = am.getAPIMethods();
|
||||||
methods.length.should.equal(4);
|
methods.length.should.equal(4);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user