// Delete deletes all witnesses associated with anchor ID.
Delete deletes all witnesses associated with anchor ID.
// Delete deletes all witnesses associated with anchor ID .
func (s *Store) Delete(anchorID string) error {
	var err error
	anchorIDEncoded := base64.RawURLEncoding.EncodeToString([]byte(anchorID))
	query := fmt.Sprintf("%s:%s", anchorIndex, anchorIDEncoded)
	iter, err := s.store.Query(query)
	if err != nil {
		return orberrors.NewTransient(fmt.Errorf("failed to get witnesses for[%s]: %w", query, err))
	}
	defer func() {
		err = iter.Close()
		if err != nil {
			logger.Errorf("failed to close iterator: %s", err.Error())
		}
	}()
	ok, err := iter.Next()
	if err != nil {
		return fmt.Errorf("iterator error for anchorID[%s] : %w", anchorID, err)
	}
	if !ok {
		logger.Debugf("no witnesses to delete for anchorID[%s], nothing to do", anchorID)
		return nil
	}
	var witnessKeys []string
	for ok {
		var key string
		key, err = iter.Key()
		if err != nil {
			return fmt.Errorf("failed to get iterator value for anchorID[%s]: %w", anchorID, err)
		}
		witnessKeys = append(witnessKeys, key)
		ok, err = iter.Next()
		if err != nil {
			return fmt.Errorf("iterator error for anchorID[%s] : %w", anchorID, err)
		}
	}
	operations := make([]storage.Operation, len(witnessKeys))
	for i, k := range witnessKeys {
		operations[i] = storage.Operation{Key: k}
	}
	err = s.store.Batch(operations)
	if err != nil {
		return orberrors.NewTransient(fmt.Errorf("failed to delete witnesses for anchorID[%s]: %w", anchorID, err))
	}
	logger.Debugf("deleted %d witnesses for anchorID[%s]", len(witnessKeys), anchorID)
	return nil
}
func ( s * Store ) Delete ( anchorID string ) error { var err error anchorIDEncoded := base64 . RawURLEncoding . EncodeToString ( [ ] byte ( anchorID ) ) query := fmt . Sprintf ( " " , anchorIndex , anchorIDEncoded ) iter , err := s . store . Query ( query ) if err != nil { return orberrors . NewTransient ( fmt . Errorf ( " " , query , err ) ) } defer func ( ) { err = iter . Close ( ) if err != nil { logger . Errorf ( " " , err . Error ( ) ) } } ( ) ok , err := iter . Next ( ) if err != nil { return fmt . Errorf ( " " , anchorID , err ) } if ! ok { logger . Debugf ( " " , anchorID ) return nil } var witnessKeys [ ] string for ok { var key string key , err = iter . Key ( ) if err != nil { return fmt . Errorf ( " " , anchorID , err ) } witnessKeys = append ( witnessKeys , key ) ok , err = iter . Next ( ) if err != nil { return fmt . Errorf ( " " , anchorID , err ) } } operations := make ( [ ] storage . Operation , len ( witnessKeys ) ) for i , k := range witnessKeys { operations [ i ] = storage . Operation { Key : k } } err = s . store . Batch ( operations ) if err != nil { return orberrors . NewTransient ( fmt . Errorf ( " " , anchorID , err ) ) } logger . Debugf ( " " , len ( witnessKeys ) , anchorID ) return nil }
Delete deletes all witnesses associated with anchor ID.
Delete deletes all witnesses associated with anchor ID .