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

Refactoring: deposit adddress setting #56

Merged
merged 1 commit into from
Oct 24, 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
2 changes: 1 addition & 1 deletion pkg/indexer/parser/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (p *Module) parse(ctx context.Context, b types.BlockData) error {
decodeCtx := decode.NewContext(p.bridgeAssets)
decodeCtx.Proposer = proposer

if err := parseEvents(ctx, b.FinalizeBlockEvents, &decodeCtx, p.api); err != nil {
if err := parseEvents(ctx, b.FinalizeBlockEvents, b.Height, &decodeCtx, p.api); err != nil {
return errors.Wrap(err, "parse finalize events")
}

Expand Down
11 changes: 5 additions & 6 deletions pkg/indexer/parser/parseEvents.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import (
"google.golang.org/protobuf/proto"
)

func parseEvents(ctx context.Context, events []types.Event, decodeCtx *decode.Context, api node.Api) error {
func parseEvents(ctx context.Context, events []types.Event, height types.Level, decodeCtx *decode.Context, api node.Api) error {
for i := range events {
var err error
switch events[i].Type {
case "tx.fees":
err = parseTxFees(ctx, events[i].Attributes, decodeCtx, api)
case "tx.deposit":
err = parseTxDeposit(events[i].Attributes, decodeCtx)
err = parseTxDeposit(events[i].Attributes, height, decodeCtx)
default:
continue
}
Expand Down Expand Up @@ -110,17 +110,16 @@ func parseTxFees(ctx context.Context, attrs []types.EventAttribute, decodeCtx *d
return nil
}

func parseTxDeposit(attrs []types.EventAttribute, decodeCtx *decode.Context) error {
func parseTxDeposit(attrs []types.EventAttribute, height types.Level, decodeCtx *decode.Context) error {
deposit := new(storage.Deposit)
var idx int64

for i := range attrs {
switch attrs[i].Key {
case "bridgeAddress":
addr := decodeCtx.Addresses.Set(attrs[i].Value, height, decimal.Zero, currency.DefaultCurrency, 0, 0)
deposit.Bridge = &storage.Bridge{
Address: &storage.Address{
Hash: attrs[i].Value,
},
Address: addr,
}
case "rollupId":
hash, err := base64.URLEncoding.DecodeString(attrs[i].Value)
Expand Down
2 changes: 1 addition & 1 deletion pkg/indexer/parser/parseEvents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Test_parseTxDeposit(t *testing.T) {
}

ctx := decode.NewContext(map[string]string{})
err := parseTxDeposit(attrs, &ctx)
err := parseTxDeposit(attrs, 100, &ctx)
require.NoError(t, err)
require.Len(t, ctx.Deposits, 1)

Expand Down
2 changes: 1 addition & 1 deletion pkg/indexer/parser/parseTxs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func parseTxs(ctx context.Context, b types.BlockData, decodeCtx *decode.Context,
txs := make([]*storage.Tx, count)

for i := index; i < len(b.TxsResults); i++ {
if err := parseEvents(ctx, b.TxsResults[i].Events, decodeCtx, api); err != nil {
if err := parseEvents(ctx, b.TxsResults[i].Events, b.Height, decodeCtx, api); err != nil {
return nil, errors.Wrap(err, "parse events")
}

Expand Down
Loading