Skip to content

Instantly share code, notes, and snippets.

@akegaviar
Created August 17, 2020 07:23
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 akegaviar/bfc6b5a05a010d169a117439479f5714 to your computer and use it in GitHub Desktop.
Save akegaviar/bfc6b5a05a010d169a117439479f5714 to your computer and use it in GitHub Desktop.
package com.helloBlock.contracts;
import net.corda.core.contracts.CommandData;
import net.corda.core.contracts.CommandWithParties;
import net.corda.core.contracts.Contract;
import net.corda.core.contracts.TypeOnlyCommandData;
import net.corda.core.transactions.LedgerTransaction;
import com.helloBlock.states.helloBlockState;
import org.jetbrains.annotations.NotNull;
import static net.corda.core.contracts.ContractsDSL.requireSingleCommand;
import static net.corda.core.contracts.ContractsDSL.requireThat;
// ************
// * Contract *
// ************
// Contract and state.
public class helloBlockContract implements Contract {
// Used to identify our contract when building a transaction.
public static final String ID = "com.helloBlock.contracts.helloBlockContract";
// Contract code.
@Override
public void verify(@NotNull LedgerTransaction tx) throws IllegalArgumentException {
final CommandWithParties<Commands.Send> command = requireSingleCommand(tx.getCommands(), Commands.Send.class);
requireThat(require -> {
final helloBlockState helloBlock = tx.outputsOfType(helloBlockState.class).get(0);
require.using("Sender must sign the message.", helloBlock.getOrigin().getOwningKey().equals(command.getSigners().get(0)));
return null;
});
}
// Used to indicate the transaction's intent.
public interface Commands extends CommandData {
class Send extends TypeOnlyCommandData {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment