diff --git a/gql/resolver_mpool.go b/gql/resolver_mpool.go index 9860ffed0..7e2db36f8 100644 --- a/gql/resolver_mpool.go +++ b/gql/resolver_mpool.go @@ -4,17 +4,16 @@ import ( "bytes" "context" "encoding/json" - "errors" "fmt" + "reflect" "github.com/filecoin-project/lotus/chain/consensus" + cbg "github.com/whyrusleeping/cbor-gen" gqltypes "github.com/filecoin-project/boost/gql/types" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - stbig "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/chain/types" - "github.com/filecoin-project/specs-actors/actors/builtin/multisig" ) type msg struct { @@ -65,22 +64,24 @@ func (r *resolver) Mpool(ctx context.Context, args struct{ Local bool }) ([]*msg } } - method := m.Message.Method.String() + var params string + methodName := m.Message.Method.String() toact, err := r.fullNode.StateGetActor(ctx, m.Message.To, types.EmptyTSK) if err == nil { - method = consensus.NewActorRegistry().Methods[toact.Code][m.Message.Method].Name - } - - var params string - paramsMsg, err := messageFromBytes(m.Message.Params) - if err != nil { - params = err.Error() - } else { - paramsBytes, err := json.MarshalIndent(paramsMsg, "", " ") - if err != nil { - params = err.Error() - } else { - params = string(paramsBytes) + method, ok := consensus.NewActorRegistry().Methods[toact.Code][m.Message.Method] + if ok { + methodName = method.Name + + params = string(m.Message.Params) + p, ok := reflect.New(method.Params.Elem()).Interface().(cbg.CBORUnmarshaler) + if ok { + if err := p.UnmarshalCBOR(bytes.NewReader(m.Message.Params)); err == nil { + b, err := json.MarshalIndent(p, "", " ") + if err == nil { + params = string(b) + } + } + } } } @@ -92,7 +93,7 @@ func (r *resolver) Mpool(ctx context.Context, args struct{ Local bool }) ([]*msg GasFeeCap: gqltypes.BigInt{Int: m.Message.GasFeeCap}, GasLimit: gqltypes.Uint64(uint64(m.Message.GasLimit)), GasPremium: gqltypes.BigInt{Int: m.Message.GasPremium}, - Method: method, + Method: methodName, Params: params, BaseFee: gqltypes.BigInt{Int: baseFee}, }) @@ -101,83 +102,6 @@ func (r *resolver) Mpool(ctx context.Context, args struct{ Local bool }) ([]*msg return gqlmsgs, nil } -func messageFromBytes(msgb []byte) (types.ChainMsg, error) { - // Signed - { - var msg types.SignedMessage - if err := msg.UnmarshalCBOR(bytes.NewReader(msgb)); err == nil { - return &msg, nil - } - } - - // Unsigned - { - var msg types.Message - if err := msg.UnmarshalCBOR(bytes.NewReader(msgb)); err == nil { - return &msg, nil - } - } - - // Multisig propose? - { - var pp multisig.ProposeParams - if err := pp.UnmarshalCBOR(bytes.NewReader(msgb)); err == nil { - i, err := address.NewIDAddress(0) - if err != nil { - return nil, err - } - - return &types.Message{ - // Hack(-ish) - Version: 0x6d736967, - From: i, - - To: pp.To, - Value: pp.Value, - - Method: pp.Method, - Params: pp.Params, - - GasFeeCap: stbig.Zero(), - GasPremium: stbig.Zero(), - }, nil - } - } - - // Encoded json??? - { - if msg, err := messageFromJson(msgb); err == nil { - return msg, nil - } - } - - return nil, errors.New("probably not a cbor-serialized message") -} - -func messageFromJson(msgb []byte) (types.ChainMsg, error) { - // Unsigned - { - var msg types.Message - if err := json.Unmarshal(msgb, &msg); err == nil { - if msg.To != address.Undef { - return &msg, nil - } - } - } - - // Signed - { - var msg types.SignedMessage - if err := json.Unmarshal(msgb, &msg); err == nil { - if msg.Message.To != address.Undef { - return &msg, nil - } - } - } - - return nil, errors.New("probably not a json-serialized message") -} - func mockMessages() []*types.SignedMessage { to0, _ := address.NewFromString("f01469945") from0, _ := address.NewFromString("f3uakndzne4lorwykinlitx2d2puuhgburvxw4dpkfskeofmzg33pm7okyzikqe2gzvaqj2k3hpunwayij6haa") diff --git a/react/src/Mpool.css b/react/src/Mpool.css index 588ec5427..2a30e787e 100644 --- a/react/src/Mpool.css +++ b/react/src/Mpool.css @@ -117,4 +117,19 @@ left: 1.5em; border-left: 1px solid #000; height: 0.5em; +} + +.mpool .params{ + width: 1080px; + text-overflow: ellipsis; + cursor: pointer; + word-break: break-all; + overflow: hidden; + white-space: nowrap; +} + +.mpool .params:hover{ + overflow: visible; + white-space: normal; + width: auto; } \ No newline at end of file diff --git a/react/src/Mpool.js b/react/src/Mpool.js index 89950b346..c7b609afe 100644 --- a/react/src/Mpool.js +++ b/react/src/Mpool.js @@ -67,7 +67,9 @@ function MpoolMessage(props) { Params - {msg.Params} + +
{msg.Params}
+ Gas Fee Cap