Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RedeemHouseToken
/**
* 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
You can’t perform that action at this time.