Skip to content

Commit

Permalink
Merge branch 'subdev' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
powerpook committed Nov 21, 2020
1 parent 9a4f11f commit 9dd2b28
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 133 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
language: go

env: GO111MODULE=on
script: go build github.com/IBAX/go-ibax

go:
- 1.12.x
- master

go_import_path: github.com/IBAX/go-ibax
31 changes: 16 additions & 15 deletions packages/api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,6 @@ func parseJWTToken(header string) (*jwt.Token, error) {
}

if strings.HasPrefix(header, jwtPrefix) {
header = header[len(jwtPrefix):]
} else {
return nil, errJWTAuthValue
}

return jwt.ParseWithClaims(header, &JWTClaims{}, func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
}
return []byte(jwtSecret), nil
})
}

func RefreshToken(header string) (*jwt.Token, error) {
if len(header) == 0 {
return nil, nil
}
if strings.HasPrefix(header, jwtPrefix) {
Expand Down Expand Up @@ -143,6 +128,22 @@ func RefreshToken(header string) (*jwt.Token, error) {
gd := GRefreshClaims{
Header: header,
}
gd.DeleteClaims()
return token, err
}

token, err := jwt.ParseWithClaims(header, &JWTClaims{}, func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
}

return []byte(jwtSecret), nil
})
if err != nil {
return nil, err
}

return token, err
}

func getClientFromToken(token *jwt.Token, ecosysNameService types.EcosystemNameGetter) (*Client, error) {
Expand Down
19 changes: 14 additions & 5 deletions packages/api/balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,27 @@ import (

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

func TestBalance(t *testing.T) {
if err := keyLogin(1); err != nil {
t.Error(err)
return
}
var ret balanceResult
err := sendGet(`balance/`+gAddress, nil, &ret)
if err != nil {
t.Error(err)
return
}
if len(ret.Amount) < 10 {
t.Error(`too low balance`, ret)
}
err = sendGet(`balance/3434341`, nil, &ret)
if err != nil {
t.Error(err)
return
}
if len(ret.Amount) > 0 {
t.Error(fmt.Errorf(`wrong balance %s`, ret.Amount))
return
}
}

func TestAssignBalance(t *testing.T) {
if err := keyLogin(1); err != nil {
t.Error(err)
Expand Down
15 changes: 6 additions & 9 deletions packages/daemons/disseminator.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,6 @@ func sendBlockWithTxHashes(ctx context.Context, honorNodeID int64, logger *log.E
if (trs == nil || len(*trs) == 0) && block == nil {
// it's nothing to send
logger.Debug("nothing to send")
return nil
}

hosts, banHosts, err := service.GetNodesBanService().FilterHosts(syspar.GetRemoteHosts())
if err != nil {
log.WithFields(log.Fields{"error": err}).Error("on getting remotes hosts")
return err
}
if len(banHosts) > 0 {
if err := tcpclient.SendFullBlockToAll(ctx, banHosts, nil, *trs, honorNodeID); err != nil {
log.WithFields(log.Fields{"type": consts.TCPClientError, "error": err}).Warn("on sending block with hashes to ban hosts")
return err
Expand All @@ -125,6 +116,12 @@ func sendBlockWithTxHashes(ctx context.Context, honorNodeID int64, logger *log.E
if err != nil {
logger.WithFields(log.Fields{"type": consts.DBError, "error": err}).Error("marking block sent")
return err
}
}

if trs != nil {
var hashArr [][]byte
for _, tr := range *trs {
hashArr = append(hashArr, tr.Hash)
}
if err := model.MarkTransactionSentBatches(hashArr); err != nil {
Expand Down
22 changes: 13 additions & 9 deletions packages/daemons/vde_src_task_uptochain.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ func VDESrcTaskUpToChain(ctx context.Context, d *daemon) error {
return err
}
if SrcChainInfo == nil {
log.Info("Src chain info not found")
//fmt.Println("Src chain info not found")
time.Sleep(time.Millisecond * 100)
return nil
}

blockchain_http = SrcChainInfo.BlockchainHttp
blockchain_ecosystem = SrcChainInfo.BlockchainEcosystem
//fmt.Println("SrcChainInfo:", blockchain_http, blockchain_ecosystem)
// deal with task data
for _, item := range SrcTask {
//fmt.Println("SrcTask:", item.TaskUUID)

ecosystemID, err := strconv.Atoi(blockchain_ecosystem)
if err != nil {
log.WithFields(log.Fields{"error": err}).Error("encode error")
Expand Down Expand Up @@ -177,15 +190,6 @@ func VDESrcTaskUpToChainState(ctx context.Context, d *daemon) error {
continue
}
chain_apiAddress := blockchain_http
chain_apiEcosystemID := int64(ecosystemID)

src := filepath.Join(conf.Config.KeysDir, "PrivateKey")
// Login
gAuth_chain, _, _, _, _, err := chain_api.KeyLogin(chain_apiAddress, src, chain_apiEcosystemID)
if err != nil {
log.WithFields(log.Fields{"error": err}).Error("Login chain failure")
time.Sleep(time.Millisecond * 2)
continue
}
//fmt.Println("Login OK!")

Expand Down
15 changes: 0 additions & 15 deletions packages/migration/contracts/first_ecosystem/BindWallet.sim
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
// +prop AppID = '1'
// +prop Conditions = 'ContractConditions("MainCondition")'
contract BindWallet {
data {
Id int
}
conditions {
$cur = DBRow("contracts").Columns("id,conditions,wallet_id").WhereId($Id)
if !$cur {
error Sprintf("Contract %d does not exist", $Id)
}
Eval($cur["conditions"])
if $key_id != Int($cur["wallet_id"]) {
error Sprintf("Wallet %d cannot activate the contract", $key_id)
}
}
action {
BndWallet($Id, $ecosystem_id)
22 changes: 12 additions & 10 deletions packages/model/foundation_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ import (
"errors"
"github.com/shopspring/decimal"
)

//FoundationGroup example
type FoundationGroup struct {
Id int64 `gorm:"not null" example:"1"` //
Keyid int64 `gorm:"not null"`
Deleted int64 `gorm:"not null" example:"1"` //
Date_updated int64 `gorm:"not null" example:"2019-07-19 17:45:31"` //
Date_created int64 `gorm:"not null" example:"2019-07-19 17:45:31"` //
}

func (FoundationGroup) TableName() string {
return `1_foundation_group`
}
Expand All @@ -34,6 +24,18 @@ func (m *FoundationGroup) GetByDevid(transaction *DbTransaction, devid int64) (d
if f {
fb, err := m.GetByKeyid(transaction, mo.Keyid)
if err != nil {
return ret, err
}
if !fb {
return ret, nil
}

var sp StateParameter
sp.ecosystem = 1
fs, err := sp.Get(transaction, "foundation_balance")
if err != nil {
return ret, err
}
if !fs {
return ret, errors.New("foundation_balance not found")
}
Expand Down
15 changes: 5 additions & 10 deletions packages/model/goredis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ type RedisParams struct {
Value string `json:"value"`
}

func RedisInit(host string, port string, password string, db int) error {
var (
err error
)
GRedisIsactive = false

Gclient0 = redis.NewClient(&redis.Options{
Addr: host + ":" + port,
Password: password, // no password set
DB: db, // use default DB
})
_, err = Gclient0.Ping().Result()
if err != nil {
Expand Down Expand Up @@ -84,6 +74,11 @@ func (rp *RedisParams) Cleardb() error {
var keys []string

if GRedisIsactive {
err = nil
for {
var key []string
var err error
key, cursor, err = Gclient0.Scan(cursor, "*", 10).Result()
if err != nil {
return err
}
Expand Down
21 changes: 10 additions & 11 deletions packages/model/subnode_agent_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ func (SubNodeAgentData) TableName() string {

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

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

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

func (m *SubNodeAgentData) GetAll() ([]SubNodeAgentData, error) {
var result []SubNodeAgentData
err := DBConn.Find(&result).Error
return result, err
Expand All @@ -66,5 +55,15 @@ func (m *SubNodeAgentData) GetOneByTaskUUID(TaskUUID string) (*SubNodeAgentData,
func (m *SubNodeAgentData) GetAllByTaskUUID(TaskUUID string) ([]SubNodeAgentData, error) {
result := make([]SubNodeAgentData, 0)
err := DBConn.Table("subnode_agent_data").Where("task_uuid = ?", TaskUUID).Find(&result).Error
return result, err
}

func (m *SubNodeAgentData) GetAllByDataSendStatus(DataSendStatus int64) ([]SubNodeAgentData, error) {
result := make([]SubNodeAgentData, 0)
err := DBConn.Table("subnode_agent_data").Where("data_send_state = ?", DataSendStatus).Find(&result).Error
return result, err
}

func (m *SubNodeAgentData) GetOneByDataStatus(DataStatus int64) (bool, error) {
return isFound(DBConn.Where("data_state = ?", DataStatus).First(m))
}
22 changes: 13 additions & 9 deletions packages/model/vde_src_task_chain_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ func (VDESrcTaskChainStatus) TableName() string {
}

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

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

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

func (m *VDESrcTaskChainStatus) GetAll() ([]VDESrcTaskChainStatus, error) {
var result []VDESrcTaskChainStatus
err := DBConn.Find(&result).Error
return result, err
}
Expand Down Expand Up @@ -91,15 +104,6 @@ func (m *VDESrcTaskChainStatus) GetAllByTaskState(TaskState int64) ([]VDESrcTask
func (m *VDESrcTaskChainStatus) GetOneByTaskState(TaskState int64) (bool, error) {
return isFound(DBConn.Where("task_state = ?", TaskState).First(m))
}

func (m *VDESrcTaskChainStatus) GetOneByContractState(ContractState int64) (bool, error) {
return isFound(DBConn.Where("contract_state = ?", ContractState).First(m))
}

func (m *VDESrcTaskChainStatus) GetOneByChainState(ChainState int64) (bool, error) {
return isFound(DBConn.Where("chain_state = ?", ChainState).First(m))
}

func (m *VDESrcTaskChainStatus) GetAllByContractStateAndChainState(ContractStateSrc int64, ContractStateDest int64, ChainState int64) ([]VDESrcTaskChainStatus, error) {
result := make([]VDESrcTaskChainStatus, 0)
err := DBConn.Table("vde_src_task_chain_status").Where("contract_state_src = ? AND contract_state_dest = ? AND chain_state = ?", ContractStateSrc, ContractStateDest, ChainState).Find(&result).Error
Expand Down
12 changes: 3 additions & 9 deletions packages/network/tcpserver/subnodedest_fromsrcdata_type200.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ package tcpserver

import (
"encoding/base64"
"errors"
"fmt"
"time"

"github.com/IBAX-io/go-ibax/packages/consts"
"github.com/IBAX-io/go-ibax/packages/converter"
"github.com/IBAX-io/go-ibax/packages/crypto"
"github.com/IBAX-io/go-ibax/packages/crypto/ecies"
"github.com/IBAX-io/go-ibax/packages/model"
"github.com/IBAX-io/go-ibax/packages/network"
"github.com/IBAX-io/go-ibax/packages/utils"

Expand All @@ -34,6 +25,9 @@ func Type200(r *network.SubNodeSrcDataRequest) (*network.SubNodeSrcDataResponse,
data, err := ecies.EccDeCrypto(r.Data, nodePrivateKey)
if err != nil {
fmt.Println("EccDeCrypto err!")
log.WithError(err)
return nil, err
}

//hash, err := crypto.HashHex(r.Data)
hash, err := crypto.HashHex(data)
Expand Down
23 changes: 12 additions & 11 deletions packages/types/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ func LoadMap(init map[string]interface{}) (ret *Map) {
keys = append(keys, key)
}
sort.Strings(keys)
for _, v := range keys {
ret.Set(v, ConvertMap(init[v]))
}
return
}

// Put inserts an element into the map.
func (m *Map) Set(key string, value interface{}) {
link, found := m.m[key]
if !found {
link = newLink(key, value)
if m.tail == nil {
m.head = link
m.tail = link
} else {
Expand Down Expand Up @@ -150,17 +162,6 @@ func (m *Map) Values() []interface{} {
// Clear removes all elements from the map.
func (m *Map) Clear() {
m.m = make(map[string]*Link)
m.head = nil
m.tail = nil
}

// String returns a string representation of container
func (m *Map) String() string {
str := "map["
for current := m.head; current != nil; current = current.next {
str += fmt.Sprintf("%v:%v ", current.key, current.value)
}
return strings.TrimRight(str, " ") + "]"
}

func (m *Map) MarshalJSON() ([]byte, error) {
Expand Down
Loading

0 comments on commit 9dd2b28

Please sign in to comment.