[#114] nns: Move global alias creation to 'register'
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
parent
3e221b973a
commit
05e02373e5
1 changed files with 31 additions and 27 deletions
|
@ -258,6 +258,36 @@ func checkAvailableGlobalDomain(ctx storage.Context, domain string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// createGlobalDomain creates a global alias if GUDZ is enabled for the domain.
|
||||||
|
func createGlobalDomain(ctx storage.Context, name string) {
|
||||||
|
globalDomainKey := append([]byte{prefixGlobalDomain}, getTokenKey([]byte(name))...)
|
||||||
|
globalDomainStorage := storage.Get(ctx, globalDomainKey)
|
||||||
|
alias := getGlobalDomain(ctx, name)
|
||||||
|
|
||||||
|
if globalDomainStorage == nil {
|
||||||
|
if alias != "" {
|
||||||
|
nsOriginal := getNameState(ctx, []byte(tokenIDFromName(name)))
|
||||||
|
ns := NameState{
|
||||||
|
Name: alias,
|
||||||
|
Owner: nsOriginal.Owner,
|
||||||
|
Expiration: nsOriginal.Expiration,
|
||||||
|
Admin: nsOriginal.Admin,
|
||||||
|
}
|
||||||
|
|
||||||
|
putNameStateWithKey(ctx, getTokenKey([]byte(alias)), ns)
|
||||||
|
storage.Put(ctx, globalDomainKey, alias)
|
||||||
|
|
||||||
|
var oldOwner interop.Hash160
|
||||||
|
updateBalance(ctx, []byte(name), nsOriginal.Owner, +1)
|
||||||
|
postTransfer(oldOwner, nsOriginal.Owner, []byte(name), nil)
|
||||||
|
putCnameRecord(ctx, alias, name)
|
||||||
|
runtime.Notify("RegisterDomain", alias)
|
||||||
|
} else {
|
||||||
|
storage.Put(ctx, globalDomainKey, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// getGlobalDomain returns the global domain.
|
// getGlobalDomain returns the global domain.
|
||||||
func getGlobalDomain(ctx storage.Context, domain string) string {
|
func getGlobalDomain(ctx storage.Context, domain string) string {
|
||||||
index := std.MemorySearch([]byte(domain), []byte("."))
|
index := std.MemorySearch([]byte(domain), []byte("."))
|
||||||
|
@ -407,6 +437,7 @@ func register(ctx storage.Context, name string, owner interop.Hash160, email str
|
||||||
putSoaRecord(ctx, name, email, refresh, retry, expire, ttl)
|
putSoaRecord(ctx, name, email, refresh, retry, expire, ttl)
|
||||||
updateBalance(ctx, []byte(name), owner, +1)
|
updateBalance(ctx, []byte(name), owner, +1)
|
||||||
postTransfer(oldOwner, owner, []byte(name), nil)
|
postTransfer(oldOwner, owner, []byte(name), nil)
|
||||||
|
createGlobalDomain(ctx, name)
|
||||||
runtime.Notify("RegisterDomain", name)
|
runtime.Notify("RegisterDomain", name)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -694,33 +725,6 @@ func addRecord(ctx storage.Context, tokenId []byte, name string, typ RecordType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
globalDomainKey := append([]byte{prefixGlobalDomain}, getTokenKey([]byte(name))...)
|
|
||||||
globalDomainStorage := storage.Get(ctx, globalDomainKey)
|
|
||||||
globalDomain := getGlobalDomain(ctx, name)
|
|
||||||
|
|
||||||
if globalDomainStorage == nil && typ == TXT {
|
|
||||||
if globalDomain != "" {
|
|
||||||
checkAvailableGlobalDomain(ctx, name)
|
|
||||||
nsOriginal := getNameState(ctx, []byte(tokenIDFromName(name)))
|
|
||||||
ns := NameState{
|
|
||||||
Name: globalDomain,
|
|
||||||
Owner: nsOriginal.Owner,
|
|
||||||
Expiration: nsOriginal.Expiration,
|
|
||||||
Admin: nsOriginal.Admin,
|
|
||||||
}
|
|
||||||
|
|
||||||
putNameStateWithKey(ctx, getTokenKey([]byte(globalDomain)), ns)
|
|
||||||
storage.Put(ctx, globalDomainKey, globalDomain)
|
|
||||||
|
|
||||||
var oldOwner interop.Hash160
|
|
||||||
updateBalance(ctx, []byte(name), nsOriginal.Owner, +1)
|
|
||||||
postTransfer(oldOwner, nsOriginal.Owner, []byte(name), nil)
|
|
||||||
putCnameRecord(ctx, globalDomain, name)
|
|
||||||
} else {
|
|
||||||
storage.Put(ctx, globalDomainKey, "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if typ == CNAME && id != 0 {
|
if typ == CNAME && id != 0 {
|
||||||
panic("you shouldn't have more than one CNAME record")
|
panic("you shouldn't have more than one CNAME record")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue