mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
auto-dns & manual-dns smartcontracts updated to actual DNS standard version by starlightduck
This commit is contained in:
parent
1ded7af335
commit
313d37e134
4 changed files with 61 additions and 26 deletions
|
@ -7,12 +7,15 @@
|
|||
| Author: Oleksandr Murzin (tg: @skydev / em: alexhacker64@gmail.com) |
|
||||
| October 2019 |
|
||||
\------------------------------------------------------------------------/
|
||||
Updated to actual DNS standard version by starlightduck in 2022
|
||||
-}
|
||||
|
||||
;;===========================================================================;;
|
||||
;; Custom ASM instructions ;;
|
||||
;;===========================================================================;;
|
||||
|
||||
cell udict_get_ref_(cell dict, int key_len, int index) asm(index dict key_len) "DICTUGETOPTREF";
|
||||
|
||||
(cell, ()) pfxdict_set_ref(cell dict, int key_len, slice key, cell value) {
|
||||
throw_unless(33, dict~pfxdict_set?(key_len, key, begin_cell().store_maybe_ref(value).end_cell().begin_parse()));
|
||||
return (dict, ());
|
||||
|
@ -67,9 +70,9 @@
|
|||
Operations (continuation of message):
|
||||
00 Contract initialization message (only if seqno = 0) (x=-)
|
||||
11 VSet: set specified value to specified subdomain->category (x=2)
|
||||
[Int<16b>:category] [Name<?>:subdomain] [Cell<1r>:value]
|
||||
[UInt<256b>:category] [Name<?>:subdomain] [Cell<1r>:value]
|
||||
12 VDel: delete specified subdomain->category (x=2)
|
||||
[Int<16b>:category] [Name<?>:subdomain]
|
||||
[UInt<256b>:category] [Name<?>:subdomain]
|
||||
21 DSet: replace entire category dictionary of domain with provided (x=0)
|
||||
[Name<?>:subdomain] [Cell<1r>:new_cat_table]
|
||||
22 DDel: delete entire category dictionary of specified domain (x=0)
|
||||
|
@ -112,7 +115,7 @@
|
|||
int cat = 0;
|
||||
if (op < 20) {
|
||||
;; for operations with codes 10..19 category is required
|
||||
cat = ops~load_int(16);
|
||||
cat = ops~load_uint(256); ;; update: category length now u256 instead of i16
|
||||
}
|
||||
slice name = null(); ;; any slice value
|
||||
cell cat_table = null();
|
||||
|
@ -159,13 +162,13 @@
|
|||
;; 11 VSet: set specified value to specified subdomain->category
|
||||
if (op == 11) {
|
||||
cell new_value = ops~load_maybe_ref();
|
||||
cat_table~idict_set_get_ref(16, cat, new_value);
|
||||
cat_table~udict_set_get_ref(256, cat, new_value); ;; update: category length now u256 instead of i16
|
||||
root~pfxdict_set_ref(1023, name, cat_table);
|
||||
return (root, ops);
|
||||
}
|
||||
;; 12 VDel: delete specified subdomain->category value
|
||||
if (op == 12) {
|
||||
if (cat_table~idict_delete?(16, cat)) {
|
||||
if (cat_table~udict_delete?(256, cat)) { ;; update: category length now u256 instead of i16
|
||||
root~pfxdict_set_ref(1023, name, cat_table);
|
||||
}
|
||||
return (root, ops);
|
||||
|
@ -261,7 +264,7 @@ cell process_ops(cell root, slice ops) inline_ref {
|
|||
Data structure:
|
||||
Root cell: [UInt<32b>:seqno] [UInt<256b>:owner_public_key]
|
||||
[OptRef<1b+1r?>:Hashmap<PfxDict:Slice->CatTable>:domains]
|
||||
<CatTable> := HashmapE 16 ^DNSRecord
|
||||
<CatTable> := HashmapE 256 (~~16~~) ^DNSRecord
|
||||
|
||||
STORED DOMAIN NAME SLICE FORMAT: (#ZeroChars<7b>) (Domain name value)
|
||||
#Zeros allows to simultaneously store, for example, com\0 and com\0google\0
|
||||
|
@ -291,7 +294,8 @@ int get_public_key() method_id {
|
|||
(int, cell) dnsresolve(slice subdomain, int category) method_id {
|
||||
int bits = subdomain.slice_bits();
|
||||
ifnot (bits) {
|
||||
return (0, null()); ;; zero-length input
|
||||
;; return (0, null()); ;; zero-length input
|
||||
throw(30); ;; update: throw exception for empty input
|
||||
}
|
||||
throw_if(30, bits & 7); ;; malformed input (~ 8n-bit)
|
||||
|
||||
|
@ -302,7 +306,14 @@ int get_public_key() method_id {
|
|||
bits += 8;
|
||||
}
|
||||
if (bits == 8) {
|
||||
return (0, null()); ;; zero-length input, but with zero byte
|
||||
return (8, null()); ;; zero-length input, but with zero byte
|
||||
;; update: return 8 as resolved, but with no data
|
||||
}
|
||||
int name_first_byte = subdomain.preload_uint(8);
|
||||
if (name_first_byte == 0) {
|
||||
;; update: remove prefix \0
|
||||
subdomain~load_uint(8);
|
||||
bits -= 8;
|
||||
}
|
||||
(_, _, _, cell root, _) = load_data();
|
||||
|
||||
|
@ -332,7 +343,9 @@ int get_public_key() method_id {
|
|||
zeros = - zeros;
|
||||
|
||||
ifnot (tail.slice_empty?()) { ;; if we have tail then len(pfx) < len(subdomain)
|
||||
category = -1; ;; incomplete subdomain found, must return next resolver (-1)
|
||||
;; incomplete subdomain found, must return next resolver
|
||||
category = "dns_next_resolver"H; ;; 0x19f02441ee588fdb26ee24b2568dd035c3c9206e11ab979be62e55558a1d17ff
|
||||
;; update: next resolver is now sha256("dns_next_resolver") instead of -1
|
||||
}
|
||||
int pfx_bits = pfx.slice_bits() - 7;
|
||||
cell cat_table = val;
|
||||
|
@ -342,7 +355,7 @@ int get_public_key() method_id {
|
|||
if (category == 0) {
|
||||
return (pfx_bits, cat_table); ;; return cell with entire dictionary for 0
|
||||
} else {
|
||||
cell cat_found = cat_table.idict_get_ref(16, category);
|
||||
cell cat_found = cat_table.udict_get_ref_(256, category); ;; update: category length now u256 instead of i16
|
||||
return (pfx_bits, cat_found);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue