Crowdfund contract: update to latest style for defining commands (singletons don't play nice with serialisation)

This commit is contained in:
Mike Hearn 2015-11-30 16:39:03 +00:00
parent b3f7e307c7
commit 9780f6254a
3 changed files with 15 additions and 18 deletions

View File

@ -36,13 +36,10 @@ class CrowdFund : Contract {
interface Commands : Command {
object Register : Commands
object Fund : Commands
object Funded : Commands
object Unfunded : Commands
class Register : TypeOnlyCommand(), Commands
class Fund : TypeOnlyCommand(), Commands
class Funded : TypeOnlyCommand(), Commands
class Unfunded : TypeOnlyCommand(), Commands
}
override fun verify(tx: TransactionForVerification) {
@ -155,7 +152,7 @@ class CrowdFund : Contract {
*/
fun craftRegister(owner: InstitutionReference, fundingTarget: Amount, fundingName: String, closingTime: Instant): PartialTransaction {
val state = State(owner = owner.institution.owningKey, fundingName = fundingName, fundingTarget = fundingTarget, closingTime = closingTime)
return PartialTransaction(state, WireCommand(CrowdFund.Commands.Register, owner.institution.owningKey))
return PartialTransaction(state, WireCommand(CrowdFund.Commands.Register(), owner.institution.owningKey))
}
/**
@ -168,13 +165,13 @@ class CrowdFund : Contract {
pledgeCount = campaign.state.pledgeCount + 1,
pledgeTotal = campaign.state.pledgeTotal + 1000.DOLLARS
))
tx.addArg(WireCommand(CrowdFund.Commands.Fund, subscriber))
tx.addArg(WireCommand(CrowdFund.Commands.Fund(), subscriber))
}
fun craftFunded(tx: PartialTransaction, campaign: StateAndRef<State>) {
tx.addInputState(campaign.ref)
tx.addOutputState(campaign.state.copy(closed = true))
tx.addArg(WireCommand(CrowdFund.Commands.Funded, campaign.state.owner))
tx.addArg(WireCommand(CrowdFund.Commands.Funded(), campaign.state.owner))
}
override val legalContractReference: SecureHash = SecureHash.sha256("Crowdsourcing")

View File

@ -255,9 +255,9 @@ fun createKryo(): Kryo {
register(CommercialPaper.Commands.Issue::class.java)
registerDataClass<CrowdFund.State>()
registerDataClass<CrowdFund.Pledge>()
register(CrowdFund.Commands.Register.javaClass)
register(CrowdFund.Commands.Fund.javaClass)
register(CrowdFund.Commands.Funded.javaClass)
register(CrowdFund.Commands.Register::class.java)
register(CrowdFund.Commands.Fund::class.java)
register(CrowdFund.Commands.Funded::class.java)
// And for unit testing ...
registerDataClass<DummyPublicKey>()

View File

@ -22,7 +22,7 @@ class CrowdFundTests {
transactionGroup {
transaction {
output { CF_1 }
arg(DUMMY_PUBKEY_1) { CrowdFund.Commands.Register }
arg(DUMMY_PUBKEY_1) { CrowdFund.Commands.Register() }
}
expectFailureOfTx(1, "the transaction is signed by the owner of the crowdsourcing")
@ -34,7 +34,7 @@ class CrowdFundTests {
transactionGroup {
transaction {
output { CF_1.copy(closingTime = TEST_TX_TIME - 1.days) }
arg(MINI_CORP_PUBKEY) { CrowdFund.Commands.Register }
arg(MINI_CORP_PUBKEY) { CrowdFund.Commands.Register() }
}
expectFailureOfTx(1, "the output registration has a closing time in the future")
@ -55,7 +55,7 @@ class CrowdFundTests {
// 1. Create the funding opportunity
transaction {
output("funding opportunity") { CF_1 }
arg(MINI_CORP_PUBKEY) { CrowdFund.Commands.Register }
arg(MINI_CORP_PUBKEY) { CrowdFund.Commands.Register() }
}
// 2. Place a pledge
@ -71,14 +71,14 @@ class CrowdFundTests {
}
output { 1000.DOLLARS.CASH `owned by` MINI_CORP_PUBKEY }
arg(ALICE) { Cash.Commands.Move() }
arg(ALICE) { CrowdFund.Commands.Fund }
arg(ALICE) { CrowdFund.Commands.Fund() }
}
// 3. Close the opportunity, assuming the target has been met
transaction(TEST_TX_TIME + 8.days) {
input ("pledged opportunity")
output ("funded and closed") { "pledged opportunity".output.copy(closed = true) }
arg(MINI_CORP_PUBKEY) { CrowdFund.Commands.Funded }
arg(MINI_CORP_PUBKEY) { CrowdFund.Commands.Funded() }
}
}
}