corda/docs/build/html/creating-a-cordapp.html
2016-09-23 11:55:23 +02:00

324 lines
15 KiB
HTML

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Creating a Cordapp &mdash; R3 Corda latest documentation</title>
<link rel="stylesheet" href="_static/css/custom.css" type="text/css" />
<link rel="top" title="R3 Corda latest documentation" href="index.html"/>
<link rel="next" title="Running the demos" href="running-the-demos.html"/>
<link rel="prev" title="Networking and messaging" href="messaging.html"/>
<script src="_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="index.html" class="icon icon-home"> R3 Corda
</a>
<div class="version">
latest
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<br>
<a href="api/index.html">API reference</a>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Overview</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="inthebox.html">What&#8217;s included?</a></li>
<li class="toctree-l1"><a class="reference internal" href="getting-set-up.html">Getting set up</a></li>
<li class="toctree-l1"><a class="reference internal" href="data-model.html">Data model</a></li>
<li class="toctree-l1"><a class="reference internal" href="transaction-data-types.html">Data types</a></li>
<li class="toctree-l1"><a class="reference internal" href="consensus.html">Consensus model</a></li>
<li class="toctree-l1"><a class="reference internal" href="messaging.html">Networking and messaging</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Creating a Cordapp</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#app-plugins">App Plugins</a></li>
<li class="toctree-l2"><a class="reference internal" href="#services">Services</a></li>
<li class="toctree-l2"><a class="reference internal" href="#starting-nodes">Starting Nodes</a></li>
<li class="toctree-l2"><a class="reference internal" href="#installing-apps">Installing Apps</a></li>
<li class="toctree-l2"><a class="reference internal" href="#starting-your-node">Starting your Node</a></li>
<li class="toctree-l2"><a class="reference internal" href="#debugging-your-node">Debugging your Node</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="running-the-demos.html">Running the demos</a></li>
<li class="toctree-l1"><a class="reference internal" href="node-administration.html">Node administration</a></li>
<li class="toctree-l1"><a class="reference internal" href="corda-configuration-files.html">The Corda Configuration File</a></li>
</ul>
<p class="caption"><span class="caption-text">Tutorials</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="where-to-start.html">Where to start</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial-contract.html">Writing a contract</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial-contract-clauses.html">Writing a contract using clauses</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial-test-dsl.html">Writing a contract test</a></li>
<li class="toctree-l1"><a class="reference internal" href="protocol-state-machines.html">Protocol state machines</a></li>
<li class="toctree-l1"><a class="reference internal" href="oracles.html">Writing oracle services</a></li>
<li class="toctree-l1"><a class="reference internal" href="event-scheduling.html">Event scheduling</a></li>
<li class="toctree-l1"><a class="reference internal" href="secure-coding-guidelines.html">Secure coding guidelines</a></li>
<li class="toctree-l1"><a class="reference internal" href="secure-coding-guidelines.html#protocols">Protocols</a></li>
<li class="toctree-l1"><a class="reference internal" href="secure-coding-guidelines.html#contracts">Contracts</a></li>
</ul>
<p class="caption"><span class="caption-text">Contracts</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="contract-catalogue.html">Contract catalogue</a></li>
<li class="toctree-l1"><a class="reference internal" href="contract-irs.html">Interest Rate Swaps</a></li>
</ul>
<p class="caption"><span class="caption-text">Node API</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="clientrpc.html">Client RPC</a></li>
</ul>
<p class="caption"><span class="caption-text">Appendix</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="release-process.html">Release process</a></li>
<li class="toctree-l1"><a class="reference internal" href="release-process.html#steps-to-cut-a-release">Steps to cut a release</a></li>
<li class="toctree-l1"><a class="reference internal" href="release-notes.html">Release notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="network-simulator.html">Network Simulator</a></li>
<li class="toctree-l1"><a class="reference internal" href="codestyle.html">Code style guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="building-the-docs.html">Building the documentation</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">R3 Corda</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> &raquo;</li>
<li>Creating a Cordapp</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/creating-a-cordapp.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="creating-a-cordapp">
<h1>Creating a Cordapp<a class="headerlink" href="#creating-a-cordapp" title="Permalink to this headline"></a></h1>
<p>A Cordapp is an application that runs on the Corda platform using the platform APIs and plugin system. They are self
contained in separate JARs from the node server JAR that are created and distributed.</p>
<div class="section" id="app-plugins">
<h2>App Plugins<a class="headerlink" href="#app-plugins" title="Permalink to this headline"></a></h2>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Currently apps are only supported for JVM languages.</p>
</div>
<p>To create an app plugin you must you must extend from <a class="reference external" href="api/com.r3corda.core.node/-corda-plugin-registry/index.html">CordaPluginRegistry</a>. The JavaDoc contains
specific details of the implementation, but you can extend the server in the following ways:</p>
<ol class="arabic simple">
<li>Required protocols: Specify which protocols will be whitelisted for use in your web APIs.</li>
<li>Service plugins: Register your services (see below).</li>
<li>Web APIs: You may register your own endpoints under /api/ of the built-in web server.</li>
<li>Static web endpoints: You may register your own static serving directories for serving web content.</li>
</ol>
</div>
<div class="section" id="services">
<h2>Services<a class="headerlink" href="#services" title="Permalink to this headline"></a></h2>
<p>Services are classes which are constructed after the node has started. It is provided a <a class="reference external" href="api/com.r3corda.node.services.api/-service-hub-internal/index.html">ServiceHubInternal</a> which
allows a richer API than the <a class="reference external" href="api/com.r3corda.node.services.api/-service-hub/index.html">ServiceHub</a> exposed to contracts. It enables adding protocols, registering
message handlers and more. The service does not run in a separate thread, so the only entry point to the service is during
construction, where message handlers should be registered and threads started.</p>
</div>
<div class="section" id="starting-nodes">
<h2>Starting Nodes<a class="headerlink" href="#starting-nodes" title="Permalink to this headline"></a></h2>
<p>To use an app you must also have a node server. To create a node server run the gradle installTemplateNodes task.</p>
<p>This will output the node JAR to <code class="docutils literal"><span class="pre">build/libs/corda.jar</span></code> and several sample/standard
node setups to <code class="docutils literal"><span class="pre">build/nodes</span></code>. For now you can use the <code class="docutils literal"><span class="pre">build/nodes/nodea</span></code> configuration as a template.</p>
<p>Each node server by default must have a <code class="docutils literal"><span class="pre">node.conf</span></code> file in the current working directory. After first
execution of the node server there will be many other configuration and persistence files created in a node workspace directory. This is specified as the basedir property of the node.conf file, or else can be overidden using <code class="docutils literal"><span class="pre">--base-directory=&lt;workspace&gt;</span></code>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Outside of development environments do not store your node directories in the build folder.</p>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">Also note that the bootstrapping process of the <code class="docutils literal"><span class="pre">corda.jar</span></code> unpacks the Corda dependencies into a temporary folder. It is therefore suggested that the CAPSULE_CACHE_DIR environment variable be set before starting the process to control this location.</p>
</div>
</div>
<div class="section" id="installing-apps">
<h2>Installing Apps<a class="headerlink" href="#installing-apps" title="Permalink to this headline"></a></h2>
<p>Once you have created your app JAR you can install it to a node by adding it to <code class="docutils literal"><span class="pre">&lt;node_dir&gt;/plugins/</span></code>. In this
case the <code class="docutils literal"><span class="pre">node_dir</span></code> is the location where your node server&#8217;s JAR and configuration file is.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If the directory does not exist you can create it manually.</p>
</div>
</div>
<div class="section" id="starting-your-node">
<h2>Starting your Node<a class="headerlink" href="#starting-your-node" title="Permalink to this headline"></a></h2>
<p>Now you have a node server with your app installed, you can run it by navigating to <code class="docutils literal"><span class="pre">&lt;node_dir&gt;</span></code> and running</p>
<blockquote>
<div>java -jar corda.jar</div></blockquote>
<p>The plugin should automatically be registered and the configuration file used.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">If your working directory is not <code class="docutils literal"><span class="pre">&lt;node_dir&gt;</span></code> your plugins and configuration will not be used.</p>
</div>
<p>The configuration file and workspace paths can be overidden on the command line e.g.</p>
<p><code class="docutils literal"><span class="pre">java</span> <span class="pre">-jar</span> <span class="pre">corda.jar</span> <span class="pre">--config-file=test.conf</span> <span class="pre">--base-directory=/opt/r3corda/nodes/test</span></code>.</p>
<p>Otherwise the workspace folder for the node is created based upon the <code class="docutils literal"><span class="pre">basedir</span></code> property in the <code class="docutils literal"><span class="pre">node.conf</span></code> file and if this is relative it is applied relative to the current working path.</p>
</div>
<div class="section" id="debugging-your-node">
<h2>Debugging your Node<a class="headerlink" href="#debugging-your-node" title="Permalink to this headline"></a></h2>
<p>To enable remote debugging of the corda process use a command line such as:</p>
<p><code class="docutils literal"><span class="pre">java</span> <span class="pre">-Dcapsule.jvm.args=&quot;-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005&quot;</span> <span class="pre">-jar</span> <span class="pre">corda.jar</span></code></p>
<p>This command line will start the debugger on port 5005 and pause the process awaiting debugger attachment.</p>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="running-the-demos.html" class="btn btn-neutral float-right" title="Running the demos" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="messaging.html" class="btn btn-neutral" title="Networking and messaging" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2016, Distributed Ledger Group, LLC.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'./',
VERSION:'latest',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>