-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfound_history.go
65 lines (51 loc) · 1.71 KB
/
found_history.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
"text/tabwriter"
)
// get found history
func getFoundHistory(apiKey string) error {
url := fmt.Sprintf("https://hashes.com/en/api/uploads?key=%s", apiKey)
resp, err := http.Get(url)
if err != nil {
return fmt.Errorf("failed to send request: %v", err)
}
defer resp.Body.Close()
var response struct {
Success bool `json:"success"`
List []FoundHistory `json:"list"`
}
err = json.NewDecoder(resp.Body).Decode(&response)
if err != nil {
return fmt.Errorf("failed to decode response: %v", err)
}
if !response.Success {
return fmt.Errorf("request was not successful")
}
fmt.Println("Upload History (last 20):\n")
writer := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', tabwriter.AlignRight|tabwriter.Debug)
defer writer.Flush()
fmt.Fprintln(writer, "ID\tDate/Time\tBTC (USD)\tXMR (USD)\tLTC (USD)\t-m\tTotal\tFound\tStatus")
btcRate, _ := toUSD(1, "BTC")
xmrRate, _ := toUSD(1, "XMR")
ltcRate, _ := toUSD(1, "LTC")
startIndex := len(response.List) - 20
if startIndex < 0 {
startIndex = 0
}
for i := startIndex; i < len(response.List); i++ {
history := response.List[i]
btc := parseFloat(history.BTC)
xmr := parseFloat(history.XMR)
ltc := parseFloat(history.LTC)
btcUSD := fmt.Sprintf("$%.3f", btc*parseFloat(btcRate["currentprice"].(string)))
xmrUSD := fmt.Sprintf("$%.3f", xmr*parseFloat(xmrRate["currentprice"].(string)))
ltcUSD := fmt.Sprintf("$%.3f", ltc*parseFloat(ltcRate["currentprice"].(string)))
fmt.Fprintf(writer, "%d\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%s\n",
history.ID, history.Date, btcUSD, xmrUSD, ltcUSD, history.AlgorithmID, history.TotalHashes, history.ValidHashes, history.Status)
}
return nil
}