[#102] nns: Add DeleteDomain

Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
Alexander Chuprov 2024-08-16 16:29:26 +03:00
parent 49e5270f67
commit 66f7fc43fc
3 changed files with 30 additions and 2 deletions

View file

@ -2,7 +2,7 @@ name: "NameService"
supportedstandards: ["NEP-11"] supportedstandards: ["NEP-11"]
safemethods: ["balanceOf", "decimals", "symbol", "totalSupply", "tokensOf", "ownerOf", safemethods: ["balanceOf", "decimals", "symbol", "totalSupply", "tokensOf", "ownerOf",
"tokens", "properties", "roots", "getPrice", "isAvailable", "getRecords", "tokens", "properties", "roots", "getPrice", "isAvailable", "getRecords",
"resolve", "version"] "resolve", "version","deleteDomain"]
events: events:
- name: Transfer - name: Transfer
parameters: parameters:

View file

@ -418,11 +418,15 @@ func GetRecords(name string, typ RecordType) []string {
// DeleteRecords removes domain records with the specified type. // DeleteRecords removes domain records with the specified type.
func DeleteRecords(name string, typ RecordType) { 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 { if typ == SOA {
panic("you cannot delete soa record") panic("you cannot delete soa record")
} }
tokenID := []byte(tokenIDFromName(name)) tokenID := []byte(tokenIDFromName(name))
ctx := storage.GetContext()
ns := getNameState(ctx, tokenID) ns := getNameState(ctx, tokenID)
ns.checkAdmin() ns.checkAdmin()
recordsKey := getRecordsKeyByType(tokenID, name, typ) recordsKey := getRecordsKeyByType(tokenID, name, typ)
@ -434,6 +438,25 @@ func DeleteRecords(name string, typ RecordType) {
updateSoaSerial(ctx, tokenID) updateSoaSerial(ctx, tokenID)
} }
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). // Resolve resolves given name (not more then three redirects are allowed).
func Resolve(name string, typ RecordType) []string { func Resolve(name string, typ RecordType) []string {
ctx := storage.GetReadOnlyContext() ctx := storage.GetReadOnlyContext()

View file

@ -60,6 +60,11 @@ func New(actor Actor, hash util.Uint160) *Contract {
return &Contract{ContractReader{nep11ndt.NonDivisibleReader, actor, hash}, nep11ndt.BaseWriter, actor, hash} 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. // GetPrice invokes `getPrice` method of contract.
func (c *ContractReader) GetPrice() (*big.Int, error) { func (c *ContractReader) GetPrice() (*big.Int, error) {
return unwrap.BigInt(c.invoker.Call(c.hash, "getPrice")) return unwrap.BigInt(c.invoker.Call(c.hash, "getPrice"))