Introduction
Partiture is a compact component framework for your Corda apps. For the time being, it's primary goal is flow composition.
Installation
cordaCompile "com.github.manosbatsis.partiture:partiture:$partiture_version"
Example Flows
The following sections demonstrate simple examples of initiating and responding flows.
Sample Initiating Flow
Start with a Yo!
sending flow, that uses List<Party>
and List<SignedTransaction>
for PartitureFlow
's IN
and OUT
type variables respectively:
/** Create a Yo! transaction/state for each input recipient/party */
@InitiatingFlow
@StartableByRPC
class YoFlow(input: List<Party>) : PartitureFlow<List<Party>, List<SignedTransaction>>(
// Can be any type, just match with PartitureFlow's IN generic argument above
input = input
) {
/** Override to manually init the flow's CallContext */
override fun processInput(): CallContext {
// do stuff...
}
/** Override to manually create the flow's OUT instance */
override fun processOutput(): List<SignedTransaction> {
// do stuff...
}
}
Better yet, use an InputConverter
and OutputConverter
instead of
overriding processInput()
and processOutput()
as we did above,
thus reducing the flow to a declaration-only class that binds everything together:
/** Create a Yo! transaction/state for each input recipient/party */
@InitiatingFlow
@StartableByRPC
class YoFlow(input: List<Party>) : PartitureFlow<List<Party>, List<SignedTransaction>>(
// Can be any type, just match with PartitureFlow's IN generic argument above
input = input,
inputConverter = YoInputConverter(),// Our custom IN converter
outputConverter = FinalizedTxOutputConverter()) // build-in converter matching OUT
// No implementation needed!
Both of the above flow implementations will:
- Use the overriden
processInput()
or providedinputConverter
respectively to initialize aCallContext
with a call/tx entry per inputParty
- Use the build-in default
TxStrategy
(since we have not provided one) on each ofCallContext.entries
to:- Sign an initial transaction
- Create flow sessions for counter-parties, if any exist
- Perform an identity sync if any own anonymous parties are participating in the input/output states in context
- Gather and verify counter-party signatures
- Verify the original transaction builder
- Finalize the transaction
- Use the provided
outputConverter
to produce and return the flow'scall()
result, i.e. a signed TX per Yo! state created
Corda Accounts Support
If you are using Corda Accounts, use PartitureAccountsAwareFlow
instead.
Sample Responding Flow
This is our responder flow. It uses the biuld-in SimpleTypeCheckingResponderTxStrategy
:
@InitiatedBy(YoFlow::class)
class YoFlowResponder(
otherPartySession: FlowSession
) : PartitureResponderFlow(
otherPartySession = otherPartySession,
responderTxStrategy =
SimpleTypeCheckingResponderTxStrategy(YoContract.YoState::class.java)
)
The above responder flow will verify the transaction
and ensure all output states are instances of YoState
before signing.
Sample Project
Partiture is used in the workflow module of the corbeans-yo-cordapp sample project, check it out at https://github.com/manosbatsis/corbeans-yo-cordapp/tree/master/cordapp-workflow