Skip to content

Commit

Permalink
first working version
Browse files Browse the repository at this point in the history
  • Loading branch information
umutonat committed Jun 26, 2020
1 parent 82473bc commit eef2df5
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 115 deletions.
4 changes: 0 additions & 4 deletions SCTransformation.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public Startup(IConfiguration configuration)
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
Expand All @@ -31,8 +29,6 @@ public void ConfigureServices(IServiceCollection services)
c.IncludeXmlComments(xmlPath);
});
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
Expand Down
52 changes: 23 additions & 29 deletions SCTransformation/ClientApplicationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public static void Main(string[] args)
{
var scds = SmartContractDescriptorGenerator.Transform(
File.ReadAllText(
"/Users/artuvan/Github/SmartContractDescriptorsGenerator/SCTransformation/Resources/in.sol"),
"Solidity");
BuildJavaApplication(scds.First(), "com.danyue", "call");
"/Users/artuvan/Github/SmartContractDescriptorsGenerator/SCTransformation/Resources/in.js"),
"JavaScript");
BuildJavaApplication(scds.First(), "com.uni.stuttgart", "callback");
}

private static string BuildJavaApplication(SmartContractDescriptor smartContractDescriptor,
Expand All @@ -45,15 +45,11 @@ private static string BuildJavaApplication(SmartContractDescriptor smartContract
var smartContractPath = path.Replace("smartcontract", smartContractDescriptor.Name.ToLower());
foreach (var function in smartContractDescriptor.Functions)
{
var tempPath = smartContractPath.Replace("Function",
System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(
function.Name.ToLower()));
var tempPath = smartContractPath.Replace("Function", ToUpperFirstLetter(function.Name));

var functionTemplate = CreateFreshTemplate(stream, smartContractDescriptor, packageName,
callbackUrl);
functionTemplate.Add("functionParameterName",
System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(
function.Name.ToLower()));
functionTemplate.Add("functionParameterName", ToUpperFirstLetter(function.Name));
foreach (var parameter in function.Inputs)
{
functionTemplate.Add("parameterarray",
Expand Down Expand Up @@ -81,24 +77,18 @@ private static string BuildJavaApplication(SmartContractDescriptor smartContract
{
var template = CreateFreshTemplate(stream, smartContractDescriptor, packageName,
callbackUrl);
template.Add("functionParameter",
System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(
function.Name.ToLower()));
template.Add("functionParameter", ToUpperFirstLetter(function.Name));
var privateFunction = new Function
{
Name = function.Name,
FirstCapital = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo
.ToTitleCase(
function.Name.ToLower())
FirstCapital = ToUpperFirstLetter(function.Name)
};
template.Add("functionArray", new[] {privateFunction});
foreach (var parameter in function.Inputs)
{
var privateParameter = new Parameter
{
FirstCapital = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo
.ToTitleCase(
parameter.Name.ToLower()),
FirstCapital = ToUpperFirstLetter(parameter.Name),
Name = parameter.Name,
ParamType = parameter.Type
};
Expand Down Expand Up @@ -126,18 +116,14 @@ private static string BuildJavaApplication(SmartContractDescriptor smartContract
var privateEvent= new Event
{
Name = scEvent.Name,
FirstCapital = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo
.ToTitleCase(
scEvent.Name.ToLower())
FirstCapital = ToUpperFirstLetter(scEvent.Name)
};
template.Add("eventArray", new[] {privateEvent});
foreach (var parameter in scEvent.Outputs)
{
var privateParameter = new Parameter
{
FirstCapital = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo
.ToTitleCase(
parameter.Name.ToLower()),
FirstCapital = ToUpperFirstLetter(parameter.Name),
Name = parameter.Name,
ParamType = parameter.Type
};
Expand All @@ -162,8 +148,7 @@ private static string BuildJavaApplication(SmartContractDescriptor smartContract
{
var smartContractPath = path.Replace("smartcontract", smartContractDescriptor.Name.ToLower());
smartContractPath = smartContractPath.Replace("SmartContract",
System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(
smartContractDescriptor.Name.ToLower()));
ToUpperFirstLetter(smartContractDescriptor.Name));
files.Add(new KeyValuePair<string, string>(CreateDirectory(smartContractPath, packageName),
Regex.Escape(
$"{controllerHeader}{controllerFunctions}{controllerEvents}{controllerFooter}")));
Expand All @@ -189,9 +174,7 @@ private static Template CreateFreshTemplate(Stream stream, SmartContractDescript
template.Add("sclAddress", smartContractDescriptor.SclAddress);
template.Add("callbackUrl", callbackUrl);
template.Add("contractPackageName", smartContractDescriptor.Name.ToLower());
template.Add("contractName",
System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(
smartContractDescriptor.Name.ToLower()));
template.Add("contractName", ToUpperFirstLetter(smartContractDescriptor.Name));
return template;
}

Expand Down Expand Up @@ -272,5 +255,16 @@ private class Event
public string Name;
public string FirstCapital;
}

private static string ToUpperFirstLetter(string source)
{
if (string.IsNullOrEmpty(source))
{
return string.Empty;
}
var letters = source.ToCharArray();
letters[0] = char.ToUpper(letters[0]);
return new string(letters);
}
}
}
3 changes: 2 additions & 1 deletion SCTransformation/Models/JavaScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ public class Variable
public class Function
{
public string Name { get; set; }
public string EventName { get; set; }
public List<string> Events { get; set; }
public List<Parameter> Inputs { get; set; }
public List<Parameter> Outputs { get; set; }
public bool HasSideEffects { get; set; }
}
}
}
3 changes: 3 additions & 0 deletions SCTransformation/Models/Solidity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Solidity
public List<string> Imports { get; set; }
public List<Contract> Contracts { get; set; }
public BlockChainType BlockChainType { get; set; }

public class Contract
{
public bool IsStateful { get; set; }
Expand All @@ -35,7 +36,9 @@ public class Function
public List<Parameter> Parameters { get; set; }
public List<Parameter> ReturnParameters { get; set; }
public ModifierList ModifierList { get; set; }
public List<string> Events { get; set; }
public Scope Scope { get; set; }
public bool HasSideEffects { get; set; }
}

public class Event
Expand Down
110 changes: 60 additions & 50 deletions SCTransformation/SmartContractDescriptorGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ private static IEnumerable<SmartContractDescriptor> SolidityToScd(Solidity solid
{
var inputs = new List<SmartContractDescriptor.Parameter>();
var outputs = new List<SmartContractDescriptor.Parameter>();
var functionEvents= new List<string>();
foreach (var input in function.Parameters)
{
inputs.Add(new SmartContractDescriptor.Parameter
Expand All @@ -131,13 +132,18 @@ private static IEnumerable<SmartContractDescriptor> SolidityToScd(Solidity solid
});
}

foreach (var functionEvent in function.Events)
{
functionEvents.Add(functionEvent);
}

functions.Add(new SmartContractDescriptor.Function
{
Name = function.Name,
Description = string.Empty,
Dispatcher = string.Empty, //TODO:
Events = new List<string>(), //TODO:
HasSideEffects = false, //TODO:
Dispatcher = string.Empty,
Events = functionEvents,
HasSideEffects = function.HasSideEffects,
Inputs = inputs,
Outputs = outputs,
Scope = function.Scope
Expand Down Expand Up @@ -202,62 +208,66 @@ private static IEnumerable<SmartContractDescriptor> JavaScriptToScd(JavaScript j
methods.AddRange(javaScript.Functions);
foreach (var function in methods)
{
if (function.EventName != null)
var inputs = new List<SmartContractDescriptor.Parameter>();
var outputs = new List<SmartContractDescriptor.Parameter>();
var functionEvents = new List<string>();
foreach (var input in function.Inputs)
{
var inputs = new List<SmartContractDescriptor.Parameter>();
var outputs = new List<SmartContractDescriptor.Parameter>();
foreach (var input in function.Inputs)
{
inputs.Add(new SmartContractDescriptor.Parameter
{
Name = input.Name,
Type = input.Type,
IsIndexed = false
});
}

foreach (var output in function.Outputs)
inputs.Add(new SmartContractDescriptor.Parameter
{
outputs.Add(new SmartContractDescriptor.Parameter
{
Name = output.Name,
Type = output.Type,
IsIndexed = false
});
}
Name = input.Name,
Type = input.Type,
IsIndexed = false
});
}

functions.Add(new SmartContractDescriptor.Function
foreach (var output in function.Outputs)
{
outputs.Add(new SmartContractDescriptor.Parameter
{
Name = function.Name,
Description = string.Empty,
Dispatcher = "", //TODO:
Events = new List<string>(), //TODO:
HasSideEffects = false, //TODO:
Inputs = inputs,
Outputs = outputs,
Scope = Scope.Public
Name = output.Name,
Type = output.Type,
IsIndexed = false
});
}
else

if (function.Events.Count > 0)
{
var outputs = new List<SmartContractDescriptor.Parameter>();
foreach (var output in function.Outputs)
foreach (var functionEvent in function.Events)
{
outputs.Add(new SmartContractDescriptor.Parameter
var eventOutputs = new List<SmartContractDescriptor.Parameter>();
foreach (var output in function.Outputs)
{
Name = output.Name,
Type = output.Type,
IsIndexed = false
eventOutputs.Add(new SmartContractDescriptor.Parameter
{
Name = output.Name,
Type = output.Type,
IsIndexed = false
});
}

functionEvents.Add(functionEvent);

events.Add(new SmartContractDescriptor.Event
{
Name = functionEvent,
Description = string.Empty,
Outputs = eventOutputs
});
}

events.Add(new SmartContractDescriptor.Event
{
Name = function.Name,
Description = string.Empty,
Outputs = outputs
});
}

functions.Add(new SmartContractDescriptor.Function
{
Name = function.Name,
Description = string.Empty,
Dispatcher = string.Empty,
Events = functionEvents,
HasSideEffects = function.HasSideEffects,
Inputs = inputs,
Outputs = outputs,
Scope = Scope.Public
});
}

var scdList = new List<SmartContractDescriptor>
Expand Down Expand Up @@ -322,9 +332,9 @@ private static IEnumerable<SmartContractDescriptor> GoToScd(Go go)
{
Name = function.Name,
Description = string.Empty,
Dispatcher = "", //TODO:
Events = new List<string>(), //TODO:
HasSideEffects = false, //TODO:
Dispatcher = string.Empty,
Events = new List<string>(),
HasSideEffects = false,
Inputs = inputs,
Outputs = outputs,
Scope = Scope.Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
eventArray:{eventName|
eventArray:{event|
@CrossOrigin
@RequestMapping(value = "/query/€eventName", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE\})
@RequestMapping(value = "/query/€event.Name", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE\})
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());
return scipClientFunctions.performQuery(null,"event.Name",parameters,input.getFilter(),input.getTimeFrame());
\}

@CrossOrigin
@RequestMapping(value = "/subscribe/€eventName", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE\})
@RequestMapping(value = "/subscribe/€event.Name", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE\})
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"
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());
return scipClientFunctions.performSubscribe(null,"event.Name",parameters,input.getFilter(),input.getCorrelationIdentifier(), input.getDegreeOfConfidence());
\}

@CrossOrigin
@RequestMapping(value = "/unsubscribe/€eventName", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE\})
@RequestMapping(value = "/unsubscribe/€event.Name", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE\})
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"
eventoutputparameterarray:{it|{add(new Parameter().builder().name("€it.Name").type("{\"type\": \"€it.Type\"\}").build());\}};separator="\n"
\};
return scipClientFunctions.performUnsubscribe("eventName",null,parameters,null);
return scipClientFunctions.performUnsubscribe("event.Name",null,parameters,null);
\}
};separator="\n"
Loading

0 comments on commit eef2df5

Please sign in to comment.