Skip to content

Commit

Permalink
enable target acc checking
Browse files Browse the repository at this point in the history
  • Loading branch information
jingweicb committed Nov 22, 2023
1 parent f89aae3 commit 505b697
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var (
requestUUID string
statusPort uint
InfoMetaData string
targetAccount string

// Config is the populated *configuration.Configuration from
// the configurationFile. If none is provided, this is set
Expand Down Expand Up @@ -246,6 +247,13 @@ default values.`,
"Override online node url in configuration file",
)

checkDataCmd.Flags().StringVar(
&targetAccount,
"target-account",
"",
"Override target account in configuration file",
)

checkDataCmd.Flags().Int64Var(
&startIndex,
"start-block",
Expand Down Expand Up @@ -425,6 +433,10 @@ func initConfig() {
Config.Construction.OfflineURL = offlineURL
}

if len(targetAccount) != 0 {
Config.TargetAccount = targetAccount
}

// Override start and end syncing index in configuration file when it's explicitly set via CLI
if startIndex != -1 {
Config.Data.StartIndex = &startIndex
Expand Down
3 changes: 3 additions & 0 deletions configuration/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ type Configuration struct {
// OnlineURL is the URL of a Rosetta API implementation in "online mode".
OnlineURL string `json:"online_url"`

// TargetAccount will be the only interest account
TargetAccount string `json:"target_account,omitempty"`

// DataDirectory is a folder used to store logs and any data used to perform validation.
// The path can be absolute, or it can be relative to where rosetta-cli
// binary is being executed.
Expand Down
27 changes: 27 additions & 0 deletions pkg/tester/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,30 @@ func loadAccounts(filePath string) ([]*types.AccountCurrency, error) {
return accounts, nil
}

// loadAccount is a utility function to parse the []*types.AccountCurrency
// from a string.
func loadAccount(accountAddress string) []*types.AccountCurrency {
if len(accountAddress) == 0 {
return []*types.AccountCurrency{}
}

accounts := []*types.AccountCurrency{}
accountIndentifier := &types.AccountIdentifier{
Address: accountAddress,
// You can set other fields of AccountIdentifier here if needed.
}

// Create an AccountCurrency instance with the Account field set to the created AccountIdentifier.
targetAccount := &types.AccountCurrency{
Account: accountIndentifier,
// You can set other fields of AccountCurrency here if needed.
}

accounts = append(accounts, targetAccount)

return accounts
}

// CloseDatabase closes the database used by DataTester.
func (t *DataTester) CloseDatabase(ctx context.Context) {
if err := t.database.Close(ctx); err != nil {
Expand Down Expand Up @@ -249,6 +273,9 @@ func InitializeData(
color.Red(err.Error())
return nil, err
}
if len(config.TargetAccount) != 0 {
interestingAccounts = loadAccount(config.TargetAccount)
}

counterStorage := modules.NewCounterStorage(localStore)
blockStorage := modules.NewBlockStorage(localStore, config.SerialBlockWorkers)
Expand Down

0 comments on commit 505b697

Please sign in to comment.