Skip to content

Commit

Permalink
finalise client app generator
Browse files Browse the repository at this point in the history
  • Loading branch information
umutonat committed Jun 24, 2020
1 parent 05315e8 commit 82473bc
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 59 deletions.
6 changes: 0 additions & 6 deletions SCTransformation.API/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;

namespace SCTransformation.API
Expand Down
26 changes: 22 additions & 4 deletions SCTransformation/ClientApplicationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ public static void Main(string[] args)
"Solidity");
BuildJavaApplication(scds.First(), "com.danyue", "call");
}



private static string BuildJavaApplication(SmartContractDescriptor smartContractDescriptor,
string packageName, string callbackUrl)
{
Expand Down Expand Up @@ -125,10 +123,25 @@ private static string BuildJavaApplication(SmartContractDescriptor smartContract
{
var template = CreateFreshTemplate(stream, smartContractDescriptor, packageName,
callbackUrl);
template.Add("eventArray", new[] {scEvent.Name});
var privateEvent= new Event
{
Name = scEvent.Name,
FirstCapital = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo
.ToTitleCase(
scEvent.Name.ToLower())
};
template.Add("eventArray", new[] {privateEvent});
foreach (var parameter in scEvent.Outputs)
{
template.Add("eventoutputparameterarray", new[] {parameter});
var privateParameter = new Parameter
{
FirstCapital = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo
.ToTitleCase(
parameter.Name.ToLower()),
Name = parameter.Name,
ParamType = parameter.Type
};
template.Add("eventoutputparameterarray", new[] {privateParameter});
}

controllerEvents += template.Render();
Expand Down Expand Up @@ -254,5 +267,10 @@ private class Function
public string Name;
public string FirstCapital;
}
private class Event
{
public string Name;
public string FirstCapital;
}
}
}
5 changes: 3 additions & 2 deletions SCTransformation/SCTransformation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>Exe</OutputType>
<StartupObject>SCTransformation.ClientApplicationGenerator</StartupObject>
<RuntimeIdentifiers>win10-x64;linux-x64;osx-x64</RuntimeIdentifiers>
<!--<OutputType>Exe</OutputType>
<StartupObject>SCTransformation.ClientApplicationGenerator</StartupObject>-->
</PropertyGroup>
<ItemGroup>
<Folder Include="Grammars\Solidity" />
Expand Down
2 changes: 1 addition & 1 deletion SCTransformation/SmartContractDescriptorGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private static IEnumerable<SmartContractDescriptor> SolidityToScd(Solidity solid
{
Name = function.Name,
Description = string.Empty,
Dispatcher = "", //TODO:
Dispatcher = string.Empty, //TODO:
Events = new List<string>(), //TODO:
HasSideEffects = false, //TODO:
Inputs = inputs,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
eventArray:{eventName|
@CrossOrigin
@RequestMapping(value = "/query/€eventName€", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE\})
public List<Occurrence> query€eventName€(@RequestBody QueryInput input) {
public List<Occurrence> query€event.FirstCapital€(@RequestBody QueryInput input) {
List<Parameter> parameters= new ArrayList<Parameter>(){
eventoutputparameterarray:{it|{add(new Parameter().builder().name("€it.name€").type("{\"type\": \"€it.type€\"\}").build());\}};separator="\n"
eventoutputparameterarray:{it|{add(new Parameter().builder().name("€it.name€").type("{\"type\": \"€it.type€\"\}").build());\}};separator="\n"
\};
return scipClientFunctions.performQuery(null,"€eventName€",parameters,input.getFilter(),input.getTimeFrame());
\}

//TODO: Generate Mapping
@CrossOrigin
@RequestMapping(value = "/subscribe/€eventName€", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE\})
public Observable<SubscribeResponse> subscribe€eventName€(@RequestBody SubscribeInput input) {
List<Parameter> parameters= new ArrayList<Parameter>(){{
//TODO: Generated parameters
add(new Parameter().builder().name("name").type("type").value("value").build());
\}\};
public Observable<SubscribeResponse> subscribe€event.FirstCapital€(@RequestBody SubscribeInput input) {
List<Parameter> parameters= new ArrayList<Parameter>(){
eventoutputparameterarray:{it|{add(new Parameter().builder().name("€it.name€").type("{\"type\": \"€it.type€\"\}").build());\}};separator="\n"
\};
return scipClientFunctions.performSubscribe(null,"€eventName€",parameters,input.getFilter(),input.getCorrelationIdentifier(), input.getDegreeOfConfidence());
\}

//TODO: Generate Mapping
@CrossOrigin
@RequestMapping(value = "/unsubscribe/€eventName€", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE\})
public UnsubscribeResponse unsubscribe€eventName€() {
List<Parameter> parameters= new ArrayList<Parameter>(){{
//TODO: Generated parameters
add(new Parameter().builder().name("name").type("type").value("value").build());
\}\};
public UnsubscribeResponse unsubscribe€event.FirstCapital€() {
List<Parameter> parameters= new ArrayList<Parameter>(){
eventoutputparameterarray:{it|{add(new Parameter().builder().name("€it.name€").type("{\"type\": \"€it.type€\"\}").build());\}};separator="\n"
\};
return scipClientFunctions.performUnsubscribe("€eventName€",null,parameters,null);
\}
};separator="\n"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@CrossOrigin
@CrossOrigin
@RequestMapping(value = "/unsubscribe€contractName€/", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE})
public UnsubscribeResponse unsubscribe(@RequestBody String correlationIdentifier) {
return scipClientFunctions.performUnsubscribe(null,null,null, correlationIdentifier);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,40 @@
functionArray:{function|
@CrossOrigin
@RequestMapping(value = "/invoke/€function.Name€", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE\})
public CompletableFuture<InvokeResponse> invoke€function.FirstCapital€(@RequestBody €functionParameter€Parameter parameter) {

public InvokeResponse invoke€function.FirstCapital€(@RequestBody €functionParameter€Parameter parameter) throws ExecutionException, InterruptedException {
List<Parameter> inputParameters = new ArrayList<Parameter>(){
inputparameterarray:{it|{add(Parameter.builder().name("€it.Name€").type("{\"type\": \"€it.ParamType\"\}").value(parameter.get€it.FirstCapital€()).build());\}};separator="\n"
inputparameterarray:{it|{add(Parameter.builder().name("€it.Name€").type("{\"type\": \"€it.ParamType\"\}").value(parameter.get€it.FirstCapital€()).build());\}};separator="\n"
\};
List<Parameter> outputParameters = new ArrayList<Parameter>(){
outputparameterarray:{it|{add(new Parameter().builder().name("€it.name€").type("{\"type\": \"€it.type€\"\}").build());\}};separator="\n"
outputparameterarray:{it|{add(new Parameter().builder().name("€it.name€").type("{\"type\": \"€it.type€\"\}").build());\}};separator="\n"
\};
return scipClientFunctions.performInvoke("€function.Name€",inputParameters,outputParameters,parameter.getDegreeOfConfidence());
return scipClientFunctions.performInvoke("€function.Name€",inputParameters,outputParameters,parameter.getDegreeOfConfidence()).get();
\}

//TODO:
@CrossOrigin
@RequestMapping(value = "/query/€function.Name€", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE\})
public List<Occurrence> query€function.FirstCapital€(@RequestBody QueryInput input) {
List<Parameter> parameters= new ArrayList<Parameter>(){{
//TODO: Generated parameters
add(new Parameter().builder().name("name").type("type").value("value").build());
\}\};
return scipClientFunctions.performQuery("€function.Name€",null,parameters,input.getFilter(),input.getTimeFrame());
\}
@CrossOrigin
@RequestMapping(value = "/query/€function.Name€", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE\})
public List<Occurrence> query€function.FirstCapital€(@RequestBody QueryInput input) {
List<Parameter> parameters= new ArrayList<Parameter>(){
inputparameterarray:{it|{add(Parameter.builder().name("€it.Name€").type("{\"type\": \"€it.ParamType\"\}").build());\}};separator="\n"
\};
return scipClientFunctions.performQuery("€function.Name€",null,parameters,input.getFilter(),input.getTimeFrame());
\}

//TODO: Generate Mapping
@CrossOrigin
@RequestMapping(value = "/subscribe/€function.Name€", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE\})
public Observable<SubscribeResponse> subscribe€function.FirstCapital€(@RequestBody SubscribeInput input) {
List<Parameter> parameters= new ArrayList<Parameter>(){{
//TODO: Generated parameters
add(new Parameter().builder().name("name").type("type").value("value").build());
\}\};
List<Parameter> parameters= new ArrayList<Parameter>(){
inputparameterarray:{it|{add(Parameter.builder().name("€it.Name€").type("{\"type\": \"€it.ParamType\"\}").build());\}};separator="\n"
\};
return scipClientFunctions.performSubscribe("€function.Name€",null,parameters,input.getFilter(),input.getCorrelationIdentifier(),input.getDegreeOfConfidence());
\}

//TODO: Generate Mapping
@CrossOrigin
@RequestMapping(value = "/unsubscribe/€function.Name€", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE\})
public UnsubscribeResponse unsubscribe€function.FirstCapital€() {
List<Parameter> parameters= new ArrayList<Parameter>(){{
//TODO: Generated parameters
add(new Parameter().builder().name("name").type("type").value("value").build());
\}\};
return scipClientFunctions.performUnsubscribe(null,"€function.Name€",parameters,null);
\}
@CrossOrigin
@RequestMapping(value = "/unsubscribe/€function.Name€", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE\})
public UnsubscribeResponse unsubscribe€function.FirstCapital€() {
List<Parameter> parameters= new ArrayList<Parameter>(){
inputparameterarray:{it|{add(Parameter.builder().name("€it.Name€").type("{\"type\": \"€it.ParamType\"\}").build());\}};separator="\n"
\};
return scipClientFunctions.performUnsubscribe(null,"€function.Name€",parameters,null);
\}
};separator="\n"
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

@RestController
public class €contractName€Controller {
Expand Down

0 comments on commit 82473bc

Please sign in to comment.