// HandleAnchorEvent handles an anchor event.
// nolint:funlen
HandleAnchorEvent handles an anchor event.
nolint:funlen
// HandleAnchorEvent handles an anchor event . // nolint : funlen
func (h *AnchorEventHandler) HandleAnchorEvent(actor, anchorEventRef, source *url.URL,
	anchorEvent *vocab.AnchorEventType) error {
	logger.Debugf("Received request from [%s] for anchor event URL [%s]", actor, anchorEventRef)
	var anchorEventBytes []byte
	if anchorEvent != nil {
		var err error
		anchorEventBytes, err = canonicalizer.MarshalCanonical(anchorEvent)
		if err != nil {
			return fmt.Errorf("marshal anchor event: %w", err)
		}
	}
	anchorEventBytes, localHL, err := h.casResolver.Resolve(nil, anchorEventRef.String(), anchorEventBytes)
	if err != nil {
		return fmt.Errorf("failed to resolve anchor event [%s]: %w", anchorEventRef, err)
	}
	if anchorEvent == nil {
		anchorEvent = &vocab.AnchorEventType{}
		err = h.unmarshal(anchorEventBytes, anchorEvent)
		if err != nil {
			return fmt.Errorf("unmarshal anchor event: %w", err)
		}
	}
	err = h.ensureParentAnchorsAreProcessed(anchorEventRef, anchorEvent)
	if err != nil {
		return fmt.Errorf("ensure unprocessed parents are processed for %s: %w", anchorEventRef, err)
	}
	var attributedTo string
	if actor != nil {
		attributedTo = actor.String()
	}
	logger.Infof("Processing anchor event [%s]", anchorEventRef)
	var alternateSources []string
	if source != nil {
		alternateSources = []string{source.String()}
	}
	err = h.processAnchorEvent(&anchorInfo{
		anchorEvent: anchorEvent,
		AnchorInfo: &anchorinfo.AnchorInfo{
			Hashlink:         anchorEventRef.String(),
			LocalHashlink:    localHL,
			AttributedTo:     attributedTo,
			AlternateSources: alternateSources,
		},
	})
	if err != nil {
		return fmt.Errorf("process anchor event %s: %w", anchorEventRef, err)
	}
	return nil
}
func ( h * AnchorEventHandler ) HandleAnchorEvent ( actor , anchorEventRef , source * url . URL , anchorEvent * vocab . AnchorEventType ) error { logger . Debugf ( " " , actor , anchorEventRef ) var anchorEventBytes [ ] byte if anchorEvent != nil { var err error anchorEventBytes , err = canonicalizer . MarshalCanonical ( anchorEvent ) if err != nil { return fmt . Errorf ( " " , err ) } } anchorEventBytes , localHL , err := h . casResolver . Resolve ( nil , anchorEventRef . String ( ) , anchorEventBytes ) if err != nil { return fmt . Errorf ( " " , anchorEventRef , err ) } if anchorEvent == nil { anchorEvent = & vocab . AnchorEventType { } err = h . unmarshal ( anchorEventBytes , anchorEvent ) if err != nil { return fmt . Errorf ( " " , err ) } } err = h . ensureParentAnchorsAreProcessed ( anchorEventRef , anchorEvent ) if err != nil { return fmt . Errorf ( " " , anchorEventRef , err ) } var attributedTo string if actor != nil { attributedTo = actor . String ( ) } logger . Infof ( " " , anchorEventRef ) var alternateSources [ ] string if source != nil { alternateSources = [ ] string { source . String ( ) } } err = h . processAnchorEvent ( & anchorInfo { anchorEvent : anchorEvent , AnchorInfo : & anchorinfo . AnchorInfo { Hashlink : anchorEventRef . String ( ) , LocalHashlink : localHL , AttributedTo : attributedTo , AlternateSources : alternateSources , } , } ) if err != nil { return fmt . Errorf ( " " , anchorEventRef , err ) } return nil }
HandleAnchorEvent handles an anchor event.
HandleAnchorEvent handles an anchor event .
// Make sure that all parents/grandparents of this anchor event are processed. // The anchor index in the AnchorEvent may not be found in the CAS store. This may occur in the event that // the anchor origin lost the original data. So we add an alternate source from which the Sidetree // files may be retrieved. // Now process the latest anchor event.