walletdb: list blocks.

This commit is contained in:
Christopher Jeffrey 2016-11-04 19:10:42 -07:00
parent 8d624f1b0e
commit 5069ec1bfb
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
8 changed files with 64 additions and 4 deletions

12
bin/cli
View File

@ -320,10 +320,15 @@ CLI.prototype.getDetails = co(function* getDetails() {
this.log(details);
});
CLI.prototype.getWalletBlocks = co(function* getWalletBlocks() {
var blocks = yield this.wallet.getBlocks();
this.log(blocks);
});
CLI.prototype.getWalletBlock = co(function* getWalletBlock() {
var height = this.argv[0] | 0;
var details = yield this.wallet.getBlock(height);
this.log(details);
var block = yield this.wallet.getBlock(height);
this.log(block);
});
CLI.prototype.retoken = co(function* retoken() {
@ -486,6 +491,8 @@ CLI.prototype.handleWallet = co(function* handleWallet() {
return yield this.zapWallet();
case 'tx':
return yield this.getDetails();
case 'blocks':
return yield this.getWalletBlocks();
case 'block':
return yield this.getWalletBlock();
case 'view':
@ -526,6 +533,7 @@ CLI.prototype.handleWallet = co(function* handleWallet() {
this.log(' $ sign [tx-hex]: Sign transaction.');
this.log(' $ zap [age?]: Zap pending wallet TXs.');
this.log(' $ tx [hash]: View transaction details.');
this.log(' $ blocks: List wallet blocks.');
this.log(' $ block [height]: View wallet block.');
this.log(' $ view [tx-hex]: Parse and view transaction.');
this.log(' $ import [wif|hex]: Import private or public key.');

View File

@ -541,6 +541,17 @@ HTTPClient.prototype.getWalletTX = function getWalletTX(id, hash) {
return this._get('/wallet/' + id + '/tx/' + hash);
};
/**
* Get wallet blocks.
* @param {WalletID} id
* @param {Number} height
* @returns {Promise}
*/
HTTPClient.prototype.getWalletBlocks = function getWalletBlocks(id) {
return this._get('/wallet/' + id + '/block');
};
/**
* Get wallet block.
* @param {WalletID} id

View File

@ -917,6 +917,12 @@ HTTPServer.prototype._init = function _init() {
send(200, { success: true });
}));
// List blocks
this.get('/wallet/:id/block', con(function* (req, res, send, next) {
var heights = yield req.wallet.getBlocks();
send(200, heights);
}));
// Get Block Record
this.get('/wallet/:id/block/:height', con(function* (req, res, send, next) {
var height = req.options.height;

View File

@ -198,6 +198,14 @@ HTTPWallet.prototype.getTX = function getTX(hash) {
return this.client.getWalletTX(this.id, hash);
};
/**
* @see Wallet#getBlocks
*/
HTTPWallet.prototype.getBlocks = function getBlocks() {
return this.client.getWalletBlocks(this.id);
};
/**
* @see Wallet#getBlock
*/

View File

@ -199,7 +199,8 @@ layout.txdb = {
return 'b' + pad32(height);
},
bb: function bb(key) {
return +key.slice(1);
key = key.slice(12);
return +key.slice(0);
}
};

View File

@ -198,7 +198,8 @@ var layout = {
return key;
},
bb: function bb(key) {
return key.readUInt32BE(1, true);
key = key.slice(6);
return key.readUInt32BE(0, true);
}
};
@ -974,6 +975,19 @@ TXDB.prototype.removeBlockMap = co(function* removeBlockMap(tx, height) {
this.walletdb.writeBlockMap(this.wallet, height, block);
});
/**
* List block records.
* @returns {Promise}
*/
TXDB.prototype.getBlocks = function getBlocks() {
return this.keys({
gte: layout.b(0),
lte: layout.b(0xffffffff),
parse: layout.bb
});
};
/**
* Get block record.
* @param {Number} height

View File

@ -1984,6 +1984,15 @@ Wallet.prototype.getTX = function getTX(hash) {
return this.txdb.getTX(hash);
};
/**
* List blocks for the wallet.
* @returns {Promise} - Returns {@link BlockRecord}.
*/
Wallet.prototype.getBlocks = function getBlocks() {
return this.txdb.getBlocks();
};
/**
* Get a block from the wallet.
* @param {Number} height

View File

@ -846,8 +846,11 @@ WalletDB.prototype._rename = co(function* _rename(wallet, id) {
WalletDB.prototype.renameAccount = function renameAccount(account, name) {
var wallet = account.wallet;
var batch = this.batch(wallet);
batch.del(layout.i(account.wid, account.name));
account.name = name;
this.saveAccount(account);
};