Merged in rnicoll-warnings (pull request #192)

Remove warnings from Obligation contract
This commit is contained in:
Ross Nicoll 2016-06-29 13:49:05 +01:00
commit 22e5a5dddc
3 changed files with 13 additions and 12 deletions

View File

@ -153,8 +153,8 @@ class Obligation<P> : Contract {
override val owner: PublicKey override val owner: PublicKey
get() = beneficiary get() = beneficiary
override fun move(amount: Amount<P>, beneficiary: PublicKey): Obligation.State<P> override fun move(newAmount: Amount<P>, newOwner: PublicKey): Obligation.State<P>
= copy(quantity = amount.quantity, beneficiary = beneficiary) = copy(quantity = newAmount.quantity, beneficiary = newOwner)
override fun toString() = when (lifecycle) { override fun toString() = when (lifecycle) {
Lifecycle.NORMAL -> "${Emoji.bagOfCash}Debt($amount due $dueBefore to ${beneficiary.toStringShort()})" Lifecycle.NORMAL -> "${Emoji.bagOfCash}Debt($amount due $dueBefore to ${beneficiary.toStringShort()})"
@ -272,13 +272,12 @@ class Obligation<P> : Contract {
for ((inputs, outputs, key) in groups) { for ((inputs, outputs, key) in groups) {
// Either inputs or outputs could be empty. // Either inputs or outputs could be empty.
val obligor = key.obligor val obligor = key.obligor
val commands = commandGroups[key] ?: emptyList()
requireThat { requireThat {
"there are no zero sized outputs" by outputs.none { it.amount.quantity == 0L } "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<P> : Contract {
"all outputs are in the normal state " by outputs.all { it.lifecycle == Lifecycle.NORMAL } "all outputs are in the normal state " by outputs.all { it.lifecycle == Lifecycle.NORMAL }
} }
if (issueCommand != null) { if (issueCommand != null) {
verifyIssueCommand(inputs, outputs, tx, issueCommand, issued, obligor) verifyIssueCommand(inputs, outputs, issueCommand, issued, obligor)
} else if (settleCommand != null) { } else if (settleCommand != null) {
// Perhaps through an abundance of caution, settlement is enforced as its own command. // 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 // This could perhaps be merged into verifyBalanceChange() later, however doing so introduces a lot
@ -414,7 +413,6 @@ class Obligation<P> : Contract {
@VisibleForTesting @VisibleForTesting
protected fun verifyIssueCommand(inputs: List<State<P>>, protected fun verifyIssueCommand(inputs: List<State<P>>,
outputs: List<State<P>>, outputs: List<State<P>>,
tx: TransactionForContract,
issueCommand: AuthenticatedObject<Commands.Issue<P>>, issueCommand: AuthenticatedObject<Commands.Issue<P>>,
issued: Issued<P>, issued: Issued<P>,
obligor: Party) { obligor: Party) {
@ -794,7 +792,7 @@ fun <P> sumAmountsDue(balances: Map<Pair<PublicKey, PublicKey>, Amount<P>>): Map
// Strip zero balances // Strip zero balances
val iterator = sum.iterator() val iterator = sum.iterator()
while (iterator.hasNext()) { while (iterator.hasNext()) {
val (key, amount) = iterator.next() val amount = iterator.next().value
if (amount == 0L) { if (amount == 0L) {
iterator.remove() iterator.remove()
} }

View File

@ -11,5 +11,5 @@ import java.security.PublicKey
interface FungibleAssetState<T, I> : OwnableState { interface FungibleAssetState<T, I> : OwnableState {
val issuanceDef: I val issuanceDef: I
val productAmount: Amount<T> val productAmount: Amount<T>
fun move(amount: Amount<T>, owner: PublicKey): FungibleAssetState<T, I> fun move(newAmount: Amount<T>, newOwner: PublicKey): FungibleAssetState<T, I>
} }

View File

@ -116,10 +116,13 @@ class ObligationTests {
Obligation<Currency>().generateIssue(ptx, MINI_CORP, megaCorpDollarSettlement, 100.DOLLARS.quantity, Obligation<Currency>().generateIssue(ptx, MINI_CORP, megaCorpDollarSettlement, 100.DOLLARS.quantity,
beneficiary = DUMMY_PUBKEY_1, notary = DUMMY_NOTARY) beneficiary = DUMMY_PUBKEY_1, notary = DUMMY_NOTARY)
assertTrue(ptx.inputStates().isEmpty()) assertTrue(ptx.inputStates().isEmpty())
val s = ptx.outputStates()[0].data as Obligation.State<Currency> val expected = Obligation.State(
assertEquals(100.DOLLARS, s.amount) obligor = MINI_CORP,
assertEquals(MINI_CORP, s.obligor) quantity = 100.DOLLARS.quantity,
assertEquals(DUMMY_PUBKEY_1, s.beneficiary) beneficiary = DUMMY_PUBKEY_1,
template = megaCorpDollarSettlement
)
assertEquals(ptx.outputStates()[0].data, expected)
assertTrue(ptx.commands()[0].value is Obligation.Commands.Issue<*>) assertTrue(ptx.commands()[0].value is Obligation.Commands.Issue<*>)
assertEquals(MINI_CORP_PUBKEY, ptx.commands()[0].signers[0]) assertEquals(MINI_CORP_PUBKEY, ptx.commands()[0].signers[0])