-
Notifications
You must be signed in to change notification settings - Fork 12
/
transactions.go
57 lines (45 loc) · 1.58 KB
/
transactions.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package debugapi
import (
"github.com/iotaledger/hive.go/ads"
"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/kvstore/mapdb"
"github.com/iotaledger/iota-core/pkg/protocol/engine/notarization"
iotago "github.com/iotaledger/iota.go/v4"
)
var transactionsPerSlot map[iotago.SlotIndex]*TransactionsChangesResponse
func init() {
transactionsPerSlot = make(map[iotago.SlotIndex]*TransactionsChangesResponse)
}
func storeTransactionsPerSlot(scd *notarization.SlotCommittedDetails) error {
slot := scd.Commitment.Slot()
mutationsTree := ads.NewSet[iotago.Identifier](
mapdb.NewMapDB(),
iotago.Identifier.Bytes,
iotago.IdentifierFromBytes,
iotago.TransactionID.Bytes,
iotago.TransactionIDFromBytes,
)
tcs := &TransactionsChangesResponse{
Index: slot,
IncludedTransactions: make([]string, 0),
}
for _, transaction := range scd.Mutations {
txID, err := transaction.ID()
if err != nil {
return ierrors.Wrapf(err, "failed to calculate transactionID")
}
tcs.IncludedTransactions = append(tcs.IncludedTransactions, txID.String())
if err = mutationsTree.Add(txID); err != nil {
return ierrors.Wrapf(err, "failed to add transaction to mutations tree, txID: %s", txID)
}
}
tcs.MutationsRoot = mutationsTree.Root().String()
transactionsPerSlot[slot] = tcs
return nil
}
func getSlotTransactionIDs(slot iotago.SlotIndex) (*TransactionsChangesResponse, error) {
if slotDiff, exists := transactionsPerSlot[slot]; exists {
return slotDiff, nil
}
return nil, ierrors.Errorf("cannot find transaction storage bucket for slot %d", slot)
}