Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-implement setting reward address #1391

Merged
merged 26 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7c25a94
update reward setting file generation in skywire-cli visor config priv
0pcom Oct 18, 2022
d050ed3
comment out existing priv api / rpc etc. pending reimplementation
0pcom Oct 18, 2022
34534a7
fix merge conflicts
0pcom Oct 25, 2022
36f6cc3
fix make format check errors
0pcom Oct 25, 2022
4415793
Merge branch 'develop' into fix/node-privacy-flag
0pcom Oct 28, 2022
4fb3926
re-implement reward setting
0pcom Oct 30, 2022
611c908
fix small logic error
0pcom Oct 30, 2022
9650c79
include goos and goarch in system survey ; add flag to skywire-cli re…
0pcom Oct 30, 2022
e45bfc4
add survey subcommand for skywire-cli
0pcom Oct 30, 2022
9475bae
update system survey with 'ip --json addr' command output struct
0pcom Oct 31, 2022
501bbf0
make system survey generation contingent upon the reward address bein…
0pcom Oct 31, 2022
dc67d55
add skycoin reward address to system survey struct and have the visor…
0pcom Oct 31, 2022
f5cd1ba
fix goimports errors
0pcom Oct 31, 2022
8feb95a
go mod tidy/vendor
0pcom Oct 31, 2022
a1a9067
generate checksum of system survey file
0pcom Oct 31, 2022
63296f0
small fix
0pcom Oct 31, 2022
3925d4c
add skywire-cli tree subcommand
0pcom Nov 1, 2022
a1e50ba
go mod tidy and vendor
mrpalide Nov 1, 2022
62e6efb
fix linting issues
mrpalide Nov 1, 2022
6b8c9c5
fix linting | replace tab with 4 spaces
mrpalide Nov 1, 2022
f81bb09
fix linting by Erson fixed file
mrpalide Nov 1, 2022
bb6e099
update appveyor config
mrpalide Nov 1, 2022
41f585c
fix darwin sysinfo
mrpalide Nov 1, 2022
456ce49
fix linux and windows issue on survey sysinfo
mrpalide Nov 1, 2022
26abf7e
disable IPA in windows
mrpalide Nov 1, 2022
5ce42a5
remove Memory and Product info on darwin, not available
mrpalide Nov 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 5 additions & 5 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ environment:
appveyor_build_worker_image: macos-bigsur
GOARCH: amd64
- job_name: Windows
appveyor_build_worker_image: Previous Visual Studio 2019
appveyor_build_worker_image: Visual Studio 2019
GOARCH: amd64

# For release, by pushing tag
Expand All @@ -23,7 +23,7 @@ environment:
appveyor_build_worker_image: macos-bigsur
GOARCH: amd64
- job_name: make-release-windows
appveyor_build_worker_image: Previous Visual Studio 2019
appveyor_build_worker_image: Visual Studio 2019
GOARCH: amd64

- job_name: DockerDeployMaster
Expand All @@ -39,7 +39,7 @@ for:
- job_name: Linux

install:
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.47.2
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.50.1
- make dep
- sh: ci_scripts/create-ip-aliases.sh

Expand All @@ -56,7 +56,7 @@ for:
- job_name: MacOS

install:
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.47.2
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.50.1
- make dep
- sh: ci_scripts/create-ip-aliases.sh

Expand All @@ -78,7 +78,7 @@ for:

install:
- choco install make
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.47.2
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1
- make dep
- set PATH=C:\Users\appveyor\go\bin;C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH%

Expand Down
9 changes: 5 additions & 4 deletions cmd/skywire-cli/commands/config/gen.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package cliconfig gen.go
// Package cliconfig cmd/skywire-cli/commands/config/gen.go
package cliconfig

import (
Expand Down Expand Up @@ -45,6 +45,8 @@ func init() {
genConfigCmd.Flags().StringVarP(&hypervisorPKs, "hvpks", "j", "", "list of public keys to use as hypervisor")
genConfigCmd.Flags().StringVarP(&selectedOS, "os", "k", skyenv.OS, "(linux / mac / win) paths")
gHiddenFlags = append(gHiddenFlags, "os")
genConfigCmd.Flags().BoolVarP(&isDisplayNodeIP, "publicip", "l", false, "allow display node ip in services")
gHiddenFlags = append(gHiddenFlags, "publicip")
genConfigCmd.Flags().BoolVarP(&isStdout, "stdout", "n", false, "write config to stdout")
gHiddenFlags = append(gHiddenFlags, "stdout")
genConfigCmd.Flags().StringVarP(&output, "out", "o", "", "output config: "+skyenv.ConfigName)
Expand Down Expand Up @@ -79,7 +81,7 @@ func init() {
gHiddenFlags = append(gHiddenFlags, "hide")
genConfigCmd.Flags().BoolVarP(&isPublic, "public", "z", false, "publicize visor in service discovery")
gHiddenFlags = append(gHiddenFlags, "public")
genConfigCmd.Flags().BoolVar(&displayNodeIP, "publicip", false, "display node ip")
// genConfigCmd.Flags().BoolVar(&isDisplayNodeIP, "publicip", false, "display node ip")
genConfigCmd.Flags().StringVar(&ver, "version", "", "custom version testing override")
gHiddenFlags = append(gHiddenFlags, "version")
genConfigCmd.Flags().BoolVar(&isAll, "all", false, "show all flags")
Expand Down Expand Up @@ -357,8 +359,7 @@ var genConfigCmd = &cobra.Command{
if isPublic {
conf.IsPublic = true
}

if displayNodeIP {
if isDisplayNodeIP {
conf.Launcher.DisplayNodeIP = true
}
//don't write file with stdout
Expand Down
108 changes: 0 additions & 108 deletions cmd/skywire-cli/commands/config/private.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/skywire-cli/commands/config/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var (
isUsr bool
isPublic bool
isPublicAutoConn bool
displayNodeIP bool
isDisplayNodeIP bool
)

// RootCmd contains commands that interact with the config of local skywire-visor
Expand Down
193 changes: 193 additions & 0 deletions cmd/skywire-cli/commands/reward/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
// Package clireward cmd/skywire-cli/commands/reward/root.go
package clireward

import (
"fmt"
"os"
"strings"

"github.com/bitfield/script"
coincipher "github.com/skycoin/skycoin/src/cipher"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

clirpc "github.com/skycoin/skywire/cmd/skywire-cli/commands/rpc"
"github.com/skycoin/skywire/cmd/skywire-cli/internal"
"github.com/skycoin/skywire/pkg/skyenv"
)

var (
rewardFile string = skyenv.PackageConfig().LocalPath + "/" + skyenv.RewardFile
rewardAddress string
defaultRewardAddress string
output string
isUseRPC bool
useRPC bool
isRead bool
isRewarded bool
isDeleteFile bool
isAll bool
rpcFlagTxt string
readFlagTxt string
cHiddenFlags []string
)

func init() {

rewardCmd.Flags().SortFlags = false
if defaultRewardAddress == "" {
//default is genesis address for skycoin blockchain ; for testing
defaultRewardAddress = "2jBbGxZRGoQG1mqhPBnXnLTxK6oxsTf8os6"
}
defaultRewardAddress = strings.TrimSuffix(defaultRewardAddress, "\n")
rewardCmd.Flags().StringVarP(&rewardAddress, "address", "a", "", "reward address\ndefault: "+defaultRewardAddress)
cHiddenFlags = append(cHiddenFlags, "address")
rewardCmd.Flags().StringVarP(&output, "out", "o", "", "write reward address to: "+rewardFile)
cHiddenFlags = append(cHiddenFlags, "out")
if isRewarded {
readFlagTxt = "\n" + defaultRewardAddress
}
rewardCmd.Flags().BoolVarP(&isRead, "read", "r", false, "print the skycoin reward address & exit"+readFlagTxt)
cHiddenFlags = append(cHiddenFlags, "read")

//check if the visor is running

// _, err = net.DialTimeout("tcp", "localhost:3435", 5)
//the above was insufficient in practice

//TODO: re-implement this simple check for the visor running
_, err := script.Exec(`skywire-cli visor pk`).String()
if err == nil {
useRPC = true
} else {
useRPC = false
rpcFlagTxt = "default: false - visor is not running"
}
if skyenv.IsRoot() {
useRPC = false
rpcFlagTxt = "default: false - root permissions available"
}
rewardCmd.Flags().BoolVarP(&isUseRPC, "userpc", "u", useRPC, "use the rpc of the running visor\n"+rpcFlagTxt)
cHiddenFlags = append(cHiddenFlags, "userpc")

rewardCmd.Flags().BoolVarP(&isDeleteFile, "delete", "d", false, "delete reward addresss file - opt out of rewards")
cHiddenFlags = append(cHiddenFlags, "delete")
rewardCmd.Flags().BoolVar(&isAll, "all", false, "show all flags")
for _, j := range cHiddenFlags {
rewardCmd.Flags().MarkHidden(j) //nolint
}

}

// RootCmd is rewardCmd
var RootCmd = rewardCmd

const longtext = `
reward address setting

Sets the skycoin reward address for the visor.
The config is written to the root of the default local directory

this config is served via dmsghttp along with transport logs
and the system hardware survey for automating reward distribution`

func longText() string {
//show configured reward address if valid configuration exists
//only the default is supported
if _, err := os.Stat(rewardFile); err == nil {
reward, err := os.ReadFile(rewardFile) //nolint
if err != nil {
fmt.Errorf(" reward settings misconfigured!") //nolint
}
_, err = coincipher.DecodeBase58Address(string(reward))
if err != nil {
fmt.Errorf(" invalid address in reward config %v", err) //nolint
}
isRewarded = true
defaultRewardAddress = fmt.Sprintf("%s\n", reward)
return "\n skycoin reward address set to:\n " + fmt.Sprintf("%s\n", reward) //+longtext
}
return longtext
}

var rewardCmd = &cobra.Command{
Use: "reward <address> || [flags]",
DisableFlagsInUseLine: true,
Short: "skycoin reward address",
Long: longText(),
PreRun: func(cmd *cobra.Command, _ []string) {
//--all unhides flags, prints help menu, and exits
if isAll {
for _, j := range cHiddenFlags {
f := cmd.Flags().Lookup(j) //nolint
f.Hidden = false
}
cmd.Flags().MarkHidden("all") //nolint
cmd.Help() //nolint
os.Exit(0)
}
},
Run: func(cmd *cobra.Command, args []string) {
//set default output file
if output == "" {
output = skyenv.PackageConfig().LocalPath + "/" + skyenv.RewardFile
}
if isDeleteFile {
err := os.Remove(output)
if err != nil {
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("Error deleting file. err=%v", err))
}
}
//print reward address and exit
if isRead {
dat, err := os.ReadFile(output) //nolint
if err != nil {
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("Error reading file. err=%v", err))
}
output := fmt.Sprintf("%s\n", dat)
internal.PrintOutput(cmd.Flags(), output, output)
os.Exit(0)
}
//set reward address from first argument
if len(args) > 0 {
if args[0] != "" {
rewardAddress = args[0]
}
}
if rewardAddress == "" {
rewardAddress = defaultRewardAddress
}
//remove any newline from rewardAddress string
rewardAddress = strings.TrimSuffix(rewardAddress, "\n")
//validate the skycoin address
cAddr, err := coincipher.DecodeBase58Address(rewardAddress)
if err != nil {
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("invalid address specified: %v", err))
}
//using the rpc of the running visor avoids needing sudo permissions
//true if visor is running
//false if sudo permissions exist
if isUseRPC {
client := clirpc.Client(cmd.Flags())
rewardaddress, err := client.SetRewardAddress(rewardAddress)
if err != nil {
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("Failed to connect: %v", err))
}
internal.PrintOutput(cmd.Flags(), rewardaddress, rewardaddress)

} else {
internal.Catch(cmd.Flags(), os.WriteFile(output, []byte(cAddr.String()), 0644)) //nolint
readRewardFile(cmd.Flags())
}
},
}

func readRewardFile(cmdFlags *pflag.FlagSet) {
//read the file which was written
dat, err := os.ReadFile(output) //nolint
if err != nil {
internal.PrintFatalError(cmdFlags, fmt.Errorf("Error reading file. err=%v", err))
}
output := fmt.Sprintf("Reward address file:\n %s\nreward address:\n %s\n", output, dat)
internal.PrintOutput(cmdFlags, output, output)
}
Loading