From 0b687b0053866e25ca741716612b39972aee1640 Mon Sep 17 00:00:00 2001 From: Susanoo <40375298+diwufeiwen@users.noreply.github.com> Date: Tue, 4 Jan 2022 17:47:42 +0800 Subject: [PATCH] Unify the definition of MessageReceipt (#4667) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 一页素书 <2931107265@qq.com> --- cmd/show_test.go | 8 ++++---- cmd/state.go | 2 +- pkg/types/internal/cbor_gen.go | 18 +++++++++--------- pkg/types/internal/message.go | 6 +++--- pkg/types/internal/testing_messages.go | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cmd/show_test.go b/cmd/show_test.go index e4f82f5ad3..d3e8ff1d74 100644 --- a/cmd/show_test.go +++ b/cmd/show_test.go @@ -24,10 +24,10 @@ import ( // Receipt is what is returned by executing a message on the vm. type Receipt struct { // control field for encoding struct as an array - _ struct{} `cbor:",toarray"` - ExitCode int64 `json:"exitCode"` - ReturnValue []byte `json:"return"` - GasUsed int64 `json:"gasUsed"` + _ struct{} `cbor:",toarray"` + ExitCode int64 `json:"exitCode"` + Return []byte `json:"return"` + GasUsed int64 `json:"gasUsed"` } func TestBlockDaemon(t *testing.T) { diff --git a/cmd/state.go b/cmd/state.go index 5bf26c5b19..9f5a2cc4c5 100644 --- a/cmd/state.go +++ b/cmd/state.go @@ -82,7 +82,7 @@ var stateWaitMsgCmd = &cmds.Command{ writer.Printf("message was executed in tipset: %s\n", mw.TipSet.Cids()) writer.Printf("Exit Code: %d\n", mw.Receipt.ExitCode) writer.Printf("Gas Used: %d\n", mw.Receipt.GasUsed) - writer.Printf("Return: %x\n", mw.Receipt.ReturnValue) + writer.Printf("Return: %x\n", mw.Receipt.Return) } else { writer.Printf("Unable to find message recepit of %s", cid) } diff --git a/pkg/types/internal/cbor_gen.go b/pkg/types/internal/cbor_gen.go index 822fc36726..c2cb312b5d 100644 --- a/pkg/types/internal/cbor_gen.go +++ b/pkg/types/internal/cbor_gen.go @@ -44,16 +44,16 @@ func (t *MessageReceipt) MarshalCBOR(w io.Writer) error { } } - // t.ReturnValue ([]uint8) (slice) - if len(t.ReturnValue) > cbg.ByteArrayMaxLen { - return xerrors.Errorf("Byte array in field t.ReturnValue was too long") + // t.Return ([]uint8) (slice) + if len(t.Return) > cbg.ByteArrayMaxLen { + return xerrors.Errorf("Byte array in field t.Return was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.ReturnValue))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Return))); err != nil { return err } - if _, err := w.Write(t.ReturnValue[:]); err != nil { + if _, err := w.Write(t.Return[:]); err != nil { return err } @@ -113,7 +113,7 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error { t.ExitCode = exitcode.ExitCode(extraI) } - // t.ReturnValue ([]uint8) (slice) + // t.Return ([]uint8) (slice) maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { @@ -121,17 +121,17 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error { } if extra > cbg.ByteArrayMaxLen { - return fmt.Errorf("t.ReturnValue: byte array too large (%d)", extra) + return fmt.Errorf("t.Return: byte array too large (%d)", extra) } if maj != cbg.MajByteString { return fmt.Errorf("expected byte array") } if extra > 0 { - t.ReturnValue = make([]uint8, extra) + t.Return = make([]uint8, extra) } - if _, err := io.ReadFull(br, t.ReturnValue[:]); err != nil { + if _, err := io.ReadFull(br, t.Return[:]); err != nil { return err } // t.GasUsed (int64) (int64) diff --git a/pkg/types/internal/message.go b/pkg/types/internal/message.go index 4b889707ae..4a047d7b4f 100644 --- a/pkg/types/internal/message.go +++ b/pkg/types/internal/message.go @@ -350,9 +350,9 @@ func (m *TxMeta) ToStorageBlock() (block.Block, error) { // MessageReceipt is what is returned by executing a message on the vm. type MessageReceipt struct { - ExitCode exitcode.ExitCode `json:"exitCode"` - ReturnValue []byte `json:"return"` - GasUsed int64 `json:"gasUsed"` + ExitCode exitcode.ExitCode `json:"exitCode"` + Return []byte `json:"return"` + GasUsed int64 `json:"gasUsed"` } func (r *MessageReceipt) String() string { diff --git a/pkg/types/internal/testing_messages.go b/pkg/types/internal/testing_messages.go index b4209244c1..57f470a57e 100644 --- a/pkg/types/internal/testing_messages.go +++ b/pkg/types/internal/testing_messages.go @@ -97,6 +97,6 @@ func (rm *ReceiptMaker) NewReceipt() MessageReceipt { seq := rm.seq rm.seq++ return MessageReceipt{ - ReturnValue: []byte(fmt.Sprintf("%d", seq)), + Return: []byte(fmt.Sprintf("%d", seq)), } }