Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
powerpook committed Aug 27, 2020
1 parent 2637493 commit 6c4ac72
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 92 deletions.
21 changes: 10 additions & 11 deletions packages/daemons/queue_parser_blocks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) IBAX. All rights reserved.
* See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/

package daemons

import (
"context"
"fmt"
"sync/atomic"

"github.com/IBAX-io/go-ibax/packages/conf"
"github.com/IBAX-io/go-ibax/packages/conf/syspar"
"github.com/IBAX-io/go-ibax/packages/consts"
"github.com/IBAX-io/go-ibax/packages/model"
Expand Down Expand Up @@ -29,17 +39,6 @@ func QueueParserBlocks(ctx context.Context, d *daemon) error {
DBLock()
defer DBUnlock()

infoBlock := &model.InfoBlock{}
_, err := infoBlock.Get()
if err != nil {
d.logger.WithFields(log.Fields{"type": consts.DBError, "error": err}).Error("getting info block")
return err
}
queueBlock := &model.QueueBlock{}
_, err = queueBlock.Get()
if err != nil {
d.logger.WithFields(log.Fields{"type": consts.DBError, "error": err}).Error("getting queue block")
return err
}
if len(queueBlock.Hash) == 0 {
d.logger.WithFields(log.Fields{"type": consts.NotFound}).Debug("queue block not found")
Expand Down
23 changes: 6 additions & 17 deletions packages/daemons/subnode_dest_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
*--------------------------------------------------------------------------------------------*/

package daemons

import (
"context"
"fmt"
"time"

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

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -47,23 +53,6 @@ func SubNodeDestData(ctx context.Context, d *daemon) error {
AuthState: 1,
SignState: 1,
HashState: 1,
CreateTime: item.CreateTime}
//CreateTime: time.Now().Unix()}

if err = DestDataHash.Create(); err != nil {
log.WithFields(log.Fields{"error": err}).Error("Insert subnode_dest_data_hash table failed")
continue
}
fmt.Println("Insert subnode_dest_data_hash table ok, DataUUID:", item.DataUUID)
} else if item.TranMode == 3 { // data under chain
DestDataStatus := model.SubNodeDestDataStatus{
DataUUID: item.DataUUID,
TaskUUID: item.TaskUUID,
Hash: item.Hash,
Data: item.Data,
DataInfo: item.DataInfo,
SubNodeSrcPubkey: item.SubNodeSrcPubkey,
SubNodeDestPubkey: item.SubNodeDestPubkey,
SubNodeDestIP: item.SubNodeDestIP,
SubNodeAgentPubkey: item.SubNodeAgentPubkey,
SubNodeAgentIP: item.SubNodeAgentIP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ contract BindWallet {
$cur = DBRow("contracts").Columns("id,conditions,wallet_id").WhereId($Id)
if !$cur {
error Sprintf("Contract %d does not exist", $Id)
}
12 changes: 2 additions & 10 deletions packages/migration/contracts/first_ecosystem/NewApplication.sim
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
// +prop AppID = '1'
// +prop Conditions = 'ContractConditions("MainCondition")'
contract NewApplication {
data {
Name string
Conditions string
}

conditions {
ValidateCondition($Conditions, $ecosystem_id)

if Size($Name) == 0 {
warning "Application name missing"
}
Expand All @@ -20,3 +10,5 @@ contract NewApplication {

action {
$result = DBInsert("applications", {name: $Name,conditions: $Conditions})
}
}
6 changes: 0 additions & 6 deletions packages/migration/contracts/obs/RunOBS.sim
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
// +prop AppID = '1'
// +prop Conditions = 'ContractConditions("MainCondition")'
contract RunOBS {
data {
OBSName string
}
conditions {
StartOBS($OBSName)
$result = "OBS " + $OBSName + " running"
}
Expand Down
10 changes: 10 additions & 0 deletions packages/model/log_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ func (lt *LogTransaction) GetByHash(hash []byte) (bool, error) {
// Create is creating record of model
func (lt *LogTransaction) Create(transaction *DbTransaction) error {
return GetDB(transaction).Create(lt).Error
}

func CreateLogTransactionBatches(dbTx *gorm.DB, lts []*LogTransaction) error {
return query.RowsAffected, query.Error
}

// GetLogTransactionsCount count records by transaction hash
func GetLogTransactionsCount(hash []byte) (int64, error) {
var rowsCount int64
if err := DBConn.Table("log_transactions").Where("hash = ?", hash).Count(&rowsCount).Error; err != nil {
return -1, err
}
return rowsCount, nil
Expand Down
22 changes: 5 additions & 17 deletions packages/model/responecode.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,6 @@ var (
//errUnknownSign = errType{"E_UNKNOWNSIGN", "Unknown signature", defaultStatus}
//errStateLogin = errType{"E_STATELOGIN", "%s is not a membership of ecosystem %s", http.StatusForbidden}
//errTableNotFound = errType{"E_TABLENOTFOUND", "Table %s has not been found", http.StatusNotFound}
//errToken = errType{"E_TOKEN", "Token is not valid", defaultStatus}
//errTokenExpired = errType{"E_TOKENEXPIRED", "Token is expired by %s", http.StatusUnauthorized}
//errUnauthorized = errType{"E_UNAUTHORIZED", "Unauthorized", http.StatusUnauthorized}
//errUndefineval = errType{"E_UNDEFINEVAL", "Value %s is undefined", defaultStatus}
//errUnknownUID = errType{"E_UNKNOWNUID", "Unknown uid", defaultStatus}
//errOBS = errType{"E_OBS", "Virtual Dedicated Ecosystem %d doesn't exist", defaultStatus}
//errOBSCreated = errType{"E_OBSCREATED", "Virtual Dedicated Ecosystem is already created", http.StatusBadRequest}
//errRequestNotFound = errType{"E_REQUESTNOTFOUND", "Request %s doesn't exist", defaultStatus}
//errUpdating = errType{"E_UPDATING", "Node is updating blockchain", http.StatusServiceUnavailable}
//errStopping = errType{"E_STOPPING", "Network is stopping", http.StatusServiceUnavailable}
//errNotImplemented = errType{"E_NOTIMPLEMENTED", "Not implemented", http.StatusNotImplemented}
//errParamMoneyDigit = errType{"E_PARAMMONEYDIGIT", "The number of decimal places cannot be exceeded ( %s )", http.StatusBadRequest}
//errDiffKey = CodeType{"E_DIFKEY", "Sender's key is different from tx key", defaultStatus}
//errBannded = errType{"E_BANNED", "The key is banned till %s", http.StatusForbidden}
//errCheckRole = errType{"E_CHECKROLE", "Access denied", http.StatusForbidden}
//errNewUser = errType{"E_NEWUSER", "Can't create a new user", http.StatusUnauthorized}
CodeSystembusy = CodeType{-1, "System is busy", http.StatusOK, ""}
CodeSuccess = CodeType{0, "Success", http.StatusOK, "OK"}
//CodeFileNotExists = CodeType{40001, "File %s not exists", http.StatusOK, ""}
//CodeFileFormatNotSupports = CodeType{40002, "File %s format is not supported", http.StatusOK, ""}
Expand Down Expand Up @@ -123,6 +106,11 @@ type errType struct {
Status int `json:"-"`
}

func (et errType) Error() string {
return et.Err
}

func (et errType) Errorf(v ...interface{}) errType {
et.Message = fmt.Sprintf(et.Message, v...)
return et
}
Expand Down
18 changes: 7 additions & 11 deletions packages/model/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,6 @@ func GetTransactionCountAll() (int64, error) {
}

// GetTransactionsCount count all transactions by hash
func GetTransactionsCount(hash []byte) (int64, error) {
var rowsCount int64
if err := DBConn.Table("transactions").Where("hash = ?", hash).Count(&rowsCount).Error; err != nil {
return -1, err
}
return rowsCount, nil
}

// DeleteTransactionByHash deleting transaction by hash
func DeleteTransactionByHash(dbTransaction *DbTransaction, hash []byte) error {
return GetDB(dbTransaction).Where("hash = ?", hash).Delete(&Transaction{}).Error
}

// DeleteUsedTransactions deleting used transaction
Expand Down Expand Up @@ -138,6 +127,13 @@ func (t *Transaction) Read(hash []byte) (bool, error) {

// Get is retrieving model from database
func (t *Transaction) Get(transactionHash []byte) (bool, error) {
return isFound(DBConn.Where("hash = ?", transactionHash).First(t))
}

// GetVerified is checking transaction verification by hash
func (t *Transaction) GetVerified(transactionHash []byte) (bool, error) {
return isFound(DBConn.Where("hash = ? AND verified = 1", transactionHash).First(t))
}

func (t *Transaction) BeforeCreate(db *gorm.DB) error {
if t.HighRate == 0 {
Expand Down
13 changes: 7 additions & 6 deletions packages/network/tcpserver/type88.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ func Type88(r *network.PrivateDateRequest) (*network.PrivateDateResponse, error)
log.WithFields(log.Fields{"error": err}).Error("EccCryptoKey error")
return nil, err
}
encodeDataString := base64.StdEncoding.EncodeToString(eccData)
////
err = privatePackets.Create()
if err != nil {
log.WithFields(log.Fields{"error": err}).Error("Create PrivatePackets table record error")
return nil, err
}

privatePackets := model.PrivatePackets{
Hash: hash,
//Data: r.Data,
//
return resp, nil
}
23 changes: 16 additions & 7 deletions packages/obsmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
*--------------------------------------------------------------------------------------------*/
package obsmanager

import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"strings"
"time"
"unicode"

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

"github.com/ochinchina/go-ini"
pConf "github.com/ochinchina/supervisord/config"
"github.com/ochinchina/supervisord/process"
log "github.com/sirupsen/logrus"
"github.com/IBAX-io/go-ibax/packages/consts"
"github.com/IBAX-io/go-ibax/packages/model"
)
Expand Down Expand Up @@ -182,13 +198,6 @@ func (mgr *OBSManager) DeleteOBS(name string) error {

if mgr.processes == nil {
log.WithFields(log.Fields{"type": consts.WrongModeError, "error": errWrongMode}).Error("deleting OBS")
return errWrongMode
}

mgr.StopOBS(name)
mgr.processes.Remove(name)
obsDir := path.Join(mgr.childConfigsPath, name)
obsConfigPath := filepath.Join(obsDir, consts.DefaultConfigFile)
obsConfig, err := conf.GetConfigFromPath(obsConfigPath)
if err != nil {
log.WithFields(log.Fields{"type": consts.IOError, "error": err}).Errorf("Getting config from path %s", obsConfigPath)
Expand Down
15 changes: 9 additions & 6 deletions packages/smart/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,21 @@ const (
eKeyNotFound = `sender %s has not been found`
eEcoKeyNotFound = `sender %s has not been found in ecosystem %d`
eEcoKeyDisable = `%s disable in ecosystem %d`
eEcoFuelRate = `fuel rate must be greater than 0 or empty in ecosystem %d`
eEcoCurrentBalance = `current balance is not enough in ecosystem %d, at least [%s] difference`
)

var (
errDelayedContract = errors.New(`incorrect delayed contract`)
errAccessDenied = errors.New(`access denied`)
errConditionEmpty = errors.New(`conditions is empty`)
errContractNotFound = errors.New(`contract has not been found`)
errTaxes = errors.New("not enough money to pay the taxes fee")
errEmptyColumn = errors.New(`column name is empty`)
errWrongColumn = errors.New(`column name cannot begin with digit`)
errNotFound = errors.New(`record has not been found`)
errContractChange = errors.New(`contract cannot be removed or inserted`)
errCurrentBalance = errors.New(`current balance is not enough`)
errDeletedKey = errors.New(`the key is deleted`)
errDiffKeys = errors.New(`contract and user public keys are different`)
errEmpty = errors.New(`empty value and condition`)
errEmptyCond = errors.New(`the condition is empty`)
errEmptyContract = errors.New(`empty contract name in ContractConditions`)
errEmptyPublicKey = errors.New(`empty public key`)
errFounderAccount = errors.New(`unknown founder account`)
errKeyIDAccount = errors.New(`unknown address account`)
errFuelRate = errors.New(`fuel rate must be greater than 0`)
Expand Down

0 comments on commit 6c4ac72

Please sign in to comment.