mirror of
https://github.com/corda/corda.git
synced 2025-04-08 03:44:49 +00:00
cleanup
This commit is contained in:
parent
334dfb9d7b
commit
be397881a9
@ -46,11 +46,11 @@ class GenericContract : Contract {
|
||||
is Commands.Action -> {
|
||||
val inState = tx.inStates.single() as State
|
||||
val actions = actions(inState.details)
|
||||
val actions2 = actions2(inState.details)
|
||||
requireThat {
|
||||
"action must be defined" by ( actions2.containsKey(value.name) )
|
||||
"action must be authorized" by ( cmd.signers.any { actions[ value.name ]!!.contains(it) } )
|
||||
"output state must match action result state" by ( actions2[ value.name ]!!.kontract.equals(outState.details))
|
||||
"action must be defined" by ( actions.containsKey(value.name) )
|
||||
"action must be authorized" by ( cmd.signers.any { actions[ value.name ]!!.actors.any { party -> party.owningKey == it } } )
|
||||
"output state must match action result state" by ( actions[ value.name ]!!.kontract.equals(outState.details))
|
||||
"condition must be met" by ( true ) // todo
|
||||
}
|
||||
}
|
||||
is Commands.Issue -> {
|
||||
|
@ -57,19 +57,7 @@ fun liableParties(contract: Kontract) : Set<PublicKey> {
|
||||
return visit(contract);
|
||||
}
|
||||
|
||||
fun actions(contract: Kontract) : Map<String, Set<PublicKey>> {
|
||||
|
||||
when (contract) {
|
||||
is Zero -> return mapOf()
|
||||
is Transfer -> return mapOf()
|
||||
is Action -> return mapOf( contract.name to contract.actors.map { it.owningKey }.toSet() )
|
||||
is Or -> return contract.contracts.map { it.name to it.actors.map { it.owningKey }.toSet() }.toMap()
|
||||
}
|
||||
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
|
||||
fun actions2(contract: Kontract) : Map<String, Action> {
|
||||
fun actions(contract: Kontract) : Map<String, Action> {
|
||||
|
||||
when (contract) {
|
||||
is Zero -> return mapOf()
|
||||
|
@ -18,9 +18,10 @@ val acmeCorporationHasDefaulted = DummyObservable<Boolean>()
|
||||
// example:
|
||||
val euribor3monthFixing = DummyObservable<BigDecimal>()
|
||||
|
||||
// Test parties
|
||||
val roadRunner = Party("Road Runner", generateKeyPair().public)
|
||||
val wileECoyote = Party("Wile E. Coyote", generateKeyPair().public)
|
||||
val porkPig = Party("Porky Pig", generateKeyPair().public)
|
||||
val porkyPig = Party("Porky Pig", generateKeyPair().public)
|
||||
|
||||
//
|
||||
// Example:
|
||||
|
@ -8,7 +8,7 @@ import java.util.*
|
||||
* Created by sofusmortensen on 23/05/16.
|
||||
*/
|
||||
|
||||
class Builder2 {
|
||||
class ContractBuilder {
|
||||
val contracts = mutableListOf<Kontract>()
|
||||
|
||||
fun Party.gives(beneficiary: Party, amount: Amount<Currency>) {
|
||||
@ -27,16 +27,15 @@ interface GivenThatResolve {
|
||||
fun resolve(contract: Kontract)
|
||||
}
|
||||
|
||||
class Builder(val actors: Array<Party>) {
|
||||
class ActionBuilder(val actors: Array<Party>) {
|
||||
val actions = mutableListOf<Action>()
|
||||
|
||||
fun String.givenThat(condition: Observable<Boolean>, init: Builder2.() -> Unit ) {
|
||||
val b = Builder2()
|
||||
fun String.givenThat(condition: Observable<Boolean>, init: ContractBuilder.() -> Unit ) {
|
||||
val b = ContractBuilder()
|
||||
b.init()
|
||||
actions.add( Action(this, condition, actors, b.final() ) )
|
||||
}
|
||||
|
||||
|
||||
fun String.givenThat(condition: Observable<Boolean> ) : GivenThatResolve {
|
||||
val This = this
|
||||
return object : GivenThatResolve {
|
||||
@ -46,21 +45,21 @@ class Builder(val actors: Array<Party>) {
|
||||
}
|
||||
}
|
||||
|
||||
fun String.anytime(init: Builder2.() -> Unit ) {
|
||||
val b = Builder2()
|
||||
fun String.anytime(init: ContractBuilder.() -> Unit ) {
|
||||
val b = ContractBuilder()
|
||||
b.init()
|
||||
actions.add( Action(this, const(true), actors, b.final() ) )
|
||||
}
|
||||
}
|
||||
|
||||
fun Party.may(init: Builder.() -> Unit) : Or {
|
||||
val b = Builder(arrayOf(this))
|
||||
fun Party.may(init: ActionBuilder.() -> Unit) : Or {
|
||||
val b = ActionBuilder(arrayOf(this))
|
||||
b.init()
|
||||
return Or(b.actions.toTypedArray())
|
||||
}
|
||||
|
||||
fun Array<Party>.may(init: Builder.() -> Unit) : Or {
|
||||
val b = Builder(this)
|
||||
fun Array<Party>.may(init: ActionBuilder.() -> Unit) : Or {
|
||||
val b = ActionBuilder(this)
|
||||
b.init()
|
||||
return Or(b.actions.toTypedArray())
|
||||
}
|
||||
@ -68,8 +67,8 @@ fun Array<Party>.may(init: Builder.() -> Unit) : Or {
|
||||
infix fun Party.or(party: Party) = arrayOf(this, party)
|
||||
infix fun Array<Party>.or(party: Party) = this.plus(party)
|
||||
|
||||
fun kontract(init: Builder2.() -> Unit ) : Kontract {
|
||||
val b = Builder2()
|
||||
fun kontract(init: ContractBuilder.() -> Unit ) : Kontract {
|
||||
val b = ContractBuilder()
|
||||
b.init()
|
||||
return b.final();
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ class ZCB {
|
||||
input { inState }
|
||||
output { outState }
|
||||
|
||||
arg(porkPig.owningKey) { GenericContract.Commands.Action("execute") }
|
||||
arg(porkyPig.owningKey) { GenericContract.Commands.Action("execute") }
|
||||
this `fails requirement` "action must be authorized"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user