Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
36 changes: 36 additions & 0 deletions Assets/DeployedContractAddressExtractor.cs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably live somewhere else 😉

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace Sequence
{
public static class ReceiptExtractor
{
public static string ExtractFirstContractAddressExceptOwn(TransactionReceipt receipt, string ownContractAddress)
{
ownContractAddress = ownContractAddress?.ToLower();

if (!string.IsNullOrEmpty(receipt.contractAddress))
{
var contractAddrLower = receipt.contractAddress.ToLower();
if (contractAddrLower != ownContractAddress)
{
return contractAddrLower;
}
}

if (receipt.logs != null)
{
foreach (var log in receipt.logs)
{
if (!string.IsNullOrEmpty(log.address))
{
var addrLower = log.address.ToLower();
if (addrLower != ownContractAddress)
{
return addrLower;
}
}
}
}

return null;
}
}
}
11 changes: 11 additions & 0 deletions Assets/DeployedContractAddressExtractor.cs.meta

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

181 changes: 181 additions & 0 deletions Assets/Editor/SidekickDockerUtility.cs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to ship this to users, it should go somewhere in the Packages folder

Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
using UnityEditor;
using UnityEngine;
using System.Diagnostics;
using System.IO;
using System.Linq;

public static class SidekickDockerUtility
{
private static SidekickConfig config;

private static string SidekickPath
{
get
{
if (config == null)
{
config = Resources.Load<SidekickConfig>("SidekickConfig");
if (config == null)
{
UnityEngine.Debug.LogError("Could not load SidekickConfig from Resources.");
return string.Empty;
}
}
return config.path;
}
}

[MenuItem("Sequence Dev/Start Sidekick", false, 0)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if maybe "Sequence/" is a better menu item path for these - this way we can leave "Sequence Dev" for us. What do you think?

private static void StartSidekick()
{
if (IsSidekickRunning()) return;

EnsureDockerDesktopRunning();

RunCommand("pnpm docker:restart", SidekickPath);
}

[MenuItem("Sequence Dev/Start Sidekick", true)]
private static bool ValidateStart() => !IsSidekickRunning();

[MenuItem("Sequence Dev/Stop Sidekick", false, 1)]
private static void StopSidekick()
{
if (!IsSidekickRunning()) return;

RunCommand("pnpm docker:stop", SidekickPath);
}

[MenuItem("Sequence Dev/Stop Sidekick", true)]
private static bool ValidateStop() => IsSidekickRunning();

private static void RunCommand(string command, string workingDirectory)
{
if (string.IsNullOrEmpty(workingDirectory) || !Directory.Exists(workingDirectory))
{
UnityEngine.Debug.LogError($"Sidekick path not set or invalid: {workingDirectory}");
return;
}

ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/c {command}",
WorkingDirectory = workingDirectory,
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};

Process process = new Process { StartInfo = psi };

process.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
UnityEngine.Debug.Log($"[Docker] {e.Data}");
};

process.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
UnityEngine.Debug.LogWarning($"[Docker] {e.Data}");
};

process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
}

private static void EnsureDockerDesktopRunning()
{
const int maxWaitTimeSeconds = 120;
const int pollIntervalMs = 2000;

if (!Process.GetProcessesByName("Docker Desktop").Any())
{
string dockerDesktopPath = @"C:\Program Files\Docker\Docker\Docker Desktop.exe";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worthwhile adding this to the config object?

if (File.Exists(dockerDesktopPath))
{
Process.Start(dockerDesktopPath);
}
else
{
UnityEngine.Debug.LogWarning("[Docker] Docker Desktop not found at default path.");
return;
}
}

var stopwatch = new Stopwatch();
stopwatch.Start();

while (stopwatch.Elapsed.TotalSeconds < maxWaitTimeSeconds)
{
if (IsDockerDaemonReady())
{
return;
}

System.Threading.Thread.Sleep(pollIntervalMs);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to freeze the editor and make it unresponsive until either Docker is open or the check times out? Maybe we can move this whole operation into a background thread?


UnityEngine.Debug.LogError("[Docker] Timed out waiting for Docker to become ready.");
}

private static bool IsDockerDaemonReady()
{
try
{
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = "/c docker info",
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
UseShellExecute = false
};

using (Process process = Process.Start(psi))
{
process.WaitForExit(3000);

string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();

return process.ExitCode == 0 && output.Contains("Server Version");
}
}
catch
{
return false;
}
}

private static bool IsSidekickRunning()
{
try
{
var psi = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = "/c docker ps --format \"{{.Names}}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};

using (var process = Process.Start(psi))
{
process.WaitForExit();
var output = process.StandardOutput.ReadToEnd();

return output.Contains("sidekick");
}
}
catch
{
return false;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Editor/SidekickDockerUtility.cs.meta

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

17 changes: 17 additions & 0 deletions Assets/NewToken.asset
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed?

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f43439d1f99de164fb5b87ee45ff3e5c, type: 3}
m_Name: NewToken
m_EditorClassIdentifier:
contractAddress: 0x5f6e8810da77cb4762bfa5bdd2f6993bc9cd72a1
specifyBurnAddress: 0
linkedGameObject: {fileID: 0}
8 changes: 8 additions & 0 deletions Assets/NewToken.asset.meta

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

8 changes: 8 additions & 0 deletions Assets/SequenceSDK/Marketplace/SideKick.meta
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can probably make this its own directory instead of nesting it inside of Marketplace

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

8 changes: 8 additions & 0 deletions Assets/SequenceSDK/Marketplace/SideKick/Tests.meta

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,39 @@
using System;
using System.Threading.Tasks;
using NUnit.Framework;
using UnityEngine;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Sequence.Sidekick
{
public class SequenceSidekickTests
{
SequenceSidekickClient sidekick;
string chainId;

[SetUp]
public void Setup()
{
sidekick = new SequenceSidekickClient(Chain.TestnetArbitrumSepolia);
chainId = sidekick.Chain.GetChainId();

}

[Test]
public async Task TestGetWalletAddress()
{
try
{
var sidekick = new SequenceSidekickClient();
string walletAddress = await sidekick.GetWalletAddress();
Assert.IsNotNull(walletAddress);
}
catch (Exception e)
{
Assert.Fail("Expected no exception, but got: " + e.Message);
}
}

}
}

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

Loading
Loading