private void loadExtensions(
     Wallet wallet, WalletExtension[] extensionsList, Protos.Wallet walletProto)
     throws UnreadableWalletException {
   final Map<String, WalletExtension> extensions = new HashMap<String, WalletExtension>();
   for (WalletExtension e : extensionsList) extensions.put(e.getWalletExtensionID(), e);
   // The Wallet object, if subclassed, might have added some extensions to itself already. In that
   // case, don't
   // expect them to be passed in, just fetch them here and don't re-add.
   extensions.putAll(wallet.getExtensions());
   for (Protos.Extension extProto : walletProto.getExtensionList()) {
     String id = extProto.getId();
     WalletExtension extension = extensions.get(id);
     if (extension == null) {
       if (extProto.getMandatory()) {
         if (requireMandatoryExtensions)
           throw new UnreadableWalletException("Unknown mandatory extension in wallet: " + id);
         else log.error("Unknown extension in wallet {}, ignoring", id);
       }
     } else {
       log.info("Loading wallet extension {}", id);
       try {
         extension.deserializeWalletExtension(wallet, extProto.getData().toByteArray());
         wallet.addOrGetExistingExtension(extension);
       } catch (Exception e) {
         if (extProto.getMandatory() && requireMandatoryExtensions)
           throw new UnreadableWalletException(
               "Could not parse mandatory extension in wallet: " + id);
         else log.error("Error whilst reading extension {}, ignoring", id, e);
       }
     }
   }
 }
 private static void populateExtensions(Wallet wallet, Protos.Wallet.Builder walletBuilder) {
   for (WalletExtension extension : wallet.getExtensions().values()) {
     Protos.Extension.Builder proto = Protos.Extension.newBuilder();
     proto.setId(extension.getWalletExtensionID());
     proto.setMandatory(extension.isWalletExtensionMandatory());
     proto.setData(ByteString.copyFrom(extension.serializeWalletExtension()));
     walletBuilder.addExtension(proto);
   }
 }
Ejemplo n.º 3
0
 private static void loadExtensions(Wallet wallet, Protos.Wallet walletProto) {
   final Map<String, WalletExtension> extensions = wallet.getExtensions();
   for (Protos.Extension extProto : walletProto.getExtensionList()) {
     String id = extProto.getId();
     WalletExtension extension = extensions.get(id);
     if (extension == null) {
       if (extProto.getMandatory()) {
         throw new IllegalArgumentException("Unknown mandatory extension in wallet: " + id);
       }
     } else {
       log.info("Loading wallet extension {}", id);
       try {
         extension.deserializeWalletExtension(wallet, extProto.getData().toByteArray());
       } catch (Exception e) {
         if (extProto.getMandatory())
           throw new IllegalArgumentException("Unknown mandatory extension in wallet: " + id);
       }
     }
   }
 }