Search code examples
cordacorda-flow

Tokens SDK - What's the difference between inlined and initiating flows?


I'm following along the documentation about the Tokens SDK: https://github.com/corda/token-sdk/blob/master/docs/IWantTo.md#issuing-tokens

My question is fairy simple: what's the difference between using
IssueTokens(fungibleToken)
and
subFlow(IssueTokensFlow(fungibleToken, listOf(holderSession)))?

What implications does one have on the other? When should I use one or the other? I've read the documentation about flowss/subflows, but it's not clear what the difference is: https://docs.r3.com/en/platform/corda/4.9/community/api-flows.html#subflows


Solution

  • I suggest to always go read the source code in case of questions like this. Comments and unit tests are your best friends. Corda source code is very well documented, so you will always find what you are looking for.

    From the source code of each function you mentioned:

    IssueTokens : A flow for issuing fungible or non-fungible tokens which initiates its own participantSessions. This is the case when called from the node rpc or in a unit test. However, in the case where you already have a session with another [Party] and you wish to issue tokens as part of a wider workflow, then use [IssueTokensFlow].

    IssueTokensFlow : Use this flow to issue fungible or non-fungible tokens. It should be called as an in-line sub-flow, therefore you must have flow [participantSessions] set up prior to calling this flow. Tokens are usually constructed before calling this flow. This flow is to be used in conjunction with the [IssueTokensFlowHandler].

    So, the main difference is that IssueTokens does already some things for you and can run by itself, while IssueTokensFlow needs to be included in a flow that you write and needs inputs that you need to implement before calling it.