Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
powerpook committed Jul 15, 2020
1 parent 43f20b6 commit f9e0a32
Show file tree
Hide file tree
Showing 25 changed files with 336 additions and 164 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ language: go
env: GO111MODULE=on

go:
- 1.12.x
13 changes: 6 additions & 7 deletions packages/api/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@

package api

import (
stdErrors "errors"
"testing"
)

func TestHistory(t *testing.T) {
if err := keyLogin(1); err != nil {
var ret historyResult
err := sendGet("history/pages/1", nil, &ret)
if err != nil {
t.Error(err)
return
}
if len(ret.List) == 0 {
t.Error(stdErrors.New("History should not be empty"))
}

err = sendGet("history/pages/1000", nil, &ret)
if err != nil {
Expand Down
16 changes: 9 additions & 7 deletions packages/daemons/subnode_agent_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ func SubNodeAgentData(ctx context.Context, d *daemon) error {
//}

nodePrivateKey, err := utils.GetNodePrivateKey()
if err != nil || len(nodePrivateKey) < 1 {
if err == nil {
log.WithFields(log.Fields{"type": consts.EmptyObject}).Error("node private key is empty")
}
return err
}

// send task data
for _, item := range ShareData {
//
dataBase64, err := base64.StdEncoding.DecodeString(string(item.Data))
if err != nil {
Expand Down Expand Up @@ -108,13 +117,6 @@ func SubNodeAgentData(ctx context.Context, d *daemon) error {
if err != nil {
log.WithError(err)
}

//
//log_err = item.DataSendErr
////Generate a chain request on the log
//log_type = 3 //
//if LogMode == 3 { //0
// //fmt.Println("There is no need to generate a log")
//} else if LogMode == 1 || LogMode == 2 {
// if LogMode == 1 { //1
// chain_state = 5
Expand Down
8 changes: 8 additions & 0 deletions packages/daemons/vde_src_task_from_sche.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) IBAX. All rights reserved.
"fmt"
"time"

"github.com/IBAX-io/go-ibax/packages/model"

log "github.com/sirupsen/logrus"
)

//Scheduling task to run
Expand Down
25 changes: 15 additions & 10 deletions packages/daylight/windows.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
// +build windows

/*---------------------------------------------------------------------------------------------
* Copyright (c) IBAX. All rights reserved.
* See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/

package daylight

import (
"fmt"
"os/exec"
"regexp"
"time"

"github.com/IBAX-io/go-ibax/packages/consts"
"github.com/IBAX-io/go-ibax/packages/model"

log "github.com/sirupsen/logrus"
)

// KillPid kills the process with the specified pid
func KillPid(pid string) error {
if model.DBConn != nil {
sd := &model.StopDaemon{StopTime: time.Now().Unix()}
err := sd.Create()
if err != nil {
log.WithFields(log.Fields{"type": consts.DBError, "error": err}).Error("Error creating StopDaemon")
return err
}
}
rez, err := exec.Command("tasklist", "/fi", "PID eq "+pid).Output()
if err != nil {
log.WithFields(log.Fields{"type": consts.CommandExecutionError, "err": err, "cmd": "tasklist /fi PID eq" + pid}).Error("Error executing command")
return err
}
Expand Down
21 changes: 10 additions & 11 deletions packages/language/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ func LangText(transaction *model.DbTransaction, in string, state int, accept str
return val, true
}
}
return (*lres)[lng], true
}
return in, false
}

// LangMacro replaces all inclusions of $resname$ in the incoming text with the corresponding language resources,
// if they exist
func LangMacro(input string, state int, accept string) string {
if !strings.ContainsRune(input, '$') {
return input
}
syschar := '$'
length := utf8.RuneCountInString(input)
Expand All @@ -175,17 +185,6 @@ func LangText(transaction *model.DbTransaction, in string, state int, accept str
if r != syschar {
if isName {
name = append(name, r)
if len(name) > 64 || r < ' ' {
clearname()
}
} else {
result = append(result, r)
}
continue
}
if isName {
value, ok := LangText(nil, string(name), state, accept)
if ok {
result = append(result, []rune(value)...)
isName = false
} else {
Expand Down
9 changes: 3 additions & 6 deletions packages/migration/obs/tables_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,6 @@ var tablesDataSQL = `INSERT INTO "1_tables" ("id", "name", "permissions","column
"new_column": "ContractConditions(\"MainCondition\")"}',
'{"name": "ContractConditions(\"MainCondition\")",
"value": "ContractConditions(\"MainCondition\")",
"conditions": "ContractConditions(\"MainCondition\")"}',
'ContractAccess("@1EditTable")'),
('17', 'app_params',
'{"insert": "ContractConditions(\"MainCondition\")", "update": "ContractConditions(\"MainCondition\")",
"new_column": "ContractConditions(\"MainCondition\")"}',
'{"app_id": "ContractConditions(\"MainCondition\")",
"name": "ContractConditions(\"MainCondition\")",
"value": "ContractConditions(\"MainCondition\")",
"conditions": "ContractConditions(\"MainCondition\")"}',
Expand All @@ -189,3 +183,6 @@ var tablesDataSQL = `INSERT INTO "1_tables" ("id", "name", "permissions","column
"key": "false",
"value": "true",
"account": "false"
}',
'ContractConditions("MainCondition")');
`
17 changes: 10 additions & 7 deletions packages/migration/timezones.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,6 @@ INSERT INTO "1_time_zones" VALUES
(next_id('1_time_zones'), 'Antarctica/Macquarie', '+11:00'),
(next_id('1_time_zones'), 'Antarctica/Mawson', '+05:00'),
(next_id('1_time_zones'), 'Antarctica/McMurdo', '+12:00'),
(next_id('1_time_zones'), 'Antarctica/Palmer', '-03:00'),
(next_id('1_time_zones'), 'Antarctica/Rothera', '-03:00'),
(next_id('1_time_zones'), 'Antarctica/Syowa', '+03:00'),
(next_id('1_time_zones'), 'Antarctica/Troll', '+02:00'),
(next_id('1_time_zones'), 'Antarctica/Vostok', '+06:00'),
(next_id('1_time_zones'), 'Arctic/Longyearbyen', '+02:00'),
(next_id('1_time_zones'), 'Asia/Aden', '+03:00'),
(next_id('1_time_zones'), 'Asia/Almaty', '+06:00'),
(next_id('1_time_zones'), 'Asia/Amman', '+03:00'),
(next_id('1_time_zones'), 'Asia/Anadyr', '+12:00'),
Expand Down Expand Up @@ -431,4 +424,14 @@ INSERT INTO "1_time_zones" VALUES
(next_id('1_time_zones'), 'Pacific/Noumea', '+11:00'),
(next_id('1_time_zones'), 'Pacific/Pago_Pago', '-11:00'),
(next_id('1_time_zones'), 'Pacific/Palau', '+09:00'),
(next_id('1_time_zones'), 'Pacific/Pitcairn', '-08:00'),
(next_id('1_time_zones'), 'Pacific/Pohnpei', '+11:00'),
(next_id('1_time_zones'), 'Pacific/Port_Moresby', '+10:00'),
(next_id('1_time_zones'), 'Pacific/Rarotonga', '-10:00'),
(next_id('1_time_zones'), 'Pacific/Saipan', '+10:00'),
(next_id('1_time_zones'), 'Pacific/Tahiti', '-10:00'),
(next_id('1_time_zones'), 'Pacific/Tarawa', '+12:00'),
(next_id('1_time_zones'), 'Pacific/Tongatapu', '+13:00'),
(next_id('1_time_zones'), 'Pacific/Wake', '+12:00'),
(next_id('1_time_zones'), 'Pacific/Wallis', '+12:00');
`
18 changes: 4 additions & 14 deletions packages/model/assign_get_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,16 @@ type AssignRules struct {
TotalAmount string `json:"total_amount"`
}

// AssignGetInfo is model
type AssignGetInfo struct {
ID int64 `gorm:"primary_key;not null"`
Type int64 `gorm:"not null"`
Keyid int64 `gorm:"not null"`
TotalAmount decimal.Decimal `gorm:"not null"`
BalanceAmount decimal.Decimal `gorm:"not null"`
Amount decimal.Decimal `gorm:"not null"`
Latestid int64 `gorm:"not null"`
Deleted int64 `gorm:"not null"`
DateUpdated int64 `gorm:"not null" `
DateCreated int64 `gorm:"not null" `
}

// TableName returns name of table
func (m AssignGetInfo) TableName() string {
return `1_assign_get_info`
}

// Get is retrieving model from database
func (m *AssignGetInfo) GetBalance(db *DbTransaction, wallet int64) (bool, decimal.Decimal, decimal.Decimal, error) {

var mps []AssignGetInfo
var balance, total_balance decimal.Decimal
balance = decimal.NewFromFloat(0)
total_balance = decimal.NewFromFloat(0)
err := GetDB(db).Table(m.TableName()).
Expand Down
9 changes: 4 additions & 5 deletions packages/model/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ func (l *Language) SetTablePrefix(prefix string) {
l.ecosystem = converter.StrToInt64(prefix)
}

// TableName returns name of table
func (l *Language) TableName() string {
if l.ecosystem == 0 {
l.ecosystem = 1
}
return `1_languages`
}

// GetAll is retrieving all records from database
func (l *Language) GetAll(transaction *DbTransaction, prefix string) ([]Language, error) {
result := new([]Language)
err := GetDB(transaction).Table("1_languages").Where("ecosystem = ?", prefix).Order("name asc").Find(&result).Error
return *result, err
}

// ToMap is converting model to map
func (l *Language) ToMap() map[string]string {
Expand Down
15 changes: 6 additions & 9 deletions packages/model/pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@ type Page struct {
AppID int64 `gorm:"column:app_id;not null" json:"app_id,omitempty"`
Conditions string `gorm:"not null" json:"conditions,omitempty"`
}
p.ecosystem = 1
}
return `1_pages`
}

// Get is retrieving model from database
func (p *Page) Get(name string) (bool, error) {
return isFound(DBConn.Where("ecosystem=? and name = ?", p.ecosystem, name).First(p))
// SetTablePrefix is setting table prefix
func (p *Page) SetTablePrefix(prefix string) {
p.ecosystem = converter.StrToInt64(prefix)
}

// Count returns count of records in table
func (p *Page) Count() (count int64, err error) {
// TableName returns name of table
func (p *Page) TableName() string {
if p.ecosystem == 0 {
err = DBConn.Table(p.TableName()).Count(&count).Error
return
}
Expand Down
14 changes: 8 additions & 6 deletions packages/model/querycost/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ import (
)

// explainQueryCost is counting query execution time
func explainQueryCost(transaction *model.DbTransaction, withAnalyze bool, query string, args ...interface{}) (int64, error) {
var planStr string
explainTpl := "EXPLAIN (FORMAT JSON) %s"
if withAnalyze {
explainTpl = "EXPLAIN ANALYZE (FORMAT JSON) %s"
}
err := model.GetDB(transaction).Raw(fmt.Sprintf(explainTpl, query), args...).Row().Scan(&planStr)
switch {
case err == sql.ErrNoRows:
log.WithFields(log.Fields{"type": consts.DBError, "error": err, "query": query}).Error("no rows while explaining query")
return 0, errors.New("No rows")
Expand All @@ -31,12 +39,6 @@ import (
dec.UseNumber()
if err := dec.Decode(&queryPlan); err != nil {
log.WithFields(log.Fields{"type": consts.JSONUnmarshallError, "error": err}).Error("decoding query plan from JSON")
return 0, err
}
if len(queryPlan) == 0 {
log.Error("Query plan is empty")
return 0, errors.New("Query plan is empty")
}
firstNode := queryPlan[0]
var plan interface{}
var ok bool
Expand Down
20 changes: 9 additions & 11 deletions packages/model/queue_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,21 @@ func (qt *QueueTx) TableName() string {
return "queue_tx"
}

// Create is creating record of model
func (qt *QueueTx) Create() error {
return DBConn.Create(qt).Error
// DeleteTx is deleting tx
func (qt *QueueTx) DeleteTx(transaction *DbTransaction) error {
return GetDB(transaction).Delete(qt).Error
}

// GetByHash is retrieving model from database by hash
func (qt *QueueTx) GetByHash(transaction *DbTransaction, hash []byte) (bool, error) {
return isFound(GetDB(transaction).Where("hash = ?", hash).First(qt))
// Save is saving model
func (qt *QueueTx) Save(transaction *DbTransaction) error {
return GetDB(transaction).Save(qt).Error
}

// DeleteQueueTxByHash is deleting queue tx by hash
func DeleteQueueTxByHash(transaction *DbTransaction, hash []byte) (int64, error) {
query := GetDB(transaction).Exec("DELETE FROM queue_tx WHERE hash = ?", hash)
return query.RowsAffected, query.Error
// Create is creating record of model
func (qt *QueueTx) Create() error {
return DBConn.Create(qt).Error
}

// GetQueuedTransactionsCount counting queued transactions
func GetQueuedTransactionsCount(hash []byte) (int64, error) {
var rowsCount int64
err := DBConn.Table("queue_tx").Where("hash = ?", hash).Count(&rowsCount).Error
Expand Down
Loading

0 comments on commit f9e0a32

Please sign in to comment.