Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Commit

Permalink
Release 1.0.0.2000 (#52)
Browse files Browse the repository at this point in the history
* Improved builder usages (#22)

* Using `static_cast` over `dynamic_cast` in fragment arguments (#24)

* Null HTTP client check in middleware (#26)

* Transition to pass-by-value (#29)

* Logging utility restructure (#31)

* HTTP restructure (#32)

* Automatic reauthentication for `ProjectClient` (#34)

* Reworked platform middleware (#41)

* Replaced upper-snake-case in API with pascal case (#45)

* Added JSON API and reworked serialization and deserialization (#46)

* Renamed model and request classes (#47)

* Refactored model classes to utilize Pimpl idiom (#48)

* Improved `PusherEventService` implementation (#49)

* Created static class `EnjinHosts` and moved host URIs into it (#50)
  • Loading branch information
BishopJohnson committed Jul 18, 2022
1 parent f85bef6 commit e32098b
Show file tree
Hide file tree
Showing 528 changed files with 17,664 additions and 12,011 deletions.
2 changes: 1 addition & 1 deletion .conan/profiles/workflows/ubuntu-latest
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ compiler.version=9
os=Linux
os_build=Linux
[options]
with_default_http_client=True
with_default_http_client=False
with_default_ws_client=False
[build_requires]
[env]
75 changes: 74 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,77 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

## [1.0.0.2000] - 2022-07-18

### Added

- Added `JsonValue` class.
- Added `JsonUtils` utility class.
- Added `EnumUtils` utility class.
- Added `to_json()` member-function to `ISerializable`.
- Added reauthentication features to `ProjectClient`.
- Added `close()` and `is_closed()` member-functions to `ClientMiddleware`.

### Changed

- Enums and constant expressions now use pascal case instead of upper-snake-case for their naming convention.
- Renamed `DEL` value in `HttpMethod` to `Delete`.
- Renamed `ERR` value in `LogLevel` to `Error`.
- Renamed `AssetSort` to `AssetSortInput`.
- Renamed `Melt` to `MeltInput`.
- Renamed `PaginationOptions` to `PaginationInput`.
- Renamed `Request` to `Transaction`.
- Renamed `RequestState` to `TransactionState`.
- Renamed `RequestType` to `TransactionType`.
- Renamed `Trade` to `TradeInput`.
- Renamed `TransactionSort` to `TransactionSortInput`.
- Renamed `Transfers` to `TransferInput`.
- Renamed `GetRequest` to `GetTransaction`.
- Renamed `GetRequests` to `GetTransactions`.
- Renamed `ProjectTransactionRequestArguments` to `TransactionRequestArguments`.
- Renamed `TrustedPlatformMiddleware` to `ClientMiddleware`.
- Moved `AssetTransferFeeSettingsInput` to its own header file.
- Moved `HttpMethod` to its own header file.
- Moved `LogLevel` to its own header file.
- `HttpRequest` now uses setter member-functions instead of a builder.
- Getters in `HttpRequest` now return an optional.
- Builders are now nested in the classes they are implemented for.
- Build function in builder for `PusherEventService` now returns a unique-pointer.
- Moved Enjin host URI expressions in EnjinHosts.hpp into a utility class named `EnjinHosts`.
- Changed the type of value contained within the optional for `AssetVariant::get_variant_metadata()` from a string
to `JsonValue`.
- Changed the type of value contained within the optional for `TransactionEvent::get_inputs()` from a vector of strings
to a vector of type `JsonValue`.
- Changed the type of value contained within the optional for `TransactionEvent::get_non_indexedinputs()` from a vector
of strings to a vector of type `JsonValue`.
- Changed the type of value contained within the optional for `TransactionEvent::get_indexed_inputs()` from a vector of
strings to a vector of type `JsonValue`.
- Changed the type of value contained within the optional for `TransactionLog::get_data()` from a vector of strings to a
vector of type `JsonValue`.
- Changed the type of value contained within the optional for `TransactionLog::get_topics()` from a vector of strings to
a vector of type `JsonValue`.
- Changed methods to use pass-by-value instead of pass-by-reference where appropriate.
- Moved functionality of `TrustedPlatformHandler` over to `ClientMiddleware`.
- Copy and move constructors for `PlayerClient`, `ProjectClient`, and `PusherEventService` are now explicitly deleted.
- Constructors for schema classes now take a unique-pointer for an HTTP client instead of a middleware.
- The future returned by `PusherEventService::shutdown()` no longer completes exceptionally if the function is called
prior to starting the service.
- The destructor for `PusherEventService` now attempts to shut down the service.
- Argument interfaces for requests no longer override parent functions to access internal implementations.
- Argument interfaces for requests now use static-cast instead of dynamic-cast for their chaining functions.
- Content-Type header for `HttpRequest` is now stored in its headers set.

### Removed

- Removed internal argument implementation classes.
- Removed class `LoggerImpl` from public space.

### Fixed

- `ClientMiddleware` now checks if its HTTP client is null.
- Added template specializations of `BalanceFragmentArguments` for `GetPlayer`, `GetPlayers`, `GetWallet`,
and `GetWallets` requests.

## [1.0.0.1006] - 2022-07-05

### Added
Expand Down Expand Up @@ -88,7 +159,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- Initial alpha release.

[Unreleased]: https://github.com/enjin/enjin-cpp-sdk/compare/1.0.0.1006...HEAD
[Unreleased]: https://github.com/enjin/enjin-cpp-sdk/compare/1.0.0.2000...HEAD

[1.0.0.2000]: https://github.com/enjin/enjin-cpp-sdk/compare/1.0.0.1006...1.0.0.2000

[1.0.0.1006]: https://github.com/enjin/enjin-cpp-sdk/compare/1.0.0.1005...1.0.0.1006

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include(GenerateExportHeader)
### Define project and set properties
project(enjinsdk
LANGUAGES CXX
VERSION 1.0.0.1006)
VERSION 1.0.0.2000)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
Expand Down
2 changes: 1 addition & 1 deletion DOXYFILE
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "Enjin C++ SDK"
PROJECT_NUMBER = 1.0.0.1006
PROJECT_NUMBER = 1.0.0.2000
PROJECT_BRIEF = "A C++ SDK for creating games using the Enjin blockchain platform."
PROJECT_LOGO = doxygenIcon.png
OUTPUT_DIRECTORY =
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ using namespace enjin::sdk::project;
int main() {
// Builds the project client to run on the Goerli test network.
// See: https://goerli.cloud.enjin.io to sign up for the test network.
std::unique_ptr<ProjectClient> client = ProjectClientBuilder()
.base_uri(GOERLI) // From EnjinHosts
std::unique_ptr<ProjectClient> client = ProjectClient::builder()
.base_uri(EnjinHosts::Goerli)
.build();

// Creates the request to authenticate the client.
Expand Down
39 changes: 19 additions & 20 deletions include/enjinsdk/BaseSchema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
#include "enjinsdk_export.h"
#include "enjinsdk/GraphqlResponse.hpp"
#include "enjinsdk/LoggerProvider.hpp"
#include "enjinsdk/TrustedPlatformMiddleware.hpp"
#include "enjinsdk/ClientMiddleware.hpp"
#include "enjinsdk/internal/AbstractGraphqlRequest.hpp"
#include <exception>
#include <future>
#include <memory>
#include <string>
#include <utility>
#include <vector>

namespace enjin::sdk {
Expand All @@ -34,6 +35,10 @@ class ENJINSDK_EXPORT BaseSchema {
public:
BaseSchema() = delete;

BaseSchema(const BaseSchema&) = delete;

BaseSchema(BaseSchema&&) = delete;

/// \brief Default destructor.
~BaseSchema() = default;

Expand All @@ -43,19 +48,19 @@ class ENJINSDK_EXPORT BaseSchema {

protected:
/// \brief The middleware for communicating with the platform.
TrustedPlatformMiddleware middleware;
const std::unique_ptr<ClientMiddleware> middleware;

/// \brief The logger provider.
std::shared_ptr<utils::LoggerProvider> logger_provider;
const std::shared_ptr<utils::LoggerProvider> logger_provider;

/// \brief The name of this schema.
std::string schema;
const std::string schema;

/// \brief The sole constructor for a base schema.
/// \param middleware The platform middleware.
/// \brief Constructs an instance of this class.
/// \param http_client The HTTP client.
/// \param schema The name of the schema.
/// \param logger_provider The logger provider. Null pointer by default.
BaseSchema(TrustedPlatformMiddleware middleware,
BaseSchema(std::unique_ptr<http::IHttpClient> http_client,
std::string schema,
std::shared_ptr<utils::LoggerProvider> logger_provider = nullptr);

Expand All @@ -75,13 +80,10 @@ class ENJINSDK_EXPORT BaseSchema {
/// \return The future containing the response.
template<class T>
std::future<graphql::GraphqlResponse<T>> send_request_for_one(graphql::AbstractGraphqlRequest& request) {
http::HttpRequest http_request = create_request(request);

return std::async([this, http_request] {
auto response = send_request(http_request);

return std::async([this, http_request = create_request(request)] {
try {
return graphql::GraphqlResponse<T>(response.get_body().value());
auto http_response = send_request(http_request);
return graphql::GraphqlResponse<T>(http_response.get_body().value());
} catch (const std::exception& e) {
log_graphql_exception(e);
throw e;
Expand All @@ -96,13 +98,10 @@ class ENJINSDK_EXPORT BaseSchema {
template<class T>
std::future<graphql::GraphqlResponse<std::vector<T>>>
send_request_for_many(graphql::AbstractGraphqlRequest& request) {
http::HttpRequest http_request = create_request(request);

return std::async([this, http_request]() {
auto response = send_request(http_request);

return std::async([this, http_request = create_request(request)]() {
try {
return graphql::GraphqlResponse<std::vector<T>>(response.get_body().value());
auto http_response = send_request(std::move(http_request));
return graphql::GraphqlResponse<std::vector<T>>(http_response.get_body().value());
} catch (const std::exception& e) {
log_graphql_exception(e);
throw e;
Expand All @@ -115,7 +114,7 @@ class ENJINSDK_EXPORT BaseSchema {

void log_graphql_exception(const std::exception& e);

http::HttpResponse send_request(const http::HttpRequest& request);
http::HttpResponse send_request(http::HttpRequest request);
};

}
Expand Down
88 changes: 88 additions & 0 deletions include/enjinsdk/ClientMiddleware.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* Copyright 2021 Enjin Pte. Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef ENJINSDK_CLIENTMIDDLEWARE_HPP
#define ENJINSDK_CLIENTMIDDLEWARE_HPP

#include "enjinsdk_export.h"
#include "enjinsdk/GraphqlQueryRegistry.hpp"
#include "enjinsdk/HttpRequest.hpp"
#include "enjinsdk/IHttpClient.hpp"
#include <memory>
#include <mutex>

namespace enjin::sdk {

/// \brief Middleware class used by clients to communicate with the platform.
class ENJINSDK_EXPORT ClientMiddleware {
public:
ClientMiddleware() = delete;

/// \brief Constructs the middleware with the underlying HTTP client and debug option.
/// \param client The HTTP client.
explicit ClientMiddleware(std::unique_ptr<http::IHttpClient> client);

ClientMiddleware(const ClientMiddleware&) = delete;

ClientMiddleware(ClientMiddleware&&) = delete;

/// \brief Default destructor.
~ClientMiddleware() = default;

/// \brief Closes the connection with the platform.
void close();

/// \brief Creates a new HTTP request and sets any necessary data needed for communicating with the platform.
/// \return The request.
http::HttpRequest create_request() const;

/// \brief Returns the query registry used by the middleware.
/// \return The query registry.
[[nodiscard]] const graphql::GraphqlQueryRegistry& get_query_registry() const;

/// \brief Returns the HTTP client used by the middleware.
/// \return The HTTP client.
[[nodiscard]] const std::unique_ptr<http::IHttpClient>& get_client() const;

/// \brief Determines whether this middleware is authenticated.
/// \return Whether this middleware is authenticated.
bool is_authenticated() const;

/// \brief Determines if the connection this middleware has with the platform is closed.
/// \return Whether the connection is closed.
[[nodiscard]] bool is_closed() const;

/// \brief Sets the authentication token for this middleware.
/// \param auth_token The auth token.
void set_auth_token(std::string token);

private:
std::string auth_token;
graphql::GraphqlQueryRegistry query_registry;
std::unique_ptr<http::IHttpClient> client;

// Mutexes
mutable std::mutex auth_token_mutex;

/// \brief The schema of the Authorization request header.
static constexpr char AUTHORIZATION_SCHEMA[] = "Bearer";

/// \brief The prefix for the default user agent value of this SDK in "<product>/<version>" format.
static constexpr char USER_AGENT_PREFIX[] = "Enjin-CPP-SDK/v";
};

}

#endif //ENJINSDK_CLIENTMIDDLEWARE_HPP
25 changes: 16 additions & 9 deletions include/enjinsdk/EnjinHosts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,29 @@
* limitations under the License.
*/

/* This header file contains the host names for Enjin networks.
*/

#ifndef ENJINCPPSDK_ENJINHOSTS_HPP
#define ENJINCPPSDK_ENJINHOSTS_HPP

#include "enjinsdk_export.h"

namespace enjin::sdk {

/// \brief The URI for the Enjin Platform on the Goerli test network.
static constexpr char GOERLI[] = "https://goerli.cloud.enjin.io";
/// \brief The network hosts used by the Enjin Platform.
class ENJINSDK_EXPORT EnjinHosts final {
public:
EnjinHosts() = delete;

~EnjinHosts() = delete;

/// \brief The URI for the Enjin Platform on the Goerli test network.
static constexpr char Goerli[] = "https://goerli.cloud.enjin.io";

/// \brief The URI for the Enjin Platform on the main network.
static constexpr char MAIN_NET[] = "https://cloud.enjin.io";
/// \brief The URI for the main Enjin Cloud.
static constexpr char MainNet[] = "https://cloud.enjin.io";

/// \brief The URI for the Enjin Platform on the JumpNet network.
static constexpr char JUMP_NET[] = "https://jumpnet.cloud.enjin.io";
/// \brief The URI for the JumpNet network.
static constexpr char JumpNet[] = "https://jumpnet.cloud.enjin.io";
};

}

Expand Down
Loading

0 comments on commit e32098b

Please sign in to comment.