commit
5f66a179c9
9 changed files with 84 additions and 43 deletions
|
|
@ -10,8 +10,7 @@ angular.module('copay.addresses').controller('AddressesController',
|
|||
|
||||
var _updateBalance = function () {
|
||||
controllerUtils.setSocketHandlers();
|
||||
|
||||
w.getBalance(function (balance, balanceByAddr, isMain) {
|
||||
w.getBalance(true, function (balance, balanceByAddr, isMain) {
|
||||
if (balanceByAddr && Object.keys(balanceByAddr).length) {
|
||||
$rootScope.balanceByAddr = balanceByAddr;
|
||||
$scope.isMain = isMain;
|
||||
|
|
|
|||
|
|
@ -27,11 +27,7 @@ angular.module('copay.header').controller('HeaderController',
|
|||
$rootScope.$watch('wallet', function(wallet) {
|
||||
if (wallet) {
|
||||
controllerUtils.setSocketHandlers();
|
||||
$rootScope.wallet.getBalance(function(balance) {
|
||||
$rootScope.$apply(function() {
|
||||
$rootScope.totalBalance = balance;
|
||||
});
|
||||
});
|
||||
controllerUtils.updateBalance();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,6 @@ var bitcore = require('bitcore');
|
|||
angular.module('copay.transactions').controller('TransactionsController',
|
||||
function($scope, $rootScope, $location) {
|
||||
$scope.title = 'Transactions';
|
||||
|
||||
$scope.oneAtATime = true;
|
||||
|
||||
var _updateTxs = function() {
|
||||
console.log('[transactions.js.10:_updateTxs:]'); //TODO
|
||||
var w =$rootScope.wallet;
|
||||
|
|
@ -32,6 +29,7 @@ console.log('[transactions.js.10:_updateTxs:]'); //TODO
|
|||
i.missingSignatures = tx.countInputMissingSignatures(0);
|
||||
txs.push(i);
|
||||
});
|
||||
console.log('[transactions.js.35:txs:]',txs); //TODO
|
||||
$scope.txs = txs;
|
||||
w.removeListener('txProposalsUpdated',_updateTxs)
|
||||
w.once('txProposalsUpdated',_updateTxs);
|
||||
|
|
@ -69,4 +67,5 @@ console.log('[transactions.js.68:txid:] SENTTX CALLBACK',txid); //TODO
|
|||
}
|
||||
};
|
||||
|
||||
_updateTxs();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -213,7 +213,6 @@ PublicKeyRing.prototype.getAddresses = function(onlyMain) {
|
|||
|
||||
PublicKeyRing.prototype.getRedeemScriptMap = function () {
|
||||
var ret = {};
|
||||
console.log('[PublicKeyRing.js.216]', this.changeAddressIndex, this.addressIndex); //TODO
|
||||
|
||||
for (var i=0; i<this.changeAddressIndex; i++) {
|
||||
ret[this.getAddress(i,true)] = this.getRedeemScript(i,true).getBuffer().toString('hex');
|
||||
|
|
|
|||
|
|
@ -181,6 +181,16 @@ TxProposals.prototype.setSent = function(ntxid,txid) {
|
|||
this.txps[ntxid].setSent(txid);
|
||||
};
|
||||
|
||||
TxProposals.prototype.getUsedUnspent = function() {
|
||||
var ret = [];
|
||||
for(var i in this.txps) {
|
||||
var u = this.txps[i].builder.getSelectedUnspent();
|
||||
for (var j in u){
|
||||
ret.push(u[j].txid);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
TxProposals.prototype.merge = function(t) {
|
||||
if (this.network.name !== t.network.name)
|
||||
|
|
|
|||
|
|
@ -400,7 +400,7 @@ Wallet.prototype.addressIsOwn = function(addrStr) {
|
|||
return ret;
|
||||
};
|
||||
|
||||
Wallet.prototype.getBalance = function(cb) {
|
||||
Wallet.prototype.getBalance = function(safe, cb) {
|
||||
var balance = 0;
|
||||
var balanceByAddr = {};
|
||||
var isMain = {};
|
||||
|
|
@ -414,7 +414,8 @@ Wallet.prototype.getBalance = function(cb) {
|
|||
balanceByAddr[a]=0;
|
||||
isMain[a]=1;
|
||||
});
|
||||
this.getUnspent(function(utxos) {
|
||||
var f = safe ? this.getSafeUnspent.bind(this):this.getUnspent.bind(this);
|
||||
f(function(utxos) {
|
||||
for(var i=0;i<utxos.length; i++) {
|
||||
var u= utxos[i];
|
||||
var amt = u.amount * COIN;
|
||||
|
|
@ -423,7 +424,7 @@ Wallet.prototype.getBalance = function(cb) {
|
|||
}
|
||||
for(var a in balanceByAddr){
|
||||
balanceByAddr[a] = balanceByAddr[a]/COIN;
|
||||
};
|
||||
}
|
||||
return cb(balance / COIN, balanceByAddr, isMain);
|
||||
});
|
||||
};
|
||||
|
|
@ -434,8 +435,24 @@ Wallet.prototype.getUnspent = function(cb) {
|
|||
});
|
||||
};
|
||||
|
||||
Wallet.prototype.getSafeUnspent = function(cb) {
|
||||
var self = this;
|
||||
this.blockchain.getUnspent(this.getAddressesStr(), function(unspentList) {
|
||||
|
||||
var ret=[];
|
||||
var uu = self.txProposals.getUsedUnspent();
|
||||
|
||||
for(var i in unspentList){
|
||||
if (uu.indexOf(unspentList[i].txid) === -1)
|
||||
ret.push(unspentList[i]);
|
||||
}
|
||||
|
||||
return cb(ret);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Wallet.prototype.createTx = function(toAddress, amountSatStr, opts, cb) {
|
||||
console.log('[Wallet.js.447:createTx:]'); //TODO
|
||||
var self = this;
|
||||
if (typeof opts === 'function') {
|
||||
cb = opts;
|
||||
|
|
@ -446,7 +463,8 @@ console.log('[Wallet.js.447:createTx:]'); //TODO
|
|||
if (typeof opts.spendUnconfirmed === 'undefined') {
|
||||
opts.spendUnconfirmed = this.spendUnconfirmed;
|
||||
}
|
||||
self.getUnspent(function(unspentList) {
|
||||
|
||||
self.getSafeUnspent(function(unspentList) {
|
||||
// TODO check enough funds, etc.
|
||||
self.createTxSync(toAddress, amountSatStr, unspentList, opts);
|
||||
self.sendPublicKeyRing(); // Change Address
|
||||
|
|
@ -470,7 +488,6 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, utxos, opts) {
|
|||
if (!opts.remainderOut) {
|
||||
opts.remainderOut ={ address: this.generateAddress(true).toString() };
|
||||
}
|
||||
console.log('[Wallet.js.480:opts: CREATETXSYNC]',opts); //TODO
|
||||
|
||||
var b = new Builder(opts)
|
||||
.setUnspent(utxos)
|
||||
|
|
|
|||
|
|
@ -27,27 +27,33 @@ angular.module('copay.controllerUtils').factory('controllerUtils', function ($ro
|
|||
});
|
||||
|
||||
w.on('created', function() {
|
||||
console.log('[controllerUtils.js.30:created:] RECV '); //TODO
|
||||
$location.path('peer');
|
||||
$rootScope.wallet = w;
|
||||
|
||||
$rootScope.wallet.getBalance(function(balance) {
|
||||
$rootScope.totalBalance = balance;
|
||||
});
|
||||
root.updateBalance();
|
||||
});
|
||||
w.on('refresh', function() {
|
||||
console.log('[controllerUtils.js] Refreshing'); //TODO
|
||||
$rootScope.$digest();
|
||||
root.updateBalance();
|
||||
});
|
||||
w.on('openError', root.onErrorDigest);
|
||||
w.on('close', root.onErrorDigest);
|
||||
|
||||
console.log('[controllerUtils.js.45] CALLING NETSTART FROM setupUxHandlers'); //TODO
|
||||
w.netStart();
|
||||
console.log('[controllerUtils.js.45] setupUxHandlers END'); //TODO
|
||||
};
|
||||
|
||||
root.setSocketHandlers = function(cb) {
|
||||
root.updateBalance = function() {
|
||||
var w = $rootScope.wallet;
|
||||
w.getBalance(false,function(balance, balanceByAddr) {
|
||||
$rootScope.totalBalance = balance;
|
||||
$rootScope.balanceByAddr = balanceByAddr;
|
||||
console.log('New balance:', balance);
|
||||
w.getBalance(true,function(balance) {
|
||||
$rootScope.availableBalance = balance;
|
||||
$rootScope.$digest();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
root.setSocketHandlers = function() {
|
||||
Socket.removeAllListeners();
|
||||
|
||||
var addrs = $rootScope.wallet.getAddressesStr();
|
||||
|
|
@ -59,15 +65,7 @@ console.log('[controllerUtils.js.45] setupUxHandlers END'); //TODO
|
|||
addrs.forEach(function(addr) {
|
||||
Socket.on(addr, function(txid) {
|
||||
console.log('Received!', txid);
|
||||
$rootScope.wallet.getBalance(function(balance, balanceByAddr) {
|
||||
$rootScope.$apply(function() {
|
||||
$rootScope.totalBalance = balance;
|
||||
$rootScope.balanceByAddr = balanceByAddr;
|
||||
});
|
||||
|
||||
console.log('New balance:', balance);
|
||||
if (typeof cb === 'function') return cb();
|
||||
});
|
||||
root.updateBalance();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue