diff options
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | csrc/smith.c | 12 | ||||
-rw-r--r-- | csrc/smith.h | 3 | ||||
-rw-r--r-- | go.mod | 1 | ||||
-rw-r--r-- | gosrc/main.go | 39 | ||||
-rw-r--r-- | gosrc/pipes.go | 6 | ||||
-rw-r--r-- | gosrc/requests.go | 28 |
7 files changed, 77 insertions, 13 deletions
@@ -24,6 +24,7 @@ SRCS_DIR = ${C_DIR} INCS_DIR = ${C_DIR} OBJS_DIR = ${C_DIR}obj/ OUT_DIR = ./ + #==============================================================================# #------------------------------ FILES -----------------------------------------# #==============================================================================# diff --git a/csrc/smith.c b/csrc/smith.c index 4ff5553..369bdd0 100644 --- a/csrc/smith.c +++ b/csrc/smith.c @@ -7,9 +7,21 @@ /*********************************/ #include "smith.h" +#include <sys/time.h> char * mr_smith() { return ("---SMITH_V0.0.0---"); } + +long +c_get_timestamp() +{ + struct timeval tv; + long ct; + + gettimeofday(&tv, NULL); + ct = ((tv.tv_sec * 1000) + (tv.tv_usec / 1000)); + return (ct); +} diff --git a/csrc/smith.h b/csrc/smith.h index 489c053..4401da9 100644 --- a/csrc/smith.h +++ b/csrc/smith.h @@ -11,6 +11,7 @@ #include <unistd.h> -char * mr_smith(); +char * c_mr_smith(); +long c_get_timestamp(); #endif // SMITH_H_ @@ -5,5 +5,6 @@ go 1.16 require ( github.com/ebuchman/go-shell-pipes v0.0.0-20150412091402-83e132480862 // indirect github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1 // indirect + github.com/gizak/termui/v3 v3.1.0 // indirect github.com/rivo/tview v0.0.0-20220307222120-9994674d60a8 ) diff --git a/gosrc/main.go b/gosrc/main.go index 9923d09..435dac1 100644 --- a/gosrc/main.go +++ b/gosrc/main.go @@ -8,10 +8,13 @@ package main import ( "encoding/json" - "fmt" "io/ioutil" + "fmt" "log" "os" + + ui "github.com/gizak/termui/v3" + "github.com/gizak/termui/v3/widgets" ) // #include "../csrc/smith.h" @@ -28,28 +31,52 @@ func main() { fmt.Println("Welcome, traveller, my name is " + Styles.colorGreen + C.GoString(C.mr_smith()) + Styles.colorReset + "\nI will try to help you get the bag...") + // get user config from json file config_path := "./config.json" for i, a := range os.Args[1:] { if a == "-c" || a == "--config" { config_path = os.Args[i + 2] } } - config_content, err := ioutil.ReadFile(config_path) if err != nil { - log.Fatal("config file not found") + log.Fatal("error: config file not found", err) } - var config Config err = json.Unmarshal(config_content, &config) if err != nil { - log.Fatal("error during marshall() ", err) + log.Fatal("error: marshall() ", err) } + make_ui() + fmt.Println("\n" + Styles.colorBlue + "public_key: " + Styles.colorReset + config.Public_key + "\n" + Styles.colorBlue + "secret_key: " + Styles.colorReset + config.Secret_key + "\n" + Styles.colorBlue + "mirror: " + Styles.colorReset + config.Mirror) - make_body("qwe", "qwe", "qwe") + // make request body and sign it + body := make_body("qwe", "qwe", "qwe") + fmt.Println(body) + signature := sign_request(body, config.Secret_key) + fmt.Println("[" + signature + "]") +} + +func make_ui() error { + if err := ui.Init(); err != nil { + log.Fatal("error: failed to initialize termui", err) + } + + p:= widgets.NewParagraph() + p.Text = "hello" + p.SetRect(0, 0, 25, 5) + ui.Render(p) + + for e := range ui.PollEvents() { + if e.Type == ui.KeyboardEvent { + return nil + } + } + + return nil } diff --git a/gosrc/pipes.go b/gosrc/pipes.go index f668821..0d77b45 100644 --- a/gosrc/pipes.go +++ b/gosrc/pipes.go @@ -1,3 +1,9 @@ +// SMITH ( // / +// pipes ( )/ / +// by salade )(/ / +// ________________ ( /) / +// ()__)____________))))) :^} / + package main import ( diff --git a/gosrc/requests.go b/gosrc/requests.go index 4e94533..7be1d49 100644 --- a/gosrc/requests.go +++ b/gosrc/requests.go @@ -1,23 +1,39 @@ +// SMITH ( // / +// requests ( )/ / +// by salade )(/ / +// ________________ ( /) / +// ()__)____________))))) :^} / + package main import ( "fmt" "log" + "strings" ) -func sign_request(body string, key string) { +// 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) if err != nil { - log.Fatal("hwhat") + log.Fatal("error: failed to sign request", err) } - fmt.Println(out2) - // here + // remove unwanted characters + tok := strings.Index(out2, "(") + last := len(out2) - 1 + first := tok + len("(stdin)= ") + out2 = out2[first:last] + return out2 } -func make_body(order string, ticker string, price string) { +// create body given choice ex : +// GET /sapi/v1/capital/config/getall || +// POST /sapi/v1/asset/dust-btc +func make_body(order string, ticker string, price string) string { ret := "GET /sapi/v1/capital/config/getall" - sign_request(ret, "heheheheh") + return ret } |