Skip to content

Commit

Permalink
Merge pull request #51 from cosmos-gaminghub/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
EG-easy authored Sep 16, 2021
2 parents c332dcd + 881a5be commit ed5b343
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 56 deletions.
31 changes: 30 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ func GetProposalProposer(proposalId int) (types.ProposalProposerResult, error) {
logger.Error("Get proposal proposer error", logger.String("err", err.Error()))
}

fmt.Println(string(resBytes))
var result types.ProposalProposerResult
if err := json.Unmarshal(resBytes, &result); err != nil {
logger.Error("Unmarshal proposal proposer error", logger.String("err", err.Error()))
Expand Down Expand Up @@ -267,3 +266,33 @@ func GetProposalVotes(proposalId int, offset int) ([]types.ProposalVote, error)

return votes, nil
}

func GetValSigningInfo(consensusAddress string) (types.ValSigningInfo, error) {
url := fmt.Sprintf(lcd.UrlValSigningInfo, conf.Get().Hub.LcdUrl, consensusAddress)
resBytes, err := utils.Get(url)
if err != nil {
logger.Error("Get val signing info error address:"+consensusAddress, logger.String("err", err.Error()))
}

var result types.ValSigningInfo
if err := json.Unmarshal(resBytes, &result); err != nil {
logger.Error(fmt.Sprintf("Unmarshal val signing info error address: %s", consensusAddress), logger.String("err", err.Error()))
}

return result, nil
}

func GetProposalTally(id int) (types.PropsalTally, error) {
url := fmt.Sprintf(lcd.UrlProposalTally, conf.Get().Hub.LcdUrl, id)
resBytes, err := utils.Get(url)
if err != nil {
logger.Error(fmt.Sprintf("Get proposal tally error proposal: %d", id), logger.String("err", err.Error()))
}

var result types.PropsalTally
if err := json.Unmarshal(resBytes, &result); err != nil {
logger.Error(fmt.Sprintf("Unmarshal proposal tally error proposal: %d", id), logger.String("err", err.Error()))
}

return result, nil
}
4 changes: 3 additions & 1 deletion exporter/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strconv"

"github.com/cosmos-gaminghub/explorer-backend/client"
types "github.com/cosmos-gaminghub/explorer-backend/lcd"
"github.com/cosmos-gaminghub/explorer-backend/orm"
"github.com/cosmos-gaminghub/explorer-backend/orm/document"
Expand All @@ -27,12 +28,13 @@ func GetProposals(ps types.ProposalResult) (proposals []*schema.Proposal, err er
fmt.Println(err.Error())
continue
}
proposalTally, _ := client.GetProposalTally(proposalId)
pro := &schema.Proposal{
ProposalId: proposalId,
ProposalStatus: proposal.Status,
Content: proposal.Content,
SubmitTime: proposal.SubmitTime,
FinalTallyResult: proposal.FinalTallyResult,
FinalTallyResult: proposalTally.Tally,
VotingEndTime: proposal.VotingEndTime,
VotingStartTime: proposal.VotingStartTime,
DepositEndTime: proposal.DepositEndTime,
Expand Down
36 changes: 23 additions & 13 deletions exporter/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package exporter

import (
"encoding/base64"
"strconv"

"github.com/cosmos-gaminghub/explorer-backend/client"
"github.com/cosmos-gaminghub/explorer-backend/conf"
Expand Down Expand Up @@ -30,20 +31,29 @@ func GetValidators(vals []types.Validator, validatorSets []types.ValidatorOfVali
validator.Description.ImageUrl = client.GetImageUrl(validator.Description.Identity)
}

var missedBlockCount int64
if consensusAddress != "" {
valSigningInfo, err := client.GetValSigningInfo(consensusAddress)
if err == nil {
missedBlockCount, _ = strconv.ParseInt(valSigningInfo.Info.MissedBlocksCount, 10, 64)
}
}

val := &schema.Validator{
OperatorAddr: validator.OperatorAddress,
ConsensusAddres: consensusAddress,
ConsensusPubkey: validator.ConsensusPubkey.Key,
AccountAddr: utils.Convert(conf.Get().Db.AddresPrefix, validator.OperatorAddress),
Jailed: validator.Jailed,
Status: validator.Status,
Tokens: tokens,
DelegatorShares: validator.DelegatorShares,
Description: validator.Description,
UnbondingHeight: validator.UnbondingHeight,
UnbondingTime: validator.UnbondingTime,
Commission: validator.Commission,
ProposerAddr: str,
OperatorAddr: validator.OperatorAddress,
ConsensusAddres: consensusAddress,
ConsensusPubkey: validator.ConsensusPubkey.Key,
AccountAddr: utils.Convert(conf.Get().Db.AddresPrefix, validator.OperatorAddress),
Jailed: validator.Jailed,
Status: validator.Status,
Tokens: tokens,
DelegatorShares: validator.DelegatorShares,
Description: validator.Description,
UnbondingHeight: validator.UnbondingHeight,
UnbondingTime: validator.UnbondingTime,
Commission: validator.Commission,
ProposerAddr: str,
TotalMissedBlock: missedBlockCount,
}
validators = append(validators, val)
}
Expand Down
17 changes: 16 additions & 1 deletion lcd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ const (
UrlLookupIconsByKeySuffix = "https://keybase.io/_/api/1.0/user/lookup.json?fields=pictures&key_suffix=%s"
UrlAssetTokens = "%s/asset/tokens"
UrlAssetGateways = "%s/asset/gateways"
UrlValSigningInfo = "%s/cosmos/slashing/v1beta1/signing_infos/%s"

UrlProposal = "%s/cosmos/gov/v1beta1/proposals"
UrlProposalDeposit = "%s/cosmos/gov/v1beta1/proposals/%d/deposits"
UrlProposalProposer = "%s/gov/proposals/%d/proposer"
UrlProposalVoters = "%s/cosmos/gov/v1beta1/proposals/%d/votes?pagination.offset=%d"
UrlProposalTally = "%s/cosmos/gov/v1beta1/proposals/%d/tally"

DefaultValidatorSetLimit = 100
DefaultValidatorLimit = 200
Expand Down Expand Up @@ -782,7 +784,7 @@ type ProposalFinalTallyResult struct {
Yes string `json:"yes"`
Abstain string `json:"abstain"`
No string `json:"no"`
NoWithVeto string `bson:"no_with_veto" json:"no_with_veto"`
NoWithVeto string `json:"no_with_veto"`
}

type ProposalDepositResult struct {
Expand Down Expand Up @@ -822,3 +824,16 @@ type ProposalProposerResult struct {
Proposer string `json:"proposer"`
} `json:"result"`
}

type ValSigningInfo struct {
Info struct {
Address string `json:"address"`
StartHeight string `json:"start_height"`
IndexOffset string `json:"index_offset"`
MissedBlocksCount string `json:"missed_blocks_counter"`
} `json:"val_signing_info"`
}

type PropsalTally struct {
Tally ProposalFinalTallyResult `json:"tally"`
}
29 changes: 15 additions & 14 deletions orm/document/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@ const (
)

type Validator struct {
OperatorAddr string `json:"operator_address"`
ConsensusPubkey string `json:"consensus_pubkey"`
ConsensusAddres string `json:"consensus_address"`
AccountAddr string `json:"account_address"`
Jailed bool `json:"jailed"`
Status string `json:"status"`
Tokens int64 `json:"tokens"`
DelegatorShares string `json:"delegator_shares"`
Description types.Description `json:"description"`
UnbondingHeight string `json:"unbonding_height"`
UnbondingTime time.Time `json:"unbonding_time"`
Commission types.Commission `json:"commission"`
ProposerAddr string `json:"proposer_addr"`
Icons string `json:"icons"`
OperatorAddr string `json:"operator_address"`
ConsensusPubkey string `json:"consensus_pubkey"`
ConsensusAddres string `json:"consensus_address"`
AccountAddr string `json:"account_address"`
Jailed bool `json:"jailed"`
Status string `json:"status"`
Tokens int64 `json:"tokens"`
DelegatorShares string `json:"delegator_shares"`
Description types.Description `json:"description"`
UnbondingHeight string `json:"unbonding_height"`
UnbondingTime time.Time `json:"unbonding_time"`
Commission types.Commission `json:"commission"`
ProposerAddr string `json:"proposer_addr"`
Icons string `json:"icons"`
TotalMissedBlock int64 `json:"total_missed_block"`
}

func (v Validator) GetValidatorList() ([]Validator, error) {
Expand Down
54 changes: 28 additions & 26 deletions schema/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,38 @@ import (

// Validator defines the structure for validator information.
type Validator struct {
OperatorAddr string `bson:"operator_address"`
ConsensusPubkey string `bson:"consensus_pubkey"`
ConsensusAddres string `bson:"consensus_address"`
AccountAddr string `bson:"account_address"`
Jailed bool `bson:"jailed"`
Status string `bson:"status"`
Tokens int64 `bson:"tokens" json:"tokens"`
DelegatorShares string `bson:"delegator_shares"`
Description types.Description `bson:"description" json:"description"`
UnbondingHeight string `bson:"unbonding_height"`
UnbondingTime time.Time `bson:"unbonding_time"`
Commission types.Commission `bson:"commission" json:"commission"`
ProposerAddr string `bson:"proposer_addr"`
Icons string `bson:"icons"`
OperatorAddr string `bson:"operator_address"`
ConsensusPubkey string `bson:"consensus_pubkey"`
ConsensusAddres string `bson:"consensus_address"`
AccountAddr string `bson:"account_address"`
Jailed bool `bson:"jailed"`
Status string `bson:"status"`
Tokens int64 `bson:"tokens" json:"tokens"`
DelegatorShares string `bson:"delegator_shares"`
Description types.Description `bson:"description" json:"description"`
UnbondingHeight string `bson:"unbonding_height"`
UnbondingTime time.Time `bson:"unbonding_time"`
Commission types.Commission `bson:"commission" json:"commission"`
ProposerAddr string `bson:"proposer_addr"`
Icons string `bson:"icons"`
TotalMissedBlock int64 `bson:"total_missed_block"`
}

// NewValidator returns a new Validator.
func NewValidator(v Validator) *Validator {
return &Validator{
OperatorAddr: v.OperatorAddr,
ConsensusPubkey: v.ConsensusPubkey,
ConsensusAddres: v.ConsensusAddres,
AccountAddr: v.AccountAddr,
Jailed: v.Jailed,
Status: v.Status,
Tokens: v.Tokens,
DelegatorShares: v.DelegatorShares,
Description: v.Description,
UnbondingHeight: v.UnbondingHeight,
UnbondingTime: v.UnbondingTime,
Commission: v.Commission,
OperatorAddr: v.OperatorAddr,
ConsensusPubkey: v.ConsensusPubkey,
ConsensusAddres: v.ConsensusAddres,
AccountAddr: v.AccountAddr,
Jailed: v.Jailed,
Status: v.Status,
Tokens: v.Tokens,
DelegatorShares: v.DelegatorShares,
Description: v.Description,
UnbondingHeight: v.UnbondingHeight,
UnbondingTime: v.UnbondingTime,
Commission: v.Commission,
TotalMissedBlock: v.TotalMissedBlock,
}
}

0 comments on commit ed5b343

Please sign in to comment.