From 6a10af626c77d083119a00c20dc482376916cccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 9 Oct 2020 01:50:33 +0200 Subject: [PATCH] Nicer message logging in lotus-wallet --- cmd/lotus-wallet/logged.go | 33 ++++++++++++++++++++++++++++++++- node/impl/full/wallet.go | 2 +- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/cmd/lotus-wallet/logged.go b/cmd/lotus-wallet/logged.go index c713c2e87..d3630c241 100644 --- a/cmd/lotus-wallet/logged.go +++ b/cmd/lotus-wallet/logged.go @@ -1,7 +1,11 @@ package main import ( + "bytes" "context" + "encoding/hex" + "github.com/ipfs/go-cid" + "golang.org/x/xerrors" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/crypto" @@ -38,7 +42,34 @@ func (c *LoggedWallet) WalletList(ctx context.Context) ([]address.Address, error } func (c *LoggedWallet) WalletSign(ctx context.Context, k address.Address, msg []byte, meta api.MsgMeta) (*crypto.Signature, error) { - log.Infow("WalletSign", "address", k) + switch meta.Type { + case api.MTChainMsg: + var cmsg types.Message + if err := cmsg.UnmarshalCBOR(bytes.NewReader(meta.Extra)); err != nil { + return nil, xerrors.Errorf("unmarshalling message: %w", err) + } + + _, bc, err := cid.CidFromBytes(msg) + if err != nil { + return nil, xerrors.Errorf("getting cid from signing bytes: %w", err) + } + + if !cmsg.Cid().Equals(bc) { + return nil, xerrors.Errorf("cid(meta.Extra).bytes() != msg") + } + + log.Infow("WalletSign", + "address", k, + "type", meta.Type, + "from", cmsg.From, + "to", cmsg.To, + "value", types.FIL(cmsg.Value), + "feecap", types.FIL(cmsg.RequiredFunds()), + "method", cmsg.Method, + "params", hex.EncodeToString(cmsg.Params)) + default: + log.Infow("WalletSign", "address", k, "type", meta.Type) + } return c.under.WalletSign(ctx, k, msg, meta) } diff --git a/node/impl/full/wallet.go b/node/impl/full/wallet.go index 3bbb6556d..1a32cd422 100644 --- a/node/impl/full/wallet.go +++ b/node/impl/full/wallet.go @@ -41,7 +41,7 @@ func (a *WalletAPI) WalletSign(ctx context.Context, k address.Address, msg []byt return nil, xerrors.Errorf("failed to resolve ID address: %w", keyAddr) } return a.WalletAPI.WalletSign(ctx, keyAddr, msg, api.MsgMeta{ - Type: api.MTUnknown, + Type: api.MTUnknown, }) }