From f6789c93ddfe4c6c81611631e88643599516102e Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Tue, 12 Jul 2016 16:01:50 +0200 Subject: [PATCH] Disentangle the concept of CP issuer vs underlying redeemable asset issuer in the CP contract. This confusion was introduced by a previous refactoring. --- .../kotlin/com/r3corda/contracts/CommercialPaper.kt | 3 +-- .../com/r3corda/contracts/CommercialPaperTests.kt | 13 +++++++------ .../node/internal/testing/TradeSimulation.kt | 4 +++- src/main/kotlin/com/r3corda/demos/TraderDemo.kt | 4 +++- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/contracts/src/main/kotlin/com/r3corda/contracts/CommercialPaper.kt b/contracts/src/main/kotlin/com/r3corda/contracts/CommercialPaper.kt index 140eee6d8c..6bd973973e 100644 --- a/contracts/src/main/kotlin/com/r3corda/contracts/CommercialPaper.kt +++ b/contracts/src/main/kotlin/com/r3corda/contracts/CommercialPaper.kt @@ -138,8 +138,7 @@ class CommercialPaper : Contract { * an existing transaction because you aren't able to issue multiple pieces of CP in a single transaction * at the moment: this restriction is not fundamental and may be lifted later. */ - fun generateIssue(faceValue: Amount>, maturityDate: Instant, notary: Party): TransactionBuilder { - val issuance = faceValue.token.issuer + fun generateIssue(issuance: PartyAndReference, faceValue: Amount>, maturityDate: Instant, notary: Party): TransactionBuilder { val state = TransactionState(State(issuance, issuance.party.owningKey, faceValue, maturityDate), notary) return TransactionType.General.Builder(notary = notary).withItems(state, Command(Commands.Issue(notary), issuance.party.owningKey)) } diff --git a/contracts/src/test/kotlin/com/r3corda/contracts/CommercialPaperTests.kt b/contracts/src/test/kotlin/com/r3corda/contracts/CommercialPaperTests.kt index cc3546d3d6..959127169d 100644 --- a/contracts/src/test/kotlin/com/r3corda/contracts/CommercialPaperTests.kt +++ b/contracts/src/test/kotlin/com/r3corda/contracts/CommercialPaperTests.kt @@ -179,7 +179,8 @@ class CommercialPaperTestsGeneric { fun `issue move and then redeem`() { // MiniCorp issues $10,000 of commercial paper, to mature in 30 days, owned initially by itself. val issueTX: LedgerTransaction = run { - val ptx = CommercialPaper().generateIssue(10000.DOLLARS `issued by` MINI_CORP.ref(123), TEST_TX_TIME + 30.days, DUMMY_NOTARY).apply { + val ptx = CommercialPaper().generateIssue(MINI_CORP.ref(123), 10000.DOLLARS `issued by` DUMMY_CASH_ISSUER, + TEST_TX_TIME + 30.days, DUMMY_NOTARY).apply { setTime(TEST_TX_TIME, DUMMY_NOTARY, 30.seconds) signWith(MINI_CORP_KEY) signWith(DUMMY_NOTARY_KEY) @@ -189,9 +190,9 @@ class CommercialPaperTestsGeneric { } val (alicesWalletTX, alicesWallet) = cashOutputsToWallet( - 3000.DOLLARS.CASH `issued by` MINI_CORP.ref(123) `owned by` ALICE_PUBKEY `with notary` DUMMY_NOTARY, - 3000.DOLLARS.CASH `issued by` MINI_CORP.ref(123) `owned by` ALICE_PUBKEY `with notary` DUMMY_NOTARY, - 3000.DOLLARS.CASH `issued by` MINI_CORP.ref(123) `owned by` ALICE_PUBKEY `with notary` DUMMY_NOTARY + 3000.DOLLARS.CASH `issued by` DUMMY_CASH_ISSUER `owned by` ALICE_PUBKEY `with notary` DUMMY_NOTARY, + 3000.DOLLARS.CASH `issued by` DUMMY_CASH_ISSUER `owned by` ALICE_PUBKEY `with notary` DUMMY_NOTARY, + 3000.DOLLARS.CASH `issued by` DUMMY_CASH_ISSUER `owned by` ALICE_PUBKEY `with notary` DUMMY_NOTARY ) // Alice pays $9000 to MiniCorp to own some of their debt. @@ -207,8 +208,8 @@ class CommercialPaperTestsGeneric { // Won't be validated. val (corpWalletTX, corpWallet) = cashOutputsToWallet( - 9000.DOLLARS.CASH `issued by` MINI_CORP.ref(123) `owned by` MINI_CORP_PUBKEY `with notary` DUMMY_NOTARY, - 4000.DOLLARS.CASH `issued by` MINI_CORP.ref(123) `owned by` MINI_CORP_PUBKEY `with notary` DUMMY_NOTARY + 9000.DOLLARS.CASH `issued by` DUMMY_CASH_ISSUER `owned by` MINI_CORP_PUBKEY `with notary` DUMMY_NOTARY, + 4000.DOLLARS.CASH `issued by` DUMMY_CASH_ISSUER `owned by` MINI_CORP_PUBKEY `with notary` DUMMY_NOTARY ) fun makeRedeemTX(time: Instant): LedgerTransaction { diff --git a/node/src/main/kotlin/com/r3corda/node/internal/testing/TradeSimulation.kt b/node/src/main/kotlin/com/r3corda/node/internal/testing/TradeSimulation.kt index a28baef28b..007a1f8d31 100644 --- a/node/src/main/kotlin/com/r3corda/node/internal/testing/TradeSimulation.kt +++ b/node/src/main/kotlin/com/r3corda/node/internal/testing/TradeSimulation.kt @@ -3,6 +3,7 @@ package com.r3corda.node.internal.testing import com.google.common.util.concurrent.Futures import com.google.common.util.concurrent.ListenableFuture import com.r3corda.contracts.CommercialPaper +import com.r3corda.contracts.asset.DUMMY_CASH_ISSUER import com.r3corda.contracts.testing.fillWithSomeTestCash import com.r3corda.core.contracts.DOLLARS import com.r3corda.core.contracts.SignedTransaction @@ -33,7 +34,8 @@ class TradeSimulation(runAsync: Boolean, latencyInjector: InMemoryMessagingNetwo buyer.services.fillWithSomeTestCash(1500.DOLLARS, notary.info.identity) val issuance = run { - val tx = CommercialPaper().generateIssue(1100.DOLLARS `issued by` seller.info.identity.ref(1, 2, 3), Instant.now() + 10.days, notary.info.identity) + val tx = CommercialPaper().generateIssue(seller.info.identity.ref(1, 2, 3), 1100.DOLLARS `issued by` DUMMY_CASH_ISSUER, + Instant.now() + 10.days, notary.info.identity) tx.setTime(Instant.now(), notary.info.identity, 30.seconds) tx.signWith(notary.storage.myLegalIdentityKey) tx.signWith(seller.storage.myLegalIdentityKey) diff --git a/src/main/kotlin/com/r3corda/demos/TraderDemo.kt b/src/main/kotlin/com/r3corda/demos/TraderDemo.kt index fa5a499181..04d9f8871a 100644 --- a/src/main/kotlin/com/r3corda/demos/TraderDemo.kt +++ b/src/main/kotlin/com/r3corda/demos/TraderDemo.kt @@ -3,6 +3,7 @@ package com.r3corda.demos import co.paralleluniverse.fibers.Suspendable import com.google.common.net.HostAndPort import com.r3corda.contracts.CommercialPaper +import com.r3corda.contracts.asset.DUMMY_CASH_ISSUER import com.r3corda.contracts.asset.cashBalances import com.r3corda.contracts.testing.fillWithSomeTestCash import com.r3corda.core.contracts.* @@ -336,7 +337,8 @@ private class TraderDemoProtocolSeller(val otherSide: Party, val party = Party("Bank of London", keyPair.public) val issuance: SignedTransaction = run { - val tx = CommercialPaper().generateIssue(1100.DOLLARS `issued by` party.ref(1, 2, 3), Instant.now() + 10.days, notaryNode.identity) + val tx = CommercialPaper().generateIssue(party.ref(1, 2, 3), 1100.DOLLARS `issued by` DUMMY_CASH_ISSUER, + Instant.now() + 10.days, notaryNode.identity) // TODO: Consider moving these two steps below into generateIssue.