@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);
   }
 }
コード例 #2
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;
   }
 }
コード例 #3
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;
 }
コード例 #4
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");
   }
 }
コード例 #5
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);
     }
   }
 }