From 8f2511875f0bfe501091048e9edc1bed23b2e9ca Mon Sep 17 00:00:00 2001 From: Christos Porios Date: Mon, 11 Sep 2017 23:17:29 +0000 Subject: [PATCH] More CR fixes. --- src/direct_trust.js | 15 ++++++--------- src/trust_db.js | 2 +- src/trust_is_risk.js | 6 ++---- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/direct_trust.js b/src/direct_trust.js index 15fbae6..3ed4fcf 100644 --- a/src/direct_trust.js +++ b/src/direct_trust.js @@ -63,15 +63,12 @@ class DirectTrust { isValid() : boolean { // TODO: Consider removing this function and ensure validity at build time by using the flow // type system, possibly by creating sub-types like "IncreasingDirectTrust" etc. - var valid = true; - - if ((this.outputIndex === null) !== (this.script === null)) valid = false; - if (this.outputIndex === null && this.isIncrease()) valid = false; - if (this.outputIndex === null && this.amount > 0) valid = false; - if (this.isIncrease() && this.isNull()) valid = false; - if (this.isSpent() && this.isNull()) valid = false; - - return valid; + if ((this.outputIndex === null) !== (this.script === null)) return false; + if (this.outputIndex === null && this.isIncrease()) return false; + if (this.outputIndex === null && this.amount > 0) return false; + if (this.isIncrease() && this.isNull()) return false; + if (this.isSpent() && this.isNull()) return false; + return true; } getOriginEntity() : Entity { diff --git a/src/trust_db.js b/src/trust_db.js index 0af2541..d41e680 100644 --- a/src/trust_db.js +++ b/src/trust_db.js @@ -71,7 +71,7 @@ class TrustDB { } getEntities() : Entity[] { - return this.entities.slice(0, this.entities.length); + return this.entities.slice(); } getEntityIndex(entity : Entity) : number { diff --git a/src/trust_is_risk.js b/src/trust_is_risk.js index 367bbee..d92a947 100644 --- a/src/trust_is_risk.js +++ b/src/trust_is_risk.js @@ -205,9 +205,7 @@ class TrustIsRisk { getInputTrusts(inputs : bcoin$Input[]) : DirectTrust[] { return inputs.map((input) => { - var trust = this.db.getDirectTrustByOutpoint(input.prevout); - if (trust && trust.outputIndex === input.prevout.index) return trust; - else return null; + return this.db.getDirectTrustByOutpoint(input.prevout); }).filter(Boolean); } @@ -224,7 +222,7 @@ class TrustIsRisk { nextTrust.prev = prevTrust; - assert(nextTrust.amount - prevTrust.amount <= 0); + assert(nextTrust.amount <= prevTrust.amount); return nextTrust; }