Clojurescript-node.js mount module for a district server, that watches server connection to a blockchain.
Add [district0x/district-server-web3-watcher "1.0.3"]
into your project.clj
Include [district.server.web3-watcher]
in your CLJS file, where you use mount/start
Warning: district0x modules are still in early stages, therefore API can change in a future.
To see how district server modules play together in real-world app, you can take a look at NameBazaar server folder, where this is deployed in production.
You can pass following args to web3-watcher module:
:interval
Interval at which it should check the connection. Default: 3s:confirmations
How many offline responses module needs to get before triggers:on-offline
. Default: 3:on-online
Callback that is run when connection goes from offline to online:on-offline
Callback that is run when connection goes from online to offline
(ns my-district
(:require [mount.core :as mount]
[district.server.web3-watcher]))
(-> (mount/with-args
{:web3 {:port 8545}
:web3-watcher {:on-offline #(println "Node went offline")
:on-online #(println "Node is online again")}})
(mount/start))
district-server-web3-watcher
gets initial args from config provided by district-server-config/config
under the key :web3-watcher
. These args are then merged together with ones passed to mount/with-args
.
district-server-web3-watcher
relies on getting web3 instance from district-server-web3/web3
. That's why, in example, you need to set up :web3
in mount/with-args
as well.
If you wish to use custom modules instead of dependencies above while still using district-server-web3-watcher
, you can easily do so by mount's states swapping.
To try things in REPL:
- Watch
node-repl
target:npx shadow-cljs watch node-repl
- Run the compiled file:
node out/node-repl.js
- Connect REPL client:
lein repl :connect 30333
- To use the build, check
src/repl_helper.cljs
- Build:
npx shadow-cljs compile test-node
- Tests:
node out/node-tests.js
- Build:
clj -T:build jar
- Release:
clj -T:build deploy