Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: saving ridge address #55

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/storage/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type Transaction interface {
GetRollup(ctx context.Context, rollupId []byte) (Rollup, error)
Validators(ctx context.Context) ([]Validator, error)
GetBridgeIdByAddressId(ctx context.Context, id uint64) (uint64, error)
GetAddressId(ctx context.Context, hash string) (uint64, error)
}

type SearchResult struct {
Expand Down
39 changes: 39 additions & 0 deletions internal/storage/mock/generic.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions internal/storage/postgres/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,12 @@ func (tx Transaction) GetBridgeIdByAddressId(ctx context.Context, id uint64) (br
Scan(ctx, &bridgeId)
return
}

func (tx Transaction) GetAddressId(ctx context.Context, hash string) (addrId uint64, err error) {
err = tx.Tx().NewSelect().
Column("id").
Model((*models.Address)(nil)).
Where("hash = ?", hash).
Scan(ctx, &addrId)
return
}
3 changes: 3 additions & 0 deletions pkg/indexer/decode/ibc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: 2024 PK Lab AG <[email protected]>
// SPDX-License-Identifier: MIT

package decode

import "github.com/shopspring/decimal"
Expand Down
19 changes: 12 additions & 7 deletions pkg/indexer/storage/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func saveAction(
if payerId, ok := addrToId[actions[i].Fee.Payer.Hash]; ok {
actions[i].Fee.PayerId = payerId
} else {
return errors.Errorf("unknown payer id")
return errors.Errorf("unknown payer id: %s", actions[i].Fee.Payer.Hash)
}
fees = append(fees, actions[i].Fee)
}
Expand All @@ -66,15 +66,20 @@ func saveAction(
actions[i].Deposit.ActionId = actions[i].Id
actions[i].Deposit.TxId = actions[i].TxId

if addrId, ok := addrToId[actions[i].Deposit.Bridge.Address.Hash]; ok {
bridgeId, err := tx.GetBridgeIdByAddressId(ctx, addrId)
addrId, ok := addrToId[actions[i].Deposit.Bridge.Address.Hash]
if !ok {
id, err := tx.GetAddressId(ctx, actions[i].Deposit.Bridge.Address.Hash)
if err != nil {
return errors.Wrap(err, "receiving deposit bridge id")
return errors.Wrapf(err, "receiving deposit bridge address: %s", actions[i].Deposit.Bridge.Address.Hash)
}
actions[i].Deposit.BridgeId = bridgeId
} else {
return errors.Errorf("unknown payer id")
addrId = id
}

bridgeId, err := tx.GetBridgeIdByAddressId(ctx, addrId)
if err != nil {
return errors.Wrap(err, "receiving deposit bridge id")
}
actions[i].Deposit.BridgeId = bridgeId

rollup, err := tx.GetRollup(ctx, actions[i].Deposit.Rollup.AstriaId)
if err != nil {
Expand Down
Loading