Archived
1
0
Fork 0

refactor: Use struct to parse API responses

- Return bytes for each request to the Flexpool API
- Delegate JSON marshalling the higher functions
- Use int64 when possible

BREAKING CHANGE: database structure has to be updated to use integer
instead of real. Please follow instructions to upgrade from 1.0 to 1.1.

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2021-10-11 08:54:37 +02:00
commit ebbd4ac2cd
No known key found for this signature in database
GPG key ID: FF42D23B580C89F7
8 changed files with 133 additions and 65 deletions

View file

@ -12,7 +12,7 @@ const MojoToXCHDivider = 1000000000000
// ConvertCurrency divides the smallest unit of the currency to the currency itself
// Example: for "eth", convert from Weis to ETH
func ConvertCurrency(coin string, value float64) (float64, error) {
func ConvertCurrency(coin string, value int64) (float64, error) {
switch coin {
case "eth":
return ConvertWeis(value), nil
@ -24,13 +24,13 @@ func ConvertCurrency(coin string, value float64) (float64, error) {
}
// ConvertWeis converts the value from Weis to ETH
func ConvertWeis(value float64) float64 {
return value / WeisToETHDivider
func ConvertWeis(value int64) float64 {
return float64(value) / WeisToETHDivider
}
// ConvertMojo converts the value from Mojo to XCH
func ConvertMojo(value float64) float64 {
return value / MojoToXCHDivider
func ConvertMojo(value int64) float64 {
return float64(value) / MojoToXCHDivider
}
// ConvertAction returns "Miner" for Ethereum and "Farmer" for Chia