Skip to content

Commit

Permalink
stellar#4222: cleanup go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sreuland committed Feb 25, 2022
1 parent 4ba3775 commit 7804c74
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
10 changes: 5 additions & 5 deletions services/horizon/internal/ingest/filters/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type accountFilter struct {

type AccountFilter interface {
processors.LedgerTransactionFilterer
RefreshAccountFilter(filterConfig *history.FilterConfig) (error)
RefreshAccountFilter(filterConfig *history.FilterConfig) error
}

func NewAccountFilter() AccountFilter {
Expand All @@ -31,18 +31,18 @@ func NewAccountFilter() AccountFilter {
}

// TODO:(fons) this code should probably be generic for all filters
func (filter *accountFilter) RefreshAccountFilter(filterConfig *history.FilterConfig) (error) {
func (filter *accountFilter) RefreshAccountFilter(filterConfig *history.FilterConfig) error {
// only need to re-initialize the filter config state(rules) if it's cached version(in memory)
// is older than the incoming config version based on lastModified epoch timestamp
if filterConfig.LastModified > filter.lastModified {
var assetFilterRules AssetFilterRules
if err := json.Unmarshal([]byte(filterConfig.Rules), &assetFilterRules); err != nil {
return errors.Wrap(err, "unable to serialize asset filter rules")
}

filter.whitelistedAccountsSet = listToMap(assetFilterRules.CanonicalWhitelist)
filter.lastModified = filterConfig.LastModified
filter.lastModified = filterConfig.LastModified

}

return nil
Expand Down
8 changes: 4 additions & 4 deletions services/horizon/internal/ingest/filters/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type assetFilter struct {

type AssetFilter interface {
processors.LedgerTransactionFilterer
RefreshAssetFilter(filterConfig *history.FilterConfig) (error)
RefreshAssetFilter(filterConfig *history.FilterConfig) error
}

func NewAssetFilter() AssetFilter {
Expand All @@ -39,17 +39,17 @@ func NewAssetFilter() AssetFilter {
}
}

func (filter *assetFilter) RefreshAssetFilter(filterConfig *history.FilterConfig) (error) {
func (filter *assetFilter) RefreshAssetFilter(filterConfig *history.FilterConfig) error {
// only need to re-initialize the filter config state(rules) if it's cached version(in memory)
// is older than the incoming config version based on lastModified epoch timestamp
if filterConfig.LastModified > filter.lastModified {
var assetFilterRules AssetFilterRules
if err := json.Unmarshal([]byte(filterConfig.Rules), &assetFilterRules); err != nil {
return errors.Wrap(err, "unable to serialize asset filter rules")
}

filter.canonicalAssetsLookup = listToMap(assetFilterRules.CanonicalWhitelist)
filter.lastModified = filterConfig.LastModified
filter.lastModified = filterConfig.LastModified
}

return nil
Expand Down
28 changes: 14 additions & 14 deletions services/horizon/internal/ingest/filters/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ const (
)

var (
supportedFilterNames = []string{FilterAssetFilterName, FilterAccountFilterName}
LOG = log.WithFields(log.F{
supportedFilterNames = []string{FilterAssetFilterName, FilterAccountFilterName}
LOG = log.WithFields(log.F{
"filters": "load",
})
)

type filtersCache struct {
cachedFilters map[string]processors.LedgerTransactionFilterer
cachedFilters map[string]processors.LedgerTransactionFilterer
lastFilterConfigCheckUnixEpoch int64
}

type Filters interface {
GetFilters(filterQ history.QFilter, ctx context.Context) []processors.LedgerTransactionFilterer
GetFilters(filterQ history.QFilter, ctx context.Context) []processors.LedgerTransactionFilterer
}

func NewFilters() Filters {
return &filtersCache{
cachedFilters: map[string]processors.LedgerTransactionFilterer{
FilterAssetFilterName: NewAccountFilter(),
FilterAccountFilterName: NewAssetFilter(),
},
}
return &filtersCache{
cachedFilters: map[string]processors.LedgerTransactionFilterer{
FilterAssetFilterName: NewAccountFilter(),
FilterAccountFilterName: NewAssetFilter(),
},
}
}

// Provide list of the active filters. Optimize performance by caching the list, only
Expand Down Expand Up @@ -93,8 +93,8 @@ func SupportedFilterNames(name string) bool {

func (f *filtersCache) convertCacheToList() []processors.LedgerTransactionFilterer {
filters := []processors.LedgerTransactionFilterer{}
for _, filter := range f.cachedFilters {
filters = append(filters, filter)
}
return filters
for _, filter := range f.cachedFilters {
filters = append(filters, filter)
}
return filters
}
2 changes: 1 addition & 1 deletion services/horizon/internal/ingest/mock_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ type mockFilters struct {
func (m *mockFilters) GetFilters(filterQ history.QFilter, ctx context.Context) []processors.LedgerTransactionFilterer {
a := m.Called(filterQ, ctx)
return a.Get(0).([]processors.LedgerTransactionFilterer)
}
}
14 changes: 7 additions & 7 deletions services/horizon/internal/ingest/processor_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestProcessorRunnerRunHistoryArchiveIngestionGenesis(t *testing.T) {
NetworkPassphrase: network.PublicNetworkPassphrase,
},
historyQ: q,
filters: &mockFilters{},
filters: &mockFilters{},
}

_, err := runner.RunGenesisStateIngestion()
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestProcessorRunnerRunHistoryArchiveIngestionHistoryArchive(t *testing.T) {
config: config,
historyQ: q,
historyAdapter: historyAdapter,
filters: &mockFilters{},
filters: &mockFilters{},
}

_, err := runner.RunHistoryArchiveIngestion(63, MaxSupportedProtocolVersion, bucketListHash)
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestProcessorRunnerRunHistoryArchiveIngestionProtocolVersionNotSupported(t
config: config,
historyQ: q,
historyAdapter: historyAdapter,
filters: &mockFilters{},
filters: &mockFilters{},
}

_, err := runner.RunHistoryArchiveIngestion(100, 200, xdr.Hash{})
Expand All @@ -173,7 +173,7 @@ func TestProcessorRunnerBuildChangeProcessor(t *testing.T) {
runner := ProcessorRunner{
ctx: ctx,
historyQ: q,
filters: &mockFilters{},
filters: &mockFilters{},
}

stats := &ingest.StatsChangeProcessor{}
Expand All @@ -195,7 +195,7 @@ func TestProcessorRunnerBuildChangeProcessor(t *testing.T) {
runner = ProcessorRunner{
ctx: ctx,
historyQ: q,
filters: &mockFilters{},
filters: &mockFilters{},
}

processor = buildChangeProcessor(runner.historyQ, stats, historyArchiveSource, 456)
Expand Down Expand Up @@ -293,7 +293,7 @@ func TestProcessorRunnerRunAllProcessorsOnLedger(t *testing.T) {
ctx: ctx,
config: config,
historyQ: q,
filters: &mockFilters{},
filters: &mockFilters{},
}

_, err := runner.RunAllProcessorsOnLedger(ledger)
Expand Down Expand Up @@ -342,7 +342,7 @@ func TestProcessorRunnerRunAllProcessorsOnLedgerProtocolVersionNotSupported(t *t
ctx: ctx,
config: config,
historyQ: q,
filters: &mockFilters{},
filters: &mockFilters{},
}

_, err := runner.RunAllProcessorsOnLedger(ledger)
Expand Down

0 comments on commit 7804c74

Please sign in to comment.