public String toJson() {

    Gson gson = new Gson();

    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("id", id.toString());
    jsonObject.addProperty("actorDestinationType", actorDestinationType.toString());
    jsonObject.addProperty("actorSenderType", actorSenderType.toString());
    jsonObject.addProperty("actorSenderPublicKey", actorSenderPublicKey);
    jsonObject.addProperty("actorDestinationPublicKey", actorDestinationPublicKey);
    jsonObject.addProperty("actorSenderAlias", actorSenderAlias);
    jsonObject.addProperty("actorSenderPhrase", actorSenderPhrase);
    jsonObject.addProperty(
        "actorSenderProfileImage", Base64.encodeToString(actorSenderProfileImage, Base64.DEFAULT));
    jsonObject.addProperty("notificationDescriptor", notificationDescriptor.toString());
    jsonObject.addProperty("sentDate", sentDate);
    jsonObject.addProperty("actorProtocolState", actorProtocolState.toString());
    jsonObject.addProperty("flagReadead", flagReadead);
    jsonObject.addProperty("sentCount", sentCount);
    if (responseToNotificationId != null)
      jsonObject.addProperty("responseToNotificationId", responseToNotificationId.toString());
    return gson.toJson(jsonObject);
  }
  private OutgoingDraftTransactionWrapper convertToBT(DatabaseTableRecord record)
      throws InvalidParameterException {
    //        boolean sameDevice =
    // Boolean.valueOf(record.getStringValue(OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_SAME_DEVICE_COLUMN_NAME));
    String walletPublicKey =
        record.getStringValue(
            OutgoingDraftTransactionDatabaseConstants
                .OUTGOING_DRAFT_WALLET_ID_TO_DEBIT_FROM_COLUMN_NAME);
    UUID transactionId =
        record.getUUIDValue(
            OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TRANSACTION_ID_COLUMN_NAME);
    String transactionHash =
        record.getStringValue(
            OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TRANSACTION_HASH_COLUMN_NAME);
    long amount =
        record.getLongValue(
            OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_CRYPTO_AMOUNT_COLUMN_NAME);
    //        String op_Return =
    // record.getStringValue(OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_OP_RETURN_COLUMN_NAME);
    com.bitdubai.fermat_ccp_plugin.layer.crypto_transaction.outgoing_draft.developer.bitdubai
            .version_1.enums.TransactionState
        state =
            com.bitdubai.fermat_ccp_plugin.layer.crypto_transaction.outgoing_draft.developer
                .bitdubai.version_1.enums.TransactionState.getByCode(
                record.getStringValue(
                    OutgoingDraftTransactionDatabaseConstants
                        .OUTGOING_DRAFT_TRANSACTION_STATUS_COLUMN_NAME));
    long timestamp =
        record.getLongValue(
            OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TIMESTAMP_COLUMN_NAME);
    String memo =
        record.getStringValue(
            OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_DESCRIPTION_COLUMN_NAME);
    //        CryptoStatus cryptoStatus =
    // CryptoStatus.getByCode(record.getStringValue(OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_CRYPTO_STATUS_COLUMN_NAME));
    Actors actorFromType =
        Actors.getByCode(
            record.getStringValue(
                OutgoingDraftTransactionDatabaseConstants
                    .OUTGOING_DRAFT_ACTOR_FROM_TYPE_COLUMN_NAME));
    Actors actorToType =
        Actors.getByCode(
            record.getStringValue(
                OutgoingDraftTransactionDatabaseConstants
                    .OUTGOING_DRAFT_ACTOR_TO_TYPE_COLUMN_NAME));
    String actorFromPublicKey =
        record.getStringValue(
            OutgoingDraftTransactionDatabaseConstants
                .OUTGOING_DRAFT_ACTOR_FROM_PUBLIC_KEY_COLUMN_NAME);
    String actorToPublicKey =
        record.getStringValue(
            OutgoingDraftTransactionDatabaseConstants
                .OUTGOING_DRAFT_ACTOR_TO_PUBLIC_KEY_COLUMN_NAME);
    ReferenceWallet referenceWallet =
        ReferenceWallet.getByCode(
            record.getStringValue(
                OutgoingDraftTransactionDatabaseConstants
                    .OUTGOING_DRAFT_WALLET_REFERENCE_TYPE_COLUMN_NAME));
    String addressFrom =
        record.getStringValue(
            OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_ADDRESS_FROM_COLUMN_NAME);
    String addressTo =
        record.getStringValue(
            OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_ADDRESS_TO_COLUMN_NAME);
    //        CryptoAddress cryptoAddressFrom = null;
    //        if (addressFrom != null) {
    //            cryptoAddressFrom = new CryptoAddress(
    //                    addressFrom,
    //
    // CryptoCurrency.getByCode(OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_CRYPTO_CURRENCY_COLUMN_NAME));
    //        }
    CryptoAddress cryptoAddressTo = null;
    if (addressFrom != null) {
      cryptoAddressTo =
          new CryptoAddress(
              addressTo,
              CryptoCurrency.getByCode(
                  record.getStringValue(
                      OutgoingDraftTransactionDatabaseConstants
                          .OUTGOING_DRAFT_CRYPTO_CURRENCY_COLUMN_NAME)));
    }
    BlockchainNetworkType blockchainNetworkType =
        BlockchainNetworkType.getByCode(
            record.getStringValue(
                OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_RUNNING_NETWORK_TYPE));

    return new OutgoingDraftTransactionWrapper(
        transactionId,
        walletPublicKey,
        amount,
        cryptoAddressTo,
        referenceWallet,
        blockchainNetworkType,
        actorFromPublicKey,
        actorToPublicKey,
        actorFromType,
        actorToType,
        memo,
        timestamp,
        transactionHash);
  }
  private void loadRecordAsNew(
      DatabaseTableRecord databaseTableRecord,
      UUID trxId,
      String txHash,
      String walletPublicKey,
      CryptoAddress destinationAddress,
      long cryptoAmount,
      String op_Return,
      String notes,
      String deliveredByActorPublicKey,
      Actors deliveredByActorType,
      String deliveredToActorPublicKey,
      Actors deliveredToActorType,
      ReferenceWallet referenceWallet,
      boolean sameDevice,
      BlockchainNetworkType blockchainNetworkType) {

    databaseTableRecord.setUUIDValue(
        OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TRANSACTION_ID_COLUMN_NAME, trxId);
    //        if(requestId != null)
    //
    // databaseTableRecord.setUUIDValue(OutgoingIntraActorTransactionDatabaseConstants.OUTGOING_DRAFT_REQUEST_ID_COLUMN_NAME, requestId);

    databaseTableRecord.setStringValue(
        OutgoingDraftTransactionDatabaseConstants
            .OUTGOING_DRAFT_WALLET_ID_TO_DEBIT_FROM_COLUMN_NAME,
        walletPublicKey);

    // TODO: This will be completed when the vault gives it to us
    databaseTableRecord.setStringValue(
        OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TRANSACTION_HASH_COLUMN_NAME,
        txHash);

    // TODO: This need to be completed in the future
    databaseTableRecord.setStringValue(
        OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_ADDRESS_FROM_COLUMN_NAME,
        "MY_ADDRESS");
    databaseTableRecord.setStringValue(
        OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_ADDRESS_TO_COLUMN_NAME,
        destinationAddress.getAddress());
    databaseTableRecord.setStringValue(
        OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_CRYPTO_CURRENCY_COLUMN_NAME,
        destinationAddress.getCryptoCurrency().getCode());
    databaseTableRecord.setLongValue(
        OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_CRYPTO_AMOUNT_COLUMN_NAME,
        cryptoAmount);
    if (op_Return != null)
      databaseTableRecord.setStringValue(
          OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_OP_RETURN_COLUMN_NAME,
          op_Return);
    databaseTableRecord.setStringValue(
        OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TRANSACTION_STATUS_COLUMN_NAME,
        com.bitdubai.fermat_ccp_plugin.layer.crypto_transaction.outgoing_draft.developer.bitdubai
            .version_1.enums.TransactionState.NEW.getCode());

    // TODO: This have to be changed for the tinestamp when the network recognize the transaction

    // eze te saco la division para obtener el timestamp bien
    databaseTableRecord.setLongValue(
        OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TIMESTAMP_COLUMN_NAME,
        System.currentTimeMillis());
    databaseTableRecord.setStringValue(
        OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_DESCRIPTION_COLUMN_NAME, notes);
    databaseTableRecord.setStringValue(
        OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_CRYPTO_STATUS_COLUMN_NAME,
        CryptoStatus.PENDING_SUBMIT.getCode());

    databaseTableRecord.setStringValue(
        OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_ACTOR_FROM_PUBLIC_KEY_COLUMN_NAME,
        deliveredByActorPublicKey);
    databaseTableRecord.setStringValue(
        OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_ACTOR_FROM_TYPE_COLUMN_NAME,
        deliveredByActorType.getCode());
    databaseTableRecord.setStringValue(
        OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_ACTOR_TO_PUBLIC_KEY_COLUMN_NAME,
        deliveredToActorPublicKey);
    databaseTableRecord.setStringValue(
        OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_ACTOR_TO_TYPE_COLUMN_NAME,
        deliveredToActorType.getCode());
    databaseTableRecord.setStringValue(
        OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_SAME_DEVICE_COLUMN_NAME,
        String.valueOf(sameDevice));
    databaseTableRecord.setStringValue(
        OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_WALLET_REFERENCE_TYPE_COLUMN_NAME,
        referenceWallet.getCode());
    databaseTableRecord.setStringValue(
        OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_RUNNING_NETWORK_TYPE,
        blockchainNetworkType.getCode());
  }
Ejemplo n.º 4
0
  private ActorAssetNetworkServiceRecord buildAssetUserNetworkServiceRecord(
      DatabaseTableRecord record) throws InvalidParameterException {
    try {
      BlockchainNetworkType blockchainNetworkType;

      UUID notificationId =
          record.getUUIDValue(
              AssetUserNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_ID_COLUMN_NAME);
      String senderAlias =
          record.getStringValue(
              AssetUserNetworkServiceDatabaseConstants
                  .INCOMING_NOTIFICATION_SENDER_ALIAS_COLUMN_NAME);
      String descriptor =
          record.getStringValue(
              AssetUserNetworkServiceDatabaseConstants
                  .INCOMING_NOTIFICATION_DESCRIPTOR_COLUMN_NAME);
      String destinationType =
          record.getStringValue(
              AssetUserNetworkServiceDatabaseConstants
                  .INCOMING_NOTIFICATION_RECEIVER_TYPE_COLUMN_NAME);
      String senderType =
          record.getStringValue(
              AssetUserNetworkServiceDatabaseConstants
                  .INCOMING_NOTIFICATION_SENDER_TYPE_COLUMN_NAME);
      String senderPublicKey =
          record.getStringValue(
              AssetUserNetworkServiceDatabaseConstants
                  .INCOMING_NOTIFICATION_SENDER_PUBLIC_KEY_COLUMN_NAME);
      String destinationPublicKey =
          record.getStringValue(
              AssetUserNetworkServiceDatabaseConstants
                  .INCOMING_NOTIFICATION_RECEIVER_PUBLIC_KEY_COLUMN_NAME);
      long timestamp =
          record.getLongValue(
              AssetUserNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_TIMESTAMP_COLUMN_NAME);
      String protocolState =
          record.getStringValue(
              AssetUserNetworkServiceDatabaseConstants
                  .INCOMING_NOTIFICATION_PROTOCOL_STATE_COLUMN_NAME);
      String flagRead =
          record.getStringValue(
              AssetUserNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_READ_MARK_COLUMN_NAME);
      String blockChainNetwork =
          record.getStringValue(
              AssetUserNetworkServiceDatabaseConstants
                  .INCOMING_NOTIFICATION_BLOCKCHAIN_NETWORK_TYPE_COLUMN_NAME);
      UUID responseToNotificationId =
          record.getUUIDValue(
              AssetUserNetworkServiceDatabaseConstants
                  .INCOMING_NOTIFICATION_RESPONSE_TO_NOTIFICATION_ID_COLUMN_NAME);

      ActorAssetProtocolState actorAssetProtocolState =
          ActorAssetProtocolState.getByCode(protocolState);
      Boolean read = Boolean.valueOf(flagRead);
      AssetNotificationDescriptor assetNotificationDescriptor =
          AssetNotificationDescriptor.getByCode(descriptor);

      if (blockChainNetwork != null)
        blockchainNetworkType = BlockchainNetworkType.getByCode(blockChainNetwork);
      else blockchainNetworkType = BlockchainNetworkType.getDefaultBlockchainNetworkType();

      Actors actorDestinationType = Actors.getByCode(destinationType);
      Actors actorSenderType = Actors.getByCode(senderType);

      byte[] profileImage;

      try {
        profileImage =
            getActorUserProfileImagePrivateKey(
                record.getStringValue(
                    AssetUserNetworkServiceDatabaseConstants
                        .INCOMING_NOTIFICATION_SENDER_PUBLIC_KEY_COLUMN_NAME));
      } catch (FileNotFoundException e) {
        profileImage = new byte[0];
      }

      return new ActorAssetNetworkServiceRecord(
          notificationId,
          senderAlias,
          //                    senderPhrase,
          profileImage,
          assetNotificationDescriptor,
          actorDestinationType,
          actorSenderType,
          senderPublicKey,
          destinationPublicKey,
          timestamp,
          actorAssetProtocolState,
          read,
          0,
          blockchainNetworkType,
          responseToNotificationId,
          null);
    } catch (Exception e) {
      throw new InvalidParameterException();
    }
  }