Skip to content

Commit fcd83e9

Browse files
committed
smartcontract: support NEP-26 and NEP-27
A replacement of NEP11Payable and NEP17Payable. The essence is the same, but these standards have official name since neo-project/proposals#169. Signed-off-by: Anna Shaleva <[email protected]>
1 parent 16a6a59 commit fcd83e9

File tree

8 files changed

+80
-51
lines changed

8 files changed

+80
-51
lines changed

pkg/compiler/compiler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,12 @@ func CreateManifest(di *DebugInfo, o *Options) (*manifest.Manifest, error) {
468468
return m, err
469469
}
470470
if m.ABI.GetMethod(manifest.MethodOnNEP11Payment, -1) != nil {
471-
if err := standard.CheckABI(m, manifest.NEP11Payable); err != nil {
471+
if err := standard.CheckABI(m, manifest.NEP26StandardName); err != nil {
472472
return m, err
473473
}
474474
}
475475
if m.ABI.GetMethod(manifest.MethodOnNEP17Payment, -1) != nil {
476-
if err := standard.CheckABI(m, manifest.NEP17Payable); err != nil {
476+
if err := standard.CheckABI(m, manifest.NEP27StandardName); err != nil {
477477
return m, err
478478
}
479479
}

pkg/smartcontract/manifest/manifest.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,31 @@ const (
2222
NEP11StandardName = "NEP-11"
2323
// NEP17StandardName represents the name of NEP-17 smartcontract standard.
2424
NEP17StandardName = "NEP-17"
25-
// NEP11Payable represents the name of contract interface which can receive NEP-11 tokens.
26-
NEP11Payable = "NEP-11-Payable"
27-
// NEP17Payable represents the name of contract interface which can receive NEP-17 tokens.
28-
NEP17Payable = "NEP-17-Payable"
2925
// NEP24StandardName represents the name of the NEP-24 smart contract standard for NFT royalties.
3026
NEP24StandardName = "NEP-24"
3127
// NEP24Payable represents the name of the contract interface for handling royalty payments in accordance
3228
// with the NEP-24 standard.
3329
NEP24Payable = "NEP-24-Payable"
30+
// NEP26StandardName represents the name of NEP-26 smartcontract standard.
31+
NEP26StandardName = "NEP-26"
32+
// NEP27StandardName represents the name of NEP-27 smartcontract standard.
33+
NEP27StandardName = "NEP-27"
3434

3535
emptyFeatures = "{}"
3636
)
3737

38+
// Aliases of Standard names.
39+
const (
40+
// NEP11Payable represents the name of NEP-26 smartcontract standard
41+
// (contract interface which can receive NEP-11 tokens).
42+
// Deprecated: to be removed in next version; use NEP26StandardName.
43+
NEP11Payable = NEP26StandardName
44+
// NEP17Payable represents the name of NEP-27 smartcontract standard
45+
// (contract interface which can receive NEP-17 tokens).
46+
// Deprecated: to be removed in next version; use NEP27StandardName.
47+
NEP17Payable = NEP27StandardName
48+
)
49+
3850
// Manifest represens contract metadata.
3951
type Manifest struct {
4052
// Name is a contract's name.

pkg/smartcontract/manifest/manifest_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ func TestExtraToStackItem(t *testing.T) {
495495

496496
func TestManifest_IsStandardSupported(t *testing.T) {
497497
m := &Manifest{
498-
SupportedStandards: []string{NEP17StandardName, NEP17Payable, NEP11Payable},
498+
SupportedStandards: []string{NEP17StandardName, NEP27StandardName, NEP26StandardName},
499499
}
500500
for _, st := range m.SupportedStandards {
501501
require.True(t, m.IsStandardSupported(st))

pkg/smartcontract/manifest/standard/comply.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ var (
2121
var checks = map[string][]*Standard{
2222
manifest.NEP11StandardName: {Nep11NonDivisible, Nep11Divisible},
2323
manifest.NEP17StandardName: {Nep17},
24-
manifest.NEP11Payable: {Nep11Payable},
25-
manifest.NEP17Payable: {Nep17Payable},
24+
manifest.NEP26StandardName: {Nep26},
25+
manifest.NEP27StandardName: {Nep27},
2626
manifest.NEP24StandardName: {Nep24},
2727
manifest.NEP24Payable: {Nep24Payable},
2828
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package standard
2+
3+
import (
4+
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
5+
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
6+
)
7+
8+
// Nep26 is a NEP-26 Standard.
9+
var Nep26 = &Standard{
10+
Manifest: manifest.Manifest{
11+
ABI: manifest.ABI{
12+
Methods: []manifest.Method{{
13+
Name: manifest.MethodOnNEP11Payment,
14+
Parameters: []manifest.Parameter{
15+
{Name: "from", Type: smartcontract.Hash160Type},
16+
{Name: "amount", Type: smartcontract.IntegerType},
17+
{Name: "tokenid", Type: smartcontract.ByteArrayType},
18+
{Name: "data", Type: smartcontract.AnyType},
19+
},
20+
ReturnType: smartcontract.VoidType,
21+
}},
22+
},
23+
},
24+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package standard
2+
3+
import (
4+
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
5+
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
6+
)
7+
8+
// Nep27 is a NEP-27 Standard.
9+
var Nep27 = &Standard{
10+
Manifest: manifest.Manifest{
11+
ABI: manifest.ABI{
12+
Methods: []manifest.Method{{
13+
Name: manifest.MethodOnNEP17Payment,
14+
Parameters: []manifest.Parameter{
15+
{Name: "from", Type: smartcontract.Hash160Type},
16+
{Name: "amount", Type: smartcontract.IntegerType},
17+
{Name: "data", Type: smartcontract.AnyType},
18+
},
19+
ReturnType: smartcontract.VoidType,
20+
}},
21+
},
22+
},
23+
}
Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,11 @@
11
package standard
22

3-
import (
4-
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
5-
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
6-
)
3+
// Nep11Payable is an alias of [Nep26].
4+
// Deprecated: Nep11Payable will be removed in next version, use designated
5+
// [Nep26] Standard instead.
6+
var Nep11Payable = Nep26
77

8-
// Nep11Payable contains NEP-11's onNEP11Payment method definition.
9-
var Nep11Payable = &Standard{
10-
Manifest: manifest.Manifest{
11-
ABI: manifest.ABI{
12-
Methods: []manifest.Method{{
13-
Name: manifest.MethodOnNEP11Payment,
14-
Parameters: []manifest.Parameter{
15-
{Name: "from", Type: smartcontract.Hash160Type},
16-
{Name: "amount", Type: smartcontract.IntegerType},
17-
{Name: "tokenid", Type: smartcontract.ByteArrayType},
18-
{Name: "data", Type: smartcontract.AnyType},
19-
},
20-
ReturnType: smartcontract.VoidType,
21-
}},
22-
},
23-
},
24-
}
25-
26-
// Nep17Payable contains NEP-17's onNEP17Payment method definition.
27-
var Nep17Payable = &Standard{
28-
Manifest: manifest.Manifest{
29-
ABI: manifest.ABI{
30-
Methods: []manifest.Method{{
31-
Name: manifest.MethodOnNEP17Payment,
32-
Parameters: []manifest.Parameter{
33-
{Name: "from", Type: smartcontract.Hash160Type},
34-
{Name: "amount", Type: smartcontract.IntegerType},
35-
{Name: "data", Type: smartcontract.AnyType},
36-
},
37-
ReturnType: smartcontract.VoidType,
38-
}},
39-
},
40-
},
41-
}
8+
// Nep17Payable is an alias of [Nep27].
9+
// Deprecated: Nep17Payable will be removed in next version, use designated
10+
// [Nep27] Standard instead.
11+
var Nep17Payable = Nep27

pkg/smartcontract/rpcbinding/binding.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,11 @@ func Generate(cfg binding.Config) error {
459459
}
460460

461461
// OnNepXXPayment handlers normally can't be called directly.
462-
if standard.ComplyABI(cfg.Manifest, standard.Nep11Payable) == nil {
463-
mfst.ABI.Methods = dropStdMethods(mfst.ABI.Methods, standard.Nep11Payable)
462+
if standard.ComplyABI(cfg.Manifest, standard.Nep26) == nil {
463+
mfst.ABI.Methods = dropStdMethods(mfst.ABI.Methods, standard.Nep26)
464464
}
465-
if standard.ComplyABI(cfg.Manifest, standard.Nep17Payable) == nil {
466-
mfst.ABI.Methods = dropStdMethods(mfst.ABI.Methods, standard.Nep17Payable)
465+
if standard.ComplyABI(cfg.Manifest, standard.Nep27) == nil {
466+
mfst.ABI.Methods = dropStdMethods(mfst.ABI.Methods, standard.Nep27)
467467
}
468468

469469
ctr.ContractTmpl = binding.TemplateFromManifest(cfg, scTypeToGo)

0 commit comments

Comments
 (0)