コード例 #1
0
  @Override
  public CashDepositTransaction createCashDepositTransaction(
      CashTransactionParameters depositParameters) throws CantCreateDepositTransactionException {
    CashMoneyWallet wallet;
    try {
      wallet = cashMoneyWalletManager.loadCashMoneyWallet(depositParameters.getPublicKeyWallet());

    } catch (CantLoadCashMoneyWalletException e) {
      pluginRoot.reportError(UnexpectedPluginExceptionSeverity.DISABLES_THIS_PLUGIN, e);
      throw new CantCreateDepositTransactionException(
          CantCreateDepositTransactionException.DEFAULT_MESSAGE,
          e,
          "CashMoneyTransactionDepositManager",
          "Failed to load Cash Money Wallet");
    }

    try {
      // TODO - Revisar el parametro transactionId en este metodo:
      // wallet.getAvailableBalance().credit(depositParameters.getTransactionId(),
      // depositParameters.getPublicKeyActor(), depositParameters.getPublicKeyPlugin(),
      // depositParameters.getAmount(), depositParameters.getMemo());
      // TODO - Revisar el parametro transactionId en este metodo porque esta dado excepcion debido
      // a que es el mismo que el de la instruccion de mas arriba:
      // wallet.getBookBalance().credit(depositParameters.getTransactionId(),
      // depositParameters.getPublicKeyActor(), depositParameters.getPublicKeyPlugin(),
      // depositParameters.getAmount(), depositParameters.getMemo());

      // TODO - Se le esta colocando un random ID pra que sea unico. Por favor revisar esto
      wallet
          .getAvailableBalance()
          .credit(
              UUID.randomUUID(),
              depositParameters.getPublicKeyActor(),
              depositParameters.getPublicKeyPlugin(),
              depositParameters.getAmount(),
              depositParameters.getMemo());
      // TODO - Se le esta colocando un random ID pra que sea unico. Por favor revisar esto
      wallet
          .getBookBalance()
          .credit(
              UUID.randomUUID(),
              depositParameters.getPublicKeyActor(),
              depositParameters.getPublicKeyPlugin(),
              depositParameters.getAmount(),
              depositParameters.getMemo());

    } catch (CantGetCashMoneyWalletBalanceException e) {
      pluginRoot.reportError(UnexpectedPluginExceptionSeverity.DISABLES_THIS_PLUGIN, e);
      throw new CantCreateDepositTransactionException(
          CantCreateDepositTransactionException.DEFAULT_MESSAGE,
          e,
          "CashMoneyTransactionDepositManager",
          "Failed to load Cash Money Wallet Balance");
    } catch (CantRegisterCreditException e) {
      pluginRoot.reportError(UnexpectedPluginExceptionSeverity.DISABLES_THIS_PLUGIN, e);
      throw new CantCreateDepositTransactionException(
          CantCreateDepositTransactionException.DEFAULT_MESSAGE,
          e,
          "CashMoneyTransactionDepositManager",
          "Failed to register credit in Wallet Balance");
    }

    return dao.createCashDepositTransaction(depositParameters);
  }
コード例 #2
0
  private void doTheMainTask() {
    // System.out.println("CASHHOLD - Agent LOOP");

    List<CashHoldTransaction> transactionList;

    try {
      transactionList = holdTransactionManager.getAcknowledgedTransactionList();
    } catch (CantGetHoldTransactionException e) {
      errorManager.reportUnexpectedPluginException(
          Plugins.BITDUBAI_CSH_MONEY_TRANSACTION_HOLD,
          UnexpectedPluginExceptionSeverity.DISABLES_THIS_PLUGIN,
          e);
      return;
    }

    /*
     * For each new (acknowledged) transaction, this thread:
     * Changes its status to Pending
     * Tries to hold funds in wallet
     * If successfull, changes transaction status to Confirmed
     * If not, changes transaction status to Rejected.
     * Sends an event, notifying the calling plugin the status change
     */

    for (CashHoldTransaction transaction : transactionList) {

      // Cambiar el status de la transaccion a pending
      try {
        holdTransactionManager.setTransactionStatusToPending(transaction.getTransactionId());
      } catch (CantUpdateHoldTransactionException ex) {
        errorManager.reportUnexpectedPluginException(
            Plugins.BITDUBAI_CSH_MONEY_TRANSACTION_HOLD,
            UnexpectedPluginExceptionSeverity.NOT_IMPORTANT,
            ex);
      }

      // Abrir el cash wallet con el public key del transaction
      if (cashMoneyWallet == null || transaction.getPublicKeyWallet() != lastPublicKey) {
        try {
          // cashMoneyWallet =
          // cashMoneyWalletManager.loadCashMoneyWallet(transaction.getPublicKeyWallet());
          cashMoneyWallet = cashMoneyWalletManager.loadCashMoneyWallet("cash_wallet");
        } catch (CantLoadCashMoneyWalletException e) {
          errorManager.reportUnexpectedPluginException(
              Plugins.BITDUBAI_CSH_MONEY_TRANSACTION_HOLD,
              UnexpectedPluginExceptionSeverity.NOT_IMPORTANT,
              e);
          continue;
        }
      }

      // Intentar hacer el hold en el cash wallet
      try {
        cashMoneyWallet.hold(
            transaction.getTransactionId(),
            transaction.getPublicKeyActor(),
            transaction.getPublicKeyPlugin(),
            transaction.getAmount(),
            transaction.getMemo());
        holdTransactionManager.setTransactionStatusToConfirmed(transaction.getTransactionId());
      } catch (CantRegisterHoldException
          | CashMoneyWalletInsufficientFundsException
              e) { // Reject si no hay fondos o no se puede hacer el hold por alguna razon
        try {
          holdTransactionManager.setTransactionStatusToRejected(transaction.getTransactionId());
        } catch (CantUpdateHoldTransactionException ex) {
          errorManager.reportUnexpectedPluginException(
              Plugins.BITDUBAI_CSH_MONEY_TRANSACTION_HOLD,
              UnexpectedPluginExceptionSeverity.NOT_IMPORTANT,
              ex);
        }
      } catch (CantUpdateHoldTransactionException e) {
        errorManager.reportUnexpectedPluginException(
            Plugins.BITDUBAI_CSH_MONEY_TRANSACTION_HOLD,
            UnexpectedPluginExceptionSeverity.NOT_IMPORTANT,
            e);
      }

      // TODO: Lanzar un evento al plugin que envio la transaccion para avisarle que se actualizo el
      // status de su transaccion.
    }
  }