Skip to content
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d33dcbb
feat: interactive setup
Maith8Ae Feb 18, 2021
3960911
add --interactive option
Maith8Ae Feb 26, 2021
8c87633
add console
Maith8Ae Feb 26, 2021
982db89
add .backup-unset and implement interactive create/unlock
Maith8Ae Mar 1, 2021
a054bd6
update opendex.sh
Maith8Ae Mar 2, 2021
770715b
fix: opendex-launcher version match
Maith8Ae Mar 3, 2021
3d1684c
fix: macOS OPENDEX_DOCKER_HOME path
Maith8Ae Mar 3, 2021
34dab3c
chore: add warming up
Maith8Ae Mar 3, 2021
25362c2
fix: opendex-launcher version match
Maith8Ae Mar 3, 2021
a75b2f7
chore: refine help text
Maith8Ae Mar 3, 2021
ccceadb
chore: refine launcher help text
Maith8Ae Mar 3, 2021
2de4784
fix: gnu tar cannot extract zip
Maith8Ae Mar 4, 2021
b7bd205
fix: use bash instead of sh
Maith8Ae Mar 4, 2021
efb6c1a
fix: use sh
Maith8Ae Mar 4, 2021
ed39fba
fix: unzip without question
Maith8Ae Mar 4, 2021
fc6c625
fix: read
Maith8Ae Mar 4, 2021
b848fea
chore: add commit hash to the version
Maith8Ae Mar 4, 2021
d19f26e
chore: update launcher version
Maith8Ae Mar 4, 2021
57a164b
use gunzip on linux
Maith8Ae Mar 10, 2021
9700fbe
print table
Maith8Ae Mar 10, 2021
16c454f
fix table
Maith8Ae Mar 10, 2021
b4d9a95
refine container name grepping
Maith8Ae Mar 12, 2021
e33311b
reorder create/unlock functions
Maith8Ae Mar 15, 2021
4ff421b
implement status command
Maith8Ae Mar 17, 2021
85a4404
fix "Container missing"
Maith8Ae Mar 17, 2021
d74b188
bypass unlock error
Maith8Ae Mar 17, 2021
7f56faa
chdir before cleanup
Maith8Ae Mar 17, 2021
8cb9e85
hide "Still waiting..." when light clients syncing
Maith8Ae Mar 17, 2021
797eb20
update banner
Maith8Ae Mar 17, 2021
8c3c55c
add "loading opendex console"
Maith8Ae Mar 17, 2021
2cce34c
show "starting..." when opendexd getinfo got "no connection established"
Maith8Ae Mar 17, 2021
e7cdfdb
replace tabs with spaces in banner
Maith8Ae Mar 17, 2021
4f32ff7
use opendex-launcher down in console
Maith8Ae Mar 17, 2021
9e61060
fix "type not a pointer: string"
Maith8Ae Mar 22, 2021
fb806f3
trim spaces around choice
Maith8Ae Mar 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
name: Build binary launcher
strategy:
matrix:
go-version: [ 1.15.x ]
go-version: [ 1.16.x ]
os: [ linux, darwin, windows ]
arch: [ amd64, arm64 ]
exclude:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
name: Build artifacts
strategy:
matrix:
go-version: [ 1.15.x ]
go-version: [ 1.16.x ]
os: [ linux, darwin, windows ]
arch: [ amd64, arm64 ]
exclude:
Expand Down
22 changes: 21 additions & 1 deletion launcher/cmd/console.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
package cmd

// TODO console
import (
"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(consoleCmd)
}

var consoleCmd = &cobra.Command{
Use: "console",
Short: "Start the console",
PreRunE: func(cmd *cobra.Command, args []string) error {
return launcher.Apply()
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := newContext()
defer cancel()
return launcher.StartConsole(ctx)
},
}

2 changes: 1 addition & 1 deletion launcher/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
var (
rootCmd = &cobra.Command{
Use: "launcher",
Short: fmt.Sprintf("XUD environment launcher"),
Short: fmt.Sprintf("OpenDEX environment launcher"),
SilenceUsage: true,
SilenceErrors: true,
}
Expand Down
4 changes: 3 additions & 1 deletion launcher/cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

type SetupOptions struct {
NoPull bool
Interactive bool
}

var (
Expand All @@ -15,6 +16,7 @@ var (

func init() {
setupCmd.PersistentFlags().BoolVar(&setupOpts.NoPull, "nopull", false, "don't pull images")
setupCmd.PersistentFlags().BoolVarP(&setupOpts.Interactive, "interactive", "i", false, "interactive setup")
rootCmd.AddCommand(setupCmd)
}

Expand All @@ -28,6 +30,6 @@ var setupCmd = &cobra.Command{
ctx, cancel := newContext()
defer cancel()
ctx = context.WithValue(ctx, "rescue", false)
return launcher.Setup(ctx, !setupOpts.NoPull)
return launcher.Setup(ctx, !setupOpts.NoPull, setupOpts.Interactive)
},
}
196 changes: 196 additions & 0 deletions launcher/core/console/bash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package console

import (
"github.com/sirupsen/logrus"
"os"
"os/exec"
)

var logger = logrus.NewEntry(logrus.StandardLogger())

var help = `\
Opendex-cli shortcut commands
addcurrency <currency> add a currency
<swap_client> [decimal_places]
[token_address]
addpair <pair_id|base_currency> add a trading pair
[quote_currency]
ban <node_identifier> ban a remote node
buy <quantity> <pair_id> <price> place a buy order
[order_id]
closechannel <currency> close any payment channels with a
[node_identifier ] [--force] peer
connect <node_uri> connect to a remote node
create create a new opendexd instance and set a
password
discovernodes <node_identifier> discover nodes from a specific peer
getbalance [currency] get total balance for a given
currency
getinfo get general info from the local opendexd
node
getnodeinfo <node_identifier> get general information about a
known node
listcurrencies list available currencies
listorders [pair_id] [owner] list orders from the order book
[limit]
listpairs get order book's available pairs
listpeers list connected peers
openchannel <currency> <amount> open a payment channel with a peer
[node_identifier] [push_amount]
orderbook [pair_id] [precision] display the order book, with orders
aggregated per price point
removecurrency <currency> remove a currency
removeorder <order_id> [quantity] remove an order
removepair <pair_id> remove a trading pair
restore [backup_directory] restore an opendexd instance from seed
sell <quantity> <pair_id> <price> place a sell order
[order_id]
shutdown gracefully shutdown local opendexd node
streamorders [existing] stream order added, removed, and
swapped events (DEMO)
tradehistory [limit] list completed trades
tradinglimits [currency] trading limits for a given currency
unban <node_identifier> unban a previously banned remote
[--reconnect] node
unlock unlock local opendexd node
walletdeposit <currency> gets an address to deposit funds to
opendexd
walletwithdraw [amount] [currency] withdraws on-chain funds from opendexd
[destination] [fee]

General commands
report report issue
logs show service log
start start service
stop stop service
restart restart service
up bring up the environment
help show this help
exit exit opendexd-ctl shell

CLI commands
bitcoin-cli bitcoind cli
litecoin-cli litecoind cli
lndbtc-lncli lnd cli
lndltc-lncli lnd cli
geth geth cli
opendex-cli opendexd cli
boltzcli boltz cli

Boltzcli shortcut commands
boltzcli <chain> deposit
--inbound [inbound_balance] deposit from boltz (btc/ltc)
boltzcli <chain> withdraw
<amount> <address> withdraw from boltz channel
`

func writeInitScript(network string, f *os.File) {
f.WriteString(`\
export NETWORK=` + network + `
export PS1="$NETWORK > "
function help() {
echo "` + help + `"
}
function start() {
docker start ${NETWORK}_${1}_1
}
function stop() {
docker stop ${NETWORK}_${1}_1
}
function restart() {
docker restart ${NETWORK}_${1}_1
}
function down() {
echo "Not implemented yet!"
}
function logs() {
docker logs --tail=100 ${NETWORK}_${1}_1
}
function report() {
cat <<EOF
Please click on https://github.com/opendexnetwork/opendexd/issues/\
new?assignees=kilrau&labels=bug&template=bug-report.md&title=Short%2C+concise+\
description+of+the+bug, describe your issue, drag and drop the file "${NETWORK}\
.log" which is located in "{logs_dir}" into your browser window and submit \
your issue.
EOF
}
function opendex-cli() {
docker exec -it ${NETWORK}_opendexd_1 opendex-cli $@
}
function lndbtc-lncli() {
docker exec -it ${NETWORK}_lndbtc_1 lncli -n ${NETWORK} -c bitcoin $@
}
function lndltc-lncli() {
docker exec -it ${NETWORK}_lndltc_1 lncli -n ${NETWORK} -c litecoin $@
}
function geth() {
docker exec -it ${NETWORK}_geth_1 geth $@
}
function bitcoin-ctl() {
if [[ $NETWORK == "testnet" ]]; then
docker exec -it ${NETWORK}_bitcoind_1 -testnet -user xu -password xu bitcoind $@
else
docker exec -it ${NETWORK}_bitcoind_1 -user xu -password xu bitcoind $@
fi
}
function litecoin-ctl() {
if [[ $NETWORK == "testnet" ]]; then
docker exec -it ${NETWORK}_litecoind_1 -testnet -user xu -password xu litecoind $@
else
docker exec -it ${NETWORK}_litecoind_1 -user xu -password xu litecoind $@
fi
}
function boltzcli() {
docker exec -it ${NETWORK}_boltz_1 wrapper $@
}

alias getinfo='opendex-cli getinfo'
alias addcurrency='opendex-cli addcurrency'
alias addpair='opendex-cli addpair'
alias ban='opendex-cli ban'
alias buy='opendex-cli buy'
alias closechannel='opendex-cli closechannel'
alias connect='opendex-cli connect'
alias create='opendex-cli create'
alias discovernodes='opendex-cli discovernodes'
alias getbalance='opendex-cli getbalance'
alias getnodeinfo='opendex-cli getnodeinfo'
alias listcurrencies='opendex-cli listcurrencies'
alias listorders='opendex-cli listorders'
alias listpairs='opendex-cli listpairs'
alias listpeers='opendex-cli listpeers'
alias openchannel='opendex-cli openchannel'
alias orderbook='opendex-cli orderbook'
alias removeallorders='opendex-cli removeallorders'
alias removecurrency='opendex-cli removecurrency'
alias removeorder='opendex-cli removeorder'
alias removepair='opendex-cli removepair'
alias restore='opendex-cli restore'
alias sell='opendex-cli sell'
alias shutdown='opendex-cli shutdown'
alias streamorders='opendex-cli streamorders'
alias tradehistory='opendex-cli tradehistory'
alias tradinglimits='opendex-cli tradinglimits'
alias unban='opendex-cli unban'
alias unlock='opendex-cli unlock'
alias walletdeposit='opendex-cli walletdeposit'
alias walletwithdraw='opendex-cli walletwithdraw'
`)
}

func startBash() error {
network := os.Getenv("NETWORK")
f, err := os.CreateTemp(os.TempDir(), "init.*.bash")
if err != nil {
logger.Errorf("Failed to write init.bash: %s", err)
return nil
}
defer f.Close()
writeInitScript(network, f)
c := exec.Command("bash", "--init-file", f.Name())
c.Stdin = os.Stdin
c.Stdout = os.Stdout
c.Stderr = os.Stderr
return c.Run()
}
43 changes: 43 additions & 0 deletions launcher/core/console/console.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package console

import (
"fmt"
"runtime"
)

const (
DefaultBanner = `
.___ __ .__
__| _/____ ___ ___ _____/ |_| |
/ __ |/ __ \\ \/ / _/ ___\ __\ |
/ /_/ \ ___/ > < \ \___| | | |__
\____ |\___ >__/\_ \ \___ >__| |____/
\/ \/ \/ \/

--------------------------------------------------------------
`)

type Console struct {
Banner string
ShowBanner bool
}

var DefaultConsole *Console

func init() {
DefaultConsole = &Console{
Banner: DefaultBanner,
ShowBanner: true,
}
}

func (t *Console) Start() error {
if t.ShowBanner {
fmt.Println(t.Banner)
}
if runtime.GOOS == "windows" {
return startPowershell()
} else {
return startBash()
}
}
5 changes: 5 additions & 0 deletions launcher/core/console/powershell.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package console

func startPowershell() error {
return nil
}
12 changes: 12 additions & 0 deletions launcher/core/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package core

import (
"bufio"
"context"
"crypto/tls"
"errors"
"fmt"
"github.com/iancoleman/strcase"
"github.com/mitchellh/go-homedir"
"github.com/opendexnetwork/opendex-docker/launcher/core/console"
"github.com/opendexnetwork/opendex-docker/launcher/log"
"github.com/opendexnetwork/opendex-docker/launcher/service/arby"
"github.com/opendexnetwork/opendex-docker/launcher/service/bitcoind"
Expand Down Expand Up @@ -51,6 +53,7 @@ type Launcher struct {
ConfigFile string

PasswordUnsetMarker string
BackupUnsetMarker string
ExternalIp string

rootCmd *cobra.Command
Expand All @@ -59,6 +62,8 @@ type Launcher struct {
rootLogger *logrus.Logger

LogFile *os.File

Console *console.Console
}

func defaultHomeDir() (string, error) {
Expand Down Expand Up @@ -208,6 +213,7 @@ func NewLauncher() (*Launcher, error) {
return nil, err
}
}
backupUnsetMarker := filepath.Join(networkDir, ".backup-unset")

backupDir := getBackupDir(networkDir, dockerComposeFile)
defaultBackupDir := getDefaultBackupDir(networkDir)
Expand Down Expand Up @@ -237,13 +243,15 @@ func NewLauncher() (*Launcher, error) {
DockerComposeFile: dockerComposeFile,
ConfigFile: configFile,
PasswordUnsetMarker: passwordUnsetMarker,
BackupUnsetMarker: backupUnsetMarker,
ExternalIp: externalIp,
client: &http.Client{
Transport: &http.Transport{
TLSClientConfig: &config,
},
},
LogFile: f,
Console: console.DefaultConsole,
}

l.Services, l.ServicesOrder, err = initServices(&l, network)
Expand Down Expand Up @@ -545,3 +553,7 @@ func (t *Launcher) GetDataDir() string {
func (t *Launcher) Close() {
_ = t.LogFile.Close()
}

func (t *Launcher) StartConsole(ctx context.Context) error {
return t.Console.Start()
}
Loading