mirror of https://github.com/BTCPrivate/copay.git
swipe working
This commit is contained in:
parent
1325b3f34a
commit
b402a5a105
|
@ -28,14 +28,13 @@ if (!addr.isValid()){
|
|||
console.log('\tBad destination address'); //TODO
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
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('\n ----------------------------');
|
||||
|
||||
|
||||
function createWallet(networkName, extPrivKeys, index) {
|
||||
|
||||
var opts = {};
|
||||
|
||||
opts.networkName = networkName || 'testnet';
|
||||
|
@ -54,7 +53,7 @@ _.each(extPrivKeys, function(extPrivKey, i) {
|
|||
extendedPrivateKeyString: extPrivKeys[i],
|
||||
});
|
||||
|
||||
if (!i)
|
||||
if (i === index)
|
||||
opts.privateKey = privateKey;
|
||||
|
||||
opts.publicKeyRing.addCopayer(
|
||||
|
@ -84,16 +83,28 @@ opts.blockchainOpts = {
|
|||
'livenet': config.network.livenet,
|
||||
'testnet': config.network.testnet,
|
||||
};
|
||||
|
||||
opts.spendUnconfirmed = true;
|
||||
opts.version = version;
|
||||
// opts.reconnectDelay = opts.reconnectDelay || this.walletDefaults.reconnectDelay;
|
||||
|
||||
var wallet = new copay.Wallet(opts);
|
||||
console.log('Wallet created. Scanning for funds');
|
||||
wallet.updateIndexes(function(){
|
||||
return new copay.Wallet(opts);
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
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('Balance per address:', balanceByAddr); //TODO
|
||||
|
||||
|
@ -101,9 +112,25 @@ wallet.updateIndexes(function(){
|
|||
// });
|
||||
|
||||
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){
|
||||
console.log('[swipeWallet.js.96]', err, ntxid); //TODO
|
||||
var l = w.length;
|
||||
_.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);
|
||||
});
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue