read/load on Wallet
This commit is contained in:
parent
296c78cdf0
commit
124e1dff19
3 changed files with 54 additions and 7879 deletions
7840
js/copayBundle.js
7840
js/copayBundle.js
File diff suppressed because it is too large
Load diff
|
|
@ -12,67 +12,82 @@ var Blockchain = imports.Blockchain || require('FakeBlockchain');
|
||||||
var copay = copay || require('../../../copay');
|
var copay = copay || require('../../../copay');
|
||||||
|
|
||||||
|
|
||||||
function Wallet(opts, config) {
|
function Wallet(config) {
|
||||||
opts = opts || {};
|
this._startInterface(config);
|
||||||
|
}
|
||||||
|
|
||||||
console.log('### CREATING WALLET.'
|
|
||||||
+ (opts.walletId ? ' USING ID: ' +opts.walletId : ' NEW ID') );
|
|
||||||
|
|
||||||
//
|
Wallet.prototype._startInterface = function(config) {
|
||||||
this.storage = new Storage(config.storage);
|
this.storage = new Storage(config.storage);
|
||||||
this.network = new Network(config.network);
|
this.network = new Network(config.network);
|
||||||
this.blockchain = new Blockchain(config.blockchain);
|
this.blockchain = new Blockchain(config.blockchain);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Wallet.prototype._createNew = function(config, opts) {
|
||||||
|
|
||||||
|
console.log('### CREATING NEW WALLET.'
|
||||||
|
+ (opts.walletId ? ' USING ID: ' +opts.walletId : ' NEW ID') );
|
||||||
|
|
||||||
this.privateKey = new copay.PrivateKey({networkName: config.networkName});
|
this.privateKey = new copay.PrivateKey({networkName: config.networkName});
|
||||||
console.log('\t### PrivateKey Initialized');
|
console.log('\t### PrivateKey Initialized');
|
||||||
|
|
||||||
|
|
||||||
this.publicKeyRing = opts.publicKeyRing || new copay.PublicKeyRing({
|
this.publicKeyRing = opts.publicKeyRing || new copay.PublicKeyRing({
|
||||||
id: opts.walletId,
|
id: opts.walletId,
|
||||||
requiredCopayers: opts.requiredCopayers || config.wallet.requiredCopayers,
|
requiredCopayers: opts.requiredCopayers || config.wallet.requiredCopayers,
|
||||||
totalCopayers: opts.totalCopayers || config.wallet.totalCopayers,
|
totalCopayers: opts.totalCopayers || config.wallet.totalCopayers,
|
||||||
networkName: config.networkName,
|
networkName: config.networkName,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.publicKeyRing.addCopayer(this.privateKey.getBIP32().extendedPublicKeyString());
|
this.publicKeyRing.addCopayer(this.privateKey.getBIP32().extendedPublicKeyString());
|
||||||
console.log('\t### PublicKeyRing Initialized WalletID: ' + this.publicKeyRing.id);
|
console.log('\t### PublicKeyRing Initialized WalletID: ' + this.publicKeyRing.id);
|
||||||
|
|
||||||
this.txProposals = new copay.TxProposals({
|
this.txProposals = opts.txProposals || new copay.TxProposals({
|
||||||
walletId: this.publicKeyRing.id,
|
walletId: this.publicKeyRing.id,
|
||||||
publicKeyRing: this.publicKeyRing,
|
publicKeyRing: this.publicKeyRing,
|
||||||
networkName: config.networkName,
|
networkName: config.networkName,
|
||||||
});
|
});
|
||||||
console.log('\t### TxProposals Initialized');
|
console.log('\t### TxProposals Initialized');
|
||||||
}
|
};
|
||||||
//
|
|
||||||
// var Read = function(walletId) {
|
|
||||||
// this.storage.read(walletId);
|
|
||||||
// $rootScope.w = new copay.PublicKeyRing.fromObj(pkr);
|
|
||||||
// $rootScope.txProposals = new copay.TxProposals.fromObj(txp);
|
|
||||||
// $rootScope.PrivateKey = new copay.PrivateKey.fromObj(priv); //TODO secure
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
// HERE or in Storage?
|
|
||||||
// $rootScope.walletId = walletId;
|
|
||||||
// $rootScope.w = new copay.PublicKeyRing.fromObj(pkr);
|
|
||||||
// $rootScope.txProposals = new copay.TxProposals.fromObj(txp);
|
|
||||||
// $rootScope.PrivateKey = new copay.PrivateKey.fromObj(priv); //TODO secure
|
|
||||||
|
|
||||||
// // JIC: Add our key
|
Wallet.prototype._load = function(config, walletId) {
|
||||||
// try {
|
this.id = walletId;
|
||||||
// $rootScope.publicKeyRing.addCopayer(
|
this.publicKeyRing = new copay.PublicKeyRing.fromObj(
|
||||||
// $rootScope.PrivateKey.getBIP32().extendedPublicKeyString()
|
this.storage.get(this.id, 'publicKeyRing')
|
||||||
// );
|
);
|
||||||
// } catch (e) {
|
this.txProposals = new copay.TxProposals.fromObj(
|
||||||
// console.log('NOT NECCESARY AN ERROR:', e); //TODO
|
this.storage.get(this.id, 'txProposals')
|
||||||
// };
|
);
|
||||||
// ret = true;
|
this.privateKey = new copay.PrivateKey.fromObj(
|
||||||
// }
|
this.storage.get(this.id, 'privateKey')
|
||||||
// return ret;
|
); //TODO secure
|
||||||
// };
|
|
||||||
// };
|
// JIC: Add our key
|
||||||
|
try {
|
||||||
|
this.publicKeyRing.addCopayer(
|
||||||
|
this.privateKey.getBIP32().extendedPublicKeyString()
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
console.log('NOT NECCESARY AN ERROR:', e); //TODO
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// CONSTRUCTORS
|
||||||
|
Wallet.read = function(config, walletId) {
|
||||||
|
var w = new Wallet(config);
|
||||||
|
w.load(walletId);
|
||||||
|
|
||||||
|
return w;
|
||||||
|
};
|
||||||
|
|
||||||
|
Wallet.create = function(config, opts) {
|
||||||
|
var w = new Wallet(config);
|
||||||
|
w._createNew(config, opts);
|
||||||
|
|
||||||
|
return w;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = require('soop')(Wallet);
|
module.exports = require('soop')(Wallet);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ describe('Wallet model', function() {
|
||||||
|
|
||||||
it('should create an instance', function () {
|
it('should create an instance', function () {
|
||||||
var opts = {};
|
var opts = {};
|
||||||
var w = new Wallet(opts, config);
|
var w = new Wallet(config, opts);
|
||||||
should.exist(w);
|
should.exist(w);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue