-
Notifications
You must be signed in to change notification settings - Fork 151
/
receipts.go
41 lines (32 loc) · 1.29 KB
/
receipts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package coreapi
import (
"github.com/labstack/echo/v4"
"github.com/pkg/errors"
"github.com/iotaledger/hornet/v2/pkg/model/utxo"
"github.com/iotaledger/hornet/v2/pkg/restapi"
"github.com/iotaledger/inx-app/pkg/httpserver"
)
func receipts(_ echo.Context) (*receiptsResponse, error) {
receipts := make([]*utxo.ReceiptTuple, 0)
if err := deps.UTXOManager.ForEachReceiptTuple(func(rt *utxo.ReceiptTuple) bool {
receipts = append(receipts, rt)
return true
}, utxo.ReadLockLedger(false)); err != nil {
return nil, errors.WithMessagef(echo.ErrInternalServerError, "unable to retrieve receipts: %s", err)
}
return &receiptsResponse{Receipts: receipts}, nil
}
func receiptsByMigratedAtIndex(c echo.Context) (*receiptsResponse, error) {
migratedAt, err := httpserver.ParseMilestoneIndexParam(c, restapi.ParameterMilestoneIndex)
if err != nil {
return nil, err
}
receipts := make([]*utxo.ReceiptTuple, 0)
if err := deps.UTXOManager.ForEachReceiptTupleMigratedAt(migratedAt, func(rt *utxo.ReceiptTuple) bool {
receipts = append(receipts, rt)
return true
}, utxo.ReadLockLedger(false)); err != nil {
return nil, errors.WithMessagef(echo.ErrInternalServerError, "unable to retrieve receipts for migrated at index %d: %s", migratedAt, err)
}
return &receiptsResponse{Receipts: receipts}, nil
}