diff --git a/types/result.go b/types/result.go index f861308ec8..216fe56c5a 100644 --- a/types/result.go +++ b/types/result.go @@ -9,17 +9,14 @@ import ( "github.com/gogo/protobuf/proto" - yaml "gopkg.in/yaml.v2" + "gopkg.in/yaml.v2" abci "github.com/line/ostracon/abci/types" ctypes "github.com/line/ostracon/rpc/core/types" - "github.com/line/lbm-sdk/v2/codec" codectypes "github.com/line/lbm-sdk/v2/codec/types" ) -var cdc = codec.NewLegacyAmino() - func (gi GasInfo) String() string { bz, _ := yaml.Marshal(gi) return string(bz) @@ -40,6 +37,7 @@ func (r Result) GetEvents() Events { } // ABCIMessageLogs represents a slice of ABCIMessageLog. +//easyjson:json type ABCIMessageLogs []ABCIMessageLog func NewABCIMessageLog(i uint32, log string, events Events) ABCIMessageLog { @@ -51,15 +49,15 @@ func NewABCIMessageLog(i uint32, log string, events Events) ABCIMessageLog { } // String implements the fmt.Stringer interface for the ABCIMessageLogs type. -func (logs ABCIMessageLogs) String() (str string) { +func (logs ABCIMessageLogs) String() string { if logs != nil { - raw, err := cdc.MarshalJSON(logs) - if err == nil { - str = string(raw) + res, err := logs.MarshalJSON() + if err != nil { + panic(err) } + return string(res) } - - return str + return "" } // NewResponseResultTx returns a TxResponse given a ResultTx from ostracon diff --git a/types/result_easyjson.go b/types/result_easyjson.go new file mode 100644 index 0000000000..506e3e33f7 --- /dev/null +++ b/types/result_easyjson.go @@ -0,0 +1,326 @@ +// Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT. + +package types + +import ( + json "encoding/json" + easyjson "github.com/mailru/easyjson" + jlexer "github.com/mailru/easyjson/jlexer" + jwriter "github.com/mailru/easyjson/jwriter" +) + +// suppress unused package warning +var ( + _ *json.RawMessage + _ *jlexer.Lexer + _ *jwriter.Writer + _ easyjson.Marshaler +) + +func easyjsonD3b49167DecodeGithubComLineLbmSdkV2Types(in *jlexer.Lexer, out *ABCIMessageLogs) { + isTopLevel := in.IsStart() + if in.IsNull() { + in.Skip() + *out = nil + } else { + in.Delim('[') + if *out == nil { + if !in.IsDelim(']') { + *out = make(ABCIMessageLogs, 0, 1) + } else { + *out = ABCIMessageLogs{} + } + } else { + *out = (*out)[:0] + } + for !in.IsDelim(']') { + var v1 ABCIMessageLog + easyjsonD3b49167DecodeGithubComLineLbmSdkV2Types1(in, &v1) + *out = append(*out, v1) + in.WantComma() + } + in.Delim(']') + } + if isTopLevel { + in.Consumed() + } +} +func easyjsonD3b49167EncodeGithubComLineLbmSdkV2Types(out *jwriter.Writer, in ABCIMessageLogs) { + if in == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { + out.RawString("null") + } else { + out.RawByte('[') + for v2, v3 := range in { + if v2 > 0 { + out.RawByte(',') + } + easyjsonD3b49167EncodeGithubComLineLbmSdkV2Types1(out, v3) + } + out.RawByte(']') + } +} + +// MarshalJSON supports json.Marshaler interface +func (v ABCIMessageLogs) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjsonD3b49167EncodeGithubComLineLbmSdkV2Types(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v ABCIMessageLogs) MarshalEasyJSON(w *jwriter.Writer) { + easyjsonD3b49167EncodeGithubComLineLbmSdkV2Types(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *ABCIMessageLogs) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjsonD3b49167DecodeGithubComLineLbmSdkV2Types(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *ABCIMessageLogs) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjsonD3b49167DecodeGithubComLineLbmSdkV2Types(l, v) +} +func easyjsonD3b49167DecodeGithubComLineLbmSdkV2Types1(in *jlexer.Lexer, out *ABCIMessageLog) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "msg_index": + out.MsgIndex = uint32(in.Uint32()) + case "log": + out.Log = string(in.String()) + case "events": + if in.IsNull() { + in.Skip() + out.Events = nil + } else { + in.Delim('[') + if out.Events == nil { + if !in.IsDelim(']') { + out.Events = make(StringEvents, 0, 1) + } else { + out.Events = StringEvents{} + } + } else { + out.Events = (out.Events)[:0] + } + for !in.IsDelim(']') { + var v4 StringEvent + easyjsonD3b49167DecodeGithubComLineLbmSdkV2Types2(in, &v4) + out.Events = append(out.Events, v4) + in.WantComma() + } + in.Delim(']') + } + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjsonD3b49167EncodeGithubComLineLbmSdkV2Types1(out *jwriter.Writer, in ABCIMessageLog) { + out.RawByte('{') + first := true + _ = first + if in.MsgIndex != 0 { + const prefix string = ",\"msg_index\":" + first = false + out.RawString(prefix[1:]) + out.Uint32(uint32(in.MsgIndex)) + } + if in.Log != "" { + const prefix string = ",\"log\":" + if first { + first = false + out.RawString(prefix[1:]) + } else { + out.RawString(prefix) + } + out.String(string(in.Log)) + } + { + const prefix string = ",\"events\":" + if first { + first = false + out.RawString(prefix[1:]) + } else { + out.RawString(prefix) + } + if in.Events == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { + out.RawString("null") + } else { + out.RawByte('[') + for v5, v6 := range in.Events { + if v5 > 0 { + out.RawByte(',') + } + easyjsonD3b49167EncodeGithubComLineLbmSdkV2Types2(out, v6) + } + out.RawByte(']') + } + } + out.RawByte('}') +} +func easyjsonD3b49167DecodeGithubComLineLbmSdkV2Types2(in *jlexer.Lexer, out *StringEvent) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "type": + out.Type = string(in.String()) + case "attributes": + if in.IsNull() { + in.Skip() + out.Attributes = nil + } else { + in.Delim('[') + if out.Attributes == nil { + if !in.IsDelim(']') { + out.Attributes = make([]Attribute, 0, 2) + } else { + out.Attributes = []Attribute{} + } + } else { + out.Attributes = (out.Attributes)[:0] + } + for !in.IsDelim(']') { + var v7 Attribute + easyjsonD3b49167DecodeGithubComLineLbmSdkV2Types3(in, &v7) + out.Attributes = append(out.Attributes, v7) + in.WantComma() + } + in.Delim(']') + } + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjsonD3b49167EncodeGithubComLineLbmSdkV2Types2(out *jwriter.Writer, in StringEvent) { + out.RawByte('{') + first := true + _ = first + if in.Type != "" { + const prefix string = ",\"type\":" + first = false + out.RawString(prefix[1:]) + out.String(string(in.Type)) + } + { + const prefix string = ",\"attributes\":" + if first { + first = false + out.RawString(prefix[1:]) + } else { + out.RawString(prefix) + } + if in.Attributes == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { + out.RawString("null") + } else { + out.RawByte('[') + for v8, v9 := range in.Attributes { + if v8 > 0 { + out.RawByte(',') + } + easyjsonD3b49167EncodeGithubComLineLbmSdkV2Types3(out, v9) + } + out.RawByte(']') + } + } + out.RawByte('}') +} +func easyjsonD3b49167DecodeGithubComLineLbmSdkV2Types3(in *jlexer.Lexer, out *Attribute) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "key": + out.Key = string(in.String()) + case "value": + out.Value = string(in.String()) + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjsonD3b49167EncodeGithubComLineLbmSdkV2Types3(out *jwriter.Writer, in Attribute) { + out.RawByte('{') + first := true + _ = first + if in.Key != "" { + const prefix string = ",\"key\":" + first = false + out.RawString(prefix[1:]) + out.String(string(in.Key)) + } + if in.Value != "" { + const prefix string = ",\"value\":" + if first { + first = false + out.RawString(prefix[1:]) + } else { + out.RawString(prefix) + } + out.String(string(in.Value)) + } + out.RawByte('}') +} diff --git a/types/result_test.go b/types/result_test.go index faeb353799..d99bf3871f 100644 --- a/types/result_test.go +++ b/types/result_test.go @@ -44,13 +44,74 @@ func (s *resultTestSuite) TestParseABCILog() { func (s *resultTestSuite) TestABCIMessageLog() { cdc := codec.NewLegacyAmino() - events := sdk.Events{sdk.NewEvent("transfer", sdk.NewAttribute("sender", "foo"))} - msgLog := sdk.NewABCIMessageLog(0, "", events) - msgLogs := sdk.ABCIMessageLogs{msgLog} - bz, err := cdc.MarshalJSON(msgLogs) - s.Require().NoError(err) - s.Require().Equal(string(bz), msgLogs.String()) + const maxIter = 5 + + tests := []struct { + emptyLog bool + emptyType bool + emptyKey bool + emptyValue bool + }{ + {false, false, false, false}, + {true, false, false, false}, + {false, true, false, false}, + {false, false, true, false}, + {false, false, false, true}, + {false, false, true, true}, + {false, true, false, true}, + {false, true, true, false}, + {true, false, false, true}, + {true, false, true, false}, + {true, true, false, false}, + {false, true, true, true}, + {true, false, true, true}, + {true, true, false, true}, + {true, true, true, false}, + {true, true, true, true}, + } + + for _, tt := range tests { + msgLogs := sdk.ABCIMessageLogs{} + for numMsgs := 0; numMsgs < maxIter; numMsgs++ { + for i := 0; i < numMsgs; i++ { + events := sdk.Events{} + for numEvents := 0; numEvents < maxIter; numEvents++ { + for j := 0; j < numEvents; j++ { + var attributes []sdk.Attribute + for numAttributes := 0; numAttributes < maxIter; numAttributes++ { + for i := 0; i < numAttributes; i++ { + key := "" + value := "" + if !tt.emptyKey { + key = fmt.Sprintf("key%d", i) + } + if !tt.emptyValue { + value = fmt.Sprintf("value%d", i) + } + attributes = append(attributes, sdk.NewAttribute(key, value)) + } + } + typeStr := "" + if !tt.emptyType { + typeStr = fmt.Sprintf("type%d", i) + } + events = append(events, sdk.NewEvent(typeStr, attributes...)) + } + } + + log := "" + if !tt.emptyLog { + log = fmt.Sprintf("log%d", i) + } + msgLogs = append(msgLogs, sdk.NewABCIMessageLog(uint32(i), log, events)) + } + } + bz, err := cdc.MarshalJSON(msgLogs) + + s.Require().NoError(err) + s.Require().Equal(string(bz), msgLogs.String()) + } } func (s *resultTestSuite) TestNewSearchTxsResult() {