Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DX-2784] feat: added zkevm transaction receipt acquirement method #185

Merged
merged 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,411 changes: 1,316 additions & 95 deletions sample/Assets/Scenes/AuthenticatedScene.unity

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions sample/Assets/Scripts/AuthenticatedScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Immutable.Passport;
using Immutable.Passport.Model;
using Immutable.Passport.Event;
using Unity.VisualScripting;

public class AuthenticatedScript : MonoBehaviour
{
Expand Down Expand Up @@ -48,6 +49,7 @@ public class AuthenticatedScript : MonoBehaviour
[SerializeField] private Button SendTransactionButton;
[SerializeField] private Button RequestAccountsButton;
[SerializeField] private Button GetBalanceButton;
[SerializeField] private Button GetTransactionReceiptButton;

// ZkEVM Get Balance Transaction
[SerializeField] private Canvas ZkGetBalanceCanvas;
Expand All @@ -59,6 +61,10 @@ public class AuthenticatedScript : MonoBehaviour
[SerializeField] private InputField ZkSendTransactionValue;
[SerializeField] private InputField ZkSendTransactionData;

// ZkEVM Get Transaction Receipt
[SerializeField] private Canvas ZkGetTransactionReceiptCanvas;
[SerializeField] private InputField ZkGetTransactionReceiptHash;

private Passport passport;
#pragma warning restore CS8618

Expand Down Expand Up @@ -315,6 +321,7 @@ public async void ConnectEvm()
SendTransactionButton.gameObject.SetActive(true);
RequestAccountsButton.gameObject.SetActive(true);
GetBalanceButton.gameObject.SetActive(true);
GetTransactionReceiptButton.gameObject.SetActive(true);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -399,6 +406,34 @@ public void CancelZkGetBalance()
ZkGetBalanceCanvas.gameObject.SetActive(false);
}

public async void GetZkTransactionReceiptStatus()
{
try
{
ShowOutput($"Getting zkEVM transaction receipt status...");

TransactionReceiptResponse response = await passport.ZkEvmGetTransactionReceipt(ZkGetTransactionReceiptHash.text);
ShowOutput($"Transaction receipt status: {(response.status == "0x1" ? "Success" : "Failed")}");
}
catch (Exception ex)
{
ShowOutput($"Failed to get transaction receipt: {ex.Message}");
}
}

public void ShowZkTransactionReceiptStatus()
{
AuthenticatedCanvas.gameObject.SetActive(false);
ZkGetTransactionReceiptCanvas.gameObject.SetActive(true);
ZkGetTransactionReceiptHash.text = "";
}

public void CancelZkTransactionReceiptStatus()
{
AuthenticatedCanvas.gameObject.SetActive(true);
ZkGetTransactionReceiptCanvas.gameObject.SetActive(false);
}

public void ClearStorageAndCache()
{
#if (UNITY_IPHONE && !UNITY_EDITOR) || (UNITY_ANDROID && !UNITY_EDITOR)
Expand Down
12 changes: 6 additions & 6 deletions src/Packages/Passport/Runtime/Resources/index.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace Immutable.Passport.Model
{
[Serializable]
public class TransactionReceiptRequest
{
public string txHash;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace Immutable.Passport.Model
{
public class TransactionReceiptResponse
{
public string blockHash;

public string blockNumber;

public string contractAddress;

public string cumulativeGasUsed;

public string effectiveGasPrice;

public string from;

public string gasUsed;

public Log[] logs;

public string logsBloom;

/// <summary>
/// Either 1 (success) or 0 (failure) encoded as a hexadecimal.
/// </summary>
public string status;
YermekG marked this conversation as resolved.
Show resolved Hide resolved

public string to;

public string transactionHash;

public string transactionIndex;

public string type;

public class Log
{
public string address;

public string[] topics;

public string data;

public string blockNumber;

public string transactionHash;

public string transactionIndex;

public string blockHash;

public string logIndex;

public bool removed;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static class ZK_EVM
{
public const string CONNECT_EVM = "connectEvm";
public const string SEND_TRANSACTION = "zkEvmSendTransaction";
public const string GET_TRANSACTION_RECEIPT = "zkEvmGetTransactionReceipt";
public const string REQUEST_ACCOUNTS = "zkEvmRequestAccounts";
public const string GET_BALANCE = "zkEvmGetBalance";
}
Expand Down
10 changes: 10 additions & 0 deletions src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,16 @@ public async UniTask<string> ZkEvmSendTransaction(TransactionRequest request)
return callResponse.GetStringResult();
}

public async UniTask<TransactionReceiptResponse> ZkEvmGetTransactionReceipt(string hash)
{
string json = JsonUtility.ToJson(new TransactionReceiptRequest()
{
txHash = hash
});
string jsonResponse = await communicationsManager.Call(PassportFunction.ZK_EVM.GET_TRANSACTION_RECEIPT, json);
return jsonResponse.OptDeserializeObject<TransactionReceiptResponse>();
}

public async UniTask<List<string>> ZkEvmRequestAccounts()
{
string callResponse = await communicationsManager.Call(PassportFunction.ZK_EVM.REQUEST_ACCOUNTS);
Expand Down
12 changes: 12 additions & 0 deletions src/Packages/Passport/Runtime/Scripts/Public/Passport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,18 @@ public async UniTask<string> ZkEvmSendTransaction(TransactionRequest request)
return await GetPassportImpl().ZkEvmSendTransaction(request);
}

/// <summary>
/// Retrieves the transaction information of a given transaction hash. This function uses the Ethereum JSON-RPC <c>eth_getTransactionReceipt</c> method.
/// <returns>
/// The receipt of the transaction or null if it is still processing.

/// </returns>
/// </summary>
public async UniTask<TransactionReceiptResponse> ZkEvmGetTransactionReceipt(string hash)
{
return await GetPassportImpl().ZkEvmGetTransactionReceipt(hash);
}

/// <summary>
/// Returns a list of addresses owned by the user
/// <returns>
Expand Down
Loading