Skip to content

Commit

Permalink
enable target acc checking (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
jingweicb committed Dec 8, 2023
1 parent f89aae3 commit ae92cd6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ jobs:
go-version: ${{ env.go_version }}
- run: make test-cover COVERALLS_TOKEN="$COVERALLS_TOKEN"

Salus:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
version: latest
- run: make salus
# Salus:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# with:
# version: latest
# - run: make salus


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
40 changes: 39 additions & 1 deletion 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,14 @@ func InitializeData(
color.Red(err.Error())
return nil, err
}
if len(config.TargetAccount) != 0 {
interestingAccounts = loadAccount(config.TargetAccount)
}

interestingOnly := false
if len(interestingAccounts) != 0 {
interestingOnly = true
}

counterStorage := modules.NewCounterStorage(localStore)
blockStorage := modules.NewBlockStorage(localStore, config.SerialBlockWorkers)
Expand Down Expand Up @@ -357,11 +389,17 @@ func InitializeData(
counterStorage,
historicalBalanceEnabled,
exemptAccounts,
false,
interestingOnly,
networkOptions.Allow.BalanceExemptions,
config.Data.InitialBalanceFetchDisabled,
)

if interestingOnly {
for _, interesinterestingAccount := range interestingAccounts {
balanceStorageHelper.AddInterestingAddress(interesinterestingAccount.Account.Address)
}
}

balanceStorageHandler := processor.NewBalanceStorageHandler(
logger,
r,
Expand Down

0 comments on commit ae92cd6

Please sign in to comment.