mirror of
https://github.com/corda/corda.git
synced 2025-02-20 09:26:41 +00:00
Add a time parameter to the contract verify function.
This commit is contained in:
parent
163175860d
commit
1298c4b8ed
@ -2,6 +2,7 @@ package contracts
|
||||
|
||||
import core.*
|
||||
import java.security.PublicKey
|
||||
import java.time.Instant
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@ -55,7 +56,7 @@ fun Iterable<ContractState>.sumCashBy(owner: PublicKey) = this.filterIsInstance<
|
||||
*/
|
||||
object CashContract : Contract {
|
||||
/** This is the function EVERYONE runs */
|
||||
override fun verify(inStates: List<ContractState>, outStates: List<ContractState>, args: List<VerifiedSigned<Command>>) {
|
||||
override fun verify(inStates: List<ContractState>, outStates: List<ContractState>, args: List<VerifiedSigned<Command>>, time: Instant) {
|
||||
val cashInputs = inStates.filterIsInstance<CashState>()
|
||||
|
||||
requireThat {
|
||||
|
@ -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<out T : Command>(
|
||||
/**
|
||||
* 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<ContractState>, outStates: List<ContractState>, args: List<VerifiedSigned<Command>>)
|
||||
fun verify(inStates: List<ContractState>, outStates: List<ContractState>, args: List<VerifiedSigned<Command>>, time: Instant)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<PublicKey> {
|
||||
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user