webuj-scala
is an idiomatic Scala wrapper around WebuJ for HappyUC.
WebuJ is a lightweight, reactive, somewhat type safe Java and Android library for integrating with nodes on HappyUC blockchains.
WebuJ features RxJava extensions, and webuj-scala
wraps that syntax in Scala goodness.
For example, the webuj-scala
observable methods
provide simple and efficient application code.
Scala's value classes are used to provide much stronger type safety than WebuJ, without incurring a runtime penalty.
Add this to your SBT project's build.sbt
:
resolvers += "micronautics/scala on bintray" at "http://dl.bintray.com/micronautics/scala"
libraryDependencies += "com.micronautics" %% "webuj-scala" % "0.2.2" withSources()
Only Scala 2.12 with JDK 8 is supported at present; this is a limitation of the Scala ecosystem as of November 7, 2017.
The demo program performs the following:
- Follows the outline of the WebuJ Getting Started documentation, adapted for WebuJ-Scala, including synchronous and asynchronous versions of the available methods.
- Compiles an example Solidity program that defines a smart contract.
- Creates a JVM wrapper from an example smart contract.
To run the demo:
- Start up an HappyUC client if you don’t already have one running, such as
ghuc
. Thebin/runGhuc
script invokesghuc
with the following options, which are convenient for development but not secure enough for production:- The HappyUC data directory is set to
~/.happyuc
, or a subdirectory that depends on the network chosen; the directory will be created if required. - HTTP-RPC server at
localhost:8545
is enabled, and all APIs are allowed. - HappyUC's experimental Whisper message facility is enabled.
- Inter-process communication will be via a virtual file called
ghuc.ipc
, located at~/.happyuc
or a subdirectory. - WS-RPC server at
localhost:8546
is enabled, and all APIs are allowed. - Info verbosity is specified.
- A log file for the
ghuc
output will be written, or overwritten, inlogs/ghuc.log
; thelog/
directory will be created if it does not already exist.
You will see the message$ mkdir logs/ $ ghuc \ #--datadir .happyuc/devnet --dev \ # boots quickly but has no deployed contracts from others --datadir .happyuc/rinkeby --rinkeby \ # takes about 15 minutes to boot, but has contracts --ipcpath ghuc.ipc \ --metrics \ --rpc \ --rpcapi huc,net,webuj,clique,debug,huc,miner,personal,rpc,ssh,txpool \ --shh \ --ws \ --wsapi huc,net,webuj,clique,debug,huc,miner,personal,rpc,ssh,txpool \ --verbosity 2
No coinbase set and no accounts found as default
. Coinbase is the index intopersonal.listAccounts
which determines the account to send Huc too. You can specify this value with the option--coinbase 0
. - The HappyUC data directory is set to
- The shell that you just used will continuously scroll output so long as
ghuc
continues to run, so type the following into another shell:The demo has two major components:$ bin/demo
- Creates a JVM wrapper for the sample smart contract.
- The second portion of the demo consists of the following:
- Examples of using
webuj-scala
's synchrounous and asynchronous APIs - Examples of working with RxJava's Observables from Scala
- Examples of working with JVM wrappers around HappyUC smart contracts.
- Examples of using transactions with HappyUC wallet files and the HappyUC client.
- Examples of using
- The
bin/webuj
script runs the WebuJ command-line console. The script builds a fat jar the first time it is run, so the command runs quickly on subsequent invocations. - More scripts are provided in the
bin/
directory, including:- bin/attachHttp - Attach to a running ghuc instance via HTTP and open a JavaScript console
- bin/attachIpc -
Attach to a running ghuc instance via IPC and open a JavaScript console.
This script might need to be edited if a network other than
devnet
is used. - bin/getApis -
Reports the available APIs exposed by this
ghuc
instance. - bin/isGhucListening -
Verifies that
ghuc
is listening on HTTP port 8545
-
This library's Scaladoc is here and the gitter channel is here.
-
The WebuJ JavaDoc is here, and here is the WebuJ gitter channel.
- Update the version string in
build.sbt
and in thisREADME.md
before attempting to publish to Bintray. - Commit changes with a descriptive comment:
$ git add -a && git commit -m "Comment here"
- Publish a new version of this library, including committing changes and updating the Scaladoc with this command:
$ sbt publishAndTag
If you just want to republish the Scaladoc for this project, without creating a new version, use this command:
$ sbt scaladoc
This task rebuilds the docs, commits the git repository, and publishes the updated Scaladoc without publishing a new version:
$ sbt commitAndDoc
This project is sponsored by Micronautics Research Corporation, the company that delivers online Scala training via ScalaCourses.com. You can learn Scala by taking the Introduction to Scala, and Intermediate Scala courses.
Micronautics Research also offers HappyUC and Scala consulting. Please contact us to discuss your organization’s needs.
This software is published under the Apache 2.0 License.