Last active
July 17, 2019 17:23
-
-
Save snedamle/da6879c72d688952a2843465c668cc63 to your computer and use it in GitHub Desktop.
RedeemHouseToken
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
/** | |
* Redeem tokens by calling RedeemNonFungibleTokens Flow. | |
*/ | |
@StartableByRPC | |
public static class RedeemHouseToken extends FlowLogic<SignedTransaction> { | |
private final String evolvableTokenId; | |
private final Party issuer; | |
public RedeemHouseToken(String evolvableTokenId, Party issuer) { | |
this.evolvableTokenId = evolvableTokenId; | |
this.issuer = issuer; | |
} | |
@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()); | |
// redeem token by specifying the issuer | |
return (SignedTransaction) subFlow(new RedeemNonFungibleTokens(token, issuer)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment