forked from nspcc-dev/neo-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnns.go
727 lines (670 loc) · 19.8 KB
/
nns.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
/*
Package nns contains non-divisible non-fungible NEP-11-compatible token
implementation. This token is a compatible analogue of C# Neo Name Service
token and is aimed to serve as a domain name service for Neo smart-contracts,
thus it's NeoNameService. This token can be minted with new domain name
registration, the domain name itself is your NFT. Corresponding domain root
must be added by the committee before new domain name can be registered.
*/
package nns
import (
"github.com/nspcc-dev/neo-go/pkg/interop"
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
"github.com/nspcc-dev/neo-go/pkg/interop/iterator"
"github.com/nspcc-dev/neo-go/pkg/interop/native/crypto"
"github.com/nspcc-dev/neo-go/pkg/interop/native/management"
"github.com/nspcc-dev/neo-go/pkg/interop/native/neo"
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
)
// Prefixes used for contract data storage.
const (
// prefixTotalSupply contains total supply of minted domains.
prefixTotalSupply byte = 0x00
// prefixBalance contains map from owner to his balance.
prefixBalance byte = 0x01
// prefixAccountToken contains map from (owner + token key) to token ID,
// where token key = hash160(token ID) and token ID = domain name.
prefixAccountToken byte = 0x02
// prefixRegisterPrice contains price for new domain name registration.
prefixRegisterPrice byte = 0x10
// prefixRoot contains set of roots (map from root to 0).
prefixRoot byte = 0x20
// prefixName contains map from token key to token where token is domain
// NameState structure.
prefixName byte = 0x21
// prefixRecord contains map from (token key + hash160(token name) + record type)
// to record.
prefixRecord byte = 0x22
)
// Values constraints.
const (
// maxRegisterPrice is the maximum price of register method.
maxRegisterPrice = 1_0000_0000_0000
// maxRootLength is the maximum domain root length.
maxRootLength = 16
// maxDomainNameFragmentLength is the maximum length of the domain name fragment.
maxDomainNameFragmentLength = 63
// minDomainNameLength is minimum domain length.
minDomainNameLength = 3
// maxDomainNameLength is maximum domain length.
maxDomainNameLength = 255
// maxTXTRecordLength is the maximum length of the TXT domain record.
maxTXTRecordLength = 255
)
// Other constants.
const (
// defaultRegisterPrice is the default price for new domain registration.
defaultRegisterPrice = 10_0000_0000
// millisecondsInYear is amount of milliseconds per year.
millisecondsInYear = 365 * 24 * 3600 * 1000
)
// RecordState is a type that registered entities are saved to.
type RecordState struct {
Name string
Type RecordType
Data string
}
// Update updates NameService contract.
func Update(nef []byte, manifest string) {
checkCommittee()
management.Update(nef, []byte(manifest))
}
// _deploy initializes defaults (total supply and registration price) on contract deploy.
func _deploy(data any, isUpdate bool) {
if isUpdate {
return
}
ctx := storage.GetContext()
storage.Put(ctx, []byte{prefixTotalSupply}, 0)
storage.Put(ctx, []byte{prefixRegisterPrice}, defaultRegisterPrice)
}
// Symbol returns NeoNameService symbol.
func Symbol() string {
return "NNS"
}
// Decimals returns NeoNameService decimals.
func Decimals() int {
return 0
}
// TotalSupply returns overall number of domains minted by the NeoNameService contract.
func TotalSupply() int {
ctx := storage.GetReadOnlyContext()
return getTotalSupply(ctx)
}
// OwnerOf returns owner of the specified domain.
func OwnerOf(tokenID []byte) interop.Hash160 {
ctx := storage.GetReadOnlyContext()
ns := getNameState(ctx, tokenID)
return ns.Owner
}
// Properties returns domain name and expiration date of the specified domain.
func Properties(tokenID []byte) map[string]any {
ctx := storage.GetReadOnlyContext()
ns := getNameState(ctx, tokenID)
return map[string]any{
"name": ns.Name,
"expiration": ns.Expiration,
"admin": ns.Admin,
}
}
// BalanceOf returns overall number of domains owned by the specified owner.
func BalanceOf(owner interop.Hash160) int {
if !isValid(owner) {
panic(`invalid owner`)
}
ctx := storage.GetReadOnlyContext()
balance := storage.Get(ctx, append([]byte{prefixBalance}, owner...))
if balance == nil {
return 0
}
return balance.(int)
}
// Tokens returns iterator over a set of all registered domain names.
func Tokens() iterator.Iterator {
ctx := storage.GetReadOnlyContext()
return storage.Find(ctx, []byte{prefixName}, storage.ValuesOnly|storage.DeserializeValues|storage.PickField1)
}
// TokensOf returns iterator over minted domains owned by the specified owner.
func TokensOf(owner interop.Hash160) iterator.Iterator {
if !isValid(owner) {
panic(`invalid owner`)
}
ctx := storage.GetReadOnlyContext()
return storage.Find(ctx, append([]byte{prefixAccountToken}, owner...), storage.ValuesOnly)
}
// Transfer transfers domain with the specified name to new owner.
func Transfer(to interop.Hash160, tokenID []byte, data any) bool {
if !isValid(to) {
panic(`invalid receiver`)
}
var (
tokenKey = getTokenKey(tokenID)
ctx = storage.GetContext()
)
ns := getNameStateWithKey(ctx, tokenKey)
from := ns.Owner
if !runtime.CheckWitness(from) {
return false
}
if !from.Equals(to) {
// update token info
ns.Owner = to
ns.Admin = nil
putNameStateWithKey(ctx, tokenKey, ns)
// update `from` balance
updateBalance(ctx, tokenID, from, -1)
// update `to` balance
updateBalance(ctx, tokenID, to, +1)
}
postTransfer(from, to, tokenID, data)
return true
}
// AddRoot registers new root.
func AddRoot(root string) {
checkCommittee()
if !checkFragment(root, true) {
panic("invalid root format")
}
var (
ctx = storage.GetContext()
rootKey = append([]byte{prefixRoot}, []byte(root)...)
)
if storage.Get(ctx, rootKey) != nil {
panic("root already exists")
}
storage.Put(ctx, rootKey, 0)
}
// Roots returns iterator over a set of NameService roots.
func Roots() iterator.Iterator {
ctx := storage.GetReadOnlyContext()
return storage.Find(ctx, []byte{prefixRoot}, storage.KeysOnly|storage.RemovePrefix)
}
// SetPrice sets the domain registration price.
func SetPrice(price int) {
checkCommittee()
if price < 0 || price > maxRegisterPrice {
panic("The price is out of range.")
}
ctx := storage.GetContext()
storage.Put(ctx, []byte{prefixRegisterPrice}, price)
}
// GetPrice returns the domain registration price.
func GetPrice() int {
ctx := storage.GetReadOnlyContext()
return storage.Get(ctx, []byte{prefixRegisterPrice}).(int)
}
// IsAvailable checks whether provided domain name is available.
func IsAvailable(name string) bool {
fragments := splitAndCheck(name, false)
if fragments == nil {
panic("invalid domain name format")
}
ctx := storage.GetReadOnlyContext()
if storage.Get(ctx, append([]byte{prefixRoot}, []byte(fragments[1])...)) == nil {
panic("root not found")
}
nsBytes := storage.Get(ctx, append([]byte{prefixName}, getTokenKey([]byte(name))...))
if nsBytes == nil {
return true
}
ns := std.Deserialize(nsBytes.([]byte)).(NameState)
return runtime.GetTime() >= ns.Expiration
}
// Register registers new domain with the specified owner and name if it's available.
func Register(name string, owner interop.Hash160) bool {
fragments := splitAndCheck(name, false)
if fragments == nil {
panic("invalid domain name format")
}
ctx := storage.GetContext()
if storage.Get(ctx, append([]byte{prefixRoot}, []byte(fragments[1])...)) == nil {
panic("root not found")
}
if !isValid(owner) {
panic("invalid owner")
}
if !runtime.CheckWitness(owner) {
panic("not witnessed by owner")
}
runtime.BurnGas(GetPrice())
var (
tokenKey = getTokenKey([]byte(name))
oldOwner interop.Hash160
)
nsBytes := storage.Get(ctx, append([]byte{prefixName}, tokenKey...))
if nsBytes != nil {
ns := std.Deserialize(nsBytes.([]byte)).(NameState)
if runtime.GetTime() < ns.Expiration {
return false
}
oldOwner = ns.Owner
updateBalance(ctx, []byte(name), oldOwner, -1)
it := storage.Find(ctx, append([]byte{prefixRecord}, tokenKey...), storage.KeysOnly)
for iterator.Next(it) {
storage.Delete(ctx, iterator.Value(it))
}
} else {
updateTotalSupply(ctx, +1)
}
ns := NameState{
Owner: owner,
Name: name,
Expiration: runtime.GetTime() + millisecondsInYear,
}
putNameStateWithKey(ctx, tokenKey, ns)
updateBalance(ctx, []byte(name), owner, +1)
postTransfer(oldOwner, owner, []byte(name), nil)
return true
}
// Renew increases domain expiration date.
func Renew(name string) int {
if len(name) > maxDomainNameLength {
panic("invalid domain name format")
}
runtime.BurnGas(GetPrice())
ctx := storage.GetContext()
ns := getNameState(ctx, []byte(name))
ns.Expiration += millisecondsInYear
putNameState(ctx, ns)
return ns.Expiration
}
// SetAdmin updates domain admin.
func SetAdmin(name string, admin interop.Hash160) {
if len(name) > maxDomainNameLength {
panic("invalid domain name format")
}
if admin != nil && !runtime.CheckWitness(admin) {
panic("not witnessed by admin")
}
ctx := storage.GetContext()
ns := getNameState(ctx, []byte(name))
if !runtime.CheckWitness(ns.Owner) {
panic("not witnessed by owner")
}
ns.Admin = admin
putNameState(ctx, ns)
}
// SetRecord adds new record of the specified type to the provided domain.
func SetRecord(name string, typ RecordType, data string) {
tokenID := []byte(tokenIDFromName(name))
var ok bool
switch typ {
case A:
ok = checkIPv4(data)
case CNAME:
ok = splitAndCheck(data, true) != nil
case TXT:
ok = len(data) <= maxTXTRecordLength
case AAAA:
ok = checkIPv6(data)
default:
panic("unsupported record type")
}
if !ok {
panic("invalid record data")
}
ctx := storage.GetContext()
ns := getNameState(ctx, tokenID)
ns.checkAdmin()
putRecord(ctx, tokenID, name, typ, data)
}
// GetRecord returns domain record of the specified type if it exists or an empty
// string if not.
func GetRecord(name string, typ RecordType) string {
tokenID := []byte(tokenIDFromName(name))
ctx := storage.GetReadOnlyContext()
_ = getNameState(ctx, tokenID) // ensure not expired
return getRecord(ctx, tokenID, name, typ)
}
// DeleteRecord removes domain record with the specified type.
func DeleteRecord(name string, typ RecordType) {
tokenID := []byte(tokenIDFromName(name))
ctx := storage.GetContext()
ns := getNameState(ctx, tokenID)
ns.checkAdmin()
recordKey := getRecordKey(tokenID, name, typ)
storage.Delete(ctx, recordKey)
}
// Resolve resolves given name (not more then three redirects are allowed).
func Resolve(name string, typ RecordType) string {
ctx := storage.GetReadOnlyContext()
return resolve(ctx, name, typ, 2)
}
// GetAllRecords returns an Iterator with RecordState items for given name.
func GetAllRecords(name string) iterator.Iterator {
tokenID := []byte(tokenIDFromName(name))
ctx := storage.GetReadOnlyContext()
_ = getNameState(ctx, tokenID) // ensure not expired
recordsKey := getRecordsKey(tokenID, name)
return storage.Find(ctx, recordsKey, storage.ValuesOnly|storage.DeserializeValues)
}
// updateBalance updates account's balance and account's tokens.
func updateBalance(ctx storage.Context, tokenId []byte, acc interop.Hash160, diff int) {
balanceKey := append([]byte{prefixBalance}, acc...)
var balance int
if b := storage.Get(ctx, balanceKey); b != nil {
balance = b.(int)
}
balance += diff
if balance == 0 {
storage.Delete(ctx, balanceKey)
} else {
storage.Put(ctx, balanceKey, balance)
}
tokenKey := getTokenKey(tokenId)
accountTokenKey := append(append([]byte{prefixAccountToken}, acc...), tokenKey...)
if diff < 0 {
storage.Delete(ctx, accountTokenKey)
} else {
storage.Put(ctx, accountTokenKey, tokenId)
}
}
// postTransfer sends Transfer notification to the network and calls onNEP11Payment
// method.
func postTransfer(from, to interop.Hash160, tokenID []byte, data any) {
runtime.Notify("Transfer", from, to, 1, tokenID)
if management.GetContract(to) != nil {
contract.Call(to, "onNEP11Payment", contract.All, from, 1, tokenID, data)
}
}
// getTotalSupply returns total supply from storage.
func getTotalSupply(ctx storage.Context) int {
val := storage.Get(ctx, []byte{prefixTotalSupply})
return val.(int)
}
// updateTotalSupply adds specified diff to the total supply.
func updateTotalSupply(ctx storage.Context, diff int) {
tsKey := []byte{prefixTotalSupply}
ts := getTotalSupply(ctx)
storage.Put(ctx, tsKey, ts+diff)
}
// getTokenKey computes hash160 from the given tokenID.
func getTokenKey(tokenID []byte) []byte {
return crypto.Ripemd160(tokenID)
}
// getNameState returns domain name state by the specified tokenID.
func getNameState(ctx storage.Context, tokenID []byte) NameState {
tokenKey := getTokenKey(tokenID)
return getNameStateWithKey(ctx, tokenKey)
}
// getNameStateWithKey returns domain name state by the specified token key.
func getNameStateWithKey(ctx storage.Context, tokenKey []byte) NameState {
nameKey := append([]byte{prefixName}, tokenKey...)
nsBytes := storage.Get(ctx, nameKey)
if nsBytes == nil {
panic("token not found")
}
ns := std.Deserialize(nsBytes.([]byte)).(NameState)
ns.ensureNotExpired()
return ns
}
// putNameState stores domain name state.
func putNameState(ctx storage.Context, ns NameState) {
tokenKey := getTokenKey([]byte(ns.Name))
putNameStateWithKey(ctx, tokenKey, ns)
}
// putNameStateWithKey stores domain name state with the specified token key.
func putNameStateWithKey(ctx storage.Context, tokenKey []byte, ns NameState) {
nameKey := append([]byte{prefixName}, tokenKey...)
nsBytes := std.Serialize(ns)
storage.Put(ctx, nameKey, nsBytes)
}
// getRecord returns domain record.
func getRecord(ctx storage.Context, tokenId []byte, name string, typ RecordType) string {
recordKey := getRecordKey(tokenId, name, typ)
recBytes := storage.Get(ctx, recordKey)
if recBytes == nil {
return recBytes.(string) // A hack to actually return NULL.
}
record := std.Deserialize(recBytes.([]byte)).(RecordState)
return record.Data
}
// putRecord stores domain record.
func putRecord(ctx storage.Context, tokenId []byte, name string, typ RecordType, record string) {
recordKey := getRecordKey(tokenId, name, typ)
rs := RecordState{
Name: name,
Type: typ,
Data: record,
}
recBytes := std.Serialize(rs)
storage.Put(ctx, recordKey, recBytes)
}
// getRecordsKey returns prefix used to store domain records of different types.
func getRecordsKey(tokenId []byte, name string) []byte {
recordKey := append([]byte{prefixRecord}, getTokenKey(tokenId)...)
return append(recordKey, getTokenKey([]byte(name))...)
}
// getRecordKey returns key used to store domain records.
func getRecordKey(tokenId []byte, name string, typ RecordType) []byte {
recordKey := getRecordsKey(tokenId, name)
return append(recordKey, []byte{byte(typ)}...)
}
// isValid returns true if the provided address is a valid Uint160.
func isValid(address interop.Hash160) bool {
return address != nil && len(address) == 20
}
// checkCommittee panics if the script container is not signed by the committee.
func checkCommittee() {
committee := neo.GetCommittee()
if committee == nil {
panic("failed to get committee")
}
l := len(committee)
committeeMultisig := contract.CreateMultisigAccount(l-(l-1)/2, committee)
if committeeMultisig == nil || !runtime.CheckWitness(committeeMultisig) {
panic("not witnessed by committee")
}
}
// checkFragment validates root or a part of domain name.
// 1. Root domain must start with a letter.
// 2. All other fragments must start and end in a letter or a digit.
func checkFragment(v string, isRoot bool) bool {
maxLength := maxDomainNameFragmentLength
if isRoot {
maxLength = maxRootLength
}
if len(v) == 0 || len(v) > maxLength {
return false
}
c := v[0]
if isRoot {
if !(c >= 'a' && c <= 'z') {
return false
}
} else {
if !isAlNum(c) {
return false
}
}
for i := 1; i < len(v)-1; i++ {
if v[i] != '-' && !isAlNum(v[i]) {
return false
}
}
return isAlNum(v[len(v)-1])
}
// isAlNum checks whether provided char is a lowercase letter or a number.
func isAlNum(c uint8) bool {
return c >= 'a' && c <= 'z' || c >= '0' && c <= '9'
}
// splitAndCheck splits domain name into parts and validates it.
func splitAndCheck(name string, allowMultipleFragments bool) []string {
l := len(name)
if l < minDomainNameLength || maxDomainNameLength < l {
return nil
}
fragments := std.StringSplit(name, ".")
l = len(fragments)
if l < 2 {
return nil
}
if l > 2 && !allowMultipleFragments {
return nil
}
for i := 0; i < l; i++ {
if !checkFragment(fragments[i], i == l-1) {
return nil
}
}
return fragments
}
// checkIPv4 checks record on IPv4 compliance.
func checkIPv4(data string) bool {
l := len(data)
if l < 7 || 15 < l {
return false
}
fragments := std.StringSplit(data, ".")
if len(fragments) != 4 {
return false
}
numbers := make([]int, 4)
for i, f := range fragments {
if len(f) == 0 {
return false
}
number := std.Atoi10(f)
if number < 0 || 255 < number {
panic("not a byte")
}
if number > 0 && f[0] == '0' {
return false
}
if number == 0 && len(f) > 1 {
return false
}
numbers[i] = number
}
n0 := numbers[0]
n1 := numbers[1]
n3 := numbers[3]
if n0 == 0 ||
n0 == 10 ||
n0 == 127 ||
n0 >= 224 ||
(n0 == 169 && n1 == 254) ||
(n0 == 172 && 16 <= n1 && n1 <= 31) ||
(n0 == 192 && n1 == 168) ||
n3 == 0 ||
n3 == 255 {
return false
}
return true
}
// checkIPv6 checks record on IPv6 compliance.
func checkIPv6(data string) bool {
l := len(data)
if l < 2 || 39 < l {
return false
}
fragments := std.StringSplit(data, ":")
l = len(fragments)
if l < 3 || 8 < l {
return false
}
var hasEmpty bool
nums := make([]int, 8)
for i, f := range fragments {
if len(f) == 0 {
if i == 0 {
if len(fragments[1]) != 0 {
return false
}
nums[i] = 0
} else if i == l-1 {
if len(fragments[i-1]) != 0 {
return false
}
nums[7] = 0
} else if hasEmpty {
return false
} else {
hasEmpty = true
endIndex := 9 - l + i
for j := i; j < endIndex; j++ {
nums[j] = 0
}
}
} else {
if len(f) > 4 {
return false
}
n := std.Atoi(f, 16)
if 65535 < n {
panic("fragment overflows uint16: " + f)
}
idx := i
if hasEmpty {
idx = i + 8 - l
}
nums[idx] = n
}
}
if l < 8 && !hasEmpty {
return false
}
f0 := nums[0]
if f0 < 0x2000 || f0 == 0x2002 || f0 == 0x3ffe || f0 > 0x3fff { // IPv6 Global Unicast https://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.xhtml
return false
}
if f0 == 0x2001 {
f1 := nums[1]
if f1 < 0x200 || f1 == 0xdb8 {
return false
}
}
return true
}
// tokenIDFromName returns token ID (domain.root) from provided name.
func tokenIDFromName(name string) string {
fragments := splitAndCheck(name, true)
if fragments == nil {
panic("invalid domain name format")
}
l := len(fragments)
return name[len(name)-(len(fragments[l-1])+len(fragments[l-2])+1):]
}
// resolve resolves provided name using record with the specified type and given
// maximum redirections constraint.
func resolve(ctx storage.Context, name string, typ RecordType, redirect int) string {
if redirect < 0 {
panic("invalid redirect")
}
if len(name) == 0 {
panic("invalid name")
}
if name[len(name)-1] == '.' {
name = name[:len(name)-1]
}
records := getRecords(ctx, name)
cname := ""
for iterator.Next(records) {
r := iterator.Value(records).(struct {
key string
rs RecordState
})
value := r.rs.Data
rTyp := r.key[len(r.key)-1]
if rTyp == byte(typ) {
return value
}
if rTyp == byte(CNAME) {
cname = value
}
}
if cname == "" {
return string([]byte(nil))
}
return resolve(ctx, cname, typ, redirect-1)
}
// getRecords returns iterator over the set of records corresponded with the
// specified name.
func getRecords(ctx storage.Context, name string) iterator.Iterator {
tokenID := []byte(tokenIDFromName(name))
_ = getNameState(ctx, tokenID)
recordsKey := getRecordsKey(tokenID, name)
return storage.Find(ctx, recordsKey, storage.DeserializeValues)
}