How to identify one unconfirmed fact in Korda

We are currently planning to have one "draft" version of the contract, which will not be sent to the counterparty, and the initiator can make any changes before sending it to the network, so it should be like one "misunderstood fact". Since we know that Corda and the store are used for shared facts, so I'm not sure if we can use the store to store this type of "fiddle", my idea is as below and I can already make this work on my local basis See the CorDapp tutorial, but would like some input from other Corda teams / experts.

Major change in the initiator thread:

  • Initiate create command with only initiator key
  • Don't call "CollectSignaturesFlow" so it won't be sent to anyone else.
  • Calling "FinalityFlow" after check (), so this will be captured in the book

Below are the codes for the above items.

override fun call(): SignedTransaction  {
    // We create a transaction builder
    val txBuilder = TransactionBuilder()
    val notaryIdentity = serviceHub.networkMapCache.getAnyNotary()
    txBuilder.notary = notaryIdentity

    // We create the transaction components.
    val ourIdentity = serviceHub.myInfo.legalIdentity
    val iou = TemplateState(iouValue, ourIdentity, ourIdentity)
    val txCommand = Command(TemplateContract.Create(), listOf(ourIdentity.owningKey))

    // Adding the item to the builder.
    txBuilder.withItems(iou, txCommand)

    // Verifying the transaction.
    txBuilder.toWireTransaction().toLedgerTransaction(serviceHub).verify()

    // Signing the transaction.
    val partSignedTx = serviceHub.signInitialTransaction(txBuilder)

    // Finalising the transaction.
    return subFlow(FinalityFlow(partSignedTx)).single()
}

      

+3


source to share


1 answer


You can really create an untold fact in Korda! The key here is in the state participants

. Just add yourself to the list of participants and only your public key to the team. Here's a simple example:

//Contract and State.
class UnsharedFact: Contract {
    override val legalContractReference: SecureHash = SecureHash.zeroHash
    override fun verify(tx: TransactionForContract) = Unit // Stubbed out.
    class Create: CommandData

    data class State(val parties: Set<Party>): ContractState {
        override val contract: Contract get() = UnsharedFact()
        override val participants: List<AbstractParty> get() = parties.toList()
        fun addParty(newParty: Party) = copy(parties = parties + newParty)
    }
}

// Create flow.
@InitiatingFlow
@StartableByRPC
class CreateUnsharedFact(): FlowLogic<SignedTransaction>() {
    @Suspendable
    override fun call(): SignedTransaction {
        val me = serviceHub.myInfo.legalIdentity
        val notary = serviceHub.networkMapCache.getAnyNotary()
        val state = UnsharedFact.State(setOf(me))
        val command = Command(UnsharedFact.Create(), listOf(me.owningKey))
        val utx = TransactionBuilder(notary = notary).withItems(state, command)
        val stx = serviceHub.signInitialTransaction(utx)
        return subFlow(FinalityFlow(stx)).single()
    }
}

      

When called FinalityFlow

, you will be the only node to receive the output state.



If you want to recruit the other side later, you can create a new version of the state using the method addParty

on UnsharedFact.State

. Then create a new transaction, adding the original state as input and a new version (with a new side) as output. When this transaction is completed (notarized), both parties will have a copy in their vaults. Now I think the name "UnsharedFact" is inappropriate :)

You can also remove sides using a similar approach.

+3


source







All Articles