Skip to content

Commit

Permalink
added zkevm get transaction receipt method
Browse files Browse the repository at this point in the history
  • Loading branch information
YermekG committed May 6, 2024
1 parent 0731409 commit 6fc7fe2
Show file tree
Hide file tree
Showing 10 changed files with 1,464 additions and 101 deletions.
1,411 changes: 1,316 additions & 95 deletions sample/Assets/Scenes/AuthenticatedScene.unity

Large diffs are not rendered by default.

34 changes: 34 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,33 @@ public void CancelZkGetBalance()
ZkGetBalanceCanvas.gameObject.SetActive(false);
}

public async void GetZkTransactionReceiptStatus()
{
try
{
ShowOutput($"Getting zkEVM transaction receipt...");
TransactionReceiptResponse response = await passport.ZkEvmGetTransactionReceipt(ZkGetTransactionReceiptHash.text);
ShowOutput($"Transaction receipt status: {response.status}");
}
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,54 @@
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;

public string status;

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
11 changes: 11 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,17 @@ public async UniTask<string> ZkEvmSendTransaction(TransactionRequest request)
return await GetPassportImpl().ZkEvmSendTransaction(request);
}

/// <summary>
/// Returns a sent/submitted transaction status information
/// <returns>
/// The receipt of transaction, or null if the transaction is still in process
/// </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

0 comments on commit 6fc7fe2

Please sign in to comment.