Skip to content

Commit

Permalink
add output reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
ramtinms committed Sep 5, 2024
1 parent a91b40f commit c4f8095
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions cmd/util/cmd/link-reporter/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (
"github.com/spf13/cobra"

"github.com/onflow/flow-go/cmd/util/ledger/migrations"
"github.com/onflow/flow-go/cmd/util/ledger/reporters"
"github.com/onflow/flow-go/cmd/util/ledger/util"
"github.com/onflow/flow-go/cmd/util/ledger/util/registers"
"github.com/onflow/flow-go/ledger"
"github.com/onflow/flow-go/model/flow"
)

var (
flagOutputDirectory string
flagPayloads string
flagState string
flagStateCommitment string
Expand Down Expand Up @@ -48,6 +50,13 @@ func init() {
"Input state commitment",
)

Cmd.Flags().StringVar(
&flagOutputDirectory,
"output-directory",
"",
"Output directory",
)

Cmd.Flags().StringVar(
&flagChain,
"chain",
Expand All @@ -57,6 +66,13 @@ func init() {
_ = Cmd.MarkFlagRequired("chain")
}

type LinkDataPoint struct {
Address string `json:"address"`
Identifier string `json:"identifier"`
TargetPath string `json:"targetPath"`
LinkTypeID string `json:"linkType"`
}

func run(*cobra.Command, []string) {

if flagPayloads == "" && flagState == "" {
Expand All @@ -68,6 +84,10 @@ func run(*cobra.Command, []string) {
log.Fatal().Msg("--state-commitment must be provided when --state is provided")
}

reporter := reporters.NewReportFileWriterFactory(flagOutputDirectory, log.Logger)
writer := reporter.ReportWriter("link-reporter")
defer writer.Close()

chainID := flow.ChainID(flagChain)
// Validate chain ID
_ = chainID.Chain()
Expand Down Expand Up @@ -112,7 +132,7 @@ func run(*cobra.Command, []string) {

address := common.MustBytesToAddress([]byte(accountRegisters.Owner()))

log.Info().Msgf("account: %s", address)
// log.Info().Msgf("account: %s", address)

publicStorage := mr.Storage.GetStorageMap(
address,
Expand Down Expand Up @@ -142,7 +162,16 @@ func run(*cobra.Command, []string) {
targetPath := link.TargetPath
linkType := link.Type

log.Info().Msgf("%s: %s -> %s = %s", address, identifier, targetPath, linkType.ID())
linkTypeID := linkType.ID()

writer.Write(LinkDataPoint{
Address: address.String(),
Identifier: identifier,
TargetPath: targetPath.String(),
LinkTypeID: string(linkTypeID),
})

// log.Info().Msgf("%s: %s -> %s = %s", address, identifier, targetPath, linkType.ID())

case interpreter.AccountLinkValue:
// ignore
Expand Down

0 comments on commit c4f8095

Please sign in to comment.