Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ contract&#39;s lifetime as &quot;fulfillment conditions&quot; for its closure.</
<dd></dd>
</dl>

## Functions

<dl>
<dt><a href="#appendLightningStderrChunk">appendLightningStderrChunk()</a></dt>
<dd><p>Node does not chunk stderr on line boundaries; buffer and emit per logical line.</p>
</dd>
</dl>

## Typedefs

<dl>
Expand Down Expand Up @@ -12830,6 +12838,12 @@ Join a list with an Oxford comma (delegates to [module:functions/oxfordJoin](mod
| --- | --- |
| list | <code>Array.&lt;string&gt;</code> |

<a name="appendLightningStderrChunk"></a>

## appendLightningStderrChunk()
Node does not chunk stderr on line boundaries; buffer and emit per logical line.

**Kind**: global function
<a name="BitcoinCookieProbeConstraints"></a>

## BitcoinCookieProbeConstraints : <code>Object</code>
Expand Down
606 changes: 301 additions & 305 deletions assets/examples/agents.html

Large diffs are not rendered by default.

35 changes: 23 additions & 12 deletions assets/examples/bitcoin.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,10 @@ <h1>bitcoin.js</h1>

<span class="hljs-keyword">const</span> <span class="hljs-title class_">Fabric</span> = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;../&#x27;</span>);
<span class="hljs-keyword">const</span> <span class="hljs-title class_">Bitcoin</span> = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;../services/bitcoin&#x27;</span>);
<span class="hljs-keyword">const</span> <span class="hljs-title class_">Wallet</span> = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;../types/wallet&#x27;</span>);

<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">main</span> () {
<span class="hljs-keyword">let</span> fabric = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Fabric</span>();
<span class="hljs-keyword">let</span> bitcoin = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Bitcoin</span>({ <span class="hljs-attr">network</span>: <span class="hljs-string">&#x27;regtest&#x27;</span> });</pre>
<span class="hljs-keyword">const</span> fabric = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Fabric</span>();
<span class="hljs-keyword">const</span> bitcoin = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Bitcoin</span>({ <span class="hljs-attr">network</span>: <span class="hljs-string">&#x27;regtest&#x27;</span> });</pre>
</div>
</div>

Expand All @@ -185,14 +184,13 @@ <h1>bitcoin.js</h1>
<div class="sswrap ">
<a class="ss" href="#section-2">&#x00a7;</a>
</div>
<p>let wallet = new Wallet();</p>
<p>Listen for messages from the Bitcoin service</p>

</div>

<div class="content">
<div class='highlight'>
<pre>
bitcoin.<span class="hljs-title function_">on</span>(<span class="hljs-string">&#x27;message&#x27;</span>, <span class="hljs-keyword">function</span> (<span class="hljs-params">msg</span>) {
<pre> bitcoin.<span class="hljs-title function_">on</span>(<span class="hljs-string">&#x27;message&#x27;</span>, <span class="hljs-keyword">function</span> (<span class="hljs-params">msg</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&#x27;[DEVELOP]&#x27;</span>, <span class="hljs-string">&#x27;Bitcoin emitted message:&#x27;</span>, msg);
});</pre>
</div>
Expand All @@ -207,13 +205,13 @@ <h1>bitcoin.js</h1>
<div class="sswrap ">
<a class="ss" href="#section-3">&#x00a7;</a>
</div>
<p>fabric.use(bitcoin);</p>
<p>Use the Bitcoin service in the Fabric instance</p>

</div>

<div class="content">
<div class='highlight'>
<pre> <span class="hljs-keyword">await</span> bitcoin.<span class="hljs-title function_">start</span>();</pre>
<pre> fabric.<span class="hljs-title function_">use</span>(bitcoin);</pre>
</div>
</div>

Expand All @@ -226,10 +224,16 @@ <h1>bitcoin.js</h1>
<div class="sswrap ">
<a class="ss" href="#section-4">&#x00a7;</a>
</div>
<p>await wallet.start();</p>
<p>Start the Bitcoin service</p>

</div>

<div class="content">
<div class='highlight'>
<pre> <span class="hljs-keyword">await</span> bitcoin.<span class="hljs-title function_">start</span>();</pre>
</div>
</div>

</li>


Expand Down Expand Up @@ -278,9 +282,16 @@ <h1>bitcoin.js</h1>

<div class="content">
<div class='highlight'>
<pre>}

<span class="hljs-variable language_">module</span>.<span class="hljs-property">exports</span> = <span class="hljs-title function_">main</span>();</pre>
<pre>
<span class="hljs-keyword">await</span> bitcoin.<span class="hljs-title function_">stop</span>();
}

<span class="hljs-keyword">if</span> (<span class="hljs-built_in">require</span>.<span class="hljs-property">main</span> === <span class="hljs-variable language_">module</span>) {
<span class="hljs-title function_">main</span>().<span class="hljs-title function_">catch</span>(<span class="hljs-function">(<span class="hljs-params">exception</span>) =&gt;</span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">&#x27;[EXAMPLES:BITCOIN]&#x27;</span>, <span class="hljs-string">&#x27;Main Process Exception:&#x27;</span>, exception);
process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
});
}</pre>
</div>
</div>

Expand Down
10 changes: 5 additions & 5 deletions assets/examples/chain.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,19 @@ <h1>chain.js</h1>
<span class="hljs-keyword">const</span> chain = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Chain</span>();

<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">main</span> () {
<span class="hljs-keyword">await</span> chain.<span class="hljs-property">storage</span>.<span class="hljs-title function_">open</span>();
<span class="hljs-keyword">await</span> chain.<span class="hljs-title function_">start</span>();

chain.<span class="hljs-title function_">on</span>(<span class="hljs-string">&#x27;block&#x27;</span>, <span class="hljs-keyword">function</span> (<span class="hljs-params">block</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&#x27;[CHAIN]&#x27;</span>, <span class="hljs-string">&#x27;new block:&#x27;</span>, block);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&#x27;[CHAIN]&#x27;</span>, <span class="hljs-string">&#x27;chain:&#x27;</span>, chain);
});

chain.<span class="hljs-title function_">append</span>({ <span class="hljs-attr">test</span>: <span class="hljs-string">&#x27;foo&#x27;</span> });
chain.<span class="hljs-title function_">append</span>({ <span class="hljs-attr">test</span>: <span class="hljs-string">&#x27;bar&#x27;</span> });
<span class="hljs-keyword">await</span> chain.<span class="hljs-title function_">append</span>({ <span class="hljs-attr">test</span>: <span class="hljs-string">&#x27;foo&#x27;</span> });
<span class="hljs-keyword">await</span> chain.<span class="hljs-title function_">append</span>({ <span class="hljs-attr">test</span>: <span class="hljs-string">&#x27;bar&#x27;</span> });

<span class="hljs-keyword">await</span> chain.<span class="hljs-property">storage</span>.<span class="hljs-title function_">close</span>();
<span class="hljs-keyword">await</span> chain.<span class="hljs-title function_">stop</span>();

<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>;
<span class="hljs-keyword">return</span> chain;
}

<span class="hljs-title function_">main</span>().<span class="hljs-title function_">catch</span>(<span class="hljs-function">(<span class="hljs-params">exception</span>) =&gt;</span> {
Expand Down
5 changes: 3 additions & 2 deletions assets/examples/fabric.html
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ <h1 id="getting-started-with-fabric">Getting Started with Fabric</h1>
<div class="content">
<div class='highlight'>
<pre><span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">main</span>(<span class="hljs-params"></span>) {
<span class="hljs-keyword">let</span> fabric = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Fabric</span>();
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&#x27;[EXAMPLE]&#x27;</span>, <span class="hljs-string">&#x27;Fabric:&#x27;</span>, fabric);
<span class="hljs-keyword">const</span> fabric = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Fabric</span>();
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&#x27;[EXAMPLE:FABRIC]&#x27;</span>, <span class="hljs-string">&#x27;id:&#x27;</span>, fabric.<span class="hljs-property">id</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&#x27;[EXAMPLE:FABRIC]&#x27;</span>, <span class="hljs-string">&#x27;clock:&#x27;</span>, fabric.<span class="hljs-property">clock</span>);
}</pre>
</div>
</div>
Expand Down
3 changes: 0 additions & 3 deletions assets/examples/game.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ <h1>game.js</h1>
});

game.<span class="hljs-title function_">use</span>(<span class="hljs-string">&#x27;spawn&#x27;</span>, <span class="hljs-keyword">function</span> (<span class="hljs-params">input</span>) {
<span class="hljs-keyword">var</span> self = <span class="hljs-variable language_">this</span>;
<span class="hljs-keyword">var</span> data = _.<span class="hljs-title function_">clone</span>(template);

data.<span class="hljs-property">id</span> = <span class="hljs-title class_">Math</span>.<span class="hljs-title function_">random</span>();
Expand Down Expand Up @@ -264,8 +263,6 @@ <h1>game.js</h1>
});

game.<span class="hljs-title function_">use</span>(<span class="hljs-string">&#x27;battle&#x27;</span>, <span class="hljs-keyword">function</span> (<span class="hljs-params">input</span>) {
<span class="hljs-keyword">var</span> self = <span class="hljs-variable language_">this</span>;

<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&#x27;battling...&#x27;</span>, input.<span class="hljs-property">spawns</span>);

input.<span class="hljs-property">spawns</span>[<span class="hljs-number">0</span>].<span class="hljs-property">stack</span>.<span class="hljs-title function_">push</span>(<span class="hljs-string">&#x27;attack&#x27;</span>);
Expand Down
62 changes: 33 additions & 29 deletions assets/examples/heartbeat.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ <h1>heartbeat.js</h1>

<div class="content">
<div class='highlight'>
<pre><span class="hljs-keyword">const</span> <span class="hljs-title class_">Peer</span> = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;../types/peer&#x27;</span>);
<pre><span class="hljs-keyword">const</span> { setMaxListeners } = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;events&#x27;</span>);
<span class="hljs-keyword">const</span> <span class="hljs-title class_">Peer</span> = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;../types/peer&#x27;</span>);
<span class="hljs-keyword">const</span> { <span class="hljs-title class_">Swarm</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;../types/peer&#x27;</span>);
<span class="hljs-keyword">const</span> <span class="hljs-title class_">Message</span> = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;../types/message&#x27;</span>);</pre>
</div>
Expand All @@ -206,7 +207,8 @@ <h1>heartbeat.js</h1>
<span class="hljs-attr">seeds</span>: [<span class="hljs-string">&#x27;localhost:7777&#x27;</span>]
};

<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">main</span> () {</pre>
<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">main</span> () {
<span class="hljs-title function_">setMaxListeners</span>(<span class="hljs-number">0</span>);</pre>
</div>
</div>

Expand Down Expand Up @@ -276,7 +278,24 @@ <h1>heartbeat.js</h1>

<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&#x27;[EXAMPLES:HEARTBEAT]&#x27;</span>, <span class="hljs-string">&#x27;Starting Swarm...&#x27;</span>);
<span class="hljs-keyword">await</span> swarm.<span class="hljs-title function_">start</span>();
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&#x27;[EXAMPLES:HEARTBEAT]&#x27;</span>, <span class="hljs-string">&#x27;Swarm started!&#x27;</span>);</pre>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&#x27;[EXAMPLES:HEARTBEAT]&#x27;</span>, <span class="hljs-string">&#x27;Swarm started!&#x27;</span>);

<span class="hljs-keyword">const</span> stopWithTimeout = <span class="hljs-keyword">async</span> (instance, label, timeoutMs = <span class="hljs-number">1200</span>) =&gt; {
<span class="hljs-keyword">if</span> (!instance || <span class="hljs-keyword">typeof</span> instance.<span class="hljs-property">stop</span> !== <span class="hljs-string">&#x27;function&#x27;</span>) <span class="hljs-keyword">return</span>;
<span class="hljs-keyword">try</span> {
<span class="hljs-keyword">await</span> <span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">race</span>([
instance.<span class="hljs-title function_">stop</span>(),
<span class="hljs-keyword">new</span> <span class="hljs-title class_">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve</span>) =&gt;</span> <span class="hljs-built_in">setTimeout</span>(resolve, timeoutMs))
]);
} <span class="hljs-keyword">catch</span> (error) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(<span class="hljs-string">&#x27;[EXAMPLES:HEARTBEAT]&#x27;</span>, <span class="hljs-string">`<span class="hljs-subst">${label}</span> stop warning:`</span>, error.<span class="hljs-property">message</span>);
}
};

<span class="hljs-keyword">const</span> shutdown = <span class="hljs-keyword">async</span> () =&gt; {
<span class="hljs-keyword">await</span> <span class="hljs-title function_">stopWithTimeout</span>(swarm, <span class="hljs-string">&#x27;Swarm&#x27;</span>);
<span class="hljs-keyword">await</span> <span class="hljs-title function_">stopWithTimeout</span>(seeder, <span class="hljs-string">&#x27;Seeder&#x27;</span>);
};</pre>
</div>
</div>

Expand All @@ -289,16 +308,18 @@ <h1>heartbeat.js</h1>
<div class="sswrap ">
<a class="ss" href="#section-7">&#x00a7;</a>
</div>
<p>Send Regular Updates (outside of internal ping/pong)</p>
<p>Send a single explicit heartbeat over the current v1 base message type.</p>

</div>

<div class="content">
<div class='highlight'>
<pre> <span class="hljs-keyword">const</span> heartbeat = <span class="hljs-built_in">setInterval</span>(<span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(<span class="hljs-string">&#x27;[EXAMPLES:HEARTBEAT]&#x27;</span>, <span class="hljs-string">&#x27;Starting to send interval message...&#x27;</span>);
<span class="hljs-keyword">const</span> message = <span class="hljs-title class_">Message</span>.<span class="hljs-title function_">fromVector</span>([<span class="hljs-string">&#x27;Generic&#x27;</span>, <span class="hljs-title class_">Date</span>.<span class="hljs-title function_">now</span>().<span class="hljs-title function_">toString</span>()]);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&#x27;[EXAMPLES:HEARTBEAT]&#x27;</span>, <span class="hljs-string">&#x27;Sending :&#x27;</span>, message.<span class="hljs-property">raw</span>);</pre>
<pre> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(<span class="hljs-string">&#x27;[EXAMPLES:HEARTBEAT]&#x27;</span>, <span class="hljs-string">&#x27;Sending heartbeat...&#x27;</span>);
<span class="hljs-keyword">const</span> message = <span class="hljs-title class_">Message</span>.<span class="hljs-title function_">fromVector</span>([<span class="hljs-string">&#x27;P2P_BASE_MESSAGE&#x27;</span>, <span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">stringify</span>({
<span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;Heartbeat&#x27;</span>,
<span class="hljs-attr">object</span>: { <span class="hljs-attr">at</span>: <span class="hljs-title class_">Date</span>.<span class="hljs-title function_">now</span>() }
})]);
seeder.<span class="hljs-title function_">broadcast</span>(message.<span class="hljs-title function_">toBuffer</span>());</pre>
</div>
</div>

Expand All @@ -311,33 +332,16 @@ <h1>heartbeat.js</h1>
<div class="sswrap ">
<a class="ss" href="#section-8">&#x00a7;</a>
</div>
<p>Send interval message through seed node</p>
<p>Give peers a short window to process, then shut down cleanly.</p>

</div>

<div class="content">
<div class='highlight'>
<pre> seeder.<span class="hljs-title function_">broadcast</span>(message);</pre>
</div>
</div>

</li>


<li id="section-9">
<div class="annotation">
<pre> <span class="hljs-keyword">await</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve</span>) =&gt;</span> <span class="hljs-built_in">setTimeout</span>(resolve, <span class="hljs-number">1500</span>));
<span class="hljs-keyword">await</span> <span class="hljs-title function_">shutdown</span>();

<div class="sswrap ">
<a class="ss" href="#section-9">&#x00a7;</a>
</div>
<p>Send interval message through swarm agent
swarm.broadcast(message);</p>

</div>

<div class="content">
<div class='highlight'>
<pre> }, <span class="hljs-number">5000</span>);
<span class="hljs-keyword">if</span> (<span class="hljs-built_in">require</span>.<span class="hljs-property">main</span> === <span class="hljs-variable language_">module</span>) process.<span class="hljs-title function_">exit</span>(<span class="hljs-number">0</span>);
}

<span class="hljs-title function_">main</span>().<span class="hljs-title function_">catch</span>(<span class="hljs-keyword">function</span> <span class="hljs-title function_">exceptionHandler</span> (exception) {
Expand Down
Loading
Loading