Skip to content

Commit

Permalink
Merge pull request filecoin-project#4583 from filecoin-project/fix/tv…
Browse files Browse the repository at this point in the history
…x-msg-cid

tvx extract: make it work with secp messages.
  • Loading branch information
magik6k authored and bibibong committed Jan 7, 2021
1 parent c0f8799 commit 9f56823
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cmd/tvx/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"path/filepath"

"github.com/fatih/color"
"github.com/filecoin-project/go-address"

"github.com/EpiK-Protocol/go-epik/api"
"github.com/EpiK-Protocol/go-epik/chain/actors/builtin"
Expand Down Expand Up @@ -70,6 +71,11 @@ var extractCmd = &cli.Command{
Usage: "optionally, the block CID the message was included in, to avoid expensive chain scanning",
Destination: &extractFlags.block,
},
&cli.StringFlag{
Name: "exec-block",
Usage: "optionally, the block CID of a block where this message was executed, to avoid expensive chain scanning",
Destination: &extractFlags.block,
},
&cli.StringFlag{
Name: "cid",
Usage: "message CID to generate test vector from",
Expand Down Expand Up @@ -143,7 +149,7 @@ func doExtract(opts extractOpts) error {
return fmt.Errorf("failed to fetch messages in canonical order from inclusion tipset: %w", err)
}

related, found, err := findMsgAndPrecursors(opts.precursor, msg, msgs)
related, found, err := findMsgAndPrecursors(opts.precursor, mcid, msg.From, msgs)
if err != nil {
return fmt.Errorf("failed while finding message and precursors: %w", err)
}
Expand Down Expand Up @@ -496,19 +502,19 @@ func fetchThisAndPrevTipset(ctx context.Context, api api.FullNode, target types.
// findMsgAndPrecursors ranges through the canonical messages slice, locating
// the target message and returning precursors in accordance to the supplied
// mode.
func findMsgAndPrecursors(mode string, target *types.Message, msgs []api.Message) (related []*types.Message, found bool, err error) {
func findMsgAndPrecursors(mode string, msgCid cid.Cid, sender address.Address, msgs []api.Message) (related []*types.Message, found bool, err error) {
// Range through canonicalised messages, selecting only the precursors based
// on selection mode.
for _, other := range msgs {
switch {
case mode == PrecursorSelectAll:
fallthrough
case mode == PrecursorSelectSender && other.Message.From == target.From:
case mode == PrecursorSelectSender && other.Message.From == sender:
related = append(related, other.Message)
}

// this message is the target; we're done.
if other.Cid == target.Cid() {
if other.Cid == msgCid {
return related, true, nil
}
}
Expand Down

0 comments on commit 9f56823

Please sign in to comment.