examples/appnet-api-server/src/main/java/com/hedera/hashgraph/identity/hcs/example/appnet/AppnetStorage.java
/**
   * Stores a newly received DID message in the local storage.
   * Before storing it, validates if the message is not a duplicate and if it is valid.
   *
   * @param envelope The DID message in an envelope.
   */
Stores a newly received DID message in the local storage.
Before storing it, validates if the message is not a duplicate and if it is valid.

@param envelope The DID message in an envelope.
Stores a newly received DID message in the local storage . Before storing it validates if the message is not a duplicate and if it is valid . @param envelope The DID message in an envelope .
public void storeDid(final MessageEnvelope<HcsDidMessage> envelope) {
    if (envelope == null) {
      log.warn("Empty envelope received, message ignored.");
      return;
    }
    if (signatures.contains(envelope.getSignature())) {
      log.warn("Duplicate message signature detected, message ignored: " + envelope.getSignature());
      return;
    }
    signatures.add(envelope.getSignature());
    persistSignatures();
    HcsDidMessage msg = envelope.open();
    HcsDidMessage existing = didStorage.get(msg.getDid());
    if (existing != null
            && (envelope.getConsensusTimestamp().isBefore(existing.getUpdated())
            || (DidMethodOperation.DELETE.equals(existing.getOperation())
            && !DidMethodOperation.DELETE.equals(msg.getOperation())))) {
      log.warn("Outdated DID message received, ignored.");
      return;
    }
    msg.setUpdated(envelope.getConsensusTimestamp());
    if (DidMethodOperation.CREATE.equals(msg.getOperation())) {
      msg.setCreated(envelope.getConsensusTimestamp());
    } else if (existing != null) {
      msg.setCreated(existing.getCreated());
    }
    log.info("New DID message " + msg.getOperation() + " received for: " + msg.getDid());
    didStorage.put(msg.getDid(), msg);
    persistDiDs(envelope.getConsensusTimestamp());
  }
public void storeDid ( final MessageEnvelope < HcsDidMessage > envelope ) { if ( envelope == null ) { log . warn ( "Empty envelope received, message ignored." ) ; return ; } if ( signatures . contains ( envelope . getSignature ( ) ) ) { log . warn ( "Duplicate message signature detected, message ignored: " + envelope . getSignature ( ) ) ; return ; } signatures . add ( envelope . getSignature ( ) ) ; persistSignatures ( ) ; HcsDidMessage msg = envelope . open ( ) ; HcsDidMessage existing = didStorage . get ( msg . getDid ( ) ) ; if ( existing != null && ( envelope . getConsensusTimestamp ( ) . isBefore ( existing . getUpdated ( ) ) || ( DidMethodOperation . DELETE . equals ( existing . getOperation ( ) ) && ! DidMethodOperation . DELETE . equals ( msg . getOperation ( ) ) ) ) ) { log . warn ( "Outdated DID message received, ignored." ) ; return ; } msg . setUpdated ( envelope . getConsensusTimestamp ( ) ) ; if ( DidMethodOperation . CREATE . equals ( msg . getOperation ( ) ) ) { msg . setCreated ( envelope . getConsensusTimestamp ( ) ) ; } else if ( existing != null ) { msg . setCreated ( existing . getCreated ( ) ) ; } log . info ( "New DID message " + msg . getOperation ( ) + " received for: " + msg . getDid ( ) ) ; didStorage . put ( msg . getDid ( ) , msg ) ; persistDiDs ( envelope . getConsensusTimestamp ( ) ) ; }
Stores a newly received DID message in the local storage.
Stores a newly received DID message in the local storage .
// Preserve created and updated timestamps