203 lines
14 KiB
HTML
203 lines
14 KiB
HTML
<!DOCTYPE html>
|
||
<html class="writer-html5" lang="en" >
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
<title>API — Plugeth Austin Roberts documentation</title><link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
|
||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||
<!--[if lt IE 9]>
|
||
<script src="_static/js/html5shiv.min.js"></script>
|
||
<![endif]-->
|
||
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
|
||
<script src="_static/jquery.js"></script>
|
||
<script src="_static/underscore.js"></script>
|
||
<script src="_static/doctools.js"></script>
|
||
<script src="_static/js/theme.js"></script>
|
||
<link rel="index" title="Index" href="genindex.html" />
|
||
<link rel="search" title="Search" href="search.html" />
|
||
<link rel="next" title="Plugin Loader" href="plugin_loader.html" />
|
||
<link rel="prev" title="Version" href="version.html" />
|
||
</head>
|
||
|
||
<body class="wy-body-for-nav">
|
||
<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"> Plugeth
|
||
</a>
|
||
<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>
|
||
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
|
||
<p class="caption"><span class="caption-text">Overview</span></p>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="project.html">Project Design</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="types.html">Basic Types of Plugins</a></li>
|
||
</ul>
|
||
<p class="caption"><span class="caption-text">Tutorials</span></p>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="install.html">Install</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="build.html">Build and Deploy</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="custom.html">Building a Custom Plugin</a></li>
|
||
</ul>
|
||
<p class="caption"><span class="caption-text">Reference</span></p>
|
||
<ul class="current">
|
||
<li class="toctree-l1"><a class="reference internal" href="system_req.html">System Requirements</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="version.html">Version</a></li>
|
||
<li class="toctree-l1 current"><a class="current reference internal" href="#">API</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="#flags">Flags</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="#subcommands">Subcommands</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="#initialize">Initialize</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="#initializenode">InitializeNode</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="#getapis">GetAPIs</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="plugin_loader.html">Plugin Loader</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="hooks.html">Selected Plugin Hooks</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="hook_writing.html">Hook Writing Guide</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="core_restricted.html">Core vs Restricted packages in Plugeth-utils</a></li>
|
||
</ul>
|
||
<p class="caption"><span class="caption-text">Contact</span></p>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="contact.html">Get in touch with us</a></li>
|
||
</ul>
|
||
|
||
</div>
|
||
</div>
|
||
</nav>
|
||
|
||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
|
||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
||
<a href="index.html">Plugeth</a>
|
||
</nav>
|
||
|
||
<div class="wy-nav-content">
|
||
<div class="rst-content">
|
||
<div role="navigation" aria-label="Page navigation">
|
||
<ul class="wy-breadcrumbs">
|
||
<li><a href="index.html" class="icon icon-home"></a> »</li>
|
||
<li>API</li>
|
||
<li class="wy-breadcrumbs-aside">
|
||
<a href="_sources/api.rst.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="api">
|
||
<span id="id1"></span><h1>API<a class="headerlink" href="#api" title="Permalink to this headline">¶</a></h1>
|
||
<p>Plugins for Plugeth use Golang’s <a class="reference external" href="https://pkg.go.dev/plugin">Native Plugin System</a>. Plugin modules must export variables using specific names and types. These will be processed by the plugin loader, and invoked at certain points during Geth’s operations.</p>
|
||
<div class="section" id="flags">
|
||
<h2>Flags<a class="headerlink" href="#flags" title="Permalink to this headline">¶</a></h2>
|
||
<ul class="simple">
|
||
<li><p><strong>Name:</strong> Flags</p></li>
|
||
<li><p><strong>Type:</strong> <a class="reference external" href="https://pkg.go.dev/flag#FlagSet">flag.FlagSet</a></p></li>
|
||
<li><p><strong>Behavior:</strong> This FlagSet will be parsed and your plugin will be able to access the resulting flags. Flags will be passed to Geth from the command line and are intended to of the plugin. Note that if any flags are provided, certain checks are disabled within Geth to avoid failing due to unexpected flags.</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="subcommands">
|
||
<h2>Subcommands<a class="headerlink" href="#subcommands" title="Permalink to this headline">¶</a></h2>
|
||
<ul class="simple">
|
||
<li><p><strong>Name:</strong> Subcommands</p></li>
|
||
<li><p><strong>Type:</strong> map[string]func(ctx <a class="reference external" href="https://pkg.go.dev/github.com/urfave/cli#Context">*cli.Context</a>, args []string) error</p></li>
|
||
<li><p><strong>Behavior:</strong> If Geth is invoked with <code class="docutils literal notranslate"><span class="pre">./geth</span> <span class="pre">YOUR_COMMAND</span></code>, the plugin loader will look for <code class="docutils literal notranslate"><span class="pre">YOUR_COMMAND</span></code> within this map, and invoke the corresponding function. This can be useful for certain behaviors like manipulating Geth’s database without having to build a separate binary.</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="initialize">
|
||
<h2>Initialize<a class="headerlink" href="#initialize" title="Permalink to this headline">¶</a></h2>
|
||
<ul class="simple">
|
||
<li><p><strong>Name:</strong> Initialize</p></li>
|
||
<li><p><strong>Type:</strong> func(<a href="#id2"><span class="problematic" id="id3">*</span></a>cli.Context, core.PluginLoader, core.logs )</p></li>
|
||
<li><p><strong>Behavior:</strong> Called as soon as the plugin is loaded, with the cli context and a reference to the plugin loader. This is your plugin’s opportunity to initialize required variables as needed. Note that using the context object you can check arguments, and optionally can manipulate arguments if needed for your plugin.</p></li>
|
||
</ul>
|
||
<div class="admonition-todo admonition" id="id4">
|
||
<p class="admonition-title">Todo</p>
|
||
<p>explain that plugin could provide node.Node with
|
||
restricted.backend</p>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="initializenode">
|
||
<h2>InitializeNode<a class="headerlink" href="#initializenode" title="Permalink to this headline">¶</a></h2>
|
||
<ul class="simple">
|
||
<li><p><strong>Name:</strong> InitializeNode</p></li>
|
||
<li><p><strong>Type:</strong> func(core.Node, core.Backend)</p></li>
|
||
<li><p><strong>Behavior:</strong> This is called as soon as the Geth node is initialized. The core.Node object represents the running node with p2p and RPC capabilities, while the Backend gives you access to a wide array of data you may need to access.</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="getapis">
|
||
<h2>GetAPIs<a class="headerlink" href="#getapis" title="Permalink to this headline">¶</a></h2>
|
||
<ul class="simple">
|
||
<li><p><strong>Name:</strong> GetAPIs</p></li>
|
||
<li><p><strong>Type:</strong> func(core.Node, core.Backend) []rpc.API</p></li>
|
||
<li><p><strong>Behavior:</strong> This allows you to register new RPC methods to run within Geth.</p></li>
|
||
</ul>
|
||
<p>The GetAPIs function itself will generally be fairly brief, and will looks something like this:</p>
|
||
<div class="highlight-go notranslate"><div class="highlight"><pre><span></span> <span class="s">``</span><span class="kd">func</span> <span class="nx">GetAPIs</span><span class="p">(</span><span class="nx">stack</span> <span class="o">*</span><span class="nx">node</span><span class="p">.</span><span class="nx">Node</span><span class="p">,</span> <span class="nx">backend</span> <span class="nx">core</span><span class="p">.</span><span class="nx">Backend</span><span class="p">)</span> <span class="p">[]</span><span class="nx">core</span><span class="p">.</span><span class="nx">API</span> <span class="p">{</span>
|
||
<span class="k">return</span> <span class="p">[]</span><span class="nx">rpc</span><span class="p">.</span><span class="nx">API</span><span class="p">{</span>
|
||
<span class="p">{</span>
|
||
<span class="nx">Namespace</span><span class="p">:</span> <span class="s">"mynamespace"</span><span class="p">,</span>
|
||
<span class="nx">Version</span><span class="p">:</span> <span class="s">"1.0"</span><span class="p">,</span>
|
||
<span class="nx">Service</span><span class="p">:</span> <span class="o">&</span><span class="nx">MyService</span><span class="p">{</span><span class="nx">backend</span><span class="p">},</span>
|
||
<span class="nx">Public</span><span class="p">:</span> <span class="kc">true</span><span class="p">,</span>
|
||
<span class="p">},</span>
|
||
<span class="p">}</span>
|
||
<span class="p">}</span><span class="s">``</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>The bulk of the implementation will be in the <code class="docutils literal notranslate"><span class="pre">MyService</span></code> struct. MyService should be a struct with public functions. These functions can have two different types of signatures:</p>
|
||
<ul class="simple">
|
||
<li><p>RPC Calls: For straight RPC calls, a function should have a <code class="docutils literal notranslate"><span class="pre">context.Context</span></code> object as the first argument, followed by an arbitrary number of JSON marshallable arguments, and return either a single JSON marshal object, or a JSON marshallable object and an error. The RPC framework will take care of decoding inputs to this function and encoding outputs, and if the error is non-nil it will serve an error response.</p></li>
|
||
<li><p>Subscriptions: For subscriptions (supported on IPC and websockets), a function should have a <code class="docutils literal notranslate"><span class="pre">context.Context</span></code> object as the first argument followed by an arbitrary number of JSON marshallable arguments, and should return an <code class="docutils literal notranslate"><span class="pre">*rpc.Subscription</span></code> object. The subscription object can be created with <code class="docutils literal notranslate"><span class="pre">rpcSub</span> <span class="pre">:=</span> <span class="pre">notifier.CreateSubscription()</span></code>, and JSON marshallable data can be sent to the subscriber with <code class="docutils literal notranslate"><span class="pre">notifier.Notify(rpcSub.ID,</span> <span class="pre">b)</span></code>.</p></li>
|
||
</ul>
|
||
<p>A very simple MyService might look like:</p>
|
||
<div class="highlight-go notranslate"><div class="highlight"><pre><span></span><span class="s">``</span><span class="kd">type</span> <span class="nx">MyService</span> <span class="kd">struct</span><span class="p">{}</span>
|
||
|
||
<span class="kd">func</span> <span class="p">(</span><span class="nx">h</span> <span class="nx">MyService</span><span class="p">)</span> <span class="nx">HelloWorld</span><span class="p">(</span><span class="nx">ctx</span> <span class="nx">context</span><span class="p">.</span><span class="nx">Context</span><span class="p">)</span> <span class="kt">string</span> <span class="p">{</span>
|
||
<span class="k">return</span> <span class="s">"Hello World"</span>
|
||
<span class="p">}</span><span class="s">``</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>And the client could access this with an rpc call to
|
||
<code class="docutils literal notranslate"><span class="pre">mynamespace_helloworld</span></code></p>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
|
||
<a href="version.html" class="btn btn-neutral float-left" title="Version" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
|
||
<a href="plugin_loader.html" class="btn btn-neutral float-right" title="Plugin Loader" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
|
||
</div>
|
||
|
||
<hr/>
|
||
|
||
<div role="contentinfo">
|
||
<p>© Copyright 2021, Philip Morlier.</p>
|
||
</div>
|
||
|
||
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
|
||
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
|
||
provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
||
|
||
|
||
</footer>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
<script>
|
||
jQuery(function () {
|
||
SphinxRtdTheme.Navigation.enable(true);
|
||
});
|
||
</script>
|
||
|
||
</body>
|
||
</html> |