Skip to content

Commit

Permalink
Merge pull request #5656 from filecoin-project/feat/state-search-repl…
Browse files Browse the repository at this point in the history
…aced

Show replacing message CID is state search-msg cli
  • Loading branch information
magik6k authored Feb 24, 2021
2 parents 55b85f3 + 6b8cbad commit 3c9e376
Showing 1 changed file with 47 additions and 33 deletions.
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

0 comments on commit 3c9e376

Please sign in to comment.