From 44a848fa6a583376cb7a62363605e3a519cc1648 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 5 Feb 2021 16:18:08 +0300 Subject: [PATCH] native: call onNEP11Transfer for NEP-11 transfers See neo-project/neo#2287. --- pkg/core/native/nonfungible.go | 21 +++++++++++++++++++++ pkg/smartcontract/manifest/manifest.go | 3 +++ 2 files changed, 24 insertions(+) diff --git a/pkg/core/native/nonfungible.go b/pkg/core/native/nonfungible.go index 36826506fd..902287d92a 100644 --- a/pkg/core/native/nonfungible.go +++ b/pkg/core/native/nonfungible.go @@ -8,6 +8,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/dao" "github.com/nspcc-dev/neo-go/pkg/core/interop" + "github.com/nspcc-dev/neo-go/pkg/core/interop/contract" "github.com/nspcc-dev/neo-go/pkg/core/interop/runtime" istorage "github.com/nspcc-dev/neo-go/pkg/core/interop/storage" "github.com/nspcc-dev/neo-go/pkg/core/state" @@ -277,6 +278,26 @@ func (n *nonfungible) postTransfer(ic *interop.Context, from, to *util.Uint160, }), } ic.Notifications = append(ic.Notifications, ne) + if to == nil { + return + } + cs, err := ic.GetContract(*to) + if err != nil { + return + } + + fromArg := stackitem.Item(stackitem.Null{}) + if from != nil { + fromArg = stackitem.NewByteArray((*from).BytesBE()) + } + args := []stackitem.Item{ + fromArg, + stackitem.NewBigInteger(intOne), + stackitem.NewByteArray(tokenID), + } + if err := contract.CallFromNative(ic, n.Hash, cs, manifest.MethodOnNEP11Payment, args, false); err != nil { + panic(err) + } } func (n *nonfungible) burn(ic *interop.Context, tokenID []byte) { diff --git a/pkg/smartcontract/manifest/manifest.go b/pkg/smartcontract/manifest/manifest.go index dc9a07640f..b622ab33dc 100644 --- a/pkg/smartcontract/manifest/manifest.go +++ b/pkg/smartcontract/manifest/manifest.go @@ -24,6 +24,9 @@ const ( // MethodOnNEP17Payment is name of the method which is called when contract receives NEP-17 tokens. MethodOnNEP17Payment = "onNEP17Payment" + // MethodOnNEP11Payment is the name of the method which is called when contract receives NEP-11 tokens. + MethodOnNEP11Payment = "onNEP11Payment" + // NEP10StandardName represents the name of NEP10 smartcontract standard. NEP10StandardName = "NEP-10" // NEP17StandardName represents the name of NEP17 smartcontract standard.