Skip to content

Commit

Permalink
chore: updated zkevm api (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
YermekG authored Nov 3, 2024
1 parent 5774b10 commit 1f4be53
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 260 deletions.
27 changes: 27 additions & 0 deletions Source/Experimental/ImmutablezkEVMAPI/Private/APIMetadataApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,33 @@ void APIMetadataApi::OnListMetadataForChainResponse(FHttpRequestPtr HttpRequest,
Delegate.ExecuteIfBound(Response);
}

FHttpRequestPtr APIMetadataApi::ListStacks(const ListStacksRequest& Request, const FListStacksDelegate& Delegate /*= FListStacksDelegate()*/) const
{
if (!IsValid())
return nullptr;

FHttpRequestRef HttpRequest = CreateHttpRequest(Request);
HttpRequest->SetURL(*(Url + Request.ComputePath()));

for(const auto& It : AdditionalHeaderParams)
{
HttpRequest->SetHeader(It.Key, It.Value);
}

Request.SetupHttpRequest(HttpRequest);

HttpRequest->OnProcessRequestComplete().BindRaw(this, &APIMetadataApi::OnListStacksResponse, Delegate);
HttpRequest->ProcessRequest();
return HttpRequest;
}

void APIMetadataApi::OnListStacksResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FListStacksDelegate Delegate) const
{
ListStacksResponse Response;
HandleResponse(HttpResponse, bSucceeded, Response);
Delegate.ExecuteIfBound(Response);
}

FHttpRequestPtr APIMetadataApi::RefreshMetadataByID(const RefreshMetadataByIDRequest& Request, const FRefreshMetadataByIDDelegate& Delegate /*= FRefreshMetadataByIDDelegate()*/) const
{
if (!IsValid())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,64 @@ bool APIMetadataApi::ListMetadataForChainResponse::FromJson(const TSharedPtr<FJs
return TryGetJsonValue(JsonValue, Content);
}

FString APIMetadataApi::ListStacksRequest::ComputePath() const
{
TMap<FString, FStringFormatArg> PathParams = {
{ TEXT("chain_name"), FStringFormatArg(ToUrlString(ChainName)) } };

FString Path = FString::Format(TEXT("/v1/chains/{chain_name}/stacks"), PathParams);

TArray<FString> QueryParams;
QueryParams.Add(CollectionToUrlString_multi(StackId, TEXT("stack_id")));
Path += TCHAR('?');
Path += FString::Join(QueryParams, TEXT("&"));

return Path;
}

void APIMetadataApi::ListStacksRequest::SetupHttpRequest(const FHttpRequestRef& HttpRequest) const
{
static const TArray<FString> Consumes = { };
//static const TArray<FString> Produces = { TEXT("application/json") };

HttpRequest->SetVerb(TEXT("GET"));

}

void APIMetadataApi::ListStacksResponse::SetHttpResponseCode(EHttpResponseCodes::Type InHttpResponseCode)
{
Response::SetHttpResponseCode(InHttpResponseCode);
switch ((int)InHttpResponseCode)
{
case 200:
SetResponseString(TEXT("200 response"));
break;
case 400:
SetResponseString(TEXT("Bad Request (400)"));
break;
case 401:
SetResponseString(TEXT("Unauthorised Request (401)"));
break;
case 403:
SetResponseString(TEXT("Forbidden Request (403)"));
break;
case 404:
SetResponseString(TEXT("The specified resource was not found (404)"));
break;
case 429:
SetResponseString(TEXT("Too Many Requests (429)"));
break;
case 500:
SetResponseString(TEXT("Internal Server Error (500)"));
break;
}
}

bool APIMetadataApi::ListStacksResponse::FromJson(const TSharedPtr<FJsonValue>& JsonValue)
{
return TryGetJsonValue(JsonValue, Content);
}

FString APIMetadataApi::RefreshMetadataByIDRequest::ComputePath() const
{
TMap<FString, FStringFormatArg> PathParams = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
* Do not edit the class manually.
*/

#include "APIStacksApi.h"
#include "APIMetadataSearchApi.h"

#include "APIStacksApiOperations.h"
#include "APIMetadataSearchApiOperations.h"
#include "ImmutablezkEVMAPIModule.h"

#include "HttpModule.h"
Expand All @@ -21,40 +21,40 @@
namespace ImmutablezkEVMAPI
{

APIStacksApi::APIStacksApi()
APIMetadataSearchApi::APIMetadataSearchApi()
: Url(TEXT("https://api.sandbox.immutable.com"))
{
}

APIStacksApi::~APIStacksApi() {}
APIMetadataSearchApi::~APIMetadataSearchApi() {}

void APIStacksApi::SetURL(const FString& InUrl)
void APIMetadataSearchApi::SetURL(const FString& InUrl)
{
Url = InUrl;
}

void APIStacksApi::AddHeaderParam(const FString& Key, const FString& Value)
void APIMetadataSearchApi::AddHeaderParam(const FString& Key, const FString& Value)
{
AdditionalHeaderParams.Add(Key, Value);
}

void APIStacksApi::ClearHeaderParams()
void APIMetadataSearchApi::ClearHeaderParams()
{
AdditionalHeaderParams.Reset();
}

bool APIStacksApi::IsValid() const
bool APIMetadataSearchApi::IsValid() const
{
if (Url.IsEmpty())
{
UE_LOG(LogImmutablezkEVMAPI, Error, TEXT("APIStacksApi: Endpoint Url is not set, request cannot be performed"));
UE_LOG(LogImmutablezkEVMAPI, Error, TEXT("APIMetadataSearchApi: Endpoint Url is not set, request cannot be performed"));
return false;
}

return true;
}

void APIStacksApi::SetHttpRetryManager(FHttpRetrySystem::FManager& InRetryManager)
void APIMetadataSearchApi::SetHttpRetryManager(FHttpRetrySystem::FManager& InRetryManager)
{
if (RetryManager != &InRetryManager)
{
Expand All @@ -63,13 +63,13 @@ void APIStacksApi::SetHttpRetryManager(FHttpRetrySystem::FManager& InRetryManage
}
}

FHttpRetrySystem::FManager& APIStacksApi::GetHttpRetryManager()
FHttpRetrySystem::FManager& APIMetadataSearchApi::GetHttpRetryManager()
{
checkf(RetryManager, TEXT("APIStacksApi: RetryManager is null. You may have meant to set it with SetHttpRetryManager first, or you may not be using a custom RetryManager at all."))
checkf(RetryManager, TEXT("APIMetadataSearchApi: RetryManager is null. You may have meant to set it with SetHttpRetryManager first, or you may not be using a custom RetryManager at all."))
return *RetryManager;
}

FHttpRequestRef APIStacksApi::CreateHttpRequest(const Request& Request) const
FHttpRequestRef APIMetadataSearchApi::CreateHttpRequest(const Request& Request) const
{
if (!Request.GetRetryParams().IsSet())
{
Expand All @@ -89,7 +89,7 @@ FHttpRequestRef APIStacksApi::CreateHttpRequest(const Request& Request) const
}
}

void APIStacksApi::HandleResponse(FHttpResponsePtr HttpResponse, bool bSucceeded, Response& InOutResponse) const
void APIMetadataSearchApi::HandleResponse(FHttpResponsePtr HttpResponse, bool bSucceeded, Response& InOutResponse) const
{
InOutResponse.SetHttpResponse(HttpResponse);
InOutResponse.SetSuccessful(bSucceeded);
Expand Down Expand Up @@ -133,7 +133,7 @@ void APIStacksApi::HandleResponse(FHttpResponsePtr HttpResponse, bool bSucceeded
InOutResponse.SetHttpResponseCode(EHttpResponseCodes::RequestTimeout);
}

FHttpRequestPtr APIStacksApi::ListFilters(const ListFiltersRequest& Request, const FListFiltersDelegate& Delegate /*= FListFiltersDelegate()*/) const
FHttpRequestPtr APIMetadataSearchApi::ListFilters(const ListFiltersRequest& Request, const FListFiltersDelegate& Delegate /*= FListFiltersDelegate()*/) const
{
if (!IsValid())
return nullptr;
Expand All @@ -148,19 +148,19 @@ FHttpRequestPtr APIStacksApi::ListFilters(const ListFiltersRequest& Request, con

Request.SetupHttpRequest(HttpRequest);

HttpRequest->OnProcessRequestComplete().BindRaw(this, &APIStacksApi::OnListFiltersResponse, Delegate);
HttpRequest->OnProcessRequestComplete().BindRaw(this, &APIMetadataSearchApi::OnListFiltersResponse, Delegate);
HttpRequest->ProcessRequest();
return HttpRequest;
}

void APIStacksApi::OnListFiltersResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FListFiltersDelegate Delegate) const
void APIMetadataSearchApi::OnListFiltersResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FListFiltersDelegate Delegate) const
{
ListFiltersResponse Response;
HandleResponse(HttpResponse, bSucceeded, Response);
Delegate.ExecuteIfBound(Response);
}

FHttpRequestPtr APIStacksApi::ListStacks(const ListStacksRequest& Request, const FListStacksDelegate& Delegate /*= FListStacksDelegate()*/) const
FHttpRequestPtr APIMetadataSearchApi::SearchNFTs(const SearchNFTsRequest& Request, const FSearchNFTsDelegate& Delegate /*= FSearchNFTsDelegate()*/) const
{
if (!IsValid())
return nullptr;
Expand All @@ -175,46 +175,19 @@ FHttpRequestPtr APIStacksApi::ListStacks(const ListStacksRequest& Request, const

Request.SetupHttpRequest(HttpRequest);

HttpRequest->OnProcessRequestComplete().BindRaw(this, &APIStacksApi::OnListStacksResponse, Delegate);
HttpRequest->OnProcessRequestComplete().BindRaw(this, &APIMetadataSearchApi::OnSearchNFTsResponse, Delegate);
HttpRequest->ProcessRequest();
return HttpRequest;
}

void APIStacksApi::OnListStacksResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FListStacksDelegate Delegate) const
{
ListStacksResponse Response;
HandleResponse(HttpResponse, bSucceeded, Response);
Delegate.ExecuteIfBound(Response);
}

FHttpRequestPtr APIStacksApi::SearchNFTs(const SearchNFTsRequest& Request, const FSearchNFTsDelegate& Delegate /*= FSearchNFTsDelegate()*/) const
{
if (!IsValid())
return nullptr;

FHttpRequestRef HttpRequest = CreateHttpRequest(Request);
HttpRequest->SetURL(*(Url + Request.ComputePath()));

for(const auto& It : AdditionalHeaderParams)
{
HttpRequest->SetHeader(It.Key, It.Value);
}

Request.SetupHttpRequest(HttpRequest);

HttpRequest->OnProcessRequestComplete().BindRaw(this, &APIStacksApi::OnSearchNFTsResponse, Delegate);
HttpRequest->ProcessRequest();
return HttpRequest;
}

void APIStacksApi::OnSearchNFTsResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FSearchNFTsDelegate Delegate) const
void APIMetadataSearchApi::OnSearchNFTsResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FSearchNFTsDelegate Delegate) const
{
SearchNFTsResponse Response;
HandleResponse(HttpResponse, bSucceeded, Response);
Delegate.ExecuteIfBound(Response);
}

FHttpRequestPtr APIStacksApi::SearchStacks(const SearchStacksRequest& Request, const FSearchStacksDelegate& Delegate /*= FSearchStacksDelegate()*/) const
FHttpRequestPtr APIMetadataSearchApi::SearchStacks(const SearchStacksRequest& Request, const FSearchStacksDelegate& Delegate /*= FSearchStacksDelegate()*/) const
{
if (!IsValid())
return nullptr;
Expand All @@ -229,12 +202,12 @@ FHttpRequestPtr APIStacksApi::SearchStacks(const SearchStacksRequest& Request, c

Request.SetupHttpRequest(HttpRequest);

HttpRequest->OnProcessRequestComplete().BindRaw(this, &APIStacksApi::OnSearchStacksResponse, Delegate);
HttpRequest->OnProcessRequestComplete().BindRaw(this, &APIMetadataSearchApi::OnSearchStacksResponse, Delegate);
HttpRequest->ProcessRequest();
return HttpRequest;
}

void APIStacksApi::OnSearchStacksResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FSearchStacksDelegate Delegate) const
void APIMetadataSearchApi::OnSearchStacksResponse(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, FSearchStacksDelegate Delegate) const
{
SearchStacksResponse Response;
HandleResponse(HttpResponse, bSucceeded, Response);
Expand Down
Loading

0 comments on commit 1f4be53

Please sign in to comment.