Skip to content

Commit

Permalink
Merged release/0.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Potekhin committed Jul 24, 2018
2 parents da97624 + 2d41559 commit 2603ab1
Show file tree
Hide file tree
Showing 252 changed files with 28,414 additions and 3,014 deletions.
4 changes: 2 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func init() {
configCmd.Flags().StringVar(&conf.Config.TLSKey, "tls-key", "", "Filepath to the private key")
configCmd.Flags().Int64Var(&conf.Config.MaxPageGenerationTime, "mpgt", 1000, "Max page generation time in ms")
configCmd.Flags().StringSliceVar(&conf.Config.NodesAddr, "nodesAddr", []string{}, "List of addresses for downloading blockchain")
configCmd.Flags().BoolVar(&conf.Config.PrivateBlockchain, "privateBlockchain", false, "Is blockchain private")
configCmd.Flags().StringVar(&conf.Config.RunningMode, "runMode", "PublicBlockchain", "Node running mode")

viper.BindPFlag("PidFilePath", configCmd.Flags().Lookup("pid"))
viper.BindPFlag("LockFilePath", configCmd.Flags().Lookup("lock"))
Expand All @@ -147,7 +147,7 @@ func init() {
viper.BindPFlag("TLSCert", configCmd.Flags().Lookup("tls-cert"))
viper.BindPFlag("TLSKey", configCmd.Flags().Lookup("tls-key"))
viper.BindPFlag("MaxPageGenerationTime", configCmd.Flags().Lookup("mpgt"))
viper.BindPFlag("PrivateBlockchain", configCmd.Flags().Lookup("privateBlockchain"))
viper.BindPFlag("TempDir", configCmd.Flags().Lookup("tempDir"))
viper.BindPFlag("NodesAddr", configCmd.Flags().Lookup("nodesAddr"))
viper.BindPFlag("RunningMode", configCmd.Flags().Lookup("runMode"))
}
4 changes: 2 additions & 2 deletions cmd/generateFirstBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

"path/filepath"

"github.com/GenesisKernel/go-genesis/packages/block"
"github.com/GenesisKernel/go-genesis/packages/conf"
"github.com/GenesisKernel/go-genesis/packages/consts"
"github.com/GenesisKernel/go-genesis/packages/converter"
"github.com/GenesisKernel/go-genesis/packages/parser"
"github.com/GenesisKernel/go-genesis/packages/utils"
log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -83,7 +83,7 @@ var generateFirstBlockCmd = &cobra.Command{
return
}

block, err := parser.MarshallBlock(header, [][]byte{tx}, []byte("0"), "")
block, err := block.MarshallBlock(header, [][]byte{tx}, []byte("0"), "")
if err != nil {
log.WithFields(log.Fields{"type": consts.MarshallingError, "error": err}).Fatal("first block marshalling")
return
Expand Down
5 changes: 2 additions & 3 deletions cmd/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/GenesisKernel/go-genesis/packages/conf"
"github.com/GenesisKernel/go-genesis/packages/conf/syspar"
"github.com/GenesisKernel/go-genesis/packages/model"
"github.com/GenesisKernel/go-genesis/packages/parser"
"github.com/GenesisKernel/go-genesis/packages/rollback"
"github.com/GenesisKernel/go-genesis/packages/smart"
"github.com/GenesisKernel/go-genesis/packages/utils"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -39,8 +39,7 @@ var rollbackCmd = &cobra.Command{
log.WithError(err).Fatal("loading contracts")
return
}
parser := new(parser.Parser)
err := parser.RollbackToBlockID(blockID)
err := rollback.ToBlockID(blockID, nil, log.WithFields(log.Fields{}))
if err != nil {
log.WithError(err).Fatal("rollback to block id")
return
Expand Down
57 changes: 29 additions & 28 deletions packages/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
hr "github.com/julienschmidt/httprouter"
log "github.com/sirupsen/logrus"

"github.com/GenesisKernel/go-genesis/packages/conf"
"github.com/GenesisKernel/go-genesis/packages/consts"
"github.com/GenesisKernel/go-genesis/packages/converter"
"github.com/GenesisKernel/go-genesis/packages/model"
Expand All @@ -41,8 +42,9 @@ import (
)

const (
jwtPrefix = "Bearer "
jwtExpire = 36000 // By default, seconds
jwtPrefix = "Bearer "
jwtExpire = 36000 // By default, seconds
multipartBuf = 100000 // the buffer size for ParseMultipartForm
)

type apiData struct {
Expand Down Expand Up @@ -132,9 +134,6 @@ func errorAPI(w http.ResponseWriter, err interface{}, code int, params ...interf

func getPrefix(data *apiData) (prefix string) {
prefix = converter.Int64ToStr(data.ecosystemId)
if data.vde {
prefix += `_vde`
}
return
}

Expand Down Expand Up @@ -165,6 +164,7 @@ func getHeader(txName string, data *apiData) (tx.Header, error) {
// DefaultHandler is a common handle function for api requests
func DefaultHandler(method, pattern string, params map[string]int, handlers ...apiHandle) hr.Handle {
return hr.Handle(func(w http.ResponseWriter, r *http.Request, ps hr.Params) {
r.ParseMultipartForm(multipartBuf)
counterName := statsd.APIRouteCounterName(method, pattern)
statsd.Client.Inc(counterName+statsd.Count, 1, 1.0)
startTime := time.Now()
Expand Down Expand Up @@ -241,17 +241,12 @@ func fillToken(w http.ResponseWriter, r *http.Request, data *apiData, logger *lo

func fillParams(params map[string]int) apiHandle {
return func(w http.ResponseWriter, r *http.Request, data *apiData, logger *log.Entry) error {
// Getting and validating request parameters
vde := r.FormValue(`vde`)
if vde == `1` || vde == `true` {
data.vm = smart.GetVM(true, data.ecosystemId)
if data.vm == nil {
return errorAPI(w, `E_VDE`, http.StatusBadRequest, data.ecosystemId)
}
if conf.Config.IsSupportingVDE() {
data.vde = true
} else {
data.vm = smart.GetVM(false, 0)
}

data.vm = smart.GetVM()

for key, par := range params {
val := r.FormValue(key)
if par&pOptional == 0 && len(val) == 0 {
Expand All @@ -278,6 +273,10 @@ func fillParams(params map[string]int) apiHandle {
}

func checkEcosystem(w http.ResponseWriter, data *apiData, logger *log.Entry) (int64, string, error) {
if conf.Config.IsSupportingVDE() {
return consts.DefaultVDE, "1", nil
}

ecosystemID := data.ecosystemId
if data.params[`ecosystem`].(int64) > 0 {
ecosystemID = data.params[`ecosystem`].(int64)
Expand All @@ -292,9 +291,9 @@ func checkEcosystem(w http.ResponseWriter, data *apiData, logger *log.Entry) (in
}
}
prefix := converter.Int64ToStr(ecosystemID)
if data.vde {
prefix += `_vde`
}
// if data.vde {
// prefix += `_vde`
// }
return ecosystemID, prefix, nil
}

Expand All @@ -303,18 +302,20 @@ func fillTokenData(data *apiData, claims *JWTClaims, logger *log.Entry) error {
data.keyId = converter.StrToInt64(claims.KeyID)
data.isMobile = claims.IsMobile
data.roleId = converter.StrToInt64(claims.RoleID)
ecosystem := &model.Ecosystem{}
found, err := ecosystem.Get(data.ecosystemId)
if err != nil {
logger.WithFields(log.Fields{"type": consts.DBError, "error": err}).Error("on getting ecosystem from db")
return err
}
if !conf.Config.IsSupportingVDE() {
ecosystem := &model.Ecosystem{}
found, err := ecosystem.Get(data.ecosystemId)
if err != nil {
logger.WithFields(log.Fields{"type": consts.DBError, "error": err}).Error("on getting ecosystem from db")
return err
}

if !found {
err := fmt.Errorf("ecosystem not found")
logger.WithFields(log.Fields{"type": consts.NotFound, "id": data.ecosystemId, "error": err}).Error("ecosystem not found")
}
if !found {
err := fmt.Errorf("ecosystem not found")
logger.WithFields(log.Fields{"type": consts.NotFound, "id": data.ecosystemId, "error": err}).Error("ecosystem not found")
}

data.ecosystemName = ecosystem.Name
data.ecosystemName = ecosystem.Name
}
return nil
}
12 changes: 11 additions & 1 deletion packages/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"net/http"
"strings"

"github.com/GenesisKernel/go-genesis/packages/conf"

Expand Down Expand Up @@ -31,12 +32,21 @@ func getConfigOption(w http.ResponseWriter, r *http.Request, data *apiData, logg
return err
}

func replaceHttpSchemeToWs(centrifugoURL string) string {
if strings.HasPrefix(centrifugoURL, "http:") {
return strings.Replace(centrifugoURL, "http:", "ws:", -1)
} else if strings.HasPrefix(centrifugoURL, "https:") {
return strings.Replace(centrifugoURL, "https:", "wss:", -1)
}
return centrifugoURL
}

func centrifugoAddressHandler(w http.ResponseWriter, data *apiData) error {
if _, err := publisher.GetStats(); err != nil {
log.WithFields(log.Fields{"type": consts.CentrifugoError, "error": err}).Warn("on getting centrifugo stats")
return errorAPI(w, err, http.StatusNotFound)
}

data.result = conf.Config.Centrifugo.URL
data.result = replaceHttpSchemeToWs(conf.Config.Centrifugo.URL)
return nil
}
34 changes: 28 additions & 6 deletions packages/api/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,34 @@ func initVars(r *http.Request, data *apiData) *map[string]string {
vars[name] = r.FormValue(name)
}
vars[`_full`] = `0`
vars[`ecosystem_id`] = converter.Int64ToStr(data.ecosystemId)
vars[`key_id`] = converter.Int64ToStr(data.keyId)
vars[`isMobile`] = data.isMobile
vars[`role_id`] = converter.Int64ToStr(data.roleId)
vars[`ecosystem_name`] = data.ecosystemName

if data.keyId != 0 {
vars[`ecosystem_id`] = converter.Int64ToStr(data.ecosystemId)
vars[`key_id`] = converter.Int64ToStr(data.keyId)
vars[`isMobile`] = data.isMobile
vars[`role_id`] = converter.Int64ToStr(data.roleId)
vars[`ecosystem_name`] = data.ecosystemName
} else {
vars[`ecosystem_id`] = vars[`ecosystem`]
if len(vars[`keyID`]) > 0 {
vars[`key_id`] = vars[`keyID`]
} else {
vars[`key_id`] = `0`
}
if len(vars[`roleID`]) > 0 {
vars[`role_id`] = vars[`roleID`]
} else {
vars[`role_id`] = `0`
}
if len(vars[`isMobile`]) == 0 {
vars[`isMobile`] = `0`
}
if len(vars[`ecosystem_id`]) != 0 {
ecosystems := model.Ecosystem{}
if found, _ := ecosystems.Get(converter.StrToInt64(vars[`ecosystem_id`])); found {
vars[`ecosystem_name`] = ecosystems.Name
}
}
}
if _, ok := vars[`lang`]; !ok {
vars[`lang`] = r.Header.Get(`Accept-Language`)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api/content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestContent(t *testing.T) {
)`},
"source": {"true"},
},
`[{"tag":"data","attr":{"columns":"id,name","data":"1,Test message 1\n\t\t\t\t\t2,"Test message 2"\n\t\t\t\t\t3,"Test message 3"","source":"myforlist"}}]`,
`[{"tag":"data","attr":{"columns":"id,name","data":"1,Test message 1\n\t\t\t\t\t2,\"Test message 2\"\n\t\t\t\t\t3,\"Test message 3\"","source":"myforlist"}}]`,
},
{
"content",
Expand Down
Loading

0 comments on commit 2603ab1

Please sign in to comment.