From 27de2896d8d2a69fa4575d90ca073f04dbd1a3ec Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 17 Jun 2014 16:42:49 -0300 Subject: [PATCH] working on refactor --- js/models/core/TxProposals.js | 13 ++++++++----- js/models/core/Wallet.js | 13 +++---------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/js/models/core/TxProposals.js b/js/models/core/TxProposals.js index a4fd20117..da985431a 100644 --- a/js/models/core/TxProposals.js +++ b/js/models/core/TxProposals.js @@ -22,6 +22,11 @@ function TxProposal(opts) { this.comment = opts.comment || null; } +TxProposal.prototype.getID = function() { + var ntxid = this.builder.build().getNormalizedHash().toString('hex'); + return ntxid; +}; + TxProposal.prototype.toObj = function() { var o = JSON.parse(JSON.stringify(this)); delete o['builder']; @@ -47,7 +52,6 @@ TxProposal.getSentTs = function() { }; TxProposal.prototype.mergeBuilder = function(other) { - var v0 = this.builder; var v1 = other.builder; @@ -59,7 +63,6 @@ TxProposal.prototype.mergeBuilder = function(other) { }; TxProposal.prototype.mergeMetadata = function(v1) { - var events = []; var v0 = this; Object.keys(v1.seenBy).forEach(function(k) { @@ -250,12 +253,12 @@ TxProposals.prototype.merge = function(t) { }; TxProposals.prototype.add = function(data) { - var ntxid = data.builder.build().getNormalizedHash().toString('hex'); - this.txps[ntxid] = new TxProposal(data); + var txp = new TxProposal(data); + var ntxid = txp.getID(); + this.txps[ntxid] = txp; return ntxid; }; - TxProposals.prototype.setSent = function(ntxid, txid) { //sent TxProposals are local an not broadcasted. this.txps[ntxid].setSent(txid); diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 782881046..65013ee1c 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -120,17 +120,10 @@ Wallet.prototype._handleTxProposals = function(senderId, data, isInbound) { this.log('RECV TXPROPOSAL:', data); var recipients; - var inTxp = TxProposals.fromObj(data.txProposals); - var ids = inTxp.getNtxids(); + var inTxp = TxProposal.fromObj(data.txProposal); - if (ids.length > 1) { - this.emit('badMessage', senderId); - this.log('Received BAD TxProposal messsage FROM:', senderId); //TODO - return; - } - - var newId = ids[0]; - var mergeInfo = this.txProposals.merge(inTxp, true); + var newId = inTxp.getID(); + var mergeInfo = this.txProposals.merge(inTxp); var addSeen = this.addSeenToTxProposals(); if (mergeInfo.hasChanged || addSeen) { this.log('### BROADCASTING txProposals. ');