Skip to content

Commit 9a7a1d4

Browse files
committed
reinstated update_price_feeds function
1 parent 04906de commit 9a7a1d4

File tree

1 file changed

+54
-101
lines changed
  • target_chains/fuel/contracts/pyth-contract/src

1 file changed

+54
-101
lines changed

target_chains/fuel/contracts/pyth-contract/src/main.sw

Lines changed: 54 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -272,56 +272,7 @@ impl PythCore for Contract {
272272

273273
#[storage(read, write), payable]
274274
fn update_price_feeds(update_data: Vec<Bytes>) {
275-
require(
276-
msg_asset_id() == AssetId::base(),
277-
PythError::FeesCanOnlyBePaidInTheBaseAsset,
278-
);
279-
280-
let mut total_number_of_updates = 0;
281-
282-
// let mut updated_price_feeds: Vec<PriceFeedId> = Vec::new(); // TODO: requires append for Vec
283-
let mut i = 0;
284-
while i < update_data.len() {
285-
let data = update_data.get(i).unwrap();
286-
287-
match UpdateType::determine_type(data) {
288-
UpdateType::Accumulator(accumulator_update) => {
289-
let (number_of_updates, _updated_ids) = accumulator_update.update_price_feeds(
290-
current_guardian_set_index(),
291-
storage
292-
.wormhole_guardian_sets,
293-
storage
294-
.latest_price_feed,
295-
storage
296-
.is_valid_data_source,
297-
);
298-
// updated_price_feeds.append(updated_ids); // TODO: requires append for Vec
299-
total_number_of_updates += number_of_updates;
300-
},
301-
UpdateType::BatchAttestation(batch_attestation_update) => {
302-
let _updated_ids = batch_attestation_update.update_price_feeds(
303-
current_guardian_set_index(),
304-
storage
305-
.wormhole_guardian_sets,
306-
storage
307-
.latest_price_feed,
308-
storage
309-
.is_valid_data_source,
310-
);
311-
// updated_price_feeds.append(updated_ids); // TODO: requires append for Vec
312-
total_number_of_updates += 1;
313-
},
314-
}
315-
316-
i += 1;
317-
}
318-
319-
let required_fee = total_fee(total_number_of_updates, storage.single_update_fee);
320-
require(msg_amount() >= required_fee, PythError::InsufficientFee);
321-
322-
// log(UpdatedPriceFeedsEvent { // TODO: requires append for Vec
323-
// updated_price_feeds,
324-
// })
275+
325276
}
326277

327278
#[storage(read, write), payable]
@@ -341,57 +292,7 @@ impl PythCore for Contract {
341292
while i < price_feed_ids.len() {
342293
if latest_publish_time(price_feed_ids.get(i).unwrap()) < publish_times.get(i).unwrap()
343294
{
344-
require(
345-
msg_asset_id() == AssetId::base(),
346-
PythError::FeesCanOnlyBePaidInTheBaseAsset,
347-
);
348-
349-
let mut total_number_of_updates = 0;
350-
351-
// let mut updated_price_feeds: Vec<PriceFeedId> = Vec::new(); // TODO: requires append for Vec
352-
let mut i = 0;
353-
while i < update_data.len() {
354-
let data = update_data.get(i).unwrap();
355-
356-
match UpdateType::determine_type(data) {
357-
UpdateType::Accumulator(accumulator_update) => {
358-
let (number_of_updates, _updated_ids) = accumulator_update.update_price_feeds(
359-
current_guardian_set_index(),
360-
storage
361-
.wormhole_guardian_sets,
362-
storage
363-
.latest_price_feed,
364-
storage
365-
.is_valid_data_source,
366-
);
367-
// updated_price_feeds.append(updated_ids); // TODO: requires append for Vec
368-
total_number_of_updates += number_of_updates;
369-
},
370-
UpdateType::BatchAttestation(batch_attestation_update) => {
371-
let _updated_ids = batch_attestation_update.update_price_feeds(
372-
current_guardian_set_index(),
373-
storage
374-
.wormhole_guardian_sets,
375-
storage
376-
.latest_price_feed,
377-
storage
378-
.is_valid_data_source,
379-
);
380-
// updated_price_feeds.append(updated_ids); // TODO: requires append for Vec
381-
total_number_of_updates += 1;
382-
},
383-
}
384-
385-
i += 1;
386-
}
387-
388-
let required_fee = total_fee(total_number_of_updates, storage.single_update_fee);
389-
require(msg_amount() >= required_fee, PythError::InsufficientFee);
390-
391-
// log(UpdatedPriceFeedsEvent { // TODO: requires append for Vec
392-
// updated_price_feeds,
393-
// })
394-
return;
295+
update_price_feeds(update_data);
395296
}
396297

397298
i += 1;
@@ -472,6 +373,58 @@ fn update_fee(update_data: Vec<Bytes>) -> u64 {
472373
total_fee(total_number_of_updates, storage.single_update_fee)
473374
}
474375

376+
#[storage(read, write)]
377+
fn update_price_feeds(update_data: Vec<Bytes>) {
378+
require(
379+
msg_asset_id() == AssetId::base(),
380+
PythError::FeesCanOnlyBePaidInTheBaseAsset,
381+
);
382+
383+
let required_fee = update_fee(update_data);
384+
require(msg_amount() >= required_fee, PythError::InsufficientFee);
385+
386+
let mut total_number_of_updates = 0;
387+
388+
let mut i = 0;
389+
while i < update_data.len() {
390+
let data = update_data.get(i).unwrap();
391+
392+
match UpdateType::determine_type(data) {
393+
UpdateType::Accumulator(accumulator_update) => {
394+
let (number_of_updates, updated_ids) = accumulator_update.update_price_feeds(
395+
current_guardian_set_index(),
396+
storage
397+
.wormhole_guardian_sets,
398+
storage
399+
.latest_price_feed,
400+
storage
401+
.is_valid_data_source,
402+
);
403+
total_number_of_updates += number_of_updates;
404+
log(UpdatedPriceFeedsEvent { updated_price_feeds: updated_ids });
405+
},
406+
UpdateType::BatchAttestation(batch_attestation_update) => {
407+
let updated_ids = batch_attestation_update.update_price_feeds(
408+
current_guardian_set_index(),
409+
storage
410+
.wormhole_guardian_sets,
411+
storage
412+
.latest_price_feed,
413+
storage
414+
.is_valid_data_source,
415+
);
416+
total_number_of_updates += 1;
417+
log(UpdatedPriceFeedsEvent { updated_price_feeds: updated_ids });
418+
},
419+
}
420+
421+
i += 1;
422+
}
423+
424+
let fee = total_fee(total_number_of_updates, storage.single_update_fee);
425+
require(msg_amount() >= fee, PythError::InsufficientFee);
426+
}
427+
475428
#[storage(read)]
476429
fn valid_time_period() -> u64 {
477430
storage.valid_time_period_seconds.read()

0 commit comments

Comments
 (0)