github.com/hyperledger/aries-framework-go@v0.3.2/pkg/didcomm/protocol/issuecredential/properties.go (about)

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package issuecredential
     8  
     9  import "errors"
    10  
    11  const (
    12  	myDIDPropKey    = "myDID"
    13  	theirDIDPropKey = "theirDID"
    14  	piidPropKey     = "piid"
    15  	errorPropKey    = "error"
    16  )
    17  
    18  type eventProps struct {
    19  	properties map[string]interface{}
    20  	myDID      string
    21  	theirDID   string
    22  	piid       string
    23  	err        error
    24  }
    25  
    26  func newEventProps(md *MetaData) *eventProps {
    27  	properties := md.properties
    28  	if properties == nil {
    29  		properties = map[string]interface{}{}
    30  	}
    31  
    32  	return &eventProps{
    33  		properties: properties,
    34  		myDID:      md.MyDID,
    35  		theirDID:   md.TheirDID,
    36  		piid:       md.PIID,
    37  		err:        md.err,
    38  	}
    39  }
    40  
    41  func (e *eventProps) MyDID() string {
    42  	return e.myDID
    43  }
    44  
    45  func (e *eventProps) TheirDID() string {
    46  	return e.theirDID
    47  }
    48  
    49  func (e *eventProps) PIID() string {
    50  	return e.piid
    51  }
    52  
    53  func (e eventProps) Err() error {
    54  	if errors.As(e.err, &customError{}) {
    55  		return nil
    56  	}
    57  
    58  	return e.err
    59  }
    60  
    61  // All implements EventProperties interface.
    62  func (e eventProps) All() map[string]interface{} {
    63  	props := map[string]interface{}{}
    64  
    65  	for k, v := range e.properties {
    66  		props[k] = v
    67  	}
    68  
    69  	if e.myDID != "" {
    70  		props[myDIDPropKey] = e.myDID
    71  	}
    72  
    73  	if e.theirDID != "" {
    74  		props[theirDIDPropKey] = e.theirDID
    75  	}
    76  
    77  	if e.piid != "" {
    78  		props[piidPropKey] = e.piid
    79  	}
    80  
    81  	if e.Err() != nil {
    82  		props[errorPropKey] = e.Err()
    83  	}
    84  
    85  	return props
    86  }