Skip to content
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
4 changes: 2 additions & 2 deletions Assets/Dojo/Plugins/Linux/libdojo_c.so
Git LFS file not shown
4 changes: 2 additions & 2 deletions Assets/Dojo/Plugins/Windows/libdojo_c.dll
Git LFS file not shown
4 changes: 2 additions & 2 deletions Assets/Dojo/Plugins/iOS/libdojo_c.a
Git LFS file not shown
4 changes: 2 additions & 2 deletions Assets/Dojo/Plugins/macOS/libdojo_c.bundle
Git LFS file not shown
2 changes: 1 addition & 1 deletion Assets/Dojo/Runtime/Bindings/AssemblyAttributes.gen.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// To disable generating this file set `isEnabledGenerateAssemblyAttributes` to `false` in the config file for generating C# code.
// <auto-generated>
// This code was generated by the following tool on 2025-08-26 10:41:56 GMT+01:00:
// This code was generated by the following tool on 2025-09-05 15:56:58 GMT+01:00:
// https://github.com/bottlenoselabs/c2cs (v0.0.0.0)
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
Expand Down
2 changes: 1 addition & 1 deletion Assets/Dojo/Runtime/Bindings/Runtime.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// To disable generating this file set `isEnabledGeneratingRuntimeCode` to `false` in the config file for generating C# code.

// <auto-generated>
// This code was generated by the following tool on 2025-08-26 10:41:56 GMT+01:00:
// This code was generated by the following tool on 2025-09-05 15:56:58 GMT+01:00:
// https://github.com/bottlenoselabs/c2cs (v0.0.0.0)
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
Expand Down
41 changes: 29 additions & 12 deletions Assets/Dojo/Runtime/Bindings/dojo.gen.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// <auto-generated>
// This code was generated by the following tool on 2025-08-26 10:41:56 GMT+01:00:
// This code was generated by the following tool on 2025-09-05 15:56:58 GMT+01:00:
// https://github.com/bottlenoselabs/c2cs (v0.0.0.0)
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
Expand Down Expand Up @@ -103,11 +103,11 @@ public static unsafe partial class dojo

[CNode(Kind = "Function")]
[DllImport(LibraryName, EntryPoint = "client_on_entity_state_update", CallingConvention = CallingConvention.Cdecl)]
public static extern ResultSubscription client_on_entity_state_update(ToriiClient* client, COptionClause clause, FnPtr_FieldElement_CArrayStruct_Void callback);
public static extern ResultSubscription client_on_entity_state_update(ToriiClient* client, COptionClause clause, FnPtr_Entity_Void callback);

[CNode(Kind = "Function")]
[DllImport(LibraryName, EntryPoint = "client_on_event_message_update", CallingConvention = CallingConvention.Cdecl)]
public static extern ResultSubscription client_on_event_message_update(ToriiClient* client, COptionClause clause, FnPtr_FieldElement_CArrayStruct_Void callback);
public static extern ResultSubscription client_on_event_message_update(ToriiClient* client, COptionClause clause, FnPtr_Entity_Void callback);

[CNode(Kind = "Function")]
[DllImport(LibraryName, EntryPoint = "client_on_starknet_event", CallingConvention = CallingConvention.Cdecl)]
Expand Down Expand Up @@ -329,29 +329,29 @@ public FnPtr_ControllerAccountPtr_Void(@delegate d)

[CNode(Kind = "FunctionPointer")]
[StructLayout(LayoutKind.Sequential)]
public struct FnPtr_Event_Void
public struct FnPtr_Entity_Void
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void @delegate(Event param);
public unsafe delegate void @delegate(Entity param);

public IntPtr Pointer;

public FnPtr_Event_Void(@delegate d)
public FnPtr_Entity_Void(@delegate d)
{
Pointer = Marshal.GetFunctionPointerForDelegate(d);
}
}

[CNode(Kind = "FunctionPointer")]
[StructLayout(LayoutKind.Sequential)]
public struct FnPtr_FieldElement_CArrayStruct_Void
public struct FnPtr_Event_Void
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void @delegate(FieldElement param, CArrayStruct param2);
public unsafe delegate void @delegate(Event param);

public IntPtr Pointer;

public FnPtr_FieldElement_CArrayStruct_Void(@delegate d)
public FnPtr_Event_Void(@delegate d)
{
Pointer = Marshal.GetFunctionPointerForDelegate(d);
}
Expand Down Expand Up @@ -1218,7 +1218,7 @@ public Span<string> usernames
}

[CNode(Kind = "Struct")]
[StructLayout(LayoutKind.Explicit, Size = 48, Pack = 8)]
[StructLayout(LayoutKind.Explicit, Size = 72, Pack = 8)]
public struct Entity
{
[FieldOffset(0)] // size = 32
Expand Down Expand Up @@ -1250,6 +1250,14 @@ public Span<Struct> models
}
}

[FieldOffset(48)] // size = 8
public ulong created_at;

[FieldOffset(56)] // size = 8
public ulong updated_at;

[FieldOffset(64)] // size = 8
public ulong executed_at;
}

[CNode(Kind = "Struct")]
Expand Down Expand Up @@ -3618,7 +3626,7 @@ public Span<Member> children
}

[CNode(Kind = "Struct")]
[StructLayout(LayoutKind.Explicit, Size = 104, Pack = 8)]
[StructLayout(LayoutKind.Explicit, Size = 144, Pack = 8)]
public struct Token
{
[FieldOffset(0)] // size = 32
Expand Down Expand Up @@ -3674,6 +3682,9 @@ public string metadata
metadata_ = CString.FromString(value);
}
}

[FieldOffset(104)] // size = 36
public COptionU256 total_supply;
}

[CNode(Kind = "Struct")]
Expand Down Expand Up @@ -4691,7 +4702,13 @@ public enum ComparisonOperator : int
Lt = 4,
Lte = 5,
In = 6,
NotIn = 7
NotIn = 7,
Contains = 8,
ContainsAll = 9,
ContainsAny = 10,
ArrayLengthEq = 11,
ArrayLengthGt = 12,
ArrayLengthLt = 13
}

[CNode(Kind = "Enum")]
Expand Down
15 changes: 7 additions & 8 deletions Assets/Dojo/Runtime/Config/WorldManagerLocalConfig.asset
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ MonoBehaviour:
m_Name: WorldManagerLocalConfig
m_EditorClassIdentifier:
toriiUrl: http://localhost:8080
relayUrl: /ip4/127.0.0.1/tcp/9090
relayWebrtcUrl: /ip4/127.0.0.1/udp/9091/webrtc-direct/certhash/uEiAS9CpA5yNwO7iidBM5f9FcPl67PwohiK-1J9BhnFMrHg
worldAddress:
hex: 0x05cb84ccfa869ea8cf9acb0c77b2d1a67a7e9e8fd4a877a1c111e3c2b1eb0f03
query:
limit: 100
offset: 0
dont_include_hashed_keys: 0
order_by: []
entity_models: []
entity_updated_after: 0
pagination:
cursor:
order_by: []
direction: 0
no_hashed_keys: 0
models: []
historical: 0
2 changes: 1 addition & 1 deletion Assets/Dojo/Runtime/Starknet/StarknetInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static object Serialize(dojo.BlockId blockId)
BlockTag = blockId.block_tag switch
{
dojo.BlockTag.Latest => "Latest",
dojo.BlockTag.Pending => "Pending",
dojo.BlockTag.PreConfirmed => "PreConfirmed",
_ => throw new Exception("Unknown block tag")
}
},
Expand Down
19 changes: 9 additions & 10 deletions Assets/Dojo/Runtime/SynchronizationMaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Dojo.Starknet;
using Dojo.Torii;
using dojo_bindings;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Events;

Expand Down Expand Up @@ -87,19 +86,19 @@ private GameObject SpawnEntity(FieldElement hashedKeys, Model[] entityModels)
}

// Handles spawning / updating entities as they are updated from the dojo world
private void HandleEntityUpdate(FieldElement hashedKeys, Model[] entityModels)
private void HandleEntityUpdate(Entity entity)
{
// Get the entity game object
var entity = GameObject.Find(hashedKeys.Hex());
if (entity == null)
var entityGameObject = GameObject.Find(entity.HashedKeys.Hex());
if (entityGameObject == null)
{
entity = SpawnEntity(hashedKeys, entityModels);
entityGameObject = SpawnEntity(entity.HashedKeys, entity.Models.Values.ToArray());
// We don't need to update the entity models
return;
}

// Update each one of the entity models
foreach (var entityModel in entityModels)
foreach (var entityModel in entity.Models.Values)
{
string[] parts = entityModel.Name.Split('-');
string @namespace = parts[0];
Expand All @@ -111,12 +110,12 @@ private void HandleEntityUpdate(FieldElement hashedKeys, Model[] entityModels)
continue;
}

var component = entity.GetComponent(model.GetType());
var component = entityGameObject.GetComponent(model.GetType());
if (component == null)
{
// we dont need to initialize the component
// because it'll get updated
component = (ModelInstance)entity.AddComponent(model.GetType());
component = (ModelInstance)entityGameObject.AddComponent(model.GetType());
}

// update component with new model data
Expand All @@ -125,9 +124,9 @@ private void HandleEntityUpdate(FieldElement hashedKeys, Model[] entityModels)
}
}

private void HandleEventMessage(FieldElement hashedKeys, Model[] entityModels)
private void HandleEventMessage(Entity entity)
{
foreach (var entityModel in entityModels)
foreach (var entityModel in entity.Models.Values)
{
string[] parts = entityModel.Name.Split('-');
string @namespace = parts[0];
Expand Down
35 changes: 33 additions & 2 deletions Assets/Dojo/Runtime/Torii/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,48 @@ public class Entity
{
public Dictionary<string, Model> Models { get; }
public FieldElement HashedKeys { get; }
public Entity(FieldElement hashedKeys, Dictionary<string, Model> models)
public DateTime CreatedAt { get; }
public DateTime UpdatedAt { get; }
public DateTime ExecutedAt { get; }
public Entity(FieldElement hashedKeys, Dictionary<string, Model> models, DateTime createdAt, DateTime updatedAt, DateTime executedAt)
{
HashedKeys = hashedKeys;
Models = models;
CreatedAt = createdAt;
UpdatedAt = updatedAt;
ExecutedAt = executedAt;
}

#if UNITY_WEBGL && !UNITY_EDITOR
public Entity(WasmEntity entity)
{
HashedKeys = new FieldElement(entity.hashed_keys);

var models = new Dictionary<string, Model>();
foreach (var model in entity.models)
{
models.Add(model.Key, new Model(
model.Key,
model.Value.ToDictionary(
m => m.Key,
m => m.Value
)
));
}
Models = models;
CreatedAt = DateTimeOffset.FromUnixTimeSeconds(entity.created_at).DateTime;
UpdatedAt = DateTimeOffset.FromUnixTimeSeconds(entity.updated_at).DateTime;
ExecutedAt = DateTimeOffset.FromUnixTimeSeconds(entity.executed_at).DateTime;
}
#endif

public Entity(dojo.Entity entity)
{
HashedKeys = new FieldElement(entity.hashed_keys);
Models = new Dictionary<string, Model>(entity.models.ToArray().Select(m => new KeyValuePair<string, Model>(m.name, new Model(m))));

CreatedAt = DateTimeOffset.FromUnixTimeSeconds((long)entity.created_at).DateTime;
UpdatedAt = DateTimeOffset.FromUnixTimeSeconds((long)entity.updated_at).DateTime;
ExecutedAt = DateTimeOffset.FromUnixTimeSeconds((long)entity.executed_at).DateTime;
}

// freeing the entity is naive. if we copy the entity we will double free
Expand Down
49 changes: 48 additions & 1 deletion Assets/Dojo/Runtime/Torii/Token.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System.Numerics;
using Dojo.Starknet;
using dojo_bindings;
using Newtonsoft.Json;

namespace Dojo.Torii
{
Expand All @@ -12,15 +14,41 @@ public struct Token
public string symbol;
public int decimals;
public Dictionary<string, object> metadata;
public BigInteger? totalSupply;

public Token(FieldElement contractAddress, BigInteger? tokenId, string name, string symbol, int decimals, Dictionary<string, object> metadata)
public Token(FieldElement contractAddress, BigInteger? tokenId, string name, string symbol, int decimals, Dictionary<string, object> metadata, BigInteger? totalSupply)
{
this.contractAddress = contractAddress;
this.tokenId = tokenId;
this.name = name;
this.symbol = symbol;
this.decimals = decimals;
this.metadata = metadata;
this.totalSupply = totalSupply;
}

#if UNITY_WEBGL && !UNITY_EDITOR
public Token(WasmToken token)
{
this.contractAddress = new FieldElement(token.contract_address);
this.tokenId = token.token_id != null ? BigInteger.Parse(token.token_id.Substring(2), System.Globalization.NumberStyles.HexNumber) : null;
this.name = token.name;
this.symbol = token.symbol;
this.decimals = token.decimals;
this.metadata = JsonConvert.DeserializeObject<Dictionary<string, object>>(token.metadata);
this.totalSupply = token.total_supply != null ? BigInteger.Parse(token.total_supply.Substring(2), System.Globalization.NumberStyles.HexNumber) : null;
}
#endif

public Token(dojo.Token token)
{
this.contractAddress = new FieldElement(token.contract_address);
this.tokenId = token.token_id.tag == dojo.COptionU256_Tag.SomeU256 ? new BigInteger(token.token_id.some.data, false, true) : null;
this.name = token.name;
this.symbol = token.symbol;
this.decimals = token.decimals;
this.metadata = JsonConvert.DeserializeObject<Dictionary<string, object>>(token.metadata);
this.totalSupply = token.total_supply.tag == dojo.COptionU256_Tag.SomeU256 ? new BigInteger(token.total_supply.some.data, false, true) : null;
}
}

Expand All @@ -38,5 +66,24 @@ public TokenBalance(BigInteger balance, FieldElement accountAddress, FieldElemen
this.contractAddress = contractAddress;
this.tokenId = tokenId;
}

#if UNITY_WEBGL && !UNITY_EDITOR
public TokenBalance(WasmTokenBalance tokenBalance)
{
this.balance = BigInteger.Parse(tokenBalance.balance.Substring(2), System.Globalization.NumberStyles.HexNumber);
this.accountAddress = new FieldElement(tokenBalance.account_address);
this.contractAddress = new FieldElement(tokenBalance.contract_address);
this.tokenId = tokenBalance.token_id != null ? BigInteger.Parse(tokenBalance.token_id.Substring(2), System.Globalization.NumberStyles.HexNumber) : null;
}
#endif


public TokenBalance(dojo.TokenBalance tokenBalance)
{
this.balance = new BigInteger(tokenBalance.balance.data, false, true);
this.accountAddress = new FieldElement(tokenBalance.account_address);
this.contractAddress = new FieldElement(tokenBalance.contract_address);
this.tokenId = tokenBalance.token_id.tag == dojo.COptionU256_Tag.SomeU256 ? new BigInteger(tokenBalance.token_id.some.data, false, true) : null;
}
}
}
Loading
Loading