Skip to content

Commit 16cd19c

Browse files
authored
service: add ark-network/ark (#202)
* add ark-network/ark and gitignore volumes dir * mount both ark and arkd as volumes * Bump go; Add Docker mock client; test all combinations * go mod tidy * start: Show only running services * nigiri ark & nigiri arkd * Improve README with ark instructions * cleanup use only yaml pkg
1 parent 32bd838 commit 16cd19c

File tree

19 files changed

+878
-441
lines changed

19 files changed

+878
-441
lines changed

.github/workflows/test.yml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Go
1+
name: Go Tests
22

33
on:
44
push:
@@ -7,25 +7,26 @@ on:
77
branches: [master]
88

99
jobs:
10-
integration:
11-
name: Unit Tests
10+
test:
11+
name: Run Tests
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout
15-
uses: actions/checkout@v3
15+
uses: actions/checkout@v4
1616
with:
1717
fetch-depth: 0
1818

1919
- name: Set up Go
20-
uses: actions/setup-go@v3
20+
uses: actions/setup-go@v4
2121
with:
22-
go-version: ">1.17.2"
22+
go-version: '1.23.4'
23+
cache: true
2324

24-
- name: Get dependencies
25-
run: go get -v -t -d ./...
25+
- name: Code Format Check
26+
run: make fmt
2627

27-
- name: Test
28-
run: |
29-
make fmt
30-
make install
31-
make test-ci
28+
- name: Code Analysis
29+
run: make vet
30+
31+
- name: Run Tests
32+
run: make test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
.env
33

4+
cmd/nigiri/resources/volumes/
45
vendor/
56
build/
67
dist/

Makefile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,8 @@ test: clean install
4343
@echo "Testing..."
4444
go test -v -count=1 -race ./...
4545

46-
## test-ci: runs travis tests
47-
test-ci: clean
48-
@echo "Testing..."
49-
go test -short -v ./...
50-
5146
## cov: generates coverage report
5247
cov:
5348
@echo "Coverage..."
54-
go test -cover ./...
49+
go test -coverprofile=coverage.out ./...
50+
go tool cover -html=coverage.out

README.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
# 🍣 Nigiri Bitcoin
22

3-
Nigiri provides a command line interface that manages a selection of `docker-compose` batteries included to have ready-to-use bitcoin `regtest` development environment, with a **bitcoin** node, **electrum** explorer both backend and frontend user interface.
3+
Nigiri provides a command line interface that manages a selection of `docker-compose` batteries included to have a ready-to-use Bitcoin `regtest` development environment. Out of the box, you get:
44

5-
It offers a [JSON HTTP proxy passtrough](https://github.com/vulpemventures/nigiri-chopsticks) that adds to the explorer handy endpoints like `/faucet` and automatic block generation when calling the `/tx` pushing a transaction.
5+
* **Bitcoin Node**: A Bitcoin Core node running in regtest mode
6+
* **Electrum**: Backend and frontend explorer for quick blockchain inspection
7+
* **Chopsticks**: A [JSON HTTP proxy](https://github.com/vulpemventures/nigiri-chopsticks) that adds handy endpoints like `/faucet` and automatic block generation
68

7-
You can have Lightning with `--ln` flag and/or Elements with the `--liquid` flag.
9+
You can extend your setup with:
10+
* **Ark**: A Bitcoin layer two implementation for scalable off-chain transactions
11+
* **Elements/Liquid sidechain** with `--liquid` flag
12+
* **Lightning Network nodes** with `--ln` flag (Core Lightning, LND, and Taproot Assets)
813

914

1015
# No time to make a Nigiri yourself?
@@ -37,12 +42,17 @@ You may want to [Manage Docker as a non-root user](https://docs.docker.com/engin
3742
* Close and reopen your terminal, then start Bitcoin and Liquid
3843

3944
```
40-
$ nigiri start --liquid
45+
$ nigiri start --ark
4146
```
4247
**That's it.**
4348

44-
Go to http://localhost:5000 for quickly inspect the Bitcoin blockchain or http://localhost:5001 for Liquid.
49+
Go to http://localhost:5000 for quickly inspect the Bitcoin blockchain.
4550

51+
Want more? Add Elements/Liquid or Lightning nodes:
52+
```bash
53+
$ nigiri start --ark --liquid # Add Elements/Liquid sidechain
54+
$ nigiri start --ark --ln # Add Lightning Network nodes
55+
```
4656

4757
**Note for users of macOS Monterey an onward**
4858
<details>
@@ -187,6 +197,26 @@ $ nigiri cln connect `nigiri lnd getinfo | jq -r .identity_pubkey`@lnd:9735
187197
$ nigiri lnd openchannel --node_key=`nigiri cln getinfo | jq -r .id` --local_amt=100000
188198
```
189199

200+
### Use the Ark CLI inside the box
201+
202+
```bash
203+
# Check versions
204+
$ nigiri ark --version # or -v
205+
$ nigiri arkd --version # or -v
206+
207+
# Initialize the Ark client (only needed once)
208+
$ nigiri ark init --network regtest --password secret --server-url localhost:7070 --explorer http://chopsticks:3000
209+
210+
# Use the Ark client
211+
$ nigiri ark config # Show wallet configuration
212+
$ nigiri ark receive # Show receiving addresses
213+
$ nigiri ark balance # Show wallet balance
214+
215+
# Use the Ark daemon client
216+
$ nigiri arkd wallet status # Show wallet status
217+
$ nigiri arkd wallet create --password secret # Create a new wallet
218+
$ nigiri arkd wallet unlock --password secret # Unlock the wallet
219+
```
190220

191221
### Run in headless mode (without Esplora)
192222
If you are looking to spin-up Nigiri in Travis or Github Action you can use the `--ci` flag.

cmd/nigiri/ark.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package main
2+
3+
import (
4+
"errors"
5+
"os"
6+
"os/exec"
7+
8+
"github.com/urfave/cli/v2"
9+
)
10+
11+
var ark = cli.Command{
12+
Name: "ark",
13+
Usage: "invoke ark client commands",
14+
Action: arkAction,
15+
Flags: []cli.Flag{
16+
&cli.BoolFlag{
17+
Name: "version",
18+
Aliases: []string{"v"},
19+
Usage: "print version",
20+
},
21+
},
22+
}
23+
24+
var arkd = cli.Command{
25+
Name: "arkd",
26+
Usage: "invoke arkd client commands",
27+
Action: arkdAction,
28+
Flags: []cli.Flag{
29+
&cli.BoolFlag{
30+
Name: "version",
31+
Aliases: []string{"v"},
32+
Usage: "print version",
33+
},
34+
},
35+
}
36+
37+
func arkAction(ctx *cli.Context) error {
38+
if ctx.Bool("version") {
39+
return runArkCommand(ctx, "ark", "--version")
40+
}
41+
return runArkCommand(ctx, "ark", ctx.Args().Slice()...)
42+
}
43+
44+
func arkdAction(ctx *cli.Context) error {
45+
if ctx.Bool("version") {
46+
return runArkCommand(ctx, "arkd", "--version")
47+
}
48+
args := ctx.Args().Slice()
49+
// Add default flags
50+
args = append([]string{"--no-macaroon"}, args...)
51+
return runArkCommand(ctx, "arkd", args...)
52+
}
53+
54+
func runArkCommand(ctx *cli.Context, binary string, args ...string) error {
55+
if isRunning, _ := nigiriState.GetBool("running"); !isRunning {
56+
return errors.New("nigiri is not running")
57+
}
58+
59+
isArkEnabled, _ := nigiriState.GetBool("ark")
60+
if !isArkEnabled {
61+
return errors.New("ark is not enabled. Start nigiri with --ark flag")
62+
}
63+
64+
// Build the docker exec command
65+
cmd := []string{"exec", "ark", binary}
66+
67+
// Pass through all arguments
68+
cmd = append(cmd, args...)
69+
70+
// Run the command
71+
dockerCmd := exec.Command("docker", cmd...)
72+
dockerCmd.Stdout = os.Stdout
73+
dockerCmd.Stderr = os.Stderr
74+
75+
if err := dockerCmd.Run(); err != nil {
76+
// The error is already printed to stderr
77+
return err
78+
}
79+
80+
return nil
81+
}

cmd/nigiri/faucet.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ func faucetAction(ctx *cli.Context) error {
4646
serviceName = "chopsticks-liquid"
4747
}
4848

49-
portSlice, err := docker.GetPortsForService(composePath, serviceName)
49+
// Get the port for the service
50+
dockerClient := docker.NewDefaultClient()
51+
portSlice, err := dockerClient.GetPortsForService(composePath, serviceName)
5052
if err != nil {
5153
return err
5254
}

cmd/nigiri/main.go

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ var datadirFlag = cli.StringFlag{
4242
Value: config.DefaultDatadir,
4343
}
4444

45+
var arkFlag = cli.BoolFlag{
46+
Name: "ark",
47+
Usage: "enable Ark Network",
48+
Value: false,
49+
}
50+
4551
//go:embed resources/docker-compose.yml
4652
//go:embed resources/bitcoin.conf
4753
//go:embed resources/elements.conf
@@ -54,22 +60,30 @@ func main() {
5460
app.Version = formatVersion()
5561
app.Name = "nigiri CLI"
5662
app.Usage = "one-click bitcoin development environment"
57-
app.Flags = append(app.Flags, &datadirFlag)
58-
app.Commands = append(
59-
app.Commands,
60-
&rpc,
61-
&lnd,
62-
&cln,
63+
app.Flags = append(app.Flags, &datadirFlag, &arkFlag)
64+
app.Commands = []*cli.Command{
65+
// Core commands
66+
&start,
6367
&stop,
6468
&logs,
69+
&update,
70+
&versionCmd,
71+
72+
// Bitcoin and Elements RPCs
73+
&rpc,
74+
&faucet,
6575
&mint,
6676
&push,
77+
78+
// Ark commands
79+
&ark,
80+
&arkd,
81+
82+
// Lightning commands
83+
&cln,
84+
&lnd,
6785
&tap,
68-
&start,
69-
&update,
70-
&faucet,
71-
&versionCmd,
72-
)
86+
}
7387

7488
app.Before = func(ctx *cli.Context) error {
7589

@@ -132,6 +146,8 @@ func provisionResourcesToDatadir(datadir string) error {
132146
filepath.Join(datadir, "volumes", "lnd"),
133147
filepath.Join(datadir, "volumes", "lightningd"),
134148
filepath.Join(datadir, "volumes", "tapd"),
149+
filepath.Join(datadir, "volumes", "ark", "data"),
150+
filepath.Join(datadir, "volumes", "ark", "wallet"),
135151
}
136152

137153
for _, dir := range volumeDirs {

cmd/nigiri/mint.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ func mintAction(ctx *cli.Context) error {
3838

3939
serviceName := "chopsticks-liquid"
4040

41-
portSlice, err := docker.GetPortsForService(composePath, serviceName)
41+
// Get the port for the service
42+
dockerClient := docker.NewDefaultClient()
43+
portSlice, err := dockerClient.GetPortsForService(composePath, serviceName)
4244
if err != nil {
4345
return err
4446
}

cmd/nigiri/push.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ func pushAction(ctx *cli.Context) error {
4343
serviceName = "chopsticks-liquid"
4444
}
4545

46-
portSlice, err := docker.GetPortsForService(composePath, serviceName)
46+
// Get the port for the service
47+
dockerClient := docker.NewDefaultClient()
48+
portSlice, err := dockerClient.GetPortsForService(composePath, serviceName)
4749
if err != nil {
4850
return err
4951
}

cmd/nigiri/resources/docker-compose.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,33 @@ services:
234234
- ./volumes/lightningd:/.lightning
235235
- ./volumes/bitcoin:/etc/bitcoin
236236

237+
ark:
238+
container_name: ark
239+
image: ghcr.io/ark-network/ark:v0.4.2
240+
user: "${UID:-1000}:${GID:-1000}"
241+
depends_on:
242+
- bitcoin
243+
environment:
244+
ARK_ROUND_INTERVAL: "15"
245+
ARK_LOG_LEVEL: "5"
246+
ARK_NETWORK: "regtest"
247+
ARK_PORT: "7070"
248+
ARK_NO_TLS: "true"
249+
ARK_NO_MACAROONS: "true"
250+
ARK_TX_BUILDER_TYPE: "covenantless"
251+
ARK_BITCOIND_RPC_USER: "admin1"
252+
ARK_BITCOIND_RPC_PASS: "123"
253+
ARK_BITCOIND_RPC_HOST: "bitcoin:18443"
254+
ARK_BITCOIND_ZMQ_BLOCK: "tcp://bitcoin:28332"
255+
ARK_BITCOIND_ZMQ_TX: "tcp://bitcoin:28333"
256+
ARK_DATADIR: "/app/data"
257+
volumes:
258+
- ./volumes/ark/data:/app/data
259+
- ./volumes/ark/wallet:/app/wallet-data
260+
ports:
261+
- "7070:7070"
262+
restart: unless-stopped
263+
237264
networks:
238265
default:
239266
name: nigiri

0 commit comments

Comments
 (0)