nns: check for conflicting records on domain registration
Port f25296b17a
.
This commit is contained in:
parent
db9cea5ecc
commit
d5b1c0e429
2 changed files with 21 additions and 0 deletions
|
@ -272,6 +272,17 @@ func Register(name string, owner interop.Hash160, email string, refresh, retry,
|
|||
nsBytes := storage.Get(ctx, append([]byte{prefixName}, parentKey...))
|
||||
ns := std.Deserialize(nsBytes.([]byte)).(NameState)
|
||||
ns.checkAdmin()
|
||||
|
||||
parentRecKey := append([]byte{prefixRecord}, parentKey...)
|
||||
it := storage.Find(ctx, parentRecKey, storage.ValuesOnly|storage.DeserializeValues)
|
||||
suffix := []byte(name)
|
||||
for iterator.Next(it) {
|
||||
r := iterator.Value(it).(RecordState)
|
||||
ind := std.MemorySearchLastIndex([]byte(r.Name), suffix, len(r.Name))
|
||||
if ind > 0 && ind+len(suffix) == len(r.Name) {
|
||||
panic("parent domain has conflicting records: " + r.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !isValid(owner) {
|
||||
|
|
|
@ -623,7 +623,17 @@ func TestNNSRegisterArbitraryLevelDomain(t *testing.T) {
|
|||
args = newArgs("mainnet.fs.neo.com", acc2)
|
||||
c2.InvokeFail(t, "not witnessed by admin", "register", args...)
|
||||
|
||||
c1.Invoke(t, stackitem.Null{}, "addRecord",
|
||||
"something.mainnet.fs.neo.com", int64(nns.A), "1.2.3.4")
|
||||
c1.Invoke(t, stackitem.Null{}, "addRecord",
|
||||
"another.fs.neo.com", int64(nns.A), "4.3.2.1")
|
||||
|
||||
c2 = c.WithSigners(acc, acc2)
|
||||
c2.InvokeFail(t, "parent domain has conflicting records: something.mainnet.fs.neo.com",
|
||||
"register", args...)
|
||||
|
||||
c1.Invoke(t, stackitem.Null{}, "deleteRecords",
|
||||
"something.mainnet.fs.neo.com", int64(nns.A))
|
||||
c2.Invoke(t, true, "register", args...)
|
||||
|
||||
c2 = c.WithSigners(acc2)
|
||||
|
|
Loading…
Reference in a new issue