Skip to content

Commit

Permalink
Next ver 068 (#84)
Browse files Browse the repository at this point in the history
* updated to 0.6.7 added new rust enum version
updated net api to 24-rc5

* updated comments

* next version
  • Loading branch information
darkfriend77 authored Sep 14, 2024
1 parent 2ea72da commit 8cc1ecb
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Using a terminal of your choice, create a new directory for your project and exe
```sh
dotnet new sln
dotnet new substrate \
--sdk_version 0.6.7 \
--sdk_version 0.6.8 \
--rest_service PROJECTNAME.RestService \
--net_api PROJECTNAME.NetApiExt \
--net_integration PROJECTNAME.Integration \
Expand Down Expand Up @@ -127,7 +127,7 @@ You can also watch our short step-by-step tutorial that guides you through the e
- AstarNET
```sh
dotnet new substrate \
--sdk_version 0.6.7 \
--sdk_version 0.6.8 \
--rest_service AstarNET.RestService \
--net_api AstarNET.NetApiExt \
--net_api AstarNET.Integration \
Expand Down
2 changes: 1 addition & 1 deletion Substrate.ServiceLayer/Substrate.ServiceLayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Substrate.NET.API" Version="0.9.24-rc5" />
<PackageReference Include="Substrate.NET.API" Version="0.9.24-rc6" />
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"symbols": {
"sdk_version": {
"datatype": "string",
"defaultValue": "0.6.7",
"defaultValue": "0.6.8",
"description": "Uses the given Substrate .NET Toolchain version.",
"replaces": "SUBSTRATE_TOOLCHAIN_VERSION",
"type": "parameter"
},
"api_version": {
"datatype": "string",
"defaultValue": "0.9.24-rc5",
"defaultValue": "0.9.24-rc6",
"description": "Uses the given Substrate .NET API version.",
"replaces": "SUBSTRATE_NETAPI_VERSION",
"type": "parameter"
Expand Down
31 changes: 21 additions & 10 deletions Tools/Substrate.DotNet/Service/Node/EnumBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ public override TypeBuilderBase Create()

ClassName = $"Enum{enumName}";
ReferenzName = $"{NamespaceName}.{ClassName}";
CodeNamespace typeNamespace = new(NamespaceName);
var typeNamespace = new CodeNamespace(NamespaceName);
TargetUnit.Namespaces.Add(typeNamespace);

// Create the enum itself
CodeTypeDeclaration enumType = new(enumName)
var enumType = new CodeTypeDeclaration(enumName)
{
IsEnum = true
};
enumType.Comments.AddRange(GetComments(typeDef.Docs, null, enumName));

// Detect if this enum has associated types
bool hasAssociatedTypes = false;

if (typeDef.Variants != null)
{
foreach (TypeVariant variant in typeDef.Variants)
Expand All @@ -51,26 +54,31 @@ public override TypeBuilderBase Create()
};
enumMember.Comments.AddRange(GetComments(variant.Docs, null, variant.Name));
enumType.Members.Add(enumMember);

// Check if this variant has associated types
if (variant.TypeFields != null && variant.TypeFields.Length > 0)
{
hasAssociatedTypes = true;
}
}
}
typeNamespace.Types.Add(enumType);

// Generate the class based on BaseEnumRust
// Generate the appropriate class based on whether there are associated types
var targetClass = new CodeTypeDeclaration(ClassName)
{
IsClass = true,
TypeAttributes = TypeAttributes.Public | TypeAttributes.Sealed
};
targetClass.Comments.AddRange(GetComments(typeDef.Docs, typeDef));

if (typeDef.Variants != null)
if (hasAssociatedTypes)
{
// Constructor to register decoders
// Generate the class based on BaseEnumRust (with associated types)
var codeConstructor = new CodeConstructor
{
Attributes = MemberAttributes.Public
};

codeConstructor.Comments.AddRange(GetComments(new string[] { "Initializes a new instance of the class." }, null));

foreach (TypeVariant variant in typeDef.Variants)
Expand All @@ -96,15 +104,18 @@ public override TypeBuilderBase Create()
);
}

targetClass.BaseTypes.Add(new CodeTypeReference($"BaseEnumRust<{enumName}>"));
targetClass.Members.Add(codeConstructor);
}
else
{
// Generate the class based on BaseEnum (without associated types)
targetClass.BaseTypes.Add(new CodeTypeReference($"BaseEnum<{enumName}>"));
}

targetClass.BaseTypes.Add(new CodeTypeReference($"BaseEnumRust<{enumName}>"));
typeNamespace.Types.Add(targetClass);

return this;
}


}
}
}
2 changes: 1 addition & 1 deletion Tools/Substrate.DotNet/Substrate.DotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

<ItemGroup>
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Substrate.NET.API" Version="0.9.24-rc5" />
<PackageReference Include="Substrate.NET.API" Version="0.9.24-rc6" />
<PackageReference Include="System.CodeDom" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Version.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<!-- Configuration -->
<VersionMajor>0</VersionMajor>
<VersionMinor>6</VersionMinor>
<VersionPatch>7</VersionPatch>
<VersionPatch>8</VersionPatch>
<AssemblyVersion>$(VersionMajor).$(VersionMinor).$(VersionPatch)</AssemblyVersion>

<SubstratePackageVersion>0.6.7</SubstratePackageVersion>
<SubstratePackageVersion>0.6.8</SubstratePackageVersion>

<!-- Variables -->
<SubstrateVersion>$(AssemblyVersion)</SubstrateVersion>
Expand Down

0 comments on commit 8cc1ecb

Please sign in to comment.