Skip to content

Instantly share code, notes, and snippets.

@ashutoshmeher-r3
Created October 25, 2021 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashutoshmeher-r3/d2e93dca43fed362b379dad57c307402 to your computer and use it in GitHub Desktop.
Save ashutoshmeher-r3/d2e93dca43fed362b379dad57c307402 to your computer and use it in GitHub Desktop.
@InitiatingFlow
@StartableByRPC
public class TransferLandTitleFlow implements Flow<SignedTransactionDigest> {
// Constructor
@CordaInject
private PersistenceService persistenceService;
// Inject other services
@Suspendable
public SignedTransactionDigest call() {
// Fetch the parameters passed to the flow.
//Query the landState
Map <String, Object> namedParameters = new LinkedHashMap<>();
namedParameters.put("stateStatus", StateStatus.UNCONSUMED);
Cursor<StateAndRef<LandTitleState>> cursor = persistenceService.query(
"VaultState.findByStateStatus",
namedParameters,
new SetBasedVaultQueryFilter.Builder()
.withContractStateClassNames(Set.of(LandTitleState.class.getName()))
.build(),
"Corda.IdentityStateAndRefPostProcessor"
);
List<StateAndRef<LandTitleState>> inputLandStateStateAndRefList =
cursor.poll(100, Duration.ofSeconds(20)).getValues();
// Filter the states to find the state in question
StateAndRef<LandTitleState> inputLandStateStateAndRef =
inputLandStateStateAndRefList.stream().filter(stateAndRef -> {
LandTitleState landTitleState = stateAndRef.getState().getData();
return landTitleState.getPlotNumber().equals(plotNumber);
}).findAny().orElseThrow(() -> new FlowException("Land Not Found"));
// Build, Verify, Collect Signature and Commit Transaction.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment