mirror of
https://github.com/corda/corda.git
synced 2025-06-22 09:08:49 +00:00
moved contracts.universal to experimental
This commit is contained in:
@ -3,6 +3,7 @@ package com.r3corda.contracts.universal
|
|||||||
import com.r3corda.core.contracts.*
|
import com.r3corda.core.contracts.*
|
||||||
import com.r3corda.core.crypto.Party
|
import com.r3corda.core.crypto.Party
|
||||||
import com.r3corda.core.crypto.SecureHash
|
import com.r3corda.core.crypto.SecureHash
|
||||||
|
import java.security.PublicKey
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by sofusmortensen on 23/05/16.
|
* Created by sofusmortensen on 23/05/16.
|
||||||
@ -12,7 +13,7 @@ val UNIVERSAL_PROGRAM_ID = UniversalContract()
|
|||||||
|
|
||||||
class UniversalContract : Contract {
|
class UniversalContract : Contract {
|
||||||
|
|
||||||
data class State(override val notary: Party,
|
data class State(override val participants: List<PublicKey>,
|
||||||
val details: Arrangement) : ContractState {
|
val details: Arrangement) : ContractState {
|
||||||
override val contract = UNIVERSAL_PROGRAM_ID
|
override val contract = UNIVERSAL_PROGRAM_ID
|
||||||
}
|
}
|
||||||
@ -30,7 +31,7 @@ class UniversalContract : Contract {
|
|||||||
class Issue : TypeOnlyCommandData(), Commands
|
class Issue : TypeOnlyCommandData(), Commands
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun verify(tx: TransactionForVerification) {
|
override fun verify(tx: TransactionForContract) {
|
||||||
|
|
||||||
requireThat {
|
requireThat {
|
||||||
"transaction has a single command".by (tx.commands.size == 1 )
|
"transaction has a single command".by (tx.commands.size == 1 )
|
||||||
@ -42,7 +43,7 @@ class UniversalContract : Contract {
|
|||||||
|
|
||||||
when (value) {
|
when (value) {
|
||||||
is Commands.Action -> {
|
is Commands.Action -> {
|
||||||
val inState = tx.inStates.single() as State
|
val inState = tx.inputs.single() as State
|
||||||
val actions = actions(inState.details)
|
val actions = actions(inState.details)
|
||||||
|
|
||||||
requireThat {
|
requireThat {
|
||||||
@ -51,9 +52,9 @@ class UniversalContract : Contract {
|
|||||||
"condition must be met" by ( true ) // todo
|
"condition must be met" by ( true ) // todo
|
||||||
}
|
}
|
||||||
|
|
||||||
when (tx.outStates.size) {
|
when (tx.outputs.size) {
|
||||||
1 -> {
|
1 -> {
|
||||||
val outState = tx.outStates.single() as State
|
val outState = tx.outputs.single() as State
|
||||||
requireThat {
|
requireThat {
|
||||||
"output state must match action result state" by (actions[value.name]!!.arrangement.equals(outState.details))
|
"output state must match action result state" by (actions[value.name]!!.arrangement.equals(outState.details))
|
||||||
}
|
}
|
||||||
@ -61,7 +62,7 @@ class UniversalContract : Contract {
|
|||||||
0 -> throw IllegalArgumentException("must have at least one out state")
|
0 -> throw IllegalArgumentException("must have at least one out state")
|
||||||
else -> {
|
else -> {
|
||||||
|
|
||||||
var allContracts = And( tx.outStates.map { (it as State).details }.toSet() )
|
var allContracts = And( tx.outputs.map { (it as State).details }.toSet() )
|
||||||
|
|
||||||
requireThat {
|
requireThat {
|
||||||
"output states must match action result state" by (actions[value.name]!!.arrangement.equals(allContracts))
|
"output states must match action result state" by (actions[value.name]!!.arrangement.equals(allContracts))
|
||||||
@ -71,15 +72,15 @@ class UniversalContract : Contract {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
is Commands.Issue -> {
|
is Commands.Issue -> {
|
||||||
val outState = tx.outStates.single() as State
|
val outState = tx.outputs.single() as State
|
||||||
requireThat {
|
requireThat {
|
||||||
"the transaction is signed by all liable parties" by ( liableParties(outState.details).all { it in cmd.signers } )
|
"the transaction is signed by all liable parties" by ( liableParties(outState.details).all { it in cmd.signers } )
|
||||||
"the transaction has no input states" by tx.inStates.isEmpty()
|
"the transaction has no input states" by tx.inputs.isEmpty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is Commands.Move -> {
|
is Commands.Move -> {
|
||||||
val inState = tx.inStates.single() as State
|
val inState = tx.inputs.single() as State
|
||||||
val outState = tx.outStates.single() as State
|
val outState = tx.outputs.single() as State
|
||||||
requireThat {
|
requireThat {
|
||||||
"the transaction is signed by all liable parties" by
|
"the transaction is signed by all liable parties" by
|
||||||
( liableParties(outState.details).all { it in cmd.signers } )
|
( liableParties(outState.details).all { it in cmd.signers } )
|
||||||
@ -94,9 +95,9 @@ class UniversalContract : Contract {
|
|||||||
override val legalContractReference: SecureHash
|
override val legalContractReference: SecureHash
|
||||||
get() = throw UnsupportedOperationException()
|
get() = throw UnsupportedOperationException()
|
||||||
|
|
||||||
fun generateIssue(tx: TransactionBuilder, arrangement: Arrangement, at: PartyAndReference, notary: Party) {
|
fun generateIssue(tx: TransactionBuilder, arrangement: Arrangement, at: PartyAndReference, notary: PublicKey) {
|
||||||
check(tx.inputStates().isEmpty())
|
check(tx.inputStates().isEmpty())
|
||||||
tx.addOutputState( State(notary, arrangement) )
|
tx.addOutputState( State(listOf(notary), arrangement) )
|
||||||
tx.addCommand(Commands.Issue(), at.party.owningKey)
|
tx.addCommand(Commands.Issue(), at.party.owningKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package com.r3corda.contracts.universal
|
package com.r3corda.contracts.universal
|
||||||
|
|
||||||
import com.r3corda.core.testing.DUMMY_NOTARY
|
import com.r3corda.core.testing.DUMMY_NOTARY
|
||||||
|
import com.r3corda.core.testing.DUMMY_NOTARY_KEY
|
||||||
import com.r3corda.core.testing.transaction
|
import com.r3corda.core.testing.transaction
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
@ -21,11 +22,11 @@ class FXSwap {
|
|||||||
val transfer1 = arrange { wileECoyote.gives(roadRunner, 1200.K*USD) }
|
val transfer1 = arrange { wileECoyote.gives(roadRunner, 1200.K*USD) }
|
||||||
val transfer2 = arrange { roadRunner.gives(wileECoyote, 1.M*EUR) }
|
val transfer2 = arrange { roadRunner.gives(wileECoyote, 1.M*EUR) }
|
||||||
|
|
||||||
val outState1 = UniversalContract.State( DUMMY_NOTARY, transfer1 )
|
val outState1 = UniversalContract.State( listOf(DUMMY_NOTARY.owningKey), transfer1 )
|
||||||
val outState2 = UniversalContract.State( DUMMY_NOTARY, transfer2 )
|
val outState2 = UniversalContract.State( listOf(DUMMY_NOTARY.owningKey), transfer2 )
|
||||||
|
|
||||||
|
|
||||||
val inState = UniversalContract.State( DUMMY_NOTARY, contract)
|
val inState = UniversalContract.State( listOf(DUMMY_NOTARY.owningKey), contract)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `issue - signature`() {
|
fun `issue - signature`() {
|
@ -28,12 +28,12 @@ class ZCB {
|
|||||||
val transfer = arrange { wileECoyote.gives(roadRunner, 100.K*GBP) }
|
val transfer = arrange { wileECoyote.gives(roadRunner, 100.K*GBP) }
|
||||||
val transferWrong = arrange { wileECoyote.gives(roadRunner, 80.K*GBP) }
|
val transferWrong = arrange { wileECoyote.gives(roadRunner, 80.K*GBP) }
|
||||||
|
|
||||||
val inState = UniversalContract.State( DUMMY_NOTARY, contract )
|
val inState = UniversalContract.State( listOf(DUMMY_NOTARY.owningKey), contract )
|
||||||
|
|
||||||
val outState = UniversalContract.State( DUMMY_NOTARY, transfer )
|
val outState = UniversalContract.State( listOf(DUMMY_NOTARY.owningKey), transfer )
|
||||||
val outStateWrong = UniversalContract.State( DUMMY_NOTARY, transferWrong )
|
val outStateWrong = UniversalContract.State( listOf(DUMMY_NOTARY.owningKey), transferWrong )
|
||||||
|
|
||||||
val outStateMove = UniversalContract.State( DUMMY_NOTARY, contractMove )
|
val outStateMove = UniversalContract.State( listOf(DUMMY_NOTARY.owningKey), contractMove )
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun basic() {
|
fun basic() {
|
Reference in New Issue
Block a user