Skip to content

Commit

Permalink
service: add ark-network/ark (#202)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tiero authored Dec 28, 2024
1 parent 32bd838 commit 16cd19c
Show file tree
Hide file tree
Showing 19 changed files with 878 additions and 441 deletions.
27 changes: 14 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Go
name: Go Tests

on:
push:
Expand All @@ -7,25 +7,26 @@ on:
branches: [master]

jobs:
integration:
name: Unit Tests
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ">1.17.2"
go-version: '1.23.4'
cache: true

- name: Get dependencies
run: go get -v -t -d ./...
- name: Code Format Check
run: make fmt

- name: Test
run: |
make fmt
make install
make test-ci
- name: Code Analysis
run: make vet

- name: Run Tests
run: make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
.env

cmd/nigiri/resources/volumes/
vendor/
build/
dist/
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,8 @@ test: clean install
@echo "Testing..."
go test -v -count=1 -race ./...

## test-ci: runs travis tests
test-ci: clean
@echo "Testing..."
go test -short -v ./...

## cov: generates coverage report
cov:
@echo "Coverage..."
go test -cover ./...
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
40 changes: 35 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# 🍣 Nigiri Bitcoin

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.
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:

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.
* **Bitcoin Node**: A Bitcoin Core node running in regtest mode
* **Electrum**: Backend and frontend explorer for quick blockchain inspection
* **Chopsticks**: A [JSON HTTP proxy](https://github.com/vulpemventures/nigiri-chopsticks) that adds handy endpoints like `/faucet` and automatic block generation

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


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

```
$ nigiri start --liquid
$ nigiri start --ark
```
**That's it.**

Go to http://localhost:5000 for quickly inspect the Bitcoin blockchain or http://localhost:5001 for Liquid.
Go to http://localhost:5000 for quickly inspect the Bitcoin blockchain.

Want more? Add Elements/Liquid or Lightning nodes:
```bash
$ nigiri start --ark --liquid # Add Elements/Liquid sidechain
$ nigiri start --ark --ln # Add Lightning Network nodes
```

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

### Use the Ark CLI inside the box

```bash
# Check versions
$ nigiri ark --version # or -v
$ nigiri arkd --version # or -v

# Initialize the Ark client (only needed once)
$ nigiri ark init --network regtest --password secret --server-url localhost:7070 --explorer http://chopsticks:3000

# Use the Ark client
$ nigiri ark config # Show wallet configuration
$ nigiri ark receive # Show receiving addresses
$ nigiri ark balance # Show wallet balance

# Use the Ark daemon client
$ nigiri arkd wallet status # Show wallet status
$ nigiri arkd wallet create --password secret # Create a new wallet
$ nigiri arkd wallet unlock --password secret # Unlock the wallet
```

### Run in headless mode (without Esplora)
If you are looking to spin-up Nigiri in Travis or Github Action you can use the `--ci` flag.
Expand Down
81 changes: 81 additions & 0 deletions cmd/nigiri/ark.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package main

import (
"errors"
"os"
"os/exec"

"github.com/urfave/cli/v2"
)

var ark = cli.Command{
Name: "ark",
Usage: "invoke ark client commands",
Action: arkAction,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "print version",
},
},
}

var arkd = cli.Command{
Name: "arkd",
Usage: "invoke arkd client commands",
Action: arkdAction,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "print version",
},
},
}

func arkAction(ctx *cli.Context) error {
if ctx.Bool("version") {
return runArkCommand(ctx, "ark", "--version")
}
return runArkCommand(ctx, "ark", ctx.Args().Slice()...)
}

func arkdAction(ctx *cli.Context) error {
if ctx.Bool("version") {
return runArkCommand(ctx, "arkd", "--version")
}
args := ctx.Args().Slice()
// Add default flags
args = append([]string{"--no-macaroon"}, args...)
return runArkCommand(ctx, "arkd", args...)
}

func runArkCommand(ctx *cli.Context, binary string, args ...string) error {
if isRunning, _ := nigiriState.GetBool("running"); !isRunning {
return errors.New("nigiri is not running")
}

isArkEnabled, _ := nigiriState.GetBool("ark")
if !isArkEnabled {
return errors.New("ark is not enabled. Start nigiri with --ark flag")
}

// Build the docker exec command
cmd := []string{"exec", "ark", binary}

// Pass through all arguments
cmd = append(cmd, args...)

// Run the command
dockerCmd := exec.Command("docker", cmd...)
dockerCmd.Stdout = os.Stdout
dockerCmd.Stderr = os.Stderr

if err := dockerCmd.Run(); err != nil {
// The error is already printed to stderr
return err
}

return nil
}
4 changes: 3 additions & 1 deletion cmd/nigiri/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ func faucetAction(ctx *cli.Context) error {
serviceName = "chopsticks-liquid"
}

portSlice, err := docker.GetPortsForService(composePath, serviceName)
// Get the port for the service
dockerClient := docker.NewDefaultClient()
portSlice, err := dockerClient.GetPortsForService(composePath, serviceName)
if err != nil {
return err
}
Expand Down
38 changes: 27 additions & 11 deletions cmd/nigiri/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ var datadirFlag = cli.StringFlag{
Value: config.DefaultDatadir,
}

var arkFlag = cli.BoolFlag{
Name: "ark",
Usage: "enable Ark Network",
Value: false,
}

//go:embed resources/docker-compose.yml
//go:embed resources/bitcoin.conf
//go:embed resources/elements.conf
Expand All @@ -54,22 +60,30 @@ func main() {
app.Version = formatVersion()
app.Name = "nigiri CLI"
app.Usage = "one-click bitcoin development environment"
app.Flags = append(app.Flags, &datadirFlag)
app.Commands = append(
app.Commands,
&rpc,
&lnd,
&cln,
app.Flags = append(app.Flags, &datadirFlag, &arkFlag)
app.Commands = []*cli.Command{
// Core commands
&start,
&stop,
&logs,
&update,
&versionCmd,

// Bitcoin and Elements RPCs
&rpc,
&faucet,
&mint,
&push,

// Ark commands
&ark,
&arkd,

// Lightning commands
&cln,
&lnd,
&tap,
&start,
&update,
&faucet,
&versionCmd,
)
}

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

Expand Down Expand Up @@ -132,6 +146,8 @@ func provisionResourcesToDatadir(datadir string) error {
filepath.Join(datadir, "volumes", "lnd"),
filepath.Join(datadir, "volumes", "lightningd"),
filepath.Join(datadir, "volumes", "tapd"),
filepath.Join(datadir, "volumes", "ark", "data"),
filepath.Join(datadir, "volumes", "ark", "wallet"),
}

for _, dir := range volumeDirs {
Expand Down
4 changes: 3 additions & 1 deletion cmd/nigiri/mint.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func mintAction(ctx *cli.Context) error {

serviceName := "chopsticks-liquid"

portSlice, err := docker.GetPortsForService(composePath, serviceName)
// Get the port for the service
dockerClient := docker.NewDefaultClient()
portSlice, err := dockerClient.GetPortsForService(composePath, serviceName)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/nigiri/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func pushAction(ctx *cli.Context) error {
serviceName = "chopsticks-liquid"
}

portSlice, err := docker.GetPortsForService(composePath, serviceName)
// Get the port for the service
dockerClient := docker.NewDefaultClient()
portSlice, err := dockerClient.GetPortsForService(composePath, serviceName)
if err != nil {
return err
}
Expand Down
27 changes: 27 additions & 0 deletions cmd/nigiri/resources/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,33 @@ services:
- ./volumes/lightningd:/.lightning
- ./volumes/bitcoin:/etc/bitcoin

ark:
container_name: ark
image: ghcr.io/ark-network/ark:v0.4.2
user: "${UID:-1000}:${GID:-1000}"
depends_on:
- bitcoin
environment:
ARK_ROUND_INTERVAL: "15"
ARK_LOG_LEVEL: "5"
ARK_NETWORK: "regtest"
ARK_PORT: "7070"
ARK_NO_TLS: "true"
ARK_NO_MACAROONS: "true"
ARK_TX_BUILDER_TYPE: "covenantless"
ARK_BITCOIND_RPC_USER: "admin1"
ARK_BITCOIND_RPC_PASS: "123"
ARK_BITCOIND_RPC_HOST: "bitcoin:18443"
ARK_BITCOIND_ZMQ_BLOCK: "tcp://bitcoin:28332"
ARK_BITCOIND_ZMQ_TX: "tcp://bitcoin:28333"
ARK_DATADIR: "/app/data"
volumes:
- ./volumes/ark/data:/app/data
- ./volumes/ark/wallet:/app/wallet-data
ports:
- "7070:7070"
restart: unless-stopped

networks:
default:
name: nigiri
Loading

0 comments on commit 16cd19c

Please sign in to comment.