2020-10-28 17:35:56 +00:00
|
|
|
package store
|
|
|
|
|
2020-10-30 05:23:08 +00:00
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
|
|
|
|
"github.com/Secured-Finance/dione/rpcclient"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
)
|
2020-10-28 17:35:56 +00:00
|
|
|
|
|
|
|
// TODO: specify store for staking mechanism
|
2020-10-30 05:23:08 +00:00
|
|
|
type DioneStakeInfo struct {
|
|
|
|
MinerStake *big.Int
|
|
|
|
TotalStake *big.Int
|
|
|
|
Ethereum *rpcclient.EthereumClient
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDioneStakeInfo(minerStake, totalStake *big.Int, ethereumClient *rpcclient.EthereumClient) *DioneStakeInfo {
|
|
|
|
return &DioneStakeInfo{
|
|
|
|
MinerStake: minerStake,
|
|
|
|
TotalStake: totalStake,
|
|
|
|
Ethereum: ethereumClient,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *DioneStakeInfo) UpdateMinerStake(minerAddress common.Address) error {
|
|
|
|
minerStake, err := d.Ethereum.GetMinerStake(minerAddress)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
d.MinerStake = minerStake
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *DioneStakeInfo) UpdateTotalStake(minerAddress common.Address) error {
|
|
|
|
totalStake, err := d.Ethereum.GetTotalStake()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
d.TotalStake = totalStake
|
|
|
|
|
|
|
|
return nil
|
2020-10-28 17:35:56 +00:00
|
|
|
}
|