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

Light clean up based on goland report #3085

Merged
merged 11 commits into from
Mar 4, 2021
2 changes: 0 additions & 2 deletions api/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ var (
ErrOrderServiceGetByParty = errors.New("failed to get orders for party")
ErrOrderServiceGetByReference = errors.New("failed to get orders for reference")
ErrMissingOrderIDParameter = errors.New("missing orderID parameter")
ErrMissingReferenceIDParameter = errors.New("missing referenceID parameter")
ErrOrderAndReferenceMismatch = errors.New("referenceID and orderID do not match up")
ErrOrderNotFound = errors.New("order not found")
// TradeService...
ErrTradeServiceGetByParty = errors.New("failed to get trades for party")
Expand Down
40 changes: 20 additions & 20 deletions api/trading_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,26 +773,26 @@ func (t *tradingDataService) Statistics(ctx context.Context, _ *protoapi.Statist
}

stats := &types.Statistics{
BlockHeight: t.Stats.Blockchain.Height(),
BacklogLength: uint64(backlogLength),
TotalPeers: uint64(numPeers),
GenesisTime: genesisTime,
CurrentTime: vegatime.Format(vegatime.Now()),
VegaTime: vegatime.Format(epochTime),
Uptime: vegatime.Format(t.Stats.GetUptime()),
TxPerBlock: uint64(t.Stats.Blockchain.TotalTxLastBatch()),
AverageTxBytes: uint64(t.Stats.Blockchain.AverageTxSizeBytes()),
AverageOrdersPerBlock: uint64(t.Stats.Blockchain.AverageOrdersPerBatch()),
TradesPerSecond: t.Stats.Blockchain.TradesPerSecond(),
OrdersPerSecond: t.Stats.Blockchain.OrdersPerSecond(),
Status: t.statusChecker.ChainStatus(),
TotalMarkets: uint64(len(m)),
AppVersionHash: t.Stats.GetVersionHash(),
AppVersion: t.Stats.GetVersion(),
ChainVersion: t.Stats.GetChainVersion(),
TotalAmendOrder: t.Stats.Blockchain.TotalAmendOrder(),
TotalCancelOrder: t.Stats.Blockchain.TotalCancelOrder(),
TotalCreateOrder: t.Stats.Blockchain.TotalCreateOrder(),
BlockHeight: t.Stats.Blockchain.Height(),
BacklogLength: uint64(backlogLength),
TotalPeers: uint64(numPeers),
GenesisTime: genesisTime,
CurrentTime: vegatime.Format(vegatime.Now()),
VegaTime: vegatime.Format(epochTime),
Uptime: vegatime.Format(t.Stats.GetUptime()),
TxPerBlock: t.Stats.Blockchain.TotalTxLastBatch(),
AverageTxBytes: t.Stats.Blockchain.AverageTxSizeBytes(),
AverageOrdersPerBlock: t.Stats.Blockchain.AverageOrdersPerBatch(),
TradesPerSecond: t.Stats.Blockchain.TradesPerSecond(),
OrdersPerSecond: t.Stats.Blockchain.OrdersPerSecond(),
Status: t.statusChecker.ChainStatus(),
TotalMarkets: uint64(len(m)),
AppVersionHash: t.Stats.GetVersionHash(),
AppVersion: t.Stats.GetVersion(),
ChainVersion: t.Stats.GetChainVersion(),
TotalAmendOrder: t.Stats.Blockchain.TotalAmendOrder(),
TotalCancelOrder: t.Stats.Blockchain.TotalCancelOrder(),
TotalCreateOrder: t.Stats.Blockchain.TotalCreateOrder(),
TotalOrders: t.Stats.Blockchain.TotalOrders(),
TotalTrades: t.Stats.Blockchain.TotalTrades(),
BlockDuration: t.Stats.Blockchain.BlockDuration(),
Expand Down
4 changes: 2 additions & 2 deletions api/trading_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func getTestGRPCServer(
path := fmt.Sprintf("vegatest-%d-", port)
tempDir, tidyTempDir, err := storage.TempDir(path)
if err != nil {
err = fmt.Errorf("Failed to create tmp dir: %s", err.Error())
err = fmt.Errorf("failed to create tmp dir: %s", err.Error())
return
}

Expand Down Expand Up @@ -291,7 +291,7 @@ func getTestGRPCServer(
monitoring.New(logger, monitoring.NewDefaultConfig(), blockchainClient),
)
if g == nil {
err = fmt.Errorf("Failed to create gRPC server")
err = fmt.Errorf("failed to create gRPC server")
return
}

Expand Down
2 changes: 0 additions & 2 deletions assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import (
var (
ErrAssetInvalid = errors.New("asset invalid")
ErrAssetDoesNotExist = errors.New("asset does not exist")
ErrAssetExistForID = errors.New("an asset already exist for this ID")
ErrUnknowAssetSource = errors.New("unknown asset source")
ErrNoAssetForRef = errors.New("no assets for proposal reference")
)

// TimeService ...
Expand Down
6 changes: 3 additions & 3 deletions assets/erc20/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (b *ERC20) ValidateAssetList(w *types.ERC20AssetList, blockNumber, txIndex
return "", 0, err
}

var resp string = "ok"
var resp = "ok"
defer func() {
metrics.EthCallInc("validate_allowlist", b.asset.Id, resp)
}()
Expand Down Expand Up @@ -336,7 +336,7 @@ func (b *ERC20) ValidateWithdrawal(w *types.ERC20Withdrawal, blockNumber, txInde
return nil, "", 0, err
}

var resp string = "ok"
var resp = "ok"
defer func() {
metrics.EthCallInc("validate_withdrawal", b.asset.Id, resp)
}()
Expand Down Expand Up @@ -390,7 +390,7 @@ func (b *ERC20) ValidateDeposit(d *types.ERC20Deposit, blockNumber, txIndex uint
return "", "", "", 0, 0, err
}

var resp string = "ok"
var resp = "ok"
defer func() {
metrics.EthCallInc("validate_deposit", b.asset.Id, resp)
}()
Expand Down
2 changes: 1 addition & 1 deletion assets/genesis_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func DefaultGenesisState() GenesisState {

h := func(key []byte) []byte {
hasher := sha3.New256()
hasher.Write([]byte(key))
hasher.Write(key)
return hasher.Sum(nil)
}

Expand Down
2 changes: 0 additions & 2 deletions banking/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ var (
ErrInvalidWithdrawalState = errors.New("invalid withdrawal state")
ErrNotMatchingWithdrawalForReference = errors.New("invalid reference for withdrawal chain event")
ErrWithdrawalNotReady = errors.New("withdrawal not ready")
ErrMissingWithdrawIDFromContext = errors.New("missing withdraw ID from context")
ErrMissingDepositIDFromContext = errors.New("missing deposit ID from context")
)

//go:generate go run github.com/golang/mock/mockgen -destination mocks/assets_mock.go -package mocks code.vegaprotocol.io/vega/banking Assets
Expand Down
1 change: 0 additions & 1 deletion blockchain/abci/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func (c *testCodec) Decode(in []byte) (abci.Tx, error) {
const (
testCommandA = txn.Command(0x01)
testCommandB = txn.Command(0x02)
testCommandC = txn.Command(0x03)
)

type testCtxKey int
Expand Down
1 change: 0 additions & 1 deletion blockchain/abci/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

var (
ErrEmptyClientAddr = errors.New("abci client addr is empty in config")
ErrEmptyClientEndpoint = errors.New("abci client websocket endpoint is empty in config")
)

type Client struct {
Expand Down
2 changes: 1 addition & 1 deletion candles/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,5 @@ func (m itMatcher) Matches(x interface{}) bool {
default:
return false
}
return (v.Market == m.market && v.Interval == m.interval)
return v.Market == m.market && v.Interval == m.interval
}
2 changes: 1 addition & 1 deletion cmd/vega/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func loadVegaPubKey(log *logging.Logger, rootPath, pass string) (string, error)
return "", err
}

w, ok := nw.Get(nodewallet.Blockchain("vega"))
w, ok := nw.Get("vega")
if !ok {
return "", errors.New("no vega wallet stored in node wallet")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/vega/verify/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (r *reporter) Start(f string) {
}

func (r *reporter) Dump(result string) {
var ok string = green("OK")
var ok = green("OK")
if r.hasCurrError {
r.hasError = true
ok = red("KO")
Expand Down
2 changes: 1 addition & 1 deletion cmd/vega/verify/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func marshal(i proto.Message) string {
EmitDefaults: true,
}
buf, _ := m.MarshalToString(i)
return string(buf)
return buf
}

func readFile(r *reporter, path string) []byte {
Expand Down
8 changes: 4 additions & 4 deletions collateral/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var (
ErrInsufficientFundsToPayFees = errors.New("insufficient funds to pay fees")
// ErrInvalidTransferTypeForFeeRequest an invalid transfer type was send to build a fee transfer request
ErrInvalidTransferTypeForFeeRequest = errors.New("an invalid transfer type was send to build a fee transfer request")
// ErrNotEnoughFundsToWithdraa a party requested to withdraw more than on its general account
// ErrNotEnoughFundsToWithdraw a party requested to withdraw more than on its general account
ErrNotEnoughFundsToWithdraw = errors.New("not enough funds to withdraw")
// ErrGovernanceAssetIDMatchNoAsset
ErrGovernanceAssetIDMatchNoAsset = errors.New("governance asset ID match no asset")
Expand Down Expand Up @@ -1449,7 +1449,7 @@ func (e *Engine) ClearMarket(ctx context.Context, mktID, asset string, parties [

req.FromAccount[0] = marginAcc
req.ToAccount[0] = generalAcc
req.Amount = uint64(marginAcc.Balance)
req.Amount = marginAcc.Balance

if e.log.GetLevel() == logging.DebugLevel {
e.log.Debug("Clearing party margin account",
Expand Down Expand Up @@ -1506,7 +1506,7 @@ func (e *Engine) ClearMarket(ctx context.Context, mktID, asset string, parties [

req.FromAccount[0] = bondAcc
req.ToAccount[0] = generalAcc
req.Amount = uint64(marginAcc.Balance)
req.Amount = marginAcc.Balance

if e.log.GetLevel() == logging.DebugLevel {
e.log.Debug("Clearing party bond account",
Expand Down Expand Up @@ -2003,7 +2003,7 @@ func (e *Engine) Withdraw(ctx context.Context, partyID, asset string, amount uin
}

// check we have more money than required to withdraw
if uint64(acc.Balance) < amount {
if acc.Balance < amount {
return nil, fmt.Errorf("withdraw error, required=%v, available=%v", amount, acc.Balance)
}

Expand Down
6 changes: 3 additions & 3 deletions collateral/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ func testInitialTokens(t *testing.T) {
acc, err = eng.GetPartyTokenAccount(trader)
assert.NoError(t, err)
assert.NotNil(t, acc)
assert.Equal(t, uint64(acc.Balance), eng.GetTotalTokens())
assert.Equal(t, acc.Balance, eng.GetTotalTokens())
eng.broker.EXPECT().Send(gomock.Any()).Times(2)

// withdraw half the amount
Expand All @@ -604,7 +604,7 @@ func testInitialTokens(t *testing.T) {
assert.NoError(t, err) // half the amount

acc.Balance /= 2
assert.Equal(t, uint64(acc.Balance), eng.GetTotalTokens())
assert.Equal(t, acc.Balance, eng.GetTotalTokens())
// test subtracting something from the balance
eng.broker.EXPECT().Send(gomock.Any()).Times(2)

Expand All @@ -615,7 +615,7 @@ func testInitialTokens(t *testing.T) {

assert.NoError(t, eng.DecrementBalance(context.Background(), acc.Id, 100))
acc.Balance -= 100
assert.Equal(t, uint64(acc.Balance), eng.GetTotalTokens())
assert.Equal(t, acc.Balance, eng.GetTotalTokens())
}

func testNew(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion collateral/margins.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (n marginUpdate) MarginBalance() uint64 {
if n.margin == nil {
return 0
}
return uint64(n.margin.Balance)
return n.margin.Balance
}

// GeneralBalance here we cumulate both the general
Expand Down
2 changes: 1 addition & 1 deletion crypto/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import "golang.org/x/crypto/sha3"

func Hash(key []byte) []byte {
hasher := sha3.New256()
hasher.Write([]byte(key))
hasher.Write(key)
return hasher.Sum(nil)
}
2 changes: 1 addition & 1 deletion events/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewAccountEvent(ctx context.Context, a types.Account) *Acc {
}

func (a Acc) IsParty(id string) bool {
return (a.a.Owner == id)
return a.a.Owner == id
}

func (a Acc) PartyID() string {
Expand Down
2 changes: 1 addition & 1 deletion events/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Auction struct {

// NewAuctionEvent creates a new auction event object
func NewAuctionEvent(ctx context.Context, marketID string, leave bool, start, stop int64, trigger types.AuctionTrigger) *Auction {
opening := (trigger == types.AuctionTrigger_AUCTION_TRIGGER_OPENING)
opening := trigger == types.AuctionTrigger_AUCTION_TRIGGER_OPENING
return &Auction{
Base: newBase(ctx, AuctionEvent),
marketID: marketID,
Expand Down
4 changes: 2 additions & 2 deletions events/bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func GetMarketIDFilter(mID string) func(Event) bool {
if !ok {
return false
}
return (me.MarketID() == mID)
return me.MarketID() == mID
}
}

Expand All @@ -356,7 +356,7 @@ func GetPartyAndMarketFilter(mID, pID string) func(Event) bool {
if !ok {
return false
}
return (mpe.MarketID() == mID && mpe.PartyID() == pID)
return mpe.MarketID() == mID && mpe.PartyID() == pID
}
}

Expand Down
2 changes: 1 addition & 1 deletion events/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (d *Deposit) Deposit() types.Deposit {
}

func (d Deposit) IsParty(id string) bool {
return (d.d.PartyId == id)
return d.d.PartyId == id
}

func (d Deposit) PartyID() string { return d.d.PartyId }
Expand Down
2 changes: 1 addition & 1 deletion events/governance_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (p *Proposal) ProposalID() string {
}

func (p Proposal) IsParty(id string) bool {
return (p.p.PartyId == id)
return p.p.PartyId == id
}

// PartyID - for combined subscriber, communal interface
Expand Down
2 changes: 1 addition & 1 deletion events/liquidity_provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewLiquidityProvisionEvent(ctx context.Context, p *types.LiquidityProvision
}

func (p LiquidityProvision) IsParty(id string) bool {
return (p.p.PartyId == id)
return p.p.PartyId == id
}

func (p LiquidityProvision) PartyID() string {
Expand Down
2 changes: 1 addition & 1 deletion events/loss_socialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewLossSocializationEvent(ctx context.Context, partyID, marketID string, am
}

func (l LossSoc) IsParty(id string) bool {
return (l.partyID == id)
return l.partyID == id
}

func (l LossSoc) PartyID() string {
Expand Down
2 changes: 1 addition & 1 deletion events/margin_levels.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (m MarginLevels) MarginLevels() types.MarginLevels {
}

func (m MarginLevels) IsParty(id string) bool {
return (m.l.PartyId == id)
return m.l.PartyId == id
}

func (m MarginLevels) PartyID() string {
Expand Down
2 changes: 1 addition & 1 deletion events/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewOrderEvent(ctx context.Context, o *types.Order) *Order {
}

func (o Order) IsParty(id string) bool {
return (o.o.PartyId == id)
return o.o.PartyId == id
}

func (o Order) PartyID() string {
Expand Down
2 changes: 1 addition & 1 deletion events/party.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewPartyEvent(ctx context.Context, p types.Party) *Party {
}

func (p Party) IsParty(id string) bool {
return (p.p.Id == id)
return p.p.Id == id
}

func (p *Party) Party() types.Party {
Expand Down
2 changes: 1 addition & 1 deletion events/settle_distressed.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewSettleDistressed(ctx context.Context, partyID, marketID string, price, m
}

func (s SettleDistressed) IsParty(id string) bool {
return (s.partyID == id)
return s.partyID == id
}

func (s SettleDistressed) PartyID() string {
Expand Down
2 changes: 1 addition & 1 deletion events/settle_position.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (s SettlePos) MarketID() string {
}

func (s SettlePos) IsParty(id string) bool {
return (s.partyID == id)
return s.partyID == id
}

func (s SettlePos) PartyID() string {
Expand Down
2 changes: 1 addition & 1 deletion events/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (t Trade) MarketID() string {
}

func (t Trade) IsParty(id string) bool {
return (t.t.Buyer == id || t.t.Seller == id)
return t.t.Buyer == id || t.t.Seller == id
}

func (t *Trade) Trade() types.Trade {
Expand Down
2 changes: 1 addition & 1 deletion events/tx_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func NewTxErrEvent(ctx context.Context, err error, partyID string, tx interface{
}

func (t TxErr) IsParty(id string) bool {
return (t.evt.PartyId == id)
return t.evt.PartyId == id
}

func (t TxErr) Proto() types.TxErrorEvent {
Expand Down
Loading