Skip to content

Commit

Permalink
Refactoring: deposit adddress setting
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Oct 24, 2024
1 parent 9459228 commit f18f950
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
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

0 comments on commit f18f950

Please sign in to comment.