add getUsedUnspent to txproposals

This commit is contained in:
Matias Alejo Garcia 2014-04-21 12:00:14 -03:00
parent 22eab0205b
commit 0523d99eda
4 changed files with 38 additions and 5 deletions

View File

@ -212,7 +212,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

@ -433,7 +433,7 @@ Wallet.prototype.getBalance = function(cb) {
}
for(var a in balanceByAddr){
balanceByAddr[a] = balanceByAddr[a]/COIN;
};
}
return cb(balance / COIN, balanceByAddr, isMain);
});
};

View File

@ -104,6 +104,33 @@ describe('TxProposals model', function() {
};
it('#getUsedUnspend', function () {
var priv = new PrivateKey(config);
var w = new TxProposals({
networkName: config.networkName,
});
var start = new Date().getTime();
var pkr=createPKR([priv]);
var ts = Date.now();
var isChange=0;
var index=0;
unspentTest[0].address = pkr.getAddress(index, isChange).toString();
unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange);
w.add(createTx(
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
'123456789',
unspentTest,
{},
priv,
pkr
));
w.getUsedUnspent().length.should.equal(1);
w.getUsedUnspent()[0].should.equal(unspentTest[0].txid);
});
it('#merge with self', function () {
var priv = new PrivateKey(config);
var w = new TxProposals({
@ -472,8 +499,5 @@ var _dumpChunks = function (scriptSig, label) {
w2.merge(w);
Object.keys(w2.txps).length.should.equal(1);
});
});