@@ -328,60 +328,38 @@ cell create_price_feed_cell_chain(tuple price_feeds) {
328328 return result;
329329}
330330
331- () send_price_feeds_response(tuple price_feeds, int msg_value, int op, slice sender_address) impure {
331+ () send_price_feeds_response(tuple price_feeds, int msg_value, int op, slice sender_address, slice target_address, slice custom_payload ) impure {
332332 ;; Build response cell with price feeds
333333 builder response = begin_cell()
334334 .store_uint(op, 32) ;; Response op
335335 .store_uint(price_feeds.tlen(), 8); ;; Number of price feeds
336336
337337 ;; Create and store price feed cell chain
338338 cell price_feeds_cell = create_price_feed_cell_chain(price_feeds);
339- response = response.store_ref(price_feeds_cell);
340-
341- ;; Build the complete message cell (https://docs.ton.org/v3/documentation/smart-contracts/message-management/sending-messages#message-layout)
342- cell msg = begin_cell()
343- .store_uint(0x18, 6)
344- .store_slice(sender_address)
345- .store_coins(0) ;; Will fill in actual amount after fee calculations
346- .store_uint(1, 1 + 4 + 4 + 64 + 32 + 1 + 1)
347- .store_ref(response.end_cell())
348- .end_cell();
339+ cell custom_payload_cell = begin_cell().store_slice(custom_payload).end_cell();
340+ response = response.store_ref(price_feeds_cell).store_slice(sender_address).store_ref(custom_payload_cell);
349341
350342 int num_price_feeds = price_feeds.tlen();
351343
352- ;; Number of cells in the message
353- ;; - 2 cells: msg + response
354- int cells = 2 + num_price_feeds;
355-
356- ;; Bit layout per TL-B spec (https://github.com/ton-blockchain/ton/blob/master/crypto/block/block.tlb):
357- ;; - 6 bits: optimized way of serializing the tag and the first 4 fields
358- ;; - 256 bits: owner address
359- ;; - 128 bits: coins (VarUInteger 16) from grams$_ amount:(VarUInteger 16) = Grams
360- ;; - 107 bits: MSG_SERIALIZE_BITS
361- ;; - PRICE_FEED_BITS * num_price_feeds: space for each price feed
362- int bits = 6 + 256 + 128 + MSG_SERIALIZE_BITS + (PRICE_FEED_BITS * num_price_feeds);
363- int fwd_fee = get_forward_fee(cells, bits, WORKCHAIN);
364-
365344 ;; Calculate all fees
366345 int compute_fee = get_compute_fee(WORKCHAIN, get_gas_consumed());
367346 int update_fee = single_update_fee * price_feeds.tlen();
368347
369348 ;; Calculate total fees and remaining excess
370- int total_fees = compute_fee + update_fee + fwd_fee ;
349+ int total_fees = compute_fee + update_fee;
371350 int excess = msg_value - total_fees;
372351
373- ;; Send response message back to sender with exact excess amount
374352 send_raw_message(begin_cell()
375353 .store_uint(0x18, 6)
376- .store_slice(sender_address )
354+ .store_slice(target_address )
377355 .store_coins(excess)
378356 .store_uint(1, MSG_SERIALIZE_BITS)
379357 .store_ref(response.end_cell())
380358 .end_cell(),
381359 0);
382360}
383361
384- () parse_price_feed_updates(int msg_value, slice update_data_slice, slice price_ids_slice, int min_publish_time, int max_publish_time, slice sender_address) impure {
362+ () parse_price_feed_updates(int msg_value, slice update_data_slice, slice price_ids_slice, int min_publish_time, int max_publish_time, slice sender_address, slice target_address, slice custom_payload ) impure {
385363 load_data();
386364
387365 ;; Load price_ids tuple
@@ -393,10 +371,10 @@ cell create_price_feed_cell_chain(tuple price_feeds) {
393371 }
394372
395373 tuple price_feeds = parse_price_feeds_from_data(msg_value, update_data_slice, price_ids, min_publish_time, max_publish_time, false);
396- send_price_feeds_response(price_feeds, msg_value, OP_PARSE_PRICE_FEED_UPDATES, sender_address);
374+ send_price_feeds_response(price_feeds, msg_value, OP_PARSE_PRICE_FEED_UPDATES, sender_address, target_address, custom_payload );
397375}
398376
399- () parse_unique_price_feed_updates(int msg_value, slice update_data_slice, slice price_ids_slice, int publish_time, int max_staleness, slice sender_address) impure {
377+ () parse_unique_price_feed_updates(int msg_value, slice update_data_slice, slice price_ids_slice, int publish_time, int max_staleness, slice sender_address, slice target_address, slice custom_payload ) impure {
400378 load_data();
401379
402380 ;; Load price_ids tuple
@@ -408,7 +386,7 @@ cell create_price_feed_cell_chain(tuple price_feeds) {
408386 }
409387
410388 tuple price_feeds = parse_price_feeds_from_data(msg_value, update_data_slice, price_ids, publish_time, publish_time + max_staleness, true);
411- send_price_feeds_response(price_feeds, msg_value, OP_PARSE_UNIQUE_PRICE_FEED_UPDATES, sender_address);
389+ send_price_feeds_response(price_feeds, msg_value, OP_PARSE_UNIQUE_PRICE_FEED_UPDATES, sender_address, target_address, custom_payload );
412390}
413391
414392() update_price_feeds(int msg_value, slice data) impure {
0 commit comments