Skip to content

Commit 5918291

Browse files
authored
Merge pull request #720 from KtorZ/haskell-node-extractor
replace 'fetch.mjs' + ogmios with a pure Haskell-based solution.
2 parents 8d7f5a5 + b7d31a8 commit 5918291

35 files changed

+2171
-0
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ insert_final_newline = true
88
indent_style = space
99
indent_size = 4
1010

11+
[*.hs]
12+
indent_style = space
13+
indent_size = 4
14+
1115
[*.js]
1216
indent_style = space
1317
indent_size = 2
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist-newstyle
2+
/data
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
SHELL := /bin/sh
2+
3+
BREW_PREFIX := $(shell brew --prefix 2>/dev/null)
4+
PREFIX ?= $(if $(BREW_PREFIX),$(BREW_PREFIX),/usr/local)
5+
LIBDIR ?= $(PREFIX)/lib
6+
INCLUDEDIR ?= $(PREFIX)/include
7+
PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
8+
9+
CABAL ?= cabal
10+
INSTALL ?= install
11+
DEPS_DIR ?= .build/deps
12+
13+
SECP256K1_DIR := $(DEPS_DIR)/secp256k1
14+
SECP256K1_REV := ac83be33d0956faf6b7f61a60ab524ef7d6a473a
15+
16+
BLST_DIR := $(DEPS_DIR)/blst
17+
BLST_VERSION := v0.3.10
18+
BLST_PC := $(BLST_DIR)/libblst.pc
19+
20+
.PHONY: all build run help blst secp256k1 pre
21+
22+
all: help
23+
24+
help:
25+
@printf "\033[1;37mMakefile Targets\033[00m\n"
26+
@grep -E '^[a-z]+[^:]+:.*## &cmd ' Makefile | sort | while read -r l; do printf " \033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 3- -d'#' | sed 's/^ \&cmd//')\n"; done
27+
@echo ""
28+
29+
pre: ## &cmd check required tools, libraries, and local build configuration
30+
@printf '%s\n' 'Checking build prerequisites'
31+
@set -eu; \
32+
os_name="$$(uname -s)"; \
33+
case "$$os_name" in \
34+
Darwin) install_cmd='brew install' ;; \
35+
Linux) install_cmd='sudo apt-get install' ;; \
36+
*) install_cmd='install manually' ;; \
37+
esac; \
38+
failed=0; \
39+
check_cmd() { \
40+
label="$$1"; \
41+
cmd="$$2"; \
42+
hint="$$3"; \
43+
if command -v "$$cmd" >/dev/null 2>&1; then \
44+
printf '\033[1;32m%s\033[00m %s\n' '' "$$label"; \
45+
else \
46+
printf '\033[1;31m%s %s\033[00m → \033[1;37m%s %s\033[00m\n' '' "$$label" "$$install_cmd" "$$hint"; \
47+
failed=1; \
48+
fi; \
49+
}; \
50+
check_pkg() { \
51+
label="$$1"; \
52+
hint="$$2"; \
53+
shift; \
54+
shift; \
55+
found=0; \
56+
for pkg_name in "$$@"; do \
57+
if pkg-config --exists "$$pkg_name"; then \
58+
found=1; \
59+
break; \
60+
fi; \
61+
done; \
62+
if [ "$$found" -eq 1 ]; then \
63+
printf '\033[1;32m%s\033[00m %s\n' '' "$$label"; \
64+
else \
65+
printf '\033[1;31m%s %s\033[00m → \033[1;37m%s %s\033[00m\n' '' "$$label" "$$install_cmd" "$$hint"; \
66+
failed=1; \
67+
fi; \
68+
}; \
69+
check_path() { \
70+
label="$$1"; \
71+
path="$$2"; \
72+
hint="$$3"; \
73+
if [ -e "$$path" ]; then \
74+
printf '%s %s\n' '' "$$label"; \
75+
else \
76+
printf '%s %s (%s)\n' '' "$$label" "$$hint"; \
77+
failed=1; \
78+
fi; \
79+
}; \
80+
check_cmd 'git' git git; \
81+
check_cmd 'cabal' cabal 'ghcup && ghcup tui'; \
82+
check_cmd 'ghc' ghc 'ghcup && ghcup tui'; \
83+
check_cmd 'pkg-config' pkg-config pkg-config; \
84+
check_cmd 'autoconf' autoconf autoconf; \
85+
check_cmd 'libtool' libtool libtool; \
86+
if [ "$$os_name" = 'Darwin' ]; then \
87+
check_cmd 'install_name_tool' install_name_tool CommandLineTools; \
88+
fi; \
89+
if command -v pkg-config >/dev/null 2>&1; then \
90+
check_pkg 'libffi' libffi libffi; \
91+
check_pkg 'gmp' gmp gmp; \
92+
check_pkg 'pcre' pcre libpcre pcre; \
93+
check_pkg 'libsodium' libsodium libsodium; \
94+
check_pkg 'zlib' zlib zlib; \
95+
check_pkg 'openssl' openssl openssl; \
96+
check_pkg 'secp256k1' libsecp256k1 libsecp256k1; \
97+
check_pkg 'blst' libblst libblst; \
98+
fi; \
99+
check_cmd 'llvm-config' llvm-config llvm; \
100+
if [ "$$os_name" = 'Linux' ]; then \
101+
check_path 'libnuma headers' '/usr/include/numa.h' 'sudo apt-get install libnuma-dev'; \
102+
check_path 'libsystemd headers' '/usr/include/systemd/sd-daemon.h' 'sudo apt-get install libsystemd-dev'; \
103+
fi; \
104+
105+
build: ## &cmd compile the main binary
106+
$(CABAL) build exe:haskell-node-extractor
107+
108+
secp256k1: ## &cmd install secp256k1 as required for Cardano
109+
mkdir -p "$(DEPS_DIR)"
110+
if [ ! -d "$(SECP256K1_DIR)" ]; then git clone https://github.com/bitcoin-core/secp256k1.git "$(SECP256K1_DIR)"; fi
111+
cd "$(SECP256K1_DIR)" && git fetch --all --tags
112+
cd "$(SECP256K1_DIR)" && git checkout "$(SECP256K1_REV)"
113+
cd "$(SECP256K1_DIR)" && ./autogen.sh
114+
cd "$(SECP256K1_DIR)" && ./configure --prefix="$(PREFIX)" --libdir="$(LIBDIR)" --enable-module-schnorrsig --enable-experimental
115+
$(MAKE) -C "$(SECP256K1_DIR)"
116+
$(MAKE) -C "$(SECP256K1_DIR)" check
117+
$(MAKE) -C "$(SECP256K1_DIR)" install
118+
if [ "$$(uname -s)" = "Darwin" ] && [ -f "$(LIBDIR)/libsecp256k1.0.dylib" ]; then install_name_tool -id "$(LIBDIR)/libsecp256k1.0.dylib" "$(LIBDIR)/libsecp256k1.0.dylib"; fi
119+
120+
blst: ## &cmd install blst as required for Cardano
121+
mkdir -p "$(DEPS_DIR)"
122+
if [ ! -d "$(BLST_DIR)" ]; then git clone https://github.com/supranational/blst "$(BLST_DIR)"; fi
123+
cd "$(BLST_DIR)" && git fetch --all --tags
124+
cd "$(BLST_DIR)" && git checkout "$(BLST_VERSION)"
125+
cd "$(BLST_DIR)" && ./build.sh
126+
mkdir -p "$(PKGCONFIGDIR)" "$(INCLUDEDIR)" "$(LIBDIR)"
127+
printf '%s\n' \
128+
'prefix=$(PREFIX)' \
129+
'exec_prefix=$${prefix}' \
130+
'libdir=$${exec_prefix}/lib' \
131+
'includedir=$${prefix}/include' \
132+
'Name: libblst' \
133+
'Description: Multilingual BLS12-381 signature library' \
134+
'URL: https://github.com/supranational/blst' \
135+
'Version: 0.3.10' \
136+
'Cflags: -I$${includedir}' \
137+
'Libs: -L$${libdir} -lblst' \
138+
> "$(BLST_PC)"
139+
$(INSTALL) -m 0644 "$(BLST_PC)" "$(PKGCONFIGDIR)/libblst.pc"
140+
$(INSTALL) -m 0644 "$(BLST_DIR)/bindings/blst_aux.h" "$(INCLUDEDIR)/blst_aux.h"
141+
$(INSTALL) -m 0644 "$(BLST_DIR)/bindings/blst.h" "$(INCLUDEDIR)/blst.h"
142+
$(INSTALL) -m 0644 "$(BLST_DIR)/bindings/blst.hpp" "$(INCLUDEDIR)/blst.hpp"
143+
$(INSTALL) -m 0644 "$(BLST_DIR)/libblst.a" "$(LIBDIR)/libblst.a"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Haskell node extractor
2+
3+
This tool reads Conway ledger snapshots from disk and extracts JSON fixtures for conformance testing.
4+
5+
## Prerequisites
6+
7+
To check for any missing prerequisites, just run:
8+
9+
```console
10+
make pre
11+
```
12+
13+
Install any missing system or vendor dependency.
14+
15+
## Build
16+
17+
```console
18+
make build
19+
```
20+
21+
> [!TIP]
22+
>
23+
> The Makefile defaults `PREFIX` to `brew --prefix` when [Homebrew](brew.sh) is available, and otherwise falls back to `/usr/local`.
24+
> If your local prefix is different, override it explicitly. For example on Apple Silicon Homebrew:
25+
>
26+
>
27+
> ```console
28+
> make secp256k1 PREFIX=/opt/homebrew
29+
> ```
30+
31+
## Run
32+
33+
Simply run:
34+
35+
```console
36+
cabal run exe:haskell-node-extractor -- --help
37+
```
38+
39+
## Make targets
40+
41+
To see the available make targets, just run:
42+
43+
```console
44+
make help
45+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Main where
2+
3+
import Command
4+
( runCommandLine
5+
)
6+
7+
main :: IO ()
8+
main =
9+
runCommandLine
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
repository cardano-haskell-packages
2+
url: https://input-output-hk.github.io/cardano-haskell-packages
3+
secure: True
4+
root-keys:
5+
3e0cce471cf09815f930210f7827266fd09045445d65923e6d0238a6cd15126f
6+
443abb7fb497a134c343faf52f0b659bd7999bc06b7f63fa76dc99d631f9bea1
7+
a86a1f6ce86c449c46666bda44268677abf29b5b2d2eb5ec7af903ec2f117a82
8+
bcec67e8e99cabfa7764d75ad9b158d72bfacf70ca1d0ec8bc6b4406d1bf8413
9+
c00aae8461a256275598500ea0e187588c35a5d5d7454fb57eac18d9edb86a56
10+
d4a35cd3121aa00d18544bb0ac01c3e1691d618f462c46129271bccf39f7e8ee
11+
12+
index-state:
13+
, hackage.haskell.org 2025-09-11T07:59:00Z
14+
, cardano-haskell-packages 2025-09-11T08:36:14Z
15+
16+
constraints:
17+
, any.cardano-node == 10.5.1
18+
19+
, any.cardano-ledger-core == 1.17.0.0
20+
, any.cardano-ledger-shelley == 1.16.0.0
21+
, any.cardano-ledger-conway == 1.19.0.0
22+
23+
, any.ouroboros-consensus == 0.27.0.0
24+
, any.ouroboros-consensus-cardano == 0.25.1.0
25+
, any.ouroboros-network == 0.21.3.0
26+
27+
, any.io-classes == 1.5.0.0
28+
, any.io-classes-mtl == 0.1.2.0
29+
, any.formatting == 7.2.0
30+
, any.text source
31+
32+
allow-newer:
33+
*:formatting
34+
35+
packages:
36+
.
37+
38+
tests: False
39+
test-show-details: direct
40+
41+
package cryptonite
42+
flags: -support_rdrand
43+
44+
package bitvec
45+
flags: -simd
46+
47+
package quickcheck-state-machine
48+
flags: +no-vendored-treediff
49+
50+
package text
51+
flags: -simdutf
52+
53+
package formatting
54+
flags: +no-double-conversion
55+
56+
package cardano-crypto-praos
57+
flags: -external-libsodium-vrf
58+
59+
source-repository-package
60+
type: git
61+
location: https://github.com/CardanoSolutions/cardano-ledger.git
62+
tag: 5cca15a1f0629c11e8d4d4daeb73428684f9c34f
63+
subdir:
64+
libs/cardano-ledger-core
65+
libs/cardano-ledger-api
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
cabal-version: 3.0
2+
3+
name: haskell-node-extractor
4+
version: 0
5+
synopsis: A tool for extracting test data from the Haskell's implementation.
6+
description: A tool for extracting test data from the Haskell's implementation, to be used for conformance.
7+
category: Web
8+
stability: experimental
9+
homepage: https://github.com/pragma-org/amaru
10+
bug-reports: https://github.com/pragma-org/amaru/issues
11+
author: KtorZ <matthias.benkort@gmail.com>
12+
maintainer: matthias.benkort@gmail.com
13+
copyright: 2026 KtorZ
14+
license: Apache-2.0
15+
license-file: LICENSE
16+
build-type: Simple
17+
18+
source-repository head
19+
type: git
20+
location: https://github.com/pragma-org/amaru
21+
22+
library
23+
default-language: Haskell2010
24+
hs-source-dirs: src
25+
exposed-modules:
26+
Command
27+
, Command.ExtractSnapshot
28+
, Data.Coin
29+
, Data.Credential
30+
, Data.DelegateRepresentative
31+
, Data.Mandate
32+
, Data.NetworkName
33+
, Data.Nonce
34+
, Data.HexString
35+
, Data.PoolMetadata
36+
, Data.PoolParameters
37+
, Data.PoolDelegator
38+
, Data.PoolId
39+
, Data.PoolRelay
40+
, Data.PoolRewardsInfo
41+
, Data.Rational
42+
, Data.RewardAccount
43+
, Data.RewardsProvenance
44+
, Data.Pools
45+
, Error
46+
, Genesis
47+
, Query.DelegateRepresentatives
48+
, Query.Nonces
49+
, Query.Pots
50+
, Query.Pools
51+
, Query.RewardsProvenance
52+
, Snapshot
53+
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wpartial-fields -Wredundant-constraints -Wunused-packages -threaded
54+
default-extensions:
55+
LambdaCase
56+
MultiWayIf
57+
NamedFieldPuns
58+
NoImplicitPrelude
59+
OverloadedStrings
60+
TypeApplications
61+
build-depends:
62+
async
63+
, aeson
64+
, aeson-pretty
65+
, base >=4.7 && <5
66+
, base16
67+
, base58-bytestring
68+
, bytestring
69+
, cardano-ledger-allegra
70+
, cardano-ledger-alonzo
71+
, cardano-ledger-api
72+
, cardano-ledger-babbage
73+
, cardano-ledger-binary
74+
, cardano-ledger-byron
75+
, cardano-ledger-conway
76+
, cardano-ledger-core
77+
, cardano-ledger-mary
78+
, cardano-ledger-shelley
79+
, cardano-protocol-tpraos
80+
, cardano-slotting
81+
, cardano-strict-containers
82+
, containers
83+
, directory
84+
, filepath
85+
, fs-api
86+
, io-classes
87+
, io-sim
88+
, mtl
89+
, microlens
90+
, optparse-applicative
91+
, ouroboros-consensus
92+
, ouroboros-consensus-cardano
93+
, ouroboros-consensus-protocol
94+
, relude
95+
, serialise
96+
, text
97+
, vector
98+
, vector-map
99+
100+
executable haskell-node-extractor
101+
main-is: Main.hs
102+
default-language: Haskell2010
103+
hs-source-dirs: app
104+
ghc-options: -rtsopts
105+
build-depends:
106+
base >=4.7 && <5
107+
, haskell-node-extractor
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cradle:
2+
cabal:

0 commit comments

Comments
 (0)