// Put saves witnesses into anchor witness store.
Put saves witnesses into anchor witness store.
// Put saves witnesses into anchor witness store .
func (s *Store) Put(anchorID string, witnesses []*proof.Witness) error {
	operations := make([]storage.Operation, len(witnesses))
	anchorIDEncoded := base64.RawURLEncoding.EncodeToString([]byte(anchorID))
	putOptions := &storage.PutOptions{IsNewKey: true}
	for i, w := range witnesses {
		value, err := json.Marshal(w)
		if err != nil {
			return fmt.Errorf("failed to marshal anchor witness: %w", err)
		}
		logger.Debugf("adding %s witness to storage batch: %s", w.Type, w.URI)
		op := storage.Operation{
			Key:   uuid.New().String(),
			Value: value,
			Tags: []storage.Tag{
				{
					Name:  anchorIndex,
					Value: anchorIDEncoded,
				},
				{
					Name:  expiryTagName,
					Value: fmt.Sprintf("%d", time.Now().Add(s.maxWitnessDelay+s.delta).Unix()),
				},
			},
			PutOptions: putOptions,
		}
		operations[i] = op
	}
	err := s.store.Batch(operations)
	if err != nil {
		return orberrors.NewTransient(fmt.Errorf("failed to store witnesses for anchorID[%s]: %w", anchorID, err))
	}
	logger.Debugf("stored %d witnesses for anchorID[%s]", len(witnesses), anchorID)
	return nil
}
func ( s * Store ) Put ( anchorID string , witnesses [ ] * proof . Witness ) error { operations := make ( [ ] storage . Operation , len ( witnesses ) ) anchorIDEncoded := base64 . RawURLEncoding . EncodeToString ( [ ] byte ( anchorID ) ) putOptions := & storage . PutOptions { IsNewKey : true } for i , w := range witnesses { value , err := json . Marshal ( w ) if err != nil { return fmt . Errorf ( " " , err ) } logger . Debugf ( " " , w . Type , w . URI ) op := storage . Operation { Key : uuid . New ( ) . String ( ) , Value : value , Tags : [ ] storage . Tag { { Name : anchorIndex , Value : anchorIDEncoded , } , { Name : expiryTagName , Value : fmt . Sprintf ( " " , time . Now ( ) . Add ( s . maxWitnessDelay + s . delta ) . Unix ( ) ) , } , } , PutOptions : putOptions , } operations [ i ] = op } err := s . store . Batch ( operations ) if err != nil { return orberrors . NewTransient ( fmt . Errorf ( " " , anchorID , err ) ) } logger . Debugf ( " " , len ( witnesses ) , anchorID ) return nil }
Put saves witnesses into anchor witness store.
Put saves witnesses into anchor witness store .