aboutsummaryrefslogtreecommitdiffstats
path: root/gosrc/requests.go
diff options
context:
space:
mode:
authorsalaaad2 <arthurdurant263@gmail.com>2022-04-17 20:06:17 +0200
committersalaaad2 <arthurdurant263@gmail.com>2022-04-17 20:06:17 +0200
commitb3b1138709abbcf93ccdfbff72f09bb88b8b817f (patch)
treedf0682846f41758c4fece85a80229422a67a3aa1 /gosrc/requests.go
parentsmith is cool (diff)
downloadsmith-b3b1138709abbcf93ccdfbff72f09bb88b8b817f.tar.gz
smith-b3b1138709abbcf93ccdfbff72f09bb88b8b817f.tar.bz2
smith-b3b1138709abbcf93ccdfbff72f09bb88b8b817f.tar.xz
smith-b3b1138709abbcf93ccdfbff72f09bb88b8b817f.tar.zst
smith-b3b1138709abbcf93ccdfbff72f09bb88b8b817f.zip
refactor, readme, gui hooks, and more
Diffstat (limited to 'gosrc/requests.go')
-rw-r--r--gosrc/requests.go65
1 files changed, 40 insertions, 25 deletions
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
}