Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1461 from irisnet/hotfix/v0.11.1-0616
Browse files Browse the repository at this point in the history
R4R:merge master from Hotfix/v0.11.1 0616
  • Loading branch information
kaifei Hu authored Jul 2, 2020
2 parents c197815 + ade5768 commit 4235aa6
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 296 deletions.
4 changes: 0 additions & 4 deletions backend/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const (
KeyCaculateStartDate = "CaculateStartDate" //yyyy-mm-ddThh:mm:ss
KeyCaculateEndDate = "CaculateEndDate" //yyyy-mm-ddThh:mm:ss
KeyCaculateDate = "CaculateDate" //yyyy-mm-dd
KeyCaculatePeriodDay = "CaculatePeriodDay" //hh
KeyFoundationDelegatorAddr = "FoundationDelegatorAddr"

EnvironmentDevelop = "dev"
Expand Down Expand Up @@ -118,7 +117,6 @@ func init() {
CaculateStartDate: getEnv(KeyCaculateStartDate, DefaultEnvironment),
CaculateEndDate: getEnv(KeyCaculateEndDate, DefaultEnvironment),
CaculateDate: getEnv(KeyCaculateDate, DefaultEnvironment),
CaculatePeriodDay: getEnvInt(KeyCaculatePeriodDay, DefaultEnvironment),
NetreqLimitMax: getEnvInt(KeyNetreqLimitMax, DefaultEnvironment),
}
if "true" == strings.ToLower(getEnv(KeyCaculateDebug, DefaultEnvironment)) {
Expand Down Expand Up @@ -190,7 +188,6 @@ func loadDefault() {
KeyCaculateStartDate: "",
KeyCaculateEndDate: "",
KeyCaculateDate: "2020-06-01",
KeyCaculatePeriodDay: "31",
KeyNetreqLimitMax: "20",
KeyFoundationDelegatorAddr: "iaa1w7ewedr57z6p7f8nknmdvukfxwkwlsvfjumdts",
}
Expand Down Expand Up @@ -242,7 +239,6 @@ type serverConf struct {
CaculateStartDate string
CaculateEndDate string
CaculateDate string
CaculatePeriodDay int
NetreqLimitMax int
FoundationDelegatorAddr string
}
Expand Down
20 changes: 0 additions & 20 deletions backend/orm/document/static_delegator_month.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,6 @@ func (d ExStaticDelegatorMonth) EnsureIndexes() []mgo.Index {
return indexes
}

func (d ExStaticDelegatorMonth) GetLatest(address string) (ExStaticDelegatorMonth, error) {
var res ExStaticDelegatorMonth
cond := bson.M{}
if address != "" {
cond[ExStaticDelegatorMonthAddressTag] = address
}
var query = orm.NewQuery()
defer query.Release()
query.SetCollection(d.Name()).
SetCondition(cond).
SetSort("-date").
SetSize(1).
SetResult(&res)

err := query.Exec()
if err != nil && err != mgo.ErrNotFound {
return res, err
}
return res, nil
}

func (d ExStaticDelegatorMonth) Batch(txs []txn.Op) error {
return orm.Batch(txs)
Expand Down
15 changes: 7 additions & 8 deletions backend/orm/document/static_delegator_month_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package document

import (
"testing"
"encoding/json"
)

func TestExStaticDelegatorMonth_GetLatest(t *testing.T) {
res, err := new(ExStaticDelegatorMonth).GetLatest("faa12t4gfg502wra9lhtjjvqudq82rrzu2sk5j2l09")
if err != nil {
t.Fatal(err.Error())
}

bytedata, _ := json.Marshal(res)
t.Log(string(bytedata))
//res, err := new(ExStaticDelegatorMonth).GetLatest("faa12t4gfg502wra9lhtjjvqudq82rrzu2sk5j2l09")
//if err != nil {
// t.Fatal(err.Error())
//}
//
//bytedata, _ := json.Marshal(res)
//t.Log(string(bytedata))
}
13 changes: 13 additions & 0 deletions backend/orm/document/static_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"time"
"github.com/irisnet/explorer/backend/types"
"encoding/json"
)

func TestExStaticValidator_GetCommissionRate(t *testing.T) {
Expand Down Expand Up @@ -36,3 +37,15 @@ func TestExStaticValidator_GetCommissionRate(t *testing.T) {
}
t.Log(data.Commission.Rate)
}

func TestExStaticValidator_GetDataOneDay(t *testing.T) {
address := "iva16tvg03gnrud9hzec7nsf9k8da74fqa9sk8xfqv"
datestr := fmt.Sprintf("%d-%02d-01T00:00:00", 2020, 6)
date, _ := time.ParseInLocation(types.TimeLayout, datestr, time.FixedZone("CST", 8*3600))
data, err := new(ExStaticValidator).GetDataOneDay(date, address)
if err != nil {
t.Fatal(err)
}
bytestr, _ := json.Marshal(data)
t.Log(string(bytestr))
}
42 changes: 20 additions & 22 deletions backend/rest/controller/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import (
"time"

"github.com/gorilla/mux"
"github.com/irisnet/explorer/backend/conf"
"github.com/irisnet/explorer/backend/lcd"
"github.com/irisnet/explorer/backend/logger"
"github.com/irisnet/explorer/backend/service"
"github.com/irisnet/explorer/backend/types"
"github.com/irisnet/explorer/backend/utils"
"github.com/irisnet/explorer/backend/vo"
Expand Down Expand Up @@ -119,26 +117,26 @@ func registerNavigationBar(r *mux.Router) error {
funGroup = append(funGroup, getTokenStatCirculation)
group.Add(1)

var getTokenStatFoundationBonded = func() {
defer func() {
group.Done()
if r := recover(); r != nil {
logger.Error("getTokenStatFoundationBonded error", logger.Any("err", r))
}
}()

accService := service.AccountService{}
if conf.Get().Hub.Prefix.AccAddr == types.MainnetAccPrefix {
res := accService.QueryDelegations(types.FoundationDelegatorAddr)
foundationBondAmt := float64(0)
for _, v := range res {
foundationBondAmt += v.Amount.Amount
}
result.FoundationBonded = utils.ParseStringFromFloat64(foundationBondAmt)
}
}
funGroup = append(funGroup, getTokenStatFoundationBonded)
group.Add(1)
//var getTokenStatFoundationBonded = func() {
//defer func() {
// group.Done()
// if r := recover(); r != nil {
// logger.Error("getTokenStatFoundationBonded error", logger.Any("err", r))
// }
//}()

//accService := service.AccountService{}
//if conf.Get().Hub.Prefix.AccAddr == types.MainnetAccPrefix {
//res := accService.QueryDelegations(types.FoundationDelegatorAddr)
//foundationBondAmt := float64(0)
//for _, v := range res {
// foundationBondAmt += v.Amount.Amount
//}
//result.FoundationBonded = utils.ParseStringFromFloat64(foundationBondAmt)
//}
//}
//funGroup = append(funGroup, getTokenStatFoundationBonded)
//group.Add(1)

var calculateAvgBlockTime = func() {
defer func() {
Expand Down
11 changes: 11 additions & 0 deletions backend/service/caculate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/irisnet/explorer/backend/types"
"math"
"strconv"
"math/big"
)

type CaculateService struct {
Expand Down Expand Up @@ -46,6 +47,16 @@ func LoadFromDelModel(model document.ExStaticDelegatorMonth) vo.ExStaticDelegato
PeriodDelegationTimes: model.PeriodDelegationTimes,
}
ret.Rewards = ret.TerminalRewards + ret.PeriodWithdrawRewards - ret.PeriodIncrementRewards
if true {
rewards := new(big.Rat).Mul(new(big.Rat).SetFloat64(ret.PeriodIncrementRewards), new(big.Rat).SetInt64(365))
delegations := new(big.Rat).Mul(new(big.Rat).SetFloat64(ret.TerminalDelegation), new(big.Rat).SetInt64(30))
if delegations.Cmp(new(big.Rat).SetInt64(0)) == 1 {
data := new(big.Rat).Quo(rewards, delegations)
ret.AnnualizedRate = new(big.Rat).Mul(data, new(big.Rat).SetInt64(100)).FloatString(2)
} else {
ret.AnnualizedRate = "0"
}
}
return ret
}

Expand Down
Loading

0 comments on commit 4235aa6

Please sign in to comment.