-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Implement NEP-17 #2024
Implement NEP-17 #2024
Conversation
using Neo.IO;
using Neo.Ledger;
using Neo.SmartContract.Manifest;
using Neo.VM.Types;
using System;
using System.Linq;
using System.Numerics;
using Array = Neo.VM.Types.Array;
namespace Neo.SmartContract
{
partial class ApplicationEngine
{
public static readonly InteropDescriptor NEP5_EmitTransfer = Register("NEP5.EmitTransfer", nameof(NEP5EmitTransfer), 0, CallFlags.AllowModifyStates, false);
protected internal void NEP5EmitTransfer(UInt160 from, UInt160 to, BigInteger amount)
{
// Send notification
SendNotification(CurrentScriptHash, "Transfer",
new Array { from == null ? StackItem.Null : from.ToArray(), to == null ? StackItem.Null : to.ToArray(), amount });
if (to == null)
{
return;
}
// Call onPayment method if exists
ContractState contract = Snapshot.Contracts.TryGet(to);
if (contract is null)
{
return;
}
ContractMethodDescriptor md = contract.Manifest.Abi.GetMethod("onPayment");
if (md is null)
{
return;
}
ContractManifest currentManifest = Snapshot.Contracts.TryGet(CurrentScriptHash)?.Manifest;
if (currentManifest != null && !currentManifest.CanCall(contract.Manifest, md.Name))
throw new InvalidOperationException($"Cannot Call Method {md.Name} Of Contract {contract.ScriptHash} From Contract {CurrentScriptHash}");
CallContractInternal(contract, md, new Array(ReferenceCounter) { amount }, CallFlags.All, CheckReturnType.EnsureIsEmpty);
}
}
} What do you think? |
I don't think it's a good idea. We may have a lot of NEPs in the future. Maybe NEP-5 will be obsolete in the future, what shall we do then? |
@erikzhang Please take a look again, I added |
engine.SendNotification(Hash, "Transfer", | ||
new Array { from == null ? StackItem.Null : from.ToArray(), to == null ? StackItem.Null : to.ToArray(), amount }); | ||
|
||
if (!engine.ContractExists(to, "onPayment")) return; |
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.
Hi Shargon, I noticed that now neo is doing some method checks using hardcoded strings for method names ('verify', for example). I believe this may cause some issues in the future. First 'verify', now 'onPayment'. Maybe the manifest file should have a section to map these methods into ABI methods. This way, instead of checking only if the method exists, you would get the name of it first, and if it exists, execute it.
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.
instead of checking only if the method exists, you would get the name of it first, and if it exists, execute it.
Could you give me an example, i don't see the difference right now. 😕
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.
in #2044. |
Co-authored-by: Luchuan <[email protected]>
@erikzhang Merge before the proposal, or we should wait? |
We can merge it first. If the proposal changes, we can create another PR. |
* If exists * Call onPayment if to it's a smart contract * Increase cost in transfer * Remove Mint check * return * Remove extra args * Drop result * Clean code * Method.Exists * Rename * protected * Update ApplicationEngine.Contract.cs * Fix merge * Add Name in Extra * Name in manifest * Fix UT * dotnet format * Remove Method.Exists * Clean code * Move filed `Name` * Rename * Update null checks * Fix CallFromNativeContract parameters * Update AssetDescriptor.cs * Fix UT * format * Shargon's suggestion * Update src/neo/SmartContract/Native/Tokens/Nep17Token.cs Co-authored-by: Luchuan <[email protected]> * Fix Co-authored-by: Erik Zhang <[email protected]> Co-authored-by: Luchuan <[email protected]>
* If exists * Call onPayment if to it's a smart contract * Increase cost in transfer * Remove Mint check * return * Remove extra args * Drop result * Clean code * Method.Exists * Rename * protected * Update ApplicationEngine.Contract.cs * Fix merge * Add Name in Extra * Name in manifest * Fix UT * dotnet format * Remove Method.Exists * Clean code * Move filed `Name` * Rename * Update null checks * Fix CallFromNativeContract parameters * Update AssetDescriptor.cs * Fix UT * format * Shargon's suggestion * Update src/neo/SmartContract/Native/Tokens/Nep17Token.cs Co-authored-by: Luchuan <[email protected]> * Fix Co-authored-by: Erik Zhang <[email protected]> Co-authored-by: Luchuan <[email protected]>
Related to neo-project/proposals#108 (comment)
Close #2023 #2012
Require neo-project/proposals#124
Version with call flags