Skip to content

Commit

Permalink
Fix txs amount
Browse files Browse the repository at this point in the history
  • Loading branch information
kacpersaw committed Jun 19, 2024
1 parent 5d6f19e commit 42fbda4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions internal/service/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ func (e *Service) GetLayer(ctx context.Context, layerNum int) (*model.Layer, err
return nil, ErrNotFound
}

c, derr := e.storage.CountTransactions(ctx, &bson.D{{Key: "layer", Value: layer.Number}})
txs, derr := e.storage.GetTransactions(ctx, &bson.D{{Key: "layer", Value: layer.Number}})
if derr != nil {
return nil, fmt.Errorf("failed to count txs for layer %d: %w", layer.Number, derr)
}
layer.Txs = uint32(c)
layer.Txs = uint32(len(txs))
layer.TxsAmount = 0
for _, tx := range txs {
layer.TxsAmount += tx.Amount
}

return layer, nil
}
Expand Down Expand Up @@ -78,11 +82,15 @@ func (e *Service) GetLayers(ctx context.Context, page, perPage int64) (layers []
}

for _, layer := range layers {
c, derr := e.storage.CountTransactions(ctx, &bson.D{{Key: "layer", Value: layer.Number}})
txs, derr := e.storage.GetTransactions(ctx, &bson.D{{Key: "layer", Value: layer.Number}})
if derr != nil {
return nil, 0, fmt.Errorf("failed to count txs for layer %d: %w", layer.Number, derr)
}
layer.Txs = uint32(c)
layer.Txs = uint32(len(txs))
layer.TxsAmount = 0
for _, tx := range txs {
layer.TxsAmount += tx.Amount
}
}
return layers, total, nil
}
Expand Down

0 comments on commit 42fbda4

Please sign in to comment.