<liclass="toctree-l1"><aclass="reference internal"href="oracles.html#implementing-an-oracle-with-continuously-varying-data">Implementing an oracle with continuously varying data</a></li>
<liclass="toctree-l1"><aclass="reference internal"href="oracles.html#using-an-oracle">Using an oracle</a></li>
<liclass="toctree-l1"><aclass="reference internal"href="setting-up-a-corda-network.html">Introduction - What is a corda network?</a></li>
<liclass="toctree-l1"><aclass="reference internal"href="setting-up-a-corda-network.html#setting-up-your-own-network">Setting up your own network</a></li>
<h1>Clauses key concepts<aclass="headerlink"href="#clauses-key-concepts"title="Permalink to this headline">¶</a></h1>
<divclass="section"id="basic-clause-structure">
<h2>Basic clause structure<aclass="headerlink"href="#basic-clause-structure"title="Permalink to this headline">¶</a></h2>
<p>A clause is a small building block for assembling contract verification logic, reusable and ready to test in separation.
To see clauses in action go to: <aclass="reference internal"href="tutorial-contract-clauses.html"><spanclass="doc">Writing a contract using clauses</span></a>.
Let’s take a look at a simplified structure of the <codeclass="docutils literal"><spanclass="pre">Clause</span></code> class:</p>
<p>Basic clause structure contains two important components: <codeclass="docutils literal"><spanclass="pre">requiredCommands</span></code> and <codeclass="docutils literal"><spanclass="pre">verify</span></code> function.
A clause is triggered when all <codeclass="docutils literal"><spanclass="pre">requiredCommands</span></code> are present in transaction’s command set (opposite inclusion doesn’t have to hold).
Then the <codeclass="docutils literal"><spanclass="pre">verify</span></code> function is run, which checks if transaction meets conditions specified by this clause. Verification
is no different than normal contract verification but using clauses it’s split into smaller generic code blocks with single verify method.</p>
<p>When writing a contract you need to override the contract’s <codeclass="docutils literal"><spanclass="pre">verify</span></code> function which should call <codeclass="docutils literal"><spanclass="pre">verifyClause</span></code>. See: <aclass="reference internal"href="tutorial-contract-clauses.html#verify-ref"><spanclass="std std-ref">Commercial paper class</span></a>.</p>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<pclass="last">A clause <codeclass="docutils literal"><spanclass="pre">verify</span></code> function returns the set of processed commands, at the end of <codeclass="docutils literal"><spanclass="pre">verifyClause</span></code> execution
there is a check if all of transaction’s commands were matched. If not then an exception is raised. This is done to
enforce that spurious commands cannot be included in a transaction, ensuring that the transaction is as clear as
possible. As an example imagine a transaction with two commands: <codeclass="docutils literal"><spanclass="pre">Move</span></code> and <codeclass="docutils literal"><spanclass="pre">Issue</span></code> included, with verification written
using <codeclass="docutils literal"><spanclass="pre">FirstComposition</span></code> on clauses that require single command set. Thus only one of transaction’s commands will match
leaving the second unprocessed. It should raise an error - we want to ensure that commands set is minimal to simplify
analysis of intent of a transaction.</p>
</div>
<p>An example <codeclass="docutils literal"><spanclass="pre">verify</span></code> from <codeclass="docutils literal"><spanclass="pre">Obligation</span></code> contract:</p>
<p>It takes transaction to be verified, and passes it along with a top-level clause and commands to the <codeclass="docutils literal"><spanclass="pre">verifyClause</span></code>
function. As you can see above we have used <codeclass="docutils literal"><spanclass="pre">FirstComposition</span></code> which is a special type of clause, which extends the
<codeclass="docutils literal"><spanclass="pre">CompositeClause</span></code> abstract class (in that particular case, it ensures that either <codeclass="docutils literal"><spanclass="pre">Net</span></code> or <codeclass="docutils literal"><spanclass="pre">Group</span></code> will run - for explanation see <aclass="reference internal"href="#firstcomposition">FirstComposition</a>).
It’s a type of clause that adds support for encapsulating multiple clauses and defines common behaviour for that composition.
There is also a <codeclass="docutils literal"><spanclass="pre">GroupClauseVerifier</span></code> special clause, which specifies how to group transaction input/output states
together and passes them to adequate clause for further processing.</p>
</div>
<divclass="section"id="composition-clauses">
<h2>Composition clauses<aclass="headerlink"href="#composition-clauses"title="Permalink to this headline">¶</a></h2>
<p>One of the most important concepts of clauses - composition clauses which extend <codeclass="docutils literal"><spanclass="pre">CompositeClause</span></code> abstract class,
providing a range of ways of assembling clauses together. They define a logic of verification execution specifying which clauses
will be run.</p>
<divclass="section"id="allcomposition">
<h3>AllComposition<aclass="headerlink"href="#allcomposition"title="Permalink to this headline">¶</a></h3>
<p><strong>Description</strong></p>
<p>Composes a number of clauses, such that all of the clauses must run for verification to pass.</p>
<li>Check if all clauses that compose <codeclass="docutils literal"><spanclass="pre">AllComposition</span></code> have associated commands in a command set - if not, verification fails.</li>
<li>After successful check runs verification logic specific for every clause <em>Cl1,..,Cl5</em> from that composition.</li>
</ul>
<p><strong>Usage</strong></p>
<p>See code in <aclass="reference internal"href="#groupclauseverifier">GroupClauseVerifier</a>.</p>
</div>
<divclass="section"id="anycomposition">
<h3>AnyComposition<aclass="headerlink"href="#anycomposition"title="Permalink to this headline">¶</a></h3>
<p><strong>Description</strong></p>
<p>Composes a number of clauses, such that 0 or more of the clauses can be run.</p>
<li>Takes first clause that matches and if none found throws an exception.</li>
<li>If successful runs verification on the clause that matched (in this case <em>Cl4</em>).</li>
</ul>
<p><strong>Usage</strong></p>
<p>See code in <aclass="reference internal"href="#groupclauseverifier">GroupClauseVerifier</a>.</p>
</div>
</div>
<divclass="section"id="other-types-of-clauses">
<h2>Other types of clauses<aclass="headerlink"href="#other-types-of-clauses"title="Permalink to this headline">¶</a></h2>
<p>There are certain types of clauses that are specialized in particular types of contracts (like <codeclass="docutils literal"><spanclass="pre">AbstractIssue</span></code>) or generally
should be used as helpers in building parts of logic (the most important one is <codeclass="docutils literal"><spanclass="pre">GroupClauseVerifier</span></code>).</p>
<divclass="section"id="groupclauseverifier">
<h3>GroupClauseVerifier<aclass="headerlink"href="#groupclauseverifier"title="Permalink to this headline">¶</a></h3>
<p><strong>Description</strong></p>
<p>Groups input and output states according to <codeclass="docutils literal"><spanclass="pre">groupStates</span></code> function. Runs the top-level clause verification on each
<p><codeclass="docutils literal"><spanclass="pre">GroupClauseVerifier</span></code> wraps clause <em>Cl1</em>. After grouping relevant states together with <codeclass="docutils literal"><spanclass="pre">groupStates</span></code> into three groups
<p>For more detailed example head to <aclass="reference internal"href="tutorial-contract.html#state-ref"><spanclass="std std-ref">Using state groups</span></a>.</p>
<p><strong>Usage</strong></p>
<p>You need to extend <codeclass="docutils literal"><spanclass="pre">GroupClauseVerifier</span></code> clause and define <codeclass="docutils literal"><spanclass="pre">groupStates</span></code> function which takes transaction and returns
grouped input and output states with a grouping key used for each group. Example from <codeclass="docutils literal"><spanclass="pre">Obligation.kt</span></code> contract:</p>
<p>Usually it’s convenient to use <codeclass="docutils literal"><spanclass="pre">groupStates</span></code> function defined on <codeclass="docutils literal"><spanclass="pre">TransactionForContract</span></code> class. Which given a type and a
selector function, that returns a grouping key, associates inputs and outputs together so that they can be processed as one.
The grouping key is any arbitrary object that can act as a map key (so must implement equals and hashCode).</p>
</div>
<divclass="section"id="abstractconserveamount">
<h3>AbstractConserveAmount<aclass="headerlink"href="#abstractconserveamount"title="Permalink to this headline">¶</a></h3>
<p><strong>Description</strong></p>
<p>Standardised clause for checking input/output balances of fungible assets. Requires that a
Move command is provided, and errors if absent. Conserve amount clause can only be used on grouped states.</p>
<p>Takes <codeclass="docutils literal"><spanclass="pre">filterStates</span></code> function that limits states passed to <codeclass="docutils literal"><spanclass="pre">clause</span></code> verification.</p>
Built with <ahref="http://sphinx-doc.org/">Sphinx</a> using a <ahref="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <ahref="https://readthedocs.org">Read the Docs</a>.