Skip to content

Commit

Permalink
Added Indexer inheritance from modules.BaseModule
Browse files Browse the repository at this point in the history
  • Loading branch information
k-karuna committed Aug 27, 2024
1 parent 84cbedf commit be1edaa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 36 deletions.
2 changes: 1 addition & 1 deletion build/dipdup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ database:
port: ${POSTGRES_PORT:-5432}
user: ${POSTGRES_USER:-dipdup}
password: ${POSTGRES_PASSWORD:-changeme}
database: ${POSTGRES_DB:-dipdup}
database: ${POSTGRES_DB:-starknet_metadata}

hasura:
url: http://${HASURA_HOST:-hasura}:${HASURA_PORT:-8080}
Expand Down
42 changes: 7 additions & 35 deletions cmd/metadata/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ var (

// input name
const (
InputName = "input"
InputName = "input"
OutputName = "output"
)

// Indexer -
type Indexer struct {
modules.BaseModule

client *grpc.Client
storage postgres.Storage
input *modules.Input
Expand Down Expand Up @@ -61,6 +64,9 @@ func NewIndexer(cfg Metadata, datasources map[string]config.DataSource, pg postg
indexer.filler = filler
indexer.receiver = NewReceiver(cfg.Receiver, pg.TokenMetadata, ipfsNode)

indexer.CreateInput(InputName)
indexer.CreateOutput(OutputName)

return indexer, nil
}

Expand Down Expand Up @@ -238,40 +244,6 @@ func (indexer *Indexer) Output(name string) (*modules.Output, error) {
return nil, errors.Wrap(modules.ErrUnknownOutput, name)
}

// AttachTo - attach input to output
func (indexer *Indexer) AttachTo(outputModule modules.Module, outputName, inputName string) error {
outputChannel, err := outputModule.Output(outputName)
if err != nil {
return err
}

input, err := indexer.Input(inputName)
if err != nil {
return err
}

outputChannel.Attach(input)
return nil
}

// MustInput -
func (indexer *Indexer) MustInput(name string) *modules.Input {
input, err := indexer.Input(name)
if err != nil {
panic(err)
}
return input
}

// MustOutput -
func (indexer *Indexer) MustOutput(name string) *modules.Output {
output, err := indexer.Output(name)
if err != nil {
panic(err)
}
return output
}

// Unsubscribe -
func (indexer *Indexer) Unsubscribe(ctx context.Context) error {
log.Info().Uint64("id", indexer.subId).Msg("unsubscribing...")
Expand Down

0 comments on commit be1edaa

Please sign in to comment.