Skip to content

Instantly share code, notes, and snippets.

@anixon604
Last active July 30, 2020 15:03
Show Gist options
  • Save anixon604/97e35e4b0ce3b98398915574ebdd226b to your computer and use it in GitHub Desktop.
Save anixon604/97e35e4b0ce3b98398915574ebdd226b to your computer and use it in GitHub Desktop.
A Corda contract demonstrating business process for issuance and sale of medical drug (multi-regulatory).
// For simplicity, batches will be sold in whole
private void verifySale(LedgerTransaction tx, CommandWithParties<DrugContract.DrugCommands> command) {
requireThat(require -> {
require.using("Drug sale should consume one input statet",
tx.getInputs().size() == 1);
require.using("Drug sale should have one output state",
tx.getOutputs().size() == 1);
Drug in = tx.inputsOfType(Drug.class).get(0);
Drug out = tx.outputsOfType(Drug.class).get(0);
require.using("Output and input properties should match except/ new owner",
in.equals(out)); // .equals() override (-owner) in State class
require.using("Only the Manufacturer can be a seller",
in.getManufacturer().equals(in.getOwner()));
// STAGE 2 <================
// We have two dimensions (manufacturer and owner)
// Region.getValue returns enum region defined by the boundaries of the Country attrib in
// the CordaX500Name
Region manRegion = Region.getValue(out.getManufacturer().getName());
Region ownerRegion = Region.getValue(out.getOwner().getName());
Set<Region> regions = new HashSet<Region>(Arrays.asList(manRegion, ownerRegion));
// Run all applicable regional constraints
regionalSalesChecks(regions);
// STAGE 3
require.using("Manufacturer must sign",
command.getSigners().contains(out.getManufacturer().getOwningKey()));
require.using("Purchaser must sign",
command.getSigners().contains(out.getOwner().getOwningKey()));
return null;
});
}
private void regionalSalesChecks(Set<Region> r) {
if (r.contains(Region.EU)) {
// EU specific constraints
}
if (r.contains(Region.NA)) {
// NA specific constraints
}
if (r.contains(Region.APAC)) {
// APAC specific constraints
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment