-
Notifications
You must be signed in to change notification settings - Fork 102
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
add example nep11 #1009
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
2353d01
add example nep11
vikkkko e630e04
Merge branch 'master' into master
vikkkko 7d027ab
Update examples/Example.SmartContract.NEP11/Example.SmartContract.NEP…
Jim8y f990047
change name and change storage usage
vikkkko fd3ead6
multi-fix
superboyiii 75f90a6
more fix
superboyiii eb45055
owner revert
superboyiii f91407b
Merge pull request #1 from superboyiii/royalty-example
vikkkko 142e931
Update examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivi…
Jim8y 4ba9fc6
Update examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivi…
Jim8y ff66e79
Update examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivi…
Jim8y f6b0b92
Update examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivi…
Jim8y f363da5
Update examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivi…
Jim8y bda7481
Merge branch 'master' into master
Jim8y 5716d0c
fix name and comment
superboyiii 81c2515
fix
superboyiii 6a89ce4
fix
superboyiii 653226e
fix update
superboyiii 7d97d18
Merge pull request #3 from superboyiii/royalty-example
vikkkko e73558f
Merge branch 'master' into master
vikkkko 3aba116
fix solution
superboyiii ca1f14f
Merge pull request #4 from superboyiii/royalty-example
vikkkko d6ef385
Update SampleRoyaltyNEP11Token.cs
Jim8y dbbf66c
Apply suggestions from code review
cschuchardt88 eac9d27
Merge branch 'master' into master
Jim8y ef7c040
fix Assert
superboyiii a330c74
Merge pull request #5 from superboyiii/royalty-example
vikkkko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...xample.SmartContract.SampleRoyaltyNEP11Token/Example.SmartContract.SampleRoyaltyNEP11.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
8 changes: 8 additions & 0 deletions
8
...martContract.SampleRoyaltyNEP11Token/Example.SmartContract.SampleRoyaltyNEP11Token.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
</Project> |
202 changes: 202 additions & 0 deletions
202
examples/Example.SmartContract.SampleRoyaltyNEP11Token/SampleRoyaltyNEP11Token.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want, we can add
PostBuild
inTarget
like:But maybe just keep in the same formation with other examples is better? People can go to project path and just type
ncss
.There was a problem hiding this comment.
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)