Skip to content

Commit

Permalink
- Fix DNS
Browse files Browse the repository at this point in the history
- Add global "master" domain name
  • Loading branch information
imartemy1524 committed Sep 29, 2024
1 parent ba49d79 commit a2282d1
Show file tree
Hide file tree
Showing 19 changed files with 17,269 additions and 3,222 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Now, what **account** can do?
2. Other users can leave [comments](./contracts/comment.tact) to the post or to other comments (answering them).
3. Users can [like](./contracts/abstract/likeable.tact) any [post](./contracts/post.tact) or [comments](./contracts/comment.tact) (in future, like can contain some value, to support user).
4. Users can receive [achievements](./contracts/achievement.tact) (SBT) for doing actions.
5. You can buy NFT with unique nickname (on auction) and "link" it to your account, s.t. it would be accessible by DNS domain `nickname.neto.ton` (for example, `pavel-durov.neto.ton`).

### Features

Expand Down
10 changes: 9 additions & 1 deletion contracts/DNS/dns-collection.tact
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ trait DnsCollection with DNSResolverMy{
subdomain.skipBits(16);
prefix = 0;
let ID = subdomain.stringToInt();
maped.set(sha256("dns_next_resolver"), dnsResolveNext(self.getMasterContract(ID)));
let master = self.getMasterContract(ID);
dump(master.toString());
maped.set(sha256("dns_next_resolver"), dnsResolveNext(master));
}
else if(subdomain.startsWithMaster()){
subdomain.skipBits(48);
prefix = 48;
maped.set(sha256("dns_next_resolver"), dnsResolveNext(self.getMasterContract((1 << 64) - 1)));

}
//starts with "domain" - reference to self
else if(subdomain.startsWithDomain() && subdomain.bits() == 48){
Expand Down
2 changes: 0 additions & 2 deletions contracts/DNS/dns-item.tact
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ trait DnsItem with DNSResolverMy, Masterable{
// Self-domain resolving - no subdomain found (someone enters ".neto.ton" or "neto.ton")
if (subdomainOld.empty()) {
if(self.owner != null && self.linked){
dump("Resolved empty");
dump(self.owner!!);
dict.set(sha256("dns_next_resolver"), dnsResolveNext(self.owner!!));
}
dict.set(sha256("site"), dnsResolveNext(self.master));
Expand Down
1 change: 1 addition & 0 deletions contracts/DNS/dns-master.tact
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ trait DnsMaster with DNSResolverMy, UserPerformable, Ownable{
//starts with "owner"
else if(subdomain.startsWithOwner() && subdomain.bits() == 5*8){
maped.set(sha256("wallet"), dnsResolveWallet(self.owner));
prefix += 8;
}
return dnsResolveResult(prefix, maped, category);
}
Expand Down
16 changes: 15 additions & 1 deletion contracts/DNS/types.tact
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ inline fun validateNickName(slice: Slice): Bool{
require(!slice.startsWithId(), "System reserved nickname");
//does not starts with "owner"
require(!slice.startsWithOwner(), "System reserved nickname");
//does not starts with "master"
require(!slice.startsWithMaster(), "System reserved nickname");
// if(slice.startsWithId()){
// slice.skipBits(16);
// let bitShouldNotBeInteger = slice.loadUint(8);
Expand All @@ -66,6 +68,9 @@ extends inline fun startsWithOwner(self: Slice): Bool{
extends inline fun startsWithId(self: Slice): Bool{
return self.bits() >= 16 && self.preloadUint(16) == 0b0110100101100100;
}
extends inline fun startsWithMaster(self: Slice): Bool{
return self.bits() >= 48 && self.preloadUint(48) == 0b011011010110000101110011011101000110010101110010;
}

//string starts with "nft"
extends inline fun startsWithDomain(self: Slice): Bool{
Expand All @@ -75,12 +80,21 @@ extends inline fun startsWithDomain(self: Slice): Bool{

inline fun dnsResolveResult(prefix: Int, dict: map<Int as uint256, Cell>, category: Int): DNSResolveResult{

let recordDef = dict.get(sha256("dns_next_resolver"));
if category == 0 {
if( recordDef != null){
if(dict.get(sha256("wallet")) == null){
dict.set(sha256("wallet"), recordDef);
}
if(dict.get(sha256("site")) == null){
dict.set(sha256("site"), recordDef);
}
}
return DNSResolveResult{prefix, record: dict.asCell()};
}
let record = dict.get(category);
if record == null {
record = dict.get(sha256("dns_next_resolver"));
record = recordDef;
}

//for now no more subdomains allowed
Expand Down
21 changes: 18 additions & 3 deletions contracts/master.tact
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ message(0x12345678) Register{}
struct StringData{
data: String;
}
contract Master with OwnableTransferable, MasterUserBans, NftCollection, DnsMaster{
message SetRegisterable{registerable: Bool;}
contract Master with OwnableTransferable, MasterUserBans, NftCollection, DnsMaster, Excessable{
override const CollectionName: String = "Test";//"NetoTon users";
override fun collectionDescription(): String{
return beginString()
.concat("Collection of ")
.concat(self.lastUserId.toString())
.concat((self.lastUserId - self.startUserId).toString())
.concat(" users on NetoTon blockchain, each represented by a unique NFT")
.toString();
}
Expand All @@ -33,10 +34,14 @@ contract Master with OwnableTransferable, MasterUserBans, NftCollection, DnsMast
owner: Address;
registerAmount: Int as coins = ton("1");
lastUserId: Int as uint64 = 0;
startUserId: Int as uint64 = 0;
registerable: Bool = true;
nicknameCollection: Address;
init(owner: Address, nicknameCollection: Address){
init(owner: Address, nicknameCollection: Address, startUserId: Int){
self.owner = owner;
self.nicknameCollection = nicknameCollection;
self.startUserId = startUserId;
self.lastUserId = startUserId;
}
receive(deploy: Deploy) {
self.requireOwner();
Expand Down Expand Up @@ -75,10 +80,17 @@ contract Master with OwnableTransferable, MasterUserBans, NftCollection, DnsMast
receive(m: ChangeRegisterAmount){
self.requireOwner();
self.registerAmount = m.amount;
self.excess(sender(), "ok");
}
receive(m: SetRegisterable){
self.requireOwner();
self.registerable = m.registerable;
self.excess(sender(), "ok");
}

receive(m: Register){
require(context().value >= self.registerAmount, "Not enough value");
require(self.registerable, "Register is disabled");
self.lastUserId += 1;
let user = initOf User(myAddress(), self.lastUserId);
self.forward(
Expand All @@ -99,6 +111,9 @@ contract Master with OwnableTransferable, MasterUserBans, NftCollection, DnsMast
return contractAddress(initOf User(myAddress(), userId));
}
get fun usersCount(): Int{
return self.lastUserId - self.startUserId;
}
get fun lastUserId(): Int{
return self.lastUserId;
}
get fun achievement(): Address{
Expand Down
9 changes: 5 additions & 4 deletions contracts/nicknames-collection.tact
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ message ExternalAdd{
}


contract NicknamesCollection with DnsCollection, DnsNFTCollection, OwnableTransferable, Exitable{
contract NicknamesCollection with DnsCollection, DnsNFTCollection, OwnableTransferable, Exitable, Excessable{
owner: Address;
nicknamesCount: Int = 0;
//ADNL link to website OR ADNL link to ton storage
Expand Down Expand Up @@ -109,10 +109,8 @@ contract NicknamesCollection with DnsCollection, DnsNFTCollection, OwnableTransf
self.requireOwner();
require(self.masters.size == 0 || self.masters.masters.get(self.masters.size - 1)!!.startUserId < m.master.startUserId, "Invalid master found");
self.masters.add(m.master);
}
self.excess(sender(), "ok");

receive(m: Deploy){
self.requireOwner();
}

//update website ID
Expand All @@ -125,6 +123,9 @@ contract NicknamesCollection with DnsCollection, DnsNFTCollection, OwnableTransf
self.forward(self.owner, null, false, null);
self.exitWithoutSaving();
}
get fun masters(): Masters{
return self.masters;
}
}
//binary search LAST element, which startUserId < id
fun getMasterContractFromMaster(masters: Masters, id: Int): Address? {
Expand Down
Loading

0 comments on commit a2282d1

Please sign in to comment.