wallet: refactor and comments.
This commit is contained in:
parent
4f46bb3324
commit
10ee1dce6e
@ -74,7 +74,7 @@ function Wallet(db, options) {
|
|||||||
this.accountDepth = 0;
|
this.accountDepth = 0;
|
||||||
this.token = constants.ZERO_HASH;
|
this.token = constants.ZERO_HASH;
|
||||||
this.tokenDepth = 0;
|
this.tokenDepth = 0;
|
||||||
this.tx = new TXDB(this);
|
this.txdb = new TXDB(this);
|
||||||
|
|
||||||
this.account = null;
|
this.account = null;
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ Wallet.prototype.init = co(function* init(options) {
|
|||||||
|
|
||||||
this.logger.info('Wallet initialized (%s).', this.id);
|
this.logger.info('Wallet initialized (%s).', this.id);
|
||||||
|
|
||||||
yield this.tx.open();
|
yield this.txdb.open();
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -206,7 +206,7 @@ Wallet.prototype.open = co(function* open() {
|
|||||||
|
|
||||||
this.logger.info('Wallet opened (%s).', this.id);
|
this.logger.info('Wallet opened (%s).', this.id);
|
||||||
|
|
||||||
yield this.tx.open();
|
yield this.txdb.open();
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1155,7 +1155,7 @@ Wallet.prototype._fund = co(function* fund(tx, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Don't use any locked coins.
|
// Don't use any locked coins.
|
||||||
coins = this.tx.filterLocked(coins);
|
coins = this.txdb.filterLocked(coins);
|
||||||
|
|
||||||
tx.fund(coins, {
|
tx.fund(coins, {
|
||||||
selection: options.selection,
|
selection: options.selection,
|
||||||
@ -1609,7 +1609,7 @@ Wallet.prototype.sign = co(function* sign(tx, options) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.fillCoins = function fillCoins(tx) {
|
Wallet.prototype.fillCoins = function fillCoins(tx) {
|
||||||
return this.tx.fillCoins(tx);
|
return this.txdb.fillCoins(tx);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1619,7 +1619,7 @@ Wallet.prototype.fillCoins = function fillCoins(tx) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.fillHistory = function fillHistory(tx) {
|
Wallet.prototype.fillHistory = function fillHistory(tx) {
|
||||||
return this.tx.fillHistory(tx);
|
return this.txdb.fillHistory(tx);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1629,7 +1629,7 @@ Wallet.prototype.fillHistory = function fillHistory(tx) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.toDetails = function toDetails(tx) {
|
Wallet.prototype.toDetails = function toDetails(tx) {
|
||||||
return this.tx.toDetails(tx);
|
return this.txdb.toDetails(tx);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1639,7 +1639,7 @@ Wallet.prototype.toDetails = function toDetails(tx) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getDetails = function getDetails(tx) {
|
Wallet.prototype.getDetails = function getDetails(tx) {
|
||||||
return this.tx.getDetails(tx);
|
return this.txdb.getDetails(tx);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1650,7 +1650,7 @@ Wallet.prototype.getDetails = function getDetails(tx) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getCoin = function getCoin(hash, index) {
|
Wallet.prototype.getCoin = function getCoin(hash, index) {
|
||||||
return this.tx.getCoin(hash, index);
|
return this.txdb.getCoin(hash, index);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1660,7 +1660,7 @@ Wallet.prototype.getCoin = function getCoin(hash, index) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getTX = function getTX(hash) {
|
Wallet.prototype.getTX = function getTX(hash) {
|
||||||
return this.tx.getTX(hash);
|
return this.txdb.getTX(hash);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1681,7 +1681,7 @@ Wallet.prototype.addTX = function addTX(tx) {
|
|||||||
|
|
||||||
Wallet.prototype.getHistory = co(function* getHistory(account) {
|
Wallet.prototype.getHistory = co(function* getHistory(account) {
|
||||||
account = yield this._getIndex(account);
|
account = yield this._getIndex(account);
|
||||||
return this.tx.getHistory(account);
|
return this.txdb.getHistory(account);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1692,7 +1692,7 @@ Wallet.prototype.getHistory = co(function* getHistory(account) {
|
|||||||
|
|
||||||
Wallet.prototype.getCoins = co(function* getCoins(account) {
|
Wallet.prototype.getCoins = co(function* getCoins(account) {
|
||||||
account = yield this._getIndex(account);
|
account = yield this._getIndex(account);
|
||||||
return yield this.tx.getCoins(account);
|
return yield this.txdb.getCoins(account);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1703,7 +1703,7 @@ Wallet.prototype.getCoins = co(function* getCoins(account) {
|
|||||||
|
|
||||||
Wallet.prototype.getUnconfirmed = co(function* getUnconfirmed(account) {
|
Wallet.prototype.getUnconfirmed = co(function* getUnconfirmed(account) {
|
||||||
account = yield this._getIndex(account);
|
account = yield this._getIndex(account);
|
||||||
return yield this.tx.getUnconfirmed(account);
|
return yield this.txdb.getUnconfirmed(account);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1714,7 +1714,7 @@ Wallet.prototype.getUnconfirmed = co(function* getUnconfirmed(account) {
|
|||||||
|
|
||||||
Wallet.prototype.getBalance = co(function* getBalance(account) {
|
Wallet.prototype.getBalance = co(function* getBalance(account) {
|
||||||
account = yield this._getIndex(account);
|
account = yield this._getIndex(account);
|
||||||
return yield this.tx.getBalance(account);
|
return yield this.txdb.getBalance(account);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1732,7 +1732,7 @@ Wallet.prototype.getRange = co(function* getRange(account, options) {
|
|||||||
account = null;
|
account = null;
|
||||||
}
|
}
|
||||||
account = yield this._getIndex(account);
|
account = yield this._getIndex(account);
|
||||||
return yield this.tx.getRange(account, options);
|
return yield this.txdb.getRange(account, options);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1744,7 +1744,7 @@ Wallet.prototype.getRange = co(function* getRange(account, options) {
|
|||||||
|
|
||||||
Wallet.prototype.getLast = co(function* getLast(account, limit) {
|
Wallet.prototype.getLast = co(function* getLast(account, limit) {
|
||||||
account = yield this._getIndex(account);
|
account = yield this._getIndex(account);
|
||||||
return yield this.tx.getLast(account, limit);
|
return yield this.txdb.getLast(account, limit);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1756,7 +1756,7 @@ Wallet.prototype.getLast = co(function* getLast(account, limit) {
|
|||||||
|
|
||||||
Wallet.prototype.zap = co(function* zap(account, age) {
|
Wallet.prototype.zap = co(function* zap(account, age) {
|
||||||
account = yield this._getIndex(account);
|
account = yield this._getIndex(account);
|
||||||
return yield this.tx.zap(account, age);
|
return yield this.txdb.zap(account, age);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1766,7 +1766,7 @@ Wallet.prototype.zap = co(function* zap(account, age) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.abandon = function abandon(hash) {
|
Wallet.prototype.abandon = function abandon(hash) {
|
||||||
return this.tx.abandon(hash);
|
return this.txdb.abandon(hash);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -559,7 +559,6 @@ WalletDB.prototype._rename = co(function* _rename(wallet, id) {
|
|||||||
|
|
||||||
paths = this.pathCache.values();
|
paths = this.pathCache.values();
|
||||||
|
|
||||||
// TODO: Optimize this bullshit.
|
|
||||||
for (i = 0; i < paths.length; i++) {
|
for (i = 0; i < paths.length; i++) {
|
||||||
path = paths[i];
|
path = paths[i];
|
||||||
|
|
||||||
@ -603,7 +602,6 @@ WalletDB.prototype.renameAccount = co(function* renameAccount(account, name) {
|
|||||||
|
|
||||||
paths = this.pathCache.values();
|
paths = this.pathCache.values();
|
||||||
|
|
||||||
// TODO: Optimize this bullshit.
|
|
||||||
for (i = 0; i < paths.length; i++) {
|
for (i = 0; i < paths.length; i++) {
|
||||||
path = paths[i];
|
path = paths[i];
|
||||||
|
|
||||||
@ -1623,7 +1621,7 @@ WalletDB.prototype._removeBlock = co(function* removeBlock(entry) {
|
|||||||
if (!wallet)
|
if (!wallet)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
yield wallet.tx.unconfirm(hash);
|
yield wallet.txdb.unconfirm(hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1683,7 +1681,7 @@ WalletDB.prototype._addTX = co(function* addTX(tx, force) {
|
|||||||
|
|
||||||
info.id = wallet.id;
|
info.id = wallet.id;
|
||||||
|
|
||||||
yield wallet.tx.add(tx, info);
|
yield wallet.txdb.add(tx, info);
|
||||||
yield wallet.handleTX(info);
|
yield wallet.handleTX(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1693,6 +1691,10 @@ WalletDB.prototype._addTX = co(function* addTX(tx, force) {
|
|||||||
/**
|
/**
|
||||||
* Path Info
|
* Path Info
|
||||||
* @constructor
|
* @constructor
|
||||||
|
* @param {WalletDB} db
|
||||||
|
* @param {WalletID} wid
|
||||||
|
* @param {TX} tx
|
||||||
|
* @param {Object} table
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function PathInfo(db, wid, tx, table) {
|
function PathInfo(db, wid, tx, table) {
|
||||||
@ -1732,6 +1734,14 @@ function PathInfo(db, wid, tx, table) {
|
|||||||
this.fromTX(tx, table);
|
this.fromTX(tx, table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map a transaction to multiple wallets.
|
||||||
|
* @param {WalletDB} db
|
||||||
|
* @param {TX} tx
|
||||||
|
* @param {Object} table
|
||||||
|
* @returns {PathInfo[]}
|
||||||
|
*/
|
||||||
|
|
||||||
PathInfo.map = function map(db, tx, table) {
|
PathInfo.map = function map(db, tx, table) {
|
||||||
var hashes = Object.keys(table);
|
var hashes = Object.keys(table);
|
||||||
var wallets = [];
|
var wallets = [];
|
||||||
@ -1762,6 +1772,14 @@ PathInfo.map = function map(db, tx, table) {
|
|||||||
return info;
|
return info;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate path info from a transaction.
|
||||||
|
* @private
|
||||||
|
* @param {TX} tx
|
||||||
|
* @param {Object} table
|
||||||
|
* @returns {PathInfo}
|
||||||
|
*/
|
||||||
|
|
||||||
PathInfo.prototype.fromTX = function fromTX(tx, table) {
|
PathInfo.prototype.fromTX = function fromTX(tx, table) {
|
||||||
var uniq = {};
|
var uniq = {};
|
||||||
var i, j, hashes, hash, paths, path;
|
var i, j, hashes, hash, paths, path;
|
||||||
@ -1809,6 +1827,15 @@ PathInfo.prototype.fromTX = function fromTX(tx, table) {
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate path info from a transaction.
|
||||||
|
* @param {WalletDB} db
|
||||||
|
* @param {WalletID} wid
|
||||||
|
* @param {TX} tx
|
||||||
|
* @param {Object} table
|
||||||
|
* @returns {PathInfo}
|
||||||
|
*/
|
||||||
|
|
||||||
PathInfo.fromTX = function fromTX(db, wid, tx, table) {
|
PathInfo.fromTX = function fromTX(db, wid, tx, table) {
|
||||||
return new PathInfo(db, wid).fromTX(tx, table);
|
return new PathInfo(db, wid).fromTX(tx, table);
|
||||||
};
|
};
|
||||||
@ -1828,9 +1855,9 @@ PathInfo.prototype.hasPath = function hasPath(hash) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get paths for a given address hash.
|
* Get path for a given address hash.
|
||||||
* @param {Hash} hash
|
* @param {Hash} hash
|
||||||
* @returns {Path[]|null}
|
* @returns {Path}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
PathInfo.prototype.getPath = function getPath(hash) {
|
PathInfo.prototype.getPath = function getPath(hash) {
|
||||||
@ -1840,6 +1867,11 @@ PathInfo.prototype.getPath = function getPath(hash) {
|
|||||||
return this.pathMap[hash];
|
return this.pathMap[hash];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert path info to transaction details.
|
||||||
|
* @returns {Details}
|
||||||
|
*/
|
||||||
|
|
||||||
PathInfo.prototype.toDetails = function toDetails() {
|
PathInfo.prototype.toDetails = function toDetails() {
|
||||||
var details = this._details;
|
var details = this._details;
|
||||||
|
|
||||||
@ -1851,6 +1883,11 @@ PathInfo.prototype.toDetails = function toDetails() {
|
|||||||
return details;
|
return details;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert path info to JSON details (caches json).
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
|
||||||
PathInfo.prototype.toJSON = function toJSON() {
|
PathInfo.prototype.toJSON = function toJSON() {
|
||||||
var json = this._json;
|
var json = this._json;
|
||||||
|
|
||||||
@ -1863,8 +1900,9 @@ PathInfo.prototype.toJSON = function toJSON() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Details
|
* Transaction Details
|
||||||
* @constructor
|
* @constructor
|
||||||
|
* @param {PathInfo} info
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function Details(info) {
|
function Details(info) {
|
||||||
@ -1890,11 +1928,26 @@ function Details(info) {
|
|||||||
this.init(info.table);
|
this.init(info.table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize transactions details
|
||||||
|
* by pushing on mapped members.
|
||||||
|
* @private
|
||||||
|
* @param {Object} table
|
||||||
|
*/
|
||||||
|
|
||||||
Details.prototype.init = function init(table) {
|
Details.prototype.init = function init(table) {
|
||||||
this._insert(this.tx.inputs, this.inputs, table);
|
this._insert(this.tx.inputs, this.inputs, table);
|
||||||
this._insert(this.tx.outputs, this.outputs, table);
|
this._insert(this.tx.outputs, this.outputs, table);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert members in the input or output vector.
|
||||||
|
* @private
|
||||||
|
* @param {Input[]|Output[]} vector
|
||||||
|
* @param {Array} target
|
||||||
|
* @param {Object} table
|
||||||
|
*/
|
||||||
|
|
||||||
Details.prototype._insert = function _insert(vector, target, table) {
|
Details.prototype._insert = function _insert(vector, target, table) {
|
||||||
var i, j, io, address, hash, paths, path, member;
|
var i, j, io, address, hash, paths, path, member;
|
||||||
|
|
||||||
@ -1929,6 +1982,11 @@ Details.prototype._insert = function _insert(vector, target, table) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert details to a more json-friendly object.
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
|
||||||
Details.prototype.toJSON = function toJSON() {
|
Details.prototype.toJSON = function toJSON() {
|
||||||
var self = this;
|
var self = this;
|
||||||
return {
|
return {
|
||||||
@ -1953,8 +2011,11 @@ Details.prototype.toJSON = function toJSON() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DetailsMember
|
* Transaction Details Member
|
||||||
* @constructor
|
* @constructor
|
||||||
|
* @property {Number} value
|
||||||
|
* @property {Address} address
|
||||||
|
* @property {Path} path
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function DetailsMember() {
|
function DetailsMember() {
|
||||||
@ -1966,6 +2027,12 @@ function DetailsMember() {
|
|||||||
this.path = null;
|
this.path = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the member to a more json-friendly object.
|
||||||
|
* @param {Network} network
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
|
||||||
DetailsMember.prototype.toJSON = function toJSON(network) {
|
DetailsMember.prototype.toJSON = function toJSON(network) {
|
||||||
return {
|
return {
|
||||||
value: utils.btc(this.value),
|
value: utils.btc(this.value),
|
||||||
@ -1981,6 +2048,8 @@ DetailsMember.prototype.toJSON = function toJSON(network) {
|
|||||||
/**
|
/**
|
||||||
* Wallet Block
|
* Wallet Block
|
||||||
* @constructor
|
* @constructor
|
||||||
|
* @param {Hash} hash
|
||||||
|
* @param {Number} height
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function WalletBlock(hash, height) {
|
function WalletBlock(hash, height) {
|
||||||
@ -1993,6 +2062,12 @@ function WalletBlock(hash, height) {
|
|||||||
this.hashes = [];
|
this.hashes = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate wallet block from chain entry.
|
||||||
|
* @private
|
||||||
|
* @param {ChainEntry} entry
|
||||||
|
*/
|
||||||
|
|
||||||
WalletBlock.prototype.fromEntry = function fromEntry(entry) {
|
WalletBlock.prototype.fromEntry = function fromEntry(entry) {
|
||||||
this.hash = entry.hash;
|
this.hash = entry.hash;
|
||||||
this.height = entry.height;
|
this.height = entry.height;
|
||||||
@ -2000,6 +2075,12 @@ WalletBlock.prototype.fromEntry = function fromEntry(entry) {
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate wallet block from json object.
|
||||||
|
* @private
|
||||||
|
* @param {Object} json
|
||||||
|
*/
|
||||||
|
|
||||||
WalletBlock.prototype.fromJSON = function fromJSON(json) {
|
WalletBlock.prototype.fromJSON = function fromJSON(json) {
|
||||||
this.hash = utils.revHex(json.hash);
|
this.hash = utils.revHex(json.hash);
|
||||||
this.height = json.height;
|
this.height = json.height;
|
||||||
@ -2008,6 +2089,13 @@ WalletBlock.prototype.fromJSON = function fromJSON(json) {
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate wallet block from serialized data.
|
||||||
|
* @private
|
||||||
|
* @param {Hash} hash
|
||||||
|
* @param {Buffer} data
|
||||||
|
*/
|
||||||
|
|
||||||
WalletBlock.prototype.fromRaw = function fromRaw(hash, data) {
|
WalletBlock.prototype.fromRaw = function fromRaw(hash, data) {
|
||||||
var p = new BufferReader(data);
|
var p = new BufferReader(data);
|
||||||
this.hash = hash;
|
this.hash = hash;
|
||||||
@ -2017,6 +2105,12 @@ WalletBlock.prototype.fromRaw = function fromRaw(hash, data) {
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate wallet block from serialized tip data.
|
||||||
|
* @private
|
||||||
|
* @param {Buffer} data
|
||||||
|
*/
|
||||||
|
|
||||||
WalletBlock.prototype.fromTip = function fromTip(data) {
|
WalletBlock.prototype.fromTip = function fromTip(data) {
|
||||||
var p = new BufferReader(data);
|
var p = new BufferReader(data);
|
||||||
this.hash = p.readHash('hex');
|
this.hash = p.readHash('hex');
|
||||||
@ -2024,22 +2118,52 @@ WalletBlock.prototype.fromTip = function fromTip(data) {
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate wallet block from chain entry.
|
||||||
|
* @param {ChainEntry} entry
|
||||||
|
* @returns {WalletBlock}
|
||||||
|
*/
|
||||||
|
|
||||||
WalletBlock.fromEntry = function fromEntry(entry) {
|
WalletBlock.fromEntry = function fromEntry(entry) {
|
||||||
return new WalletBlock().fromEntry(entry);
|
return new WalletBlock().fromEntry(entry);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate wallet block from json object.
|
||||||
|
* @param {Object} json
|
||||||
|
* @returns {WalletBlock}
|
||||||
|
*/
|
||||||
|
|
||||||
WalletBlock.fromJSON = function fromJSON(json) {
|
WalletBlock.fromJSON = function fromJSON(json) {
|
||||||
return new WalletBlock().fromJSON(json);
|
return new WalletBlock().fromJSON(json);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate wallet block from serialized data.
|
||||||
|
* @param {Hash} hash
|
||||||
|
* @param {Buffer} data
|
||||||
|
* @returns {WalletBlock}
|
||||||
|
*/
|
||||||
|
|
||||||
WalletBlock.fromRaw = function fromRaw(hash, data) {
|
WalletBlock.fromRaw = function fromRaw(hash, data) {
|
||||||
return new WalletBlock().fromRaw(hash, data);
|
return new WalletBlock().fromRaw(hash, data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate wallet block from serialized tip data.
|
||||||
|
* @private
|
||||||
|
* @param {Buffer} data
|
||||||
|
*/
|
||||||
|
|
||||||
WalletBlock.fromTip = function fromTip(data) {
|
WalletBlock.fromTip = function fromTip(data) {
|
||||||
return new WalletBlock().fromTip(data);
|
return new WalletBlock().fromTip(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize the wallet block as a tip (hash and height).
|
||||||
|
* @returns {Buffer}
|
||||||
|
*/
|
||||||
|
|
||||||
WalletBlock.prototype.toTip = function toTip() {
|
WalletBlock.prototype.toTip = function toTip() {
|
||||||
var p = new BufferWriter();
|
var p = new BufferWriter();
|
||||||
p.writeHash(this.hash);
|
p.writeHash(this.hash);
|
||||||
@ -2047,6 +2171,12 @@ WalletBlock.prototype.toTip = function toTip() {
|
|||||||
return p.render();
|
return p.render();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize the wallet block as a block.
|
||||||
|
* Contains matching transaction hashes.
|
||||||
|
* @returns {Buffer}
|
||||||
|
*/
|
||||||
|
|
||||||
WalletBlock.prototype.toRaw = function toRaw() {
|
WalletBlock.prototype.toRaw = function toRaw() {
|
||||||
var p = new BufferWriter();
|
var p = new BufferWriter();
|
||||||
var i;
|
var i;
|
||||||
@ -2059,6 +2189,11 @@ WalletBlock.prototype.toRaw = function toRaw() {
|
|||||||
return p.render();
|
return p.render();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the block to a more json-friendly object.
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
|
||||||
WalletBlock.prototype.toJSON = function toJSON() {
|
WalletBlock.prototype.toJSON = function toJSON() {
|
||||||
return {
|
return {
|
||||||
hash: utils.revHex(this.hash),
|
hash: utils.revHex(this.hash),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user