Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the code grammar, #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"deploy": "ts-node ./sources/contract.deploy.ts"
},
"dependencies": {
"@tact-lang/compiler": "^1.1.0-beta.15",
"@tact-lang/coverage": "^0.0.6",
"@tact-lang/compiler": "^1.1.3",
"@tact-lang/coverage": "^0.0.5",
"@tact-lang/deployer": "^0.2.0",
"@tact-lang/emulator": "^3.4.1",
"@types/jest": "^29.2.4",
Expand Down
61 changes: 30 additions & 31 deletions sources/contract.deploy.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
import * as fs from 'fs';
import * as path from 'path';
import { Address, contractAddress } from "ton";
import * as fs from "fs";
import * as path from "path";
import { Address, contractAddress, WalletContractV4, address } from "ton";
import { SimpleDNSContract } from "./output/dns_SimpleDNSContract";
import { prepareTactDeployment } from "@tact-lang/deployer";

(async () => {
// Parameters
let testnet = true;
let packageName = "sample_SampleTactContract.pkg";
let owner = Address.parse("kQAp8i3_3zwdIrK7-bx4iDkTD6ep3v1JV4NtCLaVvyq5dHUA");
let init = await SimpleDNSContract.init(owner);

// Parameters
let testnet = true;
let packageName = 'sample_SampleTactContract.pkg';
let owner = Address.parse('kQAp8i3_3zwdIrK7-bx4iDkTD6ep3v1JV4NtCLaVvyq5dHUA');
let init = await SimpleDNSContract.init(owner);
// Load required data
let address = contractAddress(0, init);
let data = init.data.toBoc();
let pkg = fs.readFileSync(path.resolve(__dirname, "output", packageName));

// Load required data
let address = contractAddress(0, init);
let data = init.data.toBoc();
let pkg = fs.readFileSync(path.resolve(__dirname, 'output', packageName));
// Prepareing
console.log("Uploading package...");
let prepare = await prepareTactDeployment({ pkg, data, testnet });

// Prepareing
console.log('Uploading package...');
let prepare = await prepareTactDeployment({ pkg, data, testnet });

// Deploying
console.log("============================================================================================");
console.log('Contract Address')
console.log("============================================================================================");
console.log();
console.log(address.toString({ testOnly: testnet }));
console.log();
console.log("============================================================================================");
console.log('Please, follow deployment link')
console.log("============================================================================================");
console.log();
console.log(prepare);
console.log();
console.log("============================================================================================");
})();
// Deploying
console.log("============================================================================================");
console.log("Contract Address");
console.log("============================================================================================");
console.log();
console.log(address.toString({ testOnly: testnet }));
console.log();
console.log("============================================================================================");
console.log("Please, follow deployment link");
console.log("============================================================================================");
console.log();
console.log(prepare);
console.log();
console.log("============================================================================================");
})();
31 changes: 20 additions & 11 deletions sources/contract.tact
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ message EventRecordRemoved { domain: String; category: Int; }
message EventSubdomainAdded { domain: String; address: Address; }
message EventSubdomainRemoved { domain: String; }

struct DNSRecord { name: String; categories: map<Int, Cell>; }
struct Permissions { canAdd: Bool; canRemove: Bool; canReplace: Bool; }
struct DNSRecord {
name: String;
categories: map<Int, Cell>;
}
struct Permissions {
canAdd: Bool;
canRemove: Bool;
canReplace: Bool;
}

contract SimpleDNSContract with Deployable, OwnableTransferable, DNSResolver {

Expand Down Expand Up @@ -56,7 +63,7 @@ contract SimpleDNSContract with Deployable, OwnableTransferable, DNSResolver {
emit(EventRecordRemoved{ domain: update.domain, category: update.category }.toCell());

// Reply
reply("Record removed".asComment());
self.reply("Record removed".asComment());
return;
}

Expand All @@ -71,7 +78,7 @@ contract SimpleDNSContract with Deployable, OwnableTransferable, DNSResolver {
self.records.set(id, domain);

// Reply
reply("Record replaced".asComment());
self.reply("Record replaced".asComment());
return;
}

Expand All @@ -86,7 +93,7 @@ contract SimpleDNSContract with Deployable, OwnableTransferable, DNSResolver {
self.records.set(id, domain);

// Reply
reply("Record added".asComment());
self.reply("Record added".asComment());
return;
}
} else {
Expand All @@ -102,41 +109,41 @@ contract SimpleDNSContract with Deployable, OwnableTransferable, DNSResolver {
self.records.set(id, domain);

// Reply
reply("Record added".asComment());
self.reply("Record added".asComment());
return;
}
}

// Fallback
reply("Record not found".asComment());
self.reply("Record not found".asComment());
}

receive("burn canAdd") {
self.requireOwner();
require(self.permissions.canAdd, "Fuse already burned");
self.permissions.canAdd = false;
reply("Fuse burned".asComment());
self.reply("Fuse burned".asComment());
}

receive("burn canRemove") {
self.requireOwner();
require(self.permissions.canRemove, "Fuse already burned");
self.permissions.canRemove = false;
reply("Fuse burned".asComment());
self.reply("Fuse burned".asComment());
}

receive("burn canReplace") {
self.requireOwner();
require(self.permissions.canReplace, "Fuse already burned");
self.permissions.canReplace = false;
reply("Fuse burned".asComment());
self.reply("Fuse burned".asComment());
}

//
// Resolver
//

overrides fun doResolveDNS(subdomain: Slice, category: Int): DNSResolveResult {
override fun doResolveDNS(subdomain: Slice, category: Int): DNSResolveResult {

// Self-domain resolving
if (subdomain.bits() == 0) {
Expand All @@ -154,6 +161,7 @@ contract SimpleDNSContract with Deployable, OwnableTransferable, DNSResolver {
return self.resolveByKey(subdomain.bits(), subdomain.hash(), category);
}


fun resolveByKey(totalBits: Int, id: Int, category: Int): DNSResolveResult {
let record: DNSRecord? = self.records.get(id);
if (record == null) {
Expand All @@ -163,6 +171,7 @@ contract SimpleDNSContract with Deployable, OwnableTransferable, DNSResolver {
return DNSResolveResult { prefix: totalBits, record: (record!!).categories.asCell() };
}
let cat: Cell? = (record!!).categories.get(category);

return DNSResolveResult { prefix: totalBits, record: null };
}

Expand Down
Loading