[#125] Add soa record type

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2021-09-28 11:58:18 +03:00 committed by Alex Vanin
parent b412909f40
commit 2a4fc45c25
2 changed files with 28 additions and 6 deletions

View file

@ -62,8 +62,8 @@ const (
const ( const (
// defaultRegisterPrice is the default price for new domain registration. // defaultRegisterPrice is the default price for new domain registration.
defaultRegisterPrice = 10_0000_0000 defaultRegisterPrice = 10_0000_0000
// millisecondsInYear is amount of milliseconds per year. // millisecondsInSecond is amount of milliseconds per second.
millisecondsInYear = 365 * 24 * 3600 * 1000 millisecondsInSecond = 1000
) )
// RecordState is a type that registered entities are saved to. // RecordState is a type that registered entities are saved to.
@ -242,7 +242,7 @@ func IsAvailable(name string) bool {
} }
// Register registers new domain with the specified owner and name if it's available. // Register registers new domain with the specified owner and name if it's available.
func Register(name string, owner interop.Hash160) bool { func Register(name string, owner interop.Hash160, email string, refresh, retry, expire, ttl int) bool {
fragments := splitAndCheck(name, false) fragments := splitAndCheck(name, false)
if fragments == nil { if fragments == nil {
panic("invalid domain name format") panic("invalid domain name format")
@ -277,23 +277,24 @@ func Register(name string, owner interop.Hash160) bool {
ns := NameState{ ns := NameState{
Owner: owner, Owner: owner,
Name: name, Name: name,
Expiration: runtime.GetTime() + millisecondsInYear, Expiration: runtime.GetTime() + expire*millisecondsInSecond,
} }
putNameStateWithKey(ctx, tokenKey, ns) putNameStateWithKey(ctx, tokenKey, ns)
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)
return true return true
} }
// Renew increases domain expiration date. // Renew increases domain expiration date.
func Renew(name string) int { func Renew(name string, expire int) int {
if len(name) > maxDomainNameLength { if len(name) > maxDomainNameLength {
panic("invalid domain name format") panic("invalid domain name format")
} }
runtime.BurnGas(GetPrice()) runtime.BurnGas(GetPrice())
ctx := storage.GetContext() ctx := storage.GetContext()
ns := getNameState(ctx, []byte(name)) ns := getNameState(ctx, []byte(name))
ns.Expiration += millisecondsInYear ns.Expiration += expire * millisecondsInSecond
putNameState(ctx, ns) putNameState(ctx, ns)
return ns.Expiration return ns.Expiration
} }
@ -491,6 +492,25 @@ func putRecord(ctx storage.Context, tokenId []byte, name string, typ RecordType,
storage.Put(ctx, recordKey, recBytes) storage.Put(ctx, recordKey, recBytes)
} }
// putSoaRecord stores soa domain record.
func putSoaRecord(ctx storage.Context, name, email string, refresh, retry, expire, ttl int) {
tokenId := []byte(tokenIDFromName(name))
recordKey := getRecordKey(tokenId, name, SOA)
recordKey = append(recordKey, 0, 0, 0, 0) // emulate first 4 bytes of tx hash
rs := RecordState{
Name: name,
Type: SOA,
Data: name + " " + email + " " +
std.Itoa(runtime.GetTime(), 10) + " " +
std.Itoa(refresh, 10) + " " +
std.Itoa(retry, 10) + " " +
std.Itoa(expire, 10) + " " +
std.Itoa(ttl, 10),
}
recBytes := std.Serialize(rs)
storage.Put(ctx, recordKey, recBytes)
}
// getRecordsKey returns prefix used to store domain records of different types. // getRecordsKey returns prefix used to store domain records of different types.
func getRecordsKey(tokenId []byte, name string) []byte { func getRecordsKey(tokenId []byte, name string) []byte {
recordKey := append([]byte{prefixRecord}, getTokenKey(tokenId)...) recordKey := append([]byte{prefixRecord}, getTokenKey(tokenId)...)

View file

@ -9,6 +9,8 @@ const (
A RecordType = 1 A RecordType = 1
// CNAME represents canonical name record type. // CNAME represents canonical name record type.
CNAME RecordType = 5 CNAME RecordType = 5
// SOA represents start of a zone of authority record type.
SOA RecordType = 6
// TXT represents text record type. // TXT represents text record type.
TXT RecordType = 16 TXT RecordType = 16
) )