mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2024-12-25 07:19:29 -05:00
45 lines
9.9 KiB
HTML
45 lines
9.9 KiB
HTML
<!DOCTYPE html><html class="default"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>haveno-ts</title><meta name="description" content="Documentation for haveno-ts"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script async src="assets/search.js" id="search-script"></script></head><body><script>document.body.classList.add(localStorage.getItem("tsd-theme") || "os")</script><header><div class="tsd-page-toolbar"><div class="container"><div class="table-wrap"><div class="table-cell" id="tsd-search" data-base="."><div class="field"><label for="tsd-search-field" class="tsd-widget search no-caption">Search</label><input type="text" id="tsd-search-field"/></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">haveno-ts</a></div><div class="table-cell" id="tsd-widgets"><div id="tsd-filter"><a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a><div class="tsd-filter-group"><div class="tsd-select" id="tsd-filter-visibility"><span class="tsd-select-label">All</span><ul class="tsd-select-list"><li data-value="public">Public</li><li data-value="protected">Public/Protected</li><li data-value="private" class="selected">All</li></ul></div> <input type="checkbox" id="tsd-filter-inherited" checked/><label class="tsd-widget" for="tsd-filter-inherited">Inherited</label><input type="checkbox" id="tsd-filter-externals" checked/><label class="tsd-widget" for="tsd-filter-externals">Externals</label></div></div><a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a></div></div></div></div><div class="tsd-page-title"><div class="container"><h1> haveno-ts </h1></div></div></header><div class="container container-main"><div class="row"><div class="col-8 col-content"><div class="tsd-panel tsd-typography">
|
|
<a href="#haveno-typescript-library" id="haveno-typescript-library" style="color: inherit; text-decoration: none;">
|
|
<h1>Haveno TypeScript Library</h1>
|
|
</a>
|
|
<p>TypeScript library for using Haveno.</p>
|
|
|
|
<a href="#install" id="install" style="color: inherit; text-decoration: none;">
|
|
<h2>Install</h2>
|
|
</a>
|
|
<ol>
|
|
<li>Start a Haveno daemon (see <a href="https://github.com/haveno-dex/haveno/blob/master/docs/installing.md">installing.md</a>).</li>
|
|
<li>Install haveno-ts in your project: <code>npm install haveno-ts</code></li>
|
|
</ol>
|
|
|
|
<a href="#sample-code" id="sample-code" style="color: inherit; text-decoration: none;">
|
|
<h2>Sample code</h2>
|
|
</a>
|
|
<pre><code class="language-js"><span class="hl-0">import</span><span class="hl-1"> { </span><span class="hl-2">HavenoClient</span><span class="hl-1"> } </span><span class="hl-0">from</span><span class="hl-1"> </span><span class="hl-3">"haveno-ts"</span><span class="hl-1">;</span><br/><br/><span class="hl-4">// create client connected to Haveno daemon</span><br/><span class="hl-5">const</span><span class="hl-1"> </span><span class="hl-6">alice</span><span class="hl-1"> = </span><span class="hl-5">new</span><span class="hl-1"> </span><span class="hl-7">HavenoClient</span><span class="hl-1">(</span><span class="hl-3">"http://localhost:8080"</span><span class="hl-1">, </span><span class="hl-3">"apitest"</span><span class="hl-1">);</span><br/><br/><span class="hl-4">// use Haveno daemon</span><br/><span class="hl-5">const</span><span class="hl-1"> </span><span class="hl-6">balances</span><span class="hl-1"> = </span><span class="hl-0">await</span><span class="hl-1"> </span><span class="hl-2">alice</span><span class="hl-1">.</span><span class="hl-7">getBalances</span><span class="hl-1">();</span><br/><span class="hl-5">const</span><span class="hl-1"> </span><span class="hl-6">paymentAccounts</span><span class="hl-1"> = </span><span class="hl-0">await</span><span class="hl-1"> </span><span class="hl-2">alice</span><span class="hl-1">.</span><span class="hl-7">getPaymentAccounts</span><span class="hl-1">();</span><br/><span class="hl-5">const</span><span class="hl-1"> </span><span class="hl-6">myOffers</span><span class="hl-1"> = </span><span class="hl-0">await</span><span class="hl-1"> </span><span class="hl-2">alice</span><span class="hl-1">.</span><span class="hl-7">getMyOffers</span><span class="hl-1">(</span><span class="hl-3">"ETH"</span><span class="hl-1">);</span><br/><span class="hl-5">const</span><span class="hl-1"> </span><span class="hl-6">offers</span><span class="hl-1"> = </span><span class="hl-0">await</span><span class="hl-1"> </span><span class="hl-2">alice</span><span class="hl-1">.</span><span class="hl-7">getOffers</span><span class="hl-1">(</span><span class="hl-3">"ETH"</span><span class="hl-1">, </span><span class="hl-3">"BUY"</span><span class="hl-1">);</span><br/><span class="hl-5">const</span><span class="hl-1"> </span><span class="hl-6">trade</span><span class="hl-1"> = </span><span class="hl-0">await</span><span class="hl-1"> </span><span class="hl-2">alice</span><span class="hl-1">.</span><span class="hl-7">takeOffer</span><span class="hl-1">(</span><span class="hl-2">offers</span><span class="hl-1">[</span><span class="hl-8">0</span><span class="hl-1">].</span><span class="hl-7">getId</span><span class="hl-1">(), </span><span class="hl-2">paymentAccounts</span><span class="hl-1">[</span><span class="hl-8">0</span><span class="hl-1">].</span><span class="hl-7">getId</span><span class="hl-1">());</span><br/><br/><span class="hl-4">// disconnect client</span><br/><span class="hl-0">await</span><span class="hl-1"> </span><span class="hl-2">alice</span><span class="hl-1">.</span><span class="hl-7">disconnect</span><span class="hl-1">();</span>
|
|
</code></pre>
|
|
|
|
<a href="#typedocs" id="typedocs" style="color: inherit; text-decoration: none;">
|
|
<h2>TypeDocs</h2>
|
|
</a>
|
|
<p>See <a href="https://haveno-dex.github.io/haveno-ts/classes/HavenoClient.HavenoClient-1.html">typedocs</a>.</p>
|
|
|
|
<a href="#run-tests" id="run-tests" style="color: inherit; text-decoration: none;">
|
|
<h2>Run tests</h2>
|
|
</a>
|
|
<p>Running the <a href="./src/HavenoClient.test.ts">API tests</a> is the best way to develop and test Haveno end-to-end.</p>
|
|
<p><a href="./src/HavenoClient.ts"><code>HavenoClient.ts</code></a> provides the client interface to Haveno's backend daemon.</p>
|
|
<ol>
|
|
<li><a href="https://github.com/haveno-dex/haveno/blob/master/docs/installing.md">Run a local Haveno test network</a> and then shut down the arbitrator, Alice, and Bob or run them as daemons, e.g. <code>make alice-daemon</code>. You may omit the arbitrator registration steps since it is done automatically in the tests.</li>
|
|
<li>Clone this project to the same parent directory as the haveno project: <code>git clone https://github.com/haveno-dex/haveno-ts</code></li>
|
|
<li>In a new terminal, start envoy with the config in haveno-ts/config/envoy.test.yaml (change absolute path for your system): <code>docker run --rm --add-host host.docker.internal:host-gateway -it -v ~/git/haveno-ts/config/envoy.test.yaml:/envoy.test.yaml -p 8079:8079 -p 8080:8080 -p 8081:8081 -p 8082:8082 -p 8083:8083 -p 8084:8084 -p 8085:8085 -p 8086:8086 envoyproxy/envoy-dev:8a2143613d43d17d1eb35a24b4a4a4c432215606 -c /envoy.test.yaml</code></li>
|
|
<li>In a new terminal, start the funding wallet. This wallet will be automatically funded in order to fund Alice and Bob during the tests.<br>For example: <code>cd ~/git/haveno && make funding-wallet</code>.</li>
|
|
<li>Install protobuf compiler v3.19.1 or later for your system:<br>
|
|
mac: <code>brew install protobuf</code><br>
|
|
linux: <code>apt install protobuf-compiler</code>
|
|
NOTE: You may need to upgrade to v3.19.1 manually if your package manager installs an older version.</li>
|
|
<li>Download <code>protoc-gen-grpc-web</code> plugin and make executable as <a href="https://github.com/grpc/grpc-web#code-generator-plugin">shown here</a>.</li>
|
|
<li><code>cd haveno-ts</code></li>
|
|
<li><code>npm install</code></li>
|
|
<li><code>npm test</code> to run all tests or <code>npm run test -- -t 'my test'</code> to run tests by name.</li>
|
|
</ol>
|
|
</div></div><div class="col-4 col-menu menu-sticky-wrap menu-highlight"><nav class="tsd-navigation primary"><ul><li class="current"><a href="modules.html">Modules</a></li><li class=" tsd-kind-module"><a href="modules/HavenoClient.html">Haveno<wbr/>Client</a></li><li class=" tsd-kind-module"><a href="modules/index.html">index</a></li><li class=" tsd-kind-module"><a href="modules/index.html">index</a></li><li class=" tsd-kind-module"><a href="modules/protobuf_GrpcServiceClientPb.html">protobuf/<wbr/>Grpc<wbr/>Service<wbr/>Client<wbr/>Pb</a></li><li class=" tsd-kind-module"><a href="modules/protobuf_grpc_pb.html">protobuf/grpc_<wbr/>pb</a></li><li class=" tsd-kind-module"><a href="modules/protobuf_pb_pb.html">protobuf/pb_<wbr/>pb</a></li><li class=" tsd-kind-module"><a href="modules/utils_HavenoError.html">utils/<wbr/>Haveno<wbr/>Error</a></li><li class=" tsd-kind-module"><a href="modules/utils_HavenoUtils.html">utils/<wbr/>Haveno<wbr/>Utils</a></li><li class=" tsd-kind-module"><a href="modules/utils_TaskLooper.html">utils/<wbr/>Task<wbr/>Looper</a></li></ul></nav></div></div></div><footer class="with-border-bottom"><div class="container"><h2>Legend</h2><div class="tsd-legend-group"><ul class="tsd-legend"><li class="tsd-kind-namespace"><span class="tsd-kind-icon">Namespace</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-enum"><span class="tsd-kind-icon">Enumeration</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-class"><span class="tsd-kind-icon">Class</span></li></ul></div><h2>Settings</h2><p>Theme <select id="theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></p></div></footer><div class="container tsd-generator"><p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div><div class="overlay"></div><script src="assets/main.js"></script></body></html> |