standard: export standard definitions

Make Comply* functions useful and expose standard definitions for some reuse.
This commit is contained in:
Roman Khimov 2022-10-26 21:23:12 +03:00
parent 396f56f792
commit 64b603b056
6 changed files with 25 additions and 18 deletions

View file

@ -19,10 +19,10 @@ var (
) )
var checks = map[string][]*Standard{ var checks = map[string][]*Standard{
manifest.NEP11StandardName: {nep11NonDivisible, nep11Divisible}, manifest.NEP11StandardName: {Nep11NonDivisible, Nep11Divisible},
manifest.NEP17StandardName: {nep17}, manifest.NEP17StandardName: {Nep17},
manifest.NEP11Payable: {nep11payable}, manifest.NEP11Payable: {Nep11Payable},
manifest.NEP17Payable: {nep17payable}, manifest.NEP17Payable: {Nep17Payable},
} }
// Check checks if the manifest complies with all provided standards. // Check checks if the manifest complies with all provided standards.

View file

@ -135,9 +135,9 @@ func TestCheck(t *testing.T) {
m := manifest.NewManifest("Test") m := manifest.NewManifest("Test")
require.Error(t, Check(m, manifest.NEP17StandardName)) require.Error(t, Check(m, manifest.NEP17StandardName))
m.ABI.Methods = append(m.ABI.Methods, decimalTokenBase.ABI.Methods...) m.ABI.Methods = append(m.ABI.Methods, DecimalTokenBase.ABI.Methods...)
m.ABI.Methods = append(m.ABI.Methods, nep17.ABI.Methods...) m.ABI.Methods = append(m.ABI.Methods, Nep17.ABI.Methods...)
m.ABI.Events = append(m.ABI.Events, nep17.ABI.Events...) m.ABI.Events = append(m.ABI.Events, Nep17.ABI.Events...)
require.NoError(t, Check(m, manifest.NEP17StandardName)) require.NoError(t, Check(m, manifest.NEP17StandardName))
require.NoError(t, CheckABI(m, manifest.NEP17StandardName)) require.NoError(t, CheckABI(m, manifest.NEP17StandardName))
} }

View file

@ -5,8 +5,9 @@ import (
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
) )
var nep11Base = &Standard{ // Nep11Base is a Standard containing common NEP-11 methods.
Base: decimalTokenBase, var Nep11Base = &Standard{
Base: DecimalTokenBase,
Manifest: manifest.Manifest{ Manifest: manifest.Manifest{
ABI: manifest.ABI{ ABI: manifest.ABI{
Methods: []manifest.Method{ Methods: []manifest.Method{
@ -66,8 +67,9 @@ var nep11Base = &Standard{
}, },
} }
var nep11NonDivisible = &Standard{ // Nep11NonDivisible is a NEP-11 non-divisible Standard.
Base: nep11Base, var Nep11NonDivisible = &Standard{
Base: Nep11Base,
Manifest: manifest.Manifest{ Manifest: manifest.Manifest{
ABI: manifest.ABI{ ABI: manifest.ABI{
Methods: []manifest.Method{ Methods: []manifest.Method{
@ -84,8 +86,9 @@ var nep11NonDivisible = &Standard{
}, },
} }
var nep11Divisible = &Standard{ // Nep11Divisible is a NEP-11 divisible Standard.
Base: nep11Base, var Nep11Divisible = &Standard{
Base: Nep11Base,
Manifest: manifest.Manifest{ Manifest: manifest.Manifest{
ABI: manifest.ABI{ ABI: manifest.ABI{
Methods: []manifest.Method{ Methods: []manifest.Method{

View file

@ -5,8 +5,9 @@ import (
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
) )
var nep17 = &Standard{ // Nep17 is a NEP-17 Standard.
Base: decimalTokenBase, var Nep17 = &Standard{
Base: DecimalTokenBase,
Manifest: manifest.Manifest{ Manifest: manifest.Manifest{
ABI: manifest.ABI{ ABI: manifest.ABI{
Methods: []manifest.Method{ Methods: []manifest.Method{

View file

@ -5,7 +5,8 @@ import (
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
) )
var nep11payable = &Standard{ // Nep11Payable contains NEP-11's onNEP11Payment method definition.
var Nep11Payable = &Standard{
Manifest: manifest.Manifest{ Manifest: manifest.Manifest{
ABI: manifest.ABI{ ABI: manifest.ABI{
Methods: []manifest.Method{{ Methods: []manifest.Method{{
@ -22,7 +23,8 @@ var nep11payable = &Standard{
}, },
} }
var nep17payable = &Standard{ // Nep17Payable contains NEP-17's onNEP17Payment method definition.
var Nep17Payable = &Standard{
Manifest: manifest.Manifest{ Manifest: manifest.Manifest{
ABI: manifest.ABI{ ABI: manifest.ABI{
Methods: []manifest.Method{{ Methods: []manifest.Method{{

View file

@ -5,7 +5,8 @@ import (
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
) )
var decimalTokenBase = &Standard{ // DecimalTokenBase contains methods common to NEP-11 and NEP-17 token standards.
var DecimalTokenBase = &Standard{
Manifest: manifest.Manifest{ Manifest: manifest.Manifest{
ABI: manifest.ABI{ ABI: manifest.ABI{
Methods: []manifest.Method{ Methods: []manifest.Method{