Skip to content

Instantly share code, notes, and snippets.

View anixon604's full-sized avatar

Alch3mist anixon604

View GitHub Profile
@anixon604
anixon604 / compliantDrugContract
Last active July 30, 2020 15:03
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);
@anixon604
anixon604 / simpleDrugContract
Last active July 30, 2020 16:19
A Corda contract demonstrating business process for issuance and sale of medical drug.
public void verify(@NotNull LedgerTransaction tx) throws IllegalArgumentException {
CommandWithParties<DrugCommands> command = requireSingleCommand(tx.getCommands(), DrugCommands.class);
DrugCommands commandType = command.getValue();
if (commandType instanceof DrugCommands.IssueDrug) {
verifyIssuance(tx, command);
} else if (commandType instanceof DrugCommands.SellDrug) {
verifySale(tx, command);
} else {
throw new IllegalArgumentException("Command not recognized");