diff --git a/lib/http/rpc.js b/lib/http/rpc.js index fa4fc6ae..b6abec14 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -2771,7 +2771,7 @@ RPC.prototype.dumpwallet = co(function* dumpwallet(args) { address = ring.getAddress('base58'); fmt = '%s %s label= addr=%s'; - if (ring.change) + if (ring.branch === 1) fmt = '%s %s change=1 addr=%s'; str = utils.fmt(fmt, ring.toSecret(), time, address); @@ -3044,7 +3044,7 @@ RPC.prototype._toWalletTX = co(function* _toWalletTX(tx) { member = details.outputs[i]; if (member.path) { - if (member.path.change === 1) + if (member.path.branch === 1) continue; det.push({ @@ -3551,7 +3551,7 @@ RPC.prototype._toListTX = co(function* _toListTX(tx) { member = details.outputs[i]; if (member.path) { - if (member.path.change === 1) + if (member.path.branch === 1) continue; received += member.value; recMember = member; diff --git a/lib/wallet/account.js b/lib/wallet/account.js index bf3cabf8..18ef66f0 100644 --- a/lib/wallet/account.js +++ b/lib/wallet/account.js @@ -454,7 +454,7 @@ Account.prototype.derivePath = function derivePath(path, master) { switch (path.keyType) { case Path.types.HD: - return this.deriveKey(path.change, path.index, master); + return this.deriveKey(path.branch, path.index, master); case Path.types.KEY: assert(this.type === Account.types.PUBKEYHASH); @@ -476,25 +476,25 @@ Account.prototype.derivePath = function derivePath(path, master) { /** * Derive an address at `index`. Do not increment depth. - * @param {Boolean} change - Whether the address on the change branch. + * @param {Boolean} branch - Whether the address on the change branch. * @param {Number} index * @returns {WalletKey} */ -Account.prototype.deriveKey = function deriveKey(change, index, master) { +Account.prototype.deriveKey = function deriveKey(branch, index, master) { var keys = []; var i, key, shared, ring, hash; - change = +change; + branch = +branch; if (master && master.key) { key = master.key.deriveAccount44(this.accountIndex); - key = key.derive(change).derive(index); + key = key.derive(branch).derive(index); } else { - key = this.accountKey.derive(change).derive(index); + key = this.accountKey.derive(branch).derive(index); } - ring = WalletKey.fromHD(this, key, change, index); + ring = WalletKey.fromHD(this, key, branch, index); switch (this.type) { case Account.types.PUBKEYHASH: @@ -504,7 +504,7 @@ Account.prototype.deriveKey = function deriveKey(change, index, master) { for (i = 0; i < this.keys.length; i++) { shared = this.keys[i]; - shared = shared.derive(change).derive(index); + shared = shared.derive(branch).derive(index); keys.push(shared.publicKey); } diff --git a/lib/wallet/path.js b/lib/wallet/path.js index dba15746..f9c60694 100644 --- a/lib/wallet/path.js +++ b/lib/wallet/path.js @@ -21,7 +21,7 @@ var Address = require('../primitives/address'); * @property {WalletID} wid * @property {String} name - Account name. * @property {Number} account - Account index. - * @property {Number} change - Change index. + * @property {Number} branch - Branch index. * @property {Number} index - Address index. * @property {Address|null} address */ @@ -36,7 +36,7 @@ function Path() { this.wid = -1; // Passed in by caller. this.name = null; // Passed in by caller. this.account = 0; - this.change = -1; + this.branch = -1; this.index = -1; this.encrypted = false; @@ -74,7 +74,7 @@ Path.prototype.clone = function clone() { path.wid = this.wid; path.name = this.name; path.account = this.account; - path.change = this.change; + path.branch = this.branch; path.index = this.index; path.encrypted = this.encrypted; @@ -101,7 +101,7 @@ Path.prototype.fromRaw = function fromRaw(data) { switch (this.keyType) { case Path.types.HD: - this.change = p.readU32(); + this.branch = p.readU32(); this.index = p.readU32(); break; case Path.types.KEY: @@ -147,7 +147,7 @@ Path.prototype.toRaw = function toRaw(writer) { case Path.types.HD: assert(!this.data); assert(this.index !== -1); - p.writeU32(this.change); + p.writeU32(this.branch); p.writeU32(this.index); break; case Path.types.KEY: @@ -214,7 +214,7 @@ Path.prototype.toPath = function toPath() { return null; return 'm/' + this.account - + '\'/' + this.change + + '\'/' + this.branch + '/' + this.index; }; @@ -236,7 +236,7 @@ Path.prototype.toJSON = function toJSON() { return { name: this.name, account: this.account, - change: this.change === 1, + change: this.branch === 1, derivation: this.toPath() }; }; diff --git a/lib/wallet/wallet.js b/lib/wallet/wallet.js index 02fac3d5..7446962c 100644 --- a/lib/wallet/wallet.js +++ b/lib/wallet/wallet.js @@ -701,10 +701,10 @@ Wallet.prototype.createChange = function createChange(account) { * @returns {Promise} - Returns {@link WalletKey}. */ -Wallet.prototype.createKey = co(function* createKey(account, change) { +Wallet.prototype.createKey = co(function* createKey(account, branch) { var unlock = yield this.writeLock.lock(); try { - return yield this._createKey(account, change); + return yield this._createKey(account, branch); } finally { unlock(); } @@ -717,11 +717,11 @@ Wallet.prototype.createKey = co(function* createKey(account, change) { * @returns {Promise} - Returns {@link WalletKey}. */ -Wallet.prototype._createKey = co(function* createKey(account, change) { +Wallet.prototype._createKey = co(function* createKey(account, branch) { var result; - if (typeof account === 'boolean') { - change = account; + if (branch == null) { + branch = account; account = null; } @@ -736,7 +736,7 @@ Wallet.prototype._createKey = co(function* createKey(account, change) { this.start(); try { - result = yield account.createKey(change); + result = yield account.createKey(branch); } catch (e) { this.drop(); throw e; @@ -1367,7 +1367,7 @@ Wallet.prototype._syncOutputDepth = co(function* syncOutputDepth(info) { for (j = 0; j < paths.length; j++) { path = paths[j]; - if (path.change) { + if (path.branch) { if (path.index > changeDepth) changeDepth = path.index; } else { diff --git a/lib/wallet/walletkey.js b/lib/wallet/walletkey.js index 6be70c10..fc974b82 100644 --- a/lib/wallet/walletkey.js +++ b/lib/wallet/walletkey.js @@ -38,7 +38,7 @@ function WalletKey(options, network) { this.wid = -1; this.name = null; this.account = -1; - this.change = -1; + this.branch = -1; this.index = -1; } @@ -136,7 +136,7 @@ WalletKey.prototype.toJSON = function toJSON() { id: this.id, name: this.name, account: this.account, - change: this.change, + branch: this.branch, index: this.index, address: this.getAddress('base58'), nestedAddress: this.getNestedAddress('base58') @@ -169,13 +169,13 @@ WalletKey.fromRaw = function fromRaw(data) { * @returns {WalletKey} */ -WalletKey.prototype.fromHD = function fromHD(account, key, change, index) { +WalletKey.prototype.fromHD = function fromHD(account, key, branch, index) { this.keyType = Path.types.HD; this.id = account.id; this.wid = account.wid; this.name = account.name; this.account = account.accountIndex; - this.change = change; + this.branch = branch; this.index = index; this.witness = account.witness; @@ -191,8 +191,8 @@ WalletKey.prototype.fromHD = function fromHD(account, key, change, index) { * @returns {WalletKey} */ -WalletKey.fromHD = function fromHD(account, key, change, index) { - return new WalletKey().fromHD(account, key, change, index); +WalletKey.fromHD = function fromHD(account, key, branch, index) { + return new WalletKey().fromHD(account, key, branch, index); }; /** @@ -276,7 +276,7 @@ WalletKey.prototype.toPath = function toPath(nested) { switch (this.keyType) { case Path.types.HD: - path.change = this.change; + path.branch = this.branch; path.index = this.index; break; case Path.types.KEY: