-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
parse transactions
cmd (#59)
## Description ## Checklist - [x] Targeted PR against correct branch. - [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [ ] Wrote unit tests. - [x] Re-reviewed `Files changed` in the Github PR explorer.
- Loading branch information
Showing
8 changed files
with
137 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package transactions | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" | ||
) | ||
|
||
// NewTransactionsCmd returns the Cobra command that allows to fix missing or incomplete transactions | ||
func NewTransactionsCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "transactions", | ||
Short: "Parse things related to transactions", | ||
} | ||
|
||
cmd.AddCommand( | ||
newTransactionsCmd(parseConfig), | ||
) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package transactions | ||
|
||
import ( | ||
"fmt" | ||
|
||
parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" | ||
|
||
"github.com/rs/zerolog/log" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/forbole/juno/v3/parser" | ||
"github.com/forbole/juno/v3/types/config" | ||
) | ||
|
||
const ( | ||
flagStart = "start" | ||
flagEnd = "end" | ||
) | ||
|
||
// newTransactionsCmd returns a Cobra command that allows to fix missing or incomplete transactions in database | ||
func newTransactionsCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "all", | ||
Short: "Parse missing or incomplete transactions", | ||
Long: fmt.Sprintf(`Refetch missing or incomplete transactions and store them inside the database. | ||
You can specify a custom height range by using the %s and %s flags. | ||
`, flagStart, flagEnd), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
workerCtx := parser.NewContext(parseCtx.EncodingConfig, parseCtx.Node, parseCtx.Database, parseCtx.Logger, parseCtx.Modules) | ||
worker := parser.NewWorker(workerCtx, nil, 0) | ||
|
||
// Get the flag values | ||
start, _ := cmd.Flags().GetInt64(flagStart) | ||
end, _ := cmd.Flags().GetInt64(flagEnd) | ||
|
||
// Get the start height, default to the config's height; use flagStart if set | ||
startHeight := config.Cfg.Parser.StartHeight | ||
if start > 0 { | ||
startHeight = start | ||
} | ||
|
||
// Get the end height, default to the node latest height; use flagEnd if set | ||
endHeight, err := parseCtx.Node.LatestHeight() | ||
if err != nil { | ||
return fmt.Errorf("error while getting chain latest block height: %s", err) | ||
} | ||
if end > 0 { | ||
endHeight = end | ||
} | ||
|
||
log.Info().Int64("start height", startHeight).Int64("end height", endHeight). | ||
Msg("getting transactions...") | ||
for k := startHeight; k <= endHeight; k++ { | ||
log.Info().Int64("height", k).Msg("processing transactions...") | ||
err = worker.ProcessTransactions(k) | ||
if err != nil { | ||
return fmt.Errorf("error while re-fetching transactions of height %d: %s", k, err) | ||
} | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().Int64(flagStart, 0, "Height from which to start fetching missing transactions. If 0, the start height inside the config file will be used instead") | ||
cmd.Flags().Int64(flagEnd, 0, "Height at which to finish fetching missing transactions. If 0, the latest height available inside the node will be used instead") | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters