Setup:
- Corda 4.6
- Testing with MockNodes
Scenario:
I am building atomic swaps where I exchange FungibleToken’s that point to an EvolvableTokenType for FungibleToken’s representing USD. In the past I have always used SendTransactionFlow()/ReceiveTransactionFlow() like this:
SignedTransaction stx = subFlow(new ReceiveTransactionFlow(otherSideSession, true, StatesToRecord.ALL_VISIBLE));
It works great because it saves all the states to the vault on the receiver’s node – including the reference states (i.e. the EvolvableTokenType that the FungibleToken’s points to) . However in this stackoverflow answer Mike Hearn mentioned:
“You may also use SendStateAndRefFlow, which will reduce the amount of migration work involved in supporting SGX ledger encryption in future.”
So I am trying to switch to SendStateAndRefFlow()/ReceiveStateAndRefFlow().
Problem:
I cannot force the states to save in the vault using ReceiveStateAndRefFlow(). Only the transaction chain is stored in transaction storage.
When I try to add the FungibleToken’s that point to an EvolvableTokenType to the TransactionBuilder on the receiver’s node (the node constructing the swap):
List<StateAndRef<FungibleToken>> inputs = subFlow(new ReceiveStateAndRefFlow<>(otherSideSession));
txBuilder.addInputState(inputs.get(0));
… I will get an error:
java.lang.IllegalStateException: The LinearState with ID 598e1d3e-3b89-428c-b343-21c54a066856 is unknown to this node or it has been exited from the ledger.
The UUID the error refers to is the LinearId of the EvolvableTokenType the FungibleToken’s are pointing to.
Questions:
Are Mike’s comments still valid? Should I avoid using SendTransactionFlow/ReceiveTransactionFlow because SGX will break its functionality?
How can I send and save the EvolvableTokenType the FungibleToken’s point to so the state is available to the TransactionBuilder?