aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gosrc/README.org16
-rw-r--r--gosrc/default.json5
-rw-r--r--gosrc/main.go45
-rw-r--r--gosrc/requests.go65
-rw-r--r--gosrc/structs.go13
5 files changed, 96 insertions, 48 deletions
diff --git a/gosrc/README.org b/gosrc/README.org
new file mode 100644
index 0000000..a2c21b9
--- /dev/null
+++ b/gosrc/README.org
@@ -0,0 +1,16 @@
+#+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
new file mode 100644
index 0000000..b1d652f
--- /dev/null
+++ b/gosrc/default.json
@@ -0,0 +1,5 @@
+{
+ "public_key": "hello",
+ "secret_key": "hehehe",
+ "mirror": "heheheheheh"
+}
diff --git a/gosrc/main.go b/gosrc/main.go
index 496c728..58ecfe6 100644
--- a/gosrc/main.go
+++ b/gosrc/main.go
@@ -8,7 +8,6 @@ package main
import (
"encoding/json"
- "fmt"
"io"
"io/ioutil"
"log"
@@ -43,12 +42,6 @@ func main() {
log.Fatal("error: marshall() ", err)
}
- if err != nil {
- log.Fatalf("error: request failed %s", err)
- return
- }
-
- fmt.Println("hello")
ui_loop(config)
defer ui.Close()
return
@@ -74,6 +67,14 @@ func ui_loop(config Config) error {
Value: nodeValue("Available Coins"),
Nodes: nil,
},
+ {
+ Value: nodeValue("Deposit Address"),
+ Nodes: nil,
+ },
+ {
+ Value: nodeValue("Daily Snapshot"),
+ Nodes: nil,
+ },
},
},
{
@@ -117,9 +118,11 @@ func ui_loop(config Config) error {
// add items to grid
main_grid.Set(
ui.NewRow(0.1, p5),
- ui.NewRow(1.0/8, p2),
- ui.NewRow(1.0/2, l),
- ui.NewRow(1.0/2, output),
+ ui.NewRow(0.1, p2),
+ ui.NewRow(0.8,
+ ui.NewCol(0.2, l),
+ ui.NewCol(0.8, output),
+ ),
)
// ui update loop
@@ -151,19 +154,17 @@ func ui_loop(config Config) error {
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 "<Enter>":
+ if l.SelectedNode().Nodes == nil {
+ rep, err := sendRequest(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:
ticker_count++
diff --git a/gosrc/requests.go b/gosrc/requests.go
index 6c36f02..6df7bc6 100644
--- a/gosrc/requests.go
+++ b/gosrc/requests.go
@@ -16,43 +16,51 @@ import (
// #cgo LDFLAGS: -lsmith -L../
import "C"
-// send request to mirror and return response
-// @param body ?qwe=asd&foo=bar
-// @param signature duh
-// @param endpoint /sapi/v1/capital/config/qwe
-// @param config duhh
-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 ":
+func sendRequest(node_name string, config Config) (*http.Response, error) {
+ endpoint := getRequestType(node_name)
+ if len(endpoint) == 0 {
return nil, nil
}
- url := "https://" + config.Mirror + "/" + endpoint + "?" + body + "&signature=" + signature
- // add some ifs here
+ // create payload
+ body := makeBody(endpoint)
+ signature := signRequest(body, config.Secret_key)
+ url := "https://" + config.Mirror + "/" + endpoint + "?" + body + "&signature=" + signature
+ // make a request out of it
req, err := http.NewRequest("GET", url, nil)
+ req.Header.Add("X-MBX-APIKEY", config.Public_key)
if err != nil {
log.Fatal("error: creating http request ", err)
}
- req.Header.Add("X-MBX-APIKEY", config.Public_key)
- // finished bakiong request. send it
+ // send it
+ client := &http.Client{}
response, err := client.Do(req)
if err != nil {
log.Fatal("error: making http request ", err)
+ return response, err
}
-
return response, nil
}
-// sign request with given private key
-func sign_request(body string, key string) string {
+// return request path from tree node name
+func getRequestType(name string) string {
+ switch (name) {
+ case "Account Status":
+ return GET_Targets.status
+ case "Available Coins":
+ return GET_Targets.getall
+ case "Deposit Address":
+ return GET_Targets.address
+ case "Daily Snapshot":
+ return GET_Targets.snapshot
+ default :
+ return ""
+ }
+}
+// Sign payload using openssl
+func signRequest(body string, key string) string {
// run pipeline
out2, err := RunStrings("/usr/bin/echo", "-n", body, "|", "/usr/bin/openssl", "dgst", "-sha256", "-hmac", key)
if err != nil {
@@ -67,10 +75,17 @@ func sign_request(body string, key string) string {
return out2
}
-// create body given choice ex :
-// GET /sapi/v1/capital/config/getall ||
-// POST /sapi/v1/asset/dust-btc
-func make_body() string {
+// return body value from endpoint
+func makeBody(endpoint string) string {
ret := "timestamp=" + C.GoString(C.get_timestamp()) + "&recvWindow=50000"
+
+ switch (endpoint) {
+ case GET_Targets.getall , GET_Targets.status:
+ break
+ case GET_Targets.snapshot:
+ ret += "&type=SPOT"
+ case GET_Targets.address:
+ ret += "&coin=BNB"
+ }
return ret
}
diff --git a/gosrc/structs.go b/gosrc/structs.go
index ec0d285..3f2fa74 100644
--- a/gosrc/structs.go
+++ b/gosrc/structs.go
@@ -16,13 +16,24 @@ type Config struct {
// urls to hit on mirror
type Targets struct {
getall string
+ address string
status string
+ snapshot string
null string
}
-var Endpoints = Targets {
+var GET_Targets = Targets {
getall: "/sapi/v1/capital/config/getall",
+ address: "/sapi/v1/capital/deposit/address",
status: "/sapi/v1/account/status",
+ snapshot: "/sapi/v1/accountSnapshot",
null: "/null",
}
+var POST_Targets = Targets {
+ getall: "/null",
+ address: "/null",
+ status: "/null",
+ snapshot: "/null",
+ null: "/null",
+}