more wallet address mapping.

This commit is contained in:
Christopher Jeffrey 2016-06-27 16:21:17 -07:00
parent 4d6d526126
commit 64ae8c7767
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 16 additions and 25 deletions

View File

@ -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() {

View File

@ -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() {