@@ -328,60 +328,38 @@ cell create_price_feed_cell_chain(tuple price_feeds) {
328
328
return result;
329
329
}
330
330
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 {
332
332
;; Build response cell with price feeds
333
333
builder response = begin_cell()
334
334
.store_uint(op, 32) ;; Response op
335
335
.store_uint(price_feeds.tlen(), 8); ;; Number of price feeds
336
336
337
337
;; Create and store price feed cell chain
338
338
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);
349
341
350
342
int num_price_feeds = price_feeds.tlen();
351
343
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
-
365
344
;; Calculate all fees
366
345
int compute_fee = get_compute_fee(WORKCHAIN, get_gas_consumed());
367
346
int update_fee = single_update_fee * price_feeds.tlen();
368
347
369
348
;; Calculate total fees and remaining excess
370
- int total_fees = compute_fee + update_fee + fwd_fee ;
349
+ int total_fees = compute_fee + update_fee;
371
350
int excess = msg_value - total_fees;
372
351
373
- ;; Send response message back to sender with exact excess amount
374
352
send_raw_message(begin_cell()
375
353
.store_uint(0x18, 6)
376
- .store_slice(sender_address )
354
+ .store_slice(target_address )
377
355
.store_coins(excess)
378
356
.store_uint(1, MSG_SERIALIZE_BITS)
379
357
.store_ref(response.end_cell())
380
358
.end_cell(),
381
359
0);
382
360
}
383
361
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 {
385
363
load_data();
386
364
387
365
;; Load price_ids tuple
@@ -393,10 +371,10 @@ cell create_price_feed_cell_chain(tuple price_feeds) {
393
371
}
394
372
395
373
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 );
397
375
}
398
376
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 {
400
378
load_data();
401
379
402
380
;; Load price_ids tuple
@@ -408,7 +386,7 @@ cell create_price_feed_cell_chain(tuple price_feeds) {
408
386
}
409
387
410
388
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 );
412
390
}
413
391
414
392
() update_price_feeds(int msg_value, slice data) impure {
0 commit comments