Skip to content

Commit 8537939

Browse files
conditionally update statuf of validator (#54)
1 parent b1fb97c commit 8537939

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

listener/internal/api/handlers/postSignatures.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ func insertSignaturesIntoDB(signatures []types.SignatureRequestDecodedWithStatus
110110
"tag": req.Tag,
111111
"network": network,
112112
}
113+
114+
// Create a base update document with $push operation
113115
update := bson.M{
114-
"$setOnInsert": bson.M{"status": req.Status}, // do not update status if already exists
115116
"$push": bson.M{
116117
"entries": bson.M{
117118
"payload": req.Payload,
@@ -124,10 +125,19 @@ func insertSignaturesIntoDB(signatures []types.SignatureRequestDecodedWithStatus
124125
},
125126
},
126127
}
128+
129+
// Only update status unknown -> active
130+
if req.Status == "active" {
131+
update["$set"] = bson.M{"status": req.Status}
132+
} else {
133+
update["$setOnInsert"] = bson.M{"status": req.Status}
134+
}
135+
127136
options := options.Update().SetUpsert(true)
128137
if _, err := dbCollection.UpdateOne(context.Background(), filter, update, options); err != nil {
129138
return err
130139
}
140+
131141
logger.Debug("New Signature " + req.Signature + " inserted into MongoDB")
132142
}
133143
return nil

0 commit comments

Comments
 (0)