Skip to content

Commit f9c0550

Browse files
committed
trying out 1 price feed test case
1 parent cfb1ee9 commit f9c0550

File tree

3 files changed

+563
-58
lines changed

3 files changed

+563
-58
lines changed

target_chains/ton/contracts/contracts/common/utils.fc

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -77,46 +77,66 @@ Note:
7777
- If the input data exceeds 1016 bits, it is split into multiple cells linked by references
7878
- Uses direct forward construction to avoid gas-inefficient double reversal
7979
-}
80-
(cell, slice) read_and_store_large_data(slice in_msg_body, int size) {
81-
;; Collect chunks in order as we build them
82-
tuple chunk_list = empty_tuple();
83-
int total_bits_loaded = 0;
84-
builder current_builder = begin_cell();
80+
;; (cell, slice) read_and_store_large_data(slice in_msg_body, int size) {
81+
;; ;; Collect chunks in order as we build them
82+
;; tuple chunk_list = empty_tuple();
83+
;; int total_bits_loaded = 0;
84+
;; builder current_builder = begin_cell();
8585

86-
while ((~ in_msg_body.slice_empty?()) & (total_bits_loaded < size)) {
87-
int bits_to_load = min(min(in_msg_body.slice_bits(), MAX_BITS - current_builder.builder_bits()), size - total_bits_loaded);
88-
current_builder = current_builder.store_slice(in_msg_body~load_bits(bits_to_load));
89-
total_bits_loaded += bits_to_load;
86+
;; while ((~ in_msg_body.slice_empty?()) & (total_bits_loaded < size)) {
87+
;; int bits_to_load = min(min(in_msg_body.slice_bits(), MAX_BITS - current_builder.builder_bits()), size - total_bits_loaded);
88+
;; current_builder = current_builder.store_slice(in_msg_body~load_bits(bits_to_load));
89+
;; total_bits_loaded += bits_to_load;
9090

91-
if ((current_builder.builder_bits() == MAX_BITS) | (size - total_bits_loaded == 0)) {
92-
cell current_chunk = current_builder.end_cell();
93-
chunk_list~tpush(current_chunk);
94-
current_builder = begin_cell();
95-
}
91+
;; if ((current_builder.builder_bits() == MAX_BITS) | (size - total_bits_loaded == 0)) {
92+
;; cell current_chunk = current_builder.end_cell();
93+
;; chunk_list~tpush(current_chunk);
94+
;; current_builder = begin_cell();
95+
;; }
9696

97-
if ((in_msg_body.slice_bits() == 0) & (~ in_msg_body.slice_refs_empty?())) {
98-
in_msg_body = in_msg_body~load_ref().begin_parse();
99-
}
100-
}
97+
;; if ((in_msg_body.slice_bits() == 0) & (~ in_msg_body.slice_refs_empty?())) {
98+
;; in_msg_body = in_msg_body~load_ref().begin_parse();
99+
;; }
100+
;; }
101101

102-
;; Build forward chain: first chunk → second chunk → third chunk etc
103-
cell result = null();
104-
int chunk_count = chunk_list.tlen();
102+
;; ;; Build forward chain: first chunk → second chunk → third chunk etc
103+
;; cell result = null();
104+
;; int chunk_count = chunk_list.tlen();
105105

106-
if (chunk_count > 0) {
107-
;; Start from the last chunk (no references)
108-
result = chunk_list.at(chunk_count - 1);
106+
;; if (chunk_count > 0) {
107+
;; ;; Start from the last chunk (no references)
108+
;; result = chunk_list.at(chunk_count - 1);
109109

110-
;; Build forward by adding references from earlier chunks to later chunks
111-
int i = chunk_count - 2;
112-
while (i >= 0) {
113-
cell current_chunk = chunk_list.at(i);
114-
result = begin_cell().store_slice(current_chunk.begin_parse()).store_ref(result).end_cell();
115-
i -= 1;
110+
;; ;; Build forward by adding references from earlier chunks to later chunks
111+
;; int i = chunk_count - 2;
112+
;; while (i >= 0) {
113+
;; cell current_chunk = chunk_list.at(i);
114+
;; result = begin_cell().store_slice(current_chunk.begin_parse()).store_ref(result).end_cell();
115+
;; i -= 1;
116+
;; }
117+
;; }
118+
119+
;; return (result, in_msg_body);
120+
;; }
121+
122+
(cell, slice) read_and_store_large_data(slice in_msg_body, int size) {
123+
(cell chunks, slice remaining) = split_into_reverse_chunks(in_msg_body, size);
124+
cell last_cell = null();
125+
while (~ cell_null?(chunks)) {
126+
slice chunk = chunks.begin_parse();
127+
builder cb = begin_cell().store_slice(chunk~load_bits(chunk.slice_bits()));
128+
if (~ cell_null?(last_cell)) {
129+
cb = cb.store_ref(last_cell);
130+
}
131+
last_cell = cb.end_cell();
132+
if (chunk.slice_refs_empty?()) {
133+
chunks = null();
134+
} else {
135+
chunks = chunk~load_ref();
116136
}
117137
}
118-
119-
return (result, in_msg_body);
138+
139+
return (last_cell, remaining);
120140
}
121141

122142
(int) pubkey_to_eth_address(int x1, int x2) {

0 commit comments

Comments
 (0)