Skip to content

Commit

Permalink
fix msg detail marshal
Browse files Browse the repository at this point in the history
  • Loading branch information
hunjixin committed Jan 13, 2022
1 parent b0d1d14 commit 36c9939
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 13 deletions.
26 changes: 13 additions & 13 deletions cli/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,25 +367,25 @@ var tw = tablewriter.New(
func outputWithTable(msgs []*types.Message, verbose bool) error {
for _, msgT := range msgs {
msg := transformMessage(msgT)
val := venusTypes.MustParseFIL(msg.Message.Value.String() + "attofil").String()
val := venusTypes.MustParseFIL(msg.Msg.Value.String() + "attofil").String()
row := map[string]interface{}{
"ID": msg.ID,
"To": msg.Message.To,
"From": msg.Message.From,
"Nonce": msg.Message.Nonce,
"To": msg.Msg.To,
"From": msg.Msg.From,
"Nonce": msg.Msg.Nonce,
"Value": val,
"GasLimit": msg.Message.GasLimit,
"GasFeeCap": msg.Message.GasFeeCap,
"GasPremium": msg.Message.GasPremium,
"Method": msg.Message.Method,
"GasLimit": msg.Msg.GasLimit,
"GasFeeCap": msg.Msg.GasFeeCap,
"GasPremium": msg.Msg.GasPremium,
"Method": msg.Msg.Method,
"State": msg.State,
"CreateAt": msg.CreatedAt.Format("2006-01-02 15:04:05"),
}
if !verbose {
if from := msg.Message.From.String(); len(from) > 9 {
if from := msg.Msg.From.String(); len(from) > 9 {
row["From"] = from[:9] + "..."
}
if to := msg.Message.To.String(); len(to) > 9 {
if to := msg.Msg.To.String(); len(to) > 9 {
row["To"] = to[:9] + "..."
}
if len(msg.ID) > 36 {
Expand Down Expand Up @@ -716,8 +716,8 @@ type message struct {

UnsignedCid *cid.Cid
SignedCid *cid.Cid
venusTypes.Message
Signature *crypto.Signature
Msg venusTypes.Message
Signature *crypto.Signature

Height int64
Confidence int64
Expand Down Expand Up @@ -750,7 +750,7 @@ func transformMessage(msg *types.Message) *message {
ID: msg.ID,
UnsignedCid: msg.UnsignedCid,
SignedCid: msg.SignedCid,
Message: msg.Message,
Msg: msg.Message,
Signature: msg.Signature,
Height: msg.Height,
Confidence: msg.Confidence,
Expand Down
67 changes: 67 additions & 0 deletions types/msg.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
"encoding/json"
"github.com/filecoin-project/go-address"
"time"

"github.com/filecoin-project/go-state-types/abi"
Expand Down Expand Up @@ -56,6 +58,71 @@ type Message struct {
UpdatedAt time.Time
}

//todo ignore use message MarshalJSON method
func (m *Message) MarshalJSON() ([]byte, error) {
type msg struct {
Version uint64
To address.Address
From address.Address
Nonce uint64
Value abi.TokenAmount
GasLimit int64
GasFeeCap abi.TokenAmount
GasPremium abi.TokenAmount
Method abi.MethodNum
Params []byte
}
type fMsg struct {
ID string

UnsignedCid *cid.Cid
SignedCid *cid.Cid
msg
Signature *crypto.Signature

Height int64
Confidence int64
Receipt *venusTypes.MessageReceipt
TipSetKey venusTypes.TipSetKey
Meta *MsgMeta
WalletName string
FromUser string

State MessageState

CreatedAt time.Time
UpdatedAt time.Time
}
return json.Marshal(fMsg{
ID: m.ID,
UnsignedCid: m.UnsignedCid,
SignedCid: m.SignedCid,
msg: msg{
Version: m.Message.Version,
To: m.Message.To,
From: m.Message.From,
Nonce: m.Message.Nonce,
Value: m.Message.Value,
GasLimit: m.Message.GasLimit,
GasFeeCap: m.Message.GasFeeCap,
GasPremium: m.Message.GasPremium,
Method: m.Message.Method,
Params: m.Message.Params,
},
Signature: m.Signature,
Height: m.Height,
Confidence: m.Confidence,
Receipt: m.Receipt,
TipSetKey: m.TipSetKey,
Meta: m.Meta,
WalletName: m.WalletName,
FromUser: m.FromUser,
State: m.State,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
})
}

func FromUnsignedMessage(unsignedMsg venusTypes.Message) *Message {
return &Message{
Message: unsignedMsg,
Expand Down

0 comments on commit 36c9939

Please sign in to comment.