mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-10 14:00:33 +00:00
Unexport database constants.
This commit is contained in:
@@ -17,10 +17,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
TableEventBlock = "block_events"
|
||||
TableEventTx = "tx_events"
|
||||
TableResultTx = "tx_results"
|
||||
DriverName = "postgres"
|
||||
tableEventBlock = "block_events"
|
||||
tableEventTx = "tx_events"
|
||||
tableResultTx = "tx_results"
|
||||
driverName = "postgres"
|
||||
)
|
||||
|
||||
// EventSink is an indexer backend providing the tx/block index services. This
|
||||
@@ -35,7 +35,7 @@ type EventSink struct {
|
||||
// database specified by connStr. Events written to the sink are attributed to
|
||||
// the specified chainID.
|
||||
func NewEventSink(connStr, chainID string) (*EventSink, error) {
|
||||
db, err := sql.Open(DriverName, connStr)
|
||||
db, err := sql.Open(driverName, connStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func (es *EventSink) Type() indexer.EventSinkType { return indexer.PSQL }
|
||||
// indexer.EventSink interface.
|
||||
func (es *EventSink) IndexBlockEvents(h types.EventDataNewBlockHeader) error {
|
||||
sqlStmt := sq.
|
||||
Insert(TableEventBlock).
|
||||
Insert(tableEventBlock).
|
||||
Columns("key", "value", "height", "type", "created_at", "chain_id").
|
||||
PlaceholderFormat(sq.Dollar).
|
||||
Suffix("ON CONFLICT (key,height)").
|
||||
@@ -90,7 +90,7 @@ func (es *EventSink) IndexTxEvents(txr []*abci.TxResult) error {
|
||||
// index the tx result
|
||||
var txid uint32
|
||||
sqlStmtTxResult := sq.
|
||||
Insert(TableResultTx).
|
||||
Insert(tableResultTx).
|
||||
Columns("tx_result", "created_at").
|
||||
PlaceholderFormat(sq.Dollar).
|
||||
RunWith(es.store).
|
||||
@@ -99,7 +99,7 @@ func (es *EventSink) IndexTxEvents(txr []*abci.TxResult) error {
|
||||
Suffix("RETURNING \"id\"")
|
||||
|
||||
sqlStmtEvents := sq.
|
||||
Insert(TableEventTx).
|
||||
Insert(tableEventTx).
|
||||
Columns("key", "value", "height", "hash", "tx_result_id", "created_at", "chain_id").
|
||||
PlaceholderFormat(sq.Dollar).
|
||||
Suffix("ON CONFLICT (key,hash)").
|
||||
|
||||
@@ -76,7 +76,7 @@ func TestBlockFuncs(t *testing.T) {
|
||||
assert.Nil(t, r2)
|
||||
assert.Equal(t, errors.New("block search is not supported via the postgres event sink"), err)
|
||||
|
||||
require.NoError(t, verifyTimeStamp(TableEventBlock))
|
||||
require.NoError(t, verifyTimeStamp(tableEventBlock))
|
||||
|
||||
// try to insert the duplicate block events.
|
||||
err = indexer.IndexBlockEvents(getTestBlockHeader())
|
||||
@@ -103,8 +103,8 @@ func TestTxFuncs(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, txResult, tx)
|
||||
|
||||
require.NoError(t, verifyTimeStamp(TableEventTx))
|
||||
require.NoError(t, verifyTimeStamp(TableResultTx))
|
||||
require.NoError(t, verifyTimeStamp(tableEventTx))
|
||||
require.NoError(t, verifyTimeStamp(tableResultTx))
|
||||
|
||||
tx, err = indexer.GetTxByHash(types.Tx(txResult.Tx).Hash())
|
||||
assert.Nil(t, tx)
|
||||
@@ -207,10 +207,10 @@ func txResultWithEvents(events []abci.Event) *abci.TxResult {
|
||||
}
|
||||
|
||||
func verifyTx(hash []byte) (*abci.TxResult, error) {
|
||||
join := fmt.Sprintf("%s ON %s.id = tx_result_id", TableEventTx, TableResultTx)
|
||||
join := fmt.Sprintf("%s ON %s.id = tx_result_id", tableEventTx, tableResultTx)
|
||||
sqlStmt := sq.
|
||||
Select("tx_result", fmt.Sprintf("%s.id", TableResultTx), "tx_result_id", "hash", "chain_id").
|
||||
Distinct().From(TableResultTx).
|
||||
Select("tx_result", fmt.Sprintf("%s.id", tableResultTx), "tx_result_id", "hash", "chain_id").
|
||||
Distinct().From(tableResultTx).
|
||||
InnerJoin(join).
|
||||
Where(fmt.Sprintf("hash = $1 AND chain_id = '%s'", chainID), fmt.Sprintf("%X", hash))
|
||||
|
||||
@@ -270,7 +270,7 @@ func verifyBlock(h int64) (bool, error) {
|
||||
sqlStmt := sq.
|
||||
Select("height").
|
||||
Distinct().
|
||||
From(TableEventBlock).
|
||||
From(tableEventBlock).
|
||||
Where(fmt.Sprintf("height = %d", h))
|
||||
rows, err := sqlStmt.RunWith(db).Query()
|
||||
if err != nil {
|
||||
@@ -286,7 +286,7 @@ func verifyBlock(h int64) (bool, error) {
|
||||
sqlStmt = sq.
|
||||
Select("type, height", "chain_id").
|
||||
Distinct().
|
||||
From(TableEventBlock).
|
||||
From(tableEventBlock).
|
||||
Where(fmt.Sprintf("height = %d AND type = '%s' AND chain_id = '%s'", h, types.EventTypeBeginBlock, chainID))
|
||||
|
||||
rows, err = sqlStmt.RunWith(db).Query()
|
||||
@@ -302,7 +302,7 @@ func verifyBlock(h int64) (bool, error) {
|
||||
sqlStmt = sq.
|
||||
Select("type, height").
|
||||
Distinct().
|
||||
From(TableEventBlock).
|
||||
From(tableEventBlock).
|
||||
Where(fmt.Sprintf("height = %d AND type = '%s'", h, types.EventTypeEndBlock))
|
||||
rows, err = sqlStmt.RunWith(db).Query()
|
||||
|
||||
@@ -321,7 +321,7 @@ func setupDB(t *testing.T) (*dockertest.Pool, error) {
|
||||
require.NoError(t, err)
|
||||
|
||||
resource, err = pool.RunWithOptions(&dockertest.RunOptions{
|
||||
Repository: DriverName,
|
||||
Repository: driverName,
|
||||
Tag: "13",
|
||||
Env: []string{
|
||||
"POSTGRES_USER=" + user,
|
||||
|
||||
Reference in New Issue
Block a user