native: call onNEP11Transfer for NEP-11 transfers
See neo-project/neo#2287.
This commit is contained in:
parent
a442e1530d
commit
cd9b34416e
4 changed files with 53 additions and 2 deletions
|
@ -340,13 +340,20 @@ func getTestContractState(bc *Blockchain) (*state.Contract, *state.Contract) {
|
|||
emit.Syscall(w.BinWriter, interopnames.SystemStorageGetContext)
|
||||
emit.Syscall(w.BinWriter, interopnames.SystemStorageGet)
|
||||
emit.Opcodes(w.BinWriter, opcode.RET)
|
||||
onPaymentOff := w.Len()
|
||||
onNEP17PaymentOff := w.Len()
|
||||
emit.Syscall(w.BinWriter, interopnames.SystemRuntimeGetCallingScriptHash)
|
||||
emit.Int(w.BinWriter, 4)
|
||||
emit.Opcodes(w.BinWriter, opcode.PACK)
|
||||
emit.String(w.BinWriter, "LastPayment")
|
||||
emit.Syscall(w.BinWriter, interopnames.SystemRuntimeNotify)
|
||||
emit.Opcodes(w.BinWriter, opcode.RET)
|
||||
onNEP11PaymentOff := w.Len()
|
||||
emit.Syscall(w.BinWriter, interopnames.SystemRuntimeGetCallingScriptHash)
|
||||
emit.Int(w.BinWriter, 4)
|
||||
emit.Opcodes(w.BinWriter, opcode.PACK)
|
||||
emit.String(w.BinWriter, "LostPayment")
|
||||
emit.Syscall(w.BinWriter, interopnames.SystemRuntimeNotify)
|
||||
emit.Opcodes(w.BinWriter, opcode.RET)
|
||||
update3Off := w.Len()
|
||||
emit.Int(w.BinWriter, 3)
|
||||
emit.Opcodes(w.BinWriter, opcode.JMP, 2+1)
|
||||
|
@ -455,9 +462,19 @@ func getTestContractState(bc *Blockchain) (*state.Contract, *state.Contract) {
|
|||
},
|
||||
ReturnType: smartcontract.VoidType,
|
||||
},
|
||||
{
|
||||
Name: manifest.MethodOnNEP11Payment,
|
||||
Offset: onNEP11PaymentOff,
|
||||
Parameters: []manifest.Parameter{
|
||||
manifest.NewParameter("from", smartcontract.Hash160Type),
|
||||
manifest.NewParameter("amount", smartcontract.IntegerType),
|
||||
manifest.NewParameter("tokenid", smartcontract.ByteArrayType),
|
||||
},
|
||||
ReturnType: smartcontract.VoidType,
|
||||
},
|
||||
{
|
||||
Name: manifest.MethodOnNEP17Payment,
|
||||
Offset: onPaymentOff,
|
||||
Offset: onNEP17PaymentOff,
|
||||
Parameters: []manifest.Parameter{
|
||||
manifest.NewParameter("from", smartcontract.Hash160Type),
|
||||
manifest.NewParameter("amount", smartcontract.IntegerType),
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -287,6 +287,16 @@ func TestTransfer(t *testing.T) {
|
|||
testNameServiceInvokeAux(t, bc, defaultNameServiceSysfee, from, "totalSupply", 1)
|
||||
testNameServiceInvokeAux(t, bc, defaultNameServiceSysfee, from, "ownerOf",
|
||||
to.Contract.ScriptHash().BytesBE(), []byte("neo.com"))
|
||||
cs, cs2 := getTestContractState(bc) // cs2 doesn't have OnNEP11Transfer
|
||||
require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs))
|
||||
require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs2))
|
||||
testNameServiceInvokeAux(t, bc, defaultRegisterSysfee, to, "transfer",
|
||||
nil, cs2.Hash.BytesBE(), []byte("neo.com"))
|
||||
testNameServiceInvokeAux(t, bc, defaultRegisterSysfee, to, "transfer",
|
||||
true, cs.Hash.BytesBE(), []byte("neo.com"))
|
||||
testNameServiceInvokeAux(t, bc, defaultNameServiceSysfee, from, "totalSupply", 1)
|
||||
testNameServiceInvokeAux(t, bc, defaultNameServiceSysfee, from, "ownerOf",
|
||||
cs.Hash.BytesBE(), []byte("neo.com"))
|
||||
}
|
||||
|
||||
func TestTokensOf(t *testing.T) {
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue