diff --git a/lib/model/txproposal.js b/lib/model/txproposal.js index 38446b2..dc3f90d 100644 --- a/lib/model/txproposal.js +++ b/lib/model/txproposal.js @@ -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; diff --git a/lib/server.js b/lib/server.js index 2a6e8f3..858ce19 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1366,10 +1366,6 @@ WalletService.prototype.createTx2 = function(opts, cb) { if (!Utils.checkRequired(opts, ['outputs'])) return cb(new ClientError('Required argument missing')); - var type = opts.type || Model.TxProposal.Types.STANDARD; - if (!Model.TxProposal.isTypeSupported(type)) - return cb(new ClientError('Invalid proposal type')); - var feePerKb = opts.feePerKb || Defaults.DEFAULT_FEE_PER_KB; if (feePerKb < Defaults.MIN_FEE_PER_KB || feePerKb > Defaults.MAX_FEE_PER_KB) return cb(new ClientError('Invalid fee per KB value')); @@ -1383,16 +1379,13 @@ WalletService.prototype.createTx2 = function(opts, cb) { if (err) return cb(err); if (!canCreate) return cb(Errors.TX_CANNOT_CREATE); - if (type != Model.TxProposal.Types.EXTERNAL) { - var validationError = self._validateOutputs(opts, wallet); - if (validationError) { - return cb(validationError); - } + var validationError = self._validateOutputs(opts, wallet); + if (validationError) { + return cb(validationError); } var txOpts = { version: 3, - type: type, walletId: self.walletId, creatorId: self.copayerId, outputs: opts.outputs, diff --git a/test/integration/helpers.js b/test/integration/helpers.js index 6223d23..24fb9d0 100644 --- a/test/integration/helpers.js +++ b/test/integration/helpers.js @@ -372,13 +372,12 @@ helpers.createExternalProposalOpts = function(toAddress, amount, signingKey, mor }; -helpers.createStandardProposalOpts = function(outputs, moreOpts, inputs) { +helpers.createProposalOpts2 = function(outputs, moreOpts, inputs) { _.each(outputs, function(output) { output.amount = helpers.toSatoshi(output.amount); }); var opts = { - type: Model.TxProposal.Types.STANDARD, outputs: outputs, inputs: inputs || [], }; diff --git a/test/integration/server.js b/test/integration/server.js index fb21ba3..4328f8a 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -2342,7 +2342,7 @@ describe('Wallet service', function() { it('should create a tx', function(done) { helpers.stubUtxos(server, wallet, [1, 2], function() { - var txOpts = helpers.createStandardProposalOpts([{ + var txOpts = helpers.createProposalOpts2([{ toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', amount: 0.8 }], { diff --git a/test/models/txproposal.js b/test/models/txproposal.js index ea6627f..28d0cb7 100644 --- a/test/models/txproposal.js +++ b/test/models/txproposal.js @@ -16,14 +16,6 @@ describe('TxProposal', function() { txp.amount.should.equal(30000000); txp.network.should.equal('livenet'); }); - it('should create an external TxProposal', function() { - var txp = TxProposal.create(aTxpOpts(TxProposal.Types.EXTERNAL)); - should.exist(txp); - txp.outputs.length.should.equal(2); - txp.amount.should.equal(30000000); - txp.network.should.equal('livenet'); - should.exist(txp.inputs); - }); }); describe('#fromObj', function() { @@ -118,7 +110,6 @@ var theRawTx = '0100000001ab069f7073be9b491bb1ad4233a45d2e383082ccc7206df905662d var aTxpOpts = function(type) { var opts = { - type: type || TxProposal.Types.STANDARD, message: 'some message' }; opts.outputs = [{ @@ -131,24 +122,12 @@ var aTxpOpts = function(type) { message: "second message" }, ]; - if (type == TxProposal.Types.EXTERNAL) { - opts.inputs = [{ - "txid": "6ee699846d2d6605f96d20c7cc8230382e5da43342adb11b499bbe73709f06ab", - "vout": 8, - "satoshis": 100000000, - "scriptPubKey": "a914a8a9648754fbda1b6c208ac9d4e252075447f36887", - "address": "3H4pNP6J4PW4NnvdrTg37VvZ7h2QWuAwtA", - "path": "m/2147483647/0/1", - "publicKeys": ["0319008ffe1b3e208f5ebed8f46495c056763f87b07930a7027a92ee477fb0cb0f", "03b5f035af8be40d0db5abb306b7754949ab39032cf99ad177691753b37d101301"] - }]; - } return opts; }; var aTXP = function(type) { var txp = { "version": 3, - "type": type || TxProposal.Types.STANDARD, "createdOn": 1423146231, "id": "75c34f49-1ed6-255f-e9fd-0c71ae75ed1e", "walletId": "1",