Reformat files in finance

This commit is contained in:
Tommy Lillehagen 2017-10-06 15:20:22 +01:00
parent b1fb321230
commit 7a372bed59
30 changed files with 128 additions and 100 deletions

View File

@ -8,12 +8,18 @@ import net.corda.core.contracts.PartyAndReference
import java.math.BigDecimal import java.math.BigDecimal
import java.util.* import java.util.*
@JvmField val USD: Currency = Currency.getInstance("USD") @JvmField
@JvmField val GBP: Currency = Currency.getInstance("GBP") val USD: Currency = Currency.getInstance("USD")
@JvmField val EUR: Currency = Currency.getInstance("EUR") @JvmField
@JvmField val CHF: Currency = Currency.getInstance("CHF") val GBP: Currency = Currency.getInstance("GBP")
@JvmField val JPY: Currency = Currency.getInstance("JPY") @JvmField
@JvmField val RUB: Currency = Currency.getInstance("RUB") val EUR: Currency = Currency.getInstance("EUR")
@JvmField
val CHF: Currency = Currency.getInstance("CHF")
@JvmField
val JPY: Currency = Currency.getInstance("JPY")
@JvmField
val RUB: Currency = Currency.getInstance("RUB")
fun <T : Any> AMOUNT(amount: Int, token: T): Amount<T> = AMOUNT(amount.toLong(), token) fun <T : Any> AMOUNT(amount: Int, token: T): Amount<T> = AMOUNT(amount.toLong(), token)
fun <T : Any> AMOUNT(amount: Long, token: T): Amount<T> = Amount.fromDecimal(BigDecimal.valueOf(amount), token) fun <T : Any> AMOUNT(amount: Long, token: T): Amount<T> = Amount.fromDecimal(BigDecimal.valueOf(amount), token)

View File

@ -49,6 +49,7 @@ class CommercialPaper : Contract {
companion object { companion object {
const val CP_PROGRAM_ID: ContractClassName = "net.corda.finance.contracts.CommercialPaper" const val CP_PROGRAM_ID: ContractClassName = "net.corda.finance.contracts.CommercialPaper"
} }
data class State( data class State(
val issuance: PartyAndReference, val issuance: PartyAndReference,
override val owner: AbstractParty, override val owner: AbstractParty,
@ -89,7 +90,8 @@ class CommercialPaper : Contract {
} }
} }
/** @suppress */ infix fun `owned by`(owner: AbstractParty) = copy(owner = owner) /** @suppress */
infix fun `owned by`(owner: AbstractParty) = copy(owner = owner)
} }
interface Commands : CommandData { interface Commands : CommandData {

View File

@ -202,7 +202,7 @@ enum class Frequency(val annualCompoundCount: Int, val offset: LocalDate.(Long)
* no staff are around to handle problems. * no staff are around to handle problems.
*/ */
@CordaSerializable @CordaSerializable
open class BusinessCalendar (val holidayDates: List<LocalDate>) { open class BusinessCalendar(val holidayDates: List<LocalDate>) {
@CordaSerializable @CordaSerializable
class UnknownCalendar(name: String) : FlowException("$name not found") class UnknownCalendar(name: String) : FlowException("$name not found")

View File

@ -401,10 +401,17 @@ class Cash : OnLedgerAsset<Currency, Cash.Commands, Cash.State>() {
// Small DSL extensions. // Small DSL extensions.
/** @suppress */ infix fun Cash.State.`owned by`(owner: AbstractParty) = ownedBy(owner) /** @suppress */
/** @suppress */ infix fun Cash.State.`issued by`(party: AbstractParty) = issuedBy(party) infix fun Cash.State.`owned by`(owner: AbstractParty) = ownedBy(owner)
/** @suppress */ infix fun Cash.State.`issued by`(deposit: PartyAndReference) = issuedBy(deposit)
/** @suppress */ infix fun Cash.State.`with deposit`(deposit: PartyAndReference): Cash.State = withDeposit(deposit) /** @suppress */
infix fun Cash.State.`issued by`(party: AbstractParty) = issuedBy(party)
/** @suppress */
infix fun Cash.State.`issued by`(deposit: PartyAndReference) = issuedBy(deposit)
/** @suppress */
infix fun Cash.State.`with deposit`(deposit: PartyAndReference): Cash.State = withDeposit(deposit)
// Unit testing helpers. These could go in a separate file but it's hardly worth it for just a few functions. // Unit testing helpers. These could go in a separate file but it's hardly worth it for just a few functions.

View File

@ -44,6 +44,7 @@ class CommodityContract : OnLedgerAsset<Commodity, CommodityContract.Commands, C
) : FungibleAsset<Commodity> { ) : FungibleAsset<Commodity> {
constructor(deposit: PartyAndReference, amount: Amount<Commodity>, owner: AbstractParty) constructor(deposit: PartyAndReference, amount: Amount<Commodity>, owner: AbstractParty)
: this(Amount(amount.quantity, Issued(deposit, amount.token)), owner) : this(Amount(amount.quantity, Issued(deposit, amount.token)), owner)
override val exitKeys: Set<PublicKey> = Collections.singleton(owner.owningKey) override val exitKeys: Set<PublicKey> = Collections.singleton(owner.owningKey)
override val participants = listOf(owner) override val participants = listOf(owner)
@ -91,7 +92,7 @@ class CommodityContract : OnLedgerAsset<Commodity, CommodityContract.Commands, C
val party = issuer.party val party = issuer.party
requireThat { requireThat {
"there are no zero sized outputs" using ( outputs.none { it.amount.quantity == 0L } ) "there are no zero sized outputs" using (outputs.none { it.amount.quantity == 0L })
} }
val issueCommand = tx.commands.select<Commands.Issue>().firstOrNull() val issueCommand = tx.commands.select<Commands.Issue>().firstOrNull()
@ -107,7 +108,7 @@ class CommodityContract : OnLedgerAsset<Commodity, CommodityContract.Commands, C
val amountExitingLedger = exitCommand?.value?.amount ?: Amount(0, Issued(issuer, commodity)) val amountExitingLedger = exitCommand?.value?.amount ?: Amount(0, Issued(issuer, commodity))
requireThat { requireThat {
"there are no zero sized inputs" using ( inputs.none { it.amount.quantity == 0L } ) "there are no zero sized inputs" using (inputs.none { it.amount.quantity == 0L })
"for reference ${issuer.reference} at issuer ${party.nameOrNull()} the amounts balance" using "for reference ${issuer.reference} at issuer ${party.nameOrNull()} the amounts balance" using
(inputAmount == outputAmount + amountExitingLedger) (inputAmount == outputAmount + amountExitingLedger)
} }

View File

@ -73,6 +73,7 @@ class Obligation<P : Any> : Contract {
companion object { companion object {
const val PROGRAM_ID: ContractClassName = "net.corda.finance.contracts.asset.Obligation" const val PROGRAM_ID: ContractClassName = "net.corda.finance.contracts.asset.Obligation"
} }
/** /**
* Represents where in its lifecycle a contract state is, which in turn controls the commands that can be applied * Represents where in its lifecycle a contract state is, which in turn controls the commands that can be applied
* to the state. Most states will not leave the [NORMAL] lifecycle. Note that settled (as an end lifecycle) is * to the state. Most states will not leave the [NORMAL] lifecycle. Note that settled (as an end lifecycle) is
@ -785,9 +786,11 @@ infix fun <T : Any> Obligation.State<T>.between(parties: Pair<AbstractParty, Abs
infix fun <T : Any> Obligation.State<T>.`owned by`(owner: AbstractParty) = copy(beneficiary = owner) infix fun <T : Any> Obligation.State<T>.`owned by`(owner: AbstractParty) = copy(beneficiary = owner)
infix fun <T : Any> Obligation.State<T>.`issued by`(party: AbstractParty) = copy(obligor = party) infix fun <T : Any> Obligation.State<T>.`issued by`(party: AbstractParty) = copy(obligor = party)
// For Java users: // For Java users:
@Suppress("unused") fun <T : Any> Obligation.State<T>.ownedBy(owner: AbstractParty) = copy(beneficiary = owner) @Suppress("unused")
fun <T : Any> Obligation.State<T>.ownedBy(owner: AbstractParty) = copy(beneficiary = owner)
@Suppress("unused") fun <T : Any> Obligation.State<T>.issuedBy(party: AnonymousParty) = copy(obligor = party) @Suppress("unused")
fun <T : Any> Obligation.State<T>.issuedBy(party: AnonymousParty) = copy(obligor = party)
/** A randomly generated key. */ /** A randomly generated key. */
val DUMMY_OBLIGATION_ISSUER_KEY by lazy { entropyToKeyPair(BigInteger.valueOf(10)) } val DUMMY_OBLIGATION_ISSUER_KEY by lazy { entropyToKeyPair(BigInteger.valueOf(10)) }

View File

@ -55,7 +55,7 @@ abstract class OnLedgerAsset<T : Any, C : CommandData, S : FungibleAsset<T>> : C
*/ */
@Throws(InsufficientBalanceException::class) @Throws(InsufficientBalanceException::class)
@JvmStatic @JvmStatic
fun <S : FungibleAsset<T>, T: Any> generateSpend(tx: TransactionBuilder, fun <S : FungibleAsset<T>, T : Any> generateSpend(tx: TransactionBuilder,
amount: Amount<T>, amount: Amount<T>,
to: AbstractParty, to: AbstractParty,
acceptableStates: List<StateAndRef<S>>, acceptableStates: List<StateAndRef<S>>,
@ -91,7 +91,7 @@ abstract class OnLedgerAsset<T : Any, C : CommandData, S : FungibleAsset<T>> : C
*/ */
@Throws(InsufficientBalanceException::class) @Throws(InsufficientBalanceException::class)
@JvmStatic @JvmStatic
fun <S : FungibleAsset<T>, T: Any> generateSpend(tx: TransactionBuilder, fun <S : FungibleAsset<T>, T : Any> generateSpend(tx: TransactionBuilder,
payments: List<PartyAndAmount<T>>, payments: List<PartyAndAmount<T>>,
acceptableStates: List<StateAndRef<S>>, acceptableStates: List<StateAndRef<S>>,
payChangeTo: AbstractParty, payChangeTo: AbstractParty,
@ -230,7 +230,7 @@ abstract class OnLedgerAsset<T : Any, C : CommandData, S : FungibleAsset<T>> : C
*/ */
@Throws(InsufficientBalanceException::class) @Throws(InsufficientBalanceException::class)
@JvmStatic @JvmStatic
fun <S : FungibleAsset<T>, T: Any> generateExit(tx: TransactionBuilder, amountIssued: Amount<Issued<T>>, fun <S : FungibleAsset<T>, T : Any> generateExit(tx: TransactionBuilder, amountIssued: Amount<Issued<T>>,
assetStates: List<StateAndRef<S>>, assetStates: List<StateAndRef<S>>,
deriveState: (TransactionState<S>, Amount<Issued<T>>, AbstractParty) -> TransactionState<S>, deriveState: (TransactionState<S>, Amount<Issued<T>>, AbstractParty) -> TransactionState<S>,
generateMoveCommand: () -> CommandData, generateMoveCommand: () -> CommandData,
@ -272,7 +272,7 @@ abstract class OnLedgerAsset<T : Any, C : CommandData, S : FungibleAsset<T>> : C
* wrappers around this function, which build the state for you, and those should be used in preference. * wrappers around this function, which build the state for you, and those should be used in preference.
*/ */
@JvmStatic @JvmStatic
fun <S : FungibleAsset<T>, T: Any> generateIssue(tx: TransactionBuilder, fun <S : FungibleAsset<T>, T : Any> generateIssue(tx: TransactionBuilder,
transactionState: TransactionState<S>, transactionState: TransactionState<S>,
issueCommand: CommandData): Set<PublicKey> { issueCommand: CommandData): Set<PublicKey> {
check(tx.inputStates().isEmpty()) check(tx.inputStates().isEmpty())

View File

@ -29,4 +29,4 @@ class CashSelectionMySQLImpl : CashSelection {
withIssuerRefs: Set<OpaqueBytes>): List<StateAndRef<Cash.State>> { withIssuerRefs: Set<OpaqueBytes>): List<StateAndRef<Cash.State>> {
TODO("MySQL cash selection not implemented") TODO("MySQL cash selection not implemented")
} }
} }

View File

@ -32,6 +32,7 @@ class CashIssueAndPaymentFlow(val amount: Amount<Currency>,
recipient: Party, recipient: Party,
anonymous: Boolean, anonymous: Boolean,
notary: Party) : this(amount, issueRef, recipient, anonymous, notary, tracker()) notary: Party) : this(amount, issueRef, recipient, anonymous, notary, tracker())
constructor(request: IssueAndPaymentRequest) : this(request.amount, request.issueRef, request.recipient, request.anonymous, request.notary, tracker()) constructor(request: IssueAndPaymentRequest) : this(request.amount, request.issueRef, request.recipient, request.anonymous, request.notary, tracker())
@Suspendable @Suspendable

View File

@ -31,6 +31,7 @@ class CashIssueFlow(private val amount: Amount<Currency>,
constructor(amount: Amount<Currency>, constructor(amount: Amount<Currency>,
issuerBankPartyRef: OpaqueBytes, issuerBankPartyRef: OpaqueBytes,
notary: Party) : this(amount, issuerBankPartyRef, notary, tracker()) notary: Party) : this(amount, issuerBankPartyRef, notary, tracker())
constructor(request: IssueRequest) : this(request.amount, request.issueRef, request.notary, tracker()) constructor(request: IssueRequest) : this(request.amount, request.issueRef, request.notary, tracker())
@Suspendable @Suspendable

View File

@ -31,8 +31,10 @@ open class CashPaymentFlow(
val issuerConstraint: Set<Party> = emptySet()) : AbstractCashFlow<AbstractCashFlow.Result>(progressTracker) { val issuerConstraint: Set<Party> = emptySet()) : AbstractCashFlow<AbstractCashFlow.Result>(progressTracker) {
/** A straightforward constructor that constructs spends using cash states of any issuer. */ /** A straightforward constructor that constructs spends using cash states of any issuer. */
constructor(amount: Amount<Currency>, recipient: Party) : this(amount, recipient, true, tracker()) constructor(amount: Amount<Currency>, recipient: Party) : this(amount, recipient, true, tracker())
/** A straightforward constructor that constructs spends using cash states of any issuer. */ /** A straightforward constructor that constructs spends using cash states of any issuer. */
constructor(amount: Amount<Currency>, recipient: Party, anonymous: Boolean) : this(amount, recipient, anonymous, tracker()) constructor(amount: Amount<Currency>, recipient: Party, anonymous: Boolean) : this(amount, recipient, anonymous, tracker())
constructor(request: PaymentRequest) : this(request.amount, request.recipient, request.anonymous, tracker(), request.issuerConstraint) constructor(request: PaymentRequest) : this(request.amount, request.recipient, request.anonymous, tracker(), request.issuerConstraint)
@Suspendable @Suspendable

View File

@ -43,6 +43,7 @@ object TwoPartyDealFlow {
companion object { companion object {
object GENERATING_ID : ProgressTracker.Step("Generating anonymous identities") object GENERATING_ID : ProgressTracker.Step("Generating anonymous identities")
object SENDING_PROPOSAL : ProgressTracker.Step("Handshaking and awaiting transaction proposal.") object SENDING_PROPOSAL : ProgressTracker.Step("Handshaking and awaiting transaction proposal.")
fun tracker() = ProgressTracker(GENERATING_ID, SENDING_PROPOSAL) fun tracker() = ProgressTracker(GENERATING_ID, SENDING_PROPOSAL)
} }
@ -148,6 +149,7 @@ object TwoPartyDealFlow {
@Suspendable @Suspendable
protected abstract fun validateHandshake(handshake: Handshake<U>): Handshake<U> protected abstract fun validateHandshake(handshake: Handshake<U>): Handshake<U>
@Suspendable @Suspendable
protected abstract fun assembleSharedTX(handshake: Handshake<U>): Triple<TransactionBuilder, List<PublicKey>, List<TransactionSignature>> protected abstract fun assembleSharedTX(handshake: Handshake<U>): Triple<TransactionBuilder, List<PublicKey>, List<TransactionSignature>>
} }

View File

@ -136,6 +136,7 @@ object TwoPartyTradeFlow {
private val anonymous: Boolean) : FlowLogic<SignedTransaction>() { private val anonymous: Boolean) : FlowLogic<SignedTransaction>() {
constructor(otherSideSession: FlowSession, notary: Party, acceptablePrice: Amount<Currency>, typeToBuy: Class<out OwnableState>) : constructor(otherSideSession: FlowSession, notary: Party, acceptablePrice: Amount<Currency>, typeToBuy: Class<out OwnableState>) :
this(otherSideSession, notary, acceptablePrice, typeToBuy, true) this(otherSideSession, notary, acceptablePrice, typeToBuy, true)
// DOCSTART 2 // DOCSTART 2
object RECEIVING : ProgressTracker.Step("Waiting for seller trading info") object RECEIVING : ProgressTracker.Step("Waiting for seller trading info")

View File

@ -1,4 +1,5 @@
@file:JvmName("StateSumming") @file:JvmName("StateSumming")
package net.corda.finance.utils package net.corda.finance.utils
import net.corda.core.contracts.Amount import net.corda.core.contracts.Amount

View File

@ -34,7 +34,7 @@ public class CashTestsJava {
}); });
tx.tweak(tw -> { tx.tweak(tw -> {
tw.output(Cash.PROGRAM_ID, () -> outState ); tw.output(Cash.PROGRAM_ID, () -> outState);
tw.command(getMEGA_CORP_PUBKEY(), DummyCommandData.INSTANCE); tw.command(getMEGA_CORP_PUBKEY(), DummyCommandData.INSTANCE);
// Invalid command // Invalid command
return tw.failsWith("required net.corda.finance.contracts.asset.Cash.Commands.Move command"); return tw.failsWith("required net.corda.finance.contracts.asset.Cash.Commands.Move command");

View File

@ -80,7 +80,8 @@ class KotlinCommercialPaperLegacyTest : ICommercialPaperTestTemplate {
@RunWith(Parameterized::class) @RunWith(Parameterized::class)
class CommercialPaperTestsGeneric { class CommercialPaperTestsGeneric {
companion object { companion object {
@Parameterized.Parameters @JvmStatic @Parameterized.Parameters
@JvmStatic
fun data() = listOf(JavaCommercialPaperTest(), KotlinCommercialPaperTest(), KotlinCommercialPaperLegacyTest()) fun data() = listOf(JavaCommercialPaperTest(), KotlinCommercialPaperTest(), KotlinCommercialPaperLegacyTest())
} }
@ -227,7 +228,7 @@ class CommercialPaperTestsGeneric {
private lateinit var moveTX: SignedTransaction private lateinit var moveTX: SignedTransaction
// @Test // @Test
@Ignore @Ignore
fun `issue move and then redeem`() { fun `issue move and then redeem`() {
setCordappPackages("net.corda.finance.contracts") setCordappPackages("net.corda.finance.contracts")

View File

@ -796,7 +796,7 @@ class CashTests : TestDependencyInjectionBase() {
transaction { transaction {
attachment(Cash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input("MEGA_CORP cash") input("MEGA_CORP cash")
output(Cash.PROGRAM_ID, "MEGA_CORP cash 2", "MEGA_CORP cash".output<Cash.State>().copy(owner = AnonymousParty(ALICE_PUBKEY)) ) output(Cash.PROGRAM_ID, "MEGA_CORP cash 2", "MEGA_CORP cash".output<Cash.State>().copy(owner = AnonymousParty(ALICE_PUBKEY)))
command(MEGA_CORP_PUBKEY) { Cash.Commands.Move() } command(MEGA_CORP_PUBKEY) { Cash.Commands.Move() }
this.verifies() this.verifies()
} }

View File

@ -286,7 +286,7 @@ class ObligationTests {
assertEquals(expected, actual) assertEquals(expected, actual)
} }
private inline fun <reified T: ContractState> getStateAndRef(state: T, contractClassName: ContractClassName): StateAndRef<T> { private inline fun <reified T : ContractState> getStateAndRef(state: T, contractClassName: ContractClassName): StateAndRef<T> {
val txState = TransactionState(state, contractClassName, DUMMY_NOTARY) val txState = TransactionState(state, contractClassName, DUMMY_NOTARY)
return StateAndRef(txState, StateRef(SecureHash.randomSHA256(), 0)) return StateAndRef(txState, StateRef(SecureHash.randomSHA256(), 0))

View File

@ -18,7 +18,7 @@ import kotlin.test.assertEquals
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
class CashExitFlowTests { class CashExitFlowTests {
private lateinit var mockNet : MockNetwork private lateinit var mockNet: MockNetwork
private val initialBalance = 2000.DOLLARS private val initialBalance = 2000.DOLLARS
private val ref = OpaqueBytes.of(0x01) private val ref = OpaqueBytes.of(0x01)
private lateinit var bankOfCordaNode: StartedNode<MockNode> private lateinit var bankOfCordaNode: StartedNode<MockNode>

View File

@ -22,7 +22,7 @@ import kotlin.test.assertEquals
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
class CashIssueFlowTests { class CashIssueFlowTests {
private lateinit var mockNet : MockNetwork private lateinit var mockNet: MockNetwork
private lateinit var bankOfCordaNode: StartedNode<MockNode> private lateinit var bankOfCordaNode: StartedNode<MockNode>
private lateinit var bankOfCorda: Party private lateinit var bankOfCorda: Party
private lateinit var notaryNode: StartedNode<MockNode> private lateinit var notaryNode: StartedNode<MockNode>

View File

@ -21,7 +21,7 @@ import kotlin.test.assertEquals
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
class CashPaymentFlowTests { class CashPaymentFlowTests {
private lateinit var mockNet : MockNetwork private lateinit var mockNet: MockNetwork
private val initialBalance = 2000.DOLLARS private val initialBalance = 2000.DOLLARS
private val ref = OpaqueBytes.of(0x01) private val ref = OpaqueBytes.of(0x01)
private lateinit var bankOfCordaNode: StartedNode<MockNode> private lateinit var bankOfCordaNode: StartedNode<MockNode>

View File

@ -17,7 +17,7 @@ object SampleCashSchemaV2 : MappedSchema(schemaFamily = CashSchema.javaClass, ve
@Entity @Entity
@Table(name = "cash_states_v2", @Table(name = "cash_states_v2",
indexes = arrayOf(Index(name = "ccy_code_idx2", columnList = "ccy_code"))) indexes = arrayOf(Index(name = "ccy_code_idx2", columnList = "ccy_code")))
class PersistentCashState ( class PersistentCashState(
/** product type */ /** product type */
@Column(name = "ccy_code", length = 3) @Column(name = "ccy_code", length = 3)
var currency: String, var currency: String,