Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean warning from go report #5

Merged
merged 2 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ var (
// MakeCodec is the function alias for codec maker
MakeCodec = protocol.MakeCodec
// ModuleBasics is the variable alias for NewBasicManager
ModuleBasics = protocol.ModuleBasics
ModuleBasics = protocol.ModuleBasics
// DefaultCLIHome is the directory for okchaincli
DefaultCLIHome = protocol.DefaultCLIHome
DefaultCLIHome = protocol.DefaultCLIHome
// DefaultNodeHome is the directory for okchaind
DefaultNodeHome = protocol.DefaultNodeHome
)
89 changes: 30 additions & 59 deletions app/protocol/mock_protocol.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// nolint
package protocol

import (
"encoding/json"

"github.com/okex/okchain/x/token"

"github.com/tendermint/tendermint/libs/log"
Expand All @@ -18,90 +18,61 @@ import (
"github.com/okex/okchain/x/stream"
)

// MockProtocol is designed for engine test
var _ Protocol = (*MockProtocol)(nil)

// MockProtocol is designed for engine test
type MockProtocol struct {
parent Parent
version uint64
logger log.Logger
}

// NewMockProtocol creates a new instance of MockProtocol
func NewMockProtocol(version uint64) Protocol {
return &MockProtocol{
nil,
version,
nil,
}
}

// GetParent returns the Parent implements
func (mp *MockProtocol) GetParent() Parent {
if mp.parent == nil {
panic("parent is nil in the protocol")
}
return mp.parent
}

// SetLogger sets logger
func (mp *MockProtocol) SetLogger(log log.Logger) Protocol {
mp.logger = log
return mp
}

// SetParent sets Parent and return the Protocol implements
func (mp *MockProtocol) SetParent(parent Parent) Protocol {
mp.parent = parent
return mp
}

func (mp *MockProtocol) GetCrisisKeeper() crisis.Keeper {
return crisis.Keeper{}
}

func (mp *MockProtocol) GetStakingKeeper() staking.Keeper {
return staking.Keeper{}
}

func (mp *MockProtocol) GetDistrKeeper() distr.Keeper {
return distr.Keeper{}
}

func (mp *MockProtocol) GetSlashingKeeper() slashing.Keeper {
return slashing.Keeper{}
}

func (mp *MockProtocol) GetTokenKeeper() token.Keeper {
return token.Keeper{}
}

func (mp *MockProtocol) ExportGenesis(ctx sdk.Context) map[string]json.RawMessage {
return nil
}

func NewMockProtocol(version uint64) Protocol {
return &MockProtocol{
nil,
version,
nil,
}
}

// GetVersion gets version
func (mp *MockProtocol) GetVersion() uint64 {
return mp.version
}

func (*MockProtocol) LoadContext() {}

func (*MockProtocol) Init() {}

func (*MockProtocol) GetCodec() *codec.Codec {
return nil
}

func (*MockProtocol) CheckStopped() {}

func (*MockProtocol) GetBackendKeeper() backend.Keeper {
return backend.Keeper{}
}

func (*MockProtocol) GetStreamKeeper() stream.Keeper {
return stream.Keeper{}
}

func (*MockProtocol) GetKVStoreKeysMap() map[string]*sdk.KVStoreKey {
return nil
}

func (*MockProtocol) GetTransientStoreKeysMap() map[string]*sdk.TransientStoreKey {
return nil
}
// nolint
func (*MockProtocol) LoadContext() {}
func (*MockProtocol) Init() {}
func (*MockProtocol) CheckStopped() {}
func (*MockProtocol) GetCodec() *codec.Codec { return nil }
func (*MockProtocol) ExportGenesis(ctx sdk.Context) map[string]json.RawMessage { return nil }
func (*MockProtocol) GetKVStoreKeysMap() map[string]*sdk.KVStoreKey { return nil }
func (*MockProtocol) GetTransientStoreKeysMap() map[string]*sdk.TransientStoreKey { return nil }
func (*MockProtocol) GetBackendKeeper() backend.Keeper { return backend.Keeper{} }
func (*MockProtocol) GetStreamKeeper() stream.Keeper { return stream.Keeper{} }
func (*MockProtocol) GetCrisisKeeper() crisis.Keeper { return crisis.Keeper{} }
func (*MockProtocol) GetStakingKeeper() staking.Keeper { return staking.Keeper{} }
func (*MockProtocol) GetDistrKeeper() distr.Keeper { return distr.Keeper{} }
func (*MockProtocol) GetSlashingKeeper() slashing.Keeper { return slashing.Keeper{} }
func (*MockProtocol) GetTokenKeeper() token.Keeper { return token.Keeper{} }
7 changes: 3 additions & 4 deletions app/protocol/protocol_v0.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,16 @@ func (p *ProtocolV0) produceKeepers() {
p.crisisKeeper = crisis.NewKeeper(crisisSubspace, p.invCheckPeriod, p.supplyKeeper, auth.FeeCollectorName)

p.tokenKeeper = token.NewKeeper(
p.bankKeeper, p.paramsKeeper, tokenSubspace, auth.FeeCollectorName, p.supplyKeeper,
p.bankKeeper, tokenSubspace, auth.FeeCollectorName, p.supplyKeeper,
p.keys[token.StoreKey], p.keys[token.KeyLock],
p.cdc, appConfig.BackendConfig.EnableBackend)

p.dexKeeper = dex.NewKeeper(auth.FeeCollectorName, p.supplyKeeper, dexSubspace, p.tokenKeeper, &stakingKeeper,
p.bankKeeper, p.keys[dex.StoreKey], p.keys[dex.TokenPairStoreKey], p.cdc)

p.orderKeeper = order.NewKeeper(
p.tokenKeeper, p.supplyKeeper, p.paramsKeeper, p.dexKeeper, orderSubspace, auth.FeeCollectorName,
p.keys[order.OrderStoreKey],
p.cdc, appConfig.BackendConfig.EnableBackend, orderMetrics,
p.tokenKeeper, p.supplyKeeper, p.dexKeeper, orderSubspace, auth.FeeCollectorName,
p.keys[order.OrderStoreKey], p.cdc, appConfig.BackendConfig.EnableBackend, orderMetrics,
)

p.streamKeeper = stream.NewKeeper(p.orderKeeper, p.tokenKeeper, p.dexKeeper, p.accountKeeper, p.cdc, p.logger,
Expand Down
6 changes: 3 additions & 3 deletions app/protocol/protocol_v0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ func TestProtocolV0_InitChainer_BeginBlocker_EndBlocker_ExportGenesis_ExportAppS
})

// check the event type "UpgradeAppVersion" in upgrade EndBlock
var exsited bool
var existed bool
for _, event := range endBlockResponse.Events {
if event.Type == upgrade.EventTypeUpgradeAppVersion {
exsited = true
existed = true
}
}
require.True(t, exsited)
require.True(t, existed)

///////////////////////////// test ExportGenesis /////////////////////////////
var jsonRawMessageMap map[string]json.RawMessage
Expand Down
2 changes: 1 addition & 1 deletion app/protocol/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ type Parent interface {
PushEndBlocker(endBlocker sdk.EndBlocker)
PushAnteHandler(ah sdk.AnteHandler)
SetRouter(router sdk.Router, queryRouter sdk.QueryRouter)
}
}
25 changes: 8 additions & 17 deletions cmd/okchaincli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,37 @@ import (
"github.com/tendermint/tendermint/libs/cli"
)

const (
storeAcc = "acc"
storeOrder = "order"
storeTo = "token"
disStoreKey = "distribution"
)

func main() {
// Configure cobra to sort commands
// configure cobra to sort commands
cobra.EnableCommandSorting = false

// Instantiate the codec for the command line application
// instantiate the codec for the command line application
cdc := app.MakeCodec()

// Read in the configuration file for the sdk
// read in the configuration file for the sdk
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(sdk.Bech32PrefixAccAddr, sdk.Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(sdk.Bech32PrefixValAddr, sdk.Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
config.Seal()

// TODO: setup keybase, viper object, etc. to be passed into
// the below functions and eliminate global vars, like we do
// with the cdc
// the below functions and eliminate global vars, like we do with the cdc

rootCmd := &cobra.Command{
Use: "okchaincli",
Short: "Command line interface for interacting with okchaind",
}

// Add --chain-id to persistent flags and mark it required
// add --chain-id to persistent flags and mark it required
rootCmd.PersistentFlags().String(client.FlagChainID, "", "Chain ID of tendermint node")
rootCmd.PersistentFlags().String(client.FlagKeyPass, client.DefaultKeyPass, "Pass word of sender")

rootCmd.PersistentPreRunE = func(_ *cobra.Command, _ []string) error {
return initConfig(rootCmd)
}

// Construct Root Command
// construct root command
rootCmd.AddCommand(
rpc.StatusCommand(),
client.ConfigCmd(app.DefaultCLIHome),
Expand All @@ -78,11 +70,10 @@ func main() {
client.NewCompletionCmd(rootCmd, true),
)

// Add flags and prefix all env exposed with OKCHAIN
// add flags and prefix all env exposed with OKCHAIN
executor := cli.PrepareMainCmd(rootCmd, "OKCHAIN", app.DefaultCLIHome)

err := executor.Execute()
if err != nil {
if err := executor.Execute(); err != nil {
fmt.Printf("Failed executing CLI command: %s, exiting...\n", err)
os.Exit(1)
}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require (
github.com/spf13/viper v1.6.1
github.com/stretchr/testify v1.4.0
github.com/tendermint/go-amino v0.15.1
github.com/tendermint/tendermint v0.32.9
github.com/tendermint/tendermint v0.32.10
github.com/tendermint/tm-db v0.2.0
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 // indirect
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
Expand All @@ -44,7 +44,7 @@ require (
)

replace (
github.com/cosmos/cosmos-sdk => github.com/okex/cosmos-sdk v0.37.8-okchain
github.com/cosmos/cosmos-sdk => github.com/okex/cosmos-sdk v0.37.9-okchain
github.com/tendermint/iavl => github.com/okex/iavl v0.12.4-okchain
github.com/tendermint/tendermint => github.com/okex/tendermint v0.32.9-okchain
github.com/tendermint/tendermint => github.com/okex/tendermint v0.32.10-okchain
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/okex/cosmos-sdk v0.37.8-okchain h1:8HnWnuA5jbXw8h4Zzepnu2MZETR9ZWQk+PDjcDKvCcM=
github.com/okex/cosmos-sdk v0.37.8-okchain/go.mod h1:63Y8V75rRDzUrtRUwy+5cBOy5mr6xytI11PBk53tBrE=
github.com/okex/cosmos-sdk v0.37.9-okchain h1:Gn2sRCqlczEdgpXzh5St227pdgZlsoL4bfepRZprHkU=
github.com/okex/cosmos-sdk v0.37.9-okchain/go.mod h1:PG0SiXXlRej2X62VJLGbbiQuFa+i8TX/98vcfX71QLI=
github.com/okex/iavl v0.12.4-okchain h1:BAFmygzhx6k4KGnLrY87ZrJvRSb+wf8Oo4e2KhUwXcU=
github.com/okex/iavl v0.12.4-okchain/go.mod h1:8LHakzt8/0G3/I8FUU0ReNx98S/EP6eyPJkAUvEXT/o=
github.com/okex/tendermint v0.32.9-okchain h1:YKdPlrLPHjn6ZNrxWcwFZkjfbhif1bXU7UA2xgDTwec=
github.com/okex/tendermint v0.32.9-okchain/go.mod h1:5/B1XZjNYtVBso8o1l/Eg4A0Mhu42lDcmftoQl95j/E=
github.com/okex/tendermint v0.32.10-okchain h1:4ZzRPVhDA+fHTQ/hVboAK7PPxL7uA5+Z4wKm8qeheJ0=
github.com/okex/tendermint v0.32.10-okchain/go.mod h1:5/B1XZjNYtVBso8o1l/Eg4A0Mhu42lDcmftoQl95j/E=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down
2 changes: 1 addition & 1 deletion x/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go get go-sqlite3
1. github.com/okex/okchain/vendor/github.com/mattn/go-sqlite3
../../vendor/github.com/mattn/go-sqlite3/backup.go:14:10: fatal error: 'stdlib.h' file not found
#include <stdlib.h>
^~~~~~~~~~

solution: https://github.com/mattn/go-sqlite3/issues/481

* try in ubuntu: sudo apt-get install g++
Expand Down
27 changes: 15 additions & 12 deletions x/backend/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
orderTypes "github.com/okex/okchain/x/order/types"
)

// Called every block, check expired orders
// EndBlocker called every block, check expired orders
func EndBlocker(ctx sdk.Context, keeper Keeper) {
if keeper.Config.EnableBackend && keeper.Config.EnableMktCompute {
keeper.Logger.Debug(fmt.Sprintf("begin backend endblocker: block---%d", ctx.BlockHeight()))
Expand Down Expand Up @@ -109,6 +109,7 @@ func updateOrders(ctx sdk.Context, keeper Keeper) {
}
}

// nolint
func GetNewDealsAndMatchResultsAtEndBlock(ctx sdk.Context, orderKeeper types.OrderKeeper) ([]*types.Deal, []*types.MatchResult, error) {
result := orderKeeper.GetBlockMatchResult()
if result == nil {
Expand Down Expand Up @@ -144,7 +145,7 @@ func GetNewDealsAndMatchResultsAtEndBlock(ctx sdk.Context, orderKeeper types.Ord

deal := &types.Deal{
BlockHeight: blockHeight,
OrderId: record.OrderID,
OrderID: record.OrderID,
Side: record.Side,
Sender: order.Sender.String(),
Product: product,
Expand All @@ -161,18 +162,19 @@ func GetNewDealsAndMatchResultsAtEndBlock(ctx sdk.Context, orderKeeper types.Ord
return deals, results, nil
}

// nolint
func GetNewOrdersAtEndBlock(ctx sdk.Context, orderKeeper types.OrderKeeper) ([]*types.Order, error) {
blockHeight := ctx.BlockHeight()
orderNum := orderKeeper.GetBlockOrderNum(ctx, blockHeight)
orders := make([]*types.Order, 0, orderNum)
var index int64 = 0
var index int64
for ; index < orderNum; index++ {
orderId := orderTypes.FormatOrderID(blockHeight, index+1)
order := orderKeeper.GetOrder(ctx, orderId)
orderID := orderTypes.FormatOrderID(blockHeight, index+1)
order := orderKeeper.GetOrder(ctx, orderID)
if order != nil {
orderDb := &types.Order{
TxHash: order.TxHash,
OrderId: order.OrderID,
OrderID: order.OrderID,
Sender: order.Sender.String(),
Product: order.Product,
Side: order.Side,
Expand All @@ -185,21 +187,22 @@ func GetNewOrdersAtEndBlock(ctx sdk.Context, orderKeeper types.OrderKeeper) ([]*
}
orders = append(orders, orderDb)
} else {
return nil, fmt.Errorf("failed to get order with orderId: %+v at blockHeight: %d", orderId, blockHeight)
return nil, fmt.Errorf("failed to get order with orderID: %+v at blockHeight: %d", orderID, blockHeight)
}
}
return orders, nil
}

// nolint
func GetUpdatedOrdersAtEndBlock(ctx sdk.Context, orderKeeper types.OrderKeeper) []*types.Order {
orderIds := orderKeeper.GetUpdatedOrderIDs()
orders := make([]*types.Order, 0, len(orderIds))
for _, orderId := range orderIds {
order := orderKeeper.GetOrder(ctx, orderId)
orderIDs := orderKeeper.GetUpdatedOrderIDs()
orders := make([]*types.Order, 0, len(orderIDs))
for _, orderID := range orderIDs {
order := orderKeeper.GetOrder(ctx, orderID)
if order != nil {
orderDb := &types.Order{
TxHash: order.TxHash,
OrderId: order.OrderID,
OrderID: order.OrderID,
Sender: order.Sender.String(),
Product: order.Product,
Side: order.Side,
Expand Down
3 changes: 1 addition & 2 deletions x/backend/alias.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// nolint
package backend

import (
Expand All @@ -14,8 +15,6 @@ const (
QuerierRoute = types.QuerierRoute
// RouterKey is the msg router key for the backend module
RouterKey = types.RouterKey

EngineTypeMysql = orm.EngineTypeMysql
)

type (
Expand Down
Loading