|
|
@ -17,37 +17,12 @@ var TxProposalAction = require('./txproposalaction'); |
|
|
|
|
|
|
|
function TxProposal() {}; |
|
|
|
|
|
|
|
TxProposal.Types = { |
|
|
|
STANDARD: 'standard', |
|
|
|
EXTERNAL: 'external' |
|
|
|
}; |
|
|
|
|
|
|
|
TxProposal.isTypeSupported = function(type) { |
|
|
|
return _.contains(_.values(TxProposal.Types), type); |
|
|
|
}; |
|
|
|
|
|
|
|
TxProposal._create = {}; |
|
|
|
|
|
|
|
TxProposal._create.standard = function(txp, opts) { |
|
|
|
txp.outputs = _.map(opts.outputs, function(output) { |
|
|
|
return _.pick(output, ['amount', 'toAddress', 'message']); |
|
|
|
}); |
|
|
|
txp.outputOrder = _.shuffle(_.range(txp.outputs.length + 1)); |
|
|
|
}; |
|
|
|
|
|
|
|
TxProposal._create.external = function(txp, opts) { |
|
|
|
txp.setInputs(opts.inputs || []); |
|
|
|
txp.outputs = opts.outputs; |
|
|
|
txp.outputOrder = _.range(txp.outputs.length + 1); |
|
|
|
}; |
|
|
|
|
|
|
|
TxProposal.create = function(opts) { |
|
|
|
opts = opts || {}; |
|
|
|
|
|
|
|
var x = new TxProposal(); |
|
|
|
|
|
|
|
x.version = 3; |
|
|
|
x.type = opts.type || TxProposal.Types.STANDARD; |
|
|
|
|
|
|
|
var now = Date.now(); |
|
|
|
x.createdOn = Math.floor(now / 1000); |
|
|
@ -59,6 +34,10 @@ TxProposal.create = function(opts) { |
|
|
|
x.changeAddress = opts.changeAddress; |
|
|
|
x.inputs = []; |
|
|
|
x.inputPaths = []; |
|
|
|
x.outputs = _.map(opts.outputs, function(output) { |
|
|
|
return _.pick(output, ['amount', 'toAddress', 'message']); |
|
|
|
}); |
|
|
|
x.outputOrder = _.shuffle(_.range(x.outputs.length + 1)); |
|
|
|
x.requiredSignatures = opts.requiredSignatures; |
|
|
|
x.requiredRejections = opts.requiredRejections; |
|
|
|
x.walletN = opts.walletN; |
|
|
@ -73,10 +52,6 @@ TxProposal.create = function(opts) { |
|
|
|
|
|
|
|
x.customData = opts.customData; |
|
|
|
|
|
|
|
if (_.isFunction(TxProposal._create[x.type])) { |
|
|
|
TxProposal._create[x.type](x, opts); |
|
|
|
} |
|
|
|
|
|
|
|
x.amount = x.getTotalAmount(); |
|
|
|
try { |
|
|
|
x.network = opts.network || Bitcore.Address(x.outputs[0].toAddress).toObject().network; |
|
|
@ -90,7 +65,8 @@ TxProposal.fromObj = function(obj) { |
|
|
|
var x = new TxProposal(); |
|
|
|
|
|
|
|
x.version = obj.version; |
|
|
|
x.type = obj.type; |
|
|
|
$.checkState(x.version >= 3); |
|
|
|
|
|
|
|
x.createdOn = obj.createdOn; |
|
|
|
x.id = obj.id; |
|
|
|
x.walletId = obj.walletId; |
|
|
|