Files
Hanzo AI ff32c62328 cmd/rlp-export: admin_exportChain CLI wrapper (Task #118)
Symmetric with cmd/rlp-import. Thin HTTP client that:

  1. Idempotency precheck reads <output-file>.sentinel on the local PVC
     and short-circuits when Status=done + range matches — luxd is never
     contacted in the warm-cron case.
  2. Health-probes ${LuxdRPC}/ext/health (30s cap).
  3. POSTs admin_exportChain via /ext/bc/${chain}/rpc with KMS_AUTH_TOKEN
     bearer auth (same env-var contract as rlp-import).
  4. Maps Status → exit code:
       ok | noop      → 0
       interrupted    → 4 (operator re-runs with from-height=HighestExported+1)
       bad input      → 1
       luxd unreach   → 2
       admin RPC err  → 3

Lives in the cmd/ nested module per the existing rlp-import precedent.
Builds with GOWORK=off; Makefile target `make rlp-export` does this for you.

Tests cover: flag parsing, "latest" resolution, all four idempotency
fall-through branches, happy path + noop + interrupted server responses,
luxd unreachable, admin RPC error, KMS_AUTH_TOKEN bearer header
plumbing. 14 tests, all green.

Symmetric Makefile additions: `make rlp-export`, `make rlp-import`,
`make cmds`, `make test-rlp-export`.
2026-06-05 00:29:10 -07:00

89 lines
1.8 KiB
Makefile

# Genesis Makefile
.PHONY: build test clean lint fmt vet
# Build output directory
BIN_DIR := bin
# Binary name
BINARY := genesis
# Go parameters
GOCMD := go
GOBUILD := $(GOCMD) build
GOTEST := $(GOCMD) test
GOVET := $(GOCMD) vet
GOFMT := gofmt
GOMOD := $(GOCMD) mod
# Build flags
LDFLAGS := -s -w
# Default target
all: build
# Build the binary
build:
@mkdir -p $(BIN_DIR)
$(GOBUILD) -ldflags="$(LDFLAGS)" -o $(BIN_DIR)/$(BINARY) ./cmd/genesis
# Build the rlp-export CLI (admin_exportChain wrapper).
# Lives in the nested cmd/ module so it builds with GOWORK=off, same as
# its sibling cmd/rlp-import.
.PHONY: rlp-export
rlp-export:
@mkdir -p $(BIN_DIR)
cd cmd/rlp-export && GOWORK=off $(GOBUILD) -ldflags="$(LDFLAGS)" -o ../../$(BIN_DIR)/rlp-export .
# Build the rlp-import CLI (admin_importChain wrapper) — symmetric with rlp-export.
.PHONY: rlp-import
rlp-import:
@mkdir -p $(BIN_DIR)
cd cmd/rlp-import && GOWORK=off $(GOBUILD) -ldflags="$(LDFLAGS)" -o ../../$(BIN_DIR)/rlp-import .
# Build everything in cmd/ (genesis + rlp-export + rlp-import).
.PHONY: cmds
cmds: build rlp-export rlp-import
# Run tests for the rlp-export tool (uses GOWORK=off for the nested module).
.PHONY: test-rlp-export
test-rlp-export:
cd cmd/rlp-export && GOWORK=off $(GOTEST) -v -race .
# Run tests
test:
$(GOTEST) -v -race ./...
# Run tests with coverage
test-coverage:
$(GOTEST) -v -race -coverprofile=coverage.txt -covermode=atomic ./...
# Clean build artifacts
clean:
rm -rf $(BIN_DIR)
rm -f coverage.txt
# Run linter
lint:
golangci-lint run --timeout=5m
# Format code
fmt:
$(GOFMT) -w .
# Run go vet
vet:
$(GOVET) ./...
# Download dependencies
deps:
$(GOMOD) download
# Tidy dependencies
tidy:
$(GOMOD) tidy
# Install binary to GOPATH/bin
install: build
cp $(BIN_DIR)/$(BINARY) $(GOPATH)/bin/