This commit is contained in:
Matias Alejo Garcia 2014-04-18 19:28:28 -03:00
parent 270891b5fd
commit 04d7d5abf0
11 changed files with 264 additions and 573 deletions

View File

@ -215,7 +215,7 @@
<h3>Address</h3>
<div class="row">
<div class="large-6 columns">
<a class="panel db" ng-repeat="addr in addrs" ng-click="selectAddr(addr)">{{addr}} <span class="right">{{balanceByAddr[addr] || 0}} BTC &gt;</span></a>
<a class="panel db" ng-repeat="addr in addrs" ng-click="selectAddr(addr)">{{addr}} <span class="right">{{balanceByAddr[addr] || 0}} BTC</span></a>
</div>
<div class="large-3 columns line-dashed-v text-center">
<qrcode size="160" data="{{selectedAddr}}"></qrcode>
@ -238,20 +238,27 @@
<div class="row" ng-show='$root.wallet.publicKeyRing.isComplete()'>
<div class="large-12 columns">
<h3>Pending Transactions <small>({{txs.length}})</small></h3>
<div class="panel pending" ng-repeat="txp in txs">
<div class="row" ng-repeat="o in txs.outs">
<p class="large-5 columns"> {{o.address}}</p>
<i class="large-2 columns fi-arrow-right size-16 text-center"></i>
<div class="panel pending" ng-repeat="tx in txs">
NTXID: {{tx.ntxid}}
CREATOR: {{tx.creator}}
CREATED_TS: {{tx.createdTs}}
<div class="row" ng-repeat="o in tx.outs">
<p class="large-5 columns"> {{o.value}} BTC </p>
<i class="large-2 columns fi-arrow-right size-16 text-center"></i>
<p class="large-5 columns"> {{o.address}}</p>
</div>
<div class="large-12 columns m0 panel panel-sign" ng-show="txp.signedByUs">
<i class="fi-check size-40"></i> YOU SIGNED!
<div class="large-12 columns m0 panel panel-sign" ng-show="tx.signedByUs">
<i class="fi-check size-40"></i> Signed by you already
</div>
<div class="large-12 columns m0" ng-show="!txp.signedByUs">
<div class="large-12 columns m0" ng-show="!tx.signedByUs">
<div class="line"></div>
<button class="primary round large-4 columns"><i class="large-2 columns fi-x size-16 text-center"></i> Ignore</button>
<small class="large-4 columns text-center">Faltan 3 cosigners</small>
<button class="secondary round large-4 columns" ng-click="sign(txp.ntxid)"><i class="large-2 columns fi-check size-16 text-center"></i> Sign</button>
<small class="large-4 columns text-center">
<span ng-show="tx.missingSignatures==1"> One signature </span>
<span ng-show="tx.missingSignatures>1"> {{tx.missingSignatures}} signatures </span>
missing
</small>
<button class="secondary round large-4 columns" ng-click="sign(tx.ntxid)"><i class="large-2 columns fi-check size-16 text-center"></i> Sign</button>
</div>
</div> <!-- end of row -->
</div> <!-- end of pending -->

View File

@ -3,13 +3,13 @@
var config = {
networkName: 'testnet',
network: {
// key: 'lwjd5qra8257b9',
// key: 'lwjd5qra8257b9',
// This is for running local peerJs with params: ./peerjs -p 10009 -k 'sdfjhwefh'
key: 'sdfjhwefh',
host: '192.168.1.100',
port: 10009,
path: '/',
maxPeers: 10,
key: 'sdfjhwefh',
host: 'localhost',
port: 10009,
path: '/',
maxPeers: 3,
debug: 3,
},
limits: {
@ -23,12 +23,12 @@ var config = {
verbose: 1,
},
blockchain: {
host: 'test.insight.is',
port: 80
host: 'localhost',
port: 3001
},
socket: {
host: 'test.insight.is',
port: 80
host: 'localhost',
port: 3001
},
verbose: 1,
};

View File

@ -10,10 +10,12 @@ angular.module('copay.home').controller('HomeController',
var _updateBalance = function () {
w.getBalance(function (balance, balanceByAddr) {
$scope.balanceByAddr = balanceByAddr;
$scope.addrs = Object.keys(balanceByAddr);
$scope.selectedAddr = $scope.addrs[0];
$scope.$digest();
if (balanceByAddr && Object.keys(balanceByAddr).length) {
$scope.balanceByAddr = balanceByAddr;
$scope.addrs = Object.keys(balanceByAddr);
$scope.selectedAddr = $scope.addrs[0];
$scope.$digest();
}
});
var socket = Socket($scope);
controllerUtils.handleTransactionByAddress($scope, _updateBalance);
@ -33,4 +35,5 @@ angular.module('copay.home').controller('HomeController',
$location.path('signin');
}
_updateBalance();
w.on('refresh',_updateBalance);
});

View File

@ -1,4 +1,5 @@
'use strict';
var bitcore = require('bitcore');
angular.module('copay.transactions').controller('TransactionsController',
function($scope, $rootScope, $location, Socket, controllerUtils) {
@ -9,7 +10,7 @@ angular.module('copay.transactions').controller('TransactionsController',
var _updateTxs = function() {
var w =$rootScope.wallet;
var inT = w.getTxProposals();
var ts = [];
var txs = [];
inT.forEach(function(i){
var b = i.txp.builder;
@ -18,20 +19,27 @@ angular.module('copay.transactions').controller('TransactionsController',
feeSat: b.feeSat,
};
var outs = [];
var bitcore = require('bitcore');
tx.outs.forEach(function(o) {
var s = o.getScript();
var aStr = bitcore.Address.fromScript(s, config.networkName).toString();
if (!w.addressIsOwn(aStr))
var addr = bitcore.Address.fromScriptPubKey(o.getScript(), config.networkName)[0].toString();
if (!w.addressIsOwn(addr)) {
outs.push({
address: aStr,
address: addr,
value: bitcore.util.valueToBigInt(o.getValue())/bitcore.util.COIN,
});
}
});
one.outs = outs;
ts.push(one);
// TOD: check missingSignatures === in al inputs?
one.missingSignatures = tx.countInputMissingSignatures(0);
one.signedByUs = i.signedByUs;
one.ntxid = i.ntxid;
one.creator = i.txp.creator,
one.createdTs = i.txp.createdTs;
txs.push(one);
});
$scope.txs = ts;
$scope.txs = txs;
};
@ -40,6 +48,8 @@ angular.module('copay.transactions').controller('TransactionsController',
}
else {
_updateTxs();
var w = $rootScope.wallet;
w.on('refresh',_updateTxs);
var socket = Socket($scope);
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
}
@ -47,7 +57,23 @@ angular.module('copay.transactions').controller('TransactionsController',
$scope.sign = function (ntxid) {
var w = $rootScope.wallet;
var ret = w.sign(ntxid);
$rootScope.flashMessage = {type:'success', message: 'Transactions SEND! : ' + ret};
_updateTxs();
var p = w.getTxProposal(ntxid);
if (p.txp.builder.isFullySigned()) {
w.sendTx(ntxid, function(txid) {
$rootScope.flashMessage = txid
? {type:'success', message: 'Transactions SENT! txid:' + txid}
: {type:'error', message: 'There was an error sending the Transaction'}
;
});
}
else {
$rootScope.flashMessage = ret
? {type:'success', message: 'Transactions signed'}
: {type:'error', message: 'There was an error signing the Transaction'}
;
}
_updateTxs();
};
});

View File

@ -102,7 +102,7 @@ Insight.prototype._request = function(options, callback) {
return callback({message: 'Wrong response from insight'});
}
} else {
return callback({message: 'Error ' + response.statusCode});
return callback({message: 'Error ' + request.status});
}
}
};

View File

@ -14,10 +14,27 @@ var Storage = imports.Storage || require('../storage/Base');
var storage = Storage.default();
function TxProposal(opts) {
this.creator = opts.creator;
this.createdTs = opts.createdTs;
this.seenBy = opts.seenBy || {};
this.signedBy = opts.signedBy || {};
this.builder = opts.builder;
}
TxProposal.prototype.toObj = function() {
var o = JSON.parse(JSON.stringify(this));
delete o['builder'];
o.builderObj = this.builder.toObj();
return o;
};
TxProposal.fromObj = function(o) {
var t = new TxProposal(o);
var b = new Builder.fromObj(o.builderObj);
t.builder = b;
return t;
};
module.exports = require('soop')(TxProposal);
@ -26,7 +43,7 @@ function TxProposals(opts) {
this.walletId = opts.walletId;
this.network = opts.networkName === 'livenet' ?
bitcore.networks.livenet : bitcore.networks.testnet;
this.txps = [];
this.txps = {};
}
TxProposals.fromObj = function(o) {
@ -34,12 +51,10 @@ TxProposals.fromObj = function(o) {
networkName: o.networkName,
walletId: o.walletId,
});
o.txps.forEach(function(t) {
ret.txps.push({
seenBy: t.seenBy,
signedBy: t.signedBy,
builder: new Builder.fromObj(t.builderObj),
});
o.txps.forEach(function(o2) {
var t = TxProposal.fromObj(o2);
var id = t.builder.build().getNormalizedHash().toString('hex');
ret.txps[id] = t;
});
return ret;
};
@ -47,13 +62,10 @@ TxProposals.fromObj = function(o) {
TxProposals.prototype.toObj = function() {
var ret = [];
this.txps.forEach(function(t) {
ret.push({
seenBy: t.seenBy,
signedBy: t.signedBy,
builderObj: t.builder.toObj(),
});
});
for(var id in this.txps){
var t = this.txps[id];
ret.push(t.toObj());
}
return {
txps: ret,
walletId: this.walletId,
@ -62,36 +74,27 @@ TxProposals.prototype.toObj = function() {
};
TxProposals.prototype._getNormHash = function(txps) {
var ret = {};
txps.forEach(function(txp) {
var hash = txp.builder.build().getNormalizedHash().toString('hex');
ret[hash]=txp;
});
return ret;
};
TxProposals.prototype._startMerge = function(myTxps, theirTxps) {
var fromUs=0, fromTheirs=0, merged =0;
var toMerge = {}, ready=[];
var toMerge = {}, ready={};
Object.keys(theirTxps).forEach(function(hash) {
for(var hash in theirTxps){
if (!myTxps[hash]) {
ready.push(theirTxps[hash]); // only in theirs;
ready[hash]=theirTxps[hash]; // only in theirs;
fromTheirs++;
}
else {
toMerge[hash]=theirTxps[hash]; // need Merging
merged++;
}
});
}
Object.keys(myTxps).forEach(function(hash) {
for(var hash in myTxps){
if(!toMerge[hash]) {
ready.push(myTxps[hash]); // only in myTxps;
ready[hash]=myTxps[hash]; // only in myTxps;
fromUs++;
}
});
}
return {
stats: {
@ -124,42 +127,48 @@ TxProposals.prototype._mergeMetadata = function(myTxps, theirTxps, mergeInfo) {
TxProposals.prototype._mergeBuilder = function(myTxps, theirTxps, mergeInfo) {
var self = this;
var toMerge = mergeInfo.toMerge;
Object.keys(toMerge).forEach(function(hash) {
for(var hash in toMerge){
var v0 = myTxps[hash].builder;
var v1 = toMerge[hash].builder;
v0.merge(v1);
});
};
};
TxProposals.prototype.add = function(data) {
this.txps.push( new TxProposal(data) );
var id = data.builder.build().getNormalizedHash().toString('hex');
this.txps[id] = new TxProposal(data);
};
TxProposals.prototype.remove = function(ntxid) {
console.log('[TxProposals.js.147] DELETING:', ntxid); //TODO
delete this.txps[ntxid];
};
TxProposals.prototype.merge = function(t) {
if (this.network.name !== t.network.name)
throw new Error('network mismatch in:', t);
var res = [];
var myTxps = this._getNormHash(this.txps);
var theirTxps = this._getNormHash(t.txps);
var myTxps = this.txps;
var theirTxps = t.txps;
var mergeInfo = this._startMerge(myTxps, theirTxps);
this._mergeMetadata(myTxps, theirTxps, mergeInfo);
this._mergeBuilder(myTxps, theirTxps, mergeInfo);
Object.keys(mergeInfo.toMerge).forEach(function(hash) {
mergeInfo.ready.push(myTxps[hash]);
mergeInfo.ready[hash] = myTxps[hash];
});
this.txps=mergeInfo.ready;
return mergeInfo.stats;
};
module.exports = require('soop')(TxProposals);

View File

@ -256,75 +256,82 @@ Wallet.prototype.generateAddress = function() {
return addr;
};
// TODO : sort by time... / signed.
Wallet.prototype.getTxProposals = function() {
var ret = [];
var self= this;
self.txProposals.txps.forEach(function(txp) {
for(var k in this.txProposals.txps) {
var txp = this.txProposals.txps[k];
var i = {txp:txp};
i.ntxid = txp.builder.build().getNormalizedHash();
i.signedByUs = txp.signedBy[self.privateKey.getId()]?true:false;
i.ntxid = k;
i.signedByUs = txp.signedBy[this.privateKey.getId()]?true:false;
ret.push(i);
});
return ret;
};
// TODO: this can be precalculated.
Wallet.prototype._findTxByNtxid = function(ntxid) {
var ret;
var l = this.txProposals.txps.length;
var id = ntxid.toString('hex');
for(var i=0; i<l; i++) {
var txp = this.txProposals.txps[i];
var id2 = txp.builder.build().getNormalizedHash().toString('hex');
if (id === id2 ) {
ret = txp;
}
}
return ret;
};
Wallet.prototype.getTxProposal = function(ntxid) {
var txp = this.txProposals.txps[ntxid];
var i = {txp:txp};
i.ntxid = ntxid;
i.signedByUs = txp.signedBy[this.privateKey.getId()]?true:false;
return i;
};
Wallet.prototype.sign = function(ntxid) {
var txp = this._findTxByNtxid(ntxid);
var self = this;
var txp = self.txProposals.txps[ntxid];
if (!txp) return;
var pkr = this.publicKeyRing;
var keys = this.privateKey.getAll(pkr.addressIndex, pkr.changeAddressIndex);
var ret = txp.builder.sign(keys);
var pkr = self.publicKeyRing;
var keys = self.privateKey.getAll(pkr.addressIndex, pkr.changeAddressIndex);
if (ret.signaturesAdded) {
txp.signedBy[this.privateKey.getId()] = Date.now();
this.log('[Wallet.js.230:ret:]',ret); //TODO
if (ret.isFullySigned) {
this.log('[Wallet.js.231] BROADCASTING TX!!!'); //TODO
var tx = txp.builder.build();
var txHex = tx.serialize().toString('hex');
this.blockchain.sendRawTransaction(txHex, function(txid) {
this.log('[Wallet.js.235:txid:]',txid); //TODO
if (txid) {
this.store(true);
}
});
}
else {
this.sendTxProposals();
this.store(true);
}
var b = txp.builder;
var before = b.signaturesAdded;
b.sign(keys);
var ret = false;
if (b.signaturesAdded > before) {
txp.signedBy[self.privateKey.getId()] = Date.now();
this.sendTxProposals();
this.store(true);
ret = true;
}
return ret;
};
Wallet.prototype.sendTx = function(ntxid) {
var txp = this.txProposals.txps[ntxid];
if (!txp) return;
var tx = txp.builder.build();
if (!tx.isComplete()) return;
this.log('[Wallet.js.231] BROADCASTING TX!!!'); //TODO
var txHex = tx.serialize().toString('hex');
this.log('[Wallet.js.261:txHex:]',txHex); //TODO
var self = this;
this.blockchain.sendRawTransaction(txHex, function(txid) {
self.log('BITCOND txid:',txid); //TODO
if (txid) {
self.txProposals.remove(ntxid);
self.store(true);
}
return (txid);
});
};
Wallet.prototype.addSeenToTxProposals = function() {
var ret=false;
var self=this;
this.txProposals.txps.forEach(function(txp) {
for(var k in this.txProposals.txps) {
var txp = this.txProposals.txps[k];
if (!txp.seenBy[self.privateKey.getId()]) {
txp.seenBy[self.privateKey.getId()] = Date.now();
ret = true;
}
});
}
return ret;
};
@ -359,9 +366,12 @@ Wallet.prototype.getBalance = function(cb) {
var balance = 0;
var balanceByAddr = {};
var COIN = bitcore.util.COIN;
var addresses = this.getAddressesStr(true);
if (!addresses.length) return cb(0,[]);
// Prefill balanceByAddr with main address
this.getAddressesStr(true).forEach(function(a){
addresses.forEach(function(a){
balanceByAddr[a]=0;
});
this.getUnspent(function(utxos) {
@ -371,9 +381,9 @@ Wallet.prototype.getBalance = function(cb) {
balance = balance + amt;
balanceByAddr[u.address] = (balanceByAddr[u.address]||0) + amt;
}
Object.keys(balanceByAddr).forEach(function(a) {
for(var a in balanceByAddr){
balanceByAddr[a] = balanceByAddr[a]/COIN;
});
};
return cb(balance / COIN, balanceByAddr);
});
};
@ -395,14 +405,10 @@ Wallet.prototype.createTx = function(toAddress, amountSatStr, opts, cb) {
if (typeof opts.spendUnconfirmed === 'undefined') {
opts.spendUnconfirmed = this.spendUnconfirmed;
}
if (!opts.remainderOut) {
opts.remainderOut={ address: this.publicKeyRing.generateAddress(true).toString()};
}
self.getUnspent(function(unspentList) {
// TODO check enough funds, etc.
self.createTxSync(toAddress, amountSatStr, unspentList, opts);
self.sendPublicKeyRing(); // Change Address
self.sendTxProposals();
self.store();
return cb();
@ -440,6 +446,8 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, utxos, opts) {
this.txProposals.add({
signedBy: priv && b.signaturesAdded ? me : {},
seenBy: priv ? me : {},
creator: priv.id,
createdTs: Date.now(),
builder: b,
});
};

View File

@ -23,7 +23,6 @@ angular.module('copay.controllerUtils').factory('controllerUtils', function ($ro
root.setupUxHandlers = function(w) {
w.on('badMessage', function(peerId) {
$rootScope.flashMessage = {type:'error', message: 'Received wrong message from peer id:' + peerId};
});

File diff suppressed because one or more lines are too long

1
lib/bitcore.js Symbolic link
View File

@ -0,0 +1 @@
../../bitcore/browser/bundle.js

View File

@ -125,21 +125,22 @@ describe('TxProposals model', function() {
priv,
pkr
));
var tx = w.txps[0].builder.build();
var k = Object.keys(w.txps)[0];
var tx = w.txps[k].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w.txps[0].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[0].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
w.merge(w);
w.txps.length.should.equal(1);
Object.keys(w.txps).length.should.equal(1);
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w.txps[0].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[0].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
});
@ -168,12 +169,13 @@ describe('TxProposals model', function() {
pkr
));
var tx = w.txps[0].builder.build();
var k = Object.keys(w.txps)[0];
var tx = w.txps[k].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(1);
Object.keys(w.txps[0].signedBy).length.should.equal(0);
Object.keys(w.txps[0].seenBy).length.should.equal(1);
Object.keys(w.txps[k].signedBy).length.should.equal(0);
Object.keys(w.txps[k].seenBy).length.should.equal(1);
var w2 = new TxProposals({
@ -191,21 +193,22 @@ describe('TxProposals model', function() {
pkr
));
var tx = w2.txps[0].builder.build();
var k = Object.keys(w.txps)[0];
var tx = w2.txps[k].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w2.txps[0].signedBy[priv.id] - ts > 0).should.equal(true);
(w2.txps[0].seenBy[priv.id] - ts > 0).should.equal(true);
(w2.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w2.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
w.merge(w2);
w.txps.length.should.equal(1);
Object.keys(w.txps).length.should.equal(1);
var tx = w.txps[0].builder.build();
var tx = w.txps[k].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w.txps[0].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[0].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
});
@ -243,12 +246,13 @@ var _dumpChunks = function (scriptSig, label) {
pkr
));
var tx = w.txps[0].builder.build();
var k = Object.keys(w.txps)[0];
var tx = w.txps[k].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(1);
Object.keys(w.txps[0].signedBy).length.should.equal(0);
Object.keys(w.txps[0].seenBy).length.should.equal(1);
Object.keys(w.txps[k].signedBy).length.should.equal(0);
Object.keys(w.txps[k].seenBy).length.should.equal(1);
var w2 = new TxProposals({
@ -265,21 +269,22 @@ var _dumpChunks = function (scriptSig, label) {
priv,
pkr
));
tx = w2.txps[0].builder.build();
var k = Object.keys(w2.txps)[0];
tx = w2.txps[k].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w2.txps[0].signedBy[priv.id] - ts > 0).should.equal(true);
(w2.txps[0].seenBy[priv.id] - ts > 0).should.equal(true);
(w2.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w2.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
w.merge(w2);
w.txps.length.should.equal(1);
Object.keys(w.txps).length.should.equal(1);
tx = w.txps[0].builder.build();
tx = w.txps[k].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w.txps[0].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[0].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
var w3 = new TxProposals({
@ -296,22 +301,22 @@ var _dumpChunks = function (scriptSig, label) {
priv2,
pkr
));
tx = w3.txps[0].builder.build();
tx = w3.txps[k].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w3.txps[0].signedBy[priv2.id] - ts > 0).should.equal(true);
(w3.txps[0].seenBy[priv2.id] - ts > 0).should.equal(true);
(w3.txps[k].signedBy[priv2.id] - ts > 0).should.equal(true);
(w3.txps[k].seenBy[priv2.id] - ts > 0).should.equal(true);
w.merge(w3);
w.txps.length.should.equal(1);
Object.keys(w.txps).length.should.equal(1);
(w.txps[0].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[0].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[0].signedBy[priv2.id] - ts > 0).should.equal(true);
(w.txps[0].seenBy[priv2.id] - ts > 0).should.equal(true);
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].signedBy[priv2.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv2.id] - ts > 0).should.equal(true);
tx = w.txps[0].builder.build();
tx = w.txps[k].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(1);
});
@ -341,11 +346,12 @@ var _dumpChunks = function (scriptSig, label) {
priv,
pkr
));
var tx = w.txps[0].builder.build();
var k = Object.keys(w.txps)[0];
var tx = w.txps[k].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w.txps[0].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[0].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
var w2 = new TxProposals({
@ -361,11 +367,11 @@ var _dumpChunks = function (scriptSig, label) {
priv2,
pkr
));
var tx = w2.txps[0].builder.build();
var tx = w2.txps[k].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w2.txps[0].signedBy[priv2.id] - ts > 0).should.equal(true);
(w2.txps[0].seenBy[priv2.id] - ts > 0).should.equal(true);
(w2.txps[k].signedBy[priv2.id] - ts > 0).should.equal(true);
(w2.txps[k].seenBy[priv2.id] - ts > 0).should.equal(true);
var w3 = new TxProposals({
@ -381,34 +387,34 @@ var _dumpChunks = function (scriptSig, label) {
priv3,
pkr
));
var tx = w3.txps[0].builder.build();
var tx = w3.txps[k].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w3.txps[0].signedBy[priv3.id] - ts > 0).should.equal(true);
(w3.txps[0].seenBy[priv3.id] - ts > 0).should.equal(true);
(w3.txps[k].signedBy[priv3.id] - ts > 0).should.equal(true);
(w3.txps[k].seenBy[priv3.id] - ts > 0).should.equal(true);
w.merge(w2);
w.txps.length.should.equal(1);
var tx = w.txps[0].builder.build();
Object.keys(w.txps).length.should.equal(1);
var tx = w.txps[k].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(1);
(w.txps[0].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[0].seenBy[priv2.id] - ts > 0).should.equal(true);
(w.txps[0].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[0].signedBy[priv2.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv2.id] - ts > 0).should.equal(true);
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].signedBy[priv2.id] - ts > 0).should.equal(true);
w.merge(w3);
var tx = w.txps[0].builder.build();
var tx = w.txps[k].builder.build();
tx.isComplete().should.equal(true);
tx.countInputMissingSignatures(0).should.equal(0);
w.txps.length.should.equal(1);
(w.txps[0].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[0].seenBy[priv2.id] - ts > 0).should.equal(true);
(w.txps[0].seenBy[priv3.id] - ts > 0).should.equal(true);
(w.txps[0].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[0].signedBy[priv2.id] - ts > 0).should.equal(true);
(w.txps[0].signedBy[priv3.id] - ts > 0).should.equal(true);
Object.keys(w.txps).length.should.equal(1);
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv2.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv3.id] - ts > 0).should.equal(true);
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].signedBy[priv2.id] - ts > 0).should.equal(true);
(w.txps[k].signedBy[priv3.id] - ts > 0).should.equal(true);
});
@ -435,11 +441,12 @@ var _dumpChunks = function (scriptSig, label) {
priv,
pkr
));
var tx = w.txps[0].builder.build();
var k = Object.keys(w.txps)[0];
var tx = w.txps[k].builder.build();
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
(w.txps[0].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[0].seenBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
var o = w.toObj();
should.exist(o);
@ -451,18 +458,22 @@ var _dumpChunks = function (scriptSig, label) {
should.exist(o.txps[0].builderObj.valueInSat);
should.exist(o.txps[0].signedBy[priv.id]);
var w2 = TxProposals.fromObj(o);
var o2 = JSON.parse(JSON.stringify(o));
var w2 = TxProposals.fromObj(o2);
w2.walletId.should.equal(w.walletId);
var tx2 = w2.txps[0].builder.build();
var tx2 = w2.txps[k].builder.build();
tx2.isComplete().should.equal(false);
tx2.countInputMissingSignatures(0).should.equal(2);
(w2.txps[0].signedBy[priv.id] - ts > 0).should.equal(true);
(w2.txps[0].seenBy[priv.id] - ts > 0).should.equal(true);
should.exist(w2.txps[0].builder);
should.exist(w2.txps[0].builder.valueInSat);
(w2.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
(w2.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
should.exist(w2.txps[k].builder);
should.exist(w2.txps[k].builder.valueInSat);
w2.merge(w);
Object.keys(w2.txps).length.should.equal(1);
});
});

View File

@ -126,11 +126,12 @@ describe('Wallet model', function() {
);
var t = w.txProposals;
var tx = t.txps[0].builder.build();
var k = Object.keys(t.txps)[0];
var tx = t.txps[k].builder.build();
should.exist(tx);
tx.isComplete().should.equal(false);
Object.keys(t.txps[0].signedBy).length.should.equal(1);
Object.keys(t.txps[0].seenBy).length.should.equal(1);
Object.keys(t.txps[k].signedBy).length.should.equal(1);
Object.keys(t.txps[k].seenBy).length.should.equal(1);
});
it('#addressIsOwn', function () {
@ -157,13 +158,14 @@ describe('Wallet model', function() {
unspentTest
);
var t = w.txProposals;
var tx = t.txps[0].builder.build();
var k = Object.keys(t.txps)[0];
var tx = t.txps[k].builder.build();
should.exist(tx);
tx.isComplete().should.equal(false);
tx.countInputMissingSignatures(0).should.equal(2);
( t.txps[0].signedBy[w.privateKey.id] - ts > 0).should.equal(true);
( t.txps[0].seenBy[w.privateKey.id] - ts > 0).should.equal(true);
( t.txps[k].signedBy[w.privateKey.id] - ts > 0).should.equal(true);
( t.txps[k].seenBy[w.privateKey.id] - ts > 0).should.equal(true);
}
}
});