Minor: remove ambiguous c'tor in PartialTransaction and rename addItems -> withItems

This commit is contained in:
Mike Hearn 2015-12-16 16:25:58 +01:00
parent ab9e026053
commit 4cec5dac02
4 changed files with 6 additions and 11 deletions

View File

@ -119,7 +119,7 @@ class CommercialPaper : Contract {
*/ */
fun craftIssue(issuance: PartyReference, faceValue: Amount, maturityDate: Instant): PartialTransaction { fun craftIssue(issuance: PartyReference, faceValue: Amount, maturityDate: Instant): PartialTransaction {
val state = State(issuance, issuance.party.owningKey, faceValue, maturityDate) 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))
} }
/** /**

View File

@ -146,7 +146,7 @@ class CrowdFund : Contract {
fun craftRegister(owner: PartyReference, fundingTarget: Amount, fundingName: String, closingTime: Instant): PartialTransaction { 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 campaign = Campaign(owner = owner.party.owningKey, name = fundingName, target = fundingTarget, closingTime = closingTime)
val state = State(campaign) val state = State(campaign)
return PartialTransaction(state, WireCommand(Commands.Register(), owner.party.owningKey)) return PartialTransaction().withItems(state, WireCommand(Commands.Register(), owner.party.owningKey))
} }
/** /**

View File

@ -68,14 +68,8 @@ data class WireTransaction(val inputStates: List<ContractStateRef>,
class PartialTransaction(private val inputStates: MutableList<ContractStateRef> = arrayListOf(), class PartialTransaction(private val inputStates: MutableList<ContractStateRef> = arrayListOf(),
private val outputStates: MutableList<ContractState> = arrayListOf(), private val outputStates: MutableList<ContractState> = arrayListOf(),
private val commands: MutableList<WireCommand> = arrayListOf()) { private val commands: MutableList<WireCommand> = 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 */ /** 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) { for (t in items) {
when (t) { when (t) {
is ContractStateRef -> inputStates.add(t) is ContractStateRef -> inputStates.add(t)
@ -84,6 +78,7 @@ class PartialTransaction(private val inputStates: MutableList<ContractStateRef>
else -> throw IllegalArgumentException("Wrong argument type: ${t.javaClass}") else -> throw IllegalArgumentException("Wrong argument type: ${t.javaClass}")
} }
} }
return this
} }
/** The signatures that have been collected so far - might be incomplete! */ /** The signatures that have been collected so far - might be incomplete! */

View File

@ -30,7 +30,7 @@ class TransactionSerializationTests {
@Before @Before
fun setup() { fun setup() {
tx = PartialTransaction( tx = PartialTransaction().withItems(
fakeStateRef, outputState, changeState, WireCommand(Cash.Commands.Move(), arrayListOf(TestUtils.keypair.public)) 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. // If the signature was replaced in transit, we don't like it.
assertFailsWith(SignatureException::class) { assertFailsWith(SignatureException::class) {
val tx2 = PartialTransaction(fakeStateRef, outputState, changeState, val tx2 = PartialTransaction().withItems(fakeStateRef, outputState, changeState,
WireCommand(Cash.Commands.Move(), arrayListOf(TestUtils.keypair2.public))) WireCommand(Cash.Commands.Move(), arrayListOf(TestUtils.keypair2.public)))
tx2.signWith(TestUtils.keypair2) tx2.signWith(TestUtils.keypair2)