Replace Party with Party.Full

Replace Party with Party.Full as an interim step to introducing the Party.Anonymised class.

Signed-off-by: Ross Nicoll <ross.nicoll@r3.com>
This commit is contained in:
Ross Nicoll
2017-02-01 11:13:50 +00:00
parent 3572b78372
commit 1b86ddfd6e
137 changed files with 415 additions and 411 deletions

View File

@ -24,7 +24,7 @@ class Zero() : Arrangement {
//
// TODO: should be replaced with something that uses Corda assets and/or cash?
// TODO: should only be allowed to transfer non-negative amounts
data class Obligation(val amount: Perceivable<BigDecimal>, val currency: Currency, val from: Party, val to: Party) : Arrangement
data class Obligation(val amount: Perceivable<BigDecimal>, val currency: Currency, val from: Party.Full, val to: Party.Full) : Arrangement
// A combinator over a list of arrangements. Each arrangement in list will create a separate independent arrangement state.
// The ``And`` combinator cannot be root in a arrangement.

View File

@ -4,7 +4,7 @@ import net.corda.core.crypto.Party
import java.math.BigDecimal
import java.util.*
fun swap(partyA: Party, amountA: BigDecimal, currencyA: Currency, partyB: Party, amountB: BigDecimal, currencyB: Currency) =
fun swap(partyA: Party.Full, amountA: BigDecimal, currencyA: Currency, partyB: Party.Full, amountB: BigDecimal, currencyB: Currency) =
arrange {
partyA.owes(partyB, amountA, currencyA)
partyB.owes(partyA, amountB, currencyB)
@ -12,7 +12,7 @@ fun swap(partyA: Party, amountA: BigDecimal, currencyA: Currency, partyB: Party,
fun fx_swap(expiry: String, notional: BigDecimal, strike: BigDecimal,
foreignCurrency: Currency, domesticCurrency: Currency,
partyA: Party, partyB: Party) =
partyA: Party.Full, partyB: Party.Full) =
arrange {
actions {
(partyA or partyB).may {
@ -26,6 +26,6 @@ fun fx_swap(expiry: String, notional: BigDecimal, strike: BigDecimal,
// building an fx swap using abstract swap
fun fx_swap2(expiry: String, notional: Long, strike: Double,
foreignCurrency: Currency, domesticCurrency: Currency,
partyA: Party, partyB: Party) =
partyA: Party.Full, partyB: Party.Full) =
Action("execute", after(expiry) and (signedBy(partyA) or signedBy(partyB)),
swap(partyA, BigDecimal(notional * strike), domesticCurrency, partyB, BigDecimal(notional), foreignCurrency))

View File

@ -23,14 +23,14 @@ class ActionsBuilder {
else
Actions(actions.toSet())
infix fun Party.may(init: ActionBuilder.() -> Action): Action {
infix fun Party.Full.may(init: ActionBuilder.() -> Action): Action {
val builder = ActionBuilder(setOf(this))
builder.init()
actions.addAll(builder.actions)
return builder.actions.first()
}
infix fun Set<Party>.may(init: ActionBuilder.() -> Action): Action {
infix fun Set<Party.Full>.may(init: ActionBuilder.() -> Action): Action {
val builder = ActionBuilder(this)
builder.init()
actions.addAll(builder.actions)
@ -38,8 +38,8 @@ class ActionsBuilder {
return builder.actions.first()
}
infix fun Party.or(party: Party) = setOf(this, party)
infix fun Set<Party>.or(party: Party) = this.plus(party)
infix fun Party.Full.or(party: Party.Full) = setOf(this, party)
infix fun Set<Party.Full>.or(party: Party.Full) = this.plus(party)
fun String.givenThat(condition: Perceivable<Boolean>, init: ContractBuilder.() -> Arrangement): Action {
val b = ContractBuilder()
@ -67,13 +67,13 @@ open class ContractBuilder {
return c
}
fun Party.owes(beneficiary: Party, amount: BigDecimal, currency: Currency): Obligation {
fun Party.Full.owes(beneficiary: Party.Full, amount: BigDecimal, currency: Currency): Obligation {
val c = Obligation(const(amount), currency, this, beneficiary)
contracts.add(c)
return c
}
fun Party.owes(beneficiary: Party, amount: Perceivable<BigDecimal>, currency: Currency): Obligation {
fun Party.Full.owes(beneficiary: Party.Full, amount: Perceivable<BigDecimal>, currency: Currency): Obligation {
val c = Obligation(amount, currency, this, beneficiary)
contracts.add(c)
return c
@ -81,7 +81,7 @@ open class ContractBuilder {
@Deprecated(level = DeprecationLevel.ERROR, message = "Not allowed")
fun Action(@Suppress("UNUSED_PARAMETER") name: String, @Suppress("UNUSED_PARAMETER") condition: Perceivable<Boolean>,
@Suppress("UNUSED_PARAMETER") actors: Set<Party>, @Suppress("UNUSED_PARAMETER") arrangement: Arrangement) {
@Suppress("UNUSED_PARAMETER") actors: Set<Party.Full>, @Suppress("UNUSED_PARAMETER") arrangement: Arrangement) {
}
@Deprecated(level = DeprecationLevel.ERROR, message = "Not available")
@ -97,11 +97,11 @@ open class ContractBuilder {
}
@Deprecated(level = DeprecationLevel.ERROR, message = "Not available")
fun Party.may(init: ActionBuilder.() -> Action) {
fun Party.Full.may(init: ActionBuilder.() -> Action) {
}
@Deprecated(level = DeprecationLevel.ERROR, message = "Not available")
fun Set<Party>.may(init: ActionBuilder.() -> Action) {
fun Set<Party.Full>.may(init: ActionBuilder.() -> Action) {
}
val start = StartDate()
@ -152,7 +152,7 @@ interface GivenThatResolve {
fun resolve(contract: Arrangement)
}
class ActionBuilder(val actors: Set<Party>) {
class ActionBuilder(val actors: Set<Party.Full>) {
internal val actions = mutableListOf<Action>()
fun String.givenThat(condition: Perceivable<Boolean>, init: ContractBuilder.() -> Arrangement): Action {

View File

@ -75,10 +75,10 @@ class EndDate : Perceivable<Instant> {
}
}
data class ActorPerceivable(val actor: Party) : Perceivable<Boolean>
fun signedBy(actor: Party) : Perceivable<Boolean> = ActorPerceivable(actor)
data class ActorPerceivable(val actor: Party.Full) : Perceivable<Boolean>
fun signedBy(actor: Party.Full) : Perceivable<Boolean> = ActorPerceivable(actor)
fun signedByOneOf(actors: Collection<Party>): Perceivable<Boolean> =
fun signedByOneOf(actors: Collection<Party.Full>): Perceivable<Boolean> =
if (actors.size == 0)
const(true)
else
@ -149,7 +149,7 @@ operator fun Perceivable<BigDecimal>.div(n: Double) = PerceivableOperation(this,
operator fun Perceivable<Int>.plus(n: Int) = PerceivableOperation(this, Operation.PLUS, const(n))
operator fun Perceivable<Int>.minus(n: Int) = PerceivableOperation(this, Operation.MINUS, const(n))
data class TerminalEvent(val reference: Party, val source: CompositeKey) : Perceivable<Boolean>
data class TerminalEvent(val reference: Party.Full, val source: CompositeKey) : Perceivable<Boolean>
// todo: holidays
data class Interest(val amount: Perceivable<BigDecimal>, val dayCountConvention: String,

View File

@ -44,7 +44,7 @@ private class PrettyPrint(arr : Arrangement) {
val partyMap = mutableMapOf<CompositeKey, String>()
val usedPartyNames = mutableSetOf<String>()
fun createPartyName(party : Party) : String
fun createPartyName(party : Party.Full) : String
{
val parts = party.name.toLowerCase().split(' ')

View File

@ -25,7 +25,7 @@ class UniversalContract : Contract {
// replace parties
// must be signed by all parties present in contract before and after command
class Move(val from: Party, val to: Party) : TypeOnlyCommandData(), Commands
class Move(val from: Party.Full, val to: Party.Full) : TypeOnlyCommandData(), Commands
// must be signed by all liable parties present in contract
class Issue : TypeOnlyCommandData(), Commands

View File

@ -12,14 +12,14 @@ fun Instant.toLocalDate(): LocalDate = LocalDate.ofEpochDay(this.epochSecond / 6
fun LocalDate.toInstant(): Instant = Instant.ofEpochSecond(this.toEpochDay() * 60 * 60 * 24)
private fun signingParties(perceivable: Perceivable<Boolean>) : ImmutableSet<Party> =
private fun signingParties(perceivable: Perceivable<Boolean>) : ImmutableSet<Party.Full> =
when (perceivable) {
is ActorPerceivable -> ImmutableSet.of( perceivable.actor )
is PerceivableAnd -> Sets.union( signingParties( perceivable.left ), signingParties(perceivable.right) ).immutableCopy()
is PerceivableOr -> Sets.union( signingParties( perceivable.left ), signingParties(perceivable.right) ).immutableCopy()
is TimePerceivable -> ImmutableSet.of<Party>()
is TimePerceivable -> ImmutableSet.of<Party.Full>()
is TerminalEvent -> ImmutableSet.of( perceivable.reference )
is PerceivableComparison<*> -> ImmutableSet.of<Party>() // todo
is PerceivableComparison<*> -> ImmutableSet.of<Party.Full>() // todo
else -> throw IllegalArgumentException("signingParties " + perceivable)
}
@ -47,26 +47,26 @@ private fun liablePartiesVisitor(action: Action): ImmutableSet<CompositeKey> {
/** Returns list of potentially liable parties for a given contract */
fun liableParties(contract: Arrangement): Set<CompositeKey> = liablePartiesVisitor(contract)
private fun involvedPartiesVisitor(action: Action): Set<Party> =
private fun involvedPartiesVisitor(action: Action): Set<Party.Full> =
Sets.union(involvedPartiesVisitor(action.arrangement), signingParties(action.condition)).immutableCopy()
private fun involvedPartiesVisitor(arrangement: Arrangement): ImmutableSet<Party> =
private fun involvedPartiesVisitor(arrangement: Arrangement): ImmutableSet<Party.Full> =
when (arrangement) {
is Zero -> ImmutableSet.of<Party>()
is Zero -> ImmutableSet.of<Party.Full>()
is Obligation -> ImmutableSet.of(arrangement.from, arrangement.to)
is RollOut -> involvedPartiesVisitor(arrangement.template)
is Continuation -> ImmutableSet.of<Party>()
is Continuation -> ImmutableSet.of<Party.Full>()
is And ->
arrangement.arrangements.fold(ImmutableSet.builder<Party>(), { builder, k -> builder.addAll(involvedPartiesVisitor(k)) }).build()
arrangement.arrangements.fold(ImmutableSet.builder<Party.Full>(), { builder, k -> builder.addAll(involvedPartiesVisitor(k)) }).build()
is Actions ->
arrangement.actions.fold(ImmutableSet.builder<Party>(), { builder, k -> builder.addAll(involvedPartiesVisitor(k)) }).build()
arrangement.actions.fold(ImmutableSet.builder<Party.Full>(), { builder, k -> builder.addAll(involvedPartiesVisitor(k)) }).build()
else -> throw IllegalArgumentException(arrangement.toString())
}
/** returns list of involved parties for a given contract */
fun involvedParties(arrangement: Arrangement): Set<Party> = involvedPartiesVisitor(arrangement)
fun involvedParties(arrangement: Arrangement): Set<Party.Full> = involvedPartiesVisitor(arrangement)
fun replaceParty(perceivable: Perceivable<Boolean>, from: Party, to: Party): Perceivable<Boolean> =
fun replaceParty(perceivable: Perceivable<Boolean>, from: Party.Full, to: Party.Full): Perceivable<Boolean> =
when (perceivable) {
is ActorPerceivable ->
if (perceivable.actor == from)
@ -79,14 +79,14 @@ fun replaceParty(perceivable: Perceivable<Boolean>, from: Party, to: Party): Per
else -> throw IllegalArgumentException("replaceParty " + perceivable)
}
fun replaceParty(action: Action, from: Party, to: Party): Action =
fun replaceParty(action: Action, from: Party.Full, to: Party.Full): Action =
Action(action.name, replaceParty(action.condition, from, to), replaceParty(action.arrangement, from, to))
//if (action.actors.contains(from)) {
// Action(action.name, action.condition, action.actors - from + to, replaceParty(action.arrangement, from, to))
//} else
// Action(action.name, action.condition, replaceParty(action.arrangement, from, to))
fun replaceParty(arrangement: Arrangement, from: Party, to: Party): Arrangement = when (arrangement) {
fun replaceParty(arrangement: Arrangement, from: Party.Full, to: Party.Full): Arrangement = when (arrangement) {
is Zero -> arrangement
is Obligation -> Obligation(arrangement.amount, arrangement.currency,
if (arrangement.from == from) to else arrangement.from,
@ -169,7 +169,7 @@ fun <T> debugCompare(perLeft: Perceivable<T>, perRight: Perceivable<T>) {
assert(false)
}
fun debugCompare(parLeft: Party, parRight: Party) {
fun debugCompare(parLeft: Party.Full, parRight: Party.Full) {
assert(parLeft == parRight)
}
@ -181,7 +181,7 @@ fun debugCompare(left: LocalDate, right: LocalDate) {
assert(left == right)
}
fun debugCompare(parLeft: Set<Party>, parRight: Set<Party>) {
fun debugCompare(parLeft: Set<Party.Full>, parRight: Set<Party.Full>) {
if (parLeft == parRight) return
assert(parLeft == parRight)

View File

@ -7,9 +7,9 @@ import org.junit.Test
import java.util.*
// Test parties
val acmeCorp = Party("ACME Corporation", generateKeyPair().public)
val highStreetBank = Party("High Street Bank", generateKeyPair().public)
val momAndPop = Party("Mom and Pop", generateKeyPair().public)
val acmeCorp = Party.Full("ACME Corporation", generateKeyPair().public)
val highStreetBank = Party.Full("High Street Bank", generateKeyPair().public)
val momAndPop = Party.Full("Mom and Pop", generateKeyPair().public)
val acmeCorporationHasDefaulted = TerminalEvent(acmeCorp, generateKeyPair().public.composite)