add id in converter

This commit is contained in:
D-Stacks 2022-06-17 11:56:56 +02:00
parent eb3f60d234
commit 830f3c4589

View File

@ -217,13 +217,11 @@ func (nm *NotificationManager) NotifyUTXOsChanged(utxoChanges *utxoindex.UTXOCha
for router, listener := range nm.listeners { for router, listener := range nm.listeners {
if listener.propagateUTXOsChangedNotifications { if listener.propagateUTXOsChangedNotifications {
// Filter utxoChanges and create a notification // Filter utxoChanges and create a notification
notification, err := listener.convertUTXOChangesToUTXOsChangedNotification(utxoChanges) notification, err := listener.convertUTXOChangesToUTXOsChangedNotification(utxoChanges, listener.propagateUTXOsChangedNotificationsID)
if err != nil { if err != nil {
return err return err
} }
notification.ID = listener.propagateUTXOsChangedNotificationsID
// Don't send the notification if it's empty // Don't send the notification if it's empty
if len(notification.Added) == 0 && len(notification.Removed) == 0 { if len(notification.Added) == 0 && len(notification.Removed) == 0 {
continue continue
@ -403,7 +401,7 @@ func (nl *NotificationListener) StopPropagatingUTXOsChangedNotifications(address
} }
func (nl *NotificationListener) convertUTXOChangesToUTXOsChangedNotification( func (nl *NotificationListener) convertUTXOChangesToUTXOsChangedNotification(
utxoChanges *utxoindex.UTXOChanges) (*appmessage.UTXOsChangedNotificationMessage, error) { utxoChanges *utxoindex.UTXOChanges, id string) (*appmessage.UTXOsChangedNotificationMessage, error) {
// As an optimization, we iterate over the smaller set (O(n)) among the two below // As an optimization, we iterate over the smaller set (O(n)) among the two below
// and check existence over the larger set (O(1)) // and check existence over the larger set (O(1))
@ -411,6 +409,9 @@ func (nl *NotificationListener) convertUTXOChangesToUTXOsChangedNotification(
addressesSize := len(nl.propagateUTXOsChangedNotificationAddresses) addressesSize := len(nl.propagateUTXOsChangedNotificationAddresses)
notification := &appmessage.UTXOsChangedNotificationMessage{} notification := &appmessage.UTXOsChangedNotificationMessage{}
notification.ID = id
if utxoChangesSize < addressesSize { if utxoChangesSize < addressesSize {
for scriptPublicKeyString, addedPairs := range utxoChanges.Added { for scriptPublicKeyString, addedPairs := range utxoChanges.Added {
if listenerAddress, ok := nl.propagateUTXOsChangedNotificationAddresses[scriptPublicKeyString]; ok { if listenerAddress, ok := nl.propagateUTXOsChangedNotificationAddresses[scriptPublicKeyString]; ok {