more wallet address mapping.
This commit is contained in:
parent
4d6d526126
commit
64ae8c7767
@ -1827,22 +1827,26 @@ WalletMap.prototype.toJSON = function toJSON() {
|
|||||||
}),
|
}),
|
||||||
outputs: this.outputs.map(function(output) {
|
outputs: this.outputs.map(function(output) {
|
||||||
return output.toJSON();
|
return output.toJSON();
|
||||||
}),
|
|
||||||
accounts: this.accounts.map(function(path) {
|
|
||||||
return path.toKey();
|
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletMap.prototype.fromJSON = function fromJSON(json) {
|
WalletMap.prototype.fromJSON = function fromJSON(json) {
|
||||||
var table = {};
|
var i, j, table, account, input, output, path;
|
||||||
var i, j, account, input, output, path;
|
|
||||||
var hash, paths, hashes, accounts, values, key;
|
var hash, paths, hashes, accounts, values, key;
|
||||||
|
|
||||||
|
table = {};
|
||||||
|
accounts = {};
|
||||||
|
|
||||||
for (i = 0; i < json.inputs.length; i++) {
|
for (i = 0; i < json.inputs.length; i++) {
|
||||||
input = json.inputs[i];
|
input = json.inputs[i];
|
||||||
input = MapMember.fromJSON(input);
|
input = MapMember.fromJSON(input);
|
||||||
this.inputs.push(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++) {
|
for (j = 0; j < input.paths.length; j++) {
|
||||||
path = input.paths[j];
|
path = input.paths[j];
|
||||||
path.id = input.id;
|
path.id = input.id;
|
||||||
@ -1859,6 +1863,11 @@ WalletMap.prototype.fromJSON = function fromJSON(json) {
|
|||||||
output = json.outputs[i];
|
output = json.outputs[i];
|
||||||
output = MapMember.fromJSON(output);
|
output = MapMember.fromJSON(output);
|
||||||
this.outputs.push(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++) {
|
for (j = 0; j < output.paths.length; j++) {
|
||||||
path = output.paths[j];
|
path = output.paths[j];
|
||||||
path.id = output.id;
|
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.
|
// We need to rebuild to address->paths table.
|
||||||
hashes = Object.keys(table);
|
hashes = Object.keys(table);
|
||||||
|
|
||||||
@ -1922,7 +1926,7 @@ function MapMember() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MapMember.prototype.toKey = function toKey() {
|
MapMember.prototype.toKey = function toKey() {
|
||||||
return this.id + '/' + this.name + ':' + this.account;
|
return this.id + '/' + this.account;
|
||||||
};
|
};
|
||||||
|
|
||||||
MapMember.prototype.toJSON = function toJSON() {
|
MapMember.prototype.toJSON = function toJSON() {
|
||||||
|
|||||||
@ -1247,20 +1247,7 @@ Path.fromJSON = function fromJSON(json) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Path.prototype.toKey = function toKey() {
|
Path.prototype.toKey = function toKey() {
|
||||||
return this.id + '/' + this.name + ':' + this.account;
|
return this.id + '/' + 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);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Path.prototype.toCompact = function toCompact() {
|
Path.prototype.toCompact = function toCompact() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user