mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-17 04:04:21 +01:00
Rename folders (#97)
* Rename arkd folder & drop cli * Rename ark cli folder & update docs * Update readme * Fix * scripts: add build-all * Add target to build cli for all platforms * Update build scripts --------- Co-authored-by: tiero <3596602+tiero@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
0d8c7bffb2
commit
dc00d60585
4
.github/workflows/ark.intergation.yaml
vendored
4
.github/workflows/ark.intergation.yaml
vendored
@@ -5,7 +5,7 @@ on:
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- "asp/**"
|
||||
- "server/**"
|
||||
|
||||
jobs:
|
||||
test:
|
||||
@@ -13,7 +13,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ./asp
|
||||
working-directory: ./server
|
||||
steps:
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
|
||||
4
.github/workflows/ark.release.yaml
vendored
4
.github/workflows/ark.release.yaml
vendored
@@ -6,14 +6,14 @@ on:
|
||||
tags:
|
||||
- "*"
|
||||
paths:
|
||||
- "asp/**"
|
||||
- "server/**"
|
||||
|
||||
jobs:
|
||||
goreleaser:
|
||||
runs-on: ubuntu-20.04
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ./asp
|
||||
working-directory: ./server
|
||||
env:
|
||||
DOCKER_CLI_EXPERIMENTAL: "enabled"
|
||||
|
||||
|
||||
8
.github/workflows/ark.unit.yaml
vendored
8
.github/workflows/ark.unit.yaml
vendored
@@ -3,13 +3,13 @@ name: ci_unit
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- "asp/**"
|
||||
- "server/**"
|
||||
branches: [master]
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- "asp/**"
|
||||
- "server/**"
|
||||
|
||||
jobs:
|
||||
test:
|
||||
@@ -17,7 +17,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ./asp
|
||||
working-directory: ./server
|
||||
steps:
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
@@ -27,7 +27,7 @@ jobs:
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
with:
|
||||
version: v1.54
|
||||
working-directory: ./asp
|
||||
working-directory: ./server
|
||||
- name: check code integrity
|
||||
uses: securego/gosec@master
|
||||
with:
|
||||
|
||||
@@ -11,7 +11,7 @@ WORKDIR /app
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN cd asp && CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-X 'main.Version=${COMMIT}' -X 'main.Commit=${COMMIT}' -X 'main.Date=${COMMIT}'" -o ../bin/arkd cmd/arkd/main.go
|
||||
RUN cd server && CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-X 'main.Version=${COMMIT}' -X 'main.Commit=${COMMIT}' -X 'main.Date=${COMMIT}'" -o ../bin/arkd cmd/arkd/main.go
|
||||
|
||||
# Second image, running the arkd executable
|
||||
FROM debian:buster-slim
|
||||
|
||||
@@ -6,8 +6,8 @@ Welcome to the Ark monorepo.
|
||||
|
||||
In this repository you can find:
|
||||
|
||||
- `asp` - a proof of concept of an Ark Service Provider.
|
||||
- `server` - a proof of concept of an Ark Service Provider.
|
||||
- `website` - the website where to find documentation about Ark protocol and products.
|
||||
- `noah` - the initial Ark wallet, served as CLI.
|
||||
- `client` - the initial Ark wallet, served as CLI.
|
||||
|
||||
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
rpcServerFlag = &cli.StringFlag{
|
||||
Name: "rpcserver",
|
||||
Usage: "the addr of the arkd to connect to in the form <host>:<port>",
|
||||
Value: defaultRpcServer,
|
||||
}
|
||||
noTlsFlag = &cli.BoolFlag{
|
||||
Name: "no-tls",
|
||||
Usage: "used to disable TLS termination",
|
||||
Value: false,
|
||||
}
|
||||
)
|
||||
|
||||
var configCommand = &cli.Command{
|
||||
Name: "config",
|
||||
Usage: "Print local configuration of the ark CLI",
|
||||
Action: printConfigAction,
|
||||
Subcommands: []*cli.Command{
|
||||
{
|
||||
Name: "init",
|
||||
Usage: "initialize the CLI state with flags",
|
||||
Action: configInitAction,
|
||||
Flags: []cli.Flag{rpcServerFlag, noTlsFlag},
|
||||
},
|
||||
{
|
||||
Name: "set",
|
||||
Usage: "set a <key> <value> in the local state",
|
||||
Action: configSetAction,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func printConfigAction(ctx *cli.Context) error {
|
||||
state, err := getState()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for key, value := range state {
|
||||
fmt.Println(key + ": " + value)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func configInitAction(ctx *cli.Context) error {
|
||||
return setState(map[string]string{
|
||||
"rpcserver": ctx.String("rpcserver"),
|
||||
"no-tls": strconv.FormatBool(ctx.Bool("no-tls")),
|
||||
})
|
||||
}
|
||||
|
||||
func configSetAction(c *cli.Context) error {
|
||||
if c.NArg() < 2 {
|
||||
return fmt.Errorf("key and/or value are missing")
|
||||
}
|
||||
|
||||
key := c.Args().Get(0)
|
||||
value := c.Args().Get(1)
|
||||
|
||||
if value == "" {
|
||||
return fmt.Errorf("value must not be an empty string")
|
||||
}
|
||||
|
||||
if err := setState(map[string]string{key: value}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("%s %s has been set\n", key, value)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,209 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
arkv1 "github.com/ark-network/ark/api-spec/protobuf/gen/ark/v1"
|
||||
"github.com/ark-network/ark/common"
|
||||
"github.com/gogo/protobuf/jsonpb"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/urfave/cli/v2"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
const (
|
||||
DATADIR_ENVVAR = "ARK_CLI_DATADIR"
|
||||
STATE_FILE = "state.json"
|
||||
)
|
||||
|
||||
var (
|
||||
version = "alpha"
|
||||
|
||||
datadir = common.AppDataDir("ark", false)
|
||||
statePath = filepath.Join(datadir, STATE_FILE)
|
||||
|
||||
defaultRpcServer = "localhost:6000"
|
||||
defaultNoTls = true
|
||||
|
||||
initialState = map[string]string{
|
||||
"rpcserver": defaultRpcServer,
|
||||
"no-tls": strconv.FormatBool(defaultNoTls),
|
||||
}
|
||||
)
|
||||
|
||||
func initCLIEnv() {
|
||||
dir := cleanAndExpandPath(os.Getenv(DATADIR_ENVVAR))
|
||||
if len(dir) <= 0 {
|
||||
return
|
||||
}
|
||||
datadir = dir
|
||||
statePath = filepath.Join(dir, STATE_FILE)
|
||||
}
|
||||
|
||||
func main() {
|
||||
initCLIEnv()
|
||||
|
||||
app := cli.NewApp()
|
||||
|
||||
app.Version = version
|
||||
app.Name = "Ark CLI"
|
||||
app.Usage = "Command line interface to interact with arkd"
|
||||
app.Commands = append(app.Commands, configCommand, roundCommand)
|
||||
|
||||
app.Before = func(ctx *cli.Context) error {
|
||||
if _, err := os.Stat(datadir); os.IsNotExist(err) {
|
||||
return os.Mkdir(datadir, os.ModeDir|0755)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
fmt.Println(fmt.Errorf("error: %v", err))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// cleanAndExpandPath expands environment variables and leading ~ in the
|
||||
// passed path, cleans the result, and returns it.
|
||||
// This function is taken from https://github.com/btcsuite/btcd
|
||||
func cleanAndExpandPath(path string) string {
|
||||
if path == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Expand initial ~ to OS specific home directory.
|
||||
if strings.HasPrefix(path, "~") {
|
||||
var homeDir string
|
||||
u, err := user.Current()
|
||||
if err == nil {
|
||||
homeDir = u.HomeDir
|
||||
} else {
|
||||
homeDir = os.Getenv("HOME")
|
||||
}
|
||||
|
||||
path = strings.Replace(path, "~", homeDir, 1)
|
||||
}
|
||||
|
||||
// NOTE: The os.ExpandEnv doesn't work with Windows-style %VARIABLE%,
|
||||
// but the variables can still be expanded via POSIX-style $VARIABLE.
|
||||
return filepath.Clean(os.ExpandEnv(path))
|
||||
}
|
||||
|
||||
func getState() (map[string]string, error) {
|
||||
file, err := os.ReadFile(statePath)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return nil, err
|
||||
}
|
||||
if err := setInitialState(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return initialState, nil
|
||||
}
|
||||
|
||||
data := map[string]string{}
|
||||
if err := json.Unmarshal(file, &data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func setInitialState() error {
|
||||
jsonString, err := json.Marshal(initialState)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(statePath, jsonString, 0755)
|
||||
}
|
||||
|
||||
func setState(data map[string]string) error {
|
||||
currentData, err := getState()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mergedData := merge(currentData, data)
|
||||
|
||||
jsonString, err := json.Marshal(mergedData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.WriteFile(statePath, jsonString, 0755)
|
||||
if err != nil {
|
||||
return fmt.Errorf("writing to file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func merge(maps ...map[string]string) map[string]string {
|
||||
merge := make(map[string]string, 0)
|
||||
for _, m := range maps {
|
||||
for k, v := range m {
|
||||
merge[k] = v
|
||||
}
|
||||
}
|
||||
return merge
|
||||
}
|
||||
|
||||
func printRespJSON(resp interface{}) {
|
||||
jsonMarshaler := &jsonpb.Marshaler{
|
||||
EmitDefaults: true,
|
||||
OrigName: true,
|
||||
Indent: "\t", // Matches indentation of printJSON.
|
||||
}
|
||||
|
||||
jsonStr, err := jsonMarshaler.MarshalToString(resp.(proto.Message))
|
||||
if err != nil {
|
||||
fmt.Println("unable to decode response: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(jsonStr)
|
||||
}
|
||||
|
||||
func getServiceClient() (arkv1.ArkServiceClient, func(), error) {
|
||||
conn, err := getClientConn()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
cleanup := func() { conn.Close() }
|
||||
|
||||
return arkv1.NewArkServiceClient(conn), cleanup, nil
|
||||
}
|
||||
|
||||
func getClientConn() (*grpc.ClientConn, error) {
|
||||
state, err := getState()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
address, ok := state["rpcserver"]
|
||||
if !ok {
|
||||
return nil, errors.New("set rpcserver with `config set rpcserver`")
|
||||
}
|
||||
|
||||
opts := []grpc.DialOption{grpc.WithDefaultCallOptions()}
|
||||
|
||||
noTls, _ := strconv.ParseBool(state["no-tls"])
|
||||
if !noTls {
|
||||
return nil, fmt.Errorf("secure connection not supported yet")
|
||||
}
|
||||
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
|
||||
conn, err := grpc.Dial(address, opts...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to connect to RPC server: %v",
|
||||
err)
|
||||
}
|
||||
|
||||
return conn, nil
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
arkv1 "github.com/ark-network/ark/api-spec/protobuf/gen/ark/v1"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
roundTxidFlag = &cli.StringFlag{
|
||||
Name: "txid",
|
||||
Usage: "the hash of a broadcasted pool transaction",
|
||||
}
|
||||
currentFlag = &cli.BoolFlag{
|
||||
Name: "current",
|
||||
Usage: "info about the status of the ongoing round",
|
||||
Value: false,
|
||||
}
|
||||
)
|
||||
|
||||
var roundCommand = &cli.Command{
|
||||
Name: "round",
|
||||
Usage: "Get info about an ark round",
|
||||
Action: getRoundAction,
|
||||
Flags: []cli.Flag{roundTxidFlag, currentFlag},
|
||||
}
|
||||
|
||||
func getRoundAction(ctx *cli.Context) error {
|
||||
client, cleanup, err := getServiceClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
txid := ctx.String("txid")
|
||||
current := ctx.Bool("current")
|
||||
|
||||
if txid == "" && !current {
|
||||
return fmt.Errorf("missing flag, please provide either --txid or --current")
|
||||
}
|
||||
|
||||
if current {
|
||||
return fmt.Errorf("not supported yet")
|
||||
}
|
||||
|
||||
res, err := client.GetRound(context.Background(), &arkv1.GetRoundRequest{Txid: txid})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printRespJSON(res)
|
||||
return nil
|
||||
}
|
||||
0
noah/.gitignore → client/.gitignore
vendored
0
noah/.gitignore → client/.gitignore
vendored
@@ -1,9 +1,13 @@
|
||||
.PHONY: build clean help lint vet
|
||||
.PHONY: build build-all clean help lint vet
|
||||
|
||||
build:
|
||||
@echo "Building noah binary..."
|
||||
@echo "Building binary..."
|
||||
@bash ./scripts/build
|
||||
|
||||
build-all:
|
||||
@echo "Building binary..."
|
||||
@bash ./scripts/build-all
|
||||
|
||||
## clean: cleans the binary
|
||||
clean:
|
||||
@echo "Cleaning..."
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
var balanceCommand = cli.Command{
|
||||
Name: "balance",
|
||||
Usage: "Print balance of the Noah wallet",
|
||||
Usage: "Print balance of the Ark wallet",
|
||||
Action: balanceAction,
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
var configCommand = cli.Command{
|
||||
Name: "config",
|
||||
Usage: "Print local configuration of the Noah CLI",
|
||||
Usage: "Print local configuration of the Ark CLI",
|
||||
Action: printConfigAction,
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
module github.com/ark-network/noah
|
||||
module github.com/ark-network/ark-cli
|
||||
|
||||
go 1.21.0
|
||||
|
||||
replace github.com/ark-network/ark/common => ../common
|
||||
|
||||
replace github.com/ark-network/ark => ../asp
|
||||
replace github.com/ark-network/ark => ../server
|
||||
|
||||
require (
|
||||
github.com/ark-network/ark v0.0.0-00010101000000-000000000000
|
||||
@@ -14,24 +14,23 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
DATADIR_ENVVAR = "NOAH_DATADIR"
|
||||
DATADIR_ENVVAR = "ARK_WALLET_DATADIR"
|
||||
STATE_FILE = "state.json"
|
||||
defaultArkURL = "localhost:6000"
|
||||
defaultNetwork = "testnet"
|
||||
)
|
||||
|
||||
var (
|
||||
version = "alpha"
|
||||
|
||||
noahDataDirectory = common.AppDataDir("noah", false)
|
||||
statePath = filepath.Join(noahDataDirectory, STATE_FILE)
|
||||
datadir = common.AppDataDir("ark-cli", false)
|
||||
statePath = filepath.Join(datadir, STATE_FILE)
|
||||
explorerUrl = map[string]string{
|
||||
network.Liquid.Name: "https://blockstream.info/liquid/api",
|
||||
network.Testnet.Name: "https://blockstream.info/liquidtestnet/api",
|
||||
}
|
||||
|
||||
initialState = map[string]string{
|
||||
"ark_url": defaultArkURL,
|
||||
"ark_url": "",
|
||||
"ark_pubkey": "",
|
||||
"encrypted_private_key": "",
|
||||
"password_hash": "",
|
||||
@@ -41,13 +40,13 @@ var (
|
||||
)
|
||||
|
||||
func initCLIEnv() {
|
||||
dataDir := cleanAndExpandPath(os.Getenv(DATADIR_ENVVAR))
|
||||
if len(dataDir) <= 0 {
|
||||
dir := cleanAndExpandPath(os.Getenv(DATADIR_ENVVAR))
|
||||
if len(dir) <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
noahDataDirectory = dataDir
|
||||
statePath = filepath.Join(noahDataDirectory, STATE_FILE)
|
||||
datadir = dir
|
||||
statePath = filepath.Join(datadir, STATE_FILE)
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -56,8 +55,8 @@ func main() {
|
||||
app := cli.NewApp()
|
||||
|
||||
app.Version = version
|
||||
app.Name = "noah CLI"
|
||||
app.Usage = "Command line interface for Ark wallet"
|
||||
app.Name = "Ark CLI"
|
||||
app.Usage = "command line interface for Ark wallet"
|
||||
app.Commands = append(
|
||||
app.Commands,
|
||||
&balanceCommand,
|
||||
@@ -70,8 +69,8 @@ func main() {
|
||||
)
|
||||
|
||||
app.Before = func(ctx *cli.Context) error {
|
||||
if _, err := os.Stat(noahDataDirectory); os.IsNotExist(err) {
|
||||
return os.Mkdir(noahDataDirectory, os.ModeDir|0755)
|
||||
if _, err := os.Stat(datadir); os.IsNotExist(err) {
|
||||
return os.Mkdir(datadir, os.ModeDir|0755)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -12,5 +12,5 @@ ARCH=$(eval "go env GOARCH")
|
||||
|
||||
pushd $PARENT_PATH
|
||||
mkdir -p build
|
||||
GO111MODULE=on go build -ldflags="-s -w" -o build/noah-$OS-$ARCH .
|
||||
GO111MODULE=on go build -ldflags="-s -w" -o build/ark-cli-$OS-$ARCH .
|
||||
popd
|
||||
23
client/scripts/build-all
Executable file
23
client/scripts/build-all
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
PARENT_PATH=$(dirname $(
|
||||
cd $(dirname $0)
|
||||
pwd -P
|
||||
))
|
||||
|
||||
declare -a OS=("darwin" "linux")
|
||||
declare -a ARCH=("amd64" "arm64")
|
||||
|
||||
pushd $PARENT_PATH
|
||||
mkdir -p build
|
||||
|
||||
for os in "${OS[@]}"; do
|
||||
for arch in "${ARCH[@]}"; do
|
||||
echo "Building for $os $arch"
|
||||
GOOS=$os GOARCH=$arch go build -o build/ark-$os-$arch .
|
||||
done
|
||||
done
|
||||
|
||||
popd
|
||||
0
asp/.gitignore → server/.gitignore
vendored
0
asp/.gitignore → server/.gitignore
vendored
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user