fix async loop

This commit is contained in:
Matias Alejo Garcia 2014-11-01 09:42:56 -03:00
parent 5fd3bccd8a
commit 01e8562b43
3 changed files with 32 additions and 15 deletions

View File

@ -252,7 +252,6 @@ Identity.prototype.store = function(opts, cb) {
storeFunction.call(self.storage, this.getId(), this.toObj(), function(err) { storeFunction.call(self.storage, this.getId(), this.toObj(), function(err) {
if (err) return cb(err); if (err) return cb(err);
console.log('[Identity.js.255:opts:]', opts); //TODO
if (opts.noWallets) if (opts.noWallets)
return cb(); return cb();

View File

@ -9,6 +9,7 @@ var version = require('../version').version;
var sinon = require('sinon'); var sinon = require('sinon');
var bitcore = require('bitcore'); var bitcore = require('bitcore');
var readline = require('readline'); var readline = require('readline');
var async = require('async');
var rl = readline.createInterface({ var rl = readline.createInterface({
input: process.stdin, input: process.stdin,
@ -38,6 +39,9 @@ var networkName = addr.network().name;
console.log('\tNetwork: %s\n\tDestination Address:%s\n\tRequired copayers: %d\n\tTotal copayers: %d\n\tKeys:', networkName, destAddr, requiredCopayers, totalCopayers, extPrivKeys); //TODO console.log('\tNetwork: %s\n\tDestination Address:%s\n\tRequired copayers: %d\n\tTotal copayers: %d\n\tKeys:', networkName, destAddr, requiredCopayers, totalCopayers, extPrivKeys); //TODO
console.log('\n ----------------------------'); console.log('\n ----------------------------');
if (requiredCopayers > totalCopayers)
throw new Error('No enought private keys given');
function createWallet(networkName, extPrivKeys, index) { function createWallet(networkName, extPrivKeys, index) {
@ -120,27 +124,39 @@ firstWallet.updateIndexes(function() {
} }
rl.question("\n\tShould I swipe the wallet (destination address" + destAddr + ")?\n\t(`yes` to continue)\n\t", function(answer) { rl.question("\n\tShould I swipe the wallet (destination address" + destAddr + ")?\n\t(`yes` to continue)\n\t", function(answer) {
if (answer!== 'yes') if (answer !== 'yes')
process.exit(1); process.exit(1);
var amount = balance - DFLT_FEE; var amount = balance - DFLT_FEE;
firstWallet.createTx(destAddr, amount, '', {}, function(err, ntxid) { firstWallet.createTx(destAddr, amount, '', {}, function(err, ntxid) {
console.log('\n\t### Tx Proposal Created... With copayer 0 signature.'); console.log('\n\t### Tx Proposal Created...\n\tWith copayer 0 signature.');
if (requiredCopayers === 1) {
if (requiredCopayers ===1) {
firstWallet.sendTx(ntxid, function(txid) { firstWallet.sendTx(ntxid, function(txid) {
console.log('\t ####### SENT TXID:', txid); console.log('\t ####### SENT TXID:', txid);
process.exit(1); process.exit(1);
}); });
} }
var l = w.length; var signers = w.slice(0, requiredCopayers - 1);
_.each(w, function(dummy, i) {
console.log('\t Signing with copayer', i + 1); console.log('Will add %d more signatures:', signers.length);
w[i].txProposals = firstWallet.txProposals;
w[i].sign(ntxid, function(err) { var i = 0;
console.log('\t Signed!'); async.eachSeries(signers, function(dummy, cb) {
firstWallet.txProposals = firstWallet.txProposals; console.log('\t Signing with copayer', i + 1);
w[i].txProposals = firstWallet.txProposals;
w[i].sign(ntxid, function(signed) {
if (!signed) return cb('Could not sign');
console.log('\t Signed!');
firstWallet.txProposals = firstWallet.txProposals;
i++;
return cb(null);
})
},
function(err) {
if (err)
throw new Error(err);
var p = firstWallet.txProposals.getTxProposal(ntxid); var p = firstWallet.txProposals.getTxProposal(ntxid);
if (p.builder.isFullySigned()) { if (p.builder.isFullySigned()) {
@ -149,9 +165,11 @@ firstWallet.updateIndexes(function() {
console.log('\t ####### SENT TXID:', txid); console.log('\t ####### SENT TXID:', txid);
process.exit(1); process.exit(1);
}); });
} else {
throw new Error('Error: could not fully sign the TX');
} }
}) }
}) )
}); });
}); });
}); });

View File

@ -2,7 +2,7 @@
<div data-alert class="loading-screen" ng-show="loading"> <div data-alert class="loading-screen" ng-show="loading">
<i class="size-60 fi-bitcoin-circle icon-rotate spinner"></i> <i class="size-60 fi-bitcoin-circle icon-rotate spinner"></i>
<span translate>Retreiving information from storage...</span> <span translate>Synchronizing with storage...</span>
</div> </div>
<div class="large-4 large-centered medium-6 medium-centered columns" ng-show="!loading && !retreiving"> <div class="large-4 large-centered medium-6 medium-centered columns" ng-show="!loading && !retreiving">
<div class="logo-setup"> <div class="logo-setup">