class DatabaseNetwork {

  public static DatabaseNetwork init(
      final File source, Bytes4 forkVersion, Eth1Address depositContract) throws IOException {
    final String forkVersionString = forkVersion.toHexString().toLowerCase();
    final String depositContractString =
        depositContract == null ? "" : depositContract.toHexString().toLowerCase();
    final ObjectMapper objectMapper =
        new ObjectMapper(new YAMLFactory().disable(WRITE_DOC_START_MARKER));
    if (source.exists()) {
      final DatabaseNetwork databaseNetwork =
          objectMapper.readerFor(DatabaseNetwork.class).readValue(source);

      if (!forkVersionString.equals(databaseNetwork.forkVersion)) {
        throw new DatabaseStorageException(
            formatMessage("fork version", forkVersionString, databaseNetwork.forkVersion));
      }
      if (databaseNetwork.depositContract != null
          && !databaseNetwork.depositContract.equals(depositContractString)) {
        throw new DatabaseStorageException(
            formatMessage(
                "deposit contract", depositContractString, databaseNetwork.depositContract));
      }
      return databaseNetwork;
    } else {
      DatabaseNetwork databaseNetwork =
          new DatabaseNetwork(forkVersionString, depositContractString);
      objectMapper.writerFor(DatabaseNetwork.class).writeValue(source, databaseNetwork);
      return databaseNetwork;
    }
  }

  @JsonCreator  DatabaseNetwork(
      @JsonProperty("fork_version") final String forkVersion,
      @JsonProperty("deposit_contract") final String depositContract);

}