mirror of https://github.com/BTCPrivate/copay.git
safe unspent
This commit is contained in:
parent
0523d99eda
commit
2fc3a8e8fa
|
@ -18,8 +18,10 @@
|
||||||
</figure>
|
</figure>
|
||||||
<div class="text-right" ng-show="$root.wallet">
|
<div class="text-right" ng-show="$root.wallet">
|
||||||
<h5 ng-show="$root.wallet.id">Wallet ID: {{$root.wallet.id}}</h5>
|
<h5 ng-show="$root.wallet.id">Wallet ID: {{$root.wallet.id}}</h5>
|
||||||
<p ng-show="totalBalance">{{totalBalance}} <i class="fi-bitcoin"></i></p>
|
<p>
|
||||||
<p ng-show="!totalBalance">0 <i class="fi-bitcoin"></i></p>
|
Balance: {{totalBalance || 0}} <i class="fi-bitcoin"></i><br>
|
||||||
|
Available to Spend:{{availableBalance || 0}} <i class="fi-bitcoin"></i>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,7 @@ angular.module('copay.addresses').controller('AddressesController',
|
||||||
|
|
||||||
var _updateBalance = function () {
|
var _updateBalance = function () {
|
||||||
controllerUtils.setSocketHandlers();
|
controllerUtils.setSocketHandlers();
|
||||||
|
w.getBalance(true, function (balance, balanceByAddr, isMain) {
|
||||||
w.getBalance(function (balance, balanceByAddr, isMain) {
|
|
||||||
if (balanceByAddr && Object.keys(balanceByAddr).length) {
|
if (balanceByAddr && Object.keys(balanceByAddr).length) {
|
||||||
$rootScope.balanceByAddr = balanceByAddr;
|
$rootScope.balanceByAddr = balanceByAddr;
|
||||||
$scope.isMain = isMain;
|
$scope.isMain = isMain;
|
||||||
|
|
|
@ -410,7 +410,7 @@ Wallet.prototype.addressIsOwn = function(addrStr) {
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.getBalance = function(cb) {
|
Wallet.prototype.getBalance = function(safe, cb) {
|
||||||
var balance = 0;
|
var balance = 0;
|
||||||
var balanceByAddr = {};
|
var balanceByAddr = {};
|
||||||
var isMain = {};
|
var isMain = {};
|
||||||
|
@ -424,7 +424,8 @@ Wallet.prototype.getBalance = function(cb) {
|
||||||
balanceByAddr[a]=0;
|
balanceByAddr[a]=0;
|
||||||
isMain[a]=1;
|
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++) {
|
for(var i=0;i<utxos.length; i++) {
|
||||||
var u= utxos[i];
|
var u= utxos[i];
|
||||||
var amt = u.amount * COIN;
|
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) {
|
Wallet.prototype.createTx = function(toAddress, amountSatStr, opts, cb) {
|
||||||
console.log('[Wallet.js.447:createTx:]'); //TODO
|
|
||||||
var self = this;
|
var self = this;
|
||||||
if (typeof opts === 'function') {
|
if (typeof opts === 'function') {
|
||||||
cb = opts;
|
cb = opts;
|
||||||
|
@ -456,7 +473,8 @@ console.log('[Wallet.js.447:createTx:]'); //TODO
|
||||||
if (typeof opts.spendUnconfirmed === 'undefined') {
|
if (typeof opts.spendUnconfirmed === 'undefined') {
|
||||||
opts.spendUnconfirmed = this.spendUnconfirmed;
|
opts.spendUnconfirmed = this.spendUnconfirmed;
|
||||||
}
|
}
|
||||||
self.getUnspent(function(unspentList) {
|
|
||||||
|
self.getSafeUnspent(function(unspentList) {
|
||||||
// TODO check enough funds, etc.
|
// TODO check enough funds, etc.
|
||||||
self.createTxSync(toAddress, amountSatStr, unspentList, opts);
|
self.createTxSync(toAddress, amountSatStr, unspentList, opts);
|
||||||
self.sendPublicKeyRing(); // Change Address
|
self.sendPublicKeyRing(); // Change Address
|
||||||
|
@ -480,7 +498,6 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, utxos, opts) {
|
||||||
if (!opts.remainderOut) {
|
if (!opts.remainderOut) {
|
||||||
opts.remainderOut ={ address: this.generateAddress(true).toString() };
|
opts.remainderOut ={ address: this.generateAddress(true).toString() };
|
||||||
}
|
}
|
||||||
console.log('[Wallet.js.480:opts: CREATETXSYNC]',opts); //TODO
|
|
||||||
|
|
||||||
var b = new Builder(opts)
|
var b = new Builder(opts)
|
||||||
.setUnspent(utxos)
|
.setUnspent(utxos)
|
||||||
|
|
|
@ -31,9 +31,13 @@ console.log('[controllerUtils.js.30:created:] RECV '); //TODO
|
||||||
$location.path('peer');
|
$location.path('peer');
|
||||||
$rootScope.wallet = w;
|
$rootScope.wallet = w;
|
||||||
|
|
||||||
$rootScope.wallet.getBalance(function(balance) {
|
$rootScope.wallet.getBalance(false,function(balance) {
|
||||||
$rootScope.totalBalance = balance;
|
$rootScope.totalBalance = balance;
|
||||||
});
|
});
|
||||||
|
$rootScope.wallet.getBalance(true,function(balance) {
|
||||||
|
$rootScope.availableBalance = balance;
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
w.on('refresh', function() {
|
w.on('refresh', function() {
|
||||||
console.log('[controllerUtils.js] Refreshing'); //TODO
|
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
|
console.log('[controllerUtils.js.45] setupUxHandlers END'); //TODO
|
||||||
};
|
};
|
||||||
|
|
||||||
root.setSocketHandlers = function(cb) {
|
root.setSocketHandlers = function() {
|
||||||
Socket.removeAllListeners();
|
Socket.removeAllListeners();
|
||||||
|
var w = $rootScope.wallet;
|
||||||
|
|
||||||
var addrs = $rootScope.wallet.getAddressesStr();
|
var addrs = $rootScope.wallet.getAddressesStr();
|
||||||
for(var i = 0; i < addrs.length; i++) {
|
for(var i = 0; i < addrs.length; i++) {
|
||||||
|
@ -59,14 +64,13 @@ console.log('[controllerUtils.js.45] setupUxHandlers END'); //TODO
|
||||||
addrs.forEach(function(addr) {
|
addrs.forEach(function(addr) {
|
||||||
Socket.on(addr, function(txid) {
|
Socket.on(addr, function(txid) {
|
||||||
console.log('Received!', txid);
|
console.log('Received!', txid);
|
||||||
$rootScope.wallet.getBalance(function(balance, balanceByAddr) {
|
w.getBalance(false,function(balance, balanceByAddr) {
|
||||||
$rootScope.$apply(function() {
|
|
||||||
$rootScope.totalBalance = balance;
|
$rootScope.totalBalance = balance;
|
||||||
$rootScope.balanceByAddr = balanceByAddr;
|
$rootScope.balanceByAddr = balanceByAddr;
|
||||||
|
console.log('New balance:', balance);
|
||||||
|
w.getBalance(true,function(balance) {
|
||||||
|
$rootScope.availableBalance = balance;
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('New balance:', balance);
|
|
||||||
if (typeof cb === 'function') return cb();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -128,9 +128,6 @@ describe('TxProposals model', function() {
|
||||||
w.getUsedUnspent()[0].should.equal(unspentTest[0].txid);
|
w.getUsedUnspent()[0].should.equal(unspentTest[0].txid);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it('#merge with self', function () {
|
it('#merge with self', function () {
|
||||||
var priv = new PrivateKey(config);
|
var priv = new PrivateKey(config);
|
||||||
var w = new TxProposals({
|
var w = new TxProposals({
|
||||||
|
|
Loading…
Reference in New Issue