mirror of https://github.com/BTCPrivate/copay.git
safe unspent
This commit is contained in:
parent
0523d99eda
commit
2fc3a8e8fa
|
@ -18,8 +18,10 @@
|
|||
</figure>
|
||||
<div class="text-right" ng-show="$root.wallet">
|
||||
<h5 ng-show="$root.wallet.id">Wallet ID: {{$root.wallet.id}}</h5>
|
||||
<p ng-show="totalBalance">{{totalBalance}} <i class="fi-bitcoin"></i></p>
|
||||
<p ng-show="!totalBalance">0 <i class="fi-bitcoin"></i></p>
|
||||
<p>
|
||||
Balance: {{totalBalance || 0}} <i class="fi-bitcoin"></i><br>
|
||||
Available to Spend:{{availableBalance || 0}} <i class="fi-bitcoin"></i>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -410,7 +410,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 = {};
|
||||
|
@ -424,7 +424,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;
|
||||
|
@ -444,8 +445,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;
|
||||
|
@ -456,7 +473,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
|
||||
|
@ -480,7 +498,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)
|
||||
|
|
|
@ -31,9 +31,13 @@ console.log('[controllerUtils.js.30:created:] RECV '); //TODO
|
|||
$location.path('peer');
|
||||
$rootScope.wallet = w;
|
||||
|
||||
$rootScope.wallet.getBalance(function(balance) {
|
||||
$rootScope.wallet.getBalance(false,function(balance) {
|
||||
$rootScope.totalBalance = balance;
|
||||
});
|
||||
$rootScope.wallet.getBalance(true,function(balance) {
|
||||
$rootScope.availableBalance = balance;
|
||||
});
|
||||
|
||||
});
|
||||
w.on('refresh', function() {
|
||||
console.log('[controllerUtils.js] Refreshing'); //TODO
|
||||
|
@ -47,8 +51,9 @@ console.log('[controllerUtils.js.45] CALLING NETSTART FROM setupUxHandlers'); //
|
|||
console.log('[controllerUtils.js.45] setupUxHandlers END'); //TODO
|
||||
};
|
||||
|
||||
root.setSocketHandlers = function(cb) {
|
||||
root.setSocketHandlers = function() {
|
||||
Socket.removeAllListeners();
|
||||
var w = $rootScope.wallet;
|
||||
|
||||
var addrs = $rootScope.wallet.getAddressesStr();
|
||||
for(var i = 0; i < addrs.length; i++) {
|
||||
|
@ -59,14 +64,13 @@ 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() {
|
||||
w.getBalance(false,function(balance, balanceByAddr) {
|
||||
$rootScope.totalBalance = balance;
|
||||
$rootScope.balanceByAddr = balanceByAddr;
|
||||
});
|
||||
|
||||
console.log('New balance:', balance);
|
||||
if (typeof cb === 'function') return cb();
|
||||
w.getBalance(true,function(balance) {
|
||||
$rootScope.availableBalance = balance;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -128,9 +128,6 @@ describe('TxProposals model', function() {
|
|||
w.getUsedUnspent()[0].should.equal(unspentTest[0].txid);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
it('#merge with self', function () {
|
||||
var priv = new PrivateKey(config);
|
||||
var w = new TxProposals({
|
||||
|
|
Loading…
Reference in New Issue