Skip to content

Commit

Permalink
Use own directory, fix tx size test, remove parseCmnError
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgoes committed Sep 27, 2018
1 parent f11ee67 commit fd36abf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
17 changes: 13 additions & 4 deletions client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"fmt"
"io"
"os"
"path/filepath"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -19,11 +21,14 @@ import (
tmlite "github.com/tendermint/tendermint/lite"
tmliteProxy "github.com/tendermint/tendermint/lite/proxy"
rpcclient "github.com/tendermint/tendermint/rpc/client"
"os"
)

const ctxAccStoreName = "acc"

var (
verifier tmlite.Verifier
)

// CLIContext implements a typical CLI context created in SDK modules for
// transaction handling and queries.
type CLIContext struct {
Expand Down Expand Up @@ -60,6 +65,11 @@ func NewCLIContext() CLIContext {
from := viper.GetString(client.FlagFrom)
fromAddress, fromName := fromFields(from)

// We need to use a single verifier for all contexts
if verifier == nil {
verifier = createVerifier()
}

return CLIContext{
Client: rpc,
NodeURI: nodeURI,
Expand All @@ -71,7 +81,7 @@ func NewCLIContext() CLIContext {
Async: viper.GetBool(client.FlagAsync),
JSON: viper.GetBool(client.FlagJson),
PrintResponse: viper.GetBool(client.FlagPrintResponse),
Verifier: createVerifier(),
Verifier: verifier,
DryRun: viper.GetBool(client.FlagDryRun),
GenerateOnly: viper.GetBool(client.FlagGenerateOnly),
fromAddress: fromAddress,
Expand Down Expand Up @@ -109,8 +119,7 @@ func createVerifier() tmlite.Verifier {
os.Exit(1)
}
node := rpcclient.NewHTTP(nodeURI, "/websocket")
// TODO Utilize ctx.Logger correctly
verifier, err := tmliteProxy.NewVerifier(chainID, home, node, log.NewNopLogger())
verifier, err := tmliteProxy.NewVerifier(chainID, filepath.Join(home, ".gaialite"), node, log.NewNopLogger())

if err != nil {
fmt.Printf("Create verifier failed: %s\n", err.Error())
Expand Down
2 changes: 1 addition & 1 deletion cmd/gaia/app/benchmarks/txsize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ func ExampleTxSendSize() {
fmt.Println(len(cdc.MustMarshalBinaryBare([]sdk.Msg{msg1})))
fmt.Println(len(cdc.MustMarshalBinaryBare(tx)))
// output: 80
// 173
// 167
}
19 changes: 3 additions & 16 deletions types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package types

import (
"fmt"
"strings"

"github.com/cosmos/cosmos-sdk/codec"
cmn "github.com/tendermint/tendermint/libs/common"
Expand Down Expand Up @@ -231,13 +230,8 @@ func (err *sdkError) TraceSDK(format string, args ...interface{}) Error {
}

// Implements ABCIError.
// Overrides err.Error.Error().
func (err *sdkError) Error() string {
return fmt.Sprintf(`ERROR:
Codespace: %d
Code: %d
Message: %#v
`, err.codespace, err.code, parseCmnError(err.cmnError.Error()))
return err.cmnError.Error()
}

// Implements ABCIError.
Expand All @@ -258,12 +252,12 @@ func (err *sdkError) Code() CodeType {
// Implements ABCIError.
func (err *sdkError) ABCILog() string {
cdc := codec.New()
parsedErrMsg := parseCmnError(err.cmnError.Error())
errMsg := err.cmnError.Error()
jsonErr := humanReadableError{
Codespace: err.codespace,
Code: err.code,
ABCICode: err.ABCICode(),
Message: parsedErrMsg,
Message: errMsg,
}
bz, er := cdc.MarshalJSON(jsonErr)
if er != nil {
Expand All @@ -288,13 +282,6 @@ func (err *sdkError) QueryResult() abci.ResponseQuery {
}
}

func parseCmnError(err string) string {
if idx := strings.Index(err, "{"); idx != -1 {
err = err[idx+1 : len(err)-1]
}
return err
}

// nolint
type humanReadableError struct {
Codespace CodespaceType `json:"codespace"`
Expand Down

0 comments on commit fd36abf

Please sign in to comment.