@@ -224,7 +224,7 @@ func GetPrice() int {
224
224
225
225
// IsAvailable checks whether the provided domain name is available.
226
226
func IsAvailable (name string ) bool {
227
- fragments := splitAndCheck (name , false )
227
+ fragments := splitAndCheck (name , true )
228
228
if fragments == nil {
229
229
panic ("invalid domain name format" )
230
230
}
@@ -236,7 +236,25 @@ func IsAvailable(name string) bool {
236
236
}
237
237
return true
238
238
}
239
- return parentExpired (ctx , 0 , fragments )
239
+ if ! parentExpired (ctx , 0 , fragments ) {
240
+ return false
241
+ }
242
+ return len (getParentConflictingRecord (ctx , name , fragments )) == 0
243
+ }
244
+
245
+ func getParentConflictingRecord (ctx storage.Context , name string , fragments []string ) string {
246
+ parentKey := getTokenKey ([]byte (name [len (fragments [0 ])+ 1 :]))
247
+ parentRecKey := append ([]byte {prefixRecord }, parentKey ... )
248
+ it := storage .Find (ctx , parentRecKey , storage .ValuesOnly | storage .DeserializeValues )
249
+ suffix := []byte (name )
250
+ for iterator .Next (it ) {
251
+ r := iterator .Value (it ).(RecordState )
252
+ ind := std .MemorySearchLastIndex ([]byte (r .Name ), suffix , len (r .Name ))
253
+ if ind > 0 && ind + len (suffix ) == len (r .Name ) {
254
+ return r .Name
255
+ }
256
+ }
257
+ return ""
240
258
}
241
259
242
260
// parentExpired returns true if any domain from fragments doesn't exist or is expired.
@@ -290,15 +308,8 @@ func Register(name string, owner interop.Hash160, email string, refresh, retry,
290
308
ns := std .Deserialize (nsBytes .([]byte )).(NameState )
291
309
ns .checkAdmin ()
292
310
293
- parentRecKey := append ([]byte {prefixRecord }, parentKey ... )
294
- it := storage .Find (ctx , parentRecKey , storage .ValuesOnly | storage .DeserializeValues )
295
- suffix := []byte (name )
296
- for iterator .Next (it ) {
297
- r := iterator .Value (it ).(RecordState )
298
- ind := std .MemorySearchLastIndex ([]byte (r .Name ), suffix , len (r .Name ))
299
- if ind > 0 && ind + len (suffix ) == len (r .Name ) {
300
- panic ("parent domain has conflicting records: " + r .Name )
301
- }
311
+ if conflict := getParentConflictingRecord (ctx , name , fragments ); len (conflict ) != 0 {
312
+ panic ("parent domain has conflicting records: " + conflict )
302
313
}
303
314
}
304
315
0 commit comments