Merge pull request #344 from unusualbob/typosAndServiceDocs

Fix typos and some examples in service doc
This commit is contained in:
Braydon Fuller 2015-10-22 11:52:17 -04:00
commit 5802290591
4 changed files with 17 additions and 16 deletions

View File

@ -121,12 +121,13 @@ MyService.prototype.prototype.blockHandler = function(block, addOutput, callback
var operations = []; var operations = [];
//Timestamp of the current block //Timestamp of the current block
var blocktime = new Buffer(block.header.time); var blocktime = new Buffer(4);
blocktime.writeUInt32BE(block.header.time);
for (var i = 0; i < block.transactions.length; i++) { for (var i = 0; i < block.transactions.length; i++) {
var transaction = block.transactions[i]; var transaction = block.transactions[i];
var txid = new Buffer(transaction.id, 'hex'); var txid = new Buffer(transaction.id, 'hex');
var position = new Buffer(('0000' + i).slice(-5)); var position = new Buffer(('0000' + i).slice(-5), 'hex');
//To be able to query this txid by the block date we create an index, leading with the prefix we //To be able to query this txid by the block date we create an index, leading with the prefix we
//defined earlier, the the current blocktime, and finally a differentiator, in this case the index //defined earlier, the the current blocktime, and finally a differentiator, in this case the index
@ -153,7 +154,7 @@ With our block handler code every transaction in the blockchain will now be inde
```js ```js
MyService.prototype.getTransactionIdsByDate = function(startDate, endDate, callback) { MyService.prototype.getTransactionIdsByDate = function(startDateBuffer, endDateBuffer, callback) {
var error; var error;
var transactions = []; var transactions = [];
@ -162,12 +163,12 @@ MyService.prototype.getTransactionIdsByDate = function(startDate, endDate, callb
var stream = this.node.services.db.store.createReadStream({ var stream = this.node.services.db.store.createReadStream({
gte: Buffer.concat([ gte: Buffer.concat([
MyService.datePrefix, MyService.datePrefix,
new Buffer(startDate), startDateBuffer,
MyService.minPosition MyService.minPosition
]), ]),
lte: Buffer.concat([ lte: Buffer.concat([
MyService.datePrefix, MyService.datePrefix,
new Buffer(endDate), endDateBuffer,
MyService.maxPosition MyService.maxPosition
]), ]),
valueEncoding: 'binary', valueEncoding: 'binary',
@ -205,11 +206,11 @@ Since leveldb is just a simple key-value store we need something to differentiat
//A simple example of indexing the number of inputs and ouputs given a transaction id //A simple example of indexing the number of inputs and ouputs given a transaction id
/** Wrong way **/ /** Wrong way **/
var index1key = new Buffer(transaction.id); var index1key = new Buffer(transaction.id, 'hex');
var index1value = transaction.inputs.length; var index1value = transaction.inputs.length;
//Since this key has the same value it would just overwrite index1 when we write to the db //Since this key has the same value it would just overwrite index1 when we write to the db
var index2key = new Buffer(transaction.id); var index2key = new Buffer(transaction.id, 'hex');
var index2value = transaction.outputs.length; var index2value = transaction.outputs.length;
@ -217,11 +218,11 @@ var index2value = transaction.outputs.length;
var index1prefix = new Buffer('11', 'hex'); var index1prefix = new Buffer('11', 'hex');
var index2prefix = new Buffer('12', 'hex'); var index2prefix = new Buffer('12', 'hex');
var index1key = Buffer.concat([index1prefix, new Buffer(transaction.id)]); var index1key = Buffer.concat([index1prefix, new Buffer(transaction.id, 'hex')]);
var index1value = transaction.inputs.length; var index1value = transaction.inputs.length;
//Now that the keys are different, this won't overwrite the index //Now that the keys are different, this won't overwrite the index
var index2key = Buffer.concat([index2prefix, new Buffer(transaction.id)]); var index2key = Buffer.concat([index2prefix, new Buffer(transaction.id, 'hex')]);
var index2value = transaction.outputs.length; var index2value = transaction.outputs.length;
``` ```

View File

@ -22,7 +22,7 @@ var AddressHistory = require('./history');
* The Address Service builds upon the Database Service and the Bitcoin Service to add additional * The Address Service builds upon the Database Service and the Bitcoin Service to add additional
* functionality for getting information by base58check encoded addresses. This includes getting the * functionality for getting information by base58check encoded addresses. This includes getting the
* balance for an address, the history for a collection of addresses, and unspent outputs for * balance for an address, the history for a collection of addresses, and unspent outputs for
* contstructing transactions. This is typically the core functionality for building a wallet. * constructing transactions. This is typically the core functionality for building a wallet.
* @param {Object} options * @param {Object} options
* @param {Node} options.node - An instance of the node * @param {Node} options.node - An instance of the node
* @param {String} options.name - An optional name of the service * @param {String} options.name - An optional name of the service
@ -174,7 +174,7 @@ AddressService.prototype.transactionHandler = function(txInfo) {
* satoshis - Total number of satoshis * satoshis - Total number of satoshis
* script - The script as a hex string * script - The script as a hex string
* *
* mempoolInputIndex, an object keyed by base58check encoded addreses with values: * mempoolInputIndex, an object keyed by base58check encoded addresses with values:
* txid - A hex string of the transaction hash * txid - A hex string of the transaction hash
* inputIndex - A number of the corresponding input * inputIndex - A number of the corresponding input
* *
@ -687,7 +687,7 @@ AddressService.prototype.unsubscribe = function(name, emitter, addresses) {
/** /**
* A helper function for the `unsubscribe` method to unsubscribe from all addresses. * A helper function for the `unsubscribe` method to unsubscribe from all addresses.
* @param {String} name - The name of the event * @param {String} name - The name of the event
* @param {EventEmitter} emiter - An instance of an event emitter * @param {EventEmitter} emitter - An instance of an event emitter
*/ */
AddressService.prototype.unsubscribeAll = function(name, emitter) { AddressService.prototype.unsubscribeAll = function(name, emitter) {
$.checkArgument(emitter instanceof EventEmitter, 'First argument is expected to be an EventEmitter'); $.checkArgument(emitter instanceof EventEmitter, 'First argument is expected to be an EventEmitter');

View File

@ -195,7 +195,7 @@ Bitcoin.prototype.syncPercentage = function() {
}; };
/** /**
* Will retreive a block as a Node.js Buffer from disk. * Will retrieve a block as a Node.js Buffer from disk.
* @param {String|Number} block - A block hash or block height number * @param {String|Number} block - A block hash or block height number
*/ */
Bitcoin.prototype.getBlock = function(block, callback) { Bitcoin.prototype.getBlock = function(block, callback) {
@ -266,7 +266,7 @@ Bitcoin.prototype.getTransaction = function(txid, queryMempool, callback) {
}; };
/** /**
* Will get a transation with additional information about the block, in the format: * Will get a transaction with additional information about the block, in the format:
* { * {
* blockHash: '2725743288feae6bdaa976590af7cb12d7b535b5a242787de6d2789c73682ed1', * blockHash: '2725743288feae6bdaa976590af7cb12d7b535b5a242787de6d2789c73682ed1',
* height: 48, * height: 48,

View File

@ -12,7 +12,7 @@ var log = index.log;
var fs = require('fs'); var fs = require('fs');
/** /**
* This service respresents a hub for combining several services over a single HTTP port. Services * This service represents a hub for combining several services over a single HTTP port. Services
* can extend routes by implementing the methods `getRoutePrefix` and `setupRoutes`. Additionally * can extend routes by implementing the methods `getRoutePrefix` and `setupRoutes`. Additionally
* events that are exposed via the `getPublishEvents` and API methods exposed via `getAPIMethods` * events that are exposed via the `getPublishEvents` and API methods exposed via `getAPIMethods`
* will be available over a socket.io connection. * will be available over a socket.io connection.
@ -99,7 +99,7 @@ WebService.prototype.setupAllRoutes = function() {
}; };
/** /**
* This function will contruct an API methods map of all of the * This function will construct an API methods map of all of the
* available methods that can be called from enable services. * available methods that can be called from enable services.
*/ */
WebService.prototype.createMethodsMap = function() { WebService.prototype.createMethodsMap = function() {