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"); } }
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); }
/** 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"); } }