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

Show replacing message CID is state search-msg cli #5656

Merged
merged 1 commit into from
Feb 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 47 additions & 33 deletions cli/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1403,34 +1403,10 @@ var stateWaitMsgCmd = &cli.Command{
return err
}

fmt.Printf("message was executed in tipset: %s\n", mw.TipSet.Cids())
fmt.Printf("Exit Code: %d\n", mw.Receipt.ExitCode)
fmt.Printf("Gas Used: %d\n", mw.Receipt.GasUsed)
fmt.Printf("Return: %x\n", mw.Receipt.Return)
if err := printReceiptReturn(ctx, api, m, mw.Receipt); err != nil {
return err
}

return nil
return printMsg(ctx, api, msg, mw, m)
},
}

func printReceiptReturn(ctx context.Context, api api.FullNode, m *types.Message, r types.MessageReceipt) error {
act, err := api.StateGetActor(ctx, m.To, types.EmptyTSK)
if err != nil {
return err
}

jret, err := jsonReturn(act.Code, m.Method, r.Return)
if err != nil {
return err
}

fmt.Println(jret)

return nil
}

var stateSearchMsgCmd = &cli.Command{
Name: "search-msg",
Usage: "Search to see whether a message has appeared on chain",
Expand Down Expand Up @@ -1458,18 +1434,56 @@ var stateSearchMsgCmd = &cli.Command{
return err
}

if mw != nil {
fmt.Printf("message was executed in tipset: %s", mw.TipSet.Cids())
fmt.Printf("\nExit Code: %d", mw.Receipt.ExitCode)
fmt.Printf("\nGas Used: %d", mw.Receipt.GasUsed)
fmt.Printf("\nReturn: %x", mw.Receipt.Return)
} else {
fmt.Print("message was not found on chain")
m, err := api.ChainGetMessage(ctx, msg)
if err != nil {
return err
}
return nil

return printMsg(ctx, api, msg, mw, m)
},
}

func printReceiptReturn(ctx context.Context, api api.FullNode, m *types.Message, r types.MessageReceipt) error {
if len(r.Return) == 0 {
return nil
}

act, err := api.StateGetActor(ctx, m.To, types.EmptyTSK)
if err != nil {
return err
}

jret, err := jsonReturn(act.Code, m.Method, r.Return)
if err != nil {
return err
}

fmt.Println("Decoded return value: ", jret)

return nil
}

func printMsg(ctx context.Context, api api.FullNode, msg cid.Cid, mw *lapi.MsgLookup, m *types.Message) error {
if mw != nil {
if mw.Message != msg {
fmt.Printf("Message was replaced: %s\n", mw.Message)
}

fmt.Printf("Executed in tipset: %s\n", mw.TipSet.Cids())
fmt.Printf("Exit Code: %d\n", mw.Receipt.ExitCode)
fmt.Printf("Gas Used: %d\n", mw.Receipt.GasUsed)
fmt.Printf("Return: %x\n", mw.Receipt.Return)
} else {
fmt.Println("message was not found on chain")
}

if err := printReceiptReturn(ctx, api, m, mw.Receipt); err != nil {
return err
}

return nil
}

var stateCallCmd = &cli.Command{
Name: "call",
Usage: "Invoke a method on an actor locally",
Expand Down