diff --git a/packages/api/block.go b/packages/api/block.go index de71da2f..d830090f 100644 --- a/packages/api/block.go +++ b/packages/api/block.go @@ -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) @@ -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"` diff --git a/packages/api/getuid.go b/packages/api/getuid.go index a5d79fcd..820363a7 100644 --- a/packages/api/getuid.go +++ b/packages/api/getuid.go @@ -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) diff --git a/packages/api/subnode_src_task.go b/packages/api/subnode_src_task.go index 9dc44d6f..581a0b02 100644 --- a/packages/api/subnode_src_task.go +++ b/packages/api/subnode_src_task.go @@ -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"]) diff --git a/packages/block/limits.go b/packages/block/limits.go index 9a2bef5c..ce01016f 100644 --- a/packages/block/limits.go +++ b/packages/block/limits.go @@ -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 @@ -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 diff --git a/packages/conf/conf.go b/packages/conf/conf.go index 8751216e..fea7f6a1 100644 --- a/packages/conf/conf.go +++ b/packages/conf/conf.go @@ -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 { @@ -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) diff --git a/packages/daemons/locking.go b/packages/daemons/locking.go index de9baaa5..5b91a5d9 100644 --- a/packages/daemons/locking.go +++ b/packages/daemons/locking.go @@ -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) @@ -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{} diff --git a/packages/daemons/upd_full_nodes.go b/packages/daemons/upd_full_nodes.go index 7ab44938..0cc7376d 100644 --- a/packages/daemons/upd_full_nodes.go +++ b/packages/daemons/upd_full_nodes.go @@ -1,5 +1,3 @@ /*--------------------------------------------------------------------------------------------- * Copyright (c) IBAX. All rights reserved. * See LICENSE in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - diff --git a/packages/migration/contracts/first_ecosystem/Import.sim b/packages/migration/contracts/first_ecosystem/Import.sim index 28b9dc82..e90bba0f 100644 --- a/packages/migration/contracts/first_ecosystem/Import.sim +++ b/packages/migration/contracts/first_ecosystem/Import.sim @@ -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 { diff --git a/packages/migration/first_tables_data.go b/packages/migration/first_tables_data.go index aa6abca5..32b5ce19 100644 --- a/packages/migration/first_tables_data.go +++ b/packages/migration/first_tables_data.go @@ -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', '{ @@ -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")' diff --git a/packages/migration/pages_data.go b/packages/migration/pages_data.go index 679f1eaf..8e9068c4 100644 --- a/packages/migration/pages_data.go +++ b/packages/migration/pages_data.go @@ -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}}');` diff --git a/packages/model/mine_stake.go b/packages/model/mine_stake.go index a797abc0..221e4ad9 100644 --- a/packages/model/mine_stake.go +++ b/packages/model/mine_stake.go @@ -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" ` // diff --git a/packages/model/rollback_tx.go b/packages/model/rollback_tx.go index 2fb58d9d..778c9cfa 100644 --- a/packages/model/rollback_tx.go +++ b/packages/model/rollback_tx.go @@ -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" @@ -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 diff --git a/packages/model/vde_dest_chain_info.go b/packages/model/vde_dest_chain_info.go index 224da00c..46752b81 100644 --- a/packages/model/vde_dest_chain_info.go +++ b/packages/model/vde_dest_chain_info.go @@ -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" } @@ -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 -} diff --git a/packages/model/vde_dest_data_status.go b/packages/model/vde_dest_data_status.go index 5f7379ff..b5ed9742 100644 --- a/packages/model/vde_dest_data_status.go +++ b/packages/model/vde_dest_data_status.go @@ -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) { diff --git a/packages/model/vde_dest_task_time.go b/packages/model/vde_dest_task_time.go new file mode 100644 index 00000000..c8cb1417 --- /dev/null +++ b/packages/model/vde_dest_task_time.go @@ -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 +} diff --git a/packages/smart/smart_p_test.go b/packages/smart/smart_p_test.go index 5e27a4b3..d883484d 100644 --- a/packages/smart/smart_p_test.go +++ b/packages/smart/smart_p_test.go @@ -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. @@ -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) } + }) + } +} diff --git a/packages/template/calculate.go b/packages/template/calculate.go index 1b79b789..765ec5e9 100644 --- a/packages/template/calculate.go +++ b/packages/template/calculate.go @@ -96,19 +96,6 @@ func parsing(input string, itype int) (*[]token, error) { numlen = 0 } if item, ok := ops[ch]; ok { - if prevOper() { - return nil, errExp - } - newToken(item.id, item.pr) - continue - } - switch ch { - case '(': - if prevNumber() { - return nil, errExp - } - newToken(tkLPar, 3) - case ')': if prevOper() { return nil, errExp } @@ -265,6 +252,11 @@ func calculate(exp, etype, prec string) string { stack = append(stack, last) buf[len(buf)-1] = item continue + } + } + buf = append(buf, item) + } + } for i := len(buf) - 1; i >= 0; i-- { last := buf[i] if last.Type >= tkAdd && last.Type <= tkDiv { diff --git a/packages/template/funcs.go b/packages/template/funcs.go index bc82a1d4..879d3ade 100644 --- a/packages/template/funcs.go +++ b/packages/template/funcs.go @@ -443,6 +443,11 @@ func orTag(par parFunc) string { } } return `0` +} + +func alertTag(par parFunc) string { + setAllAttr(par) + par.Owner.Attr[`alert`] = par.Node.Attr return `` } @@ -1394,12 +1399,6 @@ func binaryTag(par parFunc) string { defaultTail(par, `binary`) if par.Node.Attr[`ecosystem`] != nil { ecosystemID = par.Node.Attr[`ecosystem`].(string) - } else { - ecosystemID = getVar(par.Workspace, `ecosystem_id`) - } - binary := &model.Binary{} - binary.SetTablePrefix(ecosystemID) - var ( ok bool err error diff --git a/packages/transaction/transaction_cache.go b/packages/transaction/transaction_cache.go new file mode 100644 index 00000000..ba9c670a --- /dev/null +++ b/packages/transaction/transaction_cache.go @@ -0,0 +1,23 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) IBAX. All rights reserved. + * See LICENSE in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + defer tc.mutex.RUnlock() + + t, ok = tc.cache[hash] + return +} + +func (tc *transactionCache) Set(t *Transaction) { + tc.mutex.Lock() + defer tc.mutex.Unlock() + + tc.cache[string(t.TxHash)] = t +} + +func (tc *transactionCache) Clean() { + tc.mutex.Lock() + defer tc.mutex.Unlock() + + tc.cache = make(map[string]*Transaction) +} diff --git a/packages/vde_sdk/sdk.go b/packages/vde_sdk/sdk.go index 78ba238e..11a920d1 100644 --- a/packages/vde_sdk/sdk.go +++ b/packages/vde_sdk/sdk.go @@ -437,23 +437,6 @@ func KeyLogin(apiAddress string, from string, state int64) (gAuth string, gAddre if err != nil { return "", "", "", "", false, err } - if len(key) > 64 { - key = key[:64] - } - - // add get new uid - gAuth = "" - - var ret getUIDResult - err = sendGet(apiAddress, gAuth, `getuid`, nil, &ret) - if err != nil { - return "", "", "", "", false, err - } - gAuth = ret.Token - - if len(ret.UID) == 0 { - return "", "", "", "", false, fmt.Errorf(`getuid has returned empty uid`) - } var pub string @@ -639,6 +622,9 @@ func PostTxResult(apiAddress string, apiEcosystemID int64, gAuth string, gPrivat switch field.Type { case "bool": + params[name], err = strconv.ParseBool(value) + case "int": + params[name], err = strconv.ParseInt(value, 10, 64) case "float": params[name], err = strconv.ParseFloat(value, 64) //