Last active
January 8, 2019 04:14
-
-
Save amolpednekar/0b52f08e9e264673f53790bed94ba193 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Upgraded contracts must implement the UpgradedContract interface. | |
// We're also upgrading the state, so we pass the references to the old and new state as the input and output state. | |
open class NewContractAndState : UpgradedContract<OldState, NewContractAndState.NewState> { | |
companion object { | |
val id = "com.upgrade.NewContractAndState" | |
} | |
// We're upgrading the state as well, so we modify the OldState. | |
override fun upgrade(state: OldState) = NewContractAndState.NewState(state.a, state.b, 1) | |
// Definition of the new state | |
data class NewState(val a: AbstractParty, val b: AbstractParty, val value: Int) : ContractState { | |
override val participants get() = listOf(a, b) | |
} | |
override fun verify(tx: LedgerTransaction) { | |
val command = tx.commands.requireSingleCommand<Commands>() | |
requireThat { | |
when (command.value) { | |
is NewContractAndState.Commands.Action -> { | |
"Value should be greater than 0" using (tx.outputsOfType<NewState>().single().value > 0) | |
} | |
} | |
} | |
} | |
interface Commands : CommandData{ | |
class Action : Commands | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment