Archived
1
0
Fork 0

fix: Convert big integers to float64

Large numbers can be returned by the Flexpool API reaching the `int64`
limit. Blocks reward were seen as 0 ETH. Using `float64` instead. Also
converting signed int64 to unsigned int64 for non-timestamp numbers.

BREAKING CHANGE: please follow the upgrades instructions from 1.2 to
1.3 to convert such types in the database.

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2021-10-15 18:20:38 +02:00
commit 3d4c049323
No known key found for this signature in database
GPG key ID: FF42D23B580C89F7
7 changed files with 63 additions and 25 deletions

View file

@ -66,12 +66,12 @@ func (f *FlexpoolClient) request(url string) ([]byte, error) {
type BalanceResponse struct {
Error string `json:"error"`
Result struct {
Balance int64 `json:"balance"`
Balance float64 `json:"balance"`
} `json:"result"`
}
// MinerBalance returns the current unpaid balance
func (f *FlexpoolClient) MinerBalance(coin string, address string) (int64, error) {
func (f *FlexpoolClient) MinerBalance(coin string, address string) (float64, error) {
body, err := f.request(fmt.Sprintf("%s/miner/balance?coin=%s&address=%s", FlexpoolAPIURL, coin, address))
if err != nil {
return 0, err
@ -87,9 +87,9 @@ type PaymentsResponse struct {
Error string `json:"error"`
Result struct {
Data []struct {
Hash string `json:"hash"`
Value int64 `json:"value"`
Timestamp int64 `json:"timestamp"`
Hash string `json:"hash"`
Value float64 `json:"value"`
Timestamp int64 `json:"timestamp"`
} `json:"data"`
} `json:"result"`
}
@ -165,9 +165,9 @@ type BlocksResponse struct {
Error string `json:"error"`
Result struct {
Data []struct {
Hash string `json:"hash"`
Number int64 `json:"number"`
Reward int64 `json:"reward"`
Hash string `json:"hash"`
Number uint64 `json:"number"`
Reward float64 `json:"reward"`
} `json:"data"`
} `json:"result"`
}