walletdb: list blocks.
This commit is contained in:
parent
8d624f1b0e
commit
5069ec1bfb
12
bin/cli
12
bin/cli
@ -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.');
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user