// WriteAnchor writes Sidetree anchor string to Orb anchor.
WriteAnchor writes Sidetree anchor string to Orb anchor.
// WriteAnchor writes Sidetree anchor string to Orb anchor .
func (c *Writer) WriteAnchor(anchor string, attachments []*protocol.AnchorDocument,
	refs []*operation.Reference, version uint64) error {
	startTime := time.Now()
	defer func() { c.metrics.WriteAnchorTime(time.Since(startTime)) }()
	previousAnchors, err := c.getPreviousAnchors(refs)
	if err != nil {
		return fmt.Errorf("get previous anchors: %w", err)
	}
	ad, err := util.ParseAnchorString(anchor)
	if err != nil {
		return fmt.Errorf("parse anchor string [%s]: %w", anchor, err)
	}
	now := time.Now()
	payload := &subject.Payload{
		OperationCount:  ad.OperationCount,
		CoreIndex:       ad.CoreIndexFileURI,
		Namespace:       c.namespace,
		Version:         version,
		PreviousAnchors: previousAnchors,
		Attachments:     getAttachmentURIs(attachments),
		AnchorOrigin:    c.apServiceIRI.String(),
		Published:       &now,
	}
	batchWitnesses, err := c.getWitnessesFromBatchOperations(refs)
	if err != nil {
		return fmt.Errorf("failed to create witness list: %w", err)
	}
	anchorEvent, vc, err := c.buildAnchorEvent(payload, batchWitnesses, c.anchorAttachmentMediaType)
	if err != nil {
		return fmt.Errorf("build anchor event for anchor [%s]: %w", anchor, err)
	}
	storeStartTime := time.Now()
	err = c.AnchorEventStore.Put(anchorEvent)
	if err != nil {
		return fmt.Errorf("store anchor event: %w", err)
	}
	c.metrics.WriteAnchorStoreTime(time.Since(storeStartTime))
	logger.Debugf("signed and stored anchor event %s for anchor: %s", anchorEvent.Index(), anchor)
	err = c.postOfferActivity(anchorEvent, vc, batchWitnesses)
	if err != nil {
		return fmt.Errorf("failed to post new offer activity for anchor event %s: %w",
			anchorEvent.Index(), err)
	}
	return nil
}
func ( c * Writer ) WriteAnchor ( anchor string , attachments [ ] * protocol . AnchorDocument , refs [ ] * operation . Reference , version uint64 ) error { startTime := time . Now ( ) defer func ( ) { c . metrics . WriteAnchorTime ( time . Since ( startTime ) ) } ( ) previousAnchors , err := c . getPreviousAnchors ( refs ) if err != nil { return fmt . Errorf ( " " , err ) } ad , err := util . ParseAnchorString ( anchor ) if err != nil { return fmt . Errorf ( " " , anchor , err ) } now := time . Now ( ) payload := & subject . Payload { OperationCount : ad . OperationCount , CoreIndex : ad . CoreIndexFileURI , Namespace : c . namespace , Version : version , PreviousAnchors : previousAnchors , Attachments : getAttachmentURIs ( attachments ) , AnchorOrigin : c . apServiceIRI . String ( ) , Published : & now , } batchWitnesses , err := c . getWitnessesFromBatchOperations ( refs ) if err != nil { return fmt . Errorf ( " " , err ) } anchorEvent , vc , err := c . buildAnchorEvent ( payload , batchWitnesses , c . anchorAttachmentMediaType ) if err != nil { return fmt . Errorf ( " " , anchor , err ) } storeStartTime := time . Now ( ) err = c . AnchorEventStore . Put ( anchorEvent ) if err != nil { return fmt . Errorf ( " " , err ) } c . metrics . WriteAnchorStoreTime ( time . Since ( storeStartTime ) ) logger . Debugf ( " " , anchorEvent . Index ( ) , anchor ) err = c . postOfferActivity ( anchorEvent , vc , batchWitnesses ) if err != nil { return fmt . Errorf ( " " , anchorEvent . Index ( ) , err ) } return nil }
WriteAnchor writes Sidetree anchor string to Orb anchor.
WriteAnchor writes Sidetree anchor string to Orb anchor .
// get previous anchors for each did that is referenced in this anchor // figure out witness list for this anchor file // send an offer activity to witnesses (request witnessing anchor credential from non-local witness logs)