Skip to content

Commit

Permalink
udpate
Browse files Browse the repository at this point in the history
  • Loading branch information
powerpook committed Jul 15, 2020
1 parent 5b37ed6 commit 43f20b6
Show file tree
Hide file tree
Showing 20 changed files with 173 additions and 140 deletions.
23 changes: 10 additions & 13 deletions packages/api/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,6 @@ func getBlocksTxInfoHandler(w http.ResponseWriter, r *http.Request) {

blocks, err := model.GetBlockchain(form.BlockID, form.BlockID+form.Count, model.OrderASC)
if err != nil {
logger.WithFields(log.Fields{"type": consts.DBError, "error": err}).Error("on getting blocks range")
errorResponse(w, err)
return
}

if len(blocks) == 0 {
errorResponse(w, errNotFound)
return
}

result := map[int64][]TxInfo{}
for _, blockModel := range blocks {
blck, err := block.UnmarshallBlock(bytes.NewBuffer(blockModel.Data), false)
if err != nil {
logger.WithFields(log.Fields{"type": consts.UnmarshallingError, "error": err, "bolck_id": blockModel.ID}).Error("on unmarshalling block")
errorResponse(w, err)
Expand Down Expand Up @@ -174,6 +161,16 @@ type TxDetailedInfo struct {
}

type BlockHeaderInfo struct {
BlockID int64 `json:"block_id"`
Time int64 `json:"time"`
EcosystemID int64 `json:"-"`
KeyID int64 `json:"key_id"`
NodePosition int64 `json:"node_position"`
Sign []byte `json:"-"`
Hash []byte `json:"-"`
Version int `json:"version"`
}

type BlockDetailedInfo struct {
Header BlockHeaderInfo `json:"header"`
Hash []byte `json:"hash"`
Expand Down
12 changes: 9 additions & 3 deletions packages/api/getuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ func getUIDHandler(w http.ResponseWriter, r *http.Request) {
result.Expire = converter.Int64ToStr(claims.ExpiresAt - time.Now().Unix())
result.KeyID = claims.KeyID
jsonResponse(w, result)
return
}
}

result.UID = converter.Int64ToStr(rand.New(rand.NewSource(time.Now().Unix())).Int63())
claims := JWTClaims{
UID: result.UID,
EcosystemID: "1",
StandardClaims: jwt.StandardClaims{
ExpiresAt: time.Now().Add(jwtUIDExpire).Unix(),
},
}

var err error
if result.Token, err = generateJWTToken(claims); err != nil {
logger := getLogger(r)
logger.WithFields(log.Fields{"type": consts.JWTError, "error": err}).Error("generating jwt token")
errorResponse(w, err)
Expand Down
8 changes: 8 additions & 0 deletions packages/api/subnode_src_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ func SubNodeSrcTaskUpdateHandlre(w http.ResponseWriter, r *http.Request) {
m.UpdateTime = time.Now().Unix()
if err = m.Updates(); err != nil {
logger.WithFields(log.Fields{"error": err}).Error("Update table failed")
return
}

jsonResponse(w, result)
}

func SubNodeSrcTaskDeleteHandlre(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
logger := getLogger(r)
id := converter.StrToInt64(params["id"])

Expand Down
15 changes: 8 additions & 7 deletions packages/block/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ var (
// ErrLimitTime returns when the time limit exceeded
ErrLimitTime = errors.New(`Time limit exceeded`)
)

// NewLimits initializes Limits structure.
func NewLimits(b *Block) (limits *Limits) {
limits = &Limits{Block: b, Limiters: make([]Limiter, 0, 8)}
if b == nil {
limits.Mode = letPreprocess
} else if b.GenBlock {
limits.Mode = letGenBlock
} else {
limits.Mode = letParsing
Expand Down Expand Up @@ -108,6 +101,14 @@ func (bl *txMaxLimit) init(b *Block) {
}

func (bl *txMaxLimit) check(t *transaction.Transaction, mode int) error {
bl.Count++
if bl.Count+1 > bl.Limit && mode == letPreprocess {
return ErrLimitStop
}
if bl.Count > bl.Limit {
return limitError(`txMaxLimit`, `Max tx in the block`)
}
return nil
}

// Checking the time of the start of generating block
Expand Down
16 changes: 3 additions & 13 deletions packages/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,6 @@ func FillRuntimePaths() error {

if Config.LockFilePath == "" {
Config.LockFilePath = filepath.Join(Config.DataDir, consts.DefaultLockFilename)
}

return nil
}

// FillRuntimeKey fills parameters of keys from runtime parameters
func FillRuntimeKey() error {
keyIDFileName := filepath.Join(Config.KeysDir, consts.KeyIDFilename)
keyIDBytes, err := os.ReadFile(keyIDFileName)
if err != nil {
log.WithFields(log.Fields{"type": consts.IOError, "error": err, "path": keyIDFileName}).Error("reading KeyID file")
return err
}

Config.KeyID, err = strconv.ParseInt(string(keyIDBytes), 10, 64)
if err != nil {
Expand Down Expand Up @@ -332,6 +319,9 @@ func (c GlobalConfig) IsNode() bool {
//
//Add sub node processing
// IsSubNode check running mode
func (c GlobalConfig) IsSubNode() bool {
return RunMode(c.OBSMode).IsSubNode()
}

func registerCrypto(c CryptoSettings) {
crypto.InitCurve(c.Cryptoer)
Expand Down
20 changes: 8 additions & 12 deletions packages/daemons/locking.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ import (
"github.com/IBAX-io/go-ibax/packages/transaction"

log "github.com/sirupsen/logrus"
)

var mutex = sync.Mutex{}

// WaitDB waits for the end of the installation
func WaitDB(ctx context.Context) error {
// There is could be the situation when installation is not over yet.
// Database could be created but tables are not inserted yet

if model.DBConn != nil && CheckDB() {
return nil
}

// poll a base with period
tick := time.NewTicker(1 * time.Second)
Expand All @@ -35,6 +23,14 @@ func WaitDB(ctx context.Context) error {
case <-tick.C:
if model.DBConn != nil && CheckDB() {
return nil
}
case <-ctx.Done():
return ctx.Err()
}
}
}

// CheckDB check if installation complete or not
func CheckDB() bool {
install := &model.Install{}

Expand Down
2 changes: 0 additions & 2 deletions packages/daemons/upd_full_nodes.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) IBAX. All rights reserved.
* See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/

24 changes: 10 additions & 14 deletions packages/migration/contracts/first_ecosystem/Import.sim
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,17 @@ contract Import {
tbl = "@1" + Str(type)
if type == "app_params" {
item = DBFind(tbl).Where({"name": name, "ecosystem": $ecosystem_id, "app_id": $ApplicationId}).Row()
} else {
item = DBFind(tbl).Where({"name": name, "ecosystem": $ecosystem_id}).Row()
}
var contractName string
if item {
contractName = editors[type]
cdata["Id"] = Int(item["id"])
if type == "contracts" {
if item["conditions"] == "false" {
// ignore updating impossible
contractName = ""
}
} elif type == "menu" {
var menu menuItem string
menu = Replace(item["value"], " ", "")
menu = Replace(menu, "\n", "")
menu = Replace(menu, "\r", "")
menuItem = Replace(cdata["Value"], " ", "")
menuItem = Replace(menuItem, "\n", "")
menuItem = Replace(menuItem, "\r", "")
if Contains(menu, menuItem) {
// ignore repeated
contractName = ""
} else {
cdata["Value"] = item["value"] + "\n" + cdata["Value"]
}
}
} else {
Expand Down
16 changes: 6 additions & 10 deletions packages/migration/first_tables_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ INSERT INTO "1_tables" ("id", "name", "permissions","columns", "conditions") VAL
"block_id": "ContractAccess(\"@1CallDelayedContract\",\"@1EditDelayedContract\")",
"every_block": "ContractAccess(\"@1EditDelayedContract\")",
"counter": "ContractAccess(\"@1CallDelayedContract\",\"@1EditDelayedContract\")",
"high_rate": "ContractAccess(\"@1EditDelayedContract\")",
"limit": "ContractAccess(\"@1EditDelayedContract\")",
"deleted": "ContractAccess(\"@1EditDelayedContract\")",
"conditions": "ContractAccess(\"@1EditDelayedContract\")"
}',
'ContractConditions("@1AdminCondition")'
),
(next_id('1_tables'), 'ecosystems',
'{
Expand Down Expand Up @@ -79,16 +85,6 @@ INSERT INTO "1_tables" ("id", "name", "permissions","columns", "conditions") VAL
"ban_time": "ContractAccess(\"@1CheckNodesBan\")",
"reason": "ContractAccess(\"@1CheckNodesBan\")"
}',
'ContractConditions("@1AdminCondition")'
),
(next_id('1_tables'), 'time_zones',
'{
"insert": "false",
"update": "false",
"new_column": "false"
}',
'{
"name": "false",
"offset": "false"
}',
'ContractConditions("@1AdminCondition")'
Expand Down
7 changes: 7 additions & 0 deletions packages/migration/pages_data.go
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) IBAX. All rights reserved.
* See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/

package migration
(next_id('1_pages'), 'admin_index', '', 'admin_menu', 'ContractConditions("@1DeveloperCondition")', '{{.AppID}}', '{{.Ecosystem}}'),
(next_id('1_pages'), 'developer_index', '', 'developer_menu', 'ContractConditions("@1DeveloperCondition")', '{{.AppID}}', '{{.Ecosystem}}');`
14 changes: 10 additions & 4 deletions packages/model/mine_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ package model
import (
"github.com/shopspring/decimal"
)
Amount decimal.Decimal `gorm:"not null default 0" ` //
Expired int64 `gorm:"null" `
Status int64 `gorm:"null"` //
Review int64 `gorm:"null default 0" ` //

type MineStake struct {
ID int64 `gorm:"primary_key not null"`
Number int64 `gorm:"null" ` //number
Devid int64 `gorm:";not null" ` //devid
Keyid int64 `gorm:"not null" ` //keyid
Poolid int64 `gorm:"not null" ` //
MineType int64 `gorm:"not null"`
MineNumber string `gorm:"not null"`
MineCapacity int64 `gorm:"not null"`
Count int64 `gorm:"null default 0" ` //
Stakes int64 `gorm:"null default 0" ` //
Transfers int64 `gorm:"null" ` //
Expand Down
10 changes: 7 additions & 3 deletions packages/model/rollback_tx.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) IBAX. All rights reserved.
* See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/

package model

import "gorm.io/gorm"

Expand Down Expand Up @@ -62,6 +59,13 @@ func CreateBatchesRollbackTx(dbTx *gorm.DB, rts []*RollbackTx) error {
var err error
if rollbackSys.ID, err = GetNextID(&DbTransaction{conn: dbTx}, rollbackSys.TableName()); err != nil {
return err
}
for i := 1; i < len(rts)+1; i++ {
rts[i-1].ID = rollbackSys.ID + int64(i) - 1
}
return dbTx.Model(&RollbackTx{}).Create(&rts).Error
}

// Create is creating record of model
func (rt *RollbackTx) Create(transaction *DbTransaction) error {
return nil
Expand Down
19 changes: 13 additions & 6 deletions packages/model/vde_dest_chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
* Copyright (c) IBAX. All rights reserved.
* See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
package model

type VDEDestChainInfo struct {
ID int64 `gorm:"primary_key; not null" json:"id"`
BlockchainHttp string `gorm:"not null" json:"blockchain_http"`
BlockchainEcosystem string `gorm:"not null" json:"blockchain_ecosystem"`
Comment string `gorm:"not null" json:"comment"`

UpdateTime int64 `gorm:"not null" json:"update_time"`
CreateTime int64 `gorm:"not null" json:"create_time"`
}

func (VDEDestChainInfo) TableName() string {
return "vde_dest_chain_info"
}

Expand All @@ -25,9 +38,3 @@ func (m *VDEDestChainInfo) Get() (*VDEDestChainInfo, error) {
func (m *VDEDestChainInfo) GetAll() ([]VDEDestChainInfo, error) {
var result []VDEDestChainInfo
err := DBConn.Find(&result).Error
return result, err
}
func (m *VDEDestChainInfo) GetOneByID() (*VDEDestChainInfo, error) {
err := DBConn.Where("id=?", m.ID).First(&m).Error
return m, err
}
3 changes: 0 additions & 3 deletions packages/model/vde_dest_data_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ func (m *VDEDestDataStatus) GetAllByHashState(HashState int64) ([]VDEDestDataSta
}

func (m *VDEDestDataStatus) GetAllBySignState(SignState int64) ([]VDEDestDataStatus, error) {
result := make([]VDEDestDataStatus, 0)
err := DBConn.Table("vde_dest_data_status").Where("task_uuid = ? AND auth_state = ? AND sign_state = ? AND hash_state = ?", TaskUUID, AuthState, SignState, HashState).Find(&result).Error
return result, err
}

func (m *VDEDestDataStatus) GetAllByTaskUUIDAndDataStatusAndTime(TaskUUID string, AuthState int64, SignState int64, HashState int64, BTime int64, ETime int64) ([]VDEDestDataStatus, error) {
Expand Down
35 changes: 35 additions & 0 deletions packages/model/vde_dest_task_time.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) IBAX. All rights reserved.
* See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
package model

return "vde_dest_task_time"
}

func (m *VDEDestTaskTime) Create() error {
return DBConn.Create(&m).Error
}

func (m *VDEDestTaskTime) Updates() error {
return DBConn.Model(m).Updates(m).Error
}

func (m *VDEDestTaskTime) Delete() error {
return DBConn.Delete(m).Error
}

func (m *VDEDestTaskTime) Get() (*VDEDestTaskTime, error) {
err := DBConn.First(&m).Error
return m, err
}

func (m *VDEDestTaskTime) GetAll() ([]VDEDestTaskTime, error) {
var result []VDEDestTaskTime
err := DBConn.Find(&result).Error
return result, err
}
func (m *VDEDestTaskTime) GetOneByID() (*VDEDestTaskTime, error) {
err := DBConn.Where("id=?", m.ID).First(&m).Error
return m, err
}
17 changes: 3 additions & 14 deletions packages/smart/smart_p_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@
* Copyright (c) IBAX. All rights reserved.
* See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
package smart

import (
"testing"
)

func TestRegexpMatch(t *testing.T) {
type args struct {
str string
reg string
}
tests := []struct {
name string
args args
want bool
}{
// TODO: Add test cases.
Expand All @@ -28,3 +14,6 @@ func TestRegexpMatch(t *testing.T) {
if got := RegexpMatch(tt.args.str, tt.args.reg); got != tt.want {
t.Errorf("RegexpMatch() = %v, want %v", got, tt.want)
}
})
}
}
Loading

0 comments on commit 43f20b6

Please sign in to comment.