-
Notifications
You must be signed in to change notification settings - Fork 101
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
add example nep11 #1009
Conversation
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.
Perfect, can you verify the example https://github.com/neo-project/neo-devpack-dotnet/tree/master/examples/Example.SmartContract.NFT and maybe modify it as well?
I think there can be two examples there. Maybe give another name to each of them and move to the same folder.
Otherwise we can merge this example and do this merge later as well.
@vikkkko nice work, may you please use |
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.
Make changes and You need to write tests in order to approve this.
examples/Example.SmartContract.NEP11/Example.SmartContract.NEP11.csproj
Outdated
Show resolved
Hide resolved
Change project name to non-divisible |
…11.csproj Co-authored-by: Christopher Schuchardt <cschuchardt88@gmail.com>
Some tests will be added later. |
public static bool Update(ByteString nefFile, string manifest) | ||
{ | ||
if (IsOwner() == false) | ||
throw new InvalidOperationException("No Authorization!"); |
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.
I prefer Asserts because are not cacheable.
throw new InvalidOperationException("No Authorization!"); | ||
for (uint i = 0; i < royaltyInfos.Length; i++) | ||
{ | ||
if (((UInt160)royaltyInfos[i]["royaltyRecipient"]).IsValid == false || |
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.
check existence?
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.
check existence?
How? Maybe just a new address.
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.
Royalties are not part of the NEP-11 standard. Isn't this going to confuse people?
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.
I think we should either add a comment to the contract code that it (additionally) implements neo-project/proposals#155 or we should create one more separate example that includes Royalty standard implementation (and remove this royalty-related code from this contract).
) | ||
throw new InvalidOperationException("Parameter error"); | ||
} | ||
Storage.Put(PrefixRoyalty + tokenId, StdLib.Serialize(royaltyInfos)); |
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.
Check tokenId format
[Safe] | ||
public static bool Verify() => IsOwner(); | ||
|
||
public static bool Update(ByteString nefFile, string manifest) |
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.
Add data and send it to Update method
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.
Just a side note: The ContractManagement will use byte[]
and not string
in the manifest parameter. I can see many examples using it this way. I'm not sure why, maybe it's because of Neo Express, but I can't be sure.
{ | ||
if (IsOwner() == false) | ||
throw new InvalidOperationException("No Authorization!"); | ||
if (newOwner != null && newOwner.IsValid) |
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 (newOwner != null && newOwner.IsValid) | |
if (newOwner != null && newOwner.IsValid && !newOwner.IsZero) |
examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivisibleNEP11.cs
Outdated
Show resolved
Hide resolved
examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivisibleNEP11.cs
Outdated
Show resolved
Hide resolved
examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivisibleNEP11.cs
Outdated
Show resolved
Hide resolved
examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivisibleNEP11.cs
Outdated
Show resolved
Hide resolved
examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivisibleNEP11.cs
Outdated
Show resolved
Hide resolved
{ | ||
/// <inheritdoc /> | ||
[DisplayName("SampleNonDivisibleNEP11Token")] | ||
[ContractAuthor("core-dev", "dev@neo.org")] |
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.
The author and email can be yours.
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.
Hello,
Some extra feedback:
- This example will only work with C#. It would be helpful if there were examples that didn't use inheritance.
- The following contract can't receive payments. I would one that uses the
user data
parameter.
examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivisibleNEP11.cs
Outdated
Show resolved
Hide resolved
examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivisibleNEP11.cs
Outdated
Show resolved
Hide resolved
throw new InvalidOperationException("No Authorization!"); | ||
for (uint i = 0; i < royaltyInfos.Length; i++) | ||
{ | ||
if (((UInt160)royaltyInfos[i]["royaltyRecipient"]).IsValid == false || |
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.
Royalties are not part of the NEP-11 standard. Isn't this going to confuse people?
examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivisibleNEP11.cs
Outdated
Show resolved
Hide resolved
throw new InvalidOperationException("No Authorization!"); | ||
for (uint i = 0; i < royaltyInfos.Length; i++) | ||
{ | ||
if (((UInt160)royaltyInfos[i]["royaltyRecipient"]).IsValid == false || |
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.
I think we should either add a comment to the contract code that it (additionally) implements neo-project/proposals#155 or we should create one more separate example that includes Royalty standard implementation (and remove this royalty-related code from this contract).
examples/Example.SmartContract.NonDivisibleNEP11/SampleNonDivisibleNEP11.cs
Outdated
Show resolved
Hide resolved
Royalty example
@AnnaShaleva please check it again, the name has being updated. |
please relove conflict @vikkkko |
All done. Ready for merge. |
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
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.
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 "$(ProjectPath)"" />
</Target>
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)
examples/Example.SmartContract.SampleRoyaltyNEP11Token/SampleRoyaltyNEP11Token.cs
Outdated
Show resolved
Hide resolved
examples/Example.SmartContract.SampleRoyaltyNEP11Token/SampleRoyaltyNEP11Token.cs
Outdated
Show resolved
Hide resolved
examples/Example.SmartContract.SampleRoyaltyNEP11Token/SampleRoyaltyNEP11Token.cs
Outdated
Show resolved
Hide resolved
examples/Example.SmartContract.SampleRoyaltyNEP11Token/SampleRoyaltyNEP11Token.cs
Outdated
Show resolved
Hide resolved
examples/Example.SmartContract.SampleRoyaltyNEP11Token/SampleRoyaltyNEP11Token.cs
Show resolved
Hide resolved
examples/Example.SmartContract.SampleRoyaltyNEP11Token/SampleRoyaltyNEP11Token.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Christopher Schuchardt <cschuchardt88@gmail.com>
{ | ||
if (IsOwner() == false) | ||
throw new InvalidOperationException("No Authorization!"); | ||
if (newOwner != null && newOwner.IsValid && newOwner.IsZero == false) |
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.
It's better to use an assert, otherwise if the validation fail, the user don't get any error
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.
reason?
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 (myValueIsgood){ Action }
If your value is bad, you get the same result, the user should check the storage changes after any call?
examples/Example.SmartContract.SampleRoyaltyNEP11Token/SampleRoyaltyNEP11Token.cs
Outdated
Show resolved
Hide resolved
examples/Example.SmartContract.SampleRoyaltyNEP11Token/SampleRoyaltyNEP11Token.cs
Show resolved
Hide resolved
examples/Example.SmartContract.SampleRoyaltyNEP11Token/SampleRoyaltyNEP11Token.cs
Show resolved
Hide resolved
@shargon All done |
this is an example and unnecessarily blocked the proposal. exception or assert all make sense, not worth a debating here. Thus, i will merge. |
Yeah, this is an example and examples get copy-pasted into production code. Which means https://github.com/neo-project/neo-devpack-dotnet/pull/1009/files#r1562443533 will soon be in many C# NEP-11 implementations. And people will refer to this as the way to do things even though we know it's not the best one. |
I can't agree more, an example in the official repository is not an example, it is a template |
�I wont block your |
No description provided.