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
|
||||
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
|
||||
var inherits = require('util').inherits;
|
||||
@ -152,7 +152,7 @@ MyModule.prototype.blockHandler = function(block, add, callback) {
|
||||
* the API methods to expose
|
||||
* @return {Array} return array of methods
|
||||
*/
|
||||
MyModule.prototype.methods = function() {
|
||||
MyModule.prototype.getAPIMethods = function() {
|
||||
return [
|
||||
['getData', this, this.getData, 1]
|
||||
];
|
||||
|
||||
@ -215,7 +215,7 @@ DB.prototype.getAPIMethods = function() {
|
||||
];
|
||||
|
||||
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;
|
||||
|
||||
@ -19,7 +19,7 @@ Module.prototype.blockHandler = function(block, add, callback) {
|
||||
* the API methods to expose
|
||||
* @return {Array} return array of methods
|
||||
*/
|
||||
Module.prototype.methods = function() {
|
||||
Module.prototype.getAPIMethods = function() {
|
||||
// Example:
|
||||
// return [
|
||||
// ['getData', this, this.getData, 1]
|
||||
|
||||
@ -20,7 +20,7 @@ AddressModule.PREFIXES = {
|
||||
OUTPUTS: 'outs'
|
||||
};
|
||||
|
||||
AddressModule.prototype.methods = function() {
|
||||
AddressModule.prototype.getAPIMethods = function() {
|
||||
return [
|
||||
['getBalance', this, this.getBalance, 2],
|
||||
['getOutputs', this, this.getOutputs, 2],
|
||||
|
||||
@ -265,12 +265,12 @@ describe('Bitcoin DB', function() {
|
||||
var db = new DB({store: memdown});
|
||||
db.modules = [];
|
||||
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 = {
|
||||
methods: function() {
|
||||
getAPIMethods: function() {
|
||||
return [
|
||||
['module1-one', module1, module1, 2],
|
||||
['module1-two', module1, module1, 2]
|
||||
@ -278,7 +278,7 @@ describe('Bitcoin DB', function() {
|
||||
}
|
||||
};
|
||||
var module2 = {
|
||||
methods: function() {
|
||||
getAPIMethods: function() {
|
||||
return [
|
||||
['moudle2-one', module2, module2, 1]
|
||||
];
|
||||
@ -289,7 +289,7 @@ describe('Bitcoin DB', function() {
|
||||
db.modules = [module1, module2];
|
||||
|
||||
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('#methods', function() {
|
||||
describe('#getAPIMethods', function() {
|
||||
it('should return the correct methods', function() {
|
||||
var am = new AddressModule({});
|
||||
var methods = am.methods();
|
||||
var methods = am.getAPIMethods();
|
||||
methods.length.should.equal(4);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user