diff --git a/nns/nns_contract.go b/nns/nns_contract.go index 56dfb2c..72205f5 100644 --- a/nns/nns_contract.go +++ b/nns/nns_contract.go @@ -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. func getGlobalDomain(ctx storage.Context, domain string) string { 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) updateBalance(ctx, []byte(name), owner, +1) postTransfer(oldOwner, owner, []byte(name), nil) + createGlobalDomain(ctx, name) runtime.Notify("RegisterDomain", name) 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 { panic("you shouldn't have more than one CNAME record") }