diff --git a/contracts/imports/dns-utils.fc b/contracts/imports/dns-utils.fc index 8580e54..8105cc6 100644 --- a/contracts/imports/dns-utils.fc +++ b/contracts/imports/dns-utils.fc @@ -31,7 +31,8 @@ int get_top_domain_bits(slice domain) { return i; } -slice read_domain_from_comment(slice in_msg_body) { +;; Parse a human-readable TON comment into one slice +slice read_comment(slice in_msg_body) { int need_break = 0; builder result = begin_cell(); do { @@ -46,6 +47,10 @@ slice read_domain_from_comment(slice in_msg_body) { return result.end_cell().begin_parse(); } +slice read_domain_from_comment(slice in_msg_body) { + return read_comment(in_msg_body); +} + int check_domain_string(slice domain) { int i = 0; int len = slice_bits(domain); @@ -67,6 +72,28 @@ int check_domain_string(slice domain) { return i == len; } +(slice, slice) split_by_semicolon(slice str) { + int i = 0; + int len = slice_bits(str); + int need_break = 0; + builder result1 = begin_cell(); + do { + need_break = i == len; + if (~ need_break) { + int char = str~load_uint(8); + need_break = char == 59; ;; ';' + if (~ need_break) { + i += 8; + } + result1~store_uint(char, 8); + if (~ need_break & (i >= len)) { + throw(259); ;; no ';' found + } + } + } until (need_break); + return (result1.end_cell().begin_parse(), str~load_bits(len - i)); +} + (int, int) get_min_price_config(int domain_char_count) { if (domain_char_count == 4) { return (1000, 100); diff --git a/contracts/nft-collection.fc b/contracts/nft-collection.fc index dc63692..995d5ab 100644 --- a/contracts/nft-collection.fc +++ b/contracts/nft-collection.fc @@ -3,6 +3,9 @@ #include "imports/op-codes.fc"; #include "imports/params.fc"; +;; -1 if needed, 0 if not +const signature_needed = -1; + ;; storage scheme ;; cell collection_content ;; cell nft_item_code @@ -68,6 +71,11 @@ slice calculate_nft_item_address(int wc, cell state_init) { send_raw_message(msg.end_cell(), 64); ;; carry all the remaining value of the inbound message, fee deducted from amount } +int verify_signature(cell signature, slice sender_address, slice domain, int owner_key) { + cell option_data = begin_cell().store_slice(domain).store_slice(sender_address).end_cell(); + return check_signature(slice_hash(option_data.begin_parse()), signature.begin_parse(), owner_key); +} + () recv_internal(int msg_value, cell in_msg_full, slice in_msg_body) impure { if (in_msg_body.slice_empty?()) { ;; bounce back empty messages throw(0xffff); @@ -93,6 +101,12 @@ slice calculate_nft_item_address(int wc, cell state_init) { int item_index = slice_hash(domain); slice sender_address = cs~load_msg_addr(); + if (signature_needed) { + ;; todo: do stuff here +;; cell signature = in_msg_body~load_ref(); +;; throw_unless(205, verify_signature(signature, sender_address, domain, key)); + } + cell nft_content = begin_cell() .store_slice(sender_address) .store_ref(begin_cell().store_slice(domain).end_cell()) diff --git a/test/creation.spec.ts b/test/creation.spec.ts index 95b2826..afe9a46 100644 --- a/test/creation.spec.ts +++ b/test/creation.spec.ts @@ -9,6 +9,7 @@ import * as main from "../contracts/main"; import { internalMessage, randomAddress } from "./helpers"; import { hex } from "../build/nft-collection.compiled.json"; +import {makeSnakeCell} from "../contracts/utils"; describe("Creating items tests", () => { let contract: SmartContract;