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

feat: update typed data to be snip 12 enum compliant #46

Merged
merged 1 commit into from
Jun 11, 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
18 changes: 11 additions & 7 deletions Assets/Dojo/Runtime/Starknet/TypedData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ public struct TypedDataType
{
public string name;
public string type;
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string contains;

public TypedDataType(string name, string type)
public TypedDataType(string name, string type, string contains = null)
{
this.name = name;
this.type = type;
this.contains = contains;
}
}

Expand Down Expand Up @@ -105,8 +108,7 @@ object mapMember(Model.Ty member)
{
Model.Enum enum_ => new Dictionary<string, object>
{
{ "option", enum_.option },
{ "value", mapMember(enum_.value) }
{ enum_.option, mapMember(enum_.value) }
},
Dictionary<string, Model.Ty> struct_ => struct_.Select(child => new KeyValuePair<string, object>(child.Key, mapMember(child.Value))).ToDictionary(k => k.Key, v => v.Value),
Model.Ty[] tuple => tuple.Select(mapMember).ToArray(),
Expand Down Expand Up @@ -141,12 +143,14 @@ TypedDataType[] getMembersTypes(ref Dictionary<string, TypedDataType[]> types, D
case Model.Enum enum_:
var enumMembers = getMembersTypes(ref types, new Dictionary<string, Model.Ty>
{
// enum option is a bytearray / string
{ "option", new Model.Ty(dojo.Ty_Tag.ByteArray, "string", enum_.option, false) },
{ "value", enum_.value }
// for now we only include our selected option
// and its value
{ enum_.option, enum_.value },
// TOOD: maybe include all other enum options
// and their types?
});
types.TryAdd(member.Value.name, enumMembers);
result.Add(new TypedDataType(member.Key, member.Value.name));
result.Add(new TypedDataType(member.Key, "enum", member.Value.name));
break;
case Dictionary<string, Model.Ty> struct_:
var structMembers = getMembersTypes(ref types, struct_);
Expand Down
1 change: 1 addition & 0 deletions Assets/Spawn And Move/Models/PlayerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class PlayerConfig : ModelInstance
// Start is called before the first frame update
void Start()
{
Debug.Log(JsonConvert.SerializeObject(new TypedData(Model)));
}

// Update is called once per frame
Expand Down