Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Keyword escaping for contract method names and event names in SolCodeGen

See merge request company-projects/Meadow!31
  • Loading branch information
zone117x committed Oct 3, 2018
2 parents e161227 + 608aef7 commit 1b776a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/Meadow.SolCodeGen/CodeGenerators/ContractGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,14 @@ string GenerateFunction(Abi methodAbi)
decoderStr = "this, callData";
}

var methodName = ReservedKeywords.EscapeIdentifier(methodAbi.Name);

var (summaryDoc, paramsDoc) = GetSummaryXmlDoc(methodAbi);

return $@"
/// <summary>{summaryDoc}</summary>
{paramsDoc}
public EthFunc{returnType} {methodAbi.Name}({inputConstructorArg})
public EthFunc{returnType} {methodName}({inputConstructorArg})
{{
var callData = {typeof(EncoderUtil).FullName}.GetFunctionCallBytes({callDataString});
Expand Down Expand Up @@ -600,9 +602,11 @@ string GenerateEvent(Abi eventAbi)

string eventSignatureHash = AbiSignature.GetSignatureHash(eventAbi);

var eventName = ReservedKeywords.EscapeIdentifier(eventAbi.Name);

return $@"
[{typeof(EventSignatureAttribute).FullName}(SIGNATURE)]
public class {eventAbi.Name} : {typeof(EventLog).FullName}
public class {eventName} : {typeof(EventLog).FullName}
{{
public override string EventName => ""{eventAbi.Name}"";
public override string EventSignature => SIGNATURE;
Expand Down
2 changes: 1 addition & 1 deletion src/Meadow.SolCodeGen/ReservedKeywords.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static string EscapeIdentifier(string name)
{
if (RESERVED.Contains(name))
{
return "_" + name;
return "@" + name;
}

return name;
Expand Down

0 comments on commit 1b776a3

Please sign in to comment.