Skip to content

Commit

Permalink
Index QAP, worker, owner from lotus node
Browse files Browse the repository at this point in the history
Refer #12
  • Loading branch information
rajgoesout committed Jul 14, 2021
1 parent 2fde685 commit 881c8fa
Showing 1 changed file with 46 additions and 11 deletions.
57 changes: 46 additions & 11 deletions service/service.go
Expand Up @@ -2,6 +2,7 @@ package service

import (
"bytes"
"context"
"fmt"
"log"
"math/big"
Expand All @@ -13,6 +14,7 @@ import (
"github.com/buidl-labs/miner-marketplace-backend/db/model"
gqlmodel "github.com/buidl-labs/miner-marketplace-backend/graph/model"
"github.com/buidl-labs/miner-marketplace-backend/util"
"github.com/filecoin-project/go-address"
"github.com/go-pg/pg/v10"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -55,6 +57,17 @@ func hourlyTasks(DB *pg.DB, node lens.API) {

if filRepMiners.Pagination.Total > 0 {
for _, m := range filRepMiners.Miners {
qap := m.QualityAdjPower
if ts, err := node.ChainHead(context.Background()); err == nil {
if minerAddr, err := address.NewFromString(m.Address); err == nil {
if minerPower, err := node.StateMinerPower(context.Background(), minerAddr, ts.Key()); err == nil {
fmt.Println("powerbigint", minerPower.MinerPower.QualityAdjPower)
fmt.Println("powerbigintstring", minerPower.MinerPower.QualityAdjPower.String())
qap = minerPower.MinerPower.QualityAdjPower.String()
}
}
}

reputationScoreString, _ := m.Score.(string)
reputationScoreInt64, _ := strconv.ParseInt(reputationScoreString, 10, 64)
reputationScore := int(reputationScoreInt64)
Expand All @@ -78,7 +91,7 @@ func hourlyTasks(DB *pg.DB, node lens.API) {
}
if claimed {
miner := &model.Miner{
QualityAdjustedPower: m.QualityAdjPower,
QualityAdjustedPower: qap,
ReputationScore: reputationScore,
}
_, err = DB.Model(miner).
Expand All @@ -94,7 +107,7 @@ func hourlyTasks(DB *pg.DB, node lens.API) {
miner := &model.Miner{
Region: m.Region,
Country: m.IsoCode,
QualityAdjustedPower: m.QualityAdjPower,
QualityAdjustedPower: qap,
StorageAskPrice: storageAskPrice,
VerifiedAskPrice: verifiedAskPrice,
ReputationScore: reputationScore,
Expand Down Expand Up @@ -134,7 +147,7 @@ func hourlyTasks(DB *pg.DB, node lens.API) {
Claimed: false,
Region: m.Region,
Country: m.IsoCode,
QualityAdjustedPower: m.QualityAdjPower,
QualityAdjustedPower: qap,
StorageAskPrice: storageAskPrice,
VerifiedAskPrice: verifiedAskPrice,
ReputationScore: reputationScore,
Expand Down Expand Up @@ -199,7 +212,7 @@ func dailyTasks(DB *pg.DB, node lens.API) {
// update owner/worker/control addresses

var FILREP_MINERS string = "https://api.filrep.io/api/v1/miners"
var FILFOX_MINER string = "https://filfox.info/api/v1/address/"
// var FILFOX_MINER string = "https://filfox.info/api/v1/address/"

filRepMiners := new(FilRepMiners)
util.GetJson(FILREP_MINERS, filRepMiners)
Expand All @@ -209,15 +222,37 @@ func dailyTasks(DB *pg.DB, node lens.API) {
if filRepMiners.Pagination.Total > 0 {
for _, m := range filRepMiners.Miners {
// https://filfox.info/api/v1/address/f02770
time.Sleep(2 * time.Second)
filFoxMiner := new(FilFoxMiner)
util.GetJson(FILFOX_MINER+m.Address, filFoxMiner)
fmt.Println("daily miner", m.Address, filFoxMiner.Miner, "owner", filFoxMiner.Miner.Owner.Address, "worker", filFoxMiner.Miner.Worker.Address)
ts, err := node.ChainHead(context.Background())
if err != nil {
continue
}
minerAddr, err := address.NewFromString(m.Address)
if err != nil {
continue
}
minerInfo, err := node.StateMinerInfo(context.Background(), minerAddr, ts.Key())
if err != nil {
continue
}
workerAddr, err := node.StateAccountKey(context.Background(), minerInfo.Worker, ts.Key())
if err != nil {
continue
}
ownerAddr, err := node.StateAccountKey(context.Background(), minerInfo.Owner, ts.Key())
if err != nil {
continue
}
// time.Sleep(2 * time.Second)
// filFoxMiner := new(FilFoxMiner)
// util.GetJson(FILFOX_MINER+m.Address, filFoxMiner)
// fmt.Println("daily miner", m.Address, filFoxMiner.Miner, "owner", filFoxMiner.Miner.Owner.Address, "worker", filFoxMiner.Miner.Worker.Address)
miner := &model.Miner{
WorkerAddress: filFoxMiner.Miner.Worker.Address,
OwnerAddress: filFoxMiner.Miner.Owner.Address,
WorkerAddress: workerAddr.String(),
OwnerAddress: ownerAddr.String(),
// WorkerAddress: filFoxMiner.Miner.Worker.Address,
// OwnerAddress: filFoxMiner.Miner.Owner.Address,
}
_, err := DB.Model(miner).
_, err = DB.Model(miner).
Column("worker_address", "owner_address").
Where("id = ?", m.Address).
Update()
Expand Down

0 comments on commit 881c8fa

Please sign in to comment.