Use own directory, fix tx size test, remove parseCmnError
This commit is contained in:
parent
f11ee67782
commit
fd36abfe05
@ -4,6 +4,8 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
@ -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 {
|
||||
@ -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,
|
||||
@ -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,
|
||||
@ -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())
|
||||
|
||||
@ -31,5 +31,5 @@ func ExampleTxSendSize() {
|
||||
fmt.Println(len(cdc.MustMarshalBinaryBare([]sdk.Msg{msg1})))
|
||||
fmt.Println(len(cdc.MustMarshalBinaryBare(tx)))
|
||||
// output: 80
|
||||
// 173
|
||||
// 167
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
@ -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.
|
||||
@ -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 {
|
||||
@ -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"`
|
||||
|
||||
Loading…
Reference in New Issue
Block a user