/**
   * Saves and outgoing transaction into the database
   *
   * @param hash
   * @param cryptoStatus
   * @param blockDepth
   * @param addressTo
   * @param addressFrom
   * @param value
   * @param op_Return
   * @param protocolStatus
   * @throws CantExecuteDatabaseOperationException
   */
  public void saveNewOutgoingTransaction(
      String hash,
      CryptoStatus cryptoStatus,
      int blockDepth,
      CryptoAddress addressTo,
      CryptoAddress addressFrom,
      long value,
      String op_Return,
      ProtocolStatus protocolStatus)
      throws CantExecuteDatabaseOperationException {
    DatabaseTable databaseTable =
        database.getTable(BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_TABLE_NAME);
    DatabaseTableRecord record = databaseTable.getEmptyRecord();

    /** generates the trx_id */
    UUID trxId = UUID.randomUUID();

    record.setUUIDValue(
        BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_TRX_ID_COLUMN_NAME, trxId);
    record.setStringValue(
        BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_HASH_COLUMN_NAME, hash);
    record.setStringValue(
        BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_CRYPTO_STATUS_COLUMN_NAME,
        cryptoStatus.getCode());
    record.setIntegerValue(
        BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_BLOCK_DEPTH_COLUMN_NAME,
        blockDepth);
    record.setStringValue(
        BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_ADDRESS_TO_COLUMN_NAME,
        addressTo.getAddress());
    record.setStringValue(
        BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_ADDRESS_FROM_COLUMN_NAME,
        addressFrom.getAddress());
    record.setDoubleValue(
        BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_VALUE_COLUMN_NAME, value);
    record.setStringValue(
        BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_OP_RETURN_COLUMN_NAME,
        op_Return);
    record.setStringValue(
        BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_PROTOCOL_STATUS_COLUMN_NAME,
        protocolStatus.getCode());
    record.setStringValue(
        BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_LAST_UPDATE_COLUMN_NAME,
        getCurrentDateTime());
    try {
      databaseTable.insertRecord(record);
    } catch (CantInsertRecordException e) {
      StringBuilder outputMessage =
          new StringBuilder(
              "There was an error inserting a new transaction in the Outgoing Transactions Table. Transaction record is:");
      outputMessage.append(System.lineSeparator());
      outputMessage.append(XMLParser.parseObject(record));

      throw new CantExecuteDatabaseOperationException(
          CantExecuteDatabaseOperationException.DEFAULT_MESSAGE,
          e,
          outputMessage.toString(),
          "database issue.");
    }
  }
  /**
   * (non-javadoc)
   *
   * @see AbstractBaseDao#getDatabaseTableRecordFromEntity
   */
  @Override
  protected DatabaseTableRecord getDatabaseTableRecordFromEntity(NodeConnectionHistory entity) {

    DatabaseTableRecord databaseTableRecord = getDatabaseTable().getEmptyRecord();

    databaseTableRecord.setUUIDValue(
        CommunicationsNetworkNodeP2PDatabaseConstants.NODES_CONNECTIONS_HISTORY_UUID_COLUMN_NAME,
        entity.getUuid());
    databaseTableRecord.setLongValue(
        CommunicationsNetworkNodeP2PDatabaseConstants
            .NODES_CONNECTIONS_HISTORY_CONNECTION_TIMESTAMP_COLUMN_NAME,
        entity.getConnectionTimestamp().getTime());
    databaseTableRecord.setIntegerValue(
        CommunicationsNetworkNodeP2PDatabaseConstants
            .NODES_CONNECTIONS_HISTORY_DEFAULT_PORT_COLUMN_NAME,
        entity.getDefaultPort());
    databaseTableRecord.setStringValue(
        CommunicationsNetworkNodeP2PDatabaseConstants
            .NODES_CONNECTIONS_HISTORY_IDENTITY_PUBLIC_KEY_COLUMN_NAME,
        entity.getIdentityPublicKey());
    databaseTableRecord.setStringValue(
        CommunicationsNetworkNodeP2PDatabaseConstants.NODES_CONNECTIONS_HISTORY_IP_COLUMN_NAME,
        entity.getIp());
    databaseTableRecord.setDoubleValue(
        CommunicationsNetworkNodeP2PDatabaseConstants
            .NODES_CONNECTIONS_HISTORY_LAST_LATITUDE_COLUMN_NAME,
        entity.getLastLatitude());
    databaseTableRecord.setDoubleValue(
        CommunicationsNetworkNodeP2PDatabaseConstants
            .NODES_CONNECTIONS_HISTORY_LAST_LONGITUDE_COLUMN_NAME,
        entity.getLastLongitude());
    databaseTableRecord.setStringValue(
        CommunicationsNetworkNodeP2PDatabaseConstants.NODES_CONNECTIONS_HISTORY_STATUS_COLUMN_NAME,
        entity.getStatus());

    return databaseTableRecord;
  }