2014-04-09 13:28:35 -07:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
var imports = require('soop').imports();
|
|
|
|
var bitcore = require('bitcore');
|
|
|
|
var coinUtil = bitcore.util;
|
|
|
|
var Transaction = bitcore.Transaction;
|
|
|
|
var Builder = bitcore.TransactionBuilder;
|
|
|
|
var buffertools = bitcore.buffertools;
|
|
|
|
|
|
|
|
var Storage = imports.Storage || require('./Storage');
|
|
|
|
var storage = Storage.default();
|
|
|
|
|
2014-04-09 16:37:14 -07:00
|
|
|
function TxProposal(opts) {
|
|
|
|
this.tx = opts.tx;
|
|
|
|
this.seenBy = {};
|
|
|
|
this.signedBy = {};
|
|
|
|
};
|
|
|
|
module.exports = require('soop')(TxProposal);
|
|
|
|
|
2014-04-09 13:28:35 -07:00
|
|
|
|
|
|
|
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 = [];
|
2014-04-09 16:37:14 -07:00
|
|
|
var ret = [];
|
2014-04-09 13:28:35 -07:00
|
|
|
|
|
|
|
this.txs.forEach(function(tx) {
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-04-09 19:04:22 -07:00
|
|
|
TxProposals.prototype.create = function(toAddress, amountSat, utxos, privs) {
|
2014-04-09 13:28:35 -07:00
|
|
|
var pkr = this.publicKeyRing;
|
|
|
|
|
|
|
|
if (! pkr.isComplete() ) {
|
|
|
|
throw new Error('publicKeyRing is not complete');
|
|
|
|
}
|
|
|
|
|
|
|
|
var opts = {
|
|
|
|
remainderOut: { address: pkr.generateAddress(true) }
|
|
|
|
};
|
|
|
|
|
|
|
|
var b = new Builder(opts)
|
|
|
|
.setUnspent(utxos)
|
|
|
|
.setHashToScriptMap(pkr.getRedeemScriptMap())
|
|
|
|
.setOutputs([{address: toAddress, amountSat: amountSat}])
|
|
|
|
;
|
|
|
|
|
2014-04-09 19:04:22 -07:00
|
|
|
if (privs) {
|
|
|
|
b.sign(privs);
|
2014-04-09 13:28:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var tx = b.build();
|
2014-04-09 16:37:14 -07:00
|
|
|
this.txs.push(
|
|
|
|
new TxProposal({
|
|
|
|
signedBy: {
|
|
|
|
},
|
|
|
|
seenBy: {
|
|
|
|
},
|
|
|
|
tx: tx
|
|
|
|
})
|
|
|
|
);
|
|
|
|
return tx;
|
2014-04-09 13:28:35 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
TxProposals.prototype.sign = function(index) {
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = require('soop')(TxProposals);
|