Provides means for resolution of DNS names.
To use this library, import @stdlib/dns
:
Structs
DNSResolveResult
struct DNSResolveResult {
Functions
dnsStringToInternal
@name (dns_string_to_internal)
native dnsStringToInternal ( str : String ): Slice ? ;
Converts a DNS string to a Slice
or null
, if it’s impossible.
Source code (FunC): dns.fc#L1
dnsInternalNormalize
@name (dns_internal_normalize)
native dnsInternalNormalize ( src : Slice ): Slice ;
Normalizes the internal DNS representation of the Slice
. The passed Slice
must not have any references, otherwise an exception with exit code 134 will be thrown: Invalid argument
.
Source code (FunC): dns.fc#L125
dnsInternalVerify
@name (dns_internal_verify)
native dnsInternalVerify ( subdomain : Slice ): Bool ;
Verifies the internal DNS representation of the subdomain Slice
.
Source code (FunC): dns.fc#L81
dnsExtractTopDomainLength
fun dnsExtractTopDomainLength ( subdomain : Slice ): Int ;
Calculates length of a top domain in the subdomain
Slice
.
Source code:
fun dnsExtractTopDomainLength ( subdomain : Slice ): Int {
let needBreak : Bool = false ;
let char : Int = subdomain . loadUint ( 8 ); // we do not check domain.length because it MUST contain \0 character
require ( i != 0 , "Invalid DNS name" );
dnsExtractTopDomain
fun dnsExtractTopDomain ( subdomain : Slice ): Slice ;
Extracts top domain from a subdomain
Slice
.
Source code:
fun dnsExtractTopDomain ( subdomain : Slice ): Slice {
let len : Int = dnsExtractTopDomainLength ( subdomain );
return subdomain . loadBits ( len );
dnsResolveNext
fun dnsResolveNext ( address : Address ): Cell ;
Resolves an address
Address
into a Cell
.
Source code:
fun dnsResolveNext ( address : Address ): Cell {
dnsResolveWallet
fun dnsResolveWallet ( address : Address ): Cell ;
Resolves a wallet address
Address
into a Cell
.
Source code:
fun dnsResolveWallet ( address : Address ): Cell {
Traits
DNSResolver
Trait DNSResolver
provides two helper functions for DNS resolution:
getter function dnsresolve ()
, which corresponds to its FunC variant .
virtual function doResolveDNS ()
, which creates a struct DNSResolveResult out of subdomain Slice
bits.
Source code:
get fun dnsresolve ( subdomain : Slice , category : Int ): DNSResolveResult {
if ( subdomain . preloadUint ( 8 ) == 0 ) {
subdomain . loadUint ( 8 ); // Skip first byte
require ( dnsInternalVerify ( subdomain ), "Invalid DNS name" );
let res : DNSResolveResult = self . doResolveDNS ( subdomain , category );
return DNSResolveResult { prefix : res . prefix + delta , record : res . record };
virtual fun doResolveDNS ( subdomain : Slice , category : Int ): DNSResolveResult {
return DNSResolveResult { prefix : subdomain . bits (), record : null };
Usage example:
contract ExampleContract with DNSResolver {
// Now, this contract has a:
// 1. dnsresolve getter function
// 2. doResolveDNS virtual function
Sources