Jk_
Jk_

Reputation: 105

How to share a corda account between two nodes?

I used the below flow to share the account from one Node to Other Node

@InitiatingFlow
@StartableByService
@StartableByRPC
class ShareAccountInfotoOtherParty(val accountName: String,
                       val partyName: String) : FlowLogic<String>() {

    @Suspendable
    override fun call(): String {




        val TestAccount = subFlow(OurAccounts()).filter {  it.state.data.name == accountName  }.last()
        val newParty  = serviceHub.identityService.partiesFromName(partyName,exactMatch = true).last()

        val session1 = initiateFlow(newParty)
        val a = ShareAccountInfoFlow(TestAccount, listOf(session1))



        return "sharing Done   ${a}"
    }

    @InitiatedBy(ShareAccountInfotoOtherParty::class)
       class ShareAccountInfoHandlerFlow(val otherSession: FlowSession) : FlowLogic<AccountInfo>() {
        @Suspendable
        override fun call(): AccountInfo {
            val transaction = subFlow(ReceiveTransactionFlow(
                    otherSideSession = otherSession,
                    statesToRecord = StatesToRecord.ALL_VISIBLE
            ))
            return transaction.coreTransaction.outputsOfType(AccountInfo::class.java).single()
        }
    }
}

The flow is not throwing any error but the table of receiver Node(Accounts Table) is not getting any update.

Upvotes: 0

Views: 259

Answers (1)

Adel Rustum
Adel Rustum

Reputation: 2548

  • You are using the inline version of the flow (i.e. the pair ShareAccountInfoFlow and ShareAccountInfoHandlerFlow). Instead, use the initiating version (i.e. ShareAccountInfo) which doesn't require having a responder flow.
  • You only use the inline version if your flow is a pair (initiator and responder) where you require some action/validation in the responder (i.e. node receiving the account info) before it actually receives it (i.e. before it calls the library's ShareAccountInfoHandlerFlow).
  • See some examples in the ShareAccountInfo flow tests: https://github.com/corda/accounts/blob/master/workflows/src/test/kotlin/com/r3/corda/lib/accounts/workflows/test/ShareAccountFlowTests.kt

Upvotes: 1

Related Questions