-
Notifications
You must be signed in to change notification settings - Fork 8
Initial Commit #296
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
base: master
Are you sure you want to change the base?
Initial Commit #296
Changes from 3 commits
1c74893
5efa550
ba3d3ee
9f4ae8a
af3bd0a
d6c513c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)] | ||
|
||
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"; | ||
|
||
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); | ||
} | ||
|
||
|
||
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; | ||
} | ||
} | ||
} |
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,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} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
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.
There was a problem hiding this comment.
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 😉