diff --git a/src/contracts/Cash.kt b/src/contracts/Cash.kt index 2a7b13e227..8b71d4c278 100644 --- a/src/contracts/Cash.kt +++ b/src/contracts/Cash.kt @@ -2,6 +2,7 @@ package contracts import core.* import java.security.PublicKey +import java.time.Instant ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // @@ -55,7 +56,7 @@ fun Iterable.sumCashBy(owner: PublicKey) = this.filterIsInstance< */ object CashContract : Contract { /** This is the function EVERYONE runs */ - override fun verify(inStates: List, outStates: List, args: List>) { + override fun verify(inStates: List, outStates: List, args: List>, time: Instant) { val cashInputs = inStates.filterIsInstance() requireThat { diff --git a/src/core/Structures.kt b/src/core/Structures.kt index ace02471e8..e3f611c3cd 100644 --- a/src/core/Structures.kt +++ b/src/core/Structures.kt @@ -2,6 +2,7 @@ package core import java.security.PublicKey import java.security.Timestamp +import java.time.Instant /** * A contract state (or just "state") contains opaque data used by a contract program. It can be thought of as a disk @@ -86,11 +87,12 @@ data class VerifiedSigned( /** * Implemented by a program that implements business logic on the shared ledger. All participants run this code for * every [Transaction] they see on the network, for every input state. All input states must accept the transaction - * for it to be accepted: failure of any aborts the entire thing. + * for it to be accepted: failure of any aborts the entire thing. The time is taken from a trusted timestamp attached + * to the transaction itself i.e. it is NOT necessarily the current time. */ interface Contract { /** Must throw an exception if there's a problem that should prevent state transition. */ - fun verify(inStates: List, outStates: List, args: List>) + fun verify(inStates: List, outStates: List, args: List>, time: Instant) } /** diff --git a/src/core/TestUtils.kt b/src/core/TestUtils.kt index 9ef53aeee1..0813fb289a 100644 --- a/src/core/TestUtils.kt +++ b/src/core/TestUtils.kt @@ -2,6 +2,7 @@ package core import java.math.BigInteger import java.security.PublicKey +import java.time.Instant import kotlin.test.fail class DummyPublicKey(private val s: String) : PublicKey, Comparable { @@ -58,7 +59,7 @@ data class TransactionForTest( infix fun Contract.`fails requirement`(msg: String) { try { - verify(inStates, outStates, args) + verify(inStates, outStates, args, Instant.now()) } catch(e: Exception) { val m = e.message if (m == null) @@ -72,7 +73,7 @@ data class TransactionForTest( fun Contract.fails_requirement(msg: String) = this.`fails requirement`(msg) fun Contract.accepts() { - verify(inStates, outStates, args) + verify(inStates, outStates, args, Instant.now()) } // Allow customisation of partial transactions.