diff options
Diffstat (limited to 'gosrc')
-rw-r--r-- | gosrc/README.org | 16 | ||||
-rw-r--r-- | gosrc/default.json | 5 | ||||
-rw-r--r-- | gosrc/main.go | 7 | ||||
-rw-r--r-- | gosrc/requests.go | 27 | ||||
-rw-r--r-- | gosrc/structs.go | 45 |
5 files changed, 68 insertions, 32 deletions
diff --git a/gosrc/README.org b/gosrc/README.org deleted file mode 100644 index a2c21b9..0000000 --- a/gosrc/README.org +++ /dev/null @@ -1,16 +0,0 @@ -#+title: Readme -#+author: salade -#+email: salad@jozanofastora.xyz - -* Smith -Smith is a very good friend of mine, and a robot -His purpose is to make me money, or as we call it in France, *Cesterces*.... - -** Building -Just type -src_bash[build]{make} -And you will have a very nice executable called smith - -** Usage -You will find at the source of this repository a file called *default.json*, in which you must insert the correct value to be able to use this program -Given how early in production this program is, you might feel a little restricted in what you can ask my good friend to do. Don't worry, traveller... Enjoy the ride and the view diff --git a/gosrc/default.json b/gosrc/default.json deleted file mode 100644 index b1d652f..0000000 --- a/gosrc/default.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "public_key": "hello", - "secret_key": "hehehe", - "mirror": "heheheheheh" -} diff --git a/gosrc/main.go b/gosrc/main.go index 58ecfe6..edc3033 100644 --- a/gosrc/main.go +++ b/gosrc/main.go @@ -8,7 +8,6 @@ package main import ( "encoding/json" - "io" "io/ioutil" "log" "os" @@ -103,7 +102,8 @@ func ui_loop(config Config) error { p1.Border = true p2.Border = true - output.Border = false + output.Border = true + output.TextStyle.Fg = ui.ColorGreen p1.Title = "Active Mirror" p2.Title = "Balance" @@ -160,8 +160,7 @@ func ui_loop(config Config) error { if rep == nil || err != nil { output.Text = "something went wrong :^{" } else { - body, _ := io.ReadAll(rep.Body) - output.Text = string(body) + displayResponse(l.SelectedNode().Value.String(), rep, &output.Text) defer rep.Body.Close() } } diff --git a/gosrc/requests.go b/gosrc/requests.go index 6df7bc6..9110c89 100644 --- a/gosrc/requests.go +++ b/gosrc/requests.go @@ -7,6 +7,8 @@ package main import ( + "encoding/json" + "io" "log" "net/http" "strings" @@ -59,6 +61,31 @@ func getRequestType(name string) string { } } +func displayResponse(node_name string, response *http.Response, output *string) { + requestType := getRequestType(node_name) + body, _ := io.ReadAll(response.Body) + var outputFormatted string + + switch (requestType) { + case GET_Targets.status: + var structuredRep AccountStatusResponse + json.Unmarshal(body, &structuredRep) + outputFormatted = + "Status [" + structuredRep.Data + "]\n" + case GET_Targets.address: + var structuredRep DepositAddressResponse + json.Unmarshal(body, &structuredRep) + outputFormatted = + "Coin [" + structuredRep.Coin + "]\n" + + "Address [" + structuredRep.Address + "]\n" + + "Url [" + structuredRep.Url + "]\n" + + "Tag [" + structuredRep.Tag + "]\n" + default: + outputFormatted = string(body) + } + *output = outputFormatted +} + // Sign payload using openssl func signRequest(body string, key string) string { // run pipeline diff --git a/gosrc/structs.go b/gosrc/structs.go index 3f2fa74..49843a0 100644 --- a/gosrc/structs.go +++ b/gosrc/structs.go @@ -6,13 +6,6 @@ package main -// config.json content -type Config struct { - Public_key string - Secret_key string - Mirror string -} - // urls to hit on mirror type Targets struct { getall string @@ -37,3 +30,41 @@ var POST_Targets = Targets { snapshot: "/null", null: "/null", } + +// config.json content +type Config struct { + Public_key string + Secret_key string + Mirror string +} + +// +// ---- responses ---- +// +type AccountStatusResponse struct { + Data string +} + +type AccountSnapshotResponseMain struct { + Code float64 + Msg string + SnapshotVos map[string]interface{} +} + +type AccountSnapshotResponseVos struct { + Data map[string]interface{} + Type string + UpdateTime float64 +} + +type AccountSnapshotResponseData struct { + Balances []interface{} + TotalAssetOfBtc float64 +} + +type DepositAddressResponse struct { + Address string + Coin string + Tag string + Url string +} |