From b2eb585bb6b507187cefb935c7beb251a7c80845 Mon Sep 17 00:00:00 2001 From: Alexander Chuprov Date: Fri, 16 Aug 2024 16:37:17 +0300 Subject: [PATCH] [#102] nns: Support global domain Signed-off-by: Alexander Chuprov --- nns/nns_contract.go | 26 +++++++++++++++++++++++++- rpcclient/nns/client.go | 5 +++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/nns/nns_contract.go b/nns/nns_contract.go index 2eb53c3..8ca53e2 100644 --- a/nns/nns_contract.go +++ b/nns/nns_contract.go @@ -418,11 +418,15 @@ func GetRecords(name string, typ RecordType) []string { // DeleteRecords removes domain records with the specified type. func DeleteRecords(name string, typ RecordType) { + ctx := storage.GetContext() + deleteRecords(ctx, name, typ) +} + +func deleteRecords(ctx storage.Context, name string, typ RecordType) { if typ == SOA { panic("you cannot delete soa record") } tokenID := []byte(tokenIDFromName(name)) - ctx := storage.GetContext() ns := getNameState(ctx, tokenID) ns.checkAdmin() recordsKey := getRecordsKeyByType(tokenID, name, typ) @@ -434,6 +438,26 @@ func DeleteRecords(name string, typ RecordType) { updateSoaSerial(ctx, tokenID) } +// DeleteDomain deletes the domain with the given name. +func DeleteDomain(name string) { + ctx := storage.GetContext() + deleteDomain(ctx, name) +} + +func deleteDomain(ctx storage.Context, name string) { + nameKey := append([]byte{prefixName}, getTokenKey([]byte(name))...) + tldBytes := storage.Get(ctx, nameKey) + if tldBytes == nil { + return + } + + deleteRecords(ctx, name, CNAME) + deleteRecords(ctx, name, TXT) + deleteRecords(ctx, name, A) + deleteRecords(ctx, name, AAAA) + storage.Delete(ctx, nameKey) +} + // Resolve resolves given name (not more then three redirects are allowed). func Resolve(name string, typ RecordType) []string { ctx := storage.GetReadOnlyContext() diff --git a/rpcclient/nns/client.go b/rpcclient/nns/client.go index b929222..80bf39b 100644 --- a/rpcclient/nns/client.go +++ b/rpcclient/nns/client.go @@ -60,6 +60,11 @@ func New(actor Actor, hash util.Uint160) *Contract { return &Contract{ContractReader{nep11ndt.NonDivisibleReader, actor, hash}, nep11ndt.BaseWriter, actor, hash} } +// DeleteDomain invokes `deleteDomain` method of contract. +func (c *ContractReader) DeleteDomain(name string) (*result.Invoke, error) { + c.invoker.Call(c.hash, "deleteDomain", name) +} + // GetPrice invokes `getPrice` method of contract. func (c *ContractReader) GetPrice() (*big.Int, error) { return unwrap.BigInt(c.invoker.Call(c.hash, "getPrice"))