@ -52,11 +52,19 @@ cell pack_auction(slice max_bid_address, int max_bid_amount, int auction_end_tim
.end_cell();
}
int get_public_key() method_id {
var cs = get_data().begin_parse();
cs~load_ref();
return cs.preload_uint(256);
}
;; cell content, cell nft_item_code, uint256 index, address collection_address,
;; address owner_address, cell domain, cell auction, int last_fill_up_time
;;
;; cell: cell content, cell nft_item_code, uint256 index, address collection_address,
;; address owner_address, cell domain, cell auction, int last_fill_up_time
;; uint256 public_key
(cell, cell, int, int, slice, slice, cell, cell, int) load_data() {
slice ds = get_data().begin_parse();
slice root_cell = get_data().begin_parse();
slice ds = root_cell~load_ref().begin_parse();
cell code = ds~load_ref(); ;; code
var (index, collection_address) = (ds~load_uint(256), ds~load_msg_addr());
if (ds.slice_bits() > 0) {
@ -105,20 +113,10 @@ cell pack_state(cell content, cell nft_item_code, int index, slice collection_ad
;; Serialize the data using the storage schema
() store_data(cell content, cell nft_item_code, int index, slice collection_address, slice owner_address, cell domain, cell auction, int last_fill_up_time) impure {
;; set_data(
;; begin_cell()
;; .store_ref(nft_item_code)
;; .store_uint(index, 256)
;; .store_slice(collection_address)
;; .store_slice(owner_address)
;; .store_ref(content)
;; .store_ref(domain)
;; .store_dict(auction)
;; .store_uint(last_fill_up_time, 64)
;; .end_cell()
;; );
set_data(pack_state(content, nft_item_code, index, collection_address, owner_address, domain, auction, last_fill_up_time));
cell data = pack_state(content, nft_item_code, index, collection_address, owner_address, domain, auction, last_fill_up_time);
int public_key = get_public_key();
set_data(begin_cell().store_ref(data).store_uint(public_key, 256).end_cell());
}
() send_msg(slice to_address, int amount, int op, int query_id, builder payload, int send_mode) impure inline {
@ -205,7 +203,7 @@ cell pack_nft_item_state(cell nft_item_code, cell data) impure {
return begin_cell().store_uint(0, 2).store_dict(nft_item_code).store_dict(data).store_uint(0, 1).end_cell();
}
() deploy_bought_item(int item_index, cell code, slice owner_address, sli ce domain) impure {
() deploy_bought_item(int item_index, cell code, slice owner_address, cell domain) impure {
;; cell nft_item_code
;; uint256 index --- The index of this item in the collection
;; MsgAddressInt collection_address
@ -220,7 +218,7 @@ cell pack_nft_item_state(cell nft_item_code, cell data) impure {
.store_slice(my_address())
.store_slice(owner_address)
.store_dict(null())
.store_ref(begin_cell().store_uint(1, 1).store_slice( domain).end_cell()) ;; TODO: snake cell
.store_ref(domain) ;; snake cell
.store_dict(null())
.store_uint(0, 64)
.end_cell();
@ -233,7 +231,8 @@ cell pack_nft_item_state(cell nft_item_code, cell data) impure {
.store_coins(0)
.store_uint(4 + 2 + 1, 1 + 4 + 4 + 64 + 32 + 1 + 1 + 1)
.store_ref(state_init)
.store_uint(1, 1); ;; the content of the NFT item, will be treated as the parameter of the first incoming message
.store_uint(1, 1)
.store_ref(begin_cell().store_uint(0x437dc408, 32).end_cell()); ;; the content of the NFT item, will be treated as the parameter of the first incoming message
send_raw_message(msg.end_cell(), 64); ;; carry all the remaining value of the inbound message, fee deducted from amount
}
@ -314,32 +313,30 @@ cell pack_nft_item_state(cell nft_item_code, cell data) impure {
store_data(content, item_code, index, collection_address, owner_address, domain, auction, last_fill_up_time);
}
if (op == op::init_after_buy()) {
return ();
}
if (op == op::instant_buy_new_nft()) {
;; parsing of the signed 'option'
;; signature structure: (receiver_addr, collection_address, )
cell option_data = in_msg_body~load_ref();
cell signature = in_msg_body~load_ref();
slice reader = option_data.begin_parse();
slice receiver_addr = reader~load_msg_addr();
slice issued_collection_addr = reader~load_msg_addr();
int amount = reader~load_uint(256);
slice new_domain = reader;
throw_unless(411, slice_bits(new_domain) > 0);
throw_unless(412, equal_slices(receiver_addr, sender_address)); ;; TODO: Unsure here
throw_unless(413, equal_slices(issued_collection_addr, my_address()));
int success = check_data_signature(option_data.begin_parse(), signature.begin_parse(), owner_address);
throw_unless(413, success);
throw_unless(414, msg_value > amount);
amount_to_send = msg_value - amount; ;; TODO: Handle this later, reroute coins
int new_item_index = slice_hash(new_domain);
deploy_bought_item(item_index, cell item_code, slice receiver_addr, slice new_domain);
;; signature structure: (receiver_addr, issued_collection_address, amount, domain)
slice signature = in_msg_body~load_bits(512);
int amount = in_msg_body~load_uint(256);
slice issued_collection_addr = my_address();
cell new_domain = in_msg_body~load_ref();
int public_key = get_public_key();
cell signed_data = begin_cell().store_slice(sender_address).store_slice(issued_collection_addr).store_uint(amount, 256).store_ref(new_domain).end_cell();
int hash = cell_hash(signed_data);
dump_stack();
int success? = check_signature(hash, signature, public_key);
throw_unless(413, success?);
throw_unless(414, msg_value >= amount);
int amount_to_send = msg_value - amount; ;; TODO: Handle this later, reroute coins
int new_item_index = cell_hash(new_domain);
deploy_bought_item(new_item_index, item_code, sender_address, new_domain);
return ();
;; init_state = pack_state(... add domain here ...)
;; use modified function `deploy_nft_item` <- init_state
}
if (op == op::new_nft()) {
throw_unless(401, equal_slices(sender_address, owner_address));
@ -356,7 +353,6 @@ cell pack_nft_item_state(cell nft_item_code, cell data) impure {
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 ();