legalContractRef changed String to SecureHash (of contract contents)

This commit is contained in:
Richard G Brown 2015-11-21 16:55:50 +00:00 committed by Mike Hearn
parent 25a28a0a28
commit fa32935e77
5 changed files with 22 additions and 8 deletions

View File

@ -29,7 +29,16 @@ class InsufficientBalanceException(val amountMissing: Amount) : Exception()
* vaults can ignore the issuer/depositRefs and just examine the amount fields. * vaults can ignore the issuer/depositRefs and just examine the amount fields.
*/ */
object Cash : Contract { 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 */ /** A state representing a cash claim against some institution */
data class State( data class State(

View File

@ -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. // TODO: Generalise the notion of an owned instrument into a superclass/supercontract. Consider composition vs inheritance.
object CommercialPaper : Contract { 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( data class State(
val issuance: InstitutionReference, val issuance: InstitutionReference,

View File

@ -18,5 +18,6 @@ object DummyContract : Contract {
// Always accepts. // Always accepts.
} }
override val legalContractReference: String = "/dev/null" // The "empty contract"
override val legalContractReference: SecureHash = SecureHash.sha256("")
} }

View File

@ -118,7 +118,8 @@ public class JavaCommercialPaper implements Contract {
@NotNull @NotNull
@Override @Override
public String getLegalContractReference() { public SecureHash getLegalContractReference() {
return "https://en.wikipedia.org/wiki/Commercial_paper"; // TODO: Should return hash of the contract's contents, not its URI
return SecureHash.Companion.sha256("https://en.wikipedia.org/wiki/Commercial_paper");
} }
} }

View File

@ -69,7 +69,9 @@ interface Contract {
*/ */
fun verify(tx: TransactionForVerification) 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). */ * Unparsed reference to the natural language contract that this code is supposed to express (usually a hash of
val legalContractReference: String * the contract's contents).
*/
val legalContractReference: SecureHash
} }