lotus/cmd/lotus-wallet/logged.go

90 lines
2.3 KiB
Go
Raw Normal View History

2020-09-05 19:36:32 +00:00
package main
import (
2020-10-08 23:50:33 +00:00
"bytes"
2020-09-05 19:36:32 +00:00
"context"
2020-10-08 23:50:33 +00:00
"encoding/hex"
2020-10-08 23:50:33 +00:00
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
2020-09-05 19:36:32 +00:00
"github.com/filecoin-project/go-address"
2020-10-08 22:51:04 +00:00
"github.com/filecoin-project/go-state-types/crypto"
2020-09-05 19:36:32 +00:00
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/types"
)
type LoggedWallet struct {
under api.Wallet
2020-09-05 19:36:32 +00:00
}
func (c *LoggedWallet) WalletNew(ctx context.Context, typ types.KeyType) (address.Address, error) {
log.Infow("WalletNew", "type", typ)
2020-09-05 19:36:32 +00:00
return c.under.WalletNew(ctx, typ)
}
func (c *LoggedWallet) WalletHas(ctx context.Context, addr address.Address) (bool, error) {
log.Infow("WalletHas", "address", addr)
return c.under.WalletHas(ctx, addr)
}
func (c *LoggedWallet) WalletList(ctx context.Context) ([]address.Address, error) {
log.Infow("WalletList")
return c.under.WalletList(ctx)
}
func (c *LoggedWallet) WalletSign(ctx context.Context, k address.Address, msg []byte, meta api.MsgMeta) (*crypto.Signature, error) {
2020-10-08 23:50:33 +00:00
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)
}
2020-09-05 19:36:32 +00:00
return c.under.WalletSign(ctx, k, msg, meta)
2020-09-05 19:36:32 +00:00
}
func (c *LoggedWallet) WalletExport(ctx context.Context, a address.Address) (*types.KeyInfo, error) {
log.Infow("WalletExport", "address", a)
return c.under.WalletExport(ctx, a)
}
func (c *LoggedWallet) WalletImport(ctx context.Context, ki *types.KeyInfo) (address.Address, error) {
log.Infow("WalletImport", "type", ki.Type)
return c.under.WalletImport(ctx, ki)
}
func (c *LoggedWallet) WalletDelete(ctx context.Context, addr address.Address) error {
log.Infow("WalletDelete", "address", addr)
return c.under.WalletDelete(ctx, addr)
2020-10-08 23:27:49 +00:00
}