From 64ae8c77674f4d2ea4ceed414840f93f65c2ad43 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 27 Jun 2016 16:21:17 -0700 Subject: [PATCH] more wallet address mapping. --- lib/bcoin/txdb.js | 26 +++++++++++++++----------- lib/bcoin/walletdb.js | 15 +-------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/lib/bcoin/txdb.js b/lib/bcoin/txdb.js index d0425551..d059d564 100644 --- a/lib/bcoin/txdb.js +++ b/lib/bcoin/txdb.js @@ -1827,22 +1827,26 @@ WalletMap.prototype.toJSON = function toJSON() { }), outputs: this.outputs.map(function(output) { return output.toJSON(); - }), - accounts: this.accounts.map(function(path) { - return path.toKey(); }) }; }; WalletMap.prototype.fromJSON = function fromJSON(json) { - var table = {}; - var i, j, account, input, output, path; + var i, j, table, account, input, output, path; var hash, paths, hashes, accounts, values, key; + table = {}; + accounts = {}; + for (i = 0; i < json.inputs.length; i++) { input = json.inputs[i]; input = MapMember.fromJSON(input); this.inputs.push(input); + key = input.toKey(); + if (!accounts[key]) { + accounts[key] = true; + this.accounts.push(input); + } for (j = 0; j < input.paths.length; j++) { path = input.paths[j]; path.id = input.id; @@ -1859,6 +1863,11 @@ WalletMap.prototype.fromJSON = function fromJSON(json) { output = json.outputs[i]; output = MapMember.fromJSON(output); this.outputs.push(output); + key = output.toKey(); + if (!accounts[key]) { + accounts[key] = true; + this.accounts.push(output); + } for (j = 0; j < output.paths.length; j++) { path = output.paths[j]; path.id = output.id; @@ -1871,11 +1880,6 @@ WalletMap.prototype.fromJSON = function fromJSON(json) { } } - for (i = 0; i < json.accounts.length; i++) { - account = json.accounts[i]; - this.accounts.push(bcoin.path.fromKey(account)); - } - // We need to rebuild to address->paths table. hashes = Object.keys(table); @@ -1922,7 +1926,7 @@ function MapMember() { } MapMember.prototype.toKey = function toKey() { - return this.id + '/' + this.name + ':' + this.account; + return this.id + '/' + this.account; }; MapMember.prototype.toJSON = function toJSON() { diff --git a/lib/bcoin/walletdb.js b/lib/bcoin/walletdb.js index 0d126bb7..9fea7cd8 100644 --- a/lib/bcoin/walletdb.js +++ b/lib/bcoin/walletdb.js @@ -1247,20 +1247,7 @@ Path.fromJSON = function fromJSON(json) { }; Path.prototype.toKey = function toKey() { - return this.id + '/' + this.name + ':' + this.account; -}; - -Path.prototype.fromKey = function fromKey(key) { - var parts = key.split('/'); - this.id = parts[0]; - parts = parts[1].split(':'); - this.name = parts[0]; - this.account = +parts[1]; - return this; -}; - -Path.fromKey = function fromKey(key) { - return new Path().fromKey(key); + return this.id + '/' + this.account; }; Path.prototype.toCompact = function toCompact() {