Archived
1
0
Fork 0
This repository has been archived on 2024-12-18. You can view files and clone it, but cannot push or open issues or pull requests.
flexassistant/pool.go
Julien Riou 3d4c049323
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>
2021-10-15 18:22:48 +02:00

45 lines
867 B
Go

package main
import (
"fmt"
"gorm.io/gorm"
)
// Pool to store pool attributes
type Pool struct {
gorm.Model
Coin string `gorm:"unique;not null"`
LastBlockNumber uint64
}
// NewPool creates a Pool
func NewPool(coin string) *Pool {
return &Pool{Coin: coin}
}
// String represents Pool to a printable format
func (p *Pool) String() string {
return fmt.Sprintf("Pool<%s>", p.Coin)
}
// Block to store block attributes
type Block struct {
Hash string `gorm:"unique;not null"`
Number uint64 `gorm:"not null"`
Reward float64 `gorm:"not null"`
}
// NewBlock creates a Block
func NewBlock(hash string, number uint64, reward float64) *Block {
return &Block{
Hash: hash,
Number: number,
Reward: reward,
}
}
// String represents Block to a printable format
func (b *Block) String() string {
return fmt.Sprintf("Block<%d>", b.Number)
}