Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix storage-provider.fc #788

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions storage/storage-daemon/smartcont/storage-provider.fc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,32 @@ cell build_storage_contract_stateinit(int merkle_hash, int file_size, int rate_p
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 @@ -223,8 +249,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);
}
}