ContractState now references contract by class name (#1407)

* ContractState's contract type has been moved to TransactionState and is now a string representing the class name of the contract class to allow classloading of arbitrary contracts from custom classloaders.

* Upgraded isolated JAR to new version.
This commit is contained in:
Clinton
2017-09-11 16:44:18 +01:00
committed by GitHub
parent 10c4d46b97
commit bc6628a072
81 changed files with 669 additions and 685 deletions

View File

@ -22,6 +22,7 @@ import net.corda.core.utilities.UntrustworthyData;
import net.corda.core.utilities.X500NameUtils;
import net.corda.finance.contracts.asset.Cash;
import net.corda.testing.contracts.DummyContract;
import net.corda.testing.contracts.DummyContractKt;
import net.corda.testing.contracts.DummyState;
import org.jetbrains.annotations.NotNull;
@ -331,7 +332,7 @@ public class FlowCookbookJava {
// We can also add items using methods for the individual components:
// DOCSTART 28
txBuilder.addInputState(ourStateAndRef);
txBuilder.addOutputState(ourOutput);
txBuilder.addOutputState(ourOutput, DummyContractKt.getDUMMY_PROGRAM_ID());
txBuilder.addCommand(ourCommand);
txBuilder.addAttachment(ourAttachment);
// DOCEND 28

View File

@ -20,6 +20,7 @@ import net.corda.core.utilities.*
import net.corda.core.utilities.ProgressTracker.Step
import net.corda.finance.contracts.asset.Cash
import net.corda.testing.ALICE_PUBKEY
import net.corda.testing.contracts.DUMMY_PROGRAM_ID
import net.corda.testing.contracts.DummyContract
import net.corda.testing.contracts.DummyState
import java.security.PublicKey
@ -309,7 +310,7 @@ object FlowCookbook {
// We can also add items using methods for the individual components:
// DOCSTART 28
txBuilder.addInputState(ourStateAndRef)
txBuilder.addOutputState(ourOutput)
txBuilder.addOutputState(ourOutput, DUMMY_PROGRAM_ID)
txBuilder.addCommand(ourCommand)
txBuilder.addAttachment(ourAttachment)
// DOCEND 28

View File

@ -1,10 +1,7 @@
package net.corda.docs
import co.paralleluniverse.fibers.Suspendable
import net.corda.core.contracts.Amount
import net.corda.core.contracts.Issued
import net.corda.core.contracts.StateAndRef
import net.corda.core.contracts.withoutIssuer
import net.corda.core.contracts.*
import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.TransactionSignature
import net.corda.core.flows.*
@ -17,6 +14,7 @@ import net.corda.core.serialization.CordaSerializable
import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.unwrap
import net.corda.finance.contracts.asset.CASH_PROGRAM_ID
import net.corda.finance.contracts.asset.Cash
import net.corda.finance.schemas.CashSchemaV1
import java.util.*
@ -184,8 +182,8 @@ class ForeignExchangeFlow(val tradeId: String,
// Build and add the inputs and outputs
builder.withItems(*ourInputStates.toTypedArray())
builder.withItems(*theirInputStates.toTypedArray())
builder.withItems(*ourOutputState.toTypedArray())
builder.withItems(*theirOutputState.toTypedArray())
builder.withItems(*ourOutputState.map { StateAndContract(it, CASH_PROGRAM_ID) }.toTypedArray())
builder.withItems(*theirOutputState.map { StateAndContract(it, CASH_PROGRAM_ID) }.toTypedArray())
// We have already validated their response and trust our own data
// so we can sign. Note the returned SignedTransaction is still not fully signed

View File

@ -26,6 +26,8 @@ enum class WorkflowState {
REJECTED
}
val TRADE_APPROVAL_PROGRAM_ID = "net.corda.docs.TradeApprovalContract"
/**
* Minimal contract to encode a simple workflow with one initial state and two possible eventual states.
* It is assumed one party unilaterally submits and the other manually retrieves the deal and completes it.
@ -44,9 +46,7 @@ data class TradeApprovalContract(val blank: Unit? = null) : Contract {
val source: Party,
val counterparty: Party,
val state: WorkflowState = WorkflowState.NEW,
override val linearId: UniqueIdentifier = UniqueIdentifier(tradeId),
override val contract: TradeApprovalContract = TradeApprovalContract()) : LinearState {
override val linearId: UniqueIdentifier = UniqueIdentifier(tradeId)) : LinearState {
val parties: List<Party> get() = listOf(source, counterparty)
override val participants: List<AbstractParty> get() = parties
}
@ -108,7 +108,7 @@ class SubmitTradeApprovalFlow(val tradeId: String,
val notary = serviceHub.networkMapCache.getAnyNotary()
// Create the TransactionBuilder and populate with the new state.
val tx = TransactionBuilder(notary)
.withItems(tradeProposal, Command(TradeApprovalContract.Commands.Issue(), listOf(tradeProposal.source.owningKey)))
.withItems(StateAndContract(tradeProposal, TRADE_APPROVAL_PROGRAM_ID), Command(TradeApprovalContract.Commands.Issue(), listOf(tradeProposal.source.owningKey)))
tx.setTimeWindow(serviceHub.clock.instant(), 60.seconds)
// We can automatically sign as there is no untrusted data.
val signedTx = serviceHub.signInitialTransaction(tx)
@ -168,7 +168,7 @@ class SubmitCompletionFlow(val ref: StateRef, val verdict: WorkflowState) : Flow
val tx = TransactionBuilder(notary).
withItems(
latestRecord,
newState,
StateAndContract(newState, TRADE_APPROVAL_PROGRAM_ID),
Command(TradeApprovalContract.Commands.Completed(),
listOf(serviceHub.myInfo.legalIdentity.owningKey, latestRecord.state.data.source.owningKey)))
tx.setTimeWindow(serviceHub.clock.instant(), 60.seconds)