From 6eee868b4ae2456bf41bce768d371053588c1953 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Fri, 14 May 2021 17:55:00 +0300 Subject: [PATCH] interop: remove native NNS API wrappers --- pkg/compiler/native_test.go | 35 ----- .../native/nameservice/name_service.go | 129 ------------------ 2 files changed, 164 deletions(-) delete mode 100644 pkg/interop/native/nameservice/name_service.go diff --git a/pkg/compiler/native_test.go b/pkg/compiler/native_test.go index 12e5ab6d0..554f6e232 100644 --- a/pkg/compiler/native_test.go +++ b/pkg/compiler/native_test.go @@ -9,14 +9,12 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/interop" "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames" "github.com/nspcc-dev/neo-go/pkg/core/native" - "github.com/nspcc-dev/neo-go/pkg/core/native/nnsrecords" "github.com/nspcc-dev/neo-go/pkg/core/native/noderoles" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/interop/native/crypto" "github.com/nspcc-dev/neo-go/pkg/interop/native/gas" "github.com/nspcc-dev/neo-go/pkg/interop/native/ledger" "github.com/nspcc-dev/neo-go/pkg/interop/native/management" - "github.com/nspcc-dev/neo-go/pkg/interop/native/nameservice" "github.com/nspcc-dev/neo-go/pkg/interop/native/neo" "github.com/nspcc-dev/neo-go/pkg/interop/native/notary" "github.com/nspcc-dev/neo-go/pkg/interop/native/oracle" @@ -38,7 +36,6 @@ func TestContractHashes(t *testing.T) { require.Equalf(t, []byte(oracle.Hash), cs.Oracle.Hash.BytesBE(), "%q", string(cs.Oracle.Hash.BytesBE())) require.Equalf(t, []byte(roles.Hash), cs.Designate.Hash.BytesBE(), "%q", string(cs.Designate.Hash.BytesBE())) require.Equalf(t, []byte(policy.Hash), cs.Policy.Hash.BytesBE(), "%q", string(cs.Policy.Hash.BytesBE())) - require.Equalf(t, []byte(nameservice.Hash), cs.NameService.Hash.BytesBE(), "%q", string(cs.NameService.Hash.BytesBE())) require.Equalf(t, []byte(ledger.Hash), cs.Ledger.Hash.BytesBE(), "%q", string(cs.Ledger.Hash.BytesBE())) require.Equalf(t, []byte(management.Hash), cs.Management.Hash.BytesBE(), "%q", string(cs.Management.Hash.BytesBE())) require.Equalf(t, []byte(notary.Hash), cs.Notary.Hash.BytesBE(), "%q", string(cs.Notary.Hash.BytesBE())) @@ -69,13 +66,6 @@ func TestRoleManagementRole(t *testing.T) { require.EqualValues(t, noderoles.P2PNotary, roles.P2PNotary) } -func TestNameServiceRecordType(t *testing.T) { - require.EqualValues(t, nnsrecords.A, nameservice.TypeA) - require.EqualValues(t, nnsrecords.CNAME, nameservice.TypeCNAME) - require.EqualValues(t, nnsrecords.TXT, nameservice.TypeTXT) - require.EqualValues(t, nnsrecords.AAAA, nameservice.TypeAAAA) -} - func TestCryptoLibNamedCurve(t *testing.T) { require.EqualValues(t, native.Secp256k1, crypto.Secp256k1) require.EqualValues(t, native.Secp256r1, crypto.Secp256r1) @@ -150,31 +140,6 @@ func TestNativeHelpersCompile(t *testing.T) { {"setStoragePrice", []string{"42"}}, {"unblockAccount", []string{u160}}, }) - runNativeTestCases(t, cs.NameService.ContractMD, "nameservice", []nativeTestCase{ - // nonfungible - {"symbol", nil}, - {"decimals", nil}, - {"totalSupply", nil}, - {"ownerOf", []string{`"neo.com"`}}, - {"balanceOf", []string{u160}}, - {"properties", []string{`"neo.com"`}}, - {"tokens", nil}, - {"tokensOf", []string{u160}}, - {"transfer", []string{u160, `"neo.com"`, "nil"}}, - - // name service - {"addRoot", []string{`"com"`}}, - {"deleteRecord", []string{`"neo.com"`, "nameservice.TypeA"}}, - {"isAvailable", []string{`"neo.com"`}}, - {"getPrice", nil}, - {"getRecord", []string{`"neo.com"`, "nameservice.TypeA"}}, - {"register", []string{`"neo.com"`, u160}}, - {"renew", []string{`"neo.com"`}}, - {"resolve", []string{`"neo.com"`, "nameservice.TypeA"}}, - {"setPrice", []string{"42"}}, - {"setAdmin", []string{`"neo.com"`, u160}}, - {"setRecord", []string{`"neo.com"`, "nameservice.TypeA", `"1.1.1.1"`}}, - }) runNativeTestCases(t, cs.Ledger.ContractMD, "ledger", []nativeTestCase{ {"currentHash", nil}, {"currentIndex", nil}, diff --git a/pkg/interop/native/nameservice/name_service.go b/pkg/interop/native/nameservice/name_service.go deleted file mode 100644 index c2e568a60..000000000 --- a/pkg/interop/native/nameservice/name_service.go +++ /dev/null @@ -1,129 +0,0 @@ -/* -Package nameservice provides interface to NameService native contract. -It's a NEP-11 contract implementing a domain name service. -*/ -package nameservice - -import ( - "github.com/nspcc-dev/neo-go/pkg/interop" - "github.com/nspcc-dev/neo-go/pkg/interop/contract" - "github.com/nspcc-dev/neo-go/pkg/interop/iterator" -) - -// RecordType represents NameService record type. -type RecordType byte - -// Various record type. -const ( - TypeA RecordType = 1 - TypeCNAME RecordType = 5 - TypeTXT RecordType = 16 - TypeAAAA RecordType = 28 -) - -// Hash represents NameService contract hash. -const Hash = "\x6b\x59\x2b\x87\x66\xcc\x45\x8e\xfa\x7a\x90\x47\x56\x62\xcd\x92\x03\xcf\x8f\x7a" - -// Symbol represents `symbol` method of NameService native contract. -func Symbol() string { - return contract.Call(interop.Hash160(Hash), "symbol", contract.NoneFlag).(string) -} - -// Decimals represents `decimals` method of NameService native contract. -func Decimals() int { - return contract.Call(interop.Hash160(Hash), "decimals", contract.NoneFlag).(int) -} - -// TotalSupply represents `totalSupply` method of NameService native contract. -func TotalSupply() int { - return contract.Call(interop.Hash160(Hash), "totalSupply", contract.ReadStates).(int) -} - -// OwnerOf represents `ownerOf` method of NameService native contract. -func OwnerOf(tokenID string) interop.Hash160 { - return contract.Call(interop.Hash160(Hash), "ownerOf", contract.ReadStates, tokenID).(interop.Hash160) -} - -// BalanceOf represents `balanceOf` method of NameService native contract. -func BalanceOf(owner interop.Hash160) int { - return contract.Call(interop.Hash160(Hash), "balanceOf", contract.ReadStates, owner).(int) -} - -// Properties represents `properties` method of NameService native contract. -func Properties(tokenID string) map[string]interface{} { - return contract.Call(interop.Hash160(Hash), "properties", contract.ReadStates, tokenID).(map[string]interface{}) -} - -// Tokens represents `tokens` method of NameService native contract. -func Tokens() iterator.Iterator { - return contract.Call(interop.Hash160(Hash), "tokens", - contract.ReadStates).(iterator.Iterator) -} - -// TokensOf represents `tokensOf` method of NameService native contract. -func TokensOf(addr interop.Hash160) iterator.Iterator { - return contract.Call(interop.Hash160(Hash), "tokensOf", - contract.ReadStates, addr).(iterator.Iterator) -} - -// Transfer represents `transfer` method of NameService native contract. -func Transfer(to interop.Hash160, tokenID string, data interface{}) bool { - return contract.Call(interop.Hash160(Hash), "transfer", - contract.ReadStates|contract.States|contract.AllowNotify, to, tokenID, data).(bool) -} - -// AddRoot represents `addRoot` method of NameService native contract. -func AddRoot(root string) { - contract.Call(interop.Hash160(Hash), "addRoot", contract.States, root) -} - -// SetPrice represents `setPrice` method of NameService native contract. -func SetPrice(price int) { - contract.Call(interop.Hash160(Hash), "setPrice", contract.States, price) -} - -// GetPrice represents `getPrice` method of NameService native contract. -func GetPrice() int { - return contract.Call(interop.Hash160(Hash), "getPrice", contract.ReadStates).(int) -} - -// IsAvailable represents `isAvailable` method of NameService native contract. -func IsAvailable(name string) bool { - return contract.Call(interop.Hash160(Hash), "isAvailable", contract.ReadStates, name).(bool) -} - -// Register represents `register` method of NameService native contract. -func Register(name string, owner interop.Hash160) bool { - return contract.Call(interop.Hash160(Hash), "register", contract.States, name, owner).(bool) -} - -// Renew represents `renew` method of NameService native contract. -func Renew(name string) int { - return contract.Call(interop.Hash160(Hash), "renew", contract.States, name).(int) -} - -// SetAdmin represents `setAdmin` method of NameService native contract. -func SetAdmin(name string, admin interop.Hash160) { - contract.Call(interop.Hash160(Hash), "setAdmin", contract.States, name, admin) -} - -// SetRecord represents `setRecord` method of NameService native contract. -func SetRecord(name string, recType RecordType, data string) { - contract.Call(interop.Hash160(Hash), "setRecord", contract.States, name, recType, data) -} - -// GetRecord represents `getRecord` method of NameService native contract. -// It returns `nil` if record is missing. -func GetRecord(name string, recType RecordType) []byte { - return contract.Call(interop.Hash160(Hash), "getRecord", contract.ReadStates, name, recType).([]byte) -} - -// DeleteRecord represents `deleteRecord` method of NameService native contract. -func DeleteRecord(name string, recType RecordType) { - contract.Call(interop.Hash160(Hash), "deleteRecord", contract.States, name, recType) -} - -// Resolve represents `resolve` method of NameService native contract. -func Resolve(name string, recType RecordType) []byte { - return contract.Call(interop.Hash160(Hash), "resolve", contract.ReadStates, name, recType).([]byte) -}