Last active
July 17, 2019 17:19
-
-
Save snedamle/2206d4b87569c094e16d4e1e9e950c02 to your computer and use it in GitHub Desktop.
MoveEvolvableTokenFlow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Call built in MoveNonFungibleTokens to move token to other party. | |
*/ | |
@StartableByRPC | |
public static class MoveEvolvableTokenFlow extends FlowLogic<SignedTransaction>{ | |
private final String evolvableTokenId; | |
private final Party recipient; | |
public MoveEvolvableTokenFlow(String evolvableTokenId, Party recipient) { | |
this.evolvableTokenId = evolvableTokenId; | |
this.recipient = recipient; | |
} | |
@Override | |
@Suspendable | |
public SignedTransaction call() throws FlowException { | |
// uuid column in vault_linear_states contains the uuid of the created asset on ledger | |
UUID uuid = UUID.fromString(evolvableTokenId); | |
// construct queryCriteria to get the created asset on ledger by using LinearStateCriteria | |
// get all the unconsumed states from vault_linear_states having uuid | |
QueryCriteria queryCriteria = new QueryCriteria.LinearStateQueryCriteria(null, ImmutableList.of(uuid), null, | |
Vault.StateStatus.UNCONSUMED, null); | |
// use vaultservice to hit the vault using the query criteria | |
StateAndRef<RealEstateEvolvableTokenType> stateAndRef = getServiceHub().getVaultService(). | |
queryBy(RealEstateEvolvableTokenType.class, queryCriteria).getStates().get(0); | |
// get the state from StateAndRef returned by the query | |
RealEstateEvolvableTokenType evolvableTokenType = stateAndRef.getState().getData(); | |
LinearPointer linearPointer = new LinearPointer(evolvableTokenType.getLinearId(), RealEstateEvolvableTokenType.class); | |
// token pointer is a linear pointer to created real estate asset | |
TokenPointer token = new TokenPointer(linearPointer, evolvableTokenType.getFractionDigits()); | |
PartyAndToken partyAndToken = new PartyAndToken(recipient, token); | |
// specify which party (recipient) to move the token to | |
return (SignedTransaction) subFlow(new MoveNonFungibleTokens(partyAndToken)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment