// CreatePayload creates a payload from the given anchor event.
CreatePayload creates a payload from the given anchor event.
// CreatePayload creates a payload from the given anchor event .
func (g *Generator) CreatePayload(anchorEvent *vocab.AnchorEventType) (*subject.Payload, error) {
	anchorObj, err := anchorEvent.AnchorObject(anchorEvent.Index())
	if err != nil {
		return nil, fmt.Errorf("anchor object for [%s]: %w", anchorEvent.Index(), err)
	}
	contentObj := &contentObject{}
	err = anchorObj.ContentObject().Unmarshal(contentObj)
	if err != nil {
		return nil, fmt.Errorf("unmarshal content object: %w", err)
	}
	if contentObj.Subject == "" {
		return nil, fmt.Errorf("content object is missing subject")
	}
	resources := contentObj.Resources()
	operationCount := uint64(len(resources))
	prevAnchors, err := g.getPreviousAnchors(resources, anchorEvent.Parent())
	if err != nil {
		return nil, fmt.Errorf("failed to parse previous anchors from anchorEvent: %w", err)
	}
	return &subject.Payload{
		Namespace:       g.namespace,
		Version:         g.version,
		CoreIndex:       contentObj.Subject,
		OperationCount:  operationCount,
		PreviousAnchors: prevAnchors,
		AnchorOrigin:    anchorEvent.AttributedTo().String(),
		Published:       anchorEvent.Published(),
	}, nil
}
func ( g * Generator ) CreatePayload ( anchorEvent * vocab . AnchorEventType ) ( * subject . Payload , error ) { anchorObj , err := anchorEvent . AnchorObject ( anchorEvent . Index ( ) ) if err != nil { return nil , fmt . Errorf ( " " , anchorEvent . Index ( ) , err ) } contentObj := & contentObject { } err = anchorObj . ContentObject ( ) . Unmarshal ( contentObj ) if err != nil { return nil , fmt . Errorf ( " " , err ) } if contentObj . Subject == " " { return nil , fmt . Errorf ( " " ) } resources := contentObj . Resources ( ) operationCount := uint64 ( len ( resources ) ) prevAnchors , err := g . getPreviousAnchors ( resources , anchorEvent . Parent ( ) ) if err != nil { return nil , fmt . Errorf ( " " , err ) } return & subject . Payload { Namespace : g . namespace , Version : g . version , CoreIndex : contentObj . Subject , OperationCount : operationCount , PreviousAnchors : prevAnchors , AnchorOrigin : anchorEvent . AttributedTo ( ) . String ( ) , Published : anchorEvent . Published ( ) , } , nil }
CreatePayload creates a payload from the given anchor event.
CreatePayload creates a payload from the given anchor event .