Created
August 17, 2020 07:23
-
-
Save akegaviar/bfc6b5a05a010d169a117439479f5714 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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