// AddProof adds proof for anchor id and witness.
AddProof adds proof for anchor id and witness.
// AddProof adds proof for anchor id and witness .
func (s *Store) AddProof(anchorID string, witness *url.URL, p []byte) 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)
	}
	updatedNo := 0
	for ok {
		var value []byte
		value, err = iter.Value()
		if err != nil {
			return fmt.Errorf("failed to get iterator value for anchorID[%s]: %w", anchorID, err)
		}
		var w proof.WitnessProof
		err = json.Unmarshal(value, &w)
		if err != nil {
			return fmt.Errorf("failed to unmarshal anchor witness from store value for anchorID[%s]: %w",
				anchorID, err)
		}
		if w.URI.String() == witness.String() {
			var key string
			key, err = iter.Key()
			if err != nil {
				return fmt.Errorf("failed to get key for anchorID[%s] and witness[%s]: %w",
					anchorID, witness, err)
			}
			w.Proof = p
			witnessProofBytes, marshalErr := json.Marshal(w)
			if marshalErr != nil {
				return fmt.Errorf("failed to marshal witness[%s] proof for anchorID[%s]: %w", w.URI, anchorID, marshalErr)
			}
			err = s.store.Put(key, witnessProofBytes, storage.Tag{Name: anchorIndex, Value: anchorIDEncoded})
			if err != nil {
				return orberrors.NewTransient(fmt.Errorf("failed to add proof for anchorID[%s] and witness[%s]: %w",
					anchorID, witness, err))
			}
			updatedNo++
			logger.Debugf("added proof for anchorID[%s] and witness[%s]: %s", anchorID, witness, string(p))
		}
		ok, err = iter.Next()
		if err != nil {
			return fmt.Errorf("iterator error for anchorID[%s] : %w", anchorID, err)
		}
	}
	if updatedNo == 0 {
		return fmt.Errorf("witness[%s] not found for anchorID[%s]", witness, anchorID)
	}
	return nil
}
func ( s * Store ) AddProof ( anchorID string , witness * url . URL , p [ ] byte ) 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 ) } updatedNo := 0 for ok { var value [ ] byte value , err = iter . Value ( ) if err != nil { return fmt . Errorf ( " " , anchorID , err ) } var w proof . WitnessProof err = json . Unmarshal ( value , & w ) if err != nil { return fmt . Errorf ( " " , anchorID , err ) } if w . URI . String ( ) == witness . String ( ) { var key string key , err = iter . Key ( ) if err != nil { return fmt . Errorf ( " " , anchorID , witness , err ) } w . Proof = p witnessProofBytes , marshalErr := json . Marshal ( w ) if marshalErr != nil { return fmt . Errorf ( " " , w . URI , anchorID , marshalErr ) } err = s . store . Put ( key , witnessProofBytes , storage . Tag { Name : anchorIndex , Value : anchorIDEncoded } ) if err != nil { return orberrors . NewTransient ( fmt . Errorf ( " " , anchorID , witness , err ) ) } updatedNo ++ logger . Debugf ( " " , anchorID , witness , string ( p ) ) } ok , err = iter . Next ( ) if err != nil { return fmt . Errorf ( " " , anchorID , err ) } } if updatedNo == 0 { return fmt . Errorf ( " " , witness , anchorID ) } return nil }
AddProof adds proof for anchor id and witness.
AddProof adds proof for anchor id and witness .
//nolint:funlen,gocyclo,cyclop