// Update updates an 'accept list' of the given type with the given additions and deletions.
Update updates an 'accept list' of the given type with the given additions and deletions.
// Update updates an ' accept list ' of the given type with the given additions and deletions .
func (m *Manager) Update(acceptType string, additions, deletions []*url.URL) error {
	current, err := m.Get(acceptType)
	if err != nil {
		return fmt.Errorf("query accept list: %w", err)
	}
	additions = removeDuplicates(current, additions)
	var operations []storage.Operation
	for _, uri := range additions {
		value, e := json.Marshal(uri.String())
		if e != nil {
			return fmt.Errorf("marshal URI [%s]: %w", uri, e)
		}
		operations = append(operations, storage.Operation{
			Key:   newKey(acceptType, uri),
			Value: value,
			Tags: []storage.Tag{
				{Name: newTag("")},
				{Name: newTag(acceptType)},
			},
		})
	}
	for _, uri := range deletions {
		operations = append(operations, storage.Operation{
			Key: newKey(acceptType, uri),
		})
	}
	if len(operations) == 0 {
		logger.Debugf("No new additions or deletions for type [%s].", acceptType)
		return nil
	}
	err = m.store.Batch(operations)
	if err != nil {
		return orberrors.NewTransient(fmt.Errorf("batch update: %w", err))
	}
	logger.Debugf("Successfully updated the accept list [%s] - Additions: %s, Deletions: %s",
		acceptType, additions, deletions)
	return nil
}
func ( m * Manager ) Update ( acceptType string , additions , deletions [ ] * url . URL ) error { current , err := m . Get ( acceptType ) if err != nil { return fmt . Errorf ( " " , err ) } additions = removeDuplicates ( current , additions ) var operations [ ] storage . Operation for _ , uri := range additions { value , e := json . Marshal ( uri . String ( ) ) if e != nil { return fmt . Errorf ( " " , uri , e ) } operations = append ( operations , storage . Operation { Key : newKey ( acceptType , uri ) , Value : value , Tags : [ ] storage . Tag { { Name : newTag ( " " ) } , { Name : newTag ( acceptType ) } , } , } ) } for _ , uri := range deletions { operations = append ( operations , storage . Operation { Key : newKey ( acceptType , uri ) , } ) } if len ( operations ) == 0 { logger . Debugf ( " " , acceptType ) return nil } err = m . store . Batch ( operations ) if err != nil { return orberrors . NewTransient ( fmt . Errorf ( " " , err ) ) } logger . Debugf ( " " , acceptType , additions , deletions ) return nil }
Update updates an 'accept list' of the given type with the given additions and deletions.
Update updates an ' accept list ' of the given type with the given additions and deletions .