aboutsummaryrefslogtreecommitdiffstats
path: root/gosrc
diff options
context:
space:
mode:
authorsalaaad2 <arthurdurant263@gmail.com>2022-04-17 17:52:29 +0200
committersalaaad2 <arthurdurant263@gmail.com>2022-04-17 17:52:29 +0200
commitfd79b09ad0e7d0e3165c70ca0908ec1ac0a7116c (patch)
tree523c531f52d68ecd5bceabf3f950fe21c11391f9 /gosrc
parentcool ui and functioning requests, what can a man ask for (v0.0.1) (diff)
downloadsmith-fd79b09ad0e7d0e3165c70ca0908ec1ac0a7116c.tar.gz
smith-fd79b09ad0e7d0e3165c70ca0908ec1ac0a7116c.tar.bz2
smith-fd79b09ad0e7d0e3165c70ca0908ec1ac0a7116c.tar.xz
smith-fd79b09ad0e7d0e3165c70ca0908ec1ac0a7116c.tar.zst
smith-fd79b09ad0e7d0e3165c70ca0908ec1ac0a7116c.zip
smith is cool
Diffstat (limited to 'gosrc')
-rw-r--r--gosrc/main.go104
-rw-r--r--gosrc/requests.go11
-rw-r--r--gosrc/structs.go2
3 files changed, 86 insertions, 31 deletions
diff --git a/gosrc/main.go b/gosrc/main.go
index a83189e..496c728 100644
--- a/gosrc/main.go
+++ b/gosrc/main.go
@@ -8,8 +8,9 @@ package main
import (
"encoding/json"
- "io/ioutil"
"fmt"
+ "io"
+ "io/ioutil"
"log"
"os"
"time"
@@ -18,6 +19,12 @@ import (
"github.com/gizak/termui/v3/widgets"
)
+type nodeValue string
+
+func (nv nodeValue) String() string {
+ return string(nv)
+}
+
func main() {
// get user config from json file
config_path := "./config.json"
@@ -37,13 +44,12 @@ func main() {
}
if err != nil {
- log.Fatal("error: request failed %s", "qwe", err)
+ log.Fatalf("error: request failed %s", err)
return
}
- // make a cool ui
- ui_loop(config)
- fmt.Println("qwe")
+ fmt.Println("hello")
+ ui_loop(config)
defer ui.Close()
return
}
@@ -56,27 +62,51 @@ func ui_loop(config Config) error {
// set widgets
p1 := widgets.NewParagraph()
+ requestTree := []*widgets.TreeNode{
+ {
+ Value: nodeValue("Information"),
+ Nodes:[]*widgets.TreeNode{
+ {
+ Value: nodeValue("Account Status"),
+ Nodes:nil,
+ },
+ {
+ Value: nodeValue("Available Coins"),
+ Nodes: nil,
+ },
+ },
+ },
+ {
+ Value: nodeValue("Actions"),
+ Nodes:[]*widgets.TreeNode{
+ {
+ Value: nodeValue("Buy x coin"),
+ Nodes:nil,
+ },
+ },
+ },
+ }
+ l := widgets.NewTree()
+ l.WrapText = false
+ l.SetNodes(requestTree)
+ l.TextStyle = ui.NewStyle(ui.ColorYellow)
p2 := widgets.NewParagraph()
- p3 := widgets.NewParagraph()
- p4 := widgets.NewParagraph()
+ output := widgets.NewParagraph()
p5 := widgets.NewParagraph()
p1.Text = config.Mirror
p2.Text = "1000.0 BTC"
- p3.Text = "hello"
- p4.Text = "cool"
+ output.Text = "hello"
p5.Text = "__MR_SMITH_V001__"
p5.TextStyle.Fg = ui.ColorGreen
p1.Border = true
p2.Border = true
- p3.Border = true
- p4.Border = true
+ output.Border = false
p1.Title = "Active Mirror"
p2.Title = "Balance"
- p3.Title = "public"
- p4.Title = "Key"
+ output.Title = "Output"
p5.Title = "hello"
main_grid := ui.NewGrid()
@@ -88,11 +118,8 @@ func ui_loop(config Config) error {
main_grid.Set(
ui.NewRow(0.1, p5),
ui.NewRow(1.0/8, p2),
- ui.NewRow(1.0/2, p1),
- ui.NewRow(1.0/2,
- ui.NewCol(1.0/2, p3),
- ui.NewCol(1.0/2, p4),
- ),
+ ui.NewRow(1.0/2, l),
+ ui.NewRow(1.0/2, output),
)
// ui update loop
@@ -110,18 +137,39 @@ func ui_loop(config Config) error {
payload := e.Payload.(ui.Resize)
main_grid.SetRect(0, 0, payload.Width, payload.Height)
ui.Clear()
- ui.Render(main_grid)
- default:
- p3.Text = e.ID
+ case "j", "<Down>":
+ l.ScrollDown()
+ case "k", "<Up>":
+ l.ScrollUp()
+ case "e":
+ l.ToggleExpand()
+ case "<Home>":
+ l.ScrollTop()
+ case "G", "<End>":
+ l.ScrollBottom()
+ case "E":
+ l.ExpandAll()
+ case "C":
+ l.CollapseAll()
+ case "<Enter>":
+ if l.SelectedNode().Nodes == nil {
+ body := make_body()
+ signature := sign_request(body, config.Secret_key)
+ rep, err := send_request(body, signature, l.SelectedNode().Value.String(), config)
+ if rep == nil || err != nil {
+ output.Text = "something went wrong :^{"
+ } else {
+ body, _ := io.ReadAll(rep.Body)
+ output.Text = string(body)
+ defer rep.Body.Close()
+ }
+ }
}
- case <-ticker:
- ui.Render(main_grid)
- ticker_count++
+ case <-ticker:
+ ticker_count++
+ default:
+ ui.Render(main_grid)
}
}
}
-// make request body and sign it
-// body := make_body()
-// signature := sign_request(body, config.Secret_key)
-// res, err := send_request(body, signature, Endpoints.getall, config)
diff --git a/gosrc/requests.go b/gosrc/requests.go
index 0a939c0..6c36f02 100644
--- a/gosrc/requests.go
+++ b/gosrc/requests.go
@@ -7,7 +7,6 @@
package main
import (
- "fmt"
"log"
"net/http"
"strings"
@@ -25,6 +24,14 @@ import "C"
func send_request(body string, signature string, endpoint string, config Config) (*http.Response, error) {
// new client to allow defering of requests
client := &http.Client{}
+ switch (endpoint) {
+ case "Account Status":
+ endpoint = Endpoints.status
+ case "Available Coins":
+ endpoint = Endpoints.getall
+ case "Buy X coin ":
+ return nil, nil
+ }
url := "https://" + config.Mirror + "/" + endpoint + "?" + body + "&signature=" + signature
// add some ifs here
@@ -40,13 +47,11 @@ func send_request(body string, signature string, endpoint string, config Config)
log.Fatal("error: making http request ", err)
}
- defer response.Body.Close()
return response, nil
}
// sign request with given private key
func sign_request(body string, key string) string {
- fmt.Println("signing request : ", body)
// run pipeline
out2, err := RunStrings("/usr/bin/echo", "-n", body, "|", "/usr/bin/openssl", "dgst", "-sha256", "-hmac", key)
diff --git a/gosrc/structs.go b/gosrc/structs.go
index ac17cf6..ec0d285 100644
--- a/gosrc/structs.go
+++ b/gosrc/structs.go
@@ -16,11 +16,13 @@ type Config struct {
// urls to hit on mirror
type Targets struct {
getall string
+ status string
null string
}
var Endpoints = Targets {
getall: "/sapi/v1/capital/config/getall",
+ status: "/sapi/v1/account/status",
null: "/null",
}