コード例 #1
0
  public void setDigitalAssetMetadataAssetIssuerWalletDebit(
      DigitalAssetMetadata digitalAssetMetadata,
      CryptoTransaction genesisTransaction,
      BalanceType balanceType)
      throws CantLoadWalletException, CantGetTransactionsException, CantRegisterDebitException,
          CantGetAssetIssuerActorsException {
    AssetIssuerWallet assetIssuerWallet =
        this.assetIssuerWalletManager.loadAssetIssuerWallet(this.walletPublicKey);
    AssetIssuerWalletBalance assetIssuerWalletBalance =
        assetIssuerWallet.getBookBalance(balanceType);
    ActorAssetIssuer actorAssetIssuer = this.actorAssetIssuerManager.getActorAssetIssuer();
    String actorFromPublicKey;
    if (actorAssetIssuer == null) {
      System.out.println("ASSET DISTRIBUTION Actor Issuer is null");
      actorFromPublicKey = "UNDEFINED";
    } else {
      actorFromPublicKey = actorAssetIssuer.getActorPublicKey();
    }
    System.out.println("ASSET DISTRIBUTION Actor Issuer public key:" + actorFromPublicKey);
    AssetIssuerWalletTransactionRecordWrapper assetIssuerWalletTransactionRecordWrapper =
        new AssetIssuerWalletTransactionRecordWrapper(
            digitalAssetMetadata, genesisTransaction, actorFromPublicKey, "testActorToPublicKey");
    System.out.println(
        "ASSET DISTRIBUTION AssetIssuerWalletTransactionRecordWrapper:"
            + assetIssuerWalletTransactionRecordWrapper.getDescription());
    System.out.println("ASSET DISTRIBUTION Balance Type:" + balanceType);

    assetIssuerWalletBalance.debit(assetIssuerWalletTransactionRecordWrapper, balanceType);
  }
コード例 #2
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);
     }
   }
 }