mirror of https://github.com/BTCPrivate/copay.git
added a wrapper for the method fromObj of Wallet
This commit is contained in:
parent
1168bf82b8
commit
47cb4bd3da
|
@ -225,14 +225,16 @@ Wallet.prototype.toObj = function() {
|
||||||
return walletObj;
|
return walletObj;
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.fromObj = function(wallet) {
|
Wallet.fromObj = function(o, storage, network, blockchain) {
|
||||||
var opts = wallet.opts;
|
var opts = JSON.parse(JSON.stringify(o.opts));
|
||||||
opts['publicKeyRing'] = this.publicKeyring.fromObj(wallet.publicKeyRing);
|
opts.publicKeyRing = copay.PublicKeyRing.fromObj(o.publicKeyRing);
|
||||||
opts['txProposals'] = this.txProposal.fromObj(wallet.txProposals);
|
opts.txProposals = copay.TxProposals.fromObj(o.txProposals);
|
||||||
opts['privateKey'] = this.privateKey.fromObj(wallet.privateKey);
|
opts.privateKey = copay.PrivateKey.fromObj(o.privateKey);
|
||||||
|
|
||||||
|
opts.storage = storage;
|
||||||
|
opts.network = network;
|
||||||
|
opts.blockchain = blockchain;
|
||||||
var w = new Wallet(opts);
|
var w = new Wallet(opts);
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -52,15 +52,8 @@ WalletFactory.prototype._checkRead = function(walletId) {
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletFactory.prototype.fromObj = function(obj) {
|
WalletFactory.prototype.fromObj = function(obj) {
|
||||||
var opts = obj.opts;
|
var w = Wallet.fromObj(obj, this.storage, this.network, this.blockchain);
|
||||||
opts.publicKeyRing = new PublicKeyRing.fromObj(obj.publicKeyRing);
|
w.verbose = this.verbose;
|
||||||
opts.txProposals = new TxProposals.fromObj(obj.txProposals);
|
|
||||||
opts.privateKey = new PrivateKey.fromObj(obj.privateKey);
|
|
||||||
opts.storage = this.storage;
|
|
||||||
opts.network = this.network;
|
|
||||||
opts.blockchain = this.blockchain;
|
|
||||||
opts.verbose = this.verbose;
|
|
||||||
var w = new Wallet(opts);
|
|
||||||
|
|
||||||
// JIC: Add our key
|
// JIC: Add our key
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -170,4 +170,22 @@ describe('Wallet model', function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('#fromObj #toObj round trip', function () {
|
||||||
|
|
||||||
|
var w = createW2();
|
||||||
|
|
||||||
|
var o = w.toObj();
|
||||||
|
o = JSON.parse(JSON.stringify(o));
|
||||||
|
|
||||||
|
var w2 = Wallet.fromObj(o,
|
||||||
|
new Storage(config.storage),
|
||||||
|
new Network(config.network),
|
||||||
|
new Blockchain(config.blockchain));
|
||||||
|
should.exist(w2);
|
||||||
|
w2.publicKeyRing.requiredCopayers.should.equal(w.publicKeyRing.requiredCopayers);
|
||||||
|
should.exist(w2.publicKeyRing.getCopayerId);
|
||||||
|
should.exist(w2.txProposals.toObj);
|
||||||
|
should.exist(w2.privateKey.toObj);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue