From 64b603b05618787971bedd0e15b6fbeeb7a4a607 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 26 Oct 2022 21:23:12 +0300 Subject: [PATCH] standard: export standard definitions Make Comply* functions useful and expose standard definitions for some reuse. --- pkg/smartcontract/manifest/standard/comply.go | 8 ++++---- .../manifest/standard/comply_test.go | 6 +++--- pkg/smartcontract/manifest/standard/nep11.go | 15 +++++++++------ pkg/smartcontract/manifest/standard/nep17.go | 5 +++-- pkg/smartcontract/manifest/standard/payable.go | 6 ++++-- pkg/smartcontract/manifest/standard/token.go | 3 ++- 6 files changed, 25 insertions(+), 18 deletions(-) diff --git a/pkg/smartcontract/manifest/standard/comply.go b/pkg/smartcontract/manifest/standard/comply.go index ab7a3a2bd..edf3634b1 100644 --- a/pkg/smartcontract/manifest/standard/comply.go +++ b/pkg/smartcontract/manifest/standard/comply.go @@ -19,10 +19,10 @@ var ( ) var checks = map[string][]*Standard{ - manifest.NEP11StandardName: {nep11NonDivisible, nep11Divisible}, - manifest.NEP17StandardName: {nep17}, - manifest.NEP11Payable: {nep11payable}, - manifest.NEP17Payable: {nep17payable}, + manifest.NEP11StandardName: {Nep11NonDivisible, Nep11Divisible}, + manifest.NEP17StandardName: {Nep17}, + manifest.NEP11Payable: {Nep11Payable}, + manifest.NEP17Payable: {Nep17Payable}, } // Check checks if the manifest complies with all provided standards. diff --git a/pkg/smartcontract/manifest/standard/comply_test.go b/pkg/smartcontract/manifest/standard/comply_test.go index 0d218c536..360a7c1de 100644 --- a/pkg/smartcontract/manifest/standard/comply_test.go +++ b/pkg/smartcontract/manifest/standard/comply_test.go @@ -135,9 +135,9 @@ func TestCheck(t *testing.T) { m := manifest.NewManifest("Test") require.Error(t, Check(m, manifest.NEP17StandardName)) - m.ABI.Methods = append(m.ABI.Methods, decimalTokenBase.ABI.Methods...) - m.ABI.Methods = append(m.ABI.Methods, nep17.ABI.Methods...) - m.ABI.Events = append(m.ABI.Events, nep17.ABI.Events...) + m.ABI.Methods = append(m.ABI.Methods, DecimalTokenBase.ABI.Methods...) + m.ABI.Methods = append(m.ABI.Methods, Nep17.ABI.Methods...) + m.ABI.Events = append(m.ABI.Events, Nep17.ABI.Events...) require.NoError(t, Check(m, manifest.NEP17StandardName)) require.NoError(t, CheckABI(m, manifest.NEP17StandardName)) } diff --git a/pkg/smartcontract/manifest/standard/nep11.go b/pkg/smartcontract/manifest/standard/nep11.go index 3d896a0ff..7f94173fa 100644 --- a/pkg/smartcontract/manifest/standard/nep11.go +++ b/pkg/smartcontract/manifest/standard/nep11.go @@ -5,8 +5,9 @@ import ( "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" ) -var nep11Base = &Standard{ - Base: decimalTokenBase, +// Nep11Base is a Standard containing common NEP-11 methods. +var Nep11Base = &Standard{ + Base: DecimalTokenBase, Manifest: manifest.Manifest{ ABI: manifest.ABI{ Methods: []manifest.Method{ @@ -66,8 +67,9 @@ var nep11Base = &Standard{ }, } -var nep11NonDivisible = &Standard{ - Base: nep11Base, +// Nep11NonDivisible is a NEP-11 non-divisible Standard. +var Nep11NonDivisible = &Standard{ + Base: Nep11Base, Manifest: manifest.Manifest{ ABI: manifest.ABI{ Methods: []manifest.Method{ @@ -84,8 +86,9 @@ var nep11NonDivisible = &Standard{ }, } -var nep11Divisible = &Standard{ - Base: nep11Base, +// Nep11Divisible is a NEP-11 divisible Standard. +var Nep11Divisible = &Standard{ + Base: Nep11Base, Manifest: manifest.Manifest{ ABI: manifest.ABI{ Methods: []manifest.Method{ diff --git a/pkg/smartcontract/manifest/standard/nep17.go b/pkg/smartcontract/manifest/standard/nep17.go index 4e08c4120..4d4422aab 100644 --- a/pkg/smartcontract/manifest/standard/nep17.go +++ b/pkg/smartcontract/manifest/standard/nep17.go @@ -5,8 +5,9 @@ import ( "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" ) -var nep17 = &Standard{ - Base: decimalTokenBase, +// Nep17 is a NEP-17 Standard. +var Nep17 = &Standard{ + Base: DecimalTokenBase, Manifest: manifest.Manifest{ ABI: manifest.ABI{ Methods: []manifest.Method{ diff --git a/pkg/smartcontract/manifest/standard/payable.go b/pkg/smartcontract/manifest/standard/payable.go index 9cb4f39c6..d0e3de6fa 100644 --- a/pkg/smartcontract/manifest/standard/payable.go +++ b/pkg/smartcontract/manifest/standard/payable.go @@ -5,7 +5,8 @@ import ( "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{ ABI: manifest.ABI{ 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{ ABI: manifest.ABI{ Methods: []manifest.Method{{ diff --git a/pkg/smartcontract/manifest/standard/token.go b/pkg/smartcontract/manifest/standard/token.go index 877050131..2600fb1d7 100644 --- a/pkg/smartcontract/manifest/standard/token.go +++ b/pkg/smartcontract/manifest/standard/token.go @@ -5,7 +5,8 @@ import ( "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{ ABI: manifest.ABI{ Methods: []manifest.Method{