diff --git a/README.md b/README.md index 4d32ff89..4ce25789 100644 --- a/README.md +++ b/README.md @@ -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] ]; diff --git a/lib/db.js b/lib/db.js index 12201676..7d7b6298 100644 --- a/lib/db.js +++ b/lib/db.js @@ -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; diff --git a/lib/module.js b/lib/module.js index 8d87d42d..1acce6c4 100644 --- a/lib/module.js +++ b/lib/module.js @@ -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] diff --git a/lib/modules/address.js b/lib/modules/address.js index 4b21e05b..fd340069 100644 --- a/lib/modules/address.js +++ b/lib/modules/address.js @@ -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], diff --git a/test/db.unit.js b/test/db.unit.js index 96a75339..035d23e8 100644 --- a/test/db.unit.js +++ b/test/db.unit.js @@ -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); }); }); diff --git a/test/modules/address.unit.js b/test/modules/address.unit.js index d5c10499..2741dfbc 100644 --- a/test/modules/address.unit.js +++ b/test/modules/address.unit.js @@ -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); }); });