-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
balances.go
87 lines (84 loc) · 1.71 KB
/
balances.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"fmt"
"io/ioutil"
"strconv"
)
func CryptoBalance(coin, address string) string {
var balance string
var err error
switch coin {
case "BTC":
balance, err = BitcoinBalance(BTCapi, address)
if err != nil {
fmt.Println(err)
return "0"
}
case "BCH":
balance, err = BitcoinBalance(BCHapi, address)
if err != nil {
fmt.Println(err)
return "0"
}
case "BCHTEST":
balance, err = BitcoinBalance(BCHTESTapi, address)
if err != nil {
fmt.Println(err)
return "0"
}
case "BTCTEST":
balance, err = BitcoinBalance(BTCTESTapi, address)
if err != nil {
fmt.Println(err)
return "0"
}
case "LTC":
balance, err = BitcoinBalance(LTCapi, address)
if err != nil {
return "0"
}
case "LTCTEST":
balance, err = BitcoinBalance(LTCTESTapi, address)
if err != nil {
return "0"
}
case "DASH":
balance, err = BitcoinBalance(DASHapi, address)
if err != nil {
return "0"
}
case "ZCASH":
balance, err = BitcoinBalance(ZCASHapi, address)
if err != nil {
return "0"
}
case "ETH":
balance = EthBalance(eth, address)
case "ROPSTEN":
balance = EthBalance(ropsten, address)
case "RINKEBY":
balance = EthBalance(rinkeby, address)
default:
balance = "0"
}
return balance
}
func BitcoinBalance(endpoint, address string) (string, error) {
var url string
url = fmt.Sprintf(endpoint+"/addr/%v/balance", address)
resp, err := httpGet(url, "GET", []byte(""))
if err != nil {
return "0", err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "0", err
}
amount, err := strconv.ParseFloat(string(body), 10)
if err != nil {
return "0", err
}
amount = amount * 0.00000001
return fmt.Sprintf("%0.3f", amount), err
}