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.
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.
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. 😕
|
in #2044. |
Co-authored-by: Luchuan <luchuan@ngd.neo.org>
|
@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 <luchuan@ngd.neo.org> * Fix Co-authored-by: Erik Zhang <erik@neo.org> Co-authored-by: Luchuan <luchuan@ngd.neo.org>
* 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 <luchuan@ngd.neo.org> * Fix Co-authored-by: Erik Zhang <erik@neo.org> Co-authored-by: Luchuan <luchuan@ngd.neo.org>
Related to neo-project/proposals#108 (comment)
Close #2023 #2012
Require neo-project/proposals#124
Version with call flags