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 #1473 from irisnet/develop
Browse files Browse the repository at this point in the history
R4R:merge master from develop
  • Loading branch information
kaifei Hu authored Jul 15, 2020
2 parents 42814c9 + 7d4b54a commit da68dc5
Show file tree
Hide file tree
Showing 41 changed files with 603 additions and 245 deletions.
52 changes: 47 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
# explorer
Blockchain explorer for IRIS Hub
# Explorer

Blockchain explorer for IRIS Hub,which includes explorer-backend and explorer-frontend.

# Explorer-backend

## Run with docker
You can run application with docker.

```$xslt
cd github.com/irisnet/explorer/backend
docker build -t explorer-backend .
```
## ENV

# ENV
DB_ADDR: mongo url ( eg. 192.168.150.7:27017)

DB_DATABASE: mongo database name ( eg. sync-iris )
Expand All @@ -15,6 +25,38 @@ FAUCET_URL: faucet url ( eg. http://dev.faucet.irisplorer.io )

CHAIN_ID: chain-id ( eg. rainbow-dev )

# Docker Run
docker run -p 8080:8080 -e ${ENV Variables} explorer
detail: github.com/irisnet/explorer/backend/README.md

## Docker Run
docker run -p 8080:8080 -e ${ENV Variables} explorer-backend:latest

# Explorer-frontend

##Config
- vue.config.js
```$xslt
module.exports = {
devServer: {
proxy: {
'/api':{
target:'http://localhost:8080', //backend address:port
......
}
}
},
};
```


## Run with docker
You can run application with docker.

```$xslt
cd github.com/irisnet/explorer/frontend
docker build -t explorer-frontend .
```

## Docker Run
docker run -p 8080:8080 -e ${ENV Variables} explorer-frontend:latest


15 changes: 13 additions & 2 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
Blockchain explorer for the IRIS Hub
##### 1 Prerequisites

* go1.9.2+
* go1.13.0+

##### 2 install

```bash
go get github.com/irisnet/explorer
go get github.com/irisnet/explorer/backend
make all
```

Expand All @@ -27,14 +27,25 @@ Blockchain explorer for the IRIS Hub
CHAIN_ID : irishub chain-id
API_VERSION : explorer api version
MAX_DRAW_CNT : Maximum number of collections
SHOW_FAUCET : switch of show faucet
INITIAL_SUPPLY : initial supplay of IRIS Token
CUR_ENV : current environment(dev/qa/testnet/mainnet)
CronTimeAssetGateways: time interval of update asset gateways
CronTimeAssetTokens: time interval of update asset tokens
CronTimeGovParams: time interval of update gov params
CronTimeTxNumByDay: time interval of update tx num by day
CronTimeControlTask: time interval of monitor task execute
CronTimeAccountRewards: time interval of update account rewards
CronTimeValidators: time interval of update validators
CronTimeValidatorIcons: time interval of update validator icons
CronTimeProposalVoters: time interval of update voter info of proposal
CronTimeValidatorStaticInfo: time interval of cronjob to update validator static info include uptime, selfBond, delegatorNum
CronTimeFormatStaticDay: define time format of cronjob execute by every day
CronTimeFormatStaticMonth: define time format of cronjob execute by eveny month
CronTimeStaticDataDay: time interval of cronjob to snapshot delegator and validator rewards info
CronTimeStaticDataMonth: time interval of cronjob to caculate delegator and validator rewards info
CronTimeHeartBeat: time interval of heart beat in cron task
NetreqLimitMax: max network request to lcd node
//irishub v0.11.0 add
Expand Down
30 changes: 17 additions & 13 deletions backend/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const (
KeyCronTimeGovParams = "CronTimeGovParams"
KeyCronTimeTxNumByDay = "CronTimeTxNumByDay"
KeyCronTimeControlTask = "CronTimeControlTask"
KeyCronTimeHeartBeat = "CronTimeHeartBeat"
KeyCronTimeValidators = "CronTimeValidators"
KeyCronTimeAccountRewards = "CronTimeAccountRewards"
KeyCronTimeValidatorIcons = "CronTimeValidatorIcons"
Expand Down Expand Up @@ -96,18 +97,19 @@ func init() {
ApiVersion: getEnv(KeyApiVersion, DefaultEnvironment),
MaxDrawCnt: getEnvInt(KeyMaxDrawCnt, DefaultEnvironment),
ShowFaucet: getEnv(KeyShowFaucet, DefaultEnvironment),
CurEnv: getEnv(KeyCurEnv, DefaultEnvironment),
CronTimeAssetGateways: getEnvInt(KeyCronTimeAssetGateways, DefaultEnvironment),
CronTimeAssetTokens: getEnvInt(KeyCronTimeAssetTokens, DefaultEnvironment),
CronTimeGovParams: getEnvInt(KeyCronTimeGovParams, DefaultEnvironment),
CronTimeTxNumByDay: getEnvInt(KeyCronTimeTxNumByDay, DefaultEnvironment),
CronTimeControlTask: getEnvInt(KeyCronTimeControlTask, DefaultEnvironment),
CronTimeAccountRewards: getEnvInt(KeyCronTimeAccountRewards, DefaultEnvironment),
CronTimeValidators: getEnvInt(KeyCronTimeValidators, DefaultEnvironment),
CronTimeValidatorIcons: getEnvInt(KeyCronTimeValidatorIcons, DefaultEnvironment),
CronTimeProposalVoters: getEnvInt(KeyCronTimeProposalVoters, DefaultEnvironment),
CronTimeValidatorStaticInfo: getEnvInt(KeyCronTimeValidatorStaticInfo, DefaultEnvironment),
CronTimeFormatStaticDay: getEnv(KeyCronTimeFormatStaticDay, DefaultEnvironment),
CurEnv: getEnv(KeyCurEnv, DefaultEnvironment),
CronTimeAssetGateways: getEnvInt(KeyCronTimeAssetGateways, DefaultEnvironment),
CronTimeAssetTokens: getEnvInt(KeyCronTimeAssetTokens, DefaultEnvironment),
CronTimeGovParams: getEnvInt(KeyCronTimeGovParams, DefaultEnvironment),
CronTimeTxNumByDay: getEnvInt(KeyCronTimeTxNumByDay, DefaultEnvironment),
CronTimeControlTask: getEnvInt(KeyCronTimeControlTask, DefaultEnvironment),
CronTimeHeartBeat: getEnvInt(KeyCronTimeHeartBeat, DefaultEnvironment),
CronTimeAccountRewards: getEnvInt(KeyCronTimeAccountRewards, DefaultEnvironment),
CronTimeValidators: getEnvInt(KeyCronTimeValidators, DefaultEnvironment),
CronTimeValidatorIcons: getEnvInt(KeyCronTimeValidatorIcons, DefaultEnvironment),
CronTimeProposalVoters: getEnvInt(KeyCronTimeProposalVoters, DefaultEnvironment),
CronTimeValidatorStaticInfo: getEnvInt(KeyCronTimeValidatorStaticInfo, DefaultEnvironment),
CronTimeFormatStaticDay: getEnv(KeyCronTimeFormatStaticDay, DefaultEnvironment),
CronTimeFormatStaticMonth: getEnv(KeyCronTimeFormatStaticMonth, DefaultEnvironment),
CronTimeStaticDelegator: getEnvInt(KeyCronTimeStaticDataDay, DefaultEnvironment),
CronTimeStaticValidator: getEnvInt(KeyCronTimeStaticDataDay, DefaultEnvironment),
Expand Down Expand Up @@ -173,7 +175,8 @@ func loadDefault() {
KeyCronTimeAssetTokens: "60",
KeyCronTimeGovParams: "3600",
KeyCronTimeTxNumByDay: "86400",
KeyCronTimeControlTask: "30",
KeyCronTimeControlTask: "60",
KeyCronTimeHeartBeat: "10",
KeyCronTimeValidators: "60",
KeyCronTimeAccountRewards: "600",
KeyCronTimeProposalVoters: "60",
Expand Down Expand Up @@ -224,6 +227,7 @@ type serverConf struct {
CronTimeGovParams int
CronTimeTxNumByDay int
CronTimeControlTask int
CronTimeHeartBeat int
CronTimeValidators int
CronTimeAccountRewards int
CronTimeValidatorStaticInfo int
Expand Down
30 changes: 23 additions & 7 deletions backend/lcd/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/irisnet/explorer/backend/types"
"github.com/irisnet/explorer/backend/utils"
"github.com/irisnet/explorer/backend/vo"
"strings"
)

type (
Expand Down Expand Up @@ -56,20 +57,35 @@ func buildAccountVo(acc Account01411) AccountVo {
}

func Account(address string) (result AccountVo, err error) {
url := fmt.Sprintf(UrlAccount, conf.Get().Hub.LcdUrl, address)
resBytes, err := utils.Get(url)
acc, err := AccountInfo(address)
if err != nil {
return result, err
}
acc := Account01411{}
if err := json.Unmarshal(resBytes, &acc); err != nil {
logger.Error("get account error", logger.String("err", err.Error()))
return result, err
}
result = buildAccountVo(acc)
return result, nil
}

func AccountInfo(address string) (Account01411, error) {
acc := Account01411{}
if !strings.HasPrefix(address, conf.Get().Hub.Prefix.AccAddr) {
return acc, fmt.Errorf("address prefix is should %v", conf.Get().Hub.Prefix.AccAddr)
}
url := fmt.Sprintf(UrlAccount, conf.Get().Hub.LcdUrl, address)
resBytes, err := utils.Get(url)
if err != nil {
return acc, err
}
if len(resBytes) == 0 {
return acc, nil
}

if err := json.Unmarshal(resBytes, &acc); err != nil {
//logger.Error("get account error", logger.String("err", err.Error()))
return acc, err
}
return acc, nil
}
func Faucet(req *http.Request) (bz []byte, err error) {
uri := fmt.Sprintf(types.UrlFaucetAccountService, conf.Get().Server.FaucetUrl)
return utils.Forward(req, uri)
Expand All @@ -88,7 +104,7 @@ func GetIconsByKey(key string) (string, error) {
}
var picdata vo.LookupIcons
if err := json.Unmarshal(resBytes, &picdata); err != nil {
logger.Error("get icons error", logger.String("err", err.Error()))
//logger.Error("get icons error", logger.String("err", err.Error()))
return "", err
}

Expand Down
2 changes: 1 addition & 1 deletion backend/lcd/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func TestAccount(t *testing.T) {
address := "faa192vef4442d07lqde59mx35dvmfv9v72wrsu84a"
address := "faa1dmnnl50sagq2f6x88mz62rcn2mv5pfe53madlz"

if res, err := Account(address); err != nil {
t.Fatal(err)
Expand Down
10 changes: 9 additions & 1 deletion backend/lcd/stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func QueryWithdrawAddr(address string) (result string) {
}

func GetDelegationsByDelAddr(delAddr string) (delegations []DelegationVo) {
if !strings.HasPrefix(delAddr, conf.Get().Hub.Prefix.AccAddr) {
return
}
url := fmt.Sprintf(UrlDelegationsByDelegator, conf.Get().Hub.LcdUrl, delAddr)
resAsBytes, err := utils.Get(url)
if err != nil {
Expand Down Expand Up @@ -112,6 +115,9 @@ func GetWithdrawAddressByValidatorAcc(validatorAcc string) (string, error) {

func GetDistributionRewardsByValidatorAcc(validatorAcc string) (utils.CoinsAsStr, []RewardsFromDelegations, utils.CoinsAsStr, error) {

if !strings.HasPrefix(validatorAcc, conf.Get().Hub.Prefix.AccAddr) {
return nil, nil, nil, fmt.Errorf("address prefix is should %v", conf.Get().Hub.Prefix.AccAddr)
}
url := fmt.Sprintf(UrlDistributionRewardsByValidatorAcc, conf.Get().Hub.LcdUrl, validatorAcc)
resAsBytes, err := utils.Get(url)
if err != nil {
Expand Down Expand Up @@ -179,7 +185,9 @@ func GetUnbondingDelegationsByValidatorAddr(valAddr string) (unbondingDelegation
}

func GetUnbondingDelegationsByDelegatorAddr(delAddr string) (unbondingDelegations []UnbondingDelegations) {

if !strings.HasPrefix(delAddr, conf.Get().Hub.Prefix.AccAddr) {
return
}
url := fmt.Sprintf(UrlUnbondingDelegationByDelegator, conf.Get().Hub.LcdUrl, delAddr)
resAsBytes, err := utils.Get(url)
if err != nil {
Expand Down
5 changes: 0 additions & 5 deletions backend/lcd/stake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,3 @@ func TestGetUnbondingDelegationsByDelegatorAddr(t *testing.T) {
t.Logf("k: %v v: %v \n", k, v)
}
}

func TestGetDelegationsFromValAddrByDelAddr(t *testing.T) {
delegation := GetDelegationsFromValAddrByDelAddr("iaa1w7ewedr57z6p7f8nknmdvukfxwkwlsvfjumdts", "iva1qq93sapmdcx36uz64vvw5gzuevtxsc7lcfxsat")
t.Log(delegation.Tokens)
}
Loading

0 comments on commit da68dc5

Please sign in to comment.