WIP for automatic network join

This commit is contained in:
Manuel Araoz 2014-04-18 14:40:16 -03:00
commit d62dbeffca
12 changed files with 73 additions and 76 deletions

View file

@ -75,6 +75,7 @@ WalletFactory.prototype.read = function(walletId) {
this.log('NOT NECCESARY AN ERROR:', e); //TODO
}
this.log('### WALLET OPENED:', w.id);
w.netStart();
return w;
};
@ -112,10 +113,12 @@ WalletFactory.prototype.create = function(opts) {
opts.totalCopayers = totalCopayers;
var w = new Wallet(opts);
w.store();
w.netStart();
return w;
};
WalletFactory.prototype.open = function(walletId) {
this.log('Opening walletId:' + walletId);
var w = this.read(walletId) || this.create({
id: walletId,
verbose: this.verbose,
@ -123,44 +126,6 @@ WalletFactory.prototype.open = function(walletId) {
return w;
};
WalletFactory.prototype.openRemote = function(peedId) {
var s = WalletFactory.storage;
opts = opts || {};
this.log('### CREATING NEW WALLET.' + (opts.id ? ' USING ID: ' + opts.id : ' NEW ID'));
opts.privateKey = opts.privateKey || new PrivateKey({ networkName: this.networkName });
this.log('\t### PrivateKey Initialized');
var requiredCopayers = opts.requiredCopayers || this.walletDefaults.requiredCopayers;
var totalCopayers = opts.totalCopayers || this.walletDefaults.totalCopayers;
opts.publicKeyRing = opts.publicKeyRing || new PublicKeyRing({
networkName: this.networkName,
requiredCopayers: requiredCopayers,
totalCopayers: totalCopayers,
});
opts.publicKeyRing.addCopayer(opts.privateKey.getExtendedPublicKeyString());
this.log('\t### PublicKeyRing Initialized');
opts.txProposals = opts.txProposals || new TxProposals({
networkName: this.networkName,
});
this.log('\t### TxProposals Initialized');
opts.storage = this.storage;
opts.network = this.network;
opts.blockchain = this.blockchain;
opts.spendUnconfirmed = typeof opts.spendUnconfirmed === undefined
?this.walletDefaults.spendUnconfirmed : opts.spendUnconfirmed;
opts.requiredCopayers = requiredCopayers;
opts.totalCopayers = totalCopayers;
var w = new Wallet(opts);
w.store();
return w;
};
WalletFactory.prototype.getWalletIds = function() {
return this.storage.getWalletIds();
}
@ -175,8 +140,7 @@ WalletFactory.prototype.connectTo = function(peerId, cb) {
self.network.start(function() {
self.network.connectTo(peerId)
self.network.on('walletId', function(walletId) {
self.log('Opening walletId:' + walletId);
return cb(self.open(walletId));
return cb(walletId);
});
});
};