コード例 #1
0
 public void distributeAssets(
     HashMap<DigitalAssetMetadata, ActorAssetUser> digitalAssetsToDistribute)
     throws CantDistributeDigitalAssetsException {
   try {
     System.out.println(
         "ASSET DISTRIBUTION DistributionMap size:" + digitalAssetsToDistribute.size());
     for (Map.Entry<DigitalAssetMetadata, ActorAssetUser> entry :
         digitalAssetsToDistribute.entrySet()) {
       DigitalAssetMetadata digitalAssetMetadata = entry.getKey();
       ActorAssetUser actorAssetUser = entry.getValue();
       // Deliver one DigitalAsset
       System.out.println(
           "ASSET DISTRIBUTION DAM-Hash:" + digitalAssetMetadata.getDigitalAssetHash());
       System.out.println(
           "ASSET DISTRIBUTION ActorAssetUser - PublicKey:" + actorAssetUser.getActorPublicKey());
       System.out.println("ASSET DISTRIBUTION ActorAssetUser - Name:" + actorAssetUser.getName());
       deliverDigitalAssetToRemoteDevice(digitalAssetMetadata, actorAssetUser);
     }
   } catch (CantDeliverDigitalAssetException exception) {
     this.errorManager.reportUnexpectedPluginException(
         Plugins.BITDUBAI_ASSET_DISTRIBUTION_TRANSACTION,
         UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN,
         exception);
   } catch (Exception exception) {
     throw new CantDistributeDigitalAssetsException(
         exception, "Distributing Assets", "Unexpected exception");
   }
 }
  private void testDigitalAssetMetadataVault()
      throws CantCreateDigitalAssetFileException, CantGetDigitalAssetFromLocalStorageException {
    Logger LOG = Logger.getGlobal();
    LOG.info("MAP_TEST_DAMVault");
    DigitalAsset digitalAsset = new DigitalAsset();
    digitalAsset.setGenesisAmount(100000);
    digitalAsset.setDescription("TestAsset");
    digitalAsset.setName("testName");
    digitalAsset.setPublicKey(new ECCKeyPair().getPublicKey());
    LOG.info("MAP_DigitalAsset:" + digitalAsset);
    List<Resource> resources = new ArrayList<>();
    digitalAsset.setResources(resources);

    digitalAsset.setIdentityAssetIssuer(null);
    DigitalAssetContract digitalAssetContract = new DigitalAssetContract();
    digitalAsset.setContract(digitalAssetContract);
    LOG.info("MAP_DigitalAsset2:" + digitalAsset);
    DigitalAssetMetadata dam = new DigitalAssetMetadata(digitalAsset);
    dam.setGenesisTransaction("testGenesisTX");
    this.digitalAssetIssuingVault.persistDigitalAssetMetadataInLocalStorage(dam, "testId");
    LOG.info(
        "DAM from vault:\n"
            + this.digitalAssetIssuingVault
                .getDigitalAssetMetadataFromLocalStorage("testGenesisTX")
                .toString());
  }
コード例 #3
0
  public void persistInLocalStorage(DigitalAssetMetadata digitalAssetMetadata)
      throws CantCreateDigitalAssetFileException {
    try {
      System.out.println(
          "ASSET DISTRIBUTION Internal Id: " + digitalAssetMetadata.getGenesisTransaction());
      this.assetDistributionDao.persistDistributionId(
          digitalAssetMetadata.getGenesisTransaction(),
          digitalAssetMetadata.getGenesisTransaction());
      this.digitalAssetDistributionVault.persistDigitalAssetMetadataInLocalStorage(
          digitalAssetMetadata, digitalAssetMetadata.getGenesisTransaction());

      //            System.out.println("ASSET DISTRIBUTION Internal Id: " +
      // digitalAssetMetadata.getDigitalAsset().getPublicKey());
      //
      // this.assetDistributionDao.persistDistributionId(digitalAssetMetadata.getGenesisTransaction(), digitalAssetMetadata.getDigitalAsset().getPublicKey());
      //
      // this.digitalAssetDistributionVault.persistDigitalAssetMetadataInLocalStorage(digitalAssetMetadata, digitalAssetMetadata.getDigitalAsset().getPublicKey());

    } catch (CantPersistsTransactionUUIDException exception) {
      throw new CantCreateDigitalAssetFileException(
          exception,
          "Persisting Internal distribution id",
          "Cannot update the internal Id by genesis transaction");
    }
  }
コード例 #4
0
 /** This method check if the DigitalAssetMetadata remains with not modifications */
 public void checkDigitalAssetMetadata(DigitalAssetMetadata digitalAssetMetadata)
     throws CantDeliverDigitalAssetException {
   try {
     String genesisTransactionFromDigitalAssetMetadata =
         digitalAssetMetadata.getGenesisTransaction();
     this.assetDistributionDao.updateDistributionStatusByGenesisTransaction(
         DistributionStatus.CHECKING_HASH, genesisTransactionFromDigitalAssetMetadata);
     String digitalAssetMetadataHash = digitalAssetMetadata.getDigitalAssetHash();
     List<CryptoTransaction> cryptoTransactionList =
         bitcoinNetworkManager.getCryptoTransaction(genesisTransactionFromDigitalAssetMetadata);
     if (cryptoTransactionList == null || cryptoTransactionList.isEmpty()) {
       throw new CantGetCryptoTransactionException(
           CantGetCryptoTransactionException.DEFAULT_MESSAGE,
           null,
           "Getting the genesis transaction from Crypto Network",
           "The crypto transaction received is null");
     }
     // This won't work until I can get the CryptoTransaction from AssetVault
     String op_ReturnFromAssetVault = cryptoTransaction.getOp_Return();
     if (!digitalAssetMetadataHash.equals(op_ReturnFromAssetVault)) {
       throw new CantDeliverDigitalAssetException(
           "Cannot deliver Digital Asset because the "
               + "Hash was modified:\n"
               + "Op_return:"
               + op_ReturnFromAssetVault
               + "\n"
               + "digitalAssetMetadata:"
               + digitalAssetMetadata);
     }
     this.assetDistributionDao.updateDistributionStatusByGenesisTransaction(
         DistributionStatus.HASH_CHECKED, genesisTransactionFromDigitalAssetMetadata);
   } catch (CantGetCryptoTransactionException exception) {
     throw new CantDeliverDigitalAssetException(
         exception,
         "Delivering the Digital Asset \n" + digitalAssetMetadata,
         "Cannot get the genesis transaction from Asset vault");
   } catch (CantExecuteQueryException exception) {
     throw new CantDeliverDigitalAssetException(
         exception,
         "Delivering the Digital Asset \n" + digitalAssetMetadata,
         "Cannot execute a database operation");
   } catch (UnexpectedResultReturnedFromDatabaseException exception) {
     throw new CantDeliverDigitalAssetException(
         exception,
         "Delivering the Digital Asset \n" + digitalAssetMetadata,
         "Unexpected result in database");
   }
 }
コード例 #5
0
 public static CryptoTransaction foundCryptoTransaction(
     BitcoinNetworkManager bitcoinNetworkManager, DigitalAssetMetadata digitalAssetMetadata)
     throws CantGetCryptoTransactionException {
   CryptoTransaction cryptoTransaction =
       bitcoinNetworkManager.getCryptoTransactionFromBlockChain(
           digitalAssetMetadata.getLastTransactionHash(),
           digitalAssetMetadata.getLastTransactionBlock());
   if (cryptoTransaction == null) {
     throw new CantGetCryptoTransactionException(
         CantGetCryptoTransactionException.DEFAULT_MESSAGE,
         null,
         "Getting the genesis transaction from Crypto Network",
         "The crypto transaction received is null");
   }
   return cryptoTransaction;
 }
 @Override
 public AppropriationTransactionRecord getTransaction(
     DigitalAssetMetadata digitalAssetMetadata,
     String assetIssuerWalletPublicKey,
     String bitcoinWalletPublicKey)
     throws RecordsNotFoundException, CantLoadAssetAppropriationTransactionListException {
   String context =
       "Asset: "
           + digitalAssetMetadata
           + " - User Wallet: "
           + assetIssuerWalletPublicKey
           + " - BTC Wallet: "
           + bitcoinWalletPublicKey;
   try {
     IssuerAppropriationDAO dao =
         new IssuerAppropriationDAO(pluginDatabaseSystem, pluginId, assetVault);
     return dao.getTransaction(
         digitalAssetMetadata.getDigitalAsset(),
         assetIssuerWalletPublicKey,
         bitcoinWalletPublicKey);
   } catch (RecordsNotFoundException
       | CantLoadAssetAppropriationTransactionListException
           e) { // If I don't catch these two they'll be elapsed by the exception catch block.
     throw e;
   } catch (Exception e) {
     throw new CantLoadAssetAppropriationTransactionListException(context, e);
   }
 }
コード例 #7
0
 private void deliverToRemoteActor(
     DigitalAssetMetadata digitalAssetMetadata, ActorAssetUser remoteActorAssetUser)
     throws CantSendDigitalAssetMetadataException {
   String genesisTransaction;
   try {
     System.out.println("ASSET DISTRIBUTION Preparing delivering to remote actor");
     genesisTransaction = digitalAssetMetadata.getGenesisTransaction();
     System.out.println("ASSET DISTRIBUTION Delivering genesis transaction " + genesisTransaction);
     this.assetDistributionDao.updateDistributionStatusByGenesisTransaction(
         DistributionStatus.DELIVERING, genesisTransaction);
     System.out.println(
         "ASSET DISTRIBUTION Sender Actor name: "
             + actorAssetIssuerManager.getActorAssetIssuer().getName());
     System.out.println("ASSET DISTRIBUTION Before deliver - remote asset user ");
     this.assetTransmissionNetworkServiceManager.sendDigitalAssetMetadata(
         actorAssetIssuerManager.getActorAssetIssuer(),
         remoteActorAssetUser,
         digitalAssetMetadata);
   } catch (CantExecuteQueryException exception) {
     throw new CantSendDigitalAssetMetadataException(
         UnexpectedResultReturnedFromDatabaseException.DEFAULT_MESSAGE,
         exception,
         "Delivering Digital Asset Metadata to Remote Actor",
         "There is an error executing a query in database");
   } catch (UnexpectedResultReturnedFromDatabaseException exception) {
     throw new CantSendDigitalAssetMetadataException(
         UnexpectedResultReturnedFromDatabaseException.DEFAULT_MESSAGE,
         exception,
         "Delivering Digital Asset Metadata to Remote Actor",
         "The database return an unexpected result");
   } catch (CantGetAssetIssuerActorsException e) {
     e.printStackTrace();
   }
 }
コード例 #8
0
 public static boolean isDigitalAssetComplete(DigitalAssetMetadata digitalAssetMetadata) {
   try {
     DigitalAsset digitalAsset = digitalAssetMetadata.getDigitalAsset();
     areObjectsSettled(digitalAsset);
     CryptoAddress genesisAddress = digitalAsset.getGenesisAddress();
     if (Validate.isObjectNull(genesisAddress)) {
       return false;
     }
     String digitalAssetHash = digitalAssetMetadata.getDigitalAssetHash();
     if (Validate.isValidString(digitalAssetHash)) {
       return false;
     }
     return true;
   } catch (ObjectNotSetException e) {
     return false;
   }
 }
コード例 #9
0
 public static boolean isDigitalAssetHashValid(
     BitcoinNetworkManager bitcoinNetworkManager, DigitalAssetMetadata digitalAssetMetadata)
     throws CantGetCryptoTransactionException, DAPException {
   String digitalAssetMetadataHash = digitalAssetMetadata.getDigitalAssetHash();
   CryptoTransaction cryptoTransaction =
       getCryptoTransactionFromCryptoNetwork(bitcoinNetworkManager, digitalAssetMetadata);
   String hashFromCryptoTransaction = cryptoTransaction.getOp_Return();
   return digitalAssetMetadataHash.equals(hashFromCryptoTransaction);
 }
コード例 #10
0
 public static CryptoTransaction getCryptoTransactionFromCryptoNetworkByCryptoStatus(
     BitcoinNetworkManager bitcoinNetworkManager,
     DigitalAssetMetadata digitalAssetMetadata,
     CryptoStatus cryptoStatus)
     throws CantGetCryptoTransactionException {
   List<CryptoTransaction> transactionListFromCryptoNetwork =
       bitcoinNetworkManager.getCryptoTransactions(digitalAssetMetadata.getLastTransactionHash());
   return matchStatus(transactionListFromCryptoNetwork, cryptoStatus);
 }
コード例 #11
0
 public void setDigitalAssetLocalFilePath(DigitalAssetMetadata digitalAssetMetadata) {
   // this.digitalAssetFileName=digitalAssetMetadata.getDigitalAssetHash()+".xml";
   this.digitalAssetFileStoragePath =
       this.LOCAL_STORAGE_PATH + "/" + digitalAssetMetadata.getDigitalAssetHash();
   this.digitalAssetDistributionVault.setDigitalAssetLocalFilePath(
       this.digitalAssetFileStoragePath);
   // this.digitalAssetFileName=digitalAssetMetadata.getDigitalAssetHash()+".xml";
   // this.digitalAssetFileStoragePath=this.LOCAL_STORAGE_PATH+"/"+digitalAssetFileName;
 }
コード例 #12
0
 public AssetUserWalletTransactionRecordWrapper(
     DigitalAssetMetadata digitalAssetMetadata,
     CryptoTransaction cryptoGenesisTransaction,
     String actorFromPublicKey,
     String actorToPublicKey) {
   this.digitalAsset = digitalAssetMetadata.getDigitalAsset();
   this.digitalAssetPublicKey = this.digitalAsset.getPublicKey();
   this.name = this.digitalAsset.getName();
   this.description = this.digitalAsset.getDescription();
   this.addressFrom = cryptoGenesisTransaction.getAddressFrom();
   this.addressTo = cryptoGenesisTransaction.getAddressTo();
   this.actorFromPublicKey = actorFromPublicKey;
   this.actorToPublicKey = actorToPublicKey;
   this.actorFromType = Actors.INTRA_USER;
   this.actorToType = Actors.DAP_ASSET_ISSUER;
   this.amount = cryptoGenesisTransaction.getCryptoAmount();
   this.digitalAssetMetadataHash = digitalAssetMetadata.getDigitalAssetHash();
   this.transactionId = cryptoGenesisTransaction.getTransactionHash();
   Date date = new Date();
   this.timeStamp = date.getTime();
   this.memo = "Digital Asset delivered at" + this.timeStamp;
 }
コード例 #13
0
 public void persistDigitalAsset(
     DigitalAssetMetadata digitalAssetMetadata, ActorAssetUser actorAssetUser)
     throws CantPersistDigitalAssetException, CantCreateDigitalAssetFileException {
   System.out.println(
       "ASSET DISTRIBUTION Persist DAM: " + digitalAssetMetadata.getGenesisTransaction());
   setDigitalAssetLocalFilePath(digitalAssetMetadata);
   CryptoAddress cryptoAddress = actorAssetUser.getCryptoAddress();
   String actorAddress;
   if (cryptoAddress == null) {
     actorAddress = "UNDEFINED";
     System.out.println("ASSET DISTRIBUTION Harcoding Actor address because is null");
   } else {
     actorAddress = cryptoAddress.getAddress();
   }
   this.assetDistributionDao.persistDigitalAsset(
       digitalAssetMetadata.getGenesisTransaction(),
       this.digitalAssetFileStoragePath,
       digitalAssetMetadata.getDigitalAssetHash(),
       actorAssetUser.getActorPublicKey(),
       actorAddress);
   System.out.println("ASSET DISTRIBUTION registered in database");
   persistInLocalStorage(digitalAssetMetadata);
 }
  /**
   * (non-javadoc)
   *
   * @see FermatMessageProcessor#processingMessage(FermatMessage, JsonObject)
   */
  @Override
  public void processingMessage(FermatMessage fermatMessage, JsonObject jsonMsjContent) {

    try {

      /*
       * Get the XML representation of the Digital Asset Metadata
       */
      String digitalAssetMetadataXml =
          jsonMsjContent.get(AssetTransmissionJsonAttNames.DIGITAL_ASSET_METADATA).getAsString();
      PlatformComponentType senderType =
          gson.fromJson(
              jsonMsjContent.get(AssetTransmissionJsonAttNames.SENDER_TYPE).getAsString(),
              PlatformComponentType.class);
      PlatformComponentType receiverType =
          gson.fromJson(
              jsonMsjContent.get(AssetTransmissionJsonAttNames.RECEIVER_TYPE).getAsString(),
              PlatformComponentType.class);

      /*
       * Convert the xml to object
       */
      DigitalAssetMetadata digitalAssetMetadata =
          (DigitalAssetMetadata)
              XMLParser.parseXML(digitalAssetMetadataXml, new DigitalAssetMetadata());

      /*
       * Construct a new digitalAssetMetadataTransaction
       */
      DigitalAssetMetadataTransactionImpl digitalAssetMetadataTransaction =
          new DigitalAssetMetadataTransactionImpl();
      digitalAssetMetadataTransaction.setGenesisTransaction(
          digitalAssetMetadata.getGenesisTransaction());
      digitalAssetMetadataTransaction.setSenderId(fermatMessage.getSender());
      digitalAssetMetadataTransaction.setSenderType(senderType);
      digitalAssetMetadataTransaction.setReceiverId(fermatMessage.getReceiver());
      digitalAssetMetadataTransaction.setReceiverType(receiverType);
      digitalAssetMetadataTransaction.setDigitalAssetMetadata(digitalAssetMetadata);
      digitalAssetMetadataTransaction.setDistributionStatus(DistributionStatus.ASSET_DISTRIBUTED);
      digitalAssetMetadataTransaction.setType(
          DigitalAssetMetadataTransactionType.META_DATA_TRANSMIT);
      digitalAssetMetadataTransaction.setProcessed(
          DigitalAssetMetadataTransactionImpl.NO_PROCESSED);

      /*
       * Save into data base for audit control
       */
      getAssetTransmissionNetworkServicePluginRoot()
          .getDigitalAssetMetaDataTransactionDao()
          .create(digitalAssetMetadataTransaction);

      /*
       * Mark the message as read
       */
      ((FermatMessageCommunication) fermatMessage)
          .setFermatMessagesStatus(FermatMessagesStatus.READ);
      ((CommunicationNetworkServiceConnectionManager)
              getAssetTransmissionNetworkServicePluginRoot().getNetworkServiceConnectionManager())
          .getIncomingMessageDao()
          .update(fermatMessage);

      /*
       * Notify to the interested
       */
      FermatEvent event =
          getAssetTransmissionNetworkServicePluginRoot()
              .getEventManager()
              .getNewEvent(EventType.RECEIVED_NEW_DIGITAL_ASSET_METADATA_NOTIFICATION);
      event.setSource(AssetTransmissionNetworkServicePluginRoot.EVENT_SOURCE);
      getAssetTransmissionNetworkServicePluginRoot().getEventManager().raiseEvent(event);

    } catch (Exception e) {
      getAssetTransmissionNetworkServicePluginRoot()
          .getErrorManager()
          .reportUnexpectedPluginException(
              Plugins.BITDUBAI_DAP_ASSET_TRANSMISSION_NETWORK_SERVICE,
              UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN,
              e);
    }
  }
コード例 #15
0
 private void sendCryptoAmountToRemoteActor(DigitalAssetMetadata digitalAssetMetadata)
     throws CantSendAssetBitcoinsToUserException, CantBroadcastTransactionException {
   System.out.println("ASSET USER REDEMPTION sending genesis amount from asset vault");
   bitcoinNetworkManager.broadcastTransaction(digitalAssetMetadata.getLastTransactionHash());
 }
コード例 #16
0
    private void checkNetworkLayerEvents()
        throws CantConfirmTransactionException, CantExecuteQueryException,
            UnexpectedResultReturnedFromDatabaseException,
            CantCheckAssetUserRedemptionProgressException,
            CantGetDigitalAssetFromLocalStorageException, CantSendAssetBitcoinsToUserException,
            CantGetCryptoTransactionException, CantDeliverDigitalAssetToAssetWalletException,
            CantDistributeDigitalAssetsException, CantDeliverPendingTransactionsException,
            RecordsNotFoundException, CantBroadcastTransactionException,
            CantCreateDigitalAssetFileException, CantLoadWalletException {
      List<Transaction<DigitalAssetMetadataTransaction>> pendingEventsList =
          assetTransmissionManager.getPendingTransactions(Specialist.ASSET_ISSUER_SPECIALIST);
      if (!userRedemptionDao.getPendingNetworkLayerEvents().isEmpty()) {
        for (Transaction<DigitalAssetMetadataTransaction> transaction : pendingEventsList) {
          if (transaction.getInformation().getReceiverType()
                  == PlatformComponentType.ACTOR_ASSET_USER
              && transaction.getInformation().getSenderType()
                  == PlatformComponentType.ACTOR_ASSET_REDEEM_POINT) {
            DigitalAssetMetadataTransaction digitalAssetMetadataTransaction =
                transaction.getInformation();
            System.out.println(
                "ASSET USER REDEMPTION Digital Asset Metadata Transaction: "
                    + digitalAssetMetadataTransaction);
            DigitalAssetMetadataTransactionType digitalAssetMetadataTransactionType =
                digitalAssetMetadataTransaction.getType();
            System.out.println(
                "ASSET USER REDEMPTION Digital Asset Metadata Transaction Type: "
                    + digitalAssetMetadataTransactionType);
            String userId = digitalAssetMetadataTransaction.getSenderId();
            System.out.println("ASSET USER REDEMPTION User Id: " + userId);
            String genesisTransaction = digitalAssetMetadataTransaction.getGenesisTransaction();
            System.out.println("ASSET USER REDEMPTION Genesis Transaction: " + genesisTransaction);
            if (!userRedemptionDao.isGenesisTransactionRegistered(genesisTransaction)) {
              System.out.println("ASSET USET REDEMPTION THIS IS NOT FOR ME!!");
              break;
            }
            DistributionStatus distributionStatus =
                digitalAssetMetadataTransaction.getDistributionStatus();
            userRedemptionDao.updateDistributionStatusByGenesisTransaction(
                distributionStatus, genesisTransaction);
            assetTransmissionManager.confirmReception(transaction.getTransactionID());
          }
        }
        userRedemptionDao.updateEventStatus(
            userRedemptionDao.getPendingNetworkLayerEvents().get(0));
      }

      List<String> assetAcceptedGenesisTransactionList =
          userRedemptionDao.getGenesisTransactionByAssetAcceptedStatus();
      for (String assetAcceptedGenesisTransaction : assetAcceptedGenesisTransactionList) {
        String actorUserCryptoAddress =
            userRedemptionDao.getActorRedeemPointCryptoAddressByGenesisTransaction(
                assetAcceptedGenesisTransaction);
        System.out.println(
            "ASSET USER REDEMPTION actorUserCryptoAddress: " + actorUserCryptoAddress);
        // For now, I set the cryptoAddress for Bitcoins
        CryptoAddress cryptoAddressTo =
            new CryptoAddress(actorUserCryptoAddress, CryptoCurrency.BITCOIN);
        System.out.println("ASSET USER REDEMPTION cryptoAddressTo: " + cryptoAddressTo);
        updateDistributionStatus(
            DistributionStatus.SENDING_CRYPTO, assetAcceptedGenesisTransaction);
        DeliverRecord record = userRedemptionDao.getLastDelivering(assetAcceptedGenesisTransaction);
        switch (record.getState()) {
          case DELIVERING:
            DigitalAssetMetadata metadata =
                digitalAssetUserRedemptionVault.getDigitalAssetMetadataFromWallet(
                    assetAcceptedGenesisTransaction, record.getNetworkType());
            userRedemptionDao.sendingBitcoins(
                assetAcceptedGenesisTransaction, metadata.getLastTransactionHash());
            userRedemptionDao.updateDigitalAssetCryptoStatusByGenesisTransaction(
                assetAcceptedGenesisTransaction, CryptoStatus.PENDING_SUBMIT);
            sendCryptoAmountToRemoteActor(metadata);
            break;
          case DELIVERING_CANCELLED:
            userRedemptionDao.updateDistributionStatusByGenesisTransaction(
                DistributionStatus.SENDING_CRYPTO_FAILED, assetAcceptedGenesisTransaction);
            break;
          default:
            System.out.println("This transaction has already been updated.");
            break;
        }
      }

      // TODO CHANGE THIS!!!!!!!!!!!!!
      List<String> assetRejectedByContractGenesisTransactionList =
          userRedemptionDao.getGenesisTransactionByAssetRejectedByContractStatus();
      for (String assetRejectedGenesisTransaction : assetRejectedByContractGenesisTransactionList) {
        DigitalAssetMetadata digitalAssetMetadata =
            digitalAssetUserRedemptionVault
                .getUserWallet(BlockchainNetworkType.getDefaultBlockchainNetworkType())
                .getDigitalAssetMetadata(assetRejectedGenesisTransaction);
        String internalId =
            userRedemptionDao.getTransactionIdByGenesisTransaction(assetRejectedGenesisTransaction);
        List<CryptoTransaction> genesisTransactionList =
            bitcoinNetworkManager.getCryptoTransactions(
                digitalAssetMetadata.getLastTransactionHash());
        if (genesisTransactionList == null || genesisTransactionList.isEmpty()) {
          throw new CantCheckAssetUserRedemptionProgressException(
              "Cannot get the CryptoTransaction from Crypto Network for "
                  + assetRejectedGenesisTransaction);
        }
        System.out.println("ASSET REJECTED BY CONTRACT!! : " + digitalAssetMetadata);
        String userPublicKey =
            userRedemptionDao.getActorUserPublicKeyByGenesisTransaction(
                assetRejectedGenesisTransaction);
        digitalAssetUserRedemptionVault.setDigitalAssetMetadataAssetIssuerWalletTransaction(
            genesisTransactionList.get(0),
            digitalAssetMetadata,
            AssetBalanceType.AVAILABLE,
            TransactionType.CREDIT,
            DAPTransactionType.DISTRIBUTION,
            userPublicKey);
      }

      List<String> assetRejectedByHashGenesisTransactionList =
          userRedemptionDao.getGenesisTransactionByAssetRejectedByHashStatus();
      for (String assetRejectedGenesisTransaction : assetRejectedByHashGenesisTransactionList) {
        DigitalAssetMetadata digitalAssetMetadata =
            digitalAssetUserRedemptionVault
                .getUserWallet(BlockchainNetworkType.getDefaultBlockchainNetworkType())
                .getDigitalAssetMetadata(assetRejectedGenesisTransaction);
        String internalId =
            userRedemptionDao.getTransactionIdByGenesisTransaction(assetRejectedGenesisTransaction);
        List<CryptoTransaction> genesisTransactionList =
            bitcoinNetworkManager.getCryptoTransactions(
                digitalAssetMetadata.getLastTransactionHash());
        if (genesisTransactionList == null || genesisTransactionList.isEmpty()) {
          throw new CantCheckAssetUserRedemptionProgressException(
              "Cannot get the CryptoTransaction from Crypto Network for "
                  + assetRejectedGenesisTransaction);
        }
        System.out.println("ASSET REJECTED BY HASH!! : " + digitalAssetMetadata);
        String userPublicKey =
            userRedemptionDao.getActorUserPublicKeyByGenesisTransaction(
                assetRejectedGenesisTransaction);
        digitalAssetUserRedemptionVault.setDigitalAssetMetadataAssetIssuerWalletTransaction(
            genesisTransactionList.get(0),
            digitalAssetMetadata,
            AssetBalanceType.AVAILABLE,
            TransactionType.CREDIT,
            DAPTransactionType.DISTRIBUTION,
            userPublicKey);
      }
    }
コード例 #17
0
 private static CryptoTransaction getCryptoTransactionFromCryptoNetwork(
     BitcoinNetworkManager bitcoinNetworkManager, DigitalAssetMetadata digitalAssetMetadata)
     throws DAPException, CantGetCryptoTransactionException {
   return bitcoinNetworkManager.getGenesisCryptoTransaction(
       null, digitalAssetMetadata.getTransactionChain());
 }
コード例 #18
0
 /** This method will deliver the DigitalAssetMetadata to ActorAssetUser */
 private void deliverDigitalAssetToRemoteDevice(
     DigitalAssetMetadata digitalAssetMetadata, ActorAssetUser actorAssetUser)
     throws CantDeliverDigitalAssetException {
   try {
     // First, I going to persist in database the basic information about digitalAssetMetadata
     System.out.println("ASSET DISTRIBUTION begins for " + actorAssetUser.getActorPublicKey());
     persistDigitalAsset(digitalAssetMetadata, actorAssetUser);
     System.out.println("ASSET DISTRIBUTION begins for persisted");
     // Now, I'll check is Hash wasn't modified
     // checkDigitalAssetMetadata(digitalAssetMetadata);
     DigitalAsset digitalAsset = digitalAssetMetadata.getDigitalAsset();
     System.out.println(
         "ASSET DISTRIBUTION Digital Asset genesis address: " + digitalAsset.getGenesisAddress());
     String genesisTransaction = digitalAssetMetadata.getGenesisTransaction();
     System.out.println("ASSET DISTRIBUTION Genesis transaction:" + genesisTransaction);
     this.assetDistributionDao.updateDistributionStatusByGenesisTransaction(
         DistributionStatus.CHECKING_AVAILABLE_BALANCE, genesisTransaction);
     if (!isAvailableBalanceInAssetVault(digitalAsset.getGenesisAmount(), genesisTransaction)) {
       System.out.println(
           "ASSET DISTRIBUTION The Available balance in asset vault is insufficient - genesisAmount:"
               + digitalAsset.getGenesisAmount());
       throw new CantDeliverDigitalAssetException(
           "The Available balance in asset vault is incorrect");
     }
     this.assetDistributionDao.updateDistributionStatusByGenesisTransaction(
         DistributionStatus.AVAILABLE_BALANCE_CHECKED, genesisTransaction);
     DigitalAssetContract digitalAssetContract = digitalAsset.getContract();
     System.out.println("ASSET DISTRIBUTION Digital Asset contract: " + digitalAssetContract);
     this.assetDistributionDao.updateDistributionStatusByGenesisTransaction(
         DistributionStatus.CHECKING_CONTRACT, genesisTransaction);
     if (!isValidContract(digitalAssetContract)) {
       System.out.println("ASSET DISTRIBUTION The contract is not valid");
       throw new CantDeliverDigitalAssetException(
           "The DigitalAsset Contract is not valid, the expiration date has passed");
     }
     this.assetDistributionDao.updateDistributionStatusByGenesisTransaction(
         DistributionStatus.CONTRACT_CHECKED, genesisTransaction);
     this.assetDistributionDao.updateDistributionStatusByGenesisTransaction(
         DistributionStatus.CHECKING_HASH, genesisTransaction);
     if (!isDigitalAssetHashValid(digitalAssetMetadata)) {
       System.out.println("ASSET DISTRIBUTION The DAM Hash is not valid");
       throw new CantDeliverDigitalAssetException("The DigitalAsset hash is not valid");
     }
     this.assetDistributionDao.updateDistributionStatusByGenesisTransaction(
         DistributionStatus.HASH_CHECKED, genesisTransaction);
     System.out.println(
         "ASSET DISTRIBUTION set debit in asset issuer wallet:" + genesisTransaction);
     digitalAssetDistributionVault.setDigitalAssetMetadataAssetIssuerWalletDebit(
         digitalAssetMetadata, this.cryptoTransaction, BalanceType.AVAILABLE);
     System.out.println("ASSET DISTRIBUTION Begins the deliver to an remote actor");
     deliverToRemoteActor(digitalAssetMetadata, actorAssetUser);
   } catch (CantPersistDigitalAssetException exception) {
     throw new CantDeliverDigitalAssetException(
         exception, "Delivering digital assets", "Cannot persist digital asset into database");
   } catch (CantCreateDigitalAssetFileException exception) {
     throw new CantDeliverDigitalAssetException(
         exception,
         "Delivering digital assets",
         "Cannot persist digital asset into local storage");
   } catch (CantGetCryptoTransactionException exception) {
     throw new CantDeliverDigitalAssetException(
         exception,
         "Delivering digital assets",
         "Cannot get the genesisTransaction from Asset Vault");
   } catch (CantExecuteQueryException exception) {
     throw new CantDeliverDigitalAssetException(
         exception, "Delivering digital assets", "Cannot execute a database operation");
   } catch (UnexpectedResultReturnedFromDatabaseException exception) {
     throw new CantDeliverDigitalAssetException(
         exception, "Delivering digital assets", "Unexpected result in database");
   } catch (CantSendDigitalAssetMetadataException exception) {
     throw new CantDeliverDigitalAssetException(
         exception,
         "Delivering digital assets",
         "There is an error delivering the digital asset through the network layer");
   } catch (DAPException exception) {
     throw new CantDeliverDigitalAssetException(
         exception, "Delivering digital assets", "Generic DAP Exception");
   } catch (CantGetTransactionsException exception) {
     throw new CantDeliverDigitalAssetException(
         exception,
         "Delivering digital assets",
         "Cannot get the genesis transaction from crypto network");
   } catch (CantLoadWalletException exception) {
     throw new CantDeliverDigitalAssetException(
         exception, "Delivering digital assets", "Cannot load Asset issuer wallet");
   } catch (CantRegisterDebitException exception) {
     throw new CantDeliverDigitalAssetException(
         exception, "Delivering digital assets", "Cannot register a debit in Asset Issuer Wallet");
   }
 }
コード例 #19
0
 public void checkPendingCryptoRouterEvents() throws Exception {
   for (String eventId : issuerRedemptionDao.getPendingCryptoRouterEvents()) {
     boolean notify = true;
     switch (issuerRedemptionDao.getEventTypeById(eventId)) {
       case INCOMING_ASSET_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_REDEMPTION:
         {
           List<DigitalAssetMetadata> allUsedAssets = new ArrayList<>();
           allUsedAssets.addAll(
               assetIssuerWalletManager
                   .loadAssetIssuerWallet(issuerPublicKeyWallet, BlockchainNetworkType.TEST_NET)
                   .getAllUnusedAssets());
           allUsedAssets.addAll(
               assetIssuerWalletManager
                   .loadAssetIssuerWallet(
                       issuerPublicKeyWallet, BlockchainNetworkType.PRODUCTION)
                   .getAllUnusedAssets());
           allUsedAssets.addAll(
               assetIssuerWalletManager
                   .loadAssetIssuerWallet(issuerPublicKeyWallet, BlockchainNetworkType.REG_TEST)
                   .getAllUnusedAssets());
           for (DigitalAssetMetadata digitalAssetMetadata : allUsedAssets) {
             List<CryptoTransaction> allChildTx =
                 bitcoinNetworkManager.getChildTransactionsFromParent(
                     digitalAssetMetadata.getLastTransactionHash());
             if (allChildTx.isEmpty()) {
               notify = false;
               continue;
             }
             CryptoTransaction lastChild = allChildTx.get(0);
             digitalAssetMetadata.addNewTransaction(
                 lastChild.getTransactionHash(), lastChild.getBlockHash());
             CryptoTransaction cryptoTransactionOnCryptoNetwork =
                 AssetVerification.getCryptoTransactionFromCryptoNetworkByCryptoStatus(
                     bitcoinNetworkManager,
                     digitalAssetMetadata,
                     CryptoStatus.ON_CRYPTO_NETWORK);
             if (cryptoTransactionOnCryptoNetwork == null) {
               notify = false;
               continue; // NOT TODAY KID.
             }
             AssetIssuerWallet wallet =
                 assetIssuerWalletManager.loadAssetIssuerWallet(
                     issuerPublicKeyWallet,
                     cryptoTransactionOnCryptoNetwork.getBlockchainNetworkType());
             String publicKeyFrom =
                 wallet.getUserDeliveredToPublicKey(digitalAssetMetadata.getMetadataId());
             String publicKeyTo =
                 actorAssetIssuerManager.getActorAssetIssuer().getActorPublicKey();
             AssetIssuerWalletTransactionRecordWrapper recordWrapper =
                 new AssetIssuerWalletTransactionRecordWrapper(
                     digitalAssetMetadata,
                     cryptoTransactionOnCryptoNetwork,
                     publicKeyFrom,
                     Actors.DAP_ASSET_USER,
                     publicKeyTo,
                     Actors.DAP_ASSET_ISSUER,
                     WalletUtilities.DEFAULT_MEMO_REDEMPTION);
             issuerRedemptionDao.assetReceived(
                 digitalAssetMetadata,
                 cryptoTransactionOnCryptoNetwork.getBlockchainNetworkType());
             wallet.getBalance().credit(recordWrapper, BalanceType.BOOK);
             notify = true;
           }
           break;
         }
       case INCOMING_ASSET_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_REDEMPTION:
         {
           for (Map.Entry<BlockchainNetworkType, String> genesisTx :
               issuerRedemptionDao.getToBeAppliedGenesisTransaction().entrySet()) {
             AssetIssuerWallet wallet =
                 assetIssuerWalletManager.loadAssetIssuerWallet(
                     issuerPublicKeyWallet, genesisTx.getKey());
             DigitalAssetMetadata digitalAssetMetadata =
                 wallet.getDigitalAssetMetadata(genesisTx.getValue());
             CryptoTransaction cryptoTransactionOnBlockChain =
                 AssetVerification.getCryptoTransactionFromCryptoNetworkByCryptoStatus(
                     bitcoinNetworkManager, digitalAssetMetadata, CryptoStatus.ON_BLOCKCHAIN);
             if (cryptoTransactionOnBlockChain == null) {
               notify = false;
               continue;
             }
             CryptoAddressBookRecord bookRecord =
                 cryptoAddressBookManager.getCryptoAddressBookRecordByCryptoAddress(
                     cryptoTransactionOnBlockChain.getAddressTo());
             String publicKeyFrom =
                 wallet.getUserDeliveredToPublicKey(digitalAssetMetadata.getMetadataId());
             String publicKeyTo =
                 actorAssetIssuerManager.getActorAssetIssuer().getActorPublicKey();
             wallet.assetRedeemed(
                 digitalAssetMetadata.getMetadataId(),
                 null,
                 bookRecord.getDeliveredToActorPublicKey());
             digitalAssetMetadata
                 .getDigitalAsset()
                 .setGenesisAmount(cryptoTransactionOnBlockChain.getCryptoAmount());
             digitalAssetMetadata.setMetadataId(UUID.randomUUID());
             digitalAssetMetadata.addNewTransaction(
                 cryptoTransactionOnBlockChain.getTransactionHash(),
                 cryptoTransactionOnBlockChain.getBlockHash());
             wallet.createdNewAsset(digitalAssetMetadata);
             /**
              * Notifies the Asset Vault that the address of this Redeem Point, has been used.
              */
             assetVaultManager.notifyUsedRedeemPointAddress(
                 bookRecord.getCryptoAddress(), bookRecord.getDeliveredToActorPublicKey());
             AssetIssuerWalletTransactionRecordWrapper recordWrapper =
                 new AssetIssuerWalletTransactionRecordWrapper(
                     digitalAssetMetadata,
                     cryptoTransactionOnBlockChain,
                     publicKeyFrom,
                     Actors.DAP_ASSET_USER,
                     publicKeyTo,
                     Actors.DAP_ASSET_ISSUER,
                     WalletUtilities.DEFAULT_MEMO_REDEMPTION);
             wallet.getBalance().credit(recordWrapper, BalanceType.AVAILABLE);
             issuerRedemptionDao.redemptionFinished(digitalAssetMetadata);
             if (cryptoTransactionOnBlockChain.getCryptoAmount()
                 < DAPStandardFormats.MINIMUN_SATOSHI_AMOUNT) {
               System.out.println(
                   "ASSET AMOUNT IS NOT ENOUGH TO START ANOTHER CYCLE, AUTOMATIC APPROPRIATING IT...");
               issuerAppropriationManager.appropriateAsset(
                   digitalAssetMetadata, issuerPublicKeyWallet, btcWallet, genesisTx.getKey());
             }
             notify = true;
           }
         }
         break;
       case INCOMING_ASSET_REVERSED_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_REDEMPTION:
         break;
       case INCOMING_ASSET_REVERSED_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_REDEMPTION:
         break;
     }
     if (notify) {
       issuerRedemptionDao.notifyEvent(eventId);
     }
   }
 }