Add common Issue and Move commands

* Add common Issue command to encourage presence of a nonce value when issuing state objects.
* Add common Move command for contracts which support being moved in order to fulfil other contracts.
This commit is contained in:
Ross Nicoll 2016-05-27 16:46:52 +01:00
parent 32b593671b
commit af53a52b06
3 changed files with 26 additions and 4 deletions

View File

@ -69,13 +69,20 @@ class Cash : FungibleAsset<Currency>() {
// Just for grouping
interface Commands : CommandData {
class Move() : TypeOnlyCommandData(), FungibleAsset.Commands.Move
/**
* A command stating that money has been moved, optionally to fulfil another contract.
*
* @param contractHash the hash of the contract this cash is settling, to ensure one cash contract cannot be
* used to settle multiple contracts. May be null, if this is not relevant to any other contract in the
* same transaction
*/
data class Move(override val contractHash: SecureHash? = null) : FungibleAsset.Commands.Move, Commands
/**
* Allows new cash states to be issued into existence: the nonce ("number used once") ensures the transaction
* has a unique ID even when there are no inputs.
*/
data class Issue(override val nonce: Long = newSecureRandom().nextLong()) : FungibleAsset.Commands.Issue
data class Issue(override val nonce: Long = newSecureRandom().nextLong()) : FungibleAsset.Commands.Issue, Commands
/**
* A command stating that money has been withdrawn from the shared ledger and is now accounted for

View File

@ -41,13 +41,13 @@ abstract class FungibleAsset<T> : Contract {
// Just for grouping
interface Commands : CommandData {
interface Move : Commands
interface Move : MoveCommand, Commands
/**
* Allows new asset states to be issued into existence: the nonce ("number used once") ensures the transaction
* has a unique ID even when there are no inputs.
*/
interface Issue : Commands { val nonce: Long }
interface Issue : IssueCommand, Commands
/**
* A command stating that money has been withdrawn from the shared ledger and is now accounted for

View File

@ -228,6 +228,21 @@ data class Command(val value: CommandData, val signers: List<PublicKey>) {
override fun toString() = "${commandDataToString()} with pubkeys ${signers.map { it.toStringShort() }}"
}
/** A common issue command, to enforce that issue commands have a nonce value. */
interface IssueCommand : CommandData {
val nonce: Long
}
/** A common move command for contracts which can change owner. */
interface MoveCommand : CommandData {
/**
* Contract code the moved state(s) are for the attention of, for example to indicate that the states are moved in
* order to settle an obligation contract's state object(s).
*/
// TODO: Replace SecureHash here with a general contract constraints object
val contractHash: SecureHash?
}
/** Wraps an object that was signed by a public key, which may be a well known/recognised institutional key. */
data class AuthenticatedObject<out T : Any>(
val signers: List<PublicKey>,