From 79ca1a4451d149bd5d2be3d713af78fb5f1dda97 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 29 Sep 2021 16:10:29 +0300 Subject: [PATCH] [#135] container: remove nice names on deletion Signed-off-by: Evgenii Stratonikov --- container/config.yml | 2 +- container/container_contract.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/container/config.yml b/container/config.yml index 812fc84..14ad5a2 100644 --- a/container/config.yml +++ b/container/config.yml @@ -2,7 +2,7 @@ name: "NeoFS Container" safemethods: ["get", "owner", "list", "eACL", "getContainerSize", "listContainerSizes", "version"] permissions: - methods: ["update", "addKey", "transferX", - "addRoot", "register", "addRecord"] + "addRoot", "register", "addRecord", "deleteRecords"] events: - name: containerPut parameters: diff --git a/container/container_contract.go b/container/container_contract.go index 6678fd6..f855fbf 100644 --- a/container/container_contract.go +++ b/container/container_contract.go @@ -48,6 +48,7 @@ const ( netmapContractKey = "netmapScriptHash" nnsContractKey = "nnsScriptHash" nnsRootKey = "nnsRoot" + nnsHasAliasKey = "nnsHasAlias" notaryDisabledKey = "notary" containerFeeKey = "ContainerFee" @@ -234,6 +235,9 @@ func PutNamed(container []byte, signature interop.Signature, } contract.Call(nnsContractAddr, "addRecord", contract.All, domain, 16 /* TXT */, std.Base58Encode(containerID)) + + key := append([]byte(nnsHasAliasKey), containerID...) + storage.Put(ctx, key, domain) } if len(token) == 0 { // if container created directly without session @@ -309,6 +313,19 @@ func Delete(containerID []byte, signature interop.Signature, token []byte) { common.RemoveVotes(ctx, id) } + key := append([]byte(nnsHasAliasKey), containerID...) + domain := storage.Get(ctx, key).(string) + if len(domain) != 0 { + storage.Delete(ctx, key) + // We should do `getRecord` first because NNS record could be deleted + // by other means (expiration, manual) thus leading to failing `deleteRecord` + // and inability to delete container. We should also check that we own the record in case. + nnsContractAddr := storage.Get(ctx, nnsContractKey).(interop.Hash160) + res := contract.Call(nnsContractAddr, "getRecords", contract.ReadStates|contract.AllowCall, domain, 16 /* TXT */) + if res != nil && std.Base58Encode(containerID) == string(res.([]interface{})[0].(string)) { + contract.Call(nnsContractAddr, "deleteRecords", contract.All, domain, 16 /* TXT */) + } + } removeContainer(ctx, containerID, ownerID) runtime.Log("delete: remove container") }