From 008060eb225d16372f62ba16ee9e311565f68c08 Mon Sep 17 00:00:00 2001 From: Admin Date: Mon, 30 Oct 2023 23:34:55 +0400 Subject: [PATCH] fix storage-provider.fc --- .../contracts/storage_provider.fc | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/ton-drive-contracts/contracts/storage_provider.fc b/ton-drive-contracts/contracts/storage_provider.fc index 23a6b87..be8eef9 100644 --- a/ton-drive-contracts/contracts/storage_provider.fc +++ b/ton-drive-contracts/contracts/storage_provider.fc @@ -44,6 +44,32 @@ int max_span, slice client, int torrent_hash) { return state_init; } +cell calculate_storage_contract_stateinit(int merkle_hash, int file_size, int rate_per_mb_day, + int max_span, int last_proof_time, slice client, int torrent_hash) { + cell data = begin_cell() + .store_int(0, 1) ;; active + .store_coins(0) ;; client balance + .store_slice(my_address()) + .store_uint(merkle_hash, 256) + .store_uint(file_size, 64) + .store_uint(0, 64) ;; next_proof + .store_coins(rate_per_mb_day) + .store_uint(max_span, 32) + .store_uint(last_proof_time, 32) ;; last_proof_time + .store_ref(begin_cell() + .store_slice(client) + .store_uint(torrent_hash, 256) + .end_cell()) + .end_cell(); + + cell state_init = begin_cell() + .store_uint(0, 2) + .store_maybe_ref(storage_contract_code()) + .store_maybe_ref(data) + .store_uint(0, 1) .end_cell(); + return state_init; +} + () deploy_storage_contract (slice client, int query_id, int file_size, int merkle_hash, int torrent_hash, int expected_rate, int expected_max_span) impure { var ds = get_data().begin_parse(); @@ -224,8 +250,8 @@ _ get_storage_params() method_id { return (accept_new_contracts?, rate_per_mb_day, max_span, minimal_file_size, maximal_file_size); } -slice get_storage_contract_address(int merkle_hash, int file_size, slice client, int torrent_hash) method_id { +slice get_storage_contract_address(int merkle_hash, int file_size, int last_proof_time, slice client, int torrent_hash) method_id { var (_, rate_per_mb_day, max_span, _, _) = get_storage_params(); - cell state_init = build_storage_contract_stateinit(merkle_hash, file_size, rate_per_mb_day, max_span, client, torrent_hash); + cell state_init = calculate_storage_contract_stateinit(merkle_hash, file_size, rate_per_mb_day, max_span, last_proof_time, client, torrent_hash); return calculate_address_by_stateinit(state_init); }