51 lines
2.3 KiB
Go
51 lines
2.3 KiB
Go
package index
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strconv"
|
|
|
|
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog"
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
|
)
|
|
|
|
// The bodies of the seat's events manifest-accepted and manifest-refused are the contract's types; the indexer, who says
|
|
// them, makes them from a verdict (novox/hq ADR 0634 §1: the logic of one holder stays with it).
|
|
|
|
// refusedOf is the body of manifest-refused for the verdict v on the manifest of digest.
|
|
func refusedOf(digest string, v meshcatalog.VerdictsByDigestValue) meshcatalog.ManifestRefusedEvent {
|
|
return meshcatalog.ManifestRefusedEvent{V: keys.Version, Module: v.Module, Digest: digest, Judge: v.Judge, Problems: v.Problems}
|
|
}
|
|
|
|
// acceptedEvent is the body of manifest-accepted for the verdict v accepting the manifest m of digest, its bus-state
|
|
// entries whole (novox/hq ADR 0595 §4); an empty list when m asks for none.
|
|
func acceptedEvent(digest string, v meshcatalog.VerdictsByDigestValue, m catalogue.Manifest) meshcatalog.ManifestAcceptedEvent {
|
|
return meshcatalog.ManifestAcceptedEvent{V: keys.Version, Module: v.Module, Digest: digest, Judge: v.Judge, BusState: busStateOf(m.BusState)}
|
|
}
|
|
|
|
// busStateOf is the manifest's bus-state entries in the event's form (the same JSON).
|
|
func busStateOf(entries []catalogue.BusStateEntry) []meshcatalog.ManifestAcceptedEventBusStateItem {
|
|
out := []meshcatalog.ManifestAcceptedEventBusStateItem{}
|
|
if len(entries) == 0 {
|
|
return out
|
|
}
|
|
raw, err := json.Marshal(entries)
|
|
if err == nil {
|
|
err = json.Unmarshal(raw, &out)
|
|
}
|
|
if err != nil {
|
|
return []meshcatalog.ManifestAcceptedEventBusStateItem{}
|
|
}
|
|
return out
|
|
}
|
|
|
|
// acceptedEventID is the event's id, one per manifest digest and judge, so the bus takes it once:
|
|
// `manifest-accepted-<digest>-<judge>`. The empty one of a module leaving the trunk carries no digest, so it is named by
|
|
// its module and the indexer's revision: `manifest-accepted-left-<module>-<revision>`, so two leaves are both kept.
|
|
func acceptedEventID(a meshcatalog.ManifestAcceptedEvent) string {
|
|
if a.Digest == "" {
|
|
return meshcatalog.EventManifestAccepted + "-left-" + a.Module + "-" + strconv.FormatInt(a.Revision, 10)
|
|
}
|
|
return meshcatalog.EventManifestAccepted + "-" + a.Digest + "-" + a.Judge
|
|
}
|