diff --git a/src/main/kotlin/contracts/CommercialPaper.kt b/src/main/kotlin/contracts/CommercialPaper.kt index b0addb8386..fa031a1d38 100644 --- a/src/main/kotlin/contracts/CommercialPaper.kt +++ b/src/main/kotlin/contracts/CommercialPaper.kt @@ -119,7 +119,7 @@ class CommercialPaper : Contract { */ fun craftIssue(issuance: PartyReference, faceValue: Amount, maturityDate: Instant): PartialTransaction { val state = State(issuance, issuance.party.owningKey, faceValue, maturityDate) - return PartialTransaction(state, WireCommand(Commands.Issue(), issuance.party.owningKey)) + return PartialTransaction().withItems(state, WireCommand(Commands.Issue(), issuance.party.owningKey)) } /** diff --git a/src/main/kotlin/contracts/CrowdFund.kt b/src/main/kotlin/contracts/CrowdFund.kt index 9c1548bb29..2d67dbb01b 100644 --- a/src/main/kotlin/contracts/CrowdFund.kt +++ b/src/main/kotlin/contracts/CrowdFund.kt @@ -146,7 +146,7 @@ class CrowdFund : Contract { fun craftRegister(owner: PartyReference, fundingTarget: Amount, fundingName: String, closingTime: Instant): PartialTransaction { val campaign = Campaign(owner = owner.party.owningKey, name = fundingName, target = fundingTarget, closingTime = closingTime) val state = State(campaign) - return PartialTransaction(state, WireCommand(Commands.Register(), owner.party.owningKey)) + return PartialTransaction().withItems(state, WireCommand(Commands.Register(), owner.party.owningKey)) } /** diff --git a/src/main/kotlin/core/Transactions.kt b/src/main/kotlin/core/Transactions.kt index 4b5a60e0a1..57e1c3c887 100644 --- a/src/main/kotlin/core/Transactions.kt +++ b/src/main/kotlin/core/Transactions.kt @@ -68,14 +68,8 @@ data class WireTransaction(val inputStates: List, class PartialTransaction(private val inputStates: MutableList = arrayListOf(), private val outputStates: MutableList = arrayListOf(), private val commands: MutableList = arrayListOf()) { - - /** A more convenient way to add items to this transaction that calls the add* methods for you based on type */ - constructor(vararg items: Any) : this() { - addItems(*items) - } - /** A more convenient way to add items to this transaction that calls the add* methods for you based on type */ - public fun addItems(vararg items: Any) { + public fun withItems(vararg items: Any): PartialTransaction { for (t in items) { when (t) { is ContractStateRef -> inputStates.add(t) @@ -84,6 +78,7 @@ class PartialTransaction(private val inputStates: MutableList else -> throw IllegalArgumentException("Wrong argument type: ${t.javaClass}") } } + return this } /** The signatures that have been collected so far - might be incomplete! */ diff --git a/src/test/kotlin/core/serialization/TransactionSerializationTests.kt b/src/test/kotlin/core/serialization/TransactionSerializationTests.kt index 8c35df1d8b..e52c157cd0 100644 --- a/src/test/kotlin/core/serialization/TransactionSerializationTests.kt +++ b/src/test/kotlin/core/serialization/TransactionSerializationTests.kt @@ -30,7 +30,7 @@ class TransactionSerializationTests { @Before fun setup() { - tx = PartialTransaction( + tx = PartialTransaction().withItems( fakeStateRef, outputState, changeState, WireCommand(Cash.Commands.Move(), arrayListOf(TestUtils.keypair.public)) ) } @@ -76,7 +76,7 @@ class TransactionSerializationTests { // If the signature was replaced in transit, we don't like it. assertFailsWith(SignatureException::class) { - val tx2 = PartialTransaction(fakeStateRef, outputState, changeState, + val tx2 = PartialTransaction().withItems(fakeStateRef, outputState, changeState, WireCommand(Cash.Commands.Move(), arrayListOf(TestUtils.keypair2.public))) tx2.signWith(TestUtils.keypair2)