// Put saves an unpublished operation. If it already exists it will be overwritten.
Put saves an unpublished operation. If it already exists it will be overwritten.
// Put saves an unpublished operation . If it already exists it will be overwritten .
func (s *Store) Put(op *operation.AnchoredOperation) error {
	startTime := time.Now()
	defer func() {
		s.metrics.PutUnpublishedOperation(time.Since(startTime))
	}()
	if op.UniqueSuffix == "" {
		return fmt.Errorf("failed to save unpublished operation: suffix is empty")
	}
	opBytes, err := json.Marshal(op)
	if err != nil {
		return fmt.Errorf("failed to marshal unpublished operation: %w", err)
	}
	logger.Debugf("storing unpublished '%s' operation for suffix[%s]: %s", op.Type, op.UniqueSuffix, string(opBytes))
	tags := []storage.Tag{
		{
			Name:  index,
			Value: op.UniqueSuffix,
		},
		{
			Name:  expiryTagName,
			Value: fmt.Sprintf("%d", time.Now().Add(s.unpublishedOperationLifespan).Unix()),
		},
	}
	calculateKeyStartTime := time.Now()
	key, err := hashing.CalculateModelMultihash(op.OperationRequest, sha2_256)
	if err != nil {
		return fmt.Errorf("failed to generate key for unpublished operation for suffix[%s]: %w", op.UniqueSuffix, err)
	}
	s.metrics.CalculateUnpublishedOperationKey(time.Since(calculateKeyStartTime))
	if err := s.store.Put(key, opBytes, tags...); err != nil {
		return fmt.Errorf("failed to put unpublished operation for suffix[%s]: %w", op.UniqueSuffix, err)
	}
	return nil
}
func ( s * Store ) Put ( op * operation . AnchoredOperation ) error { startTime := time . Now ( ) defer func ( ) { s . metrics . PutUnpublishedOperation ( time . Since ( startTime ) ) } ( ) if op . UniqueSuffix == " " { return fmt . Errorf ( " " ) } opBytes , err := json . Marshal ( op ) if err != nil { return fmt . Errorf ( " " , err ) } logger . Debugf ( " " , op . Type , op . UniqueSuffix , string ( opBytes ) ) tags := [ ] storage . Tag { { Name : index , Value : op . UniqueSuffix , } , { Name : expiryTagName , Value : fmt . Sprintf ( " " , time . Now ( ) . Add ( s . unpublishedOperationLifespan ) . Unix ( ) ) , } , } calculateKeyStartTime := time . Now ( ) key , err := hashing . CalculateModelMultihash ( op . OperationRequest , sha2_256 ) if err != nil { return fmt . Errorf ( " " , op . UniqueSuffix , err ) } s . metrics . CalculateUnpublishedOperationKey ( time . Since ( calculateKeyStartTime ) ) if err := s . store . Put ( key , opBytes , tags ... ) ; err != nil { return fmt . Errorf ( " " , op . UniqueSuffix , err ) } return nil }
Put saves an unpublished operation.
Put saves an unpublished operation .