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:
parent
c4f3854861
commit
ebbd4ac2cd
8 changed files with 133 additions and 65 deletions
12
pool.go
12
pool.go
|
@ -10,7 +10,7 @@ import (
|
|||
type Pool struct {
|
||||
gorm.Model
|
||||
Coin string `gorm:"unique;not null"`
|
||||
LastBlockNumber float64
|
||||
LastBlockNumber int64
|
||||
}
|
||||
|
||||
// NewPool creates a Pool
|
||||
|
@ -25,13 +25,13 @@ func (p *Pool) String() string {
|
|||
|
||||
// Block to store block attributes
|
||||
type Block struct {
|
||||
Hash string `gorm:"unique;not null"`
|
||||
Number float64 `gorm:"not null"`
|
||||
Reward float64 `gorm:"not null"`
|
||||
Hash string `gorm:"unique;not null"`
|
||||
Number int64 `gorm:"not null"`
|
||||
Reward int64 `gorm:"not null"`
|
||||
}
|
||||
|
||||
// NewBlock creates a Block
|
||||
func NewBlock(hash string, number float64, reward float64) *Block {
|
||||
func NewBlock(hash string, number int64, reward int64) *Block {
|
||||
return &Block{
|
||||
Hash: hash,
|
||||
Number: number,
|
||||
|
@ -41,5 +41,5 @@ func NewBlock(hash string, number float64, reward float64) *Block {
|
|||
|
||||
// String represents Block to a printable format
|
||||
func (b *Block) String() string {
|
||||
return fmt.Sprintf("Block<%.0f>", b.Number)
|
||||
return fmt.Sprintf("Block<%d>", b.Number)
|
||||
}
|
||||
|
|
Reference in a new issue