tx proposal test. PrivateKey

This commit is contained in:
Matias Alejo Garcia 2014-04-10 02:16:57 -03:00
commit fe989c5c39
6 changed files with 155 additions and 64 deletions

View file

@ -13,34 +13,53 @@ var Storage = imports.Storage || require('./Storage');
var storage = Storage.default();
function TxProposal(opts) {
this.tx = opts.tx;
this.seenBy = {};
this.signedBy = {};
this.tx = opts.tx;
this.seenBy = opts.seenBy || {};
this.signedBy = opts.signedBy || {};
};
module.exports = require('soop')(TxProposal);
function TxProposals(opts) {
opts = opts || {};
this.network = opts.networkName === 'livenet' ?
bitcore.networks.livenet : bitcore.networks.testnet;
this.publicKeyRing = opts.publicKeyRing;
this.requiredCopayers = opts.requiredCopayers || 3;
this.txs = [];
this.dirty = 1;
}
TxProposals.prototype.list = function() {
var ret = [];
var ret = [];
this.txs.forEach(function(tx) {
TxProposals.fromObj = function(o) {
var ret = new TxProposals({
networkName: o.networkName,
});
o.txs.forEach(function(t) {
var tx = new Transaction;
tx.parse(t.txHex);
ret.txs.push({
seenBy: t.seenBy,
signedBy: t.signedBy,
tx: tx,
});
});
return ret;
};
TxProposals.prototype.create = function(toAddress, amountSat, utxos, privs) {
TxProposals.prototype.toObj = function() {
var ret = [];
this.txs.forEach(function(t) {
ret.push({
seenBy: t.seenBy,
signedBy: t.signedBy,
txHex: t.tx.serialize(),
});
});
return {
txs: ret,
networkName: this.network.name,
};
};
TxProposals.prototype.create = function(toAddress, amountSat, utxos, priv) {
var pkr = this.publicKeyRing;
if (! pkr.isComplete() ) {
@ -57,18 +76,21 @@ TxProposals.prototype.create = function(toAddress, amountSat, utxos, privs) {
.setOutputs([{address: toAddress, amountSat: amountSat}])
;
if (privs) {
b.sign(privs);
if (priv) {
//console.log('*** SIGNING IDX:', pkr.addressIndex, pkr.changeAddressIndex);
b.sign( priv.getAll(pkr.addressIndex, pkr.changeAddressIndex) );
}
var tx = b.build();
var me = {};
if (priv)
me[priv.id] = Date.now();
this.txs.push(
new TxProposal({
signedBy: {
},
seenBy: {
},
tx: tx
signedBy: me,
seenBy: me,
tx: tx,
})
);
return tx;