Skip to content

Commit

Permalink
Merge branch 'master' into convert-statement
Browse files Browse the repository at this point in the history
* master:
  fix error message (neo-project#854)
  Updated Templates (neo-project#853)
  Fix: ban  notify from contract developer (neo-project#845)
  • Loading branch information
Jim8y committed Jan 12, 2024
2 parents e164cef + 8fdc94d commit 0d30893
Show file tree
Hide file tree
Showing 29 changed files with 649 additions and 47 deletions.
7 changes: 7 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
<VersionPrefix>3.6.2</VersionPrefix>
<TargetFramework>net7.0</TargetFramework>
<Authors>The Neo Project</Authors>
<PackageProjectUrl>https://github.com/neo-project/neo-devpack-dotnet</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/neo-project/neo-devpack-dotnet.git</RepositoryUrl>
</PropertyGroup>

<ItemGroup>
<None Include="../neo.png" Pack="true" Visible="false" PackagePath=""/>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions src/Neo.Compiler.CSharp/DiagnosticId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ static class DiagnosticId
public const string InvalidMethodName = "NC3002";
public const string MethodNameConflict = "NC3003";
public const string EventNameConflict = "NC3004";
public const string InvalidInitialValue = "NC3005";
}
}
37 changes: 22 additions & 15 deletions src/Neo.Compiler.CSharp/MethodConvert/MethodConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,22 +339,29 @@ private void ProcessFieldInitializer(SemanticModel model, IFieldSymbol field, Ac
preInitialize?.Invoke();
string value = (string)initialValue.ConstructorArguments[0].Value!;
ContractParameterType type = (ContractParameterType)initialValue.ConstructorArguments[1].Value!;
switch (type)
try
{
case ContractParameterType.String:
Push(value);
break;
case ContractParameterType.ByteArray:
Push(value.HexToBytes(true));
break;
case ContractParameterType.Hash160:
Push((UInt160.TryParse(value, out var hash) ? hash : value.ToScriptHash(context.Options.AddressVersion)).ToArray());
break;
case ContractParameterType.PublicKey:
Push(ECPoint.Parse(value, ECCurve.Secp256r1).EncodePoint(true));
break;
default:
throw new CompilationException(field, DiagnosticId.InvalidInitialValueType, $"Unsupported initial value type: {type}");
switch (type)
{
case ContractParameterType.String:
Push(value);
break;
case ContractParameterType.ByteArray:
Push(value.HexToBytes(true));
break;
case ContractParameterType.Hash160:
Push((UInt160.TryParse(value, out var hash) ? hash : value.ToScriptHash(context.Options.AddressVersion)).ToArray());
break;
case ContractParameterType.PublicKey:
Push(ECPoint.Parse(value, ECCurve.Secp256r1).EncodePoint(true));
break;
default:
throw new CompilationException(field, DiagnosticId.InvalidInitialValueType, $"Unsupported initial value type: {type}");
}
}
catch (Exception ex) when (ex is not CompilationException)
{
throw new CompilationException(field, DiagnosticId.InvalidInitialValue, $"Invalid initial value: {value} of type: {type}");
}
postInitialize?.Invoke();
}
Expand Down
6 changes: 2 additions & 4 deletions src/Neo.Compiler.CSharp/Neo.Compiler.CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
<RootNamespace>Neo.Compiler</RootNamespace>
<Nullable>enable</Nullable>
<PackageTags>NEO;Blockchain;Smart Contract;Compiler</PackageTags>
<PackageProjectUrl>https://github.com/neo-project/neo-devpack-dotnet</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/neo-project/neo-devpack-dotnet.git</RepositoryUrl>
<Company>The Neo Project</Company>
<Product>Neo.Compiler.CSharp</Product>
<Description>Neo.Compiler.CSharp</Description>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@
<AssemblyTitle>Neo.SmartContract.Framework</AssemblyTitle>
<AssemblyName>Neo.SmartContract.Framework</AssemblyName>
<PackageId>Neo.SmartContract.Framework</PackageId>
<PackageTags>NEO;Blockchain</PackageTags>
<PackageProjectUrl>https://github.com/neo-project/neo-devpack-dotnet</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/neo-project/neo-devpack-dotnet.git</RepositoryUrl>
<Description>Neo.SmartContract.Framework</Description>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Description>Neo.SmartContract.Framework</Description>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions src/Neo.SmartContract.Framework/Services/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ public static extern byte AddressVersion
[Syscall("System.Runtime.Log")]
public static extern void Log(string message);

[Syscall("System.Runtime.Notify")]
public static extern void Notify(string eventName, object[] state);
// Events not present in the ABI were disabled in HF_Basilisk
// [Syscall("System.Runtime.Notify")]
// public static extern void Notify(string eventName, object[] state);

[Syscall("System.Runtime.BurnGas")]
public static extern void BurnGas(long gas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
<PackageType>Template</PackageType>
<PackageId>Neo.SmartContract.Template</PackageId>
<PackageTags>NEO;Blockchain;Smart Contract</PackageTags>
<PackageProjectUrl>https://github.com/neo-project/neo-devpack-dotnet</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/neo-project/neo-devpack-dotnet.git</RepositoryUrl>
<Description>Templates to use when creating a smart contract for NEO.</Description>
<IncludeContentInPack>true</IncludeContentInPack>
<IncludeBuildOutput>false</IncludeBuildOutput>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"neo.compiler.csharp": {
"version": "TemplateNeoVersion",
"commands": [
"nccs"
]
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
{
"$schema": "http://json.schemastore.org/template",
"author": "The Neo Project",
"classifications": [ "NEO", "Blockchain", "Smart Contract" ],
"identity": "Neo.SmartContract.Template",
"name": "Neo.SmartContract.Template",
"classifications": [ "NEO", "Blockchain", "Smart Contract", "Basic" ],
"identity": "Neo.SmartContract.Template.Basic",
"name": "Neo Smart Contract - Basic",
"shortName": "neocontract",
"preferNameDirectory": true,
"tags": {
"language": "C#",
"type": "project"
},
"sourceName": "ProjectName"
"sourceName": "ProjectName",
"symbols": {
"NeoVersion": {
"type": "parameter",
"datatype": "choice",
"choices": [
{
"choice": "3.6.0"
},
{
"choice": "3.6.2"
}
],
"defaultValue": "3.6.2",
"replaces": "TemplateNeoVersion"
}
}
}
25 changes: 17 additions & 8 deletions src/Neo.SmartContract.Template/templates/neocontract/Contract1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,31 @@
using Neo.SmartContract.Framework.Attributes;
using Neo.SmartContract.Framework.Native;
using Neo.SmartContract.Framework.Services;

using System;
using System.Numerics;
using System.ComponentModel;

namespace ProjectName
{
[ManifestExtra("Author", "Neo")]
[ManifestExtra("Email", "dev@neo.org")]
[ManifestExtra("Description", "This is a contract example")]
[DisplayName(nameof(Contract1))]
[ManifestExtra("Author", "<Your Name Or Company Here>")]
[ManifestExtra("Description", "<Description Here>")]
[ManifestExtra("Email", "<Your Public Email Here>")]
[ManifestExtra("Version", "<Version String Here>")]
[ContractSourceCode("https://github.com/neo-project/neo-devpack-dotnet/tree/master/src/Neo.SmartContract.Template")]
[ContractPermission("*", "*")]
public class Contract1 : SmartContract
{
//TODO: Replace it with your own address.
[InitialValue("NiNmXL8FjEUEs1nfX9uHFBNaenxDHJtmuB", ContractParameterType.Hash160)]
// TODO: Replace it with your own address.
[InitialValue("<Your Address Here>", ContractParameterType.Hash160)]
static readonly UInt160 Owner = default;

private static bool IsOwner() => Runtime.CheckWitness(Owner);

// When this contract address is included in the transaction signature,
// this method will be triggered as a VerificationTrigger to verify that the signature is correct.
// For example, this method needs to be called when withdrawing token from the contract.
[Safe]
public static bool Verify() => IsOwner();

// TODO: Replace it with your methods.
Expand All @@ -34,9 +39,13 @@ public static string MyMethod()

public static void _deploy(object data, bool update)
{
if (update) return;
if (update)
{
// This will be executed during update
return;
}

// It will be executed during deploy
// This will be executed during deploy
Storage.Put(Storage.CurrentContext, "Hello", "World");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Neo.SmartContract.Framework" Version="3.6.0" />
<PackageReference Include="Neo.SmartContract.Framework" Version="TemplateNeoVersion" />
</ItemGroup>

<PropertyGroup>
Expand All @@ -17,9 +17,9 @@
</PropertyGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Message Text="Start NeoContract converter, Source File: $(ProjectPath)" Importance="high">
<Message Text="Start NeoContract converter, Source File: &quot;$(ProjectPath)&quot;" Importance="high">
</Message>
<Exec Command="nccs $(BaseNameArgument) $(NullableArgument) $(CheckedArgument) $(DebugArgument) &quot;$(ProjectPath)&quot;" />
<Exec Command="dotnet nccs $(BaseNameArgument) $(NullableArgument) $(CheckedArgument) $(DebugArgument) &quot;$(ProjectPath)&quot;" />
</Target>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"neo.compiler.csharp": {
"version": "TemplateNeoVersion",
"commands": [
"nccs"
]
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "http://json.schemastore.org/template",
"author": "The Neo Project",
"classifications": [ "NEO", "Blockchain", "Smart Contract", "NEP-17" ],
"identity": "Neo.SmartContract.Template.Nep17",
"name": "Neo Smart Contract - NEP-17",
"shortName": "neocontractnep17",
"preferNameDirectory": true,
"tags": {
"language": "C#",
"type": "project"
},
"sourceName": "ProjectName",
"symbols": {
"NeoVersion": {
"type": "parameter",
"datatype": "choice",
"choices": [
{
"choice": "3.6.0"
},
{
"choice": "3.6.2"
}
],
"defaultValue": "3.6.2",
"replaces": "TemplateNeoVersion"
}
}
}
Loading

0 comments on commit 0d30893

Please sign in to comment.