Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: align forest-cli chain message output with lotus #3709

Merged
merged 1 commit into from
Nov 10, 2023

Conversation

hanabi1224
Copy link
Contributor

@hanabi1224 hanabi1224 commented Nov 10, 2023

Summary of changes

As part of #3639

Lotus uses ChainReadObj API to print full signed message in lotus chain getmessage [CID] output, this PR tries to match it in forest-cli chain message -c [CID].

Note: The output still slightly differs, forest-cli prints SignatureType in string format while lotus prints it in Integer format, which has been addressed by #3698

Changes introduced in this pull request:

  • align forest-cli chain message output with lotus

forest-cli chain message -c bafy2bzacedpkf2v5kgm4mvvljer6q3s45yfcdzaiyl3xdoivt5m53iv77v76w output

{
  "Message": {
    "Version": 0,
    "To": "t410famf46pkqzlieylsxhenre5ajqkutbbrb652rziy",
    "From": "t410fot3vkzzorqg4alowvghvxx4mhofhtazixbm6z2i",
    "Nonce": 26944,
    "Value": "0",
    "GasLimit": 33780427,
    "GasFeeCap": "201100",
    "GasPremium": "200900",
    "Method": 3844450837,
    "Params": "WMTq9dBOAAAAAAAAAAAAAAAAdPdVZy6MDcAt1qmPW9+MO4p5gygAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC91cGRhdGUgaGVhbHRoYm90XzMxNDE1OV81IHNldCBjb3VudGVyPWNvdW50ZXIrMQAAAAAAAAAAAAAAAAAAAAAA",
    "CID": {
      "/": "bafy2bzaceb2wxksv3na5ziqyay2wemn7tuigp2i4tvudg3jvsuzmdmvcivmzy"
    }
  },
  "Signature": {
    "Type": "delegated",
    "Data": "m4Fj5Bw0AGkLYj7XMnVDx6HHjFihzYpJ1bGOwQLee4kkQ4OcMhUsyigHLUldQ23l81+wgG0KVypQQciAznT7+wE="
  },
  "CID": {
    "/": "bafy2bzacedpkf2v5kgm4mvvljer6q3s45yfcdzaiyl3xdoivt5m53iv77v76w"
  }
}

lotus chain getmessage bafy2bzacedpkf2v5kgm4mvvljer6q3s45yfcdzaiyl3xdoivt5m53iv77v76w output:

{
  "Message": {
    "Version": 0,
    "To": "t410famf46pkqzlieylsxhenre5ajqkutbbrb652rziy",
    "From": "t410fot3vkzzorqg4alowvghvxx4mhofhtazixbm6z2i",
    "Nonce": 26944,
    "Value": "0",
    "GasLimit": 33780427,
    "GasFeeCap": "201100",
    "GasPremium": "200900",
    "Method": 3844450837,
    "Params": "WMTq9dBOAAAAAAAAAAAAAAAAdPdVZy6MDcAt1qmPW9+MO4p5gygAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC91cGRhdGUgaGVhbHRoYm90XzMxNDE1OV81IHNldCBjb3VudGVyPWNvdW50ZXIrMQAAAAAAAAAAAAAAAAAAAAAA",
    "CID": {
      "/": "bafy2bzaceb2wxksv3na5ziqyay2wemn7tuigp2i4tvudg3jvsuzmdmvcivmzy"
    }
  },
  "Signature": {
    "Type": 3,
    "Data": "m4Fj5Bw0AGkLYj7XMnVDx6HHjFihzYpJ1bGOwQLee4kkQ4OcMhUsyigHLUldQ23l81+wgG0KVypQQciAznT7+wE="
  },
  "CID": {
    "/": "bafy2bzacedpkf2v5kgm4mvvljer6q3s45yfcdzaiyl3xdoivt5m53iv77v76w"
  }
}

lotus code:

var ChainGetMsgCmd = &cli.Command{
	Name:      "getmessage",
	Aliases:   []string{"get-message", "get-msg"},
	Usage:     "Get and print a message by its cid",
	ArgsUsage: "[messageCid]",
	Action: func(cctx *cli.Context) error {
		afmt := NewAppFmt(cctx.App)

		if cctx.NArg() != 1 {
			return IncorrectNumArgs(cctx)
		}

		api, closer, err := GetFullNodeAPI(cctx)
		if err != nil {
			return err
		}
		defer closer()
		ctx := ReqContext(cctx)

		c, err := cid.Decode(cctx.Args().First())
		if err != nil {
			return xerrors.Errorf("failed to parse cid input: %w", err)
		}

		mb, err := api.ChainReadObj(ctx, c)
		if err != nil {
			return xerrors.Errorf("failed to read object: %w", err)
		}

		var i interface{}
		m, err := types.DecodeMessage(mb)
		if err != nil {
			sm, err := types.DecodeSignedMessage(mb)
			if err != nil {
				return xerrors.Errorf("failed to decode object as a message: %w", err)
			}
			i = sm
		} else {
			i = m
		}

		enc, err := json.MarshalIndent(i, "", "  ")
		if err != nil {
			return err
		}

		afmt.Println(string(enc))
		return nil
	},
}

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

@hanabi1224 hanabi1224 marked this pull request as ready for review November 10, 2023 10:25
@hanabi1224 hanabi1224 requested a review from a team as a code owner November 10, 2023 10:25
@hanabi1224 hanabi1224 requested review from lemmih and LesnyRumcajs and removed request for a team November 10, 2023 10:25
@hanabi1224 hanabi1224 added this pull request to the merge queue Nov 10, 2023
Merged via the queue into main with commit 7286a85 Nov 10, 2023
@hanabi1224 hanabi1224 deleted the hm/fix-cli-chain-message branch November 10, 2023 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants