From 5edd076a7c9a3bf926458808f0a964e463737309 Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Sun, 15 Oct 2023 14:05:48 +0300 Subject: [PATCH 01/21] Teonet project workspace created --- cmd/teoapi/go.mod | 19 +++++++++++++++++++ cmd/teoapi/go.sum | 14 ++++++++++++++ cmd/teoecho/go.mod | 19 +++++++++++++++++++ cmd/teoecho/go.sum | 14 ++++++++++++++ cmd/teonet/go.mod | 22 ++++++++++++++++++++++ cmd/teonet/go.sum | 21 +++++++++++++++++++++ go.mod | 9 ++------- go.sum | 18 ++++-------------- go.work | 5 +++++ go.work.sum | 4 ++++ 10 files changed, 124 insertions(+), 21 deletions(-) create mode 100644 cmd/teoapi/go.mod create mode 100644 cmd/teoapi/go.sum create mode 100644 cmd/teoecho/go.mod create mode 100644 cmd/teoecho/go.sum create mode 100644 cmd/teonet/go.mod create mode 100644 cmd/teonet/go.sum create mode 100644 go.work create mode 100644 go.work.sum diff --git a/cmd/teoapi/go.mod b/cmd/teoapi/go.mod new file mode 100644 index 0000000..11a0fd8 --- /dev/null +++ b/cmd/teoapi/go.mod @@ -0,0 +1,19 @@ +module github.com/teonet-go/teonet/cmd/teoapi + +go 1.21.1 + +replace github.com/teonet-go/teonet => ../.. + +require ( + github.com/teonet-go/teomon v0.5.14 + github.com/teonet-go/teonet v0.0.0-00010101000000-000000000000 +) + +require ( + github.com/denisbrodbeck/machineid v1.0.1 // indirect + github.com/google/uuid v1.3.1 // indirect + github.com/kirill-scherba/bslice v0.0.2 // indirect + github.com/kirill-scherba/stable v0.0.8 // indirect + github.com/teonet-go/tru v0.0.18 // indirect + golang.org/x/sys v0.13.0 // indirect +) diff --git a/cmd/teoapi/go.sum b/cmd/teoapi/go.sum new file mode 100644 index 0000000..ff830a4 --- /dev/null +++ b/cmd/teoapi/go.sum @@ -0,0 +1,14 @@ +github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= +github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/kirill-scherba/bslice v0.0.2 h1:ZuP0jBWKB+a6l7J6yB5bmWdm3SB6m/nfE5hKpLksH+A= +github.com/kirill-scherba/bslice v0.0.2/go.mod h1:oMZe3puDpM84VyI0S0qc2XrepyxKJIwEovbNRJPyuTw= +github.com/kirill-scherba/stable v0.0.8 h1:m0GM5FCx1SJkai1o6kfQI0lKUWeupQGTicqb8EIPorg= +github.com/kirill-scherba/stable v0.0.8/go.mod h1:Le2T16xIQmb9c9xzDVSqf7bWvpzo1pbDQLeD0s7qxZU= +github.com/teonet-go/teomon v0.5.14 h1:iYWj2x4oQD7rOp1vu/OMR0dcELEPWhJDcWDx32GvE+A= +github.com/teonet-go/teomon v0.5.14/go.mod h1:GzmuSJWL+tMiN4HvT1fZoqp/mfN8bX7p5R9bxv8JAhM= +github.com/teonet-go/tru v0.0.18 h1:4BR9zpqY0jMmTXsXzyCc4DokMucnqLcsMD+C9uilDro= +github.com/teonet-go/tru v0.0.18/go.mod h1:xCKC3B0JbfE2C8OliN/CJ7R1gGQbnTIKKWLBaC4oBLY= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/cmd/teoecho/go.mod b/cmd/teoecho/go.mod new file mode 100644 index 0000000..a84f647 --- /dev/null +++ b/cmd/teoecho/go.mod @@ -0,0 +1,19 @@ +module github.com/teonet-go/teonet/cmd/teoecho + +go 1.21.1 + +replace github.com/teonet-go/teonet => ../.. + +require ( + github.com/teonet-go/teomon v0.5.14 + github.com/teonet-go/teonet v0.0.0-00010101000000-000000000000 +) + +require ( + github.com/denisbrodbeck/machineid v1.0.1 // indirect + github.com/google/uuid v1.3.1 // indirect + github.com/kirill-scherba/bslice v0.0.2 // indirect + github.com/kirill-scherba/stable v0.0.8 // indirect + github.com/teonet-go/tru v0.0.18 // indirect + golang.org/x/sys v0.13.0 // indirect +) diff --git a/cmd/teoecho/go.sum b/cmd/teoecho/go.sum new file mode 100644 index 0000000..ff830a4 --- /dev/null +++ b/cmd/teoecho/go.sum @@ -0,0 +1,14 @@ +github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= +github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/kirill-scherba/bslice v0.0.2 h1:ZuP0jBWKB+a6l7J6yB5bmWdm3SB6m/nfE5hKpLksH+A= +github.com/kirill-scherba/bslice v0.0.2/go.mod h1:oMZe3puDpM84VyI0S0qc2XrepyxKJIwEovbNRJPyuTw= +github.com/kirill-scherba/stable v0.0.8 h1:m0GM5FCx1SJkai1o6kfQI0lKUWeupQGTicqb8EIPorg= +github.com/kirill-scherba/stable v0.0.8/go.mod h1:Le2T16xIQmb9c9xzDVSqf7bWvpzo1pbDQLeD0s7qxZU= +github.com/teonet-go/teomon v0.5.14 h1:iYWj2x4oQD7rOp1vu/OMR0dcELEPWhJDcWDx32GvE+A= +github.com/teonet-go/teomon v0.5.14/go.mod h1:GzmuSJWL+tMiN4HvT1fZoqp/mfN8bX7p5R9bxv8JAhM= +github.com/teonet-go/tru v0.0.18 h1:4BR9zpqY0jMmTXsXzyCc4DokMucnqLcsMD+C9uilDro= +github.com/teonet-go/tru v0.0.18/go.mod h1:xCKC3B0JbfE2C8OliN/CJ7R1gGQbnTIKKWLBaC4oBLY= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/cmd/teonet/go.mod b/cmd/teonet/go.mod new file mode 100644 index 0000000..fd29330 --- /dev/null +++ b/cmd/teonet/go.mod @@ -0,0 +1,22 @@ +module github.com/teonet-go/teonet/cmd/teonet + +go 1.21.1 + +replace github.com/teonet-go/teonet => ../.. + +replace github.com/teonet-go/teonet/cmd/teonet/menu => ./menu + +require ( + github.com/chzyer/readline v1.5.1 + github.com/teonet-go/teomon v0.5.14 + github.com/teonet-go/teonet v0.6.4 +) + +require ( + github.com/denisbrodbeck/machineid v1.0.1 // indirect + github.com/google/uuid v1.3.1 // indirect + github.com/kirill-scherba/bslice v0.0.2 // indirect + github.com/kirill-scherba/stable v0.0.8 // indirect + github.com/teonet-go/tru v0.0.18 // indirect + golang.org/x/sys v0.13.0 // indirect +) diff --git a/cmd/teonet/go.sum b/cmd/teonet/go.sum new file mode 100644 index 0000000..1389bb2 --- /dev/null +++ b/cmd/teonet/go.sum @@ -0,0 +1,21 @@ +github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM= +github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ= +github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI= +github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk= +github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04= +github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8= +github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= +github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/kirill-scherba/bslice v0.0.2 h1:ZuP0jBWKB+a6l7J6yB5bmWdm3SB6m/nfE5hKpLksH+A= +github.com/kirill-scherba/bslice v0.0.2/go.mod h1:oMZe3puDpM84VyI0S0qc2XrepyxKJIwEovbNRJPyuTw= +github.com/kirill-scherba/stable v0.0.8 h1:m0GM5FCx1SJkai1o6kfQI0lKUWeupQGTicqb8EIPorg= +github.com/kirill-scherba/stable v0.0.8/go.mod h1:Le2T16xIQmb9c9xzDVSqf7bWvpzo1pbDQLeD0s7qxZU= +github.com/teonet-go/teomon v0.5.14 h1:iYWj2x4oQD7rOp1vu/OMR0dcELEPWhJDcWDx32GvE+A= +github.com/teonet-go/teomon v0.5.14/go.mod h1:GzmuSJWL+tMiN4HvT1fZoqp/mfN8bX7p5R9bxv8JAhM= +github.com/teonet-go/tru v0.0.18 h1:4BR9zpqY0jMmTXsXzyCc4DokMucnqLcsMD+C9uilDro= +github.com/teonet-go/tru v0.0.18/go.mod h1:xCKC3B0JbfE2C8OliN/CJ7R1gGQbnTIKKWLBaC4oBLY= +golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/go.mod b/go.mod index d30a0d2..71bed5f 100644 --- a/go.mod +++ b/go.mod @@ -3,17 +3,12 @@ module github.com/teonet-go/teonet go 1.21 require ( - github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e github.com/kirill-scherba/bslice v0.0.2 - github.com/teonet-go/teomon v0.5.14 github.com/teonet-go/tru v0.0.18 ) require ( - github.com/chzyer/logex v1.2.0 // indirect - github.com/chzyer/test v0.0.0-20210722231415-061457976a23 // indirect - github.com/denisbrodbeck/machineid v1.0.1 // indirect - github.com/google/uuid v1.3.0 // indirect + github.com/google/uuid v1.3.1 // indirect github.com/kirill-scherba/stable v0.0.8 // indirect - golang.org/x/sys v0.11.0 // indirect + golang.org/x/sys v0.13.0 // indirect ) diff --git a/go.sum b/go.sum index d0d3895..c540eac 100644 --- a/go.sum +++ b/go.sum @@ -1,20 +1,10 @@ -github.com/chzyer/logex v1.2.0 h1:+eqR0HfOetur4tgnC8ftU5imRnhi4te+BadWS95c5AM= -github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20210722231415-061457976a23 h1:dZ0/VyGgQdVGAss6Ju0dt5P0QltE0SFY5Woh6hbIfiQ= -github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= -github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= -github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/kirill-scherba/bslice v0.0.2 h1:ZuP0jBWKB+a6l7J6yB5bmWdm3SB6m/nfE5hKpLksH+A= github.com/kirill-scherba/bslice v0.0.2/go.mod h1:oMZe3puDpM84VyI0S0qc2XrepyxKJIwEovbNRJPyuTw= github.com/kirill-scherba/stable v0.0.8 h1:m0GM5FCx1SJkai1o6kfQI0lKUWeupQGTicqb8EIPorg= github.com/kirill-scherba/stable v0.0.8/go.mod h1:Le2T16xIQmb9c9xzDVSqf7bWvpzo1pbDQLeD0s7qxZU= -github.com/teonet-go/teomon v0.5.14 h1:iYWj2x4oQD7rOp1vu/OMR0dcELEPWhJDcWDx32GvE+A= -github.com/teonet-go/teomon v0.5.14/go.mod h1:GzmuSJWL+tMiN4HvT1fZoqp/mfN8bX7p5R9bxv8JAhM= github.com/teonet-go/tru v0.0.18 h1:4BR9zpqY0jMmTXsXzyCc4DokMucnqLcsMD+C9uilDro= github.com/teonet-go/tru v0.0.18/go.mod h1:xCKC3B0JbfE2C8OliN/CJ7R1gGQbnTIKKWLBaC4oBLY= -golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/go.work b/go.work new file mode 100644 index 0000000..3e3b68c --- /dev/null +++ b/go.work @@ -0,0 +1,5 @@ +go 1.21.1 + +use ./cmd/teonet +use ./cmd/teoapi +use ./cmd/teoecho diff --git a/go.work.sum b/go.work.sum new file mode 100644 index 0000000..0c3f576 --- /dev/null +++ b/go.work.sum @@ -0,0 +1,4 @@ +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From 999ed5879d4a33489a0a551f83fd77013091a338 Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Sun, 15 Oct 2023 14:25:43 +0300 Subject: [PATCH 02/21] Error messages ; ApiClient description func added --- api_client.go | 23 ++++++++++++++++++++--- cmd/teonet/menu/menu.go | 2 +- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/api_client.go b/api_client.go index acbbf17..8fcb18d 100644 --- a/api_client.go +++ b/api_client.go @@ -25,6 +25,14 @@ const ( CmdClientAPI = 254 ) +var ( + ErrWoronCommand = errors.New("wrong command") +) + +const ( + FmtMsgCommandNotCount = "command '%s' not found" +) + // NewAPIClient create new APIClient func (teo *Teonet) NewAPIClient(address string, cmdAPIs ...byte) (apicli *APIClient, err error) { apicli = new(APIClient) @@ -63,7 +71,7 @@ func (api *APIClient) WaitFrom(command interface{}, packetID ...interface{}) (da } else { a, ok := api.AnswerMode(cmd) if !ok { - err = errors.New("wrong command") + err = ErrWoronCommand return } answerMode = a @@ -157,7 +165,7 @@ func (api *APIClient) getCmd(command interface{}) (cmd byte, err error) { var ok bool cmd, ok = api.Cmd(v) if !ok { - err = fmt.Errorf("command '%s' not found", v) + err = fmt.Errorf(FmtMsgCommandNotCount, v) return } default: @@ -238,5 +246,14 @@ func (api APIClient) Help(short bool) (str string) { return } -// Address return APIClient address +// Address returns application address func (api APIClient) Address() string { return api.address } + +// AppShort returns application short name +func (api APIClient) AppShort() string { return api.short } + +// AppName returns application name +func (api APIClient) AppName() string { return api.name } + +// AppLong returns application long name (description) +func (api APIClient) AppLong() string { return api.long } diff --git a/cmd/teonet/menu/menu.go b/cmd/teonet/menu/menu.go index 6680cc5..c417cca 100644 --- a/cmd/teonet/menu/menu.go +++ b/cmd/teonet/menu/menu.go @@ -120,7 +120,7 @@ func (m Menu) ExecuteCommand(line string) (err error) { c := m.findCommand(line) if c == nil { - err = fmt.Errorf("comand '%s' not found", line) + err = fmt.Errorf(teonet.FmtMsgCommandNotCount, line) return } line = strings.TrimSpace(line[len(c.Name()):]) From a0455b09a55b00de1a9cc4d95f7cd910f81bde72 Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Sun, 15 Oct 2023 14:32:46 +0300 Subject: [PATCH 03/21] New global api flags processing; Edit in json and text --- cmd/teonet/commands.go | 171 +++++++++++++++++++++++++++-------------- 1 file changed, 112 insertions(+), 59 deletions(-) diff --git a/cmd/teonet/commands.go b/cmd/teonet/commands.go index c07f1cd..7f785be 100644 --- a/cmd/teonet/commands.go +++ b/cmd/teonet/commands.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "io" "os" "os/exec" "strings" @@ -191,12 +192,22 @@ type CmdAPI struct { } func (c CmdAPI) Name() string { return cmdAPI } -func (c CmdAPI) Usage() string { return "
[command] [arguments...]" } +func (c CmdAPI) Usage() string { return "[flags] [address] [command] [arguments...]" } func (c CmdAPI) Help() string { return "get peers api" } func (c CmdAPI) Exec(line string) (err error) { flags := c.NewFlagSet(c.Name(), c.Usage(), c.Help()) - var list bool + var ( + list bool // list flag + appshort bool // app short name flag + appname bool // app name flag + applong bool // app long name flag + wallet bool // wallet flag + ) flags.BoolVar(&list, "list", list, "list all connected api") + flags.BoolVar(&appshort, "short", appshort, "get application short name") + flags.BoolVar(&appname, "name", appname, "get application name") + flags.BoolVar(&applong, "long", applong, "get application description") + flags.BoolVar(&wallet, "wallet", wallet, "this application wallet parameters") err = flags.Parse(c.menu.SplitSpace(line)) if err != nil { return @@ -227,9 +238,9 @@ func (c CmdAPI) Exec(line string) (err error) { // Create API interface and get API var address = c.alias.Address(args[0]) - api, ok := c.api.get(address) + apiClient, ok := c.api.get(address) if !ok { - api, err = c.teo.NewAPIClient(address) + apiClient, err = c.teo.NewAPIClient(address) if err != nil { fmt.Printf("can't get api %s, error: %s\n", address, err) if err == teonet.ErrPeerNotConnected { @@ -237,10 +248,45 @@ func (c CmdAPI) Exec(line string) (err error) { } return nil } - c.api.add(address, api) + c.api.add(address, apiClient) } + // Extend APIClient with wallet commands + var api = struct { + *teonet.APIClient + walletCommand + }{APIClient: apiClient} + + // Show flags info or api commands if len(args) == 1 { - fmt.Print(api.String() + "\n") + switch { + + // Print -appshort flag + case appshort: + fmt.Printf("%s\n", api.AppShort()) + + // Print -appname flag + case appname: + fmt.Printf("%s\n", api.AppName()) + + // Print -applong flag + case applong: + fmt.Printf("%s\n", api.AppLong()) + + // Process -wallet flag + case wallet: + fmt.Printf("%s\n", api.AppWalletUsage()) + + // Print api commands + default: + fmt.Print(api.String() + "\n") + } + + return + } + + // Process -wallet flag + if wallet { + fmt.Printf("%s\n", api.AppWalletProcess(args[:])) return } @@ -258,7 +304,7 @@ func (c CmdAPI) Exec(line string) (err error) { if answerMode, ok := api.AnswerMode(command); ok && answerMode == teonet.NoAnswer { _, err = api.SendTo(command, data) if err != nil { - fmt.Printf("can't send api command %s, error: %s\n", command, err) + c.printCantSend(command, err) err = nil } return @@ -275,7 +321,7 @@ func (c CmdAPI) Exec(line string) (err error) { switch { case strings.Contains(ret, "string"): fmt.Println("got answer:", string(data)) - err = c.edit(api, data, editparam, &editmode) + err = c.edit(api.APIClient, data, editparam, &editmode) if err != nil { // fmt.Println("editor, error:", err) } @@ -294,7 +340,7 @@ func (c CmdAPI) Exec(line string) (err error) { wait <- struct{}{} }) if err != nil { - fmt.Printf("can't send api command %s, error: %s\n", command, err) + c.printCantSend(command, err) return nil } Wait: @@ -311,11 +357,14 @@ Wait: return } func (c CmdAPI) Compliter() (cmpl []menu.Compliter) { - return c.menu.MakeCompliterFromString([]string{"-list"}) + return c.menu.MakeCompliterFromString([]string{ + "-list", "-short", "-name", "-long", "-wallet", + }) } // edit received data in os editor and save it back if edit mode enable -func (c CmdAPI) edit(api *teonet.APIClient, req []byte, saveparam string, editmode *int32) (err error) { +func (c CmdAPI) edit(api *teonet.APIClient, req []byte, saveparam string, + editmode *int32) (err error) { // Unmarshal input data var v struct { @@ -324,33 +373,35 @@ func (c CmdAPI) edit(api *teonet.APIClient, req []byte, saveparam string, editmo SaveCmd string `json:"savecmd"` Err string `json:"err"` } - err = json.Unmarshal(req, &v) - if err != nil { - return - } - if v.Edit { - // Set edit mode. We use atomic to safe race when editmode check in - // another goroutine - atomic.StoreInt32(editmode, 1) - } else { - return - } - var vv interface{} - resstr := fmt.Sprintf("%v", v.Res) - err = json.Unmarshal([]byte(resstr), &vv) - if err != nil { + if err = json.Unmarshal(req, &v); err != nil || !v.Edit { return } - // Make prety json to edit in editor - data, err := json.MarshalIndent(vv, "", " ") - if err != nil { - return + // Set edit mode. We use atomic to safe race when editmode check in + // another goroutine + atomic.StoreInt32(editmode, 1) + + var data []byte + var patern string + var wasJsonData = false + var jsonInterface interface{} + resStr := fmt.Sprintf("%v", v.Res) + + // Make prety json to edit in editor or get plain data + if err = json.Unmarshal([]byte(resStr), &jsonInterface); err == nil { + if data, err = json.MarshalIndent(jsonInterface, "", " "); err != nil { + return + } + patern = "*.json" + wasJsonData = true + } else { + data = []byte(resStr) + patern = "*.txt" } - // Create temp file + // Create temp file to edit in editor dir := os.TempDir() - file, err := os.CreateTemp(dir, "*.json") + file, err := os.CreateTemp(dir, patern) if err != nil { return } @@ -372,51 +423,51 @@ func (c CmdAPI) edit(api *teonet.APIClient, req []byte, saveparam string, editmo cmd := exec.Command(editor, filename) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout - err = cmd.Run() - if err != nil { + if err = cmd.Run(); err != nil { return } // Read temp file changed in editor - var b []byte - const bufSize = 1024 - buf := make([]byte, bufSize) - file, err = os.Open(filename) - if err != nil { + if file, err = os.Open(filename); err != nil { return } - for { - n, err := file.Read(buf) - if err != nil || n == 0 { - break - } - b = append(b, buf[:n]...) - if n < bufSize { - break - } + defer file.Close() + if data, err = io.ReadAll(file); err != nil { + return } - file.Close() // Compact json - err = json.Unmarshal(b, &vv) - if err != nil { + err = json.Unmarshal(data, &jsonInterface) + if err == nil { + if data, err = json.Marshal(jsonInterface); err != nil { + return + } + fmt.Println("edited json:", string(data)) + } else if wasJsonData { + fmt.Printf("can't save json, error: %s\n", err) + return + } + + // Skip save if resStr not changed + if resStr == string(data) { return } - data, err = json.Marshal(vv) - fmt.Println("edited json:", string(data)) // Send command to save edited file - fmt.Printf("save command: %s %s,%s\n", v.SaveCmd, saveparam, string(data)) data = []byte(fmt.Sprintf("%s,%s", saveparam, string(data))) - _, err = api.SendTo(v.SaveCmd, data) - if err != nil { - fmt.Printf("can't send api command %s, error: %s\n", v.SaveCmd, err) + fmt.Printf("save command: %s %s\n", v.SaveCmd, string(data)) + if _, err = api.SendTo(v.SaveCmd, data); err != nil { + c.printCantSend(v.SaveCmd, err) err = nil } return } +func (cli *Teocli) printCantSend(cmd string, err error) { + fmt.Printf("can't send api command %s, error: %s\n", cmd, err) +} + // Create CmdSendTo commands func (cli *Teocli) newCmdSendTo() menu.Item { return CmdSendTo{TeocliCommand: TeocliCommand{cli}} @@ -465,7 +516,9 @@ func (c CmdSendTo) Exec(line string) (err error) { // Send data to peer and wait answer wait := make(chan interface{}) - id, err := c.teo.SendTo(address, data, func(c *teonet.Channel, p *teonet.Packet, e *teonet.Event) bool { + id, err := c.teo.SendTo(address, data, func(c *teonet.Channel, + p *teonet.Packet, e *teonet.Event) bool { + // if err != nil { if e.Event != teonet.EventData { // fmt.Printf("got error: %s, from: %s\n", err, address) @@ -501,7 +554,7 @@ func (cli *Teocli) newCmdStat() menu.Item { return CmdStat{TeocliCommand: TeocliCommand{cli}, set: new(bool)} } -// CmdStat show local stat command ---------------------------------------------- +// CmdStat show local stat command --------------------------------------------- type CmdStat struct { TeocliCommand set *bool From 8de5457623fced6cf7f07ce4f39bb249be9f1e77 Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Sun, 15 Oct 2023 16:00:39 +0300 Subject: [PATCH 04/21] Descriptions and comment added to app modules --- cmd/teonet/alias.go | 29 +++++++++++++++++++------- cmd/teonet/api.go | 47 +++++++++++++++++++++++------------------- cmd/teonet/commands.go | 6 ++++++ cmd/teonet/teocli.go | 42 +++++++++++++++++++++---------------- 4 files changed, 77 insertions(+), 47 deletions(-) diff --git a/cmd/teonet/alias.go b/cmd/teonet/alias.go index c9b08a1..d87662b 100644 --- a/cmd/teonet/alias.go +++ b/cmd/teonet/alias.go @@ -1,21 +1,30 @@ +// Copyright 2021-2023 Kirill Scherba . All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Teonet CLI Alias Map processing module. + package main import "sync" +// Alias holds map of Teonet Peers address aliases, mutext to safe this map and +// methods to manage this map. +type Alias struct { + m aliasMap + sync.RWMutex +} + +// newAPI creates a new Alias object func newAlias() (a *Alias) { a = new(Alias) a.m = make(aliasMap) return } -type Alias struct { - m aliasMap - sync.RWMutex -} - type aliasMap map[string]string -// Address get address by name +// Address gets address by name func (a *Alias) Address(name string) string { if address, ok := a.get(name); ok { return address @@ -23,7 +32,7 @@ func (a *Alias) Address(name string) string { return name } -// Name get name by address +// Name gets name by address func (a *Alias) Name(address string) string { if name, ok := a.find(address); ok { return name @@ -31,18 +40,21 @@ func (a *Alias) Name(address string) string { return "" } +// add adds addres to Alias map by name func (a *Alias) add(name, address string) { a.Lock() defer a.Unlock() a.m[name] = address } +// del deletes record from Alias map by name func (a *Alias) del(name string) { a.Lock() defer a.Unlock() delete(a.m, name) } +// get gets address from Alias map by name func (a *Alias) get(name string) (address string, ok bool) { a.RLock() defer a.RUnlock() @@ -50,11 +62,11 @@ func (a *Alias) get(name string) (address string, ok bool) { return } +// find finds name in Alias map by address and returns name func (a *Alias) find(address string) (name string, ok bool) { a.RLock() defer a.RUnlock() for n, addr := range a.m { - // list = append(list, name+" "+address) if addr == address { ok = true name = n @@ -64,6 +76,7 @@ func (a *Alias) find(address string) (name string, ok bool) { return } +// list returns slice of 'name address' from Alias map func (a *Alias) list() (list []string) { a.RLock() defer a.RUnlock() diff --git a/cmd/teonet/api.go b/cmd/teonet/api.go index b957a2a..f111722 100644 --- a/cmd/teonet/api.go +++ b/cmd/teonet/api.go @@ -1,3 +1,9 @@ +// Copyright 2021-2023 Kirill Scherba . All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Teonet CLI API Map processing module. + package main import ( @@ -6,50 +12,49 @@ import ( "github.com/teonet-go/teonet" ) -func newAPI() (a *API) { - a = new(API) - a.m = make(apiMap) - return -} - +// API holds map of connected Teonet API clients, mutext to safe this map and +// methods to manage this map. type API struct { m apiMap sync.RWMutex } - type apiMap map[string]*teonet.APIClient -// func (a *API) Address(name string) string { -// if address, ok := a.get(name); ok { -// return address -// } -// return name -// } +// newAPI creates a new API object +func newAPI() (a *API) { + a = new(API) + a.m = make(apiMap) + return +} -func (a *API) add(name string, api *teonet.APIClient) { +// add adds record to API map +func (a *API) add(address string, api *teonet.APIClient) { a.Lock() defer a.Unlock() - a.m[name] = api + a.m[address] = api } -func (a *API) del(name string) { +// del deletes record from API map +func (a *API) del(address string) { a.Lock() defer a.Unlock() - delete(a.m, name) + delete(a.m, address) } -func (a *API) get(name string) (api *teonet.APIClient, ok bool) { +// get gets record from API map by name +func (a *API) get(address string) (api *teonet.APIClient, ok bool) { a.RLock() defer a.RUnlock() - api, ok = a.m[name] + api, ok = a.m[address] return } +// list returns slice of 'address - name' in API map func (a *API) list(alias *Alias) (list []string) { a.RLock() defer a.RUnlock() - for name := range a.m { - list = append(list, name+" - "+alias.Name(name)) + for address := range a.m { + list = append(list, address+" - "+alias.Name(address)) } return } diff --git a/cmd/teonet/commands.go b/cmd/teonet/commands.go index 7f785be..c50fc21 100644 --- a/cmd/teonet/commands.go +++ b/cmd/teonet/commands.go @@ -1,3 +1,9 @@ +// Copyright 2021-2023 Kirill Scherba . All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Teonet CLI application Commands processing module. + package main import ( diff --git a/cmd/teonet/teocli.go b/cmd/teonet/teocli.go index 03cefc0..4fbbd94 100644 --- a/cmd/teonet/teocli.go +++ b/cmd/teonet/teocli.go @@ -1,3 +1,9 @@ +// Copyright 2021-2023 Kirill Scherba . All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Teonet CLI client connection processing module. + package main import ( @@ -9,6 +15,17 @@ import ( "github.com/teonet-go/teonet/cmd/teonet/menu" ) +// Teocli contains commands menu items and batch, alias, menu, api and teo +// objects. +type Teocli struct { + commands []menu.Item + batch *menu.Batch + alias *Alias + menu *menu.Menu + api *API + teo *teonet.Teonet +} + // NewTeocli create new teonet cli client func NewTeocli(teo *teonet.Teonet, appShort string) (cli *Teocli, err error) { cli = &Teocli{teo: teo} @@ -30,15 +47,6 @@ func NewTeocli(teo *teonet.Teonet, appShort string) (cli *Teocli, err error) { return } -type Teocli struct { - commands []menu.Item - batch *menu.Batch - alias *Alias - menu *menu.Menu - api *API - teo *teonet.Teonet -} - // TeocliCommand common Teocli command structure type TeocliCommand struct{ *Teocli } @@ -53,8 +61,13 @@ func (cli Teocli) Command(name string) interface{} { } // Run command line interface menu -func (cli Teocli) Run() { - cli.menu.Run() +func (cli Teocli) Run() { cli.menu.Run() } + +// NewFlagSet +func (cli Teocli) NewFlagSet(name, usage string, help ...string) (flags *flag.FlagSet) { + flags = flag.NewFlagSet(name, flag.ContinueOnError) + cli.setUsage(name+" "+usage, flags, help...) + return } // setUsage set flags usage helper function @@ -69,10 +82,3 @@ func (cli Teocli) setUsage(usage string, flags *flag.FlagSet, help ...string) { fmt.Println() } } - -// NewFlagSet -func (cli Teocli) NewFlagSet(name, usage string, help ...string) (flags *flag.FlagSet) { - flags = flag.NewFlagSet(name, flag.ContinueOnError) - cli.setUsage(name+" "+usage, flags, help...) - return -} From 5509ae08730b2684f71ec06f984de91a125a89ed Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Sun, 15 Oct 2023 16:35:57 +0300 Subject: [PATCH 05/21] Api client refactoring --- api.go | 39 --------- api_client.go | 231 ++++++++++++++++++++++++++++++-------------------- 2 files changed, 139 insertions(+), 131 deletions(-) diff --git a/api.go b/api.go index 20fcadd..524c96a 100644 --- a/api.go +++ b/api.go @@ -355,42 +355,3 @@ func (a API) MarshalBinary() (data []byte, err error) { return } -type APIDataAr struct { - name string // API (application) name - short string // API short name - long string // API decription (or long name) - version string // API version - Apis []APIData // API commands data - bslice.ByteSlice -} - -// UnmarshalBinary binary unmarshal APIDataAr -func (a *APIDataAr) UnmarshalBinary(data []byte) (err error) { - var buf = bytes.NewBuffer(data) - - if a.name, err = a.ReadString(buf); err != nil { - return - } - if a.short, err = a.ReadString(buf); err != nil { - return - } - if a.long, err = a.ReadString(buf); err != nil { - return - } - if a.version, err = a.ReadString(buf); err != nil { - return - } - var numCmds uint16 - if err = binary.Read(buf, binary.LittleEndian, &numCmds); err != nil { - return - } - for i := 0; i < int(numCmds); i++ { - var api APIData - if err = api.UnmarshalBinary(buf); err != nil { - return - } - a.Apis = append(a.Apis, api) - } - - return -} diff --git a/api_client.go b/api_client.go index 8fcb18d..2fac2f7 100644 --- a/api_client.go +++ b/api_client.go @@ -1,4 +1,4 @@ -// Copyright 2021-22 Kirill Scherba . All rights reserved. +// Copyright 2021-2023 Kirill Scherba . All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -7,16 +7,13 @@ package teonet import ( + "bytes" + "encoding/binary" "errors" "fmt" -) -type APIClient struct { - APIDataAr - address string - cmdAPI byte - teo *Teonet -} + "github.com/kirill-scherba/bslice" +) const ( // Get server api command @@ -25,15 +22,62 @@ const ( CmdClientAPI = 254 ) +const ( + FmtMsgCommandNotCount = "command '%s' not found" +) + var ( ErrWoronCommand = errors.New("wrong command") ) -const ( - FmtMsgCommandNotCount = "command '%s' not found" -) +// APIClient contains clients api data and receive methods +type APIClient struct { + APIDataAr + address string + cmdAPI byte + teo *Teonet +} +type APIDataAr struct { + name string // API (application) name + short string // API short name + long string // API decription (or long name) + version string // API version + Apis []APIData // API commands data + bslice.ByteSlice +} -// NewAPIClient create new APIClient +// UnmarshalBinary binary unmarshal APIDataAr +func (a *APIDataAr) UnmarshalBinary(data []byte) (err error) { + var buf = bytes.NewBuffer(data) + + if a.name, err = a.ReadString(buf); err != nil { + return + } + if a.short, err = a.ReadString(buf); err != nil { + return + } + if a.long, err = a.ReadString(buf); err != nil { + return + } + if a.version, err = a.ReadString(buf); err != nil { + return + } + var numCmds uint16 + if err = binary.Read(buf, binary.LittleEndian, &numCmds); err != nil { + return + } + for i := 0; i < int(numCmds); i++ { + var api APIData + if err = api.UnmarshalBinary(buf); err != nil { + return + } + a.Apis = append(a.Apis, api) + } + + return +} + +// NewAPIClient create new APIClient object func (teo *Teonet) NewAPIClient(address string, cmdAPIs ...byte) (apicli *APIClient, err error) { apicli = new(APIClient) apicli.teo = teo @@ -47,6 +91,26 @@ func (teo *Teonet) NewAPIClient(address string, cmdAPIs ...byte) (apicli *APICli return } +// SendTo sends api command. +func (api *APIClient) SendTo(command interface{}, data []byte, + waits ...func(data []byte, err error)) (id int, err error) { + + cmd, err := api.getCmd(command) + if err != nil { + return + } + id, err = api.teo.Command(cmd, data).SendTo(api.address) + // TODO: i can't understand what does this code do :-) + // May be we need just call: + // api.teo.Command(cmd, data).SendTo(api.address, waits...) + // or in this case wee can lost cmd and id? + // Shure this code exactly than got answer with cmd and id in its data!!! + if len(waits) > 0 { + go func() { waits[0](api.WaitFrom(cmd, uint32(id))) }() + } + return +} + // WaitFrom wait receiving data from peer. The third function parameter is // timeout. It may be omitted or contain timeout time of time. Duration type. // If timeout parameter is omitted than default timeout value sets to 2 second. @@ -91,24 +155,7 @@ func (api *APIClient) WaitFrom(command interface{}, packetID ...interface{}) (da return } -func (api *APIClient) SendTo(command interface{}, data []byte, waits ...func(data []byte, err error)) (id int, err error) { - cmd, err := api.getCmd(command) - if err != nil { - return - } - id, err = api.teo.Command(cmd, data).SendTo(api.address) - // TODO: i can't understand what does this code do :-) - // May be we need just call: - // api.teo.Command(cmd, data).SendTo(api.address, waits...) - // or in this case wee can lost cmd and id? - // Shure this code exactly than got answer with cmd and id in its data!!! - if len(waits) > 0 { - go func() { waits[0](api.WaitFrom(cmd, uint32(id))) }() - } - return -} - -// Cmd get command number by name +// Cmd get command number by name. func (api *APIClient) Cmd(name string) (cmd byte, ok bool) { for i := range api.Apis { if api.Apis[i].name == name { @@ -120,7 +167,7 @@ func (api *APIClient) Cmd(name string) (cmd byte, ok bool) { return } -// Return get return parameter by cmd number or name +// Return get return parameter by cmd number or name. func (api *APIClient) Return(command interface{}) (ret string, ok bool) { a, ok := api.apiData(command) if ok { @@ -129,7 +176,7 @@ func (api *APIClient) Return(command interface{}) (ret string, ok bool) { return } -// AnswerMode get answer mode parameter by cmd number or name +// AnswerMode get answer mode parameter by cmd number or name. func (api *APIClient) AnswerMode(command interface{}) (ret APIanswerMode, ok bool) { a, ok := api.apiData(command) if ok { @@ -138,67 +185,13 @@ func (api *APIClient) AnswerMode(command interface{}) (ret APIanswerMode, ok boo return } -// apiData get return pointer to APIData by cmd number or name -func (api *APIClient) apiData(command interface{}) (ret *APIData, ok bool) { - cmd, err := api.getCmd(command) - if err != nil { - return - } - for i := range api.Apis { - if api.Apis[i].cmd == cmd { - ret = &api.Apis[i] - ok = true - return - } - } - return -} - -// getCmd check command type and return command number -func (api *APIClient) getCmd(command interface{}) (cmd byte, err error) { - switch v := command.(type) { - case byte: - cmd = v - case int: - cmd = byte(v) - case string: - var ok bool - cmd, ok = api.Cmd(v) - if !ok { - err = fmt.Errorf(FmtMsgCommandNotCount, v) - return - } - default: - panic("wrong type of 'command' argument") - } - return -} - -// getApi send cmdAPI command and get answer with APIDataAr: all API definition -func (api *APIClient) getApi() (err error) { - api.SendTo(api.cmdAPI, nil) - data, err := api.WaitFrom(api.cmdAPI) - if err != nil { - log.Error.Println("can't get api data, err", err) - return - } - - err = api.APIDataAr.UnmarshalBinary(data) - if err != nil { - log.Error.Println("can't unmarshal api data, err", err) - return - } - - return -} - -// String stringlify APIClient +// String stringlify APIClient, return same string as Help function. func (api APIClient) String() (str string) { str += api.Help(false) return } -// APIClient return APICient help in string +// APIClient return APICient help in string. func (api APIClient) Help(short bool) (str string) { // Name version and description @@ -246,14 +239,68 @@ func (api APIClient) Help(short bool) (str string) { return } -// Address returns application address +// Address returns application address. func (api APIClient) Address() string { return api.address } -// AppShort returns application short name +// AppShort returns application short name. func (api APIClient) AppShort() string { return api.short } -// AppName returns application name +// AppName returns application name. func (api APIClient) AppName() string { return api.name } -// AppLong returns application long name (description) +// AppLong returns application long name (description). func (api APIClient) AppLong() string { return api.long } + +// apiData get return pointer to APIData by cmd number or name. +func (api *APIClient) apiData(command interface{}) (ret *APIData, ok bool) { + cmd, err := api.getCmd(command) + if err != nil { + return + } + for i := range api.Apis { + if api.Apis[i].cmd == cmd { + ret = &api.Apis[i] + ok = true + return + } + } + return +} + +// getCmd check command type and return command number. +func (api *APIClient) getCmd(command interface{}) (cmd byte, err error) { + switch v := command.(type) { + case byte: + cmd = v + case int: + cmd = byte(v) + case string: + var ok bool + cmd, ok = api.Cmd(v) + if !ok { + err = fmt.Errorf(FmtMsgCommandNotCount, v) + return + } + default: + panic("wrong type of 'command' argument") + } + return +} + +// getApi send cmdAPI command and get answer with APIDataAr: all API definition. +func (api *APIClient) getApi() (err error) { + api.SendTo(api.cmdAPI, nil) + data, err := api.WaitFrom(api.cmdAPI) + if err != nil { + log.Error.Println("can't get api data, err", err) + return + } + + err = api.APIDataAr.UnmarshalBinary(data) + if err != nil { + log.Error.Println("can't unmarshal api data, err", err) + return + } + + return +} From 3a5c0999d0b142887051d80270498710e8d12169 Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Sun, 15 Oct 2023 16:36:57 +0300 Subject: [PATCH 06/21] API wallet commands module created --- cmd/teonet/com_wallet.go | 96 ++++++++++++++++++++++++++++++++++++++++ cmd/teonet/commands.go | 2 +- 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 cmd/teonet/com_wallet.go diff --git a/cmd/teonet/com_wallet.go b/cmd/teonet/com_wallet.go new file mode 100644 index 0000000..aa99bb4 --- /dev/null +++ b/cmd/teonet/com_wallet.go @@ -0,0 +1,96 @@ +// Copyright 2023 Kirill Scherba . All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Teonet CLI application Wallet Commands processing module. + +package main + +type walletCommands struct { +} + +const ( + usageCommand = ` +usage: api -wallet
[arguments...] + +Application wallet commands: + new + creates new wallet mnemonic (create new wallet) + insert + inserts your previously saved wallet mnemonic (import wallet) + show + shows current wallet mnemonic (export wallet) + master + shows saved master key (export wallet by master key) + password + sets password to save and read mnemonic and master key at this host + save + save wallet parameters on this host + delete + delete wallet parameters from this host` + + descriptionNew = `New wallet mnemonic created. + +The new wallet is running now. If you used another wallet before this command +and it mnemonic was not saved - you lost it. If your previously wallet was +saved on this host but you have not copy it - execute load command: + + api -wallet teos3 load + +To show created wallet mnemonic - execute show command: + + api -wallet teos3 show + +To save created wallet mnemonic on this host - execute save command: + + api -wallet teos3 seve + +` +) + +// AppWalletUsage return application walet usage string +func (c walletCommands) AppWalletUsage() string { return c.usage() } + +// AppWalletProcess process application walet options +func (c walletCommands) AppWalletProcess(args []string) string { + return c.process(args) +} + +// usage returns application wallet commands usage string +func (c walletCommands) usage() string { + return usageCommand +} + +// process application wallet commands +func (c walletCommands) process(args []string) string { + switch args[1] { + + case "new": + return descriptionNew + + case "insert": + return "wallet inserted" + + case "load": + return "popa gnom stol" + + case "show": + return "popa gnom stol" + + case "master": + return "eb2345ht" + + case "password": + return "done" + + case "save": + return "done" + + case "delete": + return "done" + + default: + return usageCommand + } + +} diff --git a/cmd/teonet/commands.go b/cmd/teonet/commands.go index c50fc21..1c3d676 100644 --- a/cmd/teonet/commands.go +++ b/cmd/teonet/commands.go @@ -259,7 +259,7 @@ func (c CmdAPI) Exec(line string) (err error) { // Extend APIClient with wallet commands var api = struct { *teonet.APIClient - walletCommand + walletCommands }{APIClient: apiClient} // Show flags info or api commands From b00ea68a184789e047da9525221d2e4022f94abd Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Sun, 15 Oct 2023 17:03:32 +0300 Subject: [PATCH 07/21] Menu package refactoring --- cmd/teonet/menu/batch.go | 7 ++ cmd/teonet/menu/menu.go | 175 ++++++++++++++++++--------------------- 2 files changed, 88 insertions(+), 94 deletions(-) diff --git a/cmd/teonet/menu/batch.go b/cmd/teonet/menu/batch.go index 96ec6ff..7af551c 100644 --- a/cmd/teonet/menu/batch.go +++ b/cmd/teonet/menu/batch.go @@ -1,3 +1,9 @@ +// Copyright 2021-2023 Kirill Scherba . All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Teonet CLI application menu. Batch module + package menu import ( @@ -10,6 +16,7 @@ import ( "github.com/teonet-go/teonet" ) +// Batch is data and methods to Save and Execute saved Teonet Menu commands. type Batch struct{ menu *Menu } // NewBatch creates new Batch object diff --git a/cmd/teonet/menu/menu.go b/cmd/teonet/menu/menu.go index c417cca..49d0aa8 100644 --- a/cmd/teonet/menu/menu.go +++ b/cmd/teonet/menu/menu.go @@ -1,3 +1,8 @@ +// Copyright 2021-2023 Kirill Scherba . All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Teonet CLI application menu. package menu import ( @@ -12,56 +17,26 @@ import ( "github.com/teonet-go/teonet" ) -func New(appShort string) (cmd *Menu, err error) { - cmd = &Menu{appShort: appShort} - return -} - +// Menu is Teonet CLI application menu type Menu struct { - r *readline.Instance - items []Item - appShort string + r *readline.Instance // Readline instance + items []Item // Menu items + appShort string // Application short name } - type Item interface { Name() string // Get command name Help() string // Get command quick help string Exec(line string) error // Execute command Compliter() []Compliter // Command compliter } +type Compliter readline.PrefixCompleterInterface // Readline compliter type -// Compliter readline compliter type -type Compliter readline.PrefixCompleterInterface - -func (m *Menu) newReadline() (l *readline.Instance, err error) { - dir, err := os.UserConfigDir() - if err != nil { - dir = os.TempDir() - } - l, err = readline.NewEx(&readline.Config{ - Prompt: "\033[31mteo»\033[0m ", - HistoryFile: dir + "/" + teonet.ConfigDir + "/" + m.appShort + "/readline.tmp", - AutoComplete: m.makeCompliter(), - InterruptPrompt: "^C", - EOFPrompt: "exit", - HistorySearchFold: true, - FuncFilterInputRune: m.filterInput, - }) - if err != nil { - panic(err) - } +// New creates new Teonet CLI application menu +func New(appShort string) (cmd *Menu, err error) { + cmd = &Menu{appShort: appShort} return } -func (m *Menu) filterInput(r rune) (rune, bool) { - switch r { - // block CtrlZ feature - case readline.CharCtrlZ: - return r, false - } - return r, true -} - // Add command (menu item) func (m *Menu) Add(items ...Item) { m.items = append(m.items, items...) @@ -116,6 +91,7 @@ func (m *Menu) Run() (err error) { return } +// ExecuteCommand executes command using input command line func (m Menu) ExecuteCommand(line string) (err error) { c := m.findCommand(line) @@ -127,6 +103,57 @@ func (m Menu) ExecuteCommand(line string) (err error) { return c.Exec(line) } +// SplitSpace split line by space helper function +func (m Menu) SplitSpace(line string) (res []string) { return m.Split(line, " ") } + +// SplitComma split line by comma helper function +func (m Menu) SplitComma(line string) (res []string) { return m.Split(line, ",") } + +// Split line by delemiter helper function +func (m Menu) Split(line, delimiter string) (res []string) { + if line != "" { + res = strings.Split(line, delimiter) + } + return +} + +// MakeCompliterFromString returns compliter created from input string slice +func (m *Menu) MakeCompliterFromString(strings []string) (cmpl []Compliter) { + for _, s := range strings { + cmpl = append(cmpl, readline.PcItem(s)) + } + return cmpl +} + +func (m *Menu) newReadline() (l *readline.Instance, err error) { + dir, err := os.UserConfigDir() + if err != nil { + dir = os.TempDir() + } + l, err = readline.NewEx(&readline.Config{ + Prompt: "\033[31mteo»\033[0m ", + HistoryFile: dir + "/" + teonet.ConfigDir + "/" + m.appShort + "/readline.tmp", + AutoComplete: m.makeCompliter(), + InterruptPrompt: "^C", + EOFPrompt: "exit", + HistorySearchFold: true, + FuncFilterInputRune: m.filterInput, + }) + if err != nil { + panic(err) + } + return +} + +func (m *Menu) filterInput(r rune) (rune, bool) { + switch r { + // block CtrlZ feature + case readline.CharCtrlZ: + return r, false + } + return r, true +} + func (m Menu) findCommand(line string) (cmd Item) { lenLine := len(line) for _, c := range m.items { @@ -146,24 +173,26 @@ func (m Menu) findCommand(line string) (cmd Item) { return nil } -// SplitSpace split line by space helper function -func (m Menu) SplitSpace(line string) (res []string) { return m.Split(line, " ") } - -// SplitComma split line by comma helper function -func (m Menu) SplitComma(line string) (res []string) { return m.Split(line, ",") } - -// Split line by delemiter helper function -func (m Menu) Split(line, delimiter string) (res []string) { - if line != "" { - res = strings.Split(line, delimiter) +func (m *Menu) makeCompliter() *readline.PrefixCompleter { + var comp []readline.PrefixCompleterInterface + for _, c := range m.items { + compConvert := func() (comp []readline.PrefixCompleterInterface) { + if c.Compliter() == nil { + return + } + for _, cc := range c.Compliter() { + comp = append(comp, cc) + } + return + } + compliter := readline.PcItem(c.Name(), compConvert()...) + comp = append(comp, compliter) } - return + return readline.NewPrefixCompleter(comp...) } // addSystemCommands add internel menu commands like help, etc. -func (m *Menu) addSystemCommands() { - m.Add(CmdHelp{m}) -} +func (m *Menu) addSystemCommands() { m.Add(CmdHelp{m}) } // CmdHelp help command name const cmdHelp = "help" @@ -207,48 +236,6 @@ func (c CmdHelp) Compliter() (cmpl []Compliter) { return } -func (m *Menu) makeCompliter() *readline.PrefixCompleter { - // var completer = readline.NewPrefixCompleter( - // readline.PcItem("mode", - // readline.PcItem("vi"), - // readline.PcItem("emacs"), - // ), - // readline.PcItem("login"), - // readline.PcItem("say", - // readline.PcItemDynamic(listFiles("./"), - // readline.PcItem("with", - // readline.PcItem("following"), - // readline.PcItem("items"), - // ), - // ), - // readline.PcItem("hello"), - // readline.PcItem("bye"), - // ), - // ) - var comp []readline.PrefixCompleterInterface - for _, c := range m.items { - compConvert := func() (comp []readline.PrefixCompleterInterface) { - if c.Compliter() == nil { - return - } - for _, cc := range c.Compliter() { - comp = append(comp, cc) - } - return - } - compliter := readline.PcItem(c.Name(), compConvert()...) - comp = append(comp, compliter) - } - return readline.NewPrefixCompleter(comp...) -} - -func (m *Menu) MakeCompliterFromString(strings []string) (cmpl []Compliter) { - for _, s := range strings { - cmpl = append(cmpl, readline.PcItem(s)) - } - return cmpl -} - // simpleCommand used in MakeItem type simpleCommand struct { name string From df07977551ef1a2ac0d0f16e59e64326be462984 Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Tue, 17 Oct 2023 15:17:00 +0300 Subject: [PATCH 08/21] UserField added to APIDataAr to as User defined field --- api_client.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/api_client.go b/api_client.go index 2fac2f7..1faa852 100644 --- a/api_client.go +++ b/api_client.go @@ -38,11 +38,12 @@ type APIClient struct { teo *Teonet } type APIDataAr struct { - name string // API (application) name - short string // API short name - long string // API decription (or long name) - version string // API version - Apis []APIData // API commands data + name string // API (application) name + short string // API short name + long string // API decription (or long name) + version string // API version + Apis []APIData // API commands data + UserField interface{} // Some user field bslice.ByteSlice } From e02d558750481d8cb41d936ef6f93cdafb742590 Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Tue, 17 Oct 2023 15:18:25 +0300 Subject: [PATCH 09/21] Wallet messages moved to seporate file --- cmd/teonet/com_wallet_messages.go | 71 +++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 cmd/teonet/com_wallet_messages.go diff --git a/cmd/teonet/com_wallet_messages.go b/cmd/teonet/com_wallet_messages.go new file mode 100644 index 0000000..2d7dadc --- /dev/null +++ b/cmd/teonet/com_wallet_messages.go @@ -0,0 +1,71 @@ +package main + +var ( + // Wallet commands usage --------------------------------------------------- + usageCommand = ` +usage: api -wallet
[arguments...] + +Application wallet commands: + new + creates new wallet mnemonic (create new wallet) + insert + inserts your previously saved wallet mnemonic (import wallet) + show + shows current wallet mnemonic and private key (export wallet) + save + save current wallet parameters to this host (save wallet) + load + load saved wallet parameters from this host (load wallet) + delete + delete saved wallet parameters from this host (delete wallet) + password + sets password to save and read mnemonic and master key at this host` + + // New command message ----------------------------------------------------- + descriptionNew = `New wallet for app %s created. + +To show created wallet mnemonic - execute 'show' command: + +` + color("api -wallet teos3 show") + ` + +To save created wallet mnemonic on this host - execute 'save' command: + +` + color("api -wallet teos3 save") + ` + +** If you used another wallet before this command and it mnemonic was not saved +than you lost it. If your previously wallet was saved on this host but you have +not copy it than execute 'load' command: + +` + color("api -wallet teos3 load") + ` +` + + // Show message ------------------------------------------------------------ + descriptionShow = `Wallet for app %s codes: + +mnemonic: +%s + +private key: +%s +` + + // Show error message ------------------------------------------------------ + descriptionShowError = `Wallet for %s was not created. + +To create new wallent use next command: + +` + color("api -wallet teos3 new") + ` + +To load saved wallent use next command: + +` + color("api -wallet teos3 load") + ` +` + + // Load message ------------------------------------------------------------ + descriptionLoad = `Wallet for app %s loaded. + +To show loaded wallet mnemonic - execute 'show' command: + +` + color("api -wallet teos3 show") + ` +` +) From 270a2db118347db297d4e19bde238f08f0c4f914 Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Tue, 17 Oct 2023 15:19:23 +0300 Subject: [PATCH 10/21] The teocrypt/mnemonic added to manage wallet --- cmd/teonet/com_wallet.go | 117 +++++++++++++++++++++++---------------- 1 file changed, 69 insertions(+), 48 deletions(-) diff --git a/cmd/teonet/com_wallet.go b/cmd/teonet/com_wallet.go index aa99bb4..5a22734 100644 --- a/cmd/teonet/com_wallet.go +++ b/cmd/teonet/com_wallet.go @@ -6,54 +6,26 @@ package main -type walletCommands struct { -} - -const ( - usageCommand = ` -usage: api -wallet
[arguments...] - -Application wallet commands: - new - creates new wallet mnemonic (create new wallet) - insert - inserts your previously saved wallet mnemonic (import wallet) - show - shows current wallet mnemonic (export wallet) - master - shows saved master key (export wallet by master key) - password - sets password to save and read mnemonic and master key at this host - save - save wallet parameters on this host - delete - delete wallet parameters from this host` - - descriptionNew = `New wallet mnemonic created. - -The new wallet is running now. If you used another wallet before this command -and it mnemonic was not saved - you lost it. If your previously wallet was -saved on this host but you have not copy it - execute load command: - - api -wallet teos3 load - -To show created wallet mnemonic - execute show command: - - api -wallet teos3 show +import ( + "fmt" -To save created wallet mnemonic on this host - execute save command: + "github.com/teonet-go/teocrypt/mnemonic" +) - api -wallet teos3 seve +// walletCommands contains data and methods to process -wallet commands +type walletCommands struct { + walletConfig mnemonic.MnemonicConfig +} -` -) +// colos returns input text with terminal colors symbols added. +func color(text string) string { return "\033[32m" + text + "\033[0m" } // AppWalletUsage return application walet usage string func (c walletCommands) AppWalletUsage() string { return c.usage() } // AppWalletProcess process application walet options -func (c walletCommands) AppWalletProcess(args []string) string { - return c.process(args) +func (c *walletCommands) AppWalletProcess(appShort string, args []string) string { + return c.process(appShort, args) } // usage returns application wallet commands usage string @@ -62,29 +34,27 @@ func (c walletCommands) usage() string { } // process application wallet commands -func (c walletCommands) process(args []string) string { +func (c *walletCommands) process(appShort string, args []string) string { switch args[1] { case "new": - return descriptionNew + c.newWallet(appShort) + return fmt.Sprintf(descriptionNew, appShort) case "insert": return "wallet inserted" case "load": - return "popa gnom stol" + return c.loadWallet(appShort) case "show": - return "popa gnom stol" - - case "master": - return "eb2345ht" + return c.showWallet(appShort) case "password": return "done" case "save": - return "done" + return c.saveWallet(appShort) case "delete": return "done" @@ -94,3 +64,54 @@ func (c walletCommands) process(args []string) string { } } + +// newWallet creates new wallet. +func (c *walletCommands) newWallet(appShort string) (err error) { + + // Generate new m + m, err := mnemonic.NewMnemonic() + if err != nil { + return + } + fmt.Println("mnemonic:", m) + c.walletConfig.Mnemonic = []byte(m) + + // Generate private and public keys from mnemonic + privateKey, _, err := mnemonic.GenerateKeys(string(m)) + if err != nil { + return + } + fmt.Println("privateKey:", privateKey) + c.walletConfig.PrivateKey = []byte(privateKey) + + return +} + +// showWallet shows current wallet mnemonic and key +func (c *walletCommands) showWallet(appShort string) string { + if len(c.walletConfig.Mnemonic) == 0 && len(c.walletConfig.PrivateKey) == 0 { + return fmt.Sprintf(descriptionShowError, appShort) + } + return fmt.Sprintf(descriptionShow, appShort, c.walletConfig.Mnemonic, + c.walletConfig.PrivateKey) +} + +// saveWallet save current wallet mnemonic and key +func (c walletCommands) saveWallet(appShort string) string { + + if err := c.walletConfig.Save(appShort); err != nil { + return "error during saving: " + err.Error() + } + + return "Saved." +} + +// loadWallet loads previously saved wallet mnemonic and key +func (c *walletCommands) loadWallet(appShort string) string { + + if err := c.walletConfig.Load(appShort); err != nil { + return "error during loading: " + err.Error() + } + + return fmt.Sprintf(descriptionLoad, appShort) +} From b368757d869c9db77620f7e55d2d596444e264a6 Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Tue, 17 Oct 2023 15:20:33 +0300 Subject: [PATCH 11/21] Wallet commands uses the UserField api field --- cmd/teonet/commands.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/teonet/commands.go b/cmd/teonet/commands.go index 1c3d676..e5bac05 100644 --- a/cmd/teonet/commands.go +++ b/cmd/teonet/commands.go @@ -257,10 +257,10 @@ func (c CmdAPI) Exec(line string) (err error) { c.api.add(address, apiClient) } // Extend APIClient with wallet commands - var api = struct { - *teonet.APIClient - walletCommands - }{APIClient: apiClient} + if _, ok := apiClient.UserField.(*walletCommands); !ok { + apiClient.UserField = &walletCommands{} + } + api := apiClient // Show flags info or api commands if len(args) == 1 { @@ -280,7 +280,7 @@ func (c CmdAPI) Exec(line string) (err error) { // Process -wallet flag case wallet: - fmt.Printf("%s\n", api.AppWalletUsage()) + fmt.Printf("%s\n", api.UserField.(*walletCommands).AppWalletUsage()) // Print api commands default: @@ -292,7 +292,7 @@ func (c CmdAPI) Exec(line string) (err error) { // Process -wallet flag if wallet { - fmt.Printf("%s\n", api.AppWalletProcess(args[:])) + fmt.Printf("%s\n", api.UserField.(*walletCommands).AppWalletProcess(api.AppShort(), args[:])) return } @@ -327,7 +327,7 @@ func (c CmdAPI) Exec(line string) (err error) { switch { case strings.Contains(ret, "string"): fmt.Println("got answer:", string(data)) - err = c.edit(api.APIClient, data, editparam, &editmode) + err = c.edit(api, data, editparam, &editmode) if err != nil { // fmt.Println("editor, error:", err) } From 7b9555d9101c23bdca79fa4e71a3029c1aaf2a3d Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Tue, 17 Oct 2023 15:21:48 +0300 Subject: [PATCH 12/21] The teocrypt added to teinet cli application --- cmd/teonet/go.mod | 8 ++++++++ cmd/teonet/go.sum | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/cmd/teonet/go.mod b/cmd/teonet/go.mod index fd29330..d99bdd6 100644 --- a/cmd/teonet/go.mod +++ b/cmd/teonet/go.mod @@ -6,17 +6,25 @@ replace github.com/teonet-go/teonet => ../.. replace github.com/teonet-go/teonet/cmd/teonet/menu => ./menu +replace github.com/teonet-go/teocrypt => ../../../teocrypt + require ( github.com/chzyer/readline v1.5.1 + github.com/teonet-go/teocrypt v0.0.0-20231016150720-b88c13bfa1c2 github.com/teonet-go/teomon v0.5.14 github.com/teonet-go/teonet v0.6.4 ) require ( + github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect + github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect github.com/denisbrodbeck/machineid v1.0.1 // indirect github.com/google/uuid v1.3.1 // indirect github.com/kirill-scherba/bslice v0.0.2 // indirect github.com/kirill-scherba/stable v0.0.8 // indirect github.com/teonet-go/tru v0.0.18 // indirect + github.com/tyler-smith/go-bip32 v1.0.0 // indirect + github.com/tyler-smith/go-bip39 v1.1.0 // indirect + golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect golang.org/x/sys v0.13.0 // indirect ) diff --git a/cmd/teonet/go.sum b/cmd/teonet/go.sum index 1389bb2..c38db38 100644 --- a/cmd/teonet/go.sum +++ b/cmd/teonet/go.sum @@ -1,9 +1,17 @@ +github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc= +github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw= +github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc= +github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U= github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM= github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ= github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI= github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk= github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04= github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8= +github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw= +github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= @@ -12,10 +20,30 @@ github.com/kirill-scherba/bslice v0.0.2 h1:ZuP0jBWKB+a6l7J6yB5bmWdm3SB6m/nfE5hKp github.com/kirill-scherba/bslice v0.0.2/go.mod h1:oMZe3puDpM84VyI0S0qc2XrepyxKJIwEovbNRJPyuTw= github.com/kirill-scherba/stable v0.0.8 h1:m0GM5FCx1SJkai1o6kfQI0lKUWeupQGTicqb8EIPorg= github.com/kirill-scherba/stable v0.0.8/go.mod h1:Le2T16xIQmb9c9xzDVSqf7bWvpzo1pbDQLeD0s7qxZU= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680 h1:oAXco1Ts88F75L1qvG3BAa4ChXI3EZDfxbB+p+y8+gE= +github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/teonet-go/teocrypt v0.0.0-20231016150720-b88c13bfa1c2 h1:oTr8lyk+7JIfapOmFGKQZclaRwhigjQTJEboxfkGBU0= +github.com/teonet-go/teocrypt v0.0.0-20231016150720-b88c13bfa1c2/go.mod h1:SVOdZV/KK/kDYUWtvxrNIaoH7OOaaUu6Do+tdXMgzCI= github.com/teonet-go/teomon v0.5.14 h1:iYWj2x4oQD7rOp1vu/OMR0dcELEPWhJDcWDx32GvE+A= github.com/teonet-go/teomon v0.5.14/go.mod h1:GzmuSJWL+tMiN4HvT1fZoqp/mfN8bX7p5R9bxv8JAhM= github.com/teonet-go/tru v0.0.18 h1:4BR9zpqY0jMmTXsXzyCc4DokMucnqLcsMD+C9uilDro= github.com/teonet-go/tru v0.0.18/go.mod h1:xCKC3B0JbfE2C8OliN/CJ7R1gGQbnTIKKWLBaC4oBLY= +github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE= +github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE= +github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= +github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= +golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54= +launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM= From b0f79a41672a2b9513e208c18f68f481fdecd39f Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Tue, 17 Oct 2023 16:26:31 +0300 Subject: [PATCH 13/21] The configName to wallet commands --- cmd/teonet/com_wallet.go | 37 +++++++++++++++++-------------- cmd/teonet/com_wallet_messages.go | 10 ++++----- cmd/teonet/go.mod | 6 ++--- cmd/teonet/go.sum | 7 +++--- go.work.sum | 6 ++--- teonet.go | 4 ++-- 6 files changed, 36 insertions(+), 34 deletions(-) diff --git a/cmd/teonet/com_wallet.go b/cmd/teonet/com_wallet.go index 5a22734..cd2f80c 100644 --- a/cmd/teonet/com_wallet.go +++ b/cmd/teonet/com_wallet.go @@ -24,8 +24,8 @@ func color(text string) string { return "\033[32m" + text + "\033[0m" } func (c walletCommands) AppWalletUsage() string { return c.usage() } // AppWalletProcess process application walet options -func (c *walletCommands) AppWalletProcess(appShort string, args []string) string { - return c.process(appShort, args) +func (c *walletCommands) AppWalletProcess(apiAppShort string, args []string) string { + return c.process(apiAppShort, args) } // usage returns application wallet commands usage string @@ -34,30 +34,33 @@ func (c walletCommands) usage() string { } // process application wallet commands -func (c *walletCommands) process(appShort string, args []string) string { +func (c *walletCommands) process(apiAppShort string, args []string) string { + + configName := "wallet-" + apiAppShort + switch args[1] { case "new": - c.newWallet(appShort) - return fmt.Sprintf(descriptionNew, appShort) + c.newWallet() + return fmt.Sprintf(descriptionNew, apiAppShort) case "insert": - return "wallet inserted" + return "under construction" case "load": - return c.loadWallet(appShort) + return c.loadWallet(apiAppShort, configName) case "show": - return c.showWallet(appShort) + return c.showWallet(apiAppShort) case "password": - return "done" + return "under construction" case "save": - return c.saveWallet(appShort) + return c.saveWallet(apiAppShort, configName) case "delete": - return "done" + return "under construction" default: return usageCommand @@ -66,7 +69,7 @@ func (c *walletCommands) process(appShort string, args []string) string { } // newWallet creates new wallet. -func (c *walletCommands) newWallet(appShort string) (err error) { +func (c *walletCommands) newWallet() (err error) { // Generate new m m, err := mnemonic.NewMnemonic() @@ -97,9 +100,9 @@ func (c *walletCommands) showWallet(appShort string) string { } // saveWallet save current wallet mnemonic and key -func (c walletCommands) saveWallet(appShort string) string { +func (c walletCommands) saveWallet(apiAppShort, configName string) string { - if err := c.walletConfig.Save(appShort); err != nil { + if err := c.walletConfig.Save(appShort, configName); err != nil { return "error during saving: " + err.Error() } @@ -107,11 +110,11 @@ func (c walletCommands) saveWallet(appShort string) string { } // loadWallet loads previously saved wallet mnemonic and key -func (c *walletCommands) loadWallet(appShort string) string { +func (c *walletCommands) loadWallet(apiAppShort, configName string) string { - if err := c.walletConfig.Load(appShort); err != nil { + if err := c.walletConfig.Load(appShort, configName); err != nil { return "error during loading: " + err.Error() } - return fmt.Sprintf(descriptionLoad, appShort) + return fmt.Sprintf(descriptionLoad, apiAppShort) } diff --git a/cmd/teonet/com_wallet_messages.go b/cmd/teonet/com_wallet_messages.go index 2d7dadc..c5573fc 100644 --- a/cmd/teonet/com_wallet_messages.go +++ b/cmd/teonet/com_wallet_messages.go @@ -50,15 +50,15 @@ private key: ` // Show error message ------------------------------------------------------ - descriptionShowError = `Wallet for %s was not created. - -To create new wallent use next command: - -` + color("api -wallet teos3 new") + ` + descriptionShowError = `Wallet for %s was not loaded. To load saved wallent use next command: ` + color("api -wallet teos3 load") + ` + +To create new wallent use next command: + +` + color("api -wallet teos3 new") + ` ` // Load message ------------------------------------------------------------ diff --git a/cmd/teonet/go.mod b/cmd/teonet/go.mod index d99bdd6..9776067 100644 --- a/cmd/teonet/go.mod +++ b/cmd/teonet/go.mod @@ -6,11 +6,11 @@ replace github.com/teonet-go/teonet => ../.. replace github.com/teonet-go/teonet/cmd/teonet/menu => ./menu -replace github.com/teonet-go/teocrypt => ../../../teocrypt +// replace github.com/teonet-go/teocrypt => ../../../teocrypt require ( github.com/chzyer/readline v1.5.1 - github.com/teonet-go/teocrypt v0.0.0-20231016150720-b88c13bfa1c2 + github.com/teonet-go/teocrypt v0.0.1 github.com/teonet-go/teomon v0.5.14 github.com/teonet-go/teonet v0.6.4 ) @@ -25,6 +25,6 @@ require ( github.com/teonet-go/tru v0.0.18 // indirect github.com/tyler-smith/go-bip32 v1.0.0 // indirect github.com/tyler-smith/go-bip39 v1.1.0 // indirect - golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect + golang.org/x/crypto v0.14.0 // indirect golang.org/x/sys v0.13.0 // indirect ) diff --git a/cmd/teonet/go.sum b/cmd/teonet/go.sum index c38db38..9bcc715 100644 --- a/cmd/teonet/go.sum +++ b/cmd/teonet/go.sum @@ -24,8 +24,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680 h1:oAXco1Ts88F75L1qvG3BAa4ChXI3EZDfxbB+p+y8+gE= github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/teonet-go/teocrypt v0.0.0-20231016150720-b88c13bfa1c2 h1:oTr8lyk+7JIfapOmFGKQZclaRwhigjQTJEboxfkGBU0= -github.com/teonet-go/teocrypt v0.0.0-20231016150720-b88c13bfa1c2/go.mod h1:SVOdZV/KK/kDYUWtvxrNIaoH7OOaaUu6Do+tdXMgzCI= +github.com/teonet-go/teocrypt v0.0.1 h1:nzhswm1vktYIDYCmGNtg7l2HvE6ABp/WweMaxB8OGQQ= +github.com/teonet-go/teocrypt v0.0.1/go.mod h1:SVOdZV/KK/kDYUWtvxrNIaoH7OOaaUu6Do+tdXMgzCI= github.com/teonet-go/teomon v0.5.14 h1:iYWj2x4oQD7rOp1vu/OMR0dcELEPWhJDcWDx32GvE+A= github.com/teonet-go/teomon v0.5.14/go.mod h1:GzmuSJWL+tMiN4HvT1fZoqp/mfN8bX7p5R9bxv8JAhM= github.com/teonet-go/tru v0.0.18 h1:4BR9zpqY0jMmTXsXzyCc4DokMucnqLcsMD+C9uilDro= @@ -36,8 +36,9 @@ github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2n github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/go.work.sum b/go.work.sum index 0c3f576..441ce40 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1,4 +1,2 @@ -github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= diff --git a/teonet.go b/teonet.go index 6b1adcd..2d80775 100644 --- a/teonet.go +++ b/teonet.go @@ -1,4 +1,4 @@ -// Copyright 2021-22 Kirill Scherba . All rights reserved. +// Copyright 2021-2023 Kirill Scherba . All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -18,7 +18,7 @@ import ( "github.com/teonet-go/tru/teolog" ) -const Version = "0.6.4" +const Version = "0.6.5" // Reset random and use rnd instead var rnd = rand.New(rand.NewSource(time.Now().Unix())) From 28d319644a2f3681c5d630a6e94c2a3c355d8050 Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Thu, 19 Oct 2023 17:20:24 +0300 Subject: [PATCH 14/21] Remove 'got answer' text in teonet cli app --- cmd/teonet/commands.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/teonet/commands.go b/cmd/teonet/commands.go index e5bac05..39db877 100644 --- a/cmd/teonet/commands.go +++ b/cmd/teonet/commands.go @@ -326,7 +326,7 @@ func (c CmdAPI) Exec(line string) (err error) { if ret, ok := api.Return(command); ok { switch { case strings.Contains(ret, "string"): - fmt.Println("got answer:", string(data)) + fmt.Println(string(data)) err = c.edit(api, data, editparam, &editmode) if err != nil { // fmt.Println("editor, error:", err) @@ -339,7 +339,7 @@ func (c CmdAPI) Exec(line string) (err error) { } fmt.Println(peers) default: - fmt.Println("got answer:", data) + fmt.Println(data) } } } From 5362f91a53a5cccc6dbb6919ca5259ddf3aa5e57 Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Mon, 23 Oct 2023 19:17:57 +0300 Subject: [PATCH 15/21] Remove extra comment --- api_client.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/api_client.go b/api_client.go index 1faa852..6468468 100644 --- a/api_client.go +++ b/api_client.go @@ -101,11 +101,6 @@ func (api *APIClient) SendTo(command interface{}, data []byte, return } id, err = api.teo.Command(cmd, data).SendTo(api.address) - // TODO: i can't understand what does this code do :-) - // May be we need just call: - // api.teo.Command(cmd, data).SendTo(api.address, waits...) - // or in this case wee can lost cmd and id? - // Shure this code exactly than got answer with cmd and id in its data!!! if len(waits) > 0 { go func() { waits[0](api.WaitFrom(cmd, uint32(id))) }() } From a08f03615b7a32a7ec732f249783756b4a91b31c Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Fri, 3 Nov 2023 14:49:19 +0300 Subject: [PATCH 16/21] Make GetCmd function globally --- api_client.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api_client.go b/api_client.go index 6468468..3e141aa 100644 --- a/api_client.go +++ b/api_client.go @@ -96,7 +96,7 @@ func (teo *Teonet) NewAPIClient(address string, cmdAPIs ...byte) (apicli *APICli func (api *APIClient) SendTo(command interface{}, data []byte, waits ...func(data []byte, err error)) (id int, err error) { - cmd, err := api.getCmd(command) + cmd, err := api.GetCmd(command) if err != nil { return } @@ -116,7 +116,7 @@ func (api *APIClient) SendTo(command interface{}, data []byte, func (api *APIClient) WaitFrom(command interface{}, packetID ...interface{}) (data []byte, err error) { // Get command number - cmd, err := api.getCmd(command) + cmd, err := api.GetCmd(command) if err != nil { return } @@ -249,7 +249,7 @@ func (api APIClient) AppLong() string { return api.long } // apiData get return pointer to APIData by cmd number or name. func (api *APIClient) apiData(command interface{}) (ret *APIData, ok bool) { - cmd, err := api.getCmd(command) + cmd, err := api.GetCmd(command) if err != nil { return } @@ -263,8 +263,8 @@ func (api *APIClient) apiData(command interface{}) (ret *APIData, ok bool) { return } -// getCmd check command type and return command number. -func (api *APIClient) getCmd(command interface{}) (cmd byte, err error) { +// GetCmd check command type and return command number. +func (api *APIClient) GetCmd(command interface{}) (cmd byte, err error) { switch v := command.(type) { case byte: cmd = v From 959aa3180ad8f7de354a9c4cf35defe671d86311 Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Fri, 10 Nov 2023 16:49:46 +0300 Subject: [PATCH 17/21] Go modules updated --- go.mod | 4 ++-- go.sum | 4 ++++ go.work.sum | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 71bed5f..7fc769a 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( ) require ( - github.com/google/uuid v1.3.1 // indirect + github.com/google/uuid v1.4.0 // indirect github.com/kirill-scherba/stable v0.0.8 // indirect - golang.org/x/sys v0.13.0 // indirect + golang.org/x/sys v0.14.0 // indirect ) diff --git a/go.sum b/go.sum index c540eac..0408165 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/kirill-scherba/bslice v0.0.2 h1:ZuP0jBWKB+a6l7J6yB5bmWdm3SB6m/nfE5hKpLksH+A= github.com/kirill-scherba/bslice v0.0.2/go.mod h1:oMZe3puDpM84VyI0S0qc2XrepyxKJIwEovbNRJPyuTw= github.com/kirill-scherba/stable v0.0.8 h1:m0GM5FCx1SJkai1o6kfQI0lKUWeupQGTicqb8EIPorg= @@ -8,3 +10,5 @@ github.com/teonet-go/tru v0.0.18 h1:4BR9zpqY0jMmTXsXzyCc4DokMucnqLcsMD+C9uilDro= github.com/teonet-go/tru v0.0.18/go.mod h1:xCKC3B0JbfE2C8OliN/CJ7R1gGQbnTIKKWLBaC4oBLY= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/go.work.sum b/go.work.sum index 441ce40..3d44504 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1,2 +1,6 @@ +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= From a26918f684cdccd9b18b9664599895c3a57d1328 Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Sat, 11 Nov 2023 13:21:03 +0300 Subject: [PATCH 18/21] Go modules updated (2) --- go.sum | 4 ---- 1 file changed, 4 deletions(-) diff --git a/go.sum b/go.sum index 0408165..ff9d254 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/kirill-scherba/bslice v0.0.2 h1:ZuP0jBWKB+a6l7J6yB5bmWdm3SB6m/nfE5hKpLksH+A= @@ -8,7 +6,5 @@ github.com/kirill-scherba/stable v0.0.8 h1:m0GM5FCx1SJkai1o6kfQI0lKUWeupQGTicqb8 github.com/kirill-scherba/stable v0.0.8/go.mod h1:Le2T16xIQmb9c9xzDVSqf7bWvpzo1pbDQLeD0s7qxZU= github.com/teonet-go/tru v0.0.18 h1:4BR9zpqY0jMmTXsXzyCc4DokMucnqLcsMD+C9uilDro= github.com/teonet-go/tru v0.0.18/go.mod h1:xCKC3B0JbfE2C8OliN/CJ7R1gGQbnTIKKWLBaC4oBLY= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= From dc940187fe18b08d8b8a6baa0fca70c32d44574d Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Sat, 11 Nov 2023 13:29:27 +0300 Subject: [PATCH 19/21] Teonet cmd go modules updated --- cmd/teoapi/go.mod | 6 +++--- cmd/teoapi/go.sum | 8 ++++---- cmd/teoecho/go.mod | 6 +++--- cmd/teoecho/go.sum | 8 ++++---- cmd/teonet/go.mod | 8 ++++---- cmd/teonet/go.sum | 16 ++++++++-------- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/cmd/teoapi/go.mod b/cmd/teoapi/go.mod index 11a0fd8..b525796 100644 --- a/cmd/teoapi/go.mod +++ b/cmd/teoapi/go.mod @@ -6,14 +6,14 @@ replace github.com/teonet-go/teonet => ../.. require ( github.com/teonet-go/teomon v0.5.14 - github.com/teonet-go/teonet v0.0.0-00010101000000-000000000000 + github.com/teonet-go/teonet v0.6.4 ) require ( github.com/denisbrodbeck/machineid v1.0.1 // indirect - github.com/google/uuid v1.3.1 // indirect + github.com/google/uuid v1.4.0 // indirect github.com/kirill-scherba/bslice v0.0.2 // indirect github.com/kirill-scherba/stable v0.0.8 // indirect github.com/teonet-go/tru v0.0.18 // indirect - golang.org/x/sys v0.13.0 // indirect + golang.org/x/sys v0.14.0 // indirect ) diff --git a/cmd/teoapi/go.sum b/cmd/teoapi/go.sum index ff830a4..7ed7713 100644 --- a/cmd/teoapi/go.sum +++ b/cmd/teoapi/go.sum @@ -1,7 +1,7 @@ github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= -github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/kirill-scherba/bslice v0.0.2 h1:ZuP0jBWKB+a6l7J6yB5bmWdm3SB6m/nfE5hKpLksH+A= github.com/kirill-scherba/bslice v0.0.2/go.mod h1:oMZe3puDpM84VyI0S0qc2XrepyxKJIwEovbNRJPyuTw= github.com/kirill-scherba/stable v0.0.8 h1:m0GM5FCx1SJkai1o6kfQI0lKUWeupQGTicqb8EIPorg= @@ -10,5 +10,5 @@ github.com/teonet-go/teomon v0.5.14 h1:iYWj2x4oQD7rOp1vu/OMR0dcELEPWhJDcWDx32GvE github.com/teonet-go/teomon v0.5.14/go.mod h1:GzmuSJWL+tMiN4HvT1fZoqp/mfN8bX7p5R9bxv8JAhM= github.com/teonet-go/tru v0.0.18 h1:4BR9zpqY0jMmTXsXzyCc4DokMucnqLcsMD+C9uilDro= github.com/teonet-go/tru v0.0.18/go.mod h1:xCKC3B0JbfE2C8OliN/CJ7R1gGQbnTIKKWLBaC4oBLY= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/cmd/teoecho/go.mod b/cmd/teoecho/go.mod index a84f647..4d29bb8 100644 --- a/cmd/teoecho/go.mod +++ b/cmd/teoecho/go.mod @@ -6,14 +6,14 @@ replace github.com/teonet-go/teonet => ../.. require ( github.com/teonet-go/teomon v0.5.14 - github.com/teonet-go/teonet v0.0.0-00010101000000-000000000000 + github.com/teonet-go/teonet v0.6.4 ) require ( github.com/denisbrodbeck/machineid v1.0.1 // indirect - github.com/google/uuid v1.3.1 // indirect + github.com/google/uuid v1.4.0 // indirect github.com/kirill-scherba/bslice v0.0.2 // indirect github.com/kirill-scherba/stable v0.0.8 // indirect github.com/teonet-go/tru v0.0.18 // indirect - golang.org/x/sys v0.13.0 // indirect + golang.org/x/sys v0.14.0 // indirect ) diff --git a/cmd/teoecho/go.sum b/cmd/teoecho/go.sum index ff830a4..7ed7713 100644 --- a/cmd/teoecho/go.sum +++ b/cmd/teoecho/go.sum @@ -1,7 +1,7 @@ github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= -github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/kirill-scherba/bslice v0.0.2 h1:ZuP0jBWKB+a6l7J6yB5bmWdm3SB6m/nfE5hKpLksH+A= github.com/kirill-scherba/bslice v0.0.2/go.mod h1:oMZe3puDpM84VyI0S0qc2XrepyxKJIwEovbNRJPyuTw= github.com/kirill-scherba/stable v0.0.8 h1:m0GM5FCx1SJkai1o6kfQI0lKUWeupQGTicqb8EIPorg= @@ -10,5 +10,5 @@ github.com/teonet-go/teomon v0.5.14 h1:iYWj2x4oQD7rOp1vu/OMR0dcELEPWhJDcWDx32GvE github.com/teonet-go/teomon v0.5.14/go.mod h1:GzmuSJWL+tMiN4HvT1fZoqp/mfN8bX7p5R9bxv8JAhM= github.com/teonet-go/tru v0.0.18 h1:4BR9zpqY0jMmTXsXzyCc4DokMucnqLcsMD+C9uilDro= github.com/teonet-go/tru v0.0.18/go.mod h1:xCKC3B0JbfE2C8OliN/CJ7R1gGQbnTIKKWLBaC4oBLY= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/cmd/teonet/go.mod b/cmd/teonet/go.mod index 9776067..e9c15c7 100644 --- a/cmd/teonet/go.mod +++ b/cmd/teonet/go.mod @@ -10,7 +10,7 @@ replace github.com/teonet-go/teonet/cmd/teonet/menu => ./menu require ( github.com/chzyer/readline v1.5.1 - github.com/teonet-go/teocrypt v0.0.1 + github.com/teonet-go/teocrypt v0.0.3 github.com/teonet-go/teomon v0.5.14 github.com/teonet-go/teonet v0.6.4 ) @@ -19,12 +19,12 @@ require ( github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect github.com/denisbrodbeck/machineid v1.0.1 // indirect - github.com/google/uuid v1.3.1 // indirect + github.com/google/uuid v1.4.0 // indirect github.com/kirill-scherba/bslice v0.0.2 // indirect github.com/kirill-scherba/stable v0.0.8 // indirect github.com/teonet-go/tru v0.0.18 // indirect github.com/tyler-smith/go-bip32 v1.0.0 // indirect github.com/tyler-smith/go-bip39 v1.1.0 // indirect - golang.org/x/crypto v0.14.0 // indirect - golang.org/x/sys v0.13.0 // indirect + golang.org/x/crypto v0.15.0 // indirect + golang.org/x/sys v0.14.0 // indirect ) diff --git a/cmd/teonet/go.sum b/cmd/teonet/go.sum index 9bcc715..13af30d 100644 --- a/cmd/teonet/go.sum +++ b/cmd/teonet/go.sum @@ -14,8 +14,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= -github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/kirill-scherba/bslice v0.0.2 h1:ZuP0jBWKB+a6l7J6yB5bmWdm3SB6m/nfE5hKpLksH+A= github.com/kirill-scherba/bslice v0.0.2/go.mod h1:oMZe3puDpM84VyI0S0qc2XrepyxKJIwEovbNRJPyuTw= github.com/kirill-scherba/stable v0.0.8 h1:m0GM5FCx1SJkai1o6kfQI0lKUWeupQGTicqb8EIPorg= @@ -24,8 +24,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680 h1:oAXco1Ts88F75L1qvG3BAa4ChXI3EZDfxbB+p+y8+gE= github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/teonet-go/teocrypt v0.0.1 h1:nzhswm1vktYIDYCmGNtg7l2HvE6ABp/WweMaxB8OGQQ= -github.com/teonet-go/teocrypt v0.0.1/go.mod h1:SVOdZV/KK/kDYUWtvxrNIaoH7OOaaUu6Do+tdXMgzCI= +github.com/teonet-go/teocrypt v0.0.3 h1:B9eEEx5UtggzEM7Msry+m6LQgXFkJSRCNRVrv6ixIEA= +github.com/teonet-go/teocrypt v0.0.3/go.mod h1:SVOdZV/KK/kDYUWtvxrNIaoH7OOaaUu6Do+tdXMgzCI= github.com/teonet-go/teomon v0.5.14 h1:iYWj2x4oQD7rOp1vu/OMR0dcELEPWhJDcWDx32GvE+A= github.com/teonet-go/teomon v0.5.14/go.mod h1:GzmuSJWL+tMiN4HvT1fZoqp/mfN8bX7p5R9bxv8JAhM= github.com/teonet-go/tru v0.0.18 h1:4BR9zpqY0jMmTXsXzyCc4DokMucnqLcsMD+C9uilDro= @@ -37,14 +37,14 @@ github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3C golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= +golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54= launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM= From d68c35937a71ffd7b04b8b1f930784252295a92f Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Sat, 11 Nov 2023 13:36:58 +0300 Subject: [PATCH 20/21] Docker builder updated --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2c16441..524e5a4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -56,7 +56,7 @@ # Docker builder # -FROM golang:1.18.0 AS builder +FROM golang:1.21.3 AS builder WORKDIR /go/src/github.com/teonet-go/teonet # RUN apt update From bacecd64f16fdfde80b333257f148265b43ef559 Mon Sep 17 00:00:00 2001 From: Kirill Scherba Date: Sat, 11 Nov 2023 13:40:29 +0300 Subject: [PATCH 21/21] Go work updated --- go.work.sum | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/go.work.sum b/go.work.sum index 3d44504..1619a19 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1,6 +1,3 @@ -github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= -github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=