Skip to content

Commit

Permalink
Fix: saving ridge address (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored Oct 23, 2024
1 parent c48b035 commit 9459228
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 7 deletions.
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

0 comments on commit 9459228

Please sign in to comment.