Skip to content

Commit

Permalink
Fixed routes
Browse files Browse the repository at this point in the history
  • Loading branch information
powerpook committed Nov 21, 2020
1 parent bfa766b commit 9a4f11f
Show file tree
Hide file tree
Showing 23 changed files with 184 additions and 228 deletions.
18 changes: 7 additions & 11 deletions packages/api/app_content.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) IBAX. All rights reserved.
* See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/

package api

import (
"net/http"

"github.com/gorilla/mux"

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

log "github.com/sirupsen/logrus"
)

type appContentResult struct {
Blocks []model.BlockInterface `json:"blocks"`
Pages []model.Page `json:"pages"`
Contracts []model.Contract `json:"contracts"`
}

func (m Mode) getAppContentHandler(w http.ResponseWriter, r *http.Request) {
form := &appParamsForm{
Expand Down
26 changes: 8 additions & 18 deletions packages/crypto/converter.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) IBAX. All rights reserved.
* See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
package crypto

import (
"encoding/hex"

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

// CutPub removes the first 04 byte
func CutPub(pubKey []byte) []byte {
if len(pubKey) == 65 && pubKey[0] == 4 {
pubKey = pubKey[1:]
}
return pubKey
}

// KeyToAddress converts a public key to chain address XXXX-...-XXXX.
Expand All @@ -37,3 +19,11 @@ func HexToPub(pub string) ([]byte, error) {
}
return CutPub(key), nil
}

// PubToHex decodes []byte of pub key to hex string
func PubToHex(pub []byte) string {
if len(pub) == 64 {
pub = append([]byte{4}, pub...)
}
return hex.EncodeToString(pub)
}
27 changes: 17 additions & 10 deletions packages/crypto/sm2.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ func (s *SM2) sign(privateKey, data []byte) ([]byte, error) {
priv.D = bi
priv.PublicKey.X, priv.PublicKey.Y = pubkeyCurve.ScalarBaseMult(bi.Bytes())
ret, err := priv.Sign(rand.Reader, data, nil)
return ret, err
}

func (s *SM2) verify(public, data, signature []byte) (bool, error) {
if len(public) == 0 {
return false, ErrCheckingSignEmpty
}
if len(data) == 0 {
return false, fmt.Errorf("invalid parameters len(data) == 0")
}
if len(public) != consts.PubkeySizeLength {
return false, fmt.Errorf("invalid parameters len(public) = %d", len(public))
}
if len(signature) == 0 {
return false, fmt.Errorf("invalid parameters len(signature) == 0")
}

pubkeyCurve := sm2.P256Sm2()
pubkey := new(sm2.PublicKey)
pubkey.Curve = pubkeyCurve
Expand All @@ -37,15 +54,5 @@ func (s *SM2) sign(privateKey, data []byte) ([]byte, error) {
if !verifystatus {
return false, ErrIncorrectSign
}
return true, nil
}

func (s *SM2) privateToPublic(key []byte) ([]byte, error) {
pubkeyCurve := sm2.P256Sm2()
bi := new(big.Int).SetBytes(key)
priv := new(sm2.PrivateKey)
priv.PublicKey.Curve = pubkeyCurve
priv.D = bi
priv.PublicKey.X, priv.PublicKey.Y = pubkeyCurve.ScalarBaseMult(key)
return append(converter.FillLeft(priv.PublicKey.X.Bytes()), converter.FillLeft(priv.PublicKey.Y.Bytes())...), nil
}
17 changes: 3 additions & 14 deletions packages/daemons/external_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

package daemons

import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
"net/url"
Expand Down Expand Up @@ -127,20 +130,6 @@ func SendExternalTransaction() error {
values["txtime"] = []string{converter.Int64ToStr(item.TxTime)}
_, hash, err = connect.PostTxResult(item.ExternalContract, &values)
if err != nil {
log.WithFields(log.Fields{"type": consts.NetworkError, "error": err}).Error("PostContract")
if item.Attempts >= maxAttempts-1 {
sendResult(item, 0, errExternalAttempt, ``)
} else {
incAttempt(item.Id)
}
} else {
log.WithFields(log.Fields{"hash": hash, "txtime": values["txtime"][0],
"nodeKey": converter.Int64ToStr(nodeKeyID)}).Info("SendExternalTransaction")
bHash, err := hex.DecodeString(hash)
if err != nil {
log.WithFields(log.Fields{"type": consts.ParseError, "error": err}).Error("DecodeHex")
incAttempt(item.Id)
} else if err = model.HashExternalTx(item.Id, bHash); err != nil {
log.WithFields(log.Fields{"type": consts.DBError, "error": err}).Error("HashExternal")
}
}
Expand Down
8 changes: 3 additions & 5 deletions packages/daemons/subnode_src_data_uptochain.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ func SubNodeSrcDataUpToChain(ctx context.Context, d *daemon) error {
time.Sleep(time.Second * 5)
continue
}
fmt.Println("Send chain Contract to run, ContractName:", ContractName)
item.ChainState = 1 //success
item.TxHash = txHash
item.BlockId = 0
item.ChainErr = ""
}
Expand All @@ -159,11 +162,6 @@ func SubNodeSrcDataUpToChain(ctx context.Context, d *daemon) error {
//item.ChainErr = ""
item.UpdateTime = time.Now().Unix()
err = item.Updates()
if err != nil {
fmt.Println("Update SubNodeSrcDataChainStatus table err: ", err)
log.WithFields(log.Fields{"error": err}).Error("Update SubNodeSrcDataChainStatus table!")
time.Sleep(time.Millisecond * 2)
continue
}
} //for
return nil
Expand Down
20 changes: 4 additions & 16 deletions packages/daemons/vde_src_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"fmt"
"time"

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

log "github.com/sirupsen/logrus"
)

//Scheduling task to run
func VDESrcTaskStatus(ctx context.Context, d *daemon) error {
Expand All @@ -31,22 +35,6 @@ func VDESrcTaskStatus(ctx context.Context, d *daemon) error {
//fmt.Println("SrcTask:", item.TaskUUID)
TaskStatus := &model.VDESrcTaskStatus{}
TaskStatus.TaskUUID = item.TaskUUID
TaskStatus.ContractRunHttp = item.ContractRunHttp
TaskStatus.ContractRunEcosystem = item.ContractRunEcosystem
TaskStatus.ContractRunParms = item.ContractRunParms
TaskStatus.ContractSrcName = item.ContractSrcName
TaskStatus.CreateTime = time.Now().Unix()
err = TaskStatus.Create()
if err != nil {
fmt.Println("Create VDESrcTaskStatus table err: ", err)
log.WithFields(log.Fields{"error": err}).Error("Create VDESrcTaskStatus table!")
time.Sleep(time.Millisecond * 2)
continue
}
item.TaskRunState = 3
item.UpdateTime = time.Now().Unix()
err = item.Updates()
if err != nil {
fmt.Println("Update VDESrcTask table err: ", err)
log.WithFields(log.Fields{"error": err}).Error("Update VDESrcTask table!")
time.Sleep(time.Millisecond * 2)
Expand Down
25 changes: 9 additions & 16 deletions packages/daylight/notandroid.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,12 @@ package daylight

import (
"net"
"net/http"

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

log "github.com/sirupsen/logrus"
)

func httpListener(ListenHTTPHost string, route http.Handler) {
l, err := net.Listen("tcp", ListenHTTPHost)
log.WithFields(log.Fields{"host": ListenHTTPHost, "type": consts.NetworkError}).Debug("trying to listen at")
if err == nil {
log.WithFields(log.Fields{"host": ListenHTTPHost}).Info("listening at")
} else {
log.WithFields(log.Fields{"host": ListenHTTPHost, "error": err, "type": consts.NetworkError}).Debug("cannot listen at host")
}

go func() {
srv := &http.Server{Handler: route}
err = srv.Serve(l)
if err != nil {
log.WithFields(log.Fields{"host": ListenHTTPHost, "error": err, "type": consts.NetworkError}).Error("serving http at host")
panic(err)
}
}()
}
3 changes: 2 additions & 1 deletion packages/migration/contracts/obs/RunOBS.sim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
action {
// +prop AppID = '1'
// +prop Conditions = 'ContractConditions("MainCondition")'
$OBSName = ToLower($OBSName)
StartOBS($OBSName)
$result = "OBS " + $OBSName + " running"
Expand Down
18 changes: 11 additions & 7 deletions packages/migration/gen/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
* See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/

package main

import (
"bufio"
"bytes"
"html/template"
"os"
"path/filepath"
"sort"
"strings"

"github.com/BurntSushi/toml"
)

Expand All @@ -14,13 +25,6 @@ const (

var (
scenarios = []scenario{
{
[]string{"./contracts/ecosystem"},
"./contracts_data.go",
"contractsDataSQL", "{{.Ecosystem}}", "{{.Owner}}",
},
{
[]string{"./contracts/first_ecosystem"},
"./first_ecosys_contracts_data.go",
"firstEcosystemContractsSQL", "1", "{{.Owner}}",
},
Expand Down
23 changes: 14 additions & 9 deletions packages/migration/obs/obs_data_contracts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 4 additions & 16 deletions packages/migration/parameters_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,10 @@ INSERT INTO "1_parameters" ("id","name", "value", "conditions", "ecosystem") VAL
(next_id('1_parameters'),'changing_tables', 'ContractConditions("MainCondition")', 'ContractConditions("DeveloperCondition")', '{{.Ecosystem}}'),
(next_id('1_parameters'),'changing_language', 'ContractConditions("MainCondition")', 'ContractConditions("DeveloperCondition")', '{{.Ecosystem}}'),
(next_id('1_parameters'),'changing_page', 'ContractConditions("MainCondition")', 'ContractConditions("DeveloperCondition")', '{{.Ecosystem}}'),
(next_id('1_parameters'),'changing_menu', 'ContractConditions("MainCondition")', 'ContractConditions("DeveloperCondition")', '{{.Ecosystem}}'),
(next_id('1_parameters'),'changing_contracts', 'ContractConditions("MainCondition")', 'ContractConditions("DeveloperCondition")', '{{.Ecosystem}}'),
(next_id('1_parameters'),'changing_parameters', 'ContractConditions("MainCondition")', 'ContractConditions("DeveloperCondition")', '{{.Ecosystem}}'),
(next_id('1_parameters'),'changing_app_params', 'ContractConditions("MainCondition")', 'ContractConditions("DeveloperCondition")', '{{.Ecosystem}}'),
(next_id('1_parameters'),'max_sum', '1000000', 'ContractConditions("DeveloperCondition")', '{{.Ecosystem}}'),
(next_id('1_parameters'),'stylesheet', 'body {
/* You can define your custom styles here or create custom CSS rules */
}', 'ContractConditions("DeveloperCondition")', '{{.Ecosystem}}'),
(next_id('1_parameters'),'print_stylesheet', 'body {
/* You can define your custom styles here or create custom CSS rules */
}', 'ContractConditions("DeveloperCondition")', '{{.Ecosystem}}'),
(next_id('1_parameters'),'max_tx_block_per_user', '1000', 'ContractConditions("DeveloperCondition")', '{{.Ecosystem}}'),
(next_id('1_parameters'),'min_page_validate_count', '1', 'ContractConditions("DeveloperCondition")', '{{.Ecosystem}}'),
(next_id('1_parameters'),'max_page_validate_count', '6', 'ContractConditions("DeveloperCondition")', '{{.Ecosystem}}'),
(next_id('1_parameters'),'changing_blocks', 'ContractConditions("MainCondition")', 'ContractConditions("DeveloperCondition")', '{{.Ecosystem}}');
`
var parametersDataSQLMintBalance = `
INSERT INTO "1_parameters" ("id","name", "value", "conditions", "ecosystem") VALUES
(next_id('1_parameters'),'assign_rule', '{"1":{"start_blockid":9223372036854775807,"end_blockid":9223372036854775807,"interval_blockid":7776000,"count":3,"total_amount":"63000000000000000000"},"2":{"start_blockid":9223372036854775807,"end_blockid":9223372036854775807,"interval_blockid":2592000,"count":4,"total_amount":"105000000000000000000"},"3":{"start_blockid":7776001,"end_blockid":9223372036854775807,"interval_blockid":1,"count":0,"total_amount":"315000000000000000000"},"4":{"start_blockid":3888001,"end_blockid":19440001,"interval_blockid":648000,"count":24,"total_amount":"168000000000000000000"},"5":{"start_blockid":3888001,"end_blockid":34344001,"interval_blockid":648000,"count":48,"total_amount":"315000000000000000000"},"6":{"start_blockid":7776001,"end_blockid":9223372036854775807,"interval_blockid":1,"count":0,"total_amount":"1128750000000000000000"},"7":{"start_blockid":1,"end_blockid":9223372036854775807,"interval_blockid":1,"count":0,"total_amount":"5250000000000000000"}}
', 'ContractConditions("@1DeveloperCondition")', '{{.Ecosystem}}'),
(next_id('1_parameters'),'mint_balance', '1128750000000000000000', 'ContractConditions("@1DeveloperCondition")', '{{.Ecosystem}}'),
(next_id('1_parameters'),'foundation_balance', '315000000000000000000', 'ContractConditions("@1DeveloperCondition")', '{{.Ecosystem}}'),
Expand Down
1 change: 0 additions & 1 deletion packages/migration/sections_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@

package migration

var sectionsDataSQL = `
36 changes: 17 additions & 19 deletions packages/migration/tables_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,6 @@ var tablesDataSQL = `INSERT INTO "1_tables" ("id", "name", "permissions","column
(next_id('1_tables'), 'languages',
'{
"insert": "ContractConditions(\"DeveloperCondition\")",
"update": "ContractConditions(\"DeveloperCondition\")",
"new_column": "ContractConditions(\"@1AdminCondition\")"
}',
'{
"name": "ContractAccess(\"@1EditLang\")",
"res": "ContractAccess(\"@1EditLang\")",
"conditions": "ContractAccess(\"@1EditLang\")",
"permissions": "ContractConditions(\"@1AdminCondition\")",
"ecosystem": "false"
}',
'ContractConditions("@1AdminCondition")', '{{.Ecosystem}}'
),
(next_id('1_tables'), 'menu',
'{
"insert": "ContractConditions(\"DeveloperCondition\")",
"update": "ContractConditions(\"DeveloperCondition\")",
"new_column": "ContractConditions(\"@1AdminCondition\")"
}',
'{
"name": "false",
"value": "ContractAccess(\"@1EditMenu\",\"@1AppendMenu\")",
"title": "ContractAccess(\"@1EditMenu\")",
Expand Down Expand Up @@ -269,6 +250,23 @@ var tablesDataSQL = `INSERT INTO "1_tables" ("id", "name", "permissions","column
),
(next_id('1_tables'), 'app_params',
'{
"insert": "ContractConditions(\"DeveloperCondition\")",
"update": "ContractAccess(\"@1EditAppParam\",\"@1VotingUpdateAssign\")",
"new_column": "ContractConditions(\"@1AdminCondition\")"
}',
'{
"app_id": "ContractAccess(\"@1ItemChangeAppId\")",
"name": "false",
"value": "ContractAccess(\"@1EditAppParam\",\"@1VotingUpdateAssign\")",
"conditions": "ContractAccess(\"@1EditAppParam\")",
"permissions": "ContractConditions(\"@1AdminCondition\")",
"ecosystem": "false"
}',
'ContractConditions("@1AdminCondition")', '{{.Ecosystem}}'
),
(next_id('1_tables'), 'buffer_data',
'{
"insert": "true",
"update": "true",
"new_column": "ContractConditions(\"@1AdminCondition\")"
}',
Expand Down
Loading

0 comments on commit 9a4f11f

Please sign in to comment.