From 97b4c7a3d9f2ee0159212eb42a380ffbbcc1720b Mon Sep 17 00:00:00 2001 From: ennucore Date: Thu, 8 Dec 2022 20:54:32 +0100 Subject: [PATCH] Added some operators --- contracts/main.fc | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/contracts/main.fc b/contracts/main.fc index 1857951..5011fa6 100644 --- a/contracts/main.fc +++ b/contracts/main.fc @@ -190,6 +190,7 @@ slice calculate_nft_item_address(int wc, cell state_init) { if (in_msg_body.slice_empty?()) { ;; bounce back empty messages throw(0xffff); } + int my_balance = pair_first(get_balance()); ;; handle internal messages int op = in_msg_body.slice_empty?() ? 0 : in_msg_body~load_uint(32); slice cs = in_msg_full.begin_parse(); @@ -199,8 +200,15 @@ slice calculate_nft_item_address(int wc, cell state_init) { return (); } slice sender_address = cs~load_msg_addr(); + + cs~load_msg_addr(); ;; skip dst + cs~load_coins(); ;; skip value + cs~skip_bits(1); ;; skip extracurrency collection + cs~load_coins(); ;; skip ihr_fee + int fwd_fee = cs~load_coins(); ;; we use message fwd_fee for estimation of forward_payload c ;; Un-serialize all the data (cell content, cell item_code, int init?, int index, slice collection_address, slice owner_address, cell domain, cell auction, int last_fill_up_time) = load_data(); + ;; This means that we are initializing the new contract ;; The initialization message has this structure: ;; address initial_owner_address (for an auction) @@ -235,6 +243,43 @@ slice calculate_nft_item_address(int wc, cell state_init) { return (); } + (slice max_bid_address, int max_bid_amount, int auction_end_time) = unpack_auction(auction); + int auction_complete = now() > auction_end_time; + int query_id = in_msg_body~load_uint(64); + + if ((auction_complete) & (~ cell_null?(auction))) { ;; take domain after auction + int balance_without_msg = my_balance - msg_value; + int amount_to_send = (max_bid_amount > balance_without_msg - min_tons_for_storage()) ? (balance_without_msg - min_tons_for_storage()) : max_bid_amount; + if (amount_to_send > 0) { + send_msg(collection_address, amount_to_send, op::fill_up, query_id, null(), 2); ;; ignore errors + my_balance -= amount_to_send; + } + owner_address = max_bid_address; + auction = null(); + store_data(content, item_code, index, collection_address, owner_address, domain, auction, last_fill_up_time); + } + + if (op == op::new_nft()) { + throw_unless(401, equal_slices(sender_address, owner_address)); + ;; TODO (this is like the most important part) + return (); + } + if (op == op::transfer()) { + throw_unless(401, equal_slices(sender_address, owner_address)); + transfer_ownership(my_balance, content, item_code, index, collection_address, owner_address, sender_address, query_id, in_msg_body, fwd_fee, domain, auction); + return (); + } + if (op == op::edit_content()) { ;; owner can change content and dns records + throw_unless(410, equal_slices(sender_address, owner_address)); + store_data(in_msg_body~load_ref(), item_code, index, collection_address, owner_address, domain, auction, now()); + return (); + } + + if (op == op::get_static_data()) { + send_msg(sender_address, 0, op::report_static_data(), query_id, begin_cell().store_uint(index, 256).store_slice(collection_address), 64); ;; carry all the remaining value of the inbound message + return (); + } + throw(0xffff); } ;;