Skip to content

Commit

Permalink
More CR responses.
Browse files Browse the repository at this point in the history
  • Loading branch information
christosporios committed Sep 11, 2017
1 parent 8df2ff5 commit 86a512c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/trust_is_risk.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,18 @@ class TrustIsRisk {
return nextTrust;
}

// Looks for direct trust outputs that originate from a sender in an array of bitcoin outputs.
// Returns a list of the corresponding DirectTrust objects.
// Looks for direct trust outputs that originate from a sender in a transaction.
// Returns an array of the corresponding DirectTrust objects.
// If the recipient parameter is set, it will limit the results only to the outputs being sent to
// the recipient.
searchForDirectTrustOutputs(tx : bcoin$TX, origin : Entity, recipient : ?Entity) : DirectTrust[] {
var directTrusts = tx.outputs.map((output, outputIndex) =>
this.parseOutputAsDirectTrust(tx, outputIndex, origin)
).filter(Boolean);
).filter(Boolean); // filter out nulls

if (recipient) {
directTrusts.filter((trust) => trust.dest === recipient);
directTrusts = directTrusts.filter((trust) =>
helpers.pubKeyToEntity(trust.dest) === recipient);
}

return directTrusts;
Expand Down
10 changes: 10 additions & 0 deletions test/trust_is_risk.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ describe("TrustIsRisk", () => {
tir.getDirectTrust(alice, bob).should.equal(20 * COIN);
});

it("decreases trust to zero for trust decreasing transactions with a wrong recipient", () => {
// By changing the trust recipient from bob to charlie, we make the transaction a
// nullifying trust transaction.
trustDecreasingMTX.outputs[0] =
testHelpers.getOneOfTwoMultisigOutput(addr.alice.pubKey, addr.charlie.pubKey, 20 * COIN);

tir.addTX(trustDecreasingMTX.toTX());
tir.getDirectTrust(alice, bob).should.equal(0);
});

it("which has a second input decreases trust to zero", () => {
trustDecreasingMTX.inputs.push(testHelpers.getP2PKHInput(addr.alice.pubKey));
tir.addTX(trustDecreasingMTX.toTX());
Expand Down

0 comments on commit 86a512c

Please sign in to comment.