From dc304199c8192d4f808b755f382e0da093f320ee Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Tue, 28 Jun 2016 11:12:52 +0100 Subject: [PATCH] Remove warnings from Obligation contract --- .../main/kotlin/com/r3corda/contracts/Obligation.kt | 12 +++++------- .../com/r3corda/contracts/cash/FungibleAssetState.kt | 2 +- .../kotlin/com/r3corda/contracts/ObligationTests.kt | 11 +++++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/contracts/src/main/kotlin/com/r3corda/contracts/Obligation.kt b/contracts/src/main/kotlin/com/r3corda/contracts/Obligation.kt index cb1504a428..e5c25dcb14 100644 --- a/contracts/src/main/kotlin/com/r3corda/contracts/Obligation.kt +++ b/contracts/src/main/kotlin/com/r3corda/contracts/Obligation.kt @@ -153,8 +153,8 @@ class Obligation

: Contract { override val owner: PublicKey get() = beneficiary - override fun move(amount: Amount

, beneficiary: PublicKey): Obligation.State

- = copy(quantity = amount.quantity, beneficiary = beneficiary) + override fun move(newAmount: Amount

, newOwner: PublicKey): Obligation.State

+ = copy(quantity = newAmount.quantity, beneficiary = newOwner) override fun toString() = when (lifecycle) { Lifecycle.NORMAL -> "${Emoji.bagOfCash}Debt($amount due $dueBefore to ${beneficiary.toStringShort()})" @@ -272,13 +272,12 @@ class Obligation

: Contract { for ((inputs, outputs, key) in groups) { // Either inputs or outputs could be empty. val obligor = key.obligor - val commands = commandGroups[key] ?: emptyList() requireThat { "there are no zero sized outputs" by outputs.none { it.amount.quantity == 0L } } - verifyCommandGroup(tx, commands, inputs, outputs, obligor, key) + verifyCommandGroup(tx, commandGroups[key] ?: emptyList(), inputs, outputs, obligor, key) } } } @@ -318,7 +317,7 @@ class Obligation

: Contract { "all outputs are in the normal state " by outputs.all { it.lifecycle == Lifecycle.NORMAL } } if (issueCommand != null) { - verifyIssueCommand(inputs, outputs, tx, issueCommand, issued, obligor) + verifyIssueCommand(inputs, outputs, issueCommand, issued, obligor) } else if (settleCommand != null) { // Perhaps through an abundance of caution, settlement is enforced as its own command. // This could perhaps be merged into verifyBalanceChange() later, however doing so introduces a lot @@ -414,7 +413,6 @@ class Obligation

: Contract { @VisibleForTesting protected fun verifyIssueCommand(inputs: List>, outputs: List>, - tx: TransactionForContract, issueCommand: AuthenticatedObject>, issued: Issued

, obligor: Party) { @@ -794,7 +792,7 @@ fun

sumAmountsDue(balances: Map, Amount

>): Map // Strip zero balances val iterator = sum.iterator() while (iterator.hasNext()) { - val (key, amount) = iterator.next() + val amount = iterator.next().value if (amount == 0L) { iterator.remove() } diff --git a/contracts/src/main/kotlin/com/r3corda/contracts/cash/FungibleAssetState.kt b/contracts/src/main/kotlin/com/r3corda/contracts/cash/FungibleAssetState.kt index b2641d5d99..28a85c173e 100644 --- a/contracts/src/main/kotlin/com/r3corda/contracts/cash/FungibleAssetState.kt +++ b/contracts/src/main/kotlin/com/r3corda/contracts/cash/FungibleAssetState.kt @@ -11,5 +11,5 @@ import java.security.PublicKey interface FungibleAssetState : OwnableState { val issuanceDef: I val productAmount: Amount - fun move(amount: Amount, owner: PublicKey): FungibleAssetState + fun move(newAmount: Amount, newOwner: PublicKey): FungibleAssetState } \ No newline at end of file diff --git a/contracts/src/test/kotlin/com/r3corda/contracts/ObligationTests.kt b/contracts/src/test/kotlin/com/r3corda/contracts/ObligationTests.kt index 6f264bc5df..3a9f9e1fdd 100644 --- a/contracts/src/test/kotlin/com/r3corda/contracts/ObligationTests.kt +++ b/contracts/src/test/kotlin/com/r3corda/contracts/ObligationTests.kt @@ -116,10 +116,13 @@ class ObligationTests { Obligation().generateIssue(ptx, MINI_CORP, megaCorpDollarSettlement, 100.DOLLARS.quantity, beneficiary = DUMMY_PUBKEY_1, notary = DUMMY_NOTARY) assertTrue(ptx.inputStates().isEmpty()) - val s = ptx.outputStates()[0].data as Obligation.State - assertEquals(100.DOLLARS, s.amount) - assertEquals(MINI_CORP, s.obligor) - assertEquals(DUMMY_PUBKEY_1, s.beneficiary) + val expected = Obligation.State( + obligor = MINI_CORP, + quantity = 100.DOLLARS.quantity, + beneficiary = DUMMY_PUBKEY_1, + template = megaCorpDollarSettlement + ) + assertEquals(ptx.outputStates()[0].data, expected) assertTrue(ptx.commands()[0].value is Obligation.Commands.Issue<*>) assertEquals(MINI_CORP_PUBKEY, ptx.commands()[0].signers[0])