feat [UNTESTED]: set removed flags on pools and tokens
This commit is contained in:
parent
16ddf2b2ce
commit
8d26e7bf3d
@ -43,5 +43,10 @@ func bootstrapRouter(handlerContainer *handler.Handler) *router.Router {
|
||||
handlerContainer.IndexOwnershipChange,
|
||||
)
|
||||
|
||||
router.RegisterRoute(
|
||||
"TRACKER.INDEX_REMOVE",
|
||||
handlerContainer.IndexRemove,
|
||||
)
|
||||
|
||||
return router
|
||||
}
|
||||
|
11
internal/handler/index_remove.go
Normal file
11
internal/handler/index_remove.go
Normal file
@ -0,0 +1,11 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grassrootseconomics/eth-tracker/pkg/event"
|
||||
)
|
||||
|
||||
func (h *Handler) IndexRemove(ctx context.Context, event event.Event) error {
|
||||
return h.store.RemoveContractAddress(ctx, event)
|
||||
}
|
@ -39,6 +39,8 @@ type (
|
||||
InsertOwnershipChange string `query:"insert-ownership-change"`
|
||||
InsertToken string `query:"insert-token"`
|
||||
InsertPool string `query:"insert-pool"`
|
||||
RemovePool string `query:"remove-pool"`
|
||||
RemoveToken string `query:"remove-token"`
|
||||
}
|
||||
)
|
||||
|
||||
@ -247,6 +249,30 @@ func (pg *Pg) InsertPool(ctx context.Context, contractAddress string, name strin
|
||||
})
|
||||
}
|
||||
|
||||
func (pg *Pg) RemoveContractAddress(ctx context.Context, eventPayload event.Event) error {
|
||||
return pg.executeTransaction(ctx, func(tx pgx.Tx) error {
|
||||
_, err := tx.Exec(
|
||||
ctx,
|
||||
pg.queries.RemovePool,
|
||||
eventPayload.Payload["address"].(string),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.Exec(
|
||||
ctx,
|
||||
pg.queries.RemoveToken,
|
||||
eventPayload.Payload["address"].(string),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (pg *Pg) insertTx(ctx context.Context, tx pgx.Tx, eventPayload event.Event) (int, error) {
|
||||
var txID int
|
||||
if err := tx.QueryRow(
|
||||
|
@ -18,6 +18,7 @@ type (
|
||||
InsertOwnershipChange(context.Context, event.Event) error
|
||||
InsertToken(context.Context, string, string, string, uint8, string) error
|
||||
InsertPool(context.Context, string, string, string) error
|
||||
RemoveContractAddress(context.Context, event.Event) error
|
||||
Pool() *pgxpool.Pool
|
||||
Close()
|
||||
}
|
||||
|
5
migrations/003_add_removed_status.sql
Normal file
5
migrations/003_add_removed_status.sql
Normal file
@ -0,0 +1,5 @@
|
||||
ALTER TABLE tokens
|
||||
ADD COLUMN removed BOOLEAN NOT NULL DEFAULT false;
|
||||
|
||||
ALTER TABLE pools
|
||||
ADD COLUMN removed BOOLEAN NOT NULL DEFAULT false;
|
@ -139,3 +139,11 @@ INSERT INTO pools(
|
||||
pool_name,
|
||||
pool_symbol
|
||||
) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING
|
||||
|
||||
--name: remove-pool
|
||||
-- $1: contract_address
|
||||
UPDATE pools SET removed = true WHERE contract_address = $1
|
||||
|
||||
--name: remove-token
|
||||
-- $1: contract_address
|
||||
UPDATE tokens SET removed = true WHERE contract_address = $1
|
||||
|
Loading…
Reference in New Issue
Block a user