Merge pull request #121 from matiu/feature/ux13

Feature/ux13
This commit is contained in:
Manuel Aráoz 2014-04-21 13:18:16 -03:00
commit 5f66a179c9
9 changed files with 84 additions and 43 deletions

View file

@ -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');

View file

@ -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)

View file

@ -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)