Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add example nep11 #1009

Merged
merged 27 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2353d01
add example nep11
vikkkko Mar 29, 2024
e630e04
Merge branch 'master' into master
vikkkko Mar 29, 2024
7d027ab
Update examples/Example.SmartContract.NEP11/Example.SmartContract.NEP…
Jim8y Mar 31, 2024
f990047
change name and change storage usage
vikkkko Apr 1, 2024
fd3ead6
multi-fix
superboyiii Apr 3, 2024
75f90a6
more fix
superboyiii Apr 3, 2024
eb45055
owner revert
superboyiii Apr 3, 2024
f91407b
Merge pull request #1 from superboyiii/royalty-example
vikkkko Apr 3, 2024
142e931
Update examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivi…
Jim8y Apr 3, 2024
4ba9fc6
Update examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivi…
Jim8y Apr 3, 2024
ff66e79
Update examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivi…
Jim8y Apr 3, 2024
f6b0b92
Update examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivi…
Jim8y Apr 3, 2024
f363da5
Update examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivi…
Jim8y Apr 3, 2024
bda7481
Merge branch 'master' into master
Jim8y Apr 4, 2024
5716d0c
fix name and comment
superboyiii Apr 11, 2024
81c2515
fix
superboyiii Apr 11, 2024
6a89ce4
fix
superboyiii Apr 11, 2024
653226e
fix update
superboyiii Apr 11, 2024
7d97d18
Merge pull request #3 from superboyiii/royalty-example
vikkkko Apr 11, 2024
e73558f
Merge branch 'master' into master
vikkkko Apr 11, 2024
3aba116
fix solution
superboyiii Apr 11, 2024
ca1f14f
Merge pull request #4 from superboyiii/royalty-example
vikkkko Apr 11, 2024
d6ef385
Update SampleRoyaltyNEP11Token.cs
Jim8y Apr 11, 2024
dbbf66c
Apply suggestions from code review
cschuchardt88 Apr 15, 2024
eac9d27
Merge branch 'master' into master
Jim8y Apr 16, 2024
ef7c040
fix Assert
superboyiii Apr 16, 2024
a330c74
Merge pull request #5 from superboyiii/royalty-example
vikkkko Apr 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34714.143
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.SmartContract.SampleRoyaltyNEP11Token", "Example.SmartContract.SampleRoyaltyNEP11Token.csproj", "{E363C475-EB64-48BD-A032-B13F48156BE2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E363C475-EB64-48BD-A032-B13F48156BE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E363C475-EB64-48BD-A032-B13F48156BE2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E363C475-EB64-48BD-A032-B13F48156BE2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E363C475-EB64-48BD-A032-B13F48156BE2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {21916810-7630-4DA1-881A-1413447D8521}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't generate the *.nef file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't generate the *.nef file.

If you want, we can add PostBuild in Target like:

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

But maybe just keep in the same formation with other examples is better? People can go to project path and just type ncss.

Copy link
Member

@shargon shargon Apr 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add it in all of them, but I think that we should find a different way to execute nccs, using a package we can do it without require user installation maybe.

(Not related to this PR)

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// SampleRoyaltyNEP11Token.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

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 NonDivisibleNEP11
{
/// <inheritdoc />
[DisplayName("SampleRoyaltyNEP11Token")]
[ContractAuthor("core-dev", "dev@neo.org")]
[ContractVersion("0.0.1")]
[ContractDescription("A sample of NEP-11 Royalty Feature")]
[ContractSourceCode("https://github.com/neo-project/neo-devpack-dotnet/tree/master/examples/")]
[ContractPermission(Permission.WildCard, Method.WildCard)]
[SupportedStandards(NepStandard.Nep11)]
public class SampleRoyaltyNEP11Token : Nep11Token<Nep11TokenState>
{
#region Owner

private const byte PrefixOwner = 0xff;

private static readonly UInt160 InitialOwner = "NUuJw4C4XJFzxAvSZnFTfsNoWZytmQKXQP";

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

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 && !newOwner.IsZero)
Jim8y marked this conversation as resolved.
Show resolved Hide resolved
{
Storage.Put(new[] { PrefixOwner }, newOwner);
OnSetOwner(newOwner);
}
}

#endregion

#region Minter

private const byte PrefixMinter = 0xfd;

private const byte PrefixCounter = 0xee;

private static readonly UInt160 InitialMinter = "NUuJw4C4XJFzxAvSZnFTfsNoWZytmQKXQP";

[Safe]
public static UInt160 GetMinter()
{
var currentMinter = Storage.Get(new[] { PrefixMinter });

if (currentMinter == null)
return InitialMinter;

return (UInt160)currentMinter;
}

private static bool IsMinter() => Runtime.CheckWitness(GetMinter());

public delegate void OnSetMinterDelegate(UInt160 newMinter);

[DisplayName("SetMinter")]
public static event OnSetMinterDelegate OnSetMinter;

public static void SetMinter(UInt160? newMinter)
{
ExecutionEngine.Assert(IsOwner(), "No Authorization!");
cschuchardt88 marked this conversation as resolved.
Show resolved Hide resolved
if (newMinter != null && newMinter.IsValid)
cschuchardt88 marked this conversation as resolved.
Show resolved Hide resolved
{
Storage.Put(new[] { PrefixMinter }, newMinter);
OnSetMinter(newMinter);
}
}

public static void Mint(UInt160 to)
{
ExecutionEngine.Assert(IsOwner() || IsMinter(), "No Authorization!");
cschuchardt88 marked this conversation as resolved.
Show resolved Hide resolved
IncreaseCount();
BigInteger tokenId = CurrentCount();
Nep11TokenState nep11TokenState = new Nep11TokenState()
{
Name = "SampleRoyaltyNep11Token",
Owner = to
};
Mint((ByteString)tokenId, nep11TokenState);
}

private static void SetCount(BigInteger count)
{
Storage.Put(new[] { PrefixCounter }, count);
}

[Safe]
public static BigInteger CurrentCount()
{
return (BigInteger)Storage.Get(new[] { PrefixCounter });
}

private static void IncreaseCount()
{
SetCount(CurrentCount() + 1);
}

#endregion

#region Example.SmartContract.NEP11

public override string Symbol { [Safe] get => "SampleRoyalty"; }

#endregion

#region Royalty
private const byte PrefixRoyalty = 0xfb;

private static readonly UInt160 InitialRecipient = "NUuJw4C4XJFzxAvSZnFTfsNoWZytmQKXQP";
private static readonly BigInteger InitialFactor = 700;

public static void SetRoyaltyInfo(ByteString tokenId, Map<string, object>[] royaltyInfos)
{
ExecutionEngine.Assert(tokenId.Length <= 64, "The argument \"tokenId\" should be 64 or less bytes long.");
ExecutionEngine.Assert(IsOwner(), "No Authorization!");
cschuchardt88 marked this conversation as resolved.
Show resolved Hide resolved
for (uint i = 0; i < royaltyInfos.Length; i++)
{
if (((UInt160)royaltyInfos[i]["royaltyRecipient"]).IsValid == false ||
(BigInteger)royaltyInfos[i]["royaltyRecipient"] < 0 ||
(BigInteger)royaltyInfos[i]["royaltyRecipient"] > 10000)
throw new InvalidOperationException("Parameter error");
}
Storage.Put(PrefixRoyalty + tokenId, StdLib.Serialize(royaltyInfos));
}

/// <summary>
/// This implements Royalty Standard: https://github.com/neo-project/proposals/pull/155/
/// This method returns a map of NeoVM Array stack item with single or multi array, each array includes royaltyRecipient and royaltyAmount
/// </summary>
/// <param name="tokenId">tokenId</param>
/// <param name="royaltyToken">royaltyToken hash for payment</param>
/// <param name="salePrice">royaltyToken amount for payment</param>
/// <returns>royaltyInfo</returns>
[Safe]
public static Map<string, object>[] RoyaltyInfo(ByteString tokenId, UInt160 royaltyToken, BigInteger salePrice)
{
ExecutionEngine.Assert(OwnerOf(tokenId) != null, "This TokenId doesn't exist!");
cschuchardt88 marked this conversation as resolved.
Show resolved Hide resolved
byte[] data = (byte[])Storage.Get(PrefixRoyalty + tokenId);
if (data == null)
{
var royaltyInfo = new Map<string, object>();
royaltyInfo["royaltyRecipient"] = InitialRecipient;
royaltyInfo["royaltyAmount"] = InitialFactor;
return new[] { royaltyInfo };
}
else
{
return (Map<string, object>[])StdLib.Deserialize((ByteString)data);
}
}
#endregion

#region Basic

[Safe]
public static bool Verify() => IsOwner();

public static bool Update(ByteString nefFile, ByteString manifest, object data)
{
ExecutionEngine.Assert(IsOwner() == false, "No Authorization!");
cschuchardt88 marked this conversation as resolved.
Show resolved Hide resolved
ContractManagement.Update(nefFile, manifest, data);
return true;
cschuchardt88 marked this conversation as resolved.
Show resolved Hide resolved
}
#endregion
}
}
19 changes: 13 additions & 6 deletions neo-devpack-dotnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.SmartContract.Trans
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.SmartContract.ZKP", "examples\Example.SmartContract.ZKP\Example.SmartContract.ZKP.csproj", "{141AD5BA-1735-4583-93B6-145CF72721E5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.SmartContract.Analyzer.UnitTests", "tests\Neo.SmartContract.Analyzer.UnitTests\Neo.SmartContract.Analyzer.UnitTests.csproj", "{F30E2375-012A-4A38-985B-31CB7DBA4D28}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.SmartContract.Analyzer.UnitTests", "tests\Neo.SmartContract.Analyzer.UnitTests\Neo.SmartContract.Analyzer.UnitTests.csproj", "{F30E2375-012A-4A38-985B-31CB7DBA4D28}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.SmartContract.NFT.UnitTests", "examples\Example.SmartContract.NFT.UnitTests\Example.SmartContract.NFT.UnitTests.csproj", "{F1512011-B002-4854-8E4E-74E67F486FD5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.SmartContract.NFT.UnitTests", "examples\Example.SmartContract.NFT.UnitTests\Example.SmartContract.NFT.UnitTests.csproj", "{F1512011-B002-4854-8E4E-74E67F486FD5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.SmartContract.SampleRoyaltyNEP11Token", "examples\Example.SmartContract.SampleRoyaltyNEP11Token\Example.SmartContract.SampleRoyaltyNEP11Token.csproj", "{50A2DABC-6131-454A-9275-215A2B7A133B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -208,6 +210,10 @@ Global
{F1512011-B002-4854-8E4E-74E67F486FD5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F1512011-B002-4854-8E4E-74E67F486FD5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F1512011-B002-4854-8E4E-74E67F486FD5}.Release|Any CPU.Build.0 = Release|Any CPU
{50A2DABC-6131-454A-9275-215A2B7A133B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{50A2DABC-6131-454A-9275-215A2B7A133B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{50A2DABC-6131-454A-9275-215A2B7A133B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{50A2DABC-6131-454A-9275-215A2B7A133B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -222,6 +228,10 @@ Global
{8D67DD5A-D683-481F-915E-98683EA38791} = {D5266066-0AFD-44D5-A83E-2F73668A63C8}
{A372F1D6-51FF-472C-9508-FDAF7E6FEB13} = {D5266066-0AFD-44D5-A83E-2F73668A63C8}
{D0153204-6AEF-4D94-B0E1-8124C38C91D4} = {D5266066-0AFD-44D5-A83E-2F73668A63C8}
{73223FBD-C562-4FA0-9722-C7F1C382A9DE} = {49D5873D-7B38-48A5-B853-85146F032091}
{D541BCE9-65BC-475B-94E5-19B6BFFF2B8E} = {49D5873D-7B38-48A5-B853-85146F032091}
{35A34EBD-F2BF-4D83-A096-D5F007B12732} = {49D5873D-7B38-48A5-B853-85146F032091}
{D6D53889-5A10-46A4-BA66-E78B56EC1881} = {49D5873D-7B38-48A5-B853-85146F032091}
{648DCE6F-A0BA-4032-951B-20CF5BBFD998} = {79389FC0-C621-4CEA-AD2B-6074C32E7BCA}
{B772B8A9-9362-4C6F-A6D3-2A4138439B2C} = {D5266066-0AFD-44D5-A83E-2F73668A63C8}
{17F45E0B-AB1C-4796-8C99-E5212A5592F8} = {D5266066-0AFD-44D5-A83E-2F73668A63C8}
Expand All @@ -240,11 +250,8 @@ Global
{5319BE3E-A5E9-4AFF-94D6-A669DA214F24} = {C10F9957-077F-42C8-B350-8607D4899B7E}
{141AD5BA-1735-4583-93B6-145CF72721E5} = {C10F9957-077F-42C8-B350-8607D4899B7E}
{F30E2375-012A-4A38-985B-31CB7DBA4D28} = {D5266066-0AFD-44D5-A83E-2F73668A63C8}
{35A34EBD-F2BF-4D83-A096-D5F007B12732} = {49D5873D-7B38-48A5-B853-85146F032091}
{73223FBD-C562-4FA0-9722-C7F1C382A9DE} = {49D5873D-7B38-48A5-B853-85146F032091}
{D6D53889-5A10-46A4-BA66-E78B56EC1881} = {49D5873D-7B38-48A5-B853-85146F032091}
{D541BCE9-65BC-475B-94E5-19B6BFFF2B8E} = {49D5873D-7B38-48A5-B853-85146F032091}
{F1512011-B002-4854-8E4E-74E67F486FD5} = {C10F9957-077F-42C8-B350-8607D4899B7E}
{50A2DABC-6131-454A-9275-215A2B7A133B} = {C10F9957-077F-42C8-B350-8607D4899B7E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6DA935E1-C674-4364-B087-F1B511B79215}
Expand Down
Loading