mirror of
https://github.com/corda/corda.git
synced 2025-06-21 00:23:09 +00:00
Fix build.
This commit is contained in:
@ -26,7 +26,7 @@ import static kotlin.collections.CollectionsKt.*;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class JavaCommercialPaper implements Contract {
|
public class JavaCommercialPaper implements Contract {
|
||||||
public static core.SecureHash JCP_PROGRAM_ID = SecureHash.Companion.sha256("java commercial paper (this should be a bytecode hash)");
|
public static SecureHash JCP_PROGRAM_ID = SecureHash.Companion.sha256("java commercial paper (this should be a bytecode hash)");
|
||||||
|
|
||||||
public static class State implements ContractState, ICommercialPaperState {
|
public static class State implements ContractState, ICommercialPaperState {
|
||||||
private PartyReference issuance;
|
private PartyReference issuance;
|
||||||
@ -201,7 +201,7 @@ public class JavaCommercialPaper implements Contract {
|
|||||||
Amount received = CashKt.sumCashBy(tx.getOutStates(), input.getOwner());
|
Amount received = CashKt.sumCashBy(tx.getOutStates(), input.getOwner());
|
||||||
|
|
||||||
if (! received.equals(input.getFaceValue()))
|
if (! received.equals(input.getFaceValue()))
|
||||||
throw new IllegalStateException(String.format("Failed Requirement: received amount equals the face value"));
|
throw new IllegalStateException("Failed Requirement: received amount equals the face value");
|
||||||
if (time.isBefore(input.getMaturityDate()))
|
if (time.isBefore(input.getMaturityDate()))
|
||||||
throw new IllegalStateException("Failed requirement: the paper must have matured");
|
throw new IllegalStateException("Failed requirement: the paper must have matured");
|
||||||
if (!input.getFaceValue().equals(received))
|
if (!input.getFaceValue().equals(received))
|
||||||
@ -220,21 +220,20 @@ public class JavaCommercialPaper implements Contract {
|
|||||||
return SecureHash.Companion.sha256("https://en.wikipedia.org/wiki/Commercial_paper");
|
return SecureHash.Companion.sha256("https://en.wikipedia.org/wiki/Commercial_paper");
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransactionBuilder craftIssue(@NotNull PartyReference issuance, @NotNull Amount faceValue, @Nullable Instant maturityDate) {
|
public TransactionBuilder generateIssue(@NotNull PartyReference issuance, @NotNull Amount faceValue, @Nullable Instant maturityDate) {
|
||||||
State state = new State(issuance,issuance.getParty().getOwningKey(), faceValue, maturityDate);
|
State state = new State(issuance,issuance.getParty().getOwningKey(), faceValue, maturityDate);
|
||||||
return new TransactionBuilder().withItems(state, new Command( new Commands.Issue(), issuance.getParty().getOwningKey()));
|
return new TransactionBuilder().withItems(state, new Command( new Commands.Issue(), issuance.getParty().getOwningKey()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void craftRedeem(TransactionBuilder tx, StateAndRef<State> paper, List<StateAndRef<Cash.State>> wallet) throws InsufficientBalanceException {
|
public void generateRedeem(TransactionBuilder tx, StateAndRef<State> paper, List<StateAndRef<Cash.State>> wallet) throws InsufficientBalanceException {
|
||||||
new Cash().craftSpend(tx, paper.getState().getFaceValue(), paper.getState().getOwner(), wallet, null);
|
new Cash().craftSpend(tx, paper.getState().getFaceValue(), paper.getState().getOwner(), wallet, null);
|
||||||
tx.addInputState(paper.getRef());
|
tx.addInputState(paper.getRef());
|
||||||
tx.addCommand(new Command( new Commands.Redeem(), paper.getState().getOwner()));
|
tx.addCommand(new Command( new Commands.Redeem(), paper.getState().getOwner()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void craftMove(TransactionBuilder tx, StateAndRef<State> paper, PublicKey newOwner) {
|
public void generateMove(TransactionBuilder tx, StateAndRef<State> paper, PublicKey newOwner) {
|
||||||
tx.addInputState(paper.getRef());
|
tx.addInputState(paper.getRef());
|
||||||
tx.addOutputState(new State(paper.getState().getIssuance(), newOwner, paper.getState().getFaceValue(), paper.getState().getMaturityDate()));
|
tx.addOutputState(new State(paper.getState().getIssuance(), newOwner, paper.getState().getFaceValue(), paper.getState().getMaturityDate()));
|
||||||
tx.addCommand(new Command(new Commands.Move(), paper.getState().getOwner()));
|
tx.addCommand(new Command(new Commands.Move(), paper.getState().getOwner()));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,6 +12,8 @@ import core.*
|
|||||||
import core.node.TimestampingError
|
import core.node.TimestampingError
|
||||||
import core.testutils.*
|
import core.testutils.*
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.junit.runners.Parameterized
|
||||||
import java.time.Clock
|
import java.time.Clock
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.ZoneOffset
|
import java.time.ZoneOffset
|
||||||
@ -25,10 +27,40 @@ interface ICommercialPaperTestTemplate {
|
|||||||
open fun getMoveCommand(): CommandData
|
open fun getMoveCommand(): CommandData
|
||||||
}
|
}
|
||||||
|
|
||||||
open class CommercialPaperTestsGeneric(templateToTest: ICommercialPaperTestTemplate) {
|
class JavaCommercialPaperTest() : ICommercialPaperTestTemplate {
|
||||||
|
override fun getPaper(): ICommercialPaperState = JavaCommercialPaper.State(
|
||||||
|
MEGA_CORP.ref(123),
|
||||||
|
MEGA_CORP_PUBKEY,
|
||||||
|
1000.DOLLARS,
|
||||||
|
TEST_TX_TIME + 7.days
|
||||||
|
)
|
||||||
|
|
||||||
val thisTest = templateToTest
|
override fun getIssueCommand(): CommandData = JavaCommercialPaper.Commands.Issue()
|
||||||
val PAPER_1 = thisTest.getPaper()
|
override fun getRedeemCommand(): CommandData = JavaCommercialPaper.Commands.Redeem()
|
||||||
|
override fun getMoveCommand(): CommandData = JavaCommercialPaper.Commands.Move()
|
||||||
|
}
|
||||||
|
|
||||||
|
class KotlinCommercialPaperTest() : ICommercialPaperTestTemplate {
|
||||||
|
override fun getPaper() : ICommercialPaperState = CommercialPaper.State(
|
||||||
|
issuance = MEGA_CORP.ref(123),
|
||||||
|
owner = MEGA_CORP_PUBKEY,
|
||||||
|
faceValue = 1000.DOLLARS,
|
||||||
|
maturityDate = TEST_TX_TIME + 7.days
|
||||||
|
)
|
||||||
|
override fun getIssueCommand(): CommandData = CommercialPaper.Commands.Issue()
|
||||||
|
override fun getRedeemCommand(): CommandData = CommercialPaper.Commands.Redeem()
|
||||||
|
override fun getMoveCommand(): CommandData = CommercialPaper.Commands.Move()
|
||||||
|
}
|
||||||
|
|
||||||
|
@RunWith(Parameterized::class)
|
||||||
|
class CommercialPaperTestsGeneric {
|
||||||
|
companion object {
|
||||||
|
@Parameterized.Parameters @JvmStatic
|
||||||
|
fun data() = listOf(JavaCommercialPaperTest(), KotlinCommercialPaperTest())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Parameterized.Parameter
|
||||||
|
lateinit var thisTest: ICommercialPaperTestTemplate
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun ok() {
|
fun ok() {
|
||||||
@ -44,7 +76,7 @@ open class CommercialPaperTestsGeneric(templateToTest: ICommercialPaperTestTempl
|
|||||||
fun `key mismatch at issue`() {
|
fun `key mismatch at issue`() {
|
||||||
transactionGroup {
|
transactionGroup {
|
||||||
transaction {
|
transaction {
|
||||||
output { PAPER_1 }
|
output { thisTest.getPaper() }
|
||||||
arg(DUMMY_PUBKEY_1) { thisTest.getIssueCommand() }
|
arg(DUMMY_PUBKEY_1) { thisTest.getIssueCommand() }
|
||||||
timestamp(TEST_TX_TIME)
|
timestamp(TEST_TX_TIME)
|
||||||
}
|
}
|
||||||
@ -57,7 +89,7 @@ open class CommercialPaperTestsGeneric(templateToTest: ICommercialPaperTestTempl
|
|||||||
fun `face value is not zero`() {
|
fun `face value is not zero`() {
|
||||||
transactionGroup {
|
transactionGroup {
|
||||||
transaction {
|
transaction {
|
||||||
output { PAPER_1.withFaceValue(0.DOLLARS) }
|
output { thisTest.getPaper().withFaceValue(0.DOLLARS) }
|
||||||
arg(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand() }
|
arg(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand() }
|
||||||
timestamp(TEST_TX_TIME)
|
timestamp(TEST_TX_TIME)
|
||||||
}
|
}
|
||||||
@ -70,7 +102,7 @@ open class CommercialPaperTestsGeneric(templateToTest: ICommercialPaperTestTempl
|
|||||||
fun `maturity date not in the past`() {
|
fun `maturity date not in the past`() {
|
||||||
transactionGroup {
|
transactionGroup {
|
||||||
transaction {
|
transaction {
|
||||||
output { PAPER_1.withMaturityDate(TEST_TX_TIME - 10.days) }
|
output { thisTest.getPaper().withMaturityDate(TEST_TX_TIME - 10.days) }
|
||||||
arg(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand() }
|
arg(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand() }
|
||||||
timestamp(TEST_TX_TIME)
|
timestamp(TEST_TX_TIME)
|
||||||
}
|
}
|
||||||
@ -105,11 +137,11 @@ open class CommercialPaperTestsGeneric(templateToTest: ICommercialPaperTestTempl
|
|||||||
fun `issue cannot replace an existing state`() {
|
fun `issue cannot replace an existing state`() {
|
||||||
transactionGroup {
|
transactionGroup {
|
||||||
roots {
|
roots {
|
||||||
transaction(PAPER_1 label "paper")
|
transaction(thisTest.getPaper() label "paper")
|
||||||
}
|
}
|
||||||
transaction {
|
transaction {
|
||||||
input("paper")
|
input("paper")
|
||||||
output { PAPER_1 }
|
output { thisTest.getPaper() }
|
||||||
arg(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand() }
|
arg(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand() }
|
||||||
timestamp(TEST_TX_TIME)
|
timestamp(TEST_TX_TIME)
|
||||||
}
|
}
|
||||||
@ -203,7 +235,7 @@ open class CommercialPaperTestsGeneric(templateToTest: ICommercialPaperTestTempl
|
|||||||
|
|
||||||
// Some CP is issued onto the ledger by MegaCorp.
|
// Some CP is issued onto the ledger by MegaCorp.
|
||||||
transaction("Issuance") {
|
transaction("Issuance") {
|
||||||
output("paper") { PAPER_1 }
|
output("paper") { thisTest.getPaper() }
|
||||||
arg(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand() }
|
arg(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand() }
|
||||||
timestamp(TEST_TX_TIME)
|
timestamp(TEST_TX_TIME)
|
||||||
}
|
}
|
@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2015 Distributed Ledger Group LLC. Distributed as Licensed Company IP to DLG Group Members
|
|
||||||
* pursuant to the August 7, 2015 Advisory Services Agreement and subject to the Company IP License terms
|
|
||||||
* set forth therein.
|
|
||||||
*
|
|
||||||
* All other rights reserved.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package contracts
|
|
||||||
|
|
||||||
import core.CommandData
|
|
||||||
import core.DOLLARS
|
|
||||||
import core.days
|
|
||||||
import core.testutils.MEGA_CORP
|
|
||||||
import core.testutils.MEGA_CORP_PUBKEY
|
|
||||||
import core.testutils.TEST_TX_TIME
|
|
||||||
|
|
||||||
fun getJavaCommericalPaper() : ICommercialPaperState {
|
|
||||||
return JavaCommercialPaper.State(
|
|
||||||
MEGA_CORP.ref(123),
|
|
||||||
MEGA_CORP_PUBKEY,
|
|
||||||
1000.DOLLARS,
|
|
||||||
TEST_TX_TIME + 7.days
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
open class JavaCommercialPaperTest() : ICommercialPaperTestTemplate {
|
|
||||||
override fun getPaper() : ICommercialPaperState = getJavaCommericalPaper()
|
|
||||||
override fun getIssueCommand() : CommandData = JavaCommercialPaper.Commands.Issue()
|
|
||||||
override fun getRedeemCommand() : CommandData = JavaCommercialPaper.Commands.Redeem()
|
|
||||||
override fun getMoveCommand() : CommandData = JavaCommercialPaper.Commands.Move()
|
|
||||||
}
|
|
||||||
|
|
||||||
class CommercialPaperTestsJava() : CommercialPaperTestsGeneric(JavaCommercialPaperTest()) { }
|
|
||||||
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
|
||||||
CommercialPaperTestsJava().trade().visualise()
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2015 Distributed Ledger Group LLC. Distributed as Licensed Company IP to DLG Group Members
|
|
||||||
* pursuant to the August 7, 2015 Advisory Services Agreement and subject to the Company IP License terms
|
|
||||||
* set forth therein.
|
|
||||||
*
|
|
||||||
* All other rights reserved.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package contracts
|
|
||||||
|
|
||||||
import core.CommandData
|
|
||||||
import core.DOLLARS
|
|
||||||
import core.days
|
|
||||||
import core.testutils.MEGA_CORP
|
|
||||||
import core.testutils.MEGA_CORP_PUBKEY
|
|
||||||
import core.testutils.TEST_TX_TIME
|
|
||||||
|
|
||||||
fun getKotlinCommercialPaper() : ICommercialPaperState {
|
|
||||||
return CommercialPaper.State(
|
|
||||||
issuance = MEGA_CORP.ref(123),
|
|
||||||
owner = MEGA_CORP_PUBKEY,
|
|
||||||
faceValue = 1000.DOLLARS,
|
|
||||||
maturityDate = TEST_TX_TIME + 7.days
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
open class KotlinCommercialPaperTest() : ICommercialPaperTestTemplate {
|
|
||||||
override fun getPaper() : ICommercialPaperState = getKotlinCommercialPaper()
|
|
||||||
override fun getIssueCommand() : CommandData = CommercialPaper.Commands.Issue()
|
|
||||||
override fun getRedeemCommand() : CommandData = CommercialPaper.Commands.Redeem()
|
|
||||||
override fun getMoveCommand() : CommandData = CommercialPaper.Commands.Move()
|
|
||||||
}
|
|
||||||
|
|
||||||
class CommercialPaperTestsKotlin() : CommercialPaperTestsGeneric( KotlinCommercialPaperTest()) { }
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
|
||||||
CommercialPaperTestsKotlin().trade().visualise()
|
|
||||||
}
|
|
||||||
|
|
Reference in New Issue
Block a user