// postOfferActivity creates and posts offer activity (requests witnessing of anchor credential).
postOfferActivity creates and posts offer activity (requests witnessing of anchor credential).
// postOfferActivity creates and posts offer activity ( requests witnessing of anchor credential ) .
func (c *Writer) postOfferActivity(anchorEvent *vocab.AnchorEventType, localProof vocab.Document,
	batchWitnesses []string) error {
	postOfferActivityStartTime := time.Now()
	defer c.metrics.WriteAnchorPostOfferActivityTime(time.Since(postOfferActivityStartTime))
	logger.Debugf("sending anchor event[%s] to system witnesses plus: %s", anchorEvent.Index(), batchWitnesses)
	witnessesIRI, err := c.getWitnesses(anchorEvent.Index().String(), batchWitnesses)
	if err != nil {
		return fmt.Errorf("failed to get witnesses: %w", err)
	}
	witnessesIRI = append(witnessesIRI, vocab.PublicIRI)
	startTime := time.Now()
	endTime := startTime.Add(c.maxWitnessDelay)
	offer := vocab.NewOfferActivity(
		vocab.NewObjectProperty(
			vocab.WithAnchorEvent(anchorEvent),
		),
		vocab.WithTo(witnessesIRI...),
		vocab.WithStartTime(&startTime),
		vocab.WithEndTime(&endTime),
		vocab.WithTarget(vocab.NewObjectProperty(vocab.WithIRI(vocab.AnchorWitnessTargetIRI))),
	)
	postID, err := c.Outbox.Post(offer)
	if err != nil {
		return fmt.Errorf("failed to post offer for anchor index[%s]: %w", anchorEvent.Index(), err)
	}
	logger.Debugf("created pre-announce activity for anchor index[%s], post id[%s]", anchorEvent.Index(), postID)
	if len(witnessesIRI) == 1 {
		logger.Debugf("According to witness policy, no witnesses are required for anchor index[%s]. "+
			"Processing the anchor immediately.", anchorEvent.Index())
		localProofBytes, e := json.Marshal(localProof)
		if err != nil {
			return fmt.Errorf("marshal localProof: %w", e)
		}
		e = c.ProofHandler.HandleProof(c.apServiceIRI, anchorEvent.Index().String(), endTime, localProofBytes)
		if e != nil {
			return fmt.Errorf("handle offer with no witnesses: %w", e)
		}
	}
	return nil
}
func ( c * Writer ) postOfferActivity ( anchorEvent * vocab . AnchorEventType , localProof vocab . Document , batchWitnesses [ ] string ) error { postOfferActivityStartTime := time . Now ( ) defer c . metrics . WriteAnchorPostOfferActivityTime ( time . Since ( postOfferActivityStartTime ) ) logger . Debugf ( " " , anchorEvent . Index ( ) , batchWitnesses ) witnessesIRI , err := c . getWitnesses ( anchorEvent . Index ( ) . String ( ) , batchWitnesses ) if err != nil { return fmt . Errorf ( " " , err ) } witnessesIRI = append ( witnessesIRI , vocab . PublicIRI ) startTime := time . Now ( ) endTime := startTime . Add ( c . maxWitnessDelay ) offer := vocab . NewOfferActivity ( vocab . NewObjectProperty ( vocab . WithAnchorEvent ( anchorEvent ) , ) , vocab . WithTo ( witnessesIRI ... ) , vocab . WithStartTime ( & startTime ) , vocab . WithEndTime ( & endTime ) , vocab . WithTarget ( vocab . NewObjectProperty ( vocab . WithIRI ( vocab . AnchorWitnessTargetIRI ) ) ) , ) postID , err := c . Outbox . Post ( offer ) if err != nil { return fmt . Errorf ( " " , anchorEvent . Index ( ) , err ) } logger . Debugf ( " " , anchorEvent . Index ( ) , postID ) if len ( witnessesIRI ) == 1 { logger . Debugf ( " " + " " , anchorEvent . Index ( ) ) localProofBytes , e := json . Marshal ( localProof ) if err != nil { return fmt . Errorf ( " " , e ) } e = c . ProofHandler . HandleProof ( c . apServiceIRI , anchorEvent . Index ( ) . String ( ) , endTime , localProofBytes ) if e != nil { return fmt . Errorf ( " " , e ) } } return nil }
postOfferActivity creates and posts offer activity (requests witnessing of anchor credential).
postOfferActivity creates and posts offer activity ( requests witnessing of anchor credential ) .
// The Offer was posted only to the public IRI. This means that it will be persisted // in the ActivityPub Outbox (to be viewed by anyone) but won't be sent to any service. // In this case we can handle the anchor event immediately. // Handle the anchor event by providing this service's proof.