-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from immutable/feat/bridge
feat: marketplace bridge (#3191)
- Loading branch information
Showing
5 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+13 KB
(100%)
Content/BlueprintSampleContent/ImtblAuthenticatedWidget4_26.uasset
Binary file not shown.
Binary file added
BIN
+699 KB
Content/BlueprintSampleContent/Marketplace/ImtblBridgeWidget4_26.uasset
Binary file not shown.
73 changes: 73 additions & 0 deletions
73
Source/Immutable/Private/Immutable/Marketplace/ImtblBridgeRequest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "Immutable/Marketplace/ImtblBridgeRequest.h" | ||
|
||
#include "GenericPlatform/GenericPlatformHttp.h" | ||
|
||
FString FImtblBridgeRequestQueryParams::GetPercentEncodedUrl() const | ||
{ | ||
TArray<FString> QueryParams; | ||
|
||
if (!FromChainID.IsEmpty()) | ||
{ | ||
QueryParams.Add(FString::Printf(TEXT("%s=%s"), TEXT("fromChain"), *FGenericPlatformHttp::UrlEncode(FromChainID))); | ||
} | ||
|
||
if (!FromTokenAddress.IsEmpty()) | ||
{ | ||
// Token address is case-sensitive. | ||
QueryParams.Add(FString::Printf(TEXT("%s=%s"), TEXT("fromToken"), *FGenericPlatformHttp::UrlEncode(FromTokenAddress.ToLower()))); | ||
} | ||
|
||
if (!ToChainID.IsEmpty()) | ||
{ | ||
QueryParams.Add(FString::Printf(TEXT("%s=%s"), TEXT("toChain"), *FGenericPlatformHttp::UrlEncode(ToChainID))); | ||
} | ||
|
||
if (!ToTokenAddress.IsEmpty()) | ||
{ | ||
// Token address is case-sensitive. | ||
QueryParams.Add(FString::Printf(TEXT("%s=%s"), TEXT("toToken"), *FGenericPlatformHttp::UrlEncode(ToTokenAddress.ToLower()))); | ||
} | ||
|
||
return FString::Join(QueryParams, TEXT("&")); | ||
} | ||
|
||
bool UImtblBridgeRequest::GetBaseUrl(EImtblEnvironment Environment, FString& BaseUrl) const | ||
{ | ||
if (const FString* Find = BaseUrls.Find(Environment)) | ||
{ | ||
BaseUrl = *Find; | ||
|
||
return true; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool UImtblBridgeRequest::ComputePath(FString& ComputedPath, EImtblEnvironment Environment, FString FromChainID, FString FromTokenAddress, FString ToChainID, FString ToTokenAddress) const | ||
{ | ||
FString BaseUrl; | ||
bool bFoundBaseUrl = GetBaseUrl(Environment, BaseUrl); | ||
|
||
if (!bFoundBaseUrl) | ||
{ | ||
return false; | ||
} | ||
|
||
FImtblBridgeRequestQueryParams QueryParams; | ||
QueryParams.FromChainID = FromChainID; | ||
QueryParams.FromTokenAddress = FromTokenAddress; | ||
QueryParams.ToChainID = ToChainID; | ||
QueryParams.ToTokenAddress = ToTokenAddress; | ||
|
||
const FString QueryParamsPercentEncodedUrl = QueryParams.GetPercentEncodedUrl(); | ||
|
||
ComputedPath = FString::Printf | ||
( | ||
TEXT("%s%s%s"), | ||
*BaseUrl, | ||
!QueryParamsPercentEncodedUrl.IsEmpty() ? TEXT("?") : TEXT(""), | ||
*QueryParamsPercentEncodedUrl | ||
); | ||
|
||
return true; | ||
} |
71 changes: 71 additions & 0 deletions
71
Source/Immutable/Public/Immutable/Marketplace/ImtblBridgeRequest.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#pragma once | ||
|
||
#include "ImtblBridgeRequest.generated.h" | ||
|
||
/** | ||
* Bridge request query params | ||
*/ | ||
USTRUCT(BlueprintType) | ||
struct FImtblBridgeRequestQueryParams | ||
{ | ||
GENERATED_BODY() | ||
|
||
public: | ||
FString GetPercentEncodedUrl() const; | ||
|
||
public: | ||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Immutable") | ||
FString FromChainID; | ||
|
||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Immutable") | ||
FString FromTokenAddress; | ||
|
||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Immutable") | ||
FString ToChainID; | ||
|
||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Immutable") | ||
FString ToTokenAddress; | ||
}; | ||
|
||
/** | ||
* Functionality to generate bridge requests | ||
*/ | ||
UCLASS(BlueprintType, Config = "Immutable", DefaultConfig) | ||
class IMMUTABLE_API UImtblBridgeRequest : public UObject | ||
{ | ||
GENERATED_BODY() | ||
|
||
public: | ||
/** | ||
* Finds the base url associated with the environment. | ||
* | ||
* @param Environment The environment that will be used to look the value up. Only sandbox and production environment are supported. | ||
* @param BaseUrl The base url associated with the key. | ||
* @return True if an item was found (False indicates nothing in the map uses the provided environment). | ||
*/ | ||
UFUNCTION(BlueprintPure, Category = "Immutable") | ||
bool GetBaseUrl(EImtblEnvironment Environment, FString& BaseUrl) const; | ||
|
||
/** | ||
* Generates a link for the bridge flow. | ||
* | ||
* @param ComputedPath [Out] The generated link. | ||
* @param Environment [In] The environment for which the path is being computed for (e.g. sandbox, production). | ||
* @param FromChainID [Optional] The ID of the source blockchain. Default value is an empty string. | ||
* @param FromTokenAddress [Optional] The contract address of the token being bridged from. | ||
* This should be a contract address of a token on the source blockchain. | ||
* Default value is an empty string. | ||
* @param ToChainID [Optional] The ID of the destination blockchain. Default value is an empty string. | ||
* @param ToTokenAddress [Optional] The contract address of the token being bridged to. | ||
* This should be a contract address of a token on the destination blockchain. | ||
* Default is an empty string. | ||
* | ||
* @return True if link was computed (False indicates link failed to compute). | ||
*/ | ||
UFUNCTION(BlueprintCallable, BlueprintPure = "False", Category = "Immutable") | ||
bool ComputePath(FString& ComputedPath, EImtblEnvironment Environment, FString FromChainID = TEXT(""), FString FromTokenAddress = TEXT(""), FString ToChainID = TEXT(""), FString ToTokenAddress = TEXT("")) const; | ||
|
||
public: | ||
UPROPERTY(Config, EditDefaultsOnly, BlueprintReadOnly, Category = "Immutable") | ||
TMap<EImtblEnvironment, FString> BaseUrls; | ||
}; |