wallet: path version and type.
This commit is contained in:
parent
2c066ddce1
commit
dd7ccd40db
@ -666,6 +666,44 @@ Account.prototype.setDepth = co(function* setDepth(receiveDepth, changeDepth, ne
|
||||
return receive || nested;
|
||||
});
|
||||
|
||||
/**
|
||||
* Get witness version for a path.
|
||||
* @param {Path}
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
Account.prototype.getWitnessVersion = function getWitnessVersion(path) {
|
||||
if (!this.witness)
|
||||
return -1;
|
||||
|
||||
if (path.branch === 2)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get address type for a path.
|
||||
* @param {Path} path
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
Account.prototype.getAddressType = function getAddressType(path) {
|
||||
if (path.branch === 2)
|
||||
return Script.types.SCRIPTHASH;
|
||||
|
||||
if (this.witness) {
|
||||
if (this.type === Acount.types.MULTISIG)
|
||||
return Script.types.WITNESSSCRIPTHASH;
|
||||
return Script.types.WITNESSPUBKEYHASH;
|
||||
}
|
||||
|
||||
if (this.type === Acount.types.MULTISIG)
|
||||
return Script.types.SCRIPTHASH;
|
||||
|
||||
return Script.types.PUBKEYHASH;
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert the account to a more inspection-friendly object.
|
||||
* @returns {Object}
|
||||
|
||||
@ -1071,6 +1071,14 @@ Wallet.prototype.getPath = co(function* getPath(address) {
|
||||
path.id = this.id;
|
||||
path.name = yield this.getAccountName(path.account);
|
||||
|
||||
assert(path.name);
|
||||
|
||||
// account = yield this.getAccount(path.account);
|
||||
// assert(account);
|
||||
// path.name = account.name;
|
||||
// path.version = account.getWitnessVersion(path);
|
||||
// path.type = account.getAddressType(path);
|
||||
|
||||
this.pathCache.set(hash, path);
|
||||
|
||||
return path;
|
||||
@ -1083,23 +1091,32 @@ Wallet.prototype.getPath = co(function* getPath(address) {
|
||||
*/
|
||||
|
||||
Wallet.prototype.getPaths = co(function* getPaths(acct) {
|
||||
var out = [];
|
||||
var i, account, paths, path;
|
||||
|
||||
account = yield this._getIndex(acct);
|
||||
paths = yield this.db.getWalletPaths(this.wid);
|
||||
var index = yield this.ensureIndex(acct);
|
||||
var paths = yield this.db.getWalletPaths(this.wid);
|
||||
var result = [];
|
||||
var i, path;
|
||||
|
||||
for (i = 0; i < paths.length; i++) {
|
||||
path = paths[i];
|
||||
if (!account || path.account === account) {
|
||||
if (index == null || path.account === index) {
|
||||
path.id = this.id;
|
||||
path.name = yield this.getAccountName(path.account);
|
||||
|
||||
assert(path.name);
|
||||
|
||||
// account = yield this.getAccount(path.account);
|
||||
// assert(account);
|
||||
// path.name = account.name;
|
||||
// path.version = account.getWitnessVersion(path);
|
||||
// path.type = account.getAddressType(path);
|
||||
|
||||
this.pathCache.set(path.hash, path);
|
||||
out.push(path);
|
||||
|
||||
result.push(path);
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
return result;
|
||||
});
|
||||
|
||||
/**
|
||||
@ -1899,7 +1916,7 @@ Wallet.prototype.zap = co(function* zap(acct, age) {
|
||||
*/
|
||||
|
||||
Wallet.prototype._zap = co(function* zap(acct, age) {
|
||||
var account = yield this._getIndex(acct);
|
||||
var account = yield this.ensureIndex(acct);
|
||||
return yield this.txdb.zap(account, age);
|
||||
});
|
||||
|
||||
@ -1957,7 +1974,7 @@ Wallet.prototype.getPathInfo = co(function* getPathInfo(tx) {
|
||||
*/
|
||||
|
||||
Wallet.prototype.getHistory = co(function* getHistory(acct) {
|
||||
var account = yield this._getIndex(acct);
|
||||
var account = yield this.ensureIndex(acct);
|
||||
return this.txdb.getHistory(account);
|
||||
});
|
||||
|
||||
@ -1968,7 +1985,7 @@ Wallet.prototype.getHistory = co(function* getHistory(acct) {
|
||||
*/
|
||||
|
||||
Wallet.prototype.getCoins = co(function* getCoins(acct) {
|
||||
var account = yield this._getIndex(acct);
|
||||
var account = yield this.ensureIndex(acct);
|
||||
return yield this.txdb.getCoins(account);
|
||||
});
|
||||
|
||||
@ -1979,7 +1996,7 @@ Wallet.prototype.getCoins = co(function* getCoins(acct) {
|
||||
*/
|
||||
|
||||
Wallet.prototype.getUnconfirmed = co(function* getUnconfirmed(acct) {
|
||||
var account = yield this._getIndex(acct);
|
||||
var account = yield this.ensureIndex(acct);
|
||||
return yield this.txdb.getUnconfirmed(account);
|
||||
});
|
||||
|
||||
@ -1990,7 +2007,7 @@ Wallet.prototype.getUnconfirmed = co(function* getUnconfirmed(acct) {
|
||||
*/
|
||||
|
||||
Wallet.prototype.getBalance = co(function* getBalance(acct) {
|
||||
var account = yield this._getIndex(acct);
|
||||
var account = yield this.ensureIndex(acct);
|
||||
return yield this.txdb.getBalance(account);
|
||||
});
|
||||
|
||||
@ -2009,7 +2026,7 @@ Wallet.prototype.getRange = co(function* getRange(acct, options) {
|
||||
options = acct;
|
||||
acct = null;
|
||||
}
|
||||
account = yield this._getIndex(acct);
|
||||
account = yield this.ensureIndex(acct);
|
||||
return yield this.txdb.getRange(account, options);
|
||||
});
|
||||
|
||||
@ -2021,7 +2038,7 @@ Wallet.prototype.getRange = co(function* getRange(acct, options) {
|
||||
*/
|
||||
|
||||
Wallet.prototype.getLast = co(function* getLast(acct, limit) {
|
||||
var account = yield this._getIndex(acct);
|
||||
var account = yield this.ensureIndex(acct);
|
||||
return yield this.txdb.getLast(account, limit);
|
||||
});
|
||||
|
||||
@ -2033,7 +2050,7 @@ Wallet.prototype.getLast = co(function* getLast(acct, limit) {
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
Wallet.prototype._getIndex = co(function* _getIndex(acct) {
|
||||
Wallet.prototype.ensureIndex = co(function* ensureIndex(acct) {
|
||||
var index;
|
||||
|
||||
if (acct == null)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user