Skip to content

Instantly share code, notes, and snippets.

@davidawad
Created March 18, 2021 18:48
Show Gist options
  • Save davidawad/54bc5dbb221776e8041d6ddd75b85e5b to your computer and use it in GitHub Desktop.
Save davidawad/54bc5dbb221776e8041d6ddd75b85e5b to your computer and use it in GitHub Desktop.
class CarIssueFlow {
@InitiatingFlow
@StartableByRPC
class Initiator(var owningBank: Party, var holdingDealer: Party) : FlowLogic<SignedTransaction?>() {
@Suspendable
@Throws(FlowException::class)
override fun call(): SignedTransaction {
// find a notary for the transaction
val notary = serviceHub.networkMapCache.notaryIdentities[0]
// get a reference to the manufacturer node, the only node that can issue new cars
val manufacturer = ourIdentity
// create our car state
val carState = CarState(owningBank, holdingDealer, manufacturer)
// build the transaction
val transactionBuilder = TransactionBuilder(notary)
// we're manufacturing a new car
val commandData: CommandData = CarContract.Commands.Issue()
// add the command and add the expected output of the transaction
transactionBuilder.addCommand(commandData, manufacturer.owningKey, holdingDealer.owningKey)
transactionBuilder.addOutputState(carState, CarContract.ID)
// verify the transaction
transactionBuilder.verify(serviceHub)
// initiate the flow and transaction
val session = initiateFlow(holdingDealer)
// use corda to collect signatures from all the required signers
val signedTransaction = serviceHub.signInitialTransaction(transactionBuilder)
val fullySignedTransaction = subFlow(CollectSignaturesFlow(signedTransaction, listOf(session)))
return subFlow(FinalityFlow(fullySignedTransaction, listOf(session)))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment