Skip to content

Commit

Permalink
Add statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Jan 31, 2025
1 parent c1bfab8 commit 9f8b25a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/api/handler/responses/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewCelestial(c *celestials.Celestial) *Celestial {
return &Celestial{
ImageUrl: c.ImageUrl,
Name: c.Id,
IsPrimary: c.IsPrimary,
IsPrimary: c.Status == celestials.StatusPRIMARY,
}
}

Expand Down
6 changes: 3 additions & 3 deletions internal/storage/postgres/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (a *Address) ByHash(ctx context.Context, hash []byte) (address storage.Addr
ColumnExpr("celestial.id as celestials__id, celestial.image_url as celestials__image_url").
ColumnExpr("balance.currency as balance__currency, balance.spendable as balance__spendable, balance.delegated as balance__delegated, balance.unbonding as balance__unbonding").
Join("left join balance on balance.id = address.id").
Join("left join celestial on celestial.address_id = address.id and celestial.is_primary = true").
Join("left join celestial on celestial.address_id = address.id and celestial.status = 'PRIMARY'").
Scan(ctx, &address)
return
}
Expand All @@ -54,7 +54,7 @@ func (a *Address) ListWithBalance(ctx context.Context, filters storage.AddressLi
ColumnExpr("celestial.id as celestials__id, celestial.image_url as celestials__image_url").
ColumnExpr("balance.currency as balance__currency, balance.spendable as balance__spendable, balance.delegated as balance__delegated, balance.unbonding as balance__unbonding").
Join("left join balance on balance.id = address.id").
Join("left join celestial on celestial.address_id = address.id and celestial.is_primary = true").
Join("left join celestial on celestial.address_id = address.id and celestial.status = 'PRIMARY'").
Scan(ctx, &result)

} else {
Expand All @@ -69,7 +69,7 @@ func (a *Address) ListWithBalance(ctx context.Context, filters storage.AddressLi
ColumnExpr("celestial.id as celestials__id, celestial.image_url as celestials__image_url").
ColumnExpr("balance.currency as balance__currency, balance.spendable as balance__spendable, balance.delegated as balance__delegated, balance.unbonding as balance__unbonding").
Join("left join address on balance.id = address.id").
Join("left join celestial on celestial.address_id = address.id and celestial.is_primary = true").
Join("left join celestial on celestial.address_id = address.id and celestial.status = 'PRIMARY'").
Scan(ctx, &result)
}

Expand Down
8 changes: 4 additions & 4 deletions internal/storage/postgres/blob_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (bl *BlobLog) ByNamespace(ctx context.Context, nsId uint64, fltrs storage.B
ColumnExpr("rollup.id as rollup__id, rollup.name as rollup__name, rollup.logo as rollup__logo, rollup.slug as rollup__slug").
TableExpr("(?) as blob_log", blobsQuery).
Join("left join address as signer on signer.id = blob_log.signer_id").
Join("left join celestial on celestial.address_id = signer.id and celestial.is_primary = true").
Join("left join celestial on celestial.address_id = signer.id and celestial.status = 'PRIMARY'").
Join("left join tx on tx.id = blob_log.tx_id").
Join("left join rollup_provider as p on blob_log.signer_id = p.address_id and blob_log.namespace_id = p.namespace_id").
Join("left join rollup on rollup.id = p.rollup_id")
Expand Down Expand Up @@ -91,7 +91,7 @@ func (bl *BlobLog) ByProviders(ctx context.Context, providers []storage.RollupPr
ColumnExpr("celestial.id as signer__celestials__id, celestial.image_url as signer__celestials__image_url").
ColumnExpr("tx.id as tx__id, tx.height as tx__height, tx.time as tx__time, tx.position as tx__position, tx.gas_wanted as tx__gas_wanted, tx.gas_used as tx__gas_used, tx.timeout_height as tx__timeout_height, tx.events_count as tx__events_count, tx.messages_count as tx__messages_count, tx.fee as tx__fee, tx.status as tx__status, tx.error as tx__error, tx.codespace as tx__codespace, tx.hash as tx__hash, tx.memo as tx__memo, tx.message_types as tx__message_types").
Join("left join address as signer on signer.id = blob_log.signer_id").
Join("left join celestial on celestial.address_id = signer.id and celestial.is_primary = true").
Join("left join celestial on celestial.address_id = signer.id and celestial.status = 'PRIMARY'").
Join("left join tx on tx.id = blob_log.tx_id")
}

Expand Down Expand Up @@ -210,7 +210,7 @@ func (bl *BlobLog) ByTxId(ctx context.Context, txId uint64, fltrs storage.BlobLo
ColumnExpr("tx.id as tx__id, tx.height as tx__height, tx.time as tx__time, tx.position as tx__position, tx.gas_wanted as tx__gas_wanted, tx.gas_used as tx__gas_used, tx.timeout_height as tx__timeout_height, tx.events_count as tx__events_count, tx.messages_count as tx__messages_count, tx.fee as tx__fee, tx.status as tx__status, tx.error as tx__error, tx.codespace as tx__codespace, tx.hash as tx__hash, tx.memo as tx__memo, tx.message_types as tx__message_types").
TableExpr("(?) as blob_log", blobLogQuery).
Join("left join address as signer on signer.id = blob_log.signer_id").
Join("left join celestial on celestial.address_id = signer.id and celestial.is_primary = true").
Join("left join celestial on celestial.address_id = signer.id and celestial.status = 'PRIMARY'").
Join("left join namespace as ns on ns.id = blob_log.namespace_id").
Join("left join tx on tx.id = blob_log.tx_id").
Join("left join rollup_provider as p on blob_log.signer_id = p.address_id and blob_log.namespace_id = p.namespace_id").
Expand All @@ -235,7 +235,7 @@ func (bl *BlobLog) ByHeight(ctx context.Context, height types.Level, fltrs stora
ColumnExpr("tx.id as tx__id, tx.height as tx__height, tx.time as tx__time, tx.position as tx__position, tx.gas_wanted as tx__gas_wanted, tx.gas_used as tx__gas_used, tx.timeout_height as tx__timeout_height, tx.events_count as tx__events_count, tx.messages_count as tx__messages_count, tx.fee as tx__fee, tx.status as tx__status, tx.error as tx__error, tx.codespace as tx__codespace, tx.hash as tx__hash, tx.memo as tx__memo, tx.message_types as tx__message_types").
TableExpr("(?) as blob_log", blobLogQuery).
Join("left join address as signer on signer.id = blob_log.signer_id").
Join("left join celestial on celestial.address_id = signer.id and celestial.is_primary = true").
Join("left join celestial on celestial.address_id = signer.id and celestial.status = 'PRIMARY'").
Join("left join namespace as ns on ns.id = blob_log.namespace_id").
Join("left join tx on tx.id = blob_log.tx_id").
Join("left join rollup_provider as p on blob_log.signer_id = p.address_id and blob_log.namespace_id = p.namespace_id").
Expand Down
5 changes: 5 additions & 0 deletions internal/storage/postgres/custom_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"database/sql"

"github.com/celenium-io/celestia-indexer/internal/storage/types"
"github.com/celenium-io/celestial-module/pkg/storage/postgres"
"github.com/dipdup-net/go-lib/database"
"github.com/rs/zerolog/log"
"github.com/uptrace/bun"
Expand All @@ -23,6 +24,10 @@ const (
)

func createTypes(ctx context.Context, conn *database.Bun) error {
if err := postgres.CreateTypes(ctx, conn); err != nil {
return err
}

log.Info().Msg("creating custom types...")
return conn.DB().RunInTx(ctx, &sql.TxOptions{}, func(ctx context.Context, tx bun.Tx) error {
if _, err := tx.ExecContext(
Expand Down
2 changes: 1 addition & 1 deletion internal/storage/postgres/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (tx *Tx) getSigners(ctx context.Context, txId ...uint64) (signers []storage
ColumnExpr("celestial.id as address__celestials__id, celestial.image_url as address__celestials__image_url").
ColumnExpr("signer.*").
Join("left join address on address.id = signer.address_id").
Join("left join celestial on celestial.address_id = signer.address_id and celestial.is_primary = true").
Join("left join celestial on celestial.address_id = signer.address_id and celestial.status = 'PRIMARY'").
Scan(ctx, &signers)
return
}
Expand Down
6 changes: 3 additions & 3 deletions test/data/celestial.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
address_id: 1
image_url:
change_id: 1
is_primary: true
status: PRIMARY
- id: name 2
address_id: 1
image_url:
change_id: 2
is_primary: false
status: VERIFIED
- id: name 3
address_id: 2
image_url:
change_id: 3
is_primary: true
status: PRIMARY

0 comments on commit 9f8b25a

Please sign in to comment.