walletdb: store addr type on path.
This commit is contained in:
parent
c93de907fe
commit
2fdfdd3c8a
@ -687,6 +687,27 @@ KeyRing.prototype.derive = function derive(key) {
|
|||||||
return key.derive(this.change).derive(this.index);
|
return key.derive(this.change).derive(this.index);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get script type.
|
||||||
|
* @returns {ScriptType}
|
||||||
|
*/
|
||||||
|
|
||||||
|
KeyRing.prototype.getScriptType = function getScriptType() {
|
||||||
|
switch (this.type) {
|
||||||
|
case KeyRing.types.PUBKEYHASH:
|
||||||
|
return this.witness
|
||||||
|
? scriptTypes.WITNESSPUBKEYHASH
|
||||||
|
: scriptTypes.PUBKEYHASH;
|
||||||
|
case KeyRing.types.MULTISIG:
|
||||||
|
return this.witness
|
||||||
|
? scriptTypes.WITNESSSCRIPTHASH
|
||||||
|
: scriptTypes.SCRIPTHASH;
|
||||||
|
default:
|
||||||
|
assert(false, 'Bad keyring type.');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
KeyRing.prototype.__defineGetter__('publicKey', function() {
|
KeyRing.prototype.__defineGetter__('publicKey', function() {
|
||||||
return this.getPublicKey();
|
return this.getPublicKey();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1561,7 +1561,11 @@ function Path() {
|
|||||||
this.change = 0;
|
this.change = 0;
|
||||||
this.index = 0;
|
this.index = 0;
|
||||||
|
|
||||||
// NOTE: Passed in by caller.
|
// Currently unused.
|
||||||
|
this.type = bcoin.script.types.PUBKEYHASH;
|
||||||
|
this.version = -1;
|
||||||
|
|
||||||
|
// Passed in by caller.
|
||||||
this.id = null;
|
this.id = null;
|
||||||
this.hash = null;
|
this.hash = null;
|
||||||
}
|
}
|
||||||
@ -1574,11 +1578,18 @@ function Path() {
|
|||||||
|
|
||||||
Path.prototype.fromRaw = function fromRaw(data) {
|
Path.prototype.fromRaw = function fromRaw(data) {
|
||||||
var p = new BufferReader(data);
|
var p = new BufferReader(data);
|
||||||
|
|
||||||
this.wid = p.readU32();
|
this.wid = p.readU32();
|
||||||
this.name = p.readVarString('utf8');
|
this.name = p.readVarString('utf8');
|
||||||
this.account = p.readU32();
|
this.account = p.readU32();
|
||||||
this.change = p.readU32();
|
this.change = p.readU32();
|
||||||
this.index = p.readU32();
|
this.index = p.readU32();
|
||||||
|
this.version = p.readU8();
|
||||||
|
this.type = p.readU8();
|
||||||
|
|
||||||
|
if (this.version === 0xff)
|
||||||
|
this.version = -1;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1605,6 +1616,8 @@ Path.prototype.toRaw = function toRaw(writer) {
|
|||||||
p.writeU32(this.account);
|
p.writeU32(this.account);
|
||||||
p.writeU32(this.change);
|
p.writeU32(this.change);
|
||||||
p.writeU32(this.index);
|
p.writeU32(this.index);
|
||||||
|
p.writeU8(this.version === -1 ? 0xff : this.version);
|
||||||
|
p.writeU8(this.type);
|
||||||
|
|
||||||
if (!writer)
|
if (!writer)
|
||||||
p = p.render();
|
p = p.render();
|
||||||
@ -1621,11 +1634,17 @@ Path.prototype.toRaw = function toRaw(writer) {
|
|||||||
|
|
||||||
Path.prototype.fromKeyRing = function fromKeyRing(address) {
|
Path.prototype.fromKeyRing = function fromKeyRing(address) {
|
||||||
this.wid = address.wid;
|
this.wid = address.wid;
|
||||||
this.id = address.id;
|
|
||||||
this.name = address.name;
|
this.name = address.name;
|
||||||
this.account = address.account;
|
this.account = address.account;
|
||||||
this.change = address.change;
|
this.change = address.change;
|
||||||
this.index = address.index;
|
this.index = address.index;
|
||||||
|
|
||||||
|
this.version = address.witness ? 0 : -1;
|
||||||
|
this.type = address.getScriptType();
|
||||||
|
|
||||||
|
this.id = address.id;
|
||||||
|
this.hash = address.getHash('hex');
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1645,12 +1664,21 @@ Path.fromKeyRing = function fromKeyRing(address) {
|
|||||||
* @returns {String}
|
* @returns {String}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Path.prototype.toPath = function() {
|
Path.prototype.toPath = function toPath() {
|
||||||
return 'm/' + this.account
|
return 'm/' + this.account
|
||||||
+ '\'/' + this.change
|
+ '\'/' + this.change
|
||||||
+ '/' + this.index;
|
+ '/' + this.index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert path object to an address (currently unused).
|
||||||
|
* @returns {Address}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Path.prototype.toAddress = function toAddress() {
|
||||||
|
return bcoin.address.fromHash(this.hash, this.type, this.version);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert path to a json-friendly object.
|
* Convert path to a json-friendly object.
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user