Skip to content

Commit

Permalink
fix storage-provider.fc
Browse files Browse the repository at this point in the history
  • Loading branch information
liminalAngel committed Oct 30, 2023
1 parent 019d226 commit 008060e
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions ton-drive-contracts/contracts/storage_provider.fc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

0 comments on commit 008060e

Please sign in to comment.