Skip to content

Commit

Permalink
Updated Templates (#853)
Browse files Browse the repository at this point in the history
* Updated Templates

* Fixed neo.smartcontract.template csproj

* Update src/Neo.SmartContract.Template/templates/neocontractowner/.template.config/template.json

Co-authored-by: Shargon <shargon@gmail.com>

---------

Co-authored-by: Shargon <shargon@gmail.com>
  • Loading branch information
cschuchardt88 and shargon committed Jan 4, 2024
1 parent 5e61a31 commit 065f04d
Show file tree
Hide file tree
Showing 25 changed files with 622 additions and 29 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>
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
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"
}
}
}
156 changes: 156 additions & 0 deletions src/Neo.SmartContract.Template/templates/neocontractnep17/Contract1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
using Neo;
using Neo.SmartContract;
using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Attributes;
using Neo.SmartContract.Framework.Native;
using Neo.SmartContract.Framework.Services;

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

namespace ProjectName
{
[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("*", "*")]
[SupportedStandards("NEP-17")]
public class Contract1 : Nep17Token
{
#region Owner

private const byte Prefix_Owner = 0xff;

// TODO: Replace it with your own address.
[InitialValue("<Your Address Here>", Neo.SmartContract.ContractParameterType.Hash160)]
private static readonly UInt160 InitialOwner = default;

[Safe]
public static UInt160 GetOwner()
{
var currentOwner = Storage.Get(new[] { Prefix_Owner });

if (currentOwner == null)
return InitialOwner;

return (UInt160)currentOwner;
}

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

public delegate void OnSetOwnerDelegate(UInt160 newOwner);

[DisplayName("SetOwner")]
public static event OnSetOwnerDelegate OnSetOwner;

public static void SetOwner(UInt160 newOwner)
{
if (IsOwner() == false)
throw new InvalidOperationException("No Authorization!");
if (newOwner != null && newOwner.IsValid)
{
Storage.Put(new[] { Prefix_Owner }, newOwner);
OnSetOwner(newOwner);
}
}

#endregion

#region NEP17

// NOTE: Valid Range 0-31
[Safe]
public override byte Decimals() => 8;

// TODO: Replace "EXAMPLE" with a short name all UPPERCASE 3-8 characters
[Safe]
public override string Symbol() => "EXAMPLE";

public static new void Burn(UInt160 account, BigInteger amount)
{
if (IsOwner() == false)
throw new InvalidOperationException("No Authorization!");
Nep17Token.Burn(account, amount);
}

public static new void Mint(UInt160 to, BigInteger amount)
{
if (IsOwner() == false)
throw new InvalidOperationException("No Authorization!");
Nep17Token.Mint(to, amount);
}

#endregion

#region Payment

public static bool Withdraw(UInt160 token, UInt160 to, BigInteger amount)
{
if (IsOwner() == false)
throw new InvalidOperationException("No Authorization!");
if (amount <= 0)
throw new ArgumentOutOfRangeException(nameof(amount));
if (to == null || to.IsValid == false)
throw new ArgumentException("Invalid Address!");
if (token == null || token.IsValid == false)
throw new ArgumentException("Invalid Token Address!");
if (ContractManagement.GetContract(token) == null)
throw new ArgumentException("Token Not A Contract!");
// TODO: Add logic
return true;
}

// NOTE: Allows ALL NEP-17 tokens to be received for this contract
public static void OnNEP17Payment(UInt160 from, BigInteger amount, object data)
{
// TODO: Add logic for specific NEP-17 contract tokens
if (Runtime.CallingScriptHash == NEO.Hash)
{
// TODO: Add logic (Burn, Mint, Transfer, Etc)
}
if (Runtime.CallingScriptHash == GAS.Hash)
{
// TODO: Add logic (Burn, Mint, Transfer, Etc)
}
}

#endregion

// 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.
public static string MyMethod()
{
return Storage.Get(Storage.CurrentContext, "Hello");
}

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

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

public static void Update(ByteString nefFile, string manifest)
{
if (!IsOwner()) throw new Exception("No authorization.");
ContractManagement.Update(nefFile, manifest, null);
}

// NOTE: NEP-17 contracts "SHOULD NOT" have "Destroy" method
}
}
Loading

0 comments on commit 065f04d

Please sign in to comment.