From 3a7bcee15b8e06e63a7bd21e5176cc5a706796a4 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Tue, 11 Apr 2017 12:39:27 +0200 Subject: [PATCH] Minor: auto-format of module: finance --- .../corda/core/node/DummyContractBackdoor.kt | 2 +- .../corda/contracts/JavaCommercialPaper.java | 47 +++++++----------- .../net/corda/contracts/CommercialPaper.kt | 6 +-- .../corda/contracts/CommercialPaperLegacy.kt | 2 +- .../net/corda/contracts/asset/Obligation.kt | 48 +++++++++---------- .../clause/AbstractConserveAmount.kt | 2 +- .../kotlin/net/corda/contracts/clause/Net.kt | 8 ++-- .../contracts/testing/DummyLinearContract.kt | 2 +- .../main/kotlin/net/corda/flows/IssuerFlow.kt | 5 +- .../net/corda/flows/TwoPartyTradeFlow.kt | 2 + .../kotlin/net/corda/schemas/CashSchemaV1.kt | 4 +- .../corda/schemas/CommercialPaperSchemaV1.kt | 2 - .../AbstractStateReplacementFlowTest.java | 10 ++-- .../net/corda/flows/CashPaymentFlowTests.kt | 1 - 14 files changed, 67 insertions(+), 74 deletions(-) diff --git a/finance/isolated/src/main/kotlin/net/corda/core/node/DummyContractBackdoor.kt b/finance/isolated/src/main/kotlin/net/corda/core/node/DummyContractBackdoor.kt index f5a33c5d32..9848e168c3 100644 --- a/finance/isolated/src/main/kotlin/net/corda/core/node/DummyContractBackdoor.kt +++ b/finance/isolated/src/main/kotlin/net/corda/core/node/DummyContractBackdoor.kt @@ -2,8 +2,8 @@ package net.corda.core.node import net.corda.core.contracts.ContractState import net.corda.core.contracts.PartyAndReference -import net.corda.core.transactions.TransactionBuilder import net.corda.core.crypto.Party +import net.corda.core.transactions.TransactionBuilder interface DummyContractBackdoor { fun generateInitial(owner: PartyAndReference, magicNumber: Int, notary: Party): TransactionBuilder diff --git a/finance/src/main/java/net/corda/contracts/JavaCommercialPaper.java b/finance/src/main/java/net/corda/contracts/JavaCommercialPaper.java index 98b7a01139..43fdaa7c2f 100644 --- a/finance/src/main/java/net/corda/contracts/JavaCommercialPaper.java +++ b/finance/src/main/java/net/corda/contracts/JavaCommercialPaper.java @@ -1,34 +1,23 @@ package net.corda.contracts; -import com.google.common.collect.ImmutableList; -import kotlin.Pair; -import kotlin.Unit; -import net.corda.contracts.asset.CashKt; +import com.google.common.collect.*; +import kotlin.*; +import net.corda.contracts.asset.*; import net.corda.core.contracts.*; -import net.corda.core.contracts.TransactionForContract.InOutGroup; -import net.corda.core.contracts.clauses.AnyOf; -import net.corda.core.contracts.clauses.Clause; -import net.corda.core.contracts.clauses.ClauseVerifier; -import net.corda.core.contracts.clauses.GroupClauseVerifier; -import net.corda.core.crypto.CompositeKey; -import net.corda.core.crypto.CryptoUtilities; -import net.corda.core.crypto.Party; -import net.corda.core.crypto.SecureHash; -import net.corda.core.node.services.VaultService; -import net.corda.core.transactions.TransactionBuilder; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import net.corda.core.contracts.Contract; +import net.corda.core.contracts.TransactionForContract.*; +import net.corda.core.contracts.clauses.*; +import net.corda.core.crypto.*; +import net.corda.core.node.services.*; +import net.corda.core.transactions.*; +import org.jetbrains.annotations.*; -import java.time.Instant; -import java.util.Collections; -import java.util.Currency; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; +import java.time.*; +import java.util.*; +import java.util.stream.*; -import static kotlin.collections.CollectionsKt.single; -import static net.corda.core.contracts.ContractsDSL.requireSingleCommand; -import static net.corda.core.contracts.ContractsDSL.requireThat; +import static kotlin.collections.CollectionsKt.*; +import static net.corda.core.contracts.ContractsDSL.*; /** @@ -144,9 +133,9 @@ public class JavaCommercialPaper implements Contract { @SuppressWarnings("unchecked") Group() { super(new AnyOf<>( - new Clauses.Redeem(), - new Clauses.Move(), - new Clauses.Issue() + new Clauses.Redeem(), + new Clauses.Move(), + new Clauses.Issue() )); } diff --git a/finance/src/main/kotlin/net/corda/contracts/CommercialPaper.kt b/finance/src/main/kotlin/net/corda/contracts/CommercialPaper.kt index 2da1f2d22d..6b08dff730 100644 --- a/finance/src/main/kotlin/net/corda/contracts/CommercialPaper.kt +++ b/finance/src/main/kotlin/net/corda/contracts/CommercialPaper.kt @@ -104,9 +104,9 @@ class CommercialPaper : Contract { interface Clauses { class Group : GroupClauseVerifier>( AnyOf( - Redeem(), - Move(), - Issue())) { + Redeem(), + Move(), + Issue())) { override fun groupStates(tx: TransactionForContract): List>> = tx.groupStates> { it.token } } diff --git a/finance/src/main/kotlin/net/corda/contracts/CommercialPaperLegacy.kt b/finance/src/main/kotlin/net/corda/contracts/CommercialPaperLegacy.kt index d121e1ae18..c437548df4 100644 --- a/finance/src/main/kotlin/net/corda/contracts/CommercialPaperLegacy.kt +++ b/finance/src/main/kotlin/net/corda/contracts/CommercialPaperLegacy.kt @@ -106,7 +106,7 @@ class CommercialPaperLegacy : Contract { } } - // TODO: Think about how to evolve contracts over time with new commands. + // TODO: Think about how to evolve contracts over time with new commands. else -> throw IllegalArgumentException("Unrecognised command") } } diff --git a/finance/src/main/kotlin/net/corda/contracts/asset/Obligation.kt b/finance/src/main/kotlin/net/corda/contracts/asset/Obligation.kt index 73db195824..9bf01f945d 100644 --- a/finance/src/main/kotlin/net/corda/contracts/asset/Obligation.kt +++ b/finance/src/main/kotlin/net/corda/contracts/asset/Obligation.kt @@ -29,7 +29,7 @@ val OBLIGATION_PROGRAM_ID = Obligation() * * @param P the product the obligation is for payment of. */ -class Obligation : Contract { +class Obligation

: Contract { /** * TODO: @@ -47,7 +47,7 @@ class Obligation : Contract { /** * Parent clause for clauses that operate on grouped states (those which are fungible). */ - class Group : GroupClauseVerifier, Commands, Issued>>( + class Group

: GroupClauseVerifier, Commands, Issued>>( AllOf( NoZeroSizedOutputs, Commands, Terms

>(), FirstOf( @@ -70,19 +70,19 @@ class Obligation : Contract { /** * Generic issuance clause */ - class Issue : AbstractIssue, Commands, Terms

>({ -> sumObligations() }, { token: Issued> -> sumObligationsOrZero(token) }) { + class Issue

: AbstractIssue, Commands, Terms

>({ -> sumObligations() }, { token: Issued> -> sumObligationsOrZero(token) }) { override val requiredCommands: Set> = setOf(Commands.Issue::class.java) } /** * Generic move/exit clause for fungible assets */ - class ConserveAmount : AbstractConserveAmount, Commands, Terms

>() + class ConserveAmount

: AbstractConserveAmount, Commands, Terms

>() /** * Clause for supporting netting of obligations. */ - class Net : NetClause() { + class Net : NetClause() { val lifecycleClause = Clauses.VerifyLifecycle() override fun toString(): String = "Net obligations" @@ -95,7 +95,7 @@ class Obligation : Contract { /** * Obligation-specific clause for changing the lifecycle of one or more states. */ - class SetLifecycle : Clause, Commands, Issued>>() { + class SetLifecycle

: Clause, Commands, Issued>>() { override val requiredCommands: Set> = setOf(Commands.SetLifecycle::class.java) override fun verify(tx: TransactionForContract, @@ -115,7 +115,7 @@ class Obligation : Contract { * Obligation-specific clause for settling an outstanding obligation by witnessing * change of ownership of other states to fulfil */ - class Settle : Clause, Commands, Issued>>() { + class Settle

: Clause, Commands, Issued>>() { override val requiredCommands: Set> = setOf(Commands.Settle::class.java) override fun verify(tx: TransactionForContract, inputs: List>, @@ -204,7 +204,7 @@ class Obligation : Contract { * any lifecycle change clause, which is the only clause that involve * non-standard lifecycle states on input/output. */ - class VerifyLifecycle : Clause() { + class VerifyLifecycle : Clause() { override fun verify(tx: TransactionForContract, inputs: List, outputs: List, @@ -245,7 +245,7 @@ class Obligation : Contract { * @param P the product the obligation is for payment of. */ @CordaSerializable - data class Terms( + data class Terms

( /** The hash of the asset contract we're willing to accept in payment for this debt. */ val acceptableContracts: NonEmptySet, /** The parties whose assets we are willing to accept in payment for this debt. */ @@ -266,7 +266,7 @@ class Obligation : Contract { * * @param P the product the obligation is for payment of. */ - data class State( + data class State

( var lifecycle: Lifecycle = Lifecycle.NORMAL, /** Where the debt originates from (obligor) */ val obligor: AnonymousParty, @@ -354,7 +354,7 @@ class Obligation : Contract { * state object to the beneficiary. If this reduces the balance to zero, the state object is destroyed. * @see [MoveCommand]. */ - data class Settle(val amount: Amount>>) : Commands + data class Settle

(val amount: Amount>>) : Commands /** * A command stating that the beneficiary is moving the contract into the defaulted state as it has not been settled @@ -372,7 +372,7 @@ class Obligation : Contract { * A command stating that the debt is being released by the beneficiary. Normally would indicate * either settlement outside of the ledger, or that the obligor is unable to pay. */ - data class Exit(override val amount: Amount>>) : Commands, FungibleAsset.Commands.Exit> + data class Exit

(override val amount: Amount>>) : Commands, FungibleAsset.Commands.Exit> } override fun verify(tx: TransactionForContract) = verifyClause(tx, FirstOf( @@ -629,7 +629,7 @@ class Obligation : Contract { * * @return a map of obligor/beneficiary pairs to the balance due. */ -fun extractAmountsDue(product: Obligation.Terms

, states: Iterable>): Map, Amount>> { +fun

extractAmountsDue(product: Obligation.Terms

, states: Iterable>): Map, Amount>> { val balances = HashMap, Amount>>() states.forEach { state -> @@ -644,7 +644,7 @@ fun extractAmountsDue(product: Obligation.Terms

, states: Iterable netAmountsDue(balances: Map, Amount

>): Map, Amount

> { +fun

netAmountsDue(balances: Map, Amount

>): Map, Amount

> { val nettedBalances = HashMap, Amount

>() balances.forEach { balance -> @@ -669,7 +669,7 @@ fun netAmountsDue(balances: Map, Amoun * @param balances payments due, indexed by obligor and beneficiary. Zero balances are stripped from the map before being * returned. */ -fun sumAmountsDue(balances: Map, Amount

>): Map { +fun

sumAmountsDue(balances: Map, Amount

>): Map { val sum = HashMap() // Fill the map with zeroes initially @@ -699,25 +699,25 @@ fun sumAmountsDue(balances: Map, Amoun } /** Sums the obligation states in the list, throwing an exception if there are none. All state objects in the list are presumed to be nettable. */ -fun Iterable.sumObligations(): Amount>> +fun

Iterable.sumObligations(): Amount>> = filterIsInstance>().map { it.amount }.sumOrThrow() /** Sums the obligation states in the list, returning null if there are none. */ -fun Iterable.sumObligationsOrNull(): Amount>>? +fun

Iterable.sumObligationsOrNull(): Amount>>? = filterIsInstance>().filter { it.lifecycle == Obligation.Lifecycle.NORMAL }.map { it.amount }.sumOrNull() /** Sums the obligation states in the list, returning zero of the given product if there are none. */ -fun Iterable.sumObligationsOrZero(issuanceDef: Issued>): Amount>> +fun

Iterable.sumObligationsOrZero(issuanceDef: Issued>): Amount>> = filterIsInstance>().filter { it.lifecycle == Obligation.Lifecycle.NORMAL }.map { it.amount }.sumOrZero(issuanceDef) -infix fun Obligation.State.at(dueBefore: Instant) = copy(template = template.copy(dueBefore = dueBefore)) -infix fun Obligation.State.between(parties: Pair) = copy(obligor = parties.first.toAnonymous(), beneficiary = parties.second) -infix fun Obligation.State.`owned by`(owner: CompositeKey) = copy(beneficiary = owner) -infix fun Obligation.State.`issued by`(party: AbstractParty) = copy(obligor = party.toAnonymous()) +infix fun Obligation.State.at(dueBefore: Instant) = copy(template = template.copy(dueBefore = dueBefore)) +infix fun Obligation.State.between(parties: Pair) = copy(obligor = parties.first.toAnonymous(), beneficiary = parties.second) +infix fun Obligation.State.`owned by`(owner: CompositeKey) = copy(beneficiary = owner) +infix fun Obligation.State.`issued by`(party: AbstractParty) = copy(obligor = party.toAnonymous()) // For Java users: -@Suppress("unused") fun Obligation.State.ownedBy(owner: CompositeKey) = copy(beneficiary = owner) +@Suppress("unused") fun Obligation.State.ownedBy(owner: CompositeKey) = copy(beneficiary = owner) -@Suppress("unused") fun Obligation.State.issuedBy(party: AnonymousParty) = copy(obligor = party) +@Suppress("unused") fun Obligation.State.issuedBy(party: AnonymousParty) = copy(obligor = party) /** A randomly generated key. */ val DUMMY_OBLIGATION_ISSUER_KEY by lazy { entropyToKeyPair(BigInteger.valueOf(10)) } diff --git a/finance/src/main/kotlin/net/corda/contracts/clause/AbstractConserveAmount.kt b/finance/src/main/kotlin/net/corda/contracts/clause/AbstractConserveAmount.kt index 6ff4d283f3..55818d9521 100644 --- a/finance/src/main/kotlin/net/corda/contracts/clause/AbstractConserveAmount.kt +++ b/finance/src/main/kotlin/net/corda/contracts/clause/AbstractConserveAmount.kt @@ -16,7 +16,7 @@ import java.util.* abstract class AbstractConserveAmount, C : CommandData, T : Any> : Clause>() { private companion object { - val log = loggerFor>() + val log = loggerFor>() } /** diff --git a/finance/src/main/kotlin/net/corda/contracts/clause/Net.kt b/finance/src/main/kotlin/net/corda/contracts/clause/Net.kt index 482c5cdfa6..3d5ebdc689 100644 --- a/finance/src/main/kotlin/net/corda/contracts/clause/Net.kt +++ b/finance/src/main/kotlin/net/corda/contracts/clause/Net.kt @@ -12,7 +12,7 @@ import net.corda.core.crypto.CompositeKey * Common interface for the state subsets used when determining nettability of two or more states. Exposes the * underlying issued thing. */ -interface NetState { +interface NetState

{ val template: Obligation.Terms

} @@ -21,7 +21,7 @@ interface NetState { * If two obligation state objects produce equal bilateral net states, they are considered safe to net directly. * Bilateral states are used in close-out netting. */ -data class BilateralNetState( +data class BilateralNetState

( val partyKeys: Set, override val template: Obligation.Terms

) : NetState

@@ -34,7 +34,7 @@ data class BilateralNetState( * input and output is handled elsewhere. * Used in cases where all parties (or their proxies) are signing, such as central clearing. */ -data class MultilateralNetState( +data class MultilateralNetState

( override val template: Obligation.Terms

) : NetState

@@ -42,7 +42,7 @@ data class MultilateralNetState( * Clause for netting contract states. Currently only supports obligation contract. */ // TODO: Make this usable for any nettable contract states -open class NetClause : Clause() { +open class NetClause : Clause() { override val requiredCommands: Set> = setOf(Obligation.Commands.Net::class.java) @Suppress("ConvertLambdaToReference") diff --git a/finance/src/main/kotlin/net/corda/contracts/testing/DummyLinearContract.kt b/finance/src/main/kotlin/net/corda/contracts/testing/DummyLinearContract.kt index 5aa1c6f80d..4c56463ecc 100644 --- a/finance/src/main/kotlin/net/corda/contracts/testing/DummyLinearContract.kt +++ b/finance/src/main/kotlin/net/corda/contracts/testing/DummyLinearContract.kt @@ -8,7 +8,7 @@ import net.corda.core.crypto.CompositeKey import net.corda.core.crypto.SecureHash import java.security.PublicKey -class DummyLinearContract: Contract { +class DummyLinearContract : Contract { override val legalContractReference: SecureHash = SecureHash.sha256("Test") val clause: Clause = LinearState.ClauseVerifier() diff --git a/finance/src/main/kotlin/net/corda/flows/IssuerFlow.kt b/finance/src/main/kotlin/net/corda/flows/IssuerFlow.kt index cbb22fa9dd..8dcbd20226 100644 --- a/finance/src/main/kotlin/net/corda/flows/IssuerFlow.kt +++ b/finance/src/main/kotlin/net/corda/flows/IssuerFlow.kt @@ -29,7 +29,7 @@ object IssuerFlow { * Returns the transaction created by the Issuer to move the cash to the Requester. */ class IssuanceRequester(val amount: Amount, val issueToParty: Party, val issueToPartyRef: OpaqueBytes, - val issuerBankParty: Party): FlowLogic() { + val issuerBankParty: Party) : FlowLogic() { @Suspendable @Throws(CashException::class) override fun call(): SignedTransaction { @@ -42,12 +42,13 @@ object IssuerFlow { * Issuer refers to a Node acting as a Bank Issuer of [FungibleAsset], and processes requests from a [IssuanceRequester] client. * Returns the generated transaction representing the transfer of the [Issued] [FungibleAsset] to the issue requester. */ - class Issuer(val otherParty: Party): FlowLogic() { + class Issuer(val otherParty: Party) : FlowLogic() { companion object { object AWAITING_REQUEST : ProgressTracker.Step("Awaiting issuance request") object ISSUING : ProgressTracker.Step("Self issuing asset") object TRANSFERRING : ProgressTracker.Step("Transferring asset to issuance requester") object SENDING_CONFIRM : ProgressTracker.Step("Confirming asset issuance to requester") + fun tracker() = ProgressTracker(AWAITING_REQUEST, ISSUING, TRANSFERRING, SENDING_CONFIRM) private val VALID_CURRENCIES = listOf(USD, GBP, EUR, CHF) } diff --git a/finance/src/main/kotlin/net/corda/flows/TwoPartyTradeFlow.kt b/finance/src/main/kotlin/net/corda/flows/TwoPartyTradeFlow.kt index 5d3117e3c7..551820a7bb 100644 --- a/finance/src/main/kotlin/net/corda/flows/TwoPartyTradeFlow.kt +++ b/finance/src/main/kotlin/net/corda/flows/TwoPartyTradeFlow.kt @@ -72,6 +72,7 @@ object TwoPartyTradeFlow { object COMMITTING : ProgressTracker.Step("Committing transaction to the ledger") { override fun childProgressTracker() = FinalityFlow.tracker() } + // DOCEND 3 object SENDING_FINAL_TX : ProgressTracker.Step("Sending final transaction to buyer") @@ -143,6 +144,7 @@ object TwoPartyTradeFlow { val typeToBuy: Class) : FlowLogic() { // DOCSTART 2 object RECEIVING : ProgressTracker.Step("Waiting for seller trading info") + object VERIFYING : ProgressTracker.Step("Verifying seller assets") object SIGNING : ProgressTracker.Step("Generating and signing transaction proposal") object SENDING_SIGNATURES : ProgressTracker.Step("Sending signatures to the seller") diff --git a/finance/src/main/kotlin/net/corda/schemas/CashSchemaV1.kt b/finance/src/main/kotlin/net/corda/schemas/CashSchemaV1.kt index 692257c2ac..8972dd9254 100644 --- a/finance/src/main/kotlin/net/corda/schemas/CashSchemaV1.kt +++ b/finance/src/main/kotlin/net/corda/schemas/CashSchemaV1.kt @@ -2,7 +2,9 @@ package net.corda.schemas import net.corda.core.schemas.MappedSchema import net.corda.core.schemas.PersistentState -import javax.persistence.* +import javax.persistence.Column +import javax.persistence.Entity +import javax.persistence.Table /** * An object used to fully qualify the [CashSchema] family name (i.e. independent of version). diff --git a/finance/src/main/kotlin/net/corda/schemas/CommercialPaperSchemaV1.kt b/finance/src/main/kotlin/net/corda/schemas/CommercialPaperSchemaV1.kt index 540004d127..4181855b70 100644 --- a/finance/src/main/kotlin/net/corda/schemas/CommercialPaperSchemaV1.kt +++ b/finance/src/main/kotlin/net/corda/schemas/CommercialPaperSchemaV1.kt @@ -1,9 +1,7 @@ package net.corda.schemas -import io.requery.Convert import net.corda.core.schemas.MappedSchema import net.corda.core.schemas.PersistentState -import net.corda.core.schemas.requery.converters.InstantConverter import java.time.Instant import javax.persistence.Column import javax.persistence.Entity diff --git a/finance/src/test/java/net/corda/flows/AbstractStateReplacementFlowTest.java b/finance/src/test/java/net/corda/flows/AbstractStateReplacementFlowTest.java index 163388cf3b..6b91b3b8eb 100644 --- a/finance/src/test/java/net/corda/flows/AbstractStateReplacementFlowTest.java +++ b/finance/src/test/java/net/corda/flows/AbstractStateReplacementFlowTest.java @@ -1,8 +1,8 @@ package net.corda.flows; -import net.corda.core.crypto.Party; -import net.corda.core.utilities.ProgressTracker; -import org.jetbrains.annotations.NotNull; +import net.corda.core.crypto.*; +import net.corda.core.utilities.*; +import org.jetbrains.annotations.*; @SuppressWarnings("unused") public class AbstractStateReplacementFlowTest { @@ -12,7 +12,9 @@ public class AbstractStateReplacementFlowTest { public TestAcceptorCanBeInheritedInJava(@NotNull Party otherSide, @NotNull ProgressTracker progressTracker) { super(otherSide, progressTracker); } + @Override - protected void verifyProposal(@NotNull AbstractStateReplacementFlow.Proposal proposal) {} + protected void verifyProposal(@NotNull AbstractStateReplacementFlow.Proposal proposal) { + } } } \ No newline at end of file diff --git a/finance/src/test/kotlin/net/corda/flows/CashPaymentFlowTests.kt b/finance/src/test/kotlin/net/corda/flows/CashPaymentFlowTests.kt index de4b15415c..28c7774352 100644 --- a/finance/src/test/kotlin/net/corda/flows/CashPaymentFlowTests.kt +++ b/finance/src/test/kotlin/net/corda/flows/CashPaymentFlowTests.kt @@ -12,7 +12,6 @@ import net.corda.testing.node.MockNetwork.MockNode import org.junit.After import org.junit.Before import org.junit.Test -import java.util.concurrent.ExecutionException import kotlin.test.assertEquals import kotlin.test.assertFailsWith