Skip to content

Commit

Permalink
Update rpc generator
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfranblanco committed Jul 15, 2022
1 parent 5c159ae commit 6c71ce7
Show file tree
Hide file tree
Showing 11 changed files with 978 additions and 362 deletions.

Large diffs are not rendered by default.

Expand Up @@ -24,6 +24,7 @@ declare module Nethereum {
GenerateAllMessages(): Core.GeneratedFile;
GenerateAll(): Core.GeneratedFile[];
GenerateService(singleMessagesFile?: boolean): Core.GeneratedFile;
GenerateUnityFunctionRequests(singleMessagesFile?: boolean): Core.GeneratedFile;
GenerateAllCQSMessages(): System.Collections.Generic.List$1<Core.GeneratedFile>;
GenerateAllFunctionDTOs(): System.Collections.Generic.List$1<Core.GeneratedFile>;
GenerateAllStructs(): System.Collections.Generic.List$1<Core.GeneratedFile>;
Expand Down Expand Up @@ -1460,6 +1461,48 @@ declare module Nethereum {
}
const StructTypeVbTemplate: StructTypeVbTemplateTypeFunc;
}
module Unity {
// Nethereum.Generators.Unity.UnityRequestsGenerator
export interface UnityRequestsGenerator extends Core.ClassGeneratorBase$2<CQS.ClassTemplateBase$1<UnityRequestsModel>, UnityRequestsModel>, Core.IFileGenerator, Core.IGenerator, Core.IClassGenerator {
get_ContractABI(): Model.ContractABI;
InitialiseTemplate(codeGenLanguage: Core.CodeGenLanguage): void;
}
export interface UnityRequestsGeneratorTypeFunc extends TypeFunction {
(): UnityRequestsGeneratorTypeFunc;
prototype: UnityRequestsGenerator;
new (contractABI: Model.ContractABI, contractName: string, byteCode: string, namespace: string, cqsNamespace: string, functionOutputNamespace: string, codeGenLanguage: Core.CodeGenLanguage): UnityRequestsGenerator;
ctor: { new (contractABI: Model.ContractABI, contractName: string, byteCode: string, namespace: string, cqsNamespace: string, functionOutputNamespace: string, codeGenLanguage: Core.CodeGenLanguage): UnityRequestsGenerator; };
}
const UnityRequestsGenerator: UnityRequestsGeneratorTypeFunc;

// Nethereum.Generators.Unity.UnityRequestsModel
export interface UnityRequestsModel extends Core.TypeMessageModel, Core.IClassModel, Core.IFileModel {
get_ContractABI(): Model.ContractABI;
get_CQSNamespace(): string;
get_FunctionOutputNamespace(): string;
get_ContractDeploymentCQSMessageModel(): CQS.ContractDeploymentCQSMessageModel;
}
export interface UnityRequestsModelTypeFunc extends TypeFunction {
(): UnityRequestsModelTypeFunc;
prototype: UnityRequestsModel;
new (contractABI: Model.ContractABI, contractName: string, byteCode: string, namespace: string, cqsNamespace: string, functionOutputNamespace: string): UnityRequestsModel;
ctor: { new (contractABI: Model.ContractABI, contractName: string, byteCode: string, namespace: string, cqsNamespace: string, functionOutputNamespace: string): UnityRequestsModel; };
}
const UnityRequestsModel: UnityRequestsModelTypeFunc;
module CSharp {
// Nethereum.Generators.Unity.CSharp.UnityFunctionRequestsClassTemplates
export interface UnityFunctionRequestsClassTemplates extends CQS.ClassTemplateBase$1<UnityRequestsModel>, Core.IClassTemplate {
GenerateSingleClass(functionABI: Model.FunctionABI): string;
}
export interface UnityFunctionRequestsClassTemplatesTypeFunc extends TypeFunction {
(): UnityFunctionRequestsClassTemplatesTypeFunc;
prototype: UnityFunctionRequestsClassTemplates;
new (model: UnityRequestsModel): UnityFunctionRequestsClassTemplates;
ctor: { new (model: UnityRequestsModel): UnityFunctionRequestsClassTemplates; };
}
const UnityFunctionRequestsClassTemplates: UnityFunctionRequestsClassTemplatesTypeFunc;
}
}
module XUnit {
// Nethereum.Generators.XUnit.SimpleTestGenerator
export interface SimpleTestGenerator extends Core.ClassGeneratorBase$2<CQS.ClassTemplateBase$1<SimpleTestModel>, SimpleTestModel>, Core.IFileGenerator, Core.IGenerator, Core.IClassGenerator {
Expand Down
Binary file not shown.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions generators/Nethereum.Generators/ContractProjectGenerator.cs
Expand Up @@ -3,6 +3,7 @@
using Nethereum.Generators.DTOs;
using Nethereum.Generators.Model;
using Nethereum.Generators.Service;
using Nethereum.Generators.Unity;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -106,6 +107,20 @@ public GeneratedFile GenerateService(bool singleMessagesFile = false)
return serviceGenerator.GenerateFileContent(serviceFullPath);
}

public GeneratedFile GenerateUnityFunctionRequests(bool singleMessagesFile = false)
{
var dtoFullNamespace = GetFullNamespace(DTONamespace);
var cqsFullNamespace = GetFullNamespace(CQSNamespace);

dtoFullNamespace = singleMessagesFile ? string.Empty : FullyQualifyNamespaceFromImport(dtoFullNamespace);
cqsFullNamespace = FullyQualifyNamespaceFromImport(cqsFullNamespace);

var serviceFullNamespace = GetFullNamespace(ServiceNamespace);
var serviceFullPath = GetFullPath(ServiceNamespace);
var unityRequestsGenerator = new UnityRequestsGenerator(ContractABI, ContractName, ByteCode, serviceFullNamespace, cqsFullNamespace, dtoFullNamespace, CodeGenLanguage);
return unityRequestsGenerator.GenerateFileContent(serviceFullPath);
}

public List<GeneratedFile> GenerateAllCQSMessages()
{
var generated = new List<GeneratedFile>();
Expand Down
34 changes: 34 additions & 0 deletions generators/Nethereum.Generators/Unity/UnityRequestsGenerator.cs
@@ -0,0 +1,34 @@
using System;
using Nethereum.Generators.Core;
using Nethereum.Generators.CQS;
using Nethereum.Generators.Model;
using Nethereum.Generators.Unity.CSharp;

namespace Nethereum.Generators.Unity
{
public class UnityRequestsGenerator : ClassGeneratorBase<ClassTemplateBase<UnityRequestsModel>, UnityRequestsModel>
{
public ContractABI ContractABI { get; }

public UnityRequestsGenerator(ContractABI contractABI, string contractName, string byteCode, string @namespace, string cqsNamespace, string functionOutputNamespace, CodeGenLanguage codeGenLanguage)
{
ContractABI = contractABI;
ClassModel = new UnityRequestsModel(contractABI, contractName, byteCode, @namespace, cqsNamespace, functionOutputNamespace);
ClassModel.CodeGenLanguage = codeGenLanguage;
InitialiseTemplate(codeGenLanguage);
}

public void InitialiseTemplate(CodeGenLanguage codeGenLanguage)
{
switch (codeGenLanguage)
{
case CodeGenLanguage.CSharp:
ClassTemplate = new UnityFunctionRequestsClassTemplates(ClassModel);
break;
default:
throw new ArgumentOutOfRangeException(nameof(codeGenLanguage), codeGenLanguage, "Code generation not implemented for this language");
}

}
}
}

0 comments on commit 6c71ce7

Please sign in to comment.