-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(indexer/postgres)!: use schema/indexer API and hide types/me…
…thods (#21363)
- Loading branch information
Showing
17 changed files
with
266 additions
and
144 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
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
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,38 @@ | ||
package postgres | ||
|
||
import ( | ||
"fmt" | ||
|
||
"cosmossdk.io/schema/appdata" | ||
) | ||
|
||
func (i *indexerImpl) listener() appdata.Listener { | ||
return appdata.Listener{ | ||
InitializeModuleData: func(data appdata.ModuleInitializationData) error { | ||
moduleName := data.ModuleName | ||
modSchema := data.Schema | ||
_, ok := i.modules[moduleName] | ||
if ok { | ||
return fmt.Errorf("module %s already initialized", moduleName) | ||
} | ||
|
||
mm := newModuleIndexer(moduleName, modSchema, i.opts) | ||
i.modules[moduleName] = mm | ||
|
||
return mm.initializeSchema(i.ctx, i.tx) | ||
}, | ||
StartBlock: func(data appdata.StartBlockData) error { | ||
_, err := i.tx.Exec("INSERT INTO block (number) VALUES ($1)", data.Height) | ||
return err | ||
}, | ||
Commit: func(data appdata.CommitData) (func() error, error) { | ||
err := i.tx.Commit() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
i.tx, err = i.db.BeginTx(i.ctx, nil) | ||
return nil, err | ||
}, | ||
} | ||
} |
Oops, something went wrong.