Skip to content

Commit 52a000a

Browse files
authored
Merge pull request #1 from mlabs-haskell/dshuiski/hydra-sdk
PureScript Hydra SDK
2 parents b03595a + fde4449 commit 52a000a

40 files changed

+38260
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/node_modules
22
/output/
3+
/result
34
/.psa-stash
5+
/.psci_modules/
46
/.spago/
7+
/.spago2nix/

.purs-repl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Prelude
2+
import HydraSdk.Extra.AppManager
3+
import HydraSdk.Lib
4+
import HydraSdk.NodeApi
5+
import HydraSdk.Process
6+
import HydraSdk.Types

.tidyrc.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"importSort": "source",
3+
"importWrap": "auto",
4+
"indent": 2,
5+
"operatorsFile": null,
6+
"ribbon": 1,
7+
"typeArrowPlacement": "first",
8+
"unicode": "source",
9+
"width": 95
10+
}

Makefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.PHONY: build, format, repl, docs
2+
3+
ps-sources := $(shell fd --no-ignore-parent -epurs)
4+
nix-sources := $(shell fd --no-ignore-parent -enix --exclude='spago*')
5+
purs-args := "--stash --censor-lib --censor-codes=ImplicitImport,ImplicitQualifiedImport,ImplicitQualifiedImportReExport,UserDefinedWarning"
6+
7+
system := $(shell uname -s)
8+
ifeq (${system},Linux)
9+
open-in-browser := xdg-open
10+
else
11+
open-in-browser := open
12+
endif
13+
14+
requires-nix-shell:
15+
@[ "$(IN_NIX_SHELL)" ] || \
16+
( echo "The '$(MAKECMDGOALS)' target must be run from inside a nix shell, run 'nix develop' first." \
17+
&& false \
18+
)
19+
20+
build: requires-nix-shell
21+
spago build --purs-args ${purs-args}
22+
23+
format: requires-nix-shell
24+
@purs-tidy format-in-place ${ps-sources}
25+
@nixpkgs-fmt ${nix-sources}
26+
doctoc README.md --github --notitle
27+
28+
repl: requires-nix-shell
29+
spago repl
30+
31+
docs:
32+
nix build .#docs
33+
${open-in-browser} result/generated-docs/html/index.html

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# purescript-hydra-sdk
2+
3+
[Cardano Hydra](https://hydra.family/head-protocol/)
4+
SDK (Software Development Kit) for PureScript. This library offers
5+
various interfaces to facilitate rapid development of Hydra-based
6+
applications.
7+
8+
**Table of Contents**
9+
10+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
11+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
12+
13+
- [Applications](#applications)
14+
- [Functionality](#functionality)
15+
- [Development Workflows](#development-workflows)
16+
17+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
18+
19+
### Applications
20+
21+
Please refer to [hydra-auction-offchain](https://github.com/mlabs-haskell/hydra-auction-offchain)
22+
for a full-fledged example that utilizes this SDK.
23+
24+
### Functionality
25+
26+
The `HydraSdk.Process` module provides an interface for spinning up a hydra-node
27+
as a Node.js subprocess.
28+
29+
The `HydraSdk.NodeApi` module exports functions for connecting to the Hydra Node
30+
WebSocket API and sending HTTP requests. The primary function provided by this
31+
module is `mkHydraNodeApiWebSocket`, which establishes a WebSocket connection to
32+
the hydra-node, attaches specified handlers for incoming messages, and returns a
33+
`HydraNodeApiWebSocket` record with type-safe actions for interacting with the
34+
Hydra Node API. It also allows to specify retry strategies for Hydra
35+
transactions that may be silently dropped by cardano-node, particularly for
36+
Close and Contest transactions.
37+
38+
The `HydraSdk.Types` module re-exports various Hydra domain-specific types
39+
(such as `HydraHeadStatus` and `HydraNodeApi_InMessage`), along with other
40+
utility types (e.g., `HostPort` and `Network`) used by the components of this
41+
library.
42+
43+
`HydraSdk.Extra.AppManager` provides an opinionated interface for managing
44+
multiple Hydra application instances, with each instance running a separate
45+
hydra-node process, as implemented in [hydra-auction-offchain](https://github.com/mlabs-haskell/hydra-auction-offchain).
46+
For more information, refer to the [AppManager README](src/Extra/README.md).
47+
48+
### Development Workflows
49+
50+
Before executing most of the commands listed below, first enter the Nix
51+
development shell by running `nix develop`.
52+
53+
**Build the project** (requires Nix shell): `make build`
54+
**Format code** (requires Nix shell): `make format`
55+
**Build docs and open them in the browser**: `make docs`

0 commit comments

Comments
 (0)