Skip to content

Commit

Permalink
[DX-2787] feat: added zkevm transaction receipt acquirement method (#85)
Browse files Browse the repository at this point in the history
* feat: added get transaction receipt functionality

* chore: game bridge update, tag 1.35.5

* fix: removed unnecessary code, edited comments

* feat: updated widget blueprints with new method
  • Loading branch information
YermekG authored May 23, 2024
1 parent bd08d56 commit 73c457b
Show file tree
Hide file tree
Showing 13 changed files with 289 additions and 2 deletions.
Binary file not shown.
Binary file modified Content/BlueprintSampleContent/ImtblEvmBalanceWidget4_26.uasset
Binary file not shown.
Binary file not shown.
Binary file modified Content/PackagedResources/index.uasset
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Fill out your copyright notice in the Description page of Project Settings.

#include "Immutable/Actions/ImtblPassportZkEvmGetTransactionReceiptAA.h"

#include "Immutable/ImmutablePassport.h"
#include "Immutable/ImmutableSubsystem.h"
#include "Immutable/Misc/ImtblLogging.h"

UImtblPassportZkEvmGetTransactionReceiptAA* UImtblPassportZkEvmGetTransactionReceiptAA::ZkEvmGetTransactionReceipt(UObject* WorldContextObject, const FString& Hash)
{
UImtblPassportZkEvmGetTransactionReceiptAA* PassportZkEvmSendTransactionBlueprintNode = NewObject<UImtblPassportZkEvmGetTransactionReceiptAA>();

PassportZkEvmSendTransactionBlueprintNode->WorldContextObject = WorldContextObject;
PassportZkEvmSendTransactionBlueprintNode->Hash = Hash;

return PassportZkEvmSendTransactionBlueprintNode;
}

void UImtblPassportZkEvmGetTransactionReceiptAA::Activate()
{
if (!WorldContextObject || !WorldContextObject->GetWorld())
{
const FString ErrorMessage = "ZkEvmSendTransaction failed due to missing world or world " "context object.";
IMTBL_WARN("%s", *ErrorMessage)
Failed.Broadcast(ErrorMessage, FZkEvmTransactionReceipt());
return;
}

GetSubsystem()->WhenReady(this, &UImtblPassportZkEvmGetTransactionReceiptAA::DoZkEvmGetTransactionReceipt);
}

void UImtblPassportZkEvmGetTransactionReceiptAA::DoZkEvmGetTransactionReceipt(TWeakObjectPtr<UImtblJSConnector> JSConnector)
{
auto Passport = GetSubsystem()->GetPassport();

if (Passport.IsValid())
{
Passport->ZkEvmGetTransactionReceipt({ Hash }, UImmutablePassport::FImtblPassportResponseDelegate::CreateUObject(this, &UImtblPassportZkEvmGetTransactionReceiptAA::OnZkEvmGetTransactionReceiptResponse));
}
}

void UImtblPassportZkEvmGetTransactionReceiptAA::OnZkEvmGetTransactionReceiptResponse(FImmutablePassportResult Result)
{
if (Result.Success)
{
auto Receipt = JsonObjectToUStruct<FZkEvmTransactionReceipt>(Result.Response.JsonObject);

if (Receipt.IsSet())
{
IMTBL_LOG("ZkEvmGetTransactionReceipt success")
Success.Broadcast(TEXT(""), Receipt.GetValue());
}
else
{
IMTBL_LOG("ZkEvm Transaction Receipt is not provided")
Success.Broadcast(TEXT(""), FZkEvmTransactionReceipt());
}
}
else
{
IMTBL_LOG("ZkEvmGetTransactionReceipt failed")
Failed.Broadcast(Result.Message, FZkEvmTransactionReceipt());
}
}
37 changes: 37 additions & 0 deletions Source/Immutable/Private/Immutable/ImmutableBlueprintLibrary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "Immutable/ImmutableBlueprintLibrary.h"


void UImmutableBlueprintLibrary::BreakFZkEvmTransactionReceiptLog(FZkEvmTransactionReceiptLog Log, FString& Address, FString& Data,
FString& BlockNumber, FString& TransactionHash, FString& TransactionIndex, FString& BlockHash, FString& LogIndex, bool& Removed,
TArray<FString>& Topics)
{
Address = Log.address;
Data = Log.data;
BlockNumber = Log.blockNumber;
TransactionHash = Log.transactionHash;
TransactionIndex = Log.transactionIndex;
BlockHash = Log.blockHash;
LogIndex = Log.logIndex;
Removed = Log.removed;
Topics = Log.topics;
}

void UImmutableBlueprintLibrary::BreakZkEvmTransactionReceipt(FZkEvmTransactionReceipt Receipt, FString& BlockHash, FString& BlockNumber,
FString& ContractAddress, FString& CumulativeGasUsed, FString& EffectiveGasPrice, FString& From, FString& GasUsed, FString& LogsBloom,
FString& Status, FString& To, FString& TransactionHash, FString& TransactionIndex, FString& Type, TArray<FZkEvmTransactionReceiptLog>& Logs)
{
BlockHash = Receipt.blockHash;
BlockNumber = Receipt.blockNumber;
ContractAddress = Receipt.contractAddress;
CumulativeGasUsed = Receipt.cumulativeGasUsed;
EffectiveGasPrice = Receipt.effectiveGasPrice;
From = Receipt.from;
GasUsed = Receipt.gasUsed;
LogsBloom = Receipt.logsBloom;
Status = Receipt.status;
To = Receipt.to;
TransactionHash = Receipt.transactionHash;
TransactionIndex = Receipt.transactionIndex;
Type = Receipt.type;
Logs = Receipt.logs;
}
22 changes: 22 additions & 0 deletions Source/Immutable/Private/Immutable/ImmutablePassport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ void UImmutablePassport::ZkEvmSendTransaction(const FImtblTransactionRequest& Re
CallJS(ImmutablePassportAction::ZkEvmSendTransaction, UStructToJsonString(Request), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnZkEvmSendTransactionResponse));
}

void UImmutablePassport::ZkEvmGetTransactionReceipt(const FZkEvmTransactionReceiptRequest& Request, const FImtblPassportResponseDelegate& ResponseDelegate)
{
CallJS(ImmutablePassportAction::ZkEvmGetTransactionReceipt, UStructToJsonString(Request), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnZkEvmGetTransactionReceiptResponse));
}

void UImmutablePassport::ConfirmCode(const FString& DeviceCode, const float Interval, const FImtblPassportResponseDelegate& ResponseDelegate)
{
FImmutablePassportCodeConfirmRequestData Data{DeviceCode, Interval};
Expand Down Expand Up @@ -647,6 +652,23 @@ void UImmutablePassport::OnZkEvmSendTransactionResponse(FImtblJSResponse Respons
}
}

void UImmutablePassport::OnZkEvmGetTransactionReceiptResponse(FImtblJSResponse Response)
{
if (auto ResponseDelegate = GetResponseDelegate(Response))
{
FString Msg;
bool bSuccess = true;

if (!Response.success)
{
IMTBL_WARN("zkEVM transaction receipt retrieval failed.");
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
bSuccess = false;
}
ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{bSuccess, Msg, Response});
}
}

void UImmutablePassport::OnConfirmCodeResponse(FImtblJSResponse Response)
{
if (auto ResponseDelegate = GetResponseDelegate(Response))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Immutable/ImmutablePassport.h"
#include "ImtblBlueprintAsyncAction.h"

#include "ImtblPassportZkEvmGetTransactionReceiptAA.generated.h"


/**
*
*/
UCLASS()
class IMMUTABLE_API UImtblPassportZkEvmGetTransactionReceiptAA : public UImtblBlueprintAsyncAction
{
GENERATED_BODY()

DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FZkEvmGetTransactionReceiptOutputPin, FString, ErrorMessage, const struct FZkEvmTransactionReceipt&, Receipt);

public:
UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", BlueprintInternalUseOnly = "true"), Category = "Immutable")
static UImtblPassportZkEvmGetTransactionReceiptAA* ZkEvmGetTransactionReceipt(UObject* WorldContextObject, const FString& Hash);

virtual void Activate() override;

private:
FString Hash;

UPROPERTY(BlueprintAssignable)
FZkEvmGetTransactionReceiptOutputPin Success;
UPROPERTY(BlueprintAssignable)
FZkEvmGetTransactionReceiptOutputPin Failed;

void DoZkEvmGetTransactionReceipt(TWeakObjectPtr<class UImtblJSConnector> JSGetConnector);
void OnZkEvmGetTransactionReceiptResponse(FImmutablePassportResult Result);
};
22 changes: 22 additions & 0 deletions Source/Immutable/Public/Immutable/ImmutableBlueprintLibrary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "Kismet/BlueprintFunctionLibrary.h"
#include "Immutable/ImmutableDataTypes.h"

#include "ImmutableBlueprintLibrary.generated.h"


UCLASS()
class IMMUTABLE_API UImmutableBlueprintLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()

public:

UFUNCTION(BlueprintPure, Category = "Immutable", meta = (NativeBreakFunc))
static void BreakFZkEvmTransactionReceiptLog(FZkEvmTransactionReceiptLog Log, FString& Address, FString& Data, FString& BlockNumber, FString& TransactionHash, FString& TransactionIndex, FString& BlockHash, FString& LogIndex, bool& Removed, TArray<FString>& Topics);

UFUNCTION(BlueprintPure, Category = "Immutable", meta = (NativeBreakFunc))
static void BreakZkEvmTransactionReceipt(FZkEvmTransactionReceipt Receipt, FString& BlockHash, FString& BlockNumber, FString& ContractAddress, FString& CumulativeGasUsed, FString& EffectiveGasPrice, FString& From, FString& GasUsed, FString& LogsBloom, FString& Status, FString& To, FString& TransactionHash, FString& TransactionIndex, FString& Type, TArray<FZkEvmTransactionReceiptLog>& Logs);

};
83 changes: 83 additions & 0 deletions Source/Immutable/Public/Immutable/ImmutableDataTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,86 @@ struct FNftTransferDetails
UPROPERTY(BlueprintReadWrite)
FString tokenAddress;
};


USTRUCT(BlueprintType, meta = (HasNativeBreak = "/Script/Immutable.ImmutableBlueprintLibrary.BreakFZkEvmTransactionReceiptLog"))
struct IMMUTABLE_API FZkEvmTransactionReceiptLog
{
GENERATED_BODY()

UPROPERTY()
FString address;

UPROPERTY()
TArray<FString> topics;

UPROPERTY()
FString data;

UPROPERTY()
FString blockNumber;

UPROPERTY()
FString transactionHash;

UPROPERTY()
FString transactionIndex;

UPROPERTY()
FString blockHash;

UPROPERTY()
FString logIndex;

UPROPERTY()
bool removed;
};

USTRUCT(BlueprintType, meta = (HasNativeBreak = "/Script/Immutable.ImmutableBlueprintLibrary.BreakZkEvmTransactionReceipt"))
struct IMMUTABLE_API FZkEvmTransactionReceipt
{
GENERATED_BODY()

UPROPERTY()
FString blockHash;

UPROPERTY()
FString blockNumber;

UPROPERTY()
FString contractAddress;

UPROPERTY()
FString cumulativeGasUsed;

UPROPERTY()
FString effectiveGasPrice;

UPROPERTY()
FString from;

UPROPERTY()
FString gasUsed;

UPROPERTY(BlueprintReadOnly)
TArray<FZkEvmTransactionReceiptLog> logs;

UPROPERTY()
FString logsBloom;

// Either 1 (success) or 0 (failure) encoded as a hexadecimal.
UPROPERTY()
FString status;

UPROPERTY()
FString to;

UPROPERTY()
FString transactionHash;

UPROPERTY()
FString transactionIndex;

UPROPERTY()
FString type;
};
1 change: 1 addition & 0 deletions Source/Immutable/Public/Immutable/ImmutableNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace ImmutablePassportAction
const FString ZkEvmRequestAccounts = TEXT("zkEvmRequestAccounts");
const FString ZkEvmGetBalance = TEXT("zkEvmGetBalance");
const FString ZkEvmSendTransaction = TEXT("zkEvmSendTransaction");
const FString ZkEvmGetTransactionReceipt = TEXT("zkEvmGetTransactionReceipt");

#if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
const FString GetPKCEAuthUrl = TEXT("getPKCEAuthUrl");
Expand Down
11 changes: 11 additions & 0 deletions Source/Immutable/Public/Immutable/ImmutablePassport.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ class IMMUTABLE_API UImmutablePassport : public UObject
* FImtblPassportResponseDelegate to call on response from JS.
*/
void ZkEvmSendTransaction(const FImtblTransactionRequest& Request, const FImtblPassportResponseDelegate& ResponseDelegate);

/**
* Retrieves the transaction information of a given transaction hash. This function uses the Ethereum JSON-RPC
* <c>eth_getTransactionReceipt</c> method. Response will contain the receipt of the transaction or null if it is still processing.
* @param Request The request data(Hash) to perform the transaction.
* @param ResponseDelegate The response delegate of type
* FImtblPassportResponseDelegate to call on response from JS.
*/
void ZkEvmGetTransactionReceipt(const FZkEvmTransactionReceiptRequest& Request, const FImtblPassportResponseDelegate& ResponseDelegate);

void GetIdToken(const FImtblPassportResponseDelegate& ResponseDelegate);
void GetAccessToken(const FImtblPassportResponseDelegate& ResponseDelegate);
void GetAddress(const FImtblPassportResponseDelegate& ResponseDelegate);
Expand Down Expand Up @@ -194,6 +204,7 @@ class IMMUTABLE_API UImmutablePassport : public UObject
void OnZkEvmRequestAccountsResponse(FImtblJSResponse Response);
void OnZkEvmGetBalanceResponse(FImtblJSResponse Response);
void OnZkEvmSendTransactionResponse(FImtblJSResponse Response);
void OnZkEvmGetTransactionReceiptResponse(FImtblJSResponse Response);
void OnConfirmCodeResponse(FImtblJSResponse Response);
#if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC
void OnGetPKCEAuthUrlResponse(FImtblJSResponse Response);
Expand Down
13 changes: 11 additions & 2 deletions Source/Immutable/Public/Immutable/ImmutableRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct IMMUTABLE_API FImtblTransactionRequest
FString value;
};

USTRUCT()
USTRUCT(BlueprintType)
struct IMMUTABLE_API FImxTransferRequest
{
GENERATED_BODY()
Expand All @@ -42,7 +42,7 @@ struct IMMUTABLE_API FImxTransferRequest
FString ToJsonString() const;
};

USTRUCT()
USTRUCT(BlueprintType)
struct IMMUTABLE_API FImxBatchNftTransferRequest
{
GENERATED_BODY()
Expand All @@ -52,3 +52,12 @@ struct IMMUTABLE_API FImxBatchNftTransferRequest

FString ToJsonString() const;
};

USTRUCT(BlueprintType)
struct IMMUTABLE_API FZkEvmTransactionReceiptRequest
{
GENERATED_BODY()

UPROPERTY()
FString txHash;
};

0 comments on commit 73c457b

Please sign in to comment.