Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# hsnNet
HSN blockChain WebSite(dev chain)
7 changes: 7 additions & 0 deletions conf/app.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appname = hsnNet
httpport = 8080
runmode = dev
autorender = false
copyrequestbody = true
EnableDocs = true
HTTPAddr = 0.0.0.0
91 changes: 91 additions & 0 deletions conf/conf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package conf

import "time"

func NewConfig() Config {
return Config{
//DBstring: "mongodb://hsnnet:jiulian666@hsn_dev_mongo:27017/admin",
//DBName: "hsnNet",
//GenesisAddress: "http://127.0.0.1:26678/genesis?",
//Remote: RpcLcd{
// Rpc: "http://127.0.0.1:26678",
// Lcd: "http://127.0.0.1:1317",
//},
//DBstring: "mongodb://hsnhub_dev_test:hsn_test@172.38.8.89:27890/hsnhub_db_dev_test", //test
//DBName :"hsnhub_db_dev_test",//test
//
//GenesisAddress: "http://172.38.8.89:26678/genesis?",
//Remote: RpcLcd{
// Rpc: "http://172.38.8.89:26678",
// Lcd: "http://172.38.8.89:1317",
//},
DBstring: "127.0.0.1:27017/HsnBeta3", //test
DBName: "HsnBeta3", //test
GenesisAddress: "http://172.38.8.89:26678/genesis?",
Remote: RpcLcd{
Rpc: "http://172.38.8.89:26678",
Lcd: "http://172.38.8.89:1317",
},

Param: Params{ /* 爬虫间隔时间 deng*/
HTTPGetTimeOut: 30,
BlockInterval: 5,
PublicInterval: 5,
DelegationInterval: 30,
ValidatorsSetsInterval: 30,
TransactionsInterval: 30,
DelegatorInterval: 30, // SetValidatorDelegatorAddress
CanNotGetErrorInterval: 10,
},
Public: Publics{
Bech32PrefixAccAddr: "hsn",
Bech32PrefixValAddr: "hsnvaloper",
ChainId: "hsn",
ChainName: "hsn",
CoinGeckoId: "hsn",
CoinToVoitingPower: 1.0,
ValidatorsSetLimit: 100,
},
}

}

type Config struct {
DBstring string
DBName string
GenesisAddress string
Remote RpcLcd
Param Params
Public Publics
}

type RpcLcd struct {
Rpc string
Lcd string
}

type Publics struct {
ChainName string
ChainId string

Bech32PrefixAccAddr string
//Bech32PrefixAccPub string
Bech32PrefixValAddr string
//Bech32PrefixValPub string
//Bech32PrefixConsAddr string
//Bech32PrefixConPub string
//GasPrice float32
CoinGeckoId string // get price for coinGeckid
CoinToVoitingPower float32 // 代币转换votingPower比例
ValidatorsSetLimit int // 验证100个区块的验证者集合
}
type Params struct {
HTTPGetTimeOut time.Duration
BlockInterval time.Duration
PublicInterval time.Duration
DelegationInterval time.Duration
ValidatorsSetsInterval time.Duration
TransactionsInterval time.Duration
DelegatorInterval time.Duration
CanNotGetErrorInterval time.Duration
}
67 changes: 67 additions & 0 deletions controllers/accountDetails/baseInfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package accountDetails

import (
"github.com/astaxie/beego"
"github.com/shopspring/decimal"
"github.com/wongyinlong/hsnNet/conf"
"github.com/wongyinlong/hsnNet/models"
"github.com/wongyinlong/hsnNet/models/accountDetail"
"strings"
)

type BaseInfoController struct {
beego.Controller
}
type baseInfoerrMsg struct {
Data error `json:"data"`
Msg string `json:"msg"`
Code string `json:"code"`
}
type baseInfoMsg struct {
Data accountDetail.BaseInfo `json:"data"`
Msg string`json:"msg"`
Code string `json:"code"`
}
/**/
// @Title
// @Description
// @Success code 0
// @Failure code 1
//@router /
func (bic *BaseInfoController) Get() {
bic.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", bic.Ctx.Request.Header.Get("Origin"))
address := bic.GetString("address")
if address == ""|| strings.Index(address,conf.NewConfig().Public.Bech32PrefixAccAddr)!=0 || strings.Index(address,conf.NewConfig().Public.Bech32PrefixValAddr)==0{
var msg baseInfoerrMsg
msg.Data=nil
msg.Msg="Delegator address is empty Or Error address!"
msg.Code ="1"
bic.Data["json"]=msg
}else {
//获取验证人账户信息和获取提款地址
var baseInfo accountDetail.BaseInfo
var account accountDetail.Account
var withdrawAddress accountDetail.WithdrawAddress
var price models.Infomation
decimalPrice,_:=decimal.NewFromString(price.GetInfo().Price)
var msg baseInfoMsg
baseInfo.Address,_ =account.GetInfo(address)
decimalTotalAmount := GetAllKindsAmount(address).Data.TotalAmount[0]
baseInfo.Amount ,_= decimalTotalAmount.Float64()
baseInfo.RewardAddress = withdrawAddress.GetWithDrawAddress(address)
baseInfo.TotalPrice,_= decimalTotalAmount.Mul(decimalPrice).Float64()
baseInfo.Price ,_= decimalPrice.Float64()
msg.Data = baseInfo
msg.Code = "0"
msg.Msg = "OK"
bic.Data["json"] = msg
}
bic.ServeJSON()

}
func getDeciamlRewardAmount(address string)decimal.Decimal{
var delegateReward accountDetail.DelegateRewards
amount := delegateReward.GetDelegateReward(address)
decimalAmount ,_:= decimal.NewFromString(amount)
return decimalAmount
}
97 changes: 97 additions & 0 deletions controllers/accountDetails/delegators.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package accountDetails

import (
"github.com/astaxie/beego"
"github.com/wongyinlong/hsnNet/conf"
"github.com/wongyinlong/hsnNet/models/accountDetail"
"strings"
)

type DeleatorsController struct {
beego.Controller
}
type DelegatorerrMsg struct {
Data error `json:"data"`
Msg string `json:"msg"`
Code string `json:"code"`
}
type DelegatorMsg struct {
Data accountDetail.Delegators `json:"data"`
Msg string `json:"msg"`
Total int `json:"total"`
Size int `json:"size"`
Code string `json:"code"`
}

// @Title
// @Description
// @Success code 0
// @Failure code 1
//@router /
func (dc *DeleatorsController) Get() {
dc.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", dc.Ctx.Request.Header.Get("Origin"))
address := dc.GetString("address")
page, _ := dc.GetInt("page", 0)
size, _ := dc.GetInt("size", 5)

if address == ""|| strings.Index(address,conf.NewConfig().Public.Bech32PrefixAccAddr)!=0 || strings.Index(address,conf.NewConfig().Public.Bech32PrefixValAddr)==0{
var msg baseInfoerrMsg
msg.Data = nil
msg.Msg = "Delegator address is empty Or Error address!"
msg.Code = "1"
dc.Data["json"] = msg
} else {
//获取验证人账户信息和获取提款地址
var msg DelegatorMsg
var delegators accountDetail.Delegators
infos := delegators.GetInfo(address)
msg.Code = "0"
msg.Size = size
msg.Total = len(infos.Result)
msg.Msg = "OK"
msg.Data = *infos
//msg.Data = *infos

/*分页*/
msg.Data = *delegatorPagination(page, size, msg.Total, infos)
dc.Data["json"]=msg



}
dc.ServeJSON()

}
func delegatorPagination(page, size, totalSize int, infos *accountDetail.Delegators) *accountDetail.Delegators {
//accountDetail.Unbonding
var tempVar accountDetail.Delegators

if page*size <= 0 {
//return first page
if totalSize < size {
for i := 0; i < totalSize; i++ {
tempVar.Result = append(tempVar.Result, infos.Result[i])
}
} else {
for i := 0; i < size; i++ {
tempVar.Result = append(tempVar.Result, infos.Result[i])
}
}
return &tempVar
}
if page*size > 0 && (page+1)*size <= totalSize {
for i := (page * size); i < (page+1)*size; i++ {
tempVar.Result = append(tempVar.Result, infos.Result[i])
}
return &tempVar
}
if (page+1)*size > totalSize {
//return last page
if totalSize-(page)*size > 0 {
for i := page * size; i < totalSize; i++ {
tempVar.Result = append(tempVar.Result, infos.Result[i])
}
}
}
return &tempVar
}
Loading