From fa32935e7724213820e8d819471274cc451b9b7c Mon Sep 17 00:00:00 2001 From: Richard G Brown Date: Sat, 21 Nov 2015 16:55:50 +0000 Subject: [PATCH] legalContractRef changed String to SecureHash (of contract contents) --- src/contracts/Cash.kt | 11 ++++++++++- src/contracts/CommercialPaper.kt | 3 ++- src/contracts/DummyContract.kt | 3 ++- src/contracts/JavaCommercialPaper.java | 5 +++-- src/core/Structures.kt | 8 +++++--- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/contracts/Cash.kt b/src/contracts/Cash.kt index 8b46c60fc9..bd23aa6176 100644 --- a/src/contracts/Cash.kt +++ b/src/contracts/Cash.kt @@ -29,7 +29,16 @@ class InsufficientBalanceException(val amountMissing: Amount) : Exception() * vaults can ignore the issuer/depositRefs and just examine the amount fields. */ object Cash : Contract { - override val legalContractReference: String = "https://www.big-book-of-banking-law.gov/cash-claims.html" + /** + * TODO: + * 1) hash should be of the contents, not the URI + * 2) allow the content to be specified at time of instance creation? + * Motivation: it's the difference between a state object referencing a programRef, which references a + * legalContractReference and a state object which directly references both. The latter allows the legal wording + * to evolve without requiring code changes. But creates a risk that users create objects governed by a program + * that is inconsistent with the legal contract + */ + override val legalContractReference: SecureHash = SecureHash.sha256("https://www.big-book-of-banking-law.gov/cash-claims.html"); /** A state representing a cash claim against some institution */ data class State( diff --git a/src/contracts/CommercialPaper.kt b/src/contracts/CommercialPaper.kt index 18273ea20b..197d32c64f 100644 --- a/src/contracts/CommercialPaper.kt +++ b/src/contracts/CommercialPaper.kt @@ -23,7 +23,8 @@ val CP_PROGRAM_ID = SecureHash.sha256("replace-me-later-with-bytecode-hash") // TODO: Generalise the notion of an owned instrument into a superclass/supercontract. Consider composition vs inheritance. object CommercialPaper : Contract { - override val legalContractReference: String = "https://en.wikipedia.org/wiki/Commercial_paper" + // TODO: should reference the content of the legal agreement, not its URI + override val legalContractReference: SecureHash = SecureHash.sha256("https://en.wikipedia.org/wiki/Commercial_paper") data class State( val issuance: InstitutionReference, diff --git a/src/contracts/DummyContract.kt b/src/contracts/DummyContract.kt index e7f117c3c0..c1a6b2ae41 100644 --- a/src/contracts/DummyContract.kt +++ b/src/contracts/DummyContract.kt @@ -18,5 +18,6 @@ object DummyContract : Contract { // Always accepts. } - override val legalContractReference: String = "/dev/null" + // The "empty contract" + override val legalContractReference: SecureHash = SecureHash.sha256("") } \ No newline at end of file diff --git a/src/contracts/JavaCommercialPaper.java b/src/contracts/JavaCommercialPaper.java index 0c81b06a9a..00611ae19a 100644 --- a/src/contracts/JavaCommercialPaper.java +++ b/src/contracts/JavaCommercialPaper.java @@ -118,7 +118,8 @@ public class JavaCommercialPaper implements Contract { @NotNull @Override - public String getLegalContractReference() { - return "https://en.wikipedia.org/wiki/Commercial_paper"; + public SecureHash getLegalContractReference() { + // TODO: Should return hash of the contract's contents, not its URI + return SecureHash.Companion.sha256("https://en.wikipedia.org/wiki/Commercial_paper"); } } diff --git a/src/core/Structures.kt b/src/core/Structures.kt index 859486382d..f95173aa3a 100644 --- a/src/core/Structures.kt +++ b/src/core/Structures.kt @@ -69,7 +69,9 @@ interface Contract { */ fun verify(tx: TransactionForVerification) - // TODO: This should probably be a hash of a document, rather than a URL to it. - /** Unparsed reference to the natural language contract that this code is supposed to express (usually a URL). */ - val legalContractReference: String + /** + * Unparsed reference to the natural language contract that this code is supposed to express (usually a hash of + * the contract's contents). + */ + val legalContractReference: SecureHash } \ No newline at end of file