swipe working

This commit is contained in:
Matias Alejo Garcia 2014-10-30 11:14:42 -03:00
commit b402a5a105

View file

@ -28,14 +28,13 @@ if (!addr.isValid()){
console.log('\tBad destination address'); //TODO console.log('\tBad destination address'); //TODO
process.exit(1); process.exit(1);
} }
var networkName = addr.network().name; 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 ----------------------------');
function createWallet(networkName, extPrivKeys, index) {
var opts = {}; var opts = {};
opts.networkName = networkName || 'testnet'; opts.networkName = networkName || 'testnet';
@ -54,7 +53,7 @@ _.each(extPrivKeys, function(extPrivKey, i) {
extendedPrivateKeyString: extPrivKeys[i], extendedPrivateKeyString: extPrivKeys[i],
}); });
if (!i) if (i === index)
opts.privateKey = privateKey; opts.privateKey = privateKey;
opts.publicKeyRing.addCopayer( opts.publicKeyRing.addCopayer(
@ -84,16 +83,28 @@ opts.blockchainOpts = {
'livenet': config.network.livenet, 'livenet': config.network.livenet,
'testnet': config.network.testnet, 'testnet': config.network.testnet,
}; };
opts.spendUnconfirmed = true; opts.spendUnconfirmed = true;
opts.version = version; opts.version = version;
// opts.reconnectDelay = opts.reconnectDelay || this.walletDefaults.reconnectDelay; // opts.reconnectDelay = opts.reconnectDelay || this.walletDefaults.reconnectDelay;
var wallet = new copay.Wallet(opts); return new copay.Wallet(opts);
console.log('Wallet created. Scanning for funds'); }
wallet.updateIndexes(function(){
console.log('## CREATING ALL WALLETS'); //TODO
var w = [];
_.each(extPrivKeys, function(extPrivKey, i) {
w.push(createWallet(networkName, extPrivKeys, i));
});
console.log(' => %d Wallets created', w.length);
console.log('\n\n## Scanning for funds');
var firstWallet = w.pop();
firstWallet.updateIndexes(function() {
console.log('Scan done.'); //TODO console.log('Scan done.'); //TODO
wallet.getBalance(function(err, balance, balanceByAddr){ firstWallet.getBalance(function(err, balance, balanceByAddr) {
console.log('\n\n\n\n### TOTAL BALANCE: %d SATOSHIS', balance); //TODO console.log('\n\n\n\n### TOTAL BALANCE: %d SATOSHIS', balance); //TODO
console.log('Balance per address:', balanceByAddr); //TODO console.log('Balance per address:', balanceByAddr); //TODO
@ -101,9 +112,25 @@ wallet.updateIndexes(function(){
// }); // });
var amount = balance - DFLT_FEE; var amount = balance - DFLT_FEE;
firstWallet.createTx(destAddr, amount, '', {}, function(err, ntxid) {
console.log('\n\t### Tx Proposal Created... With copayer 0 signature.');
wallet.createTx(destAddr, amount, '', {}, function(err, ntxid){ var l = w.length;
console.log('[swipeWallet.js.96]', err, ntxid); //TODO _.each(w, function(dummy,i){
console.log('\t Signing with copayer', i + 1);
w[i].txProposals=firstWallet.txProposals;
w[i].sign(ntxid, function(err){
console.log('\t Signed!');
firstWallet.txProposals = firstWallet.txProposals;
if (i == l - 1){
console.log('\t ALL SIGNED');
firstWallet.sendTx(ntxid,function(txid){
console.log('\t ####### SENT TXID:', txid);
process.exit(1);
});
}
})
})
}); });
}); });
}); });