|
|
@ -12,6 +12,22 @@ function TxProposal() { |
|
|
|
this.version = '1.0.1'; |
|
|
|
}; |
|
|
|
|
|
|
|
TxProposal.TYPE_SIMPLE = 'simple'; |
|
|
|
TxProposal.TYPE_MULTIPLEOUTPUTS = 'multiple-outputs'; |
|
|
|
|
|
|
|
TxProposal.prototype._createSimple = function(opts) { |
|
|
|
this.toAddress = opts.toAddress; |
|
|
|
this.amount = opts.amount; |
|
|
|
this.outputOrder = _.shuffle(_.range(2)); |
|
|
|
this.network = Bitcore.Address(this.toAddress).toObject().network; |
|
|
|
}; |
|
|
|
|
|
|
|
TxProposal.prototype._createMultipleOutputs = function(opts) { |
|
|
|
this.outputs = opts.outputs; |
|
|
|
this.outputOrder = _.shuffle(_.range(this.outputs.length + 1)); |
|
|
|
this.network = Bitcore.Address(this.outputs[0].toAddress).toObject().network; |
|
|
|
}; |
|
|
|
|
|
|
|
TxProposal.create = function(opts) { |
|
|
|
opts = opts || {}; |
|
|
|
|
|
|
@ -23,17 +39,6 @@ TxProposal.create = function(opts) { |
|
|
|
x.id = _.padLeft(now, 14, '0') + Uuid.v4(); |
|
|
|
x.walletId = opts.walletId; |
|
|
|
x.creatorId = opts.creatorId; |
|
|
|
if (x.type == 'multiple-outputs' && opts.outputs) { |
|
|
|
x.outputs = opts.outputs; |
|
|
|
} else if (x.type == 'multiple-outputs') { |
|
|
|
x.outputs = [{ |
|
|
|
toAddress: opts.toAddress, |
|
|
|
amount: opts.amount |
|
|
|
}]; |
|
|
|
} else { |
|
|
|
x.toAddress = opts.toAddress; |
|
|
|
x.amount = opts.amount; |
|
|
|
} |
|
|
|
x.message = opts.message; |
|
|
|
x.payProUrl = opts.payProUrl; |
|
|
|
x.proposalSignature = opts.proposalSignature; |
|
|
@ -44,13 +49,15 @@ TxProposal.create = function(opts) { |
|
|
|
x.requiredRejections = opts.requiredRejections; |
|
|
|
x.status = 'pending'; |
|
|
|
x.actions = []; |
|
|
|
var outputCount = x.outputs ? x.outputs.length + 1 : 2; |
|
|
|
x.outputOrder = _.shuffle(_.range(outputCount)); |
|
|
|
x.fee = null; |
|
|
|
var toAddress = x.outputs ? x.outputs[0].toAddress : x.toAddress; |
|
|
|
x.network = Bitcore.Address(toAddress).toObject().network; |
|
|
|
x.feePerKb = opts.feePerKb; |
|
|
|
|
|
|
|
if (x.type == TxProposal.TYPE_MULTIPLEOUTPUTS) { |
|
|
|
x._createMultipleOutputs(opts); |
|
|
|
} else { |
|
|
|
x._createSimple(opts); |
|
|
|
} |
|
|
|
|
|
|
|
return x; |
|
|
|
}; |
|
|
|
|
|
|
|