Skip to content

Commit

Permalink
try 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Skydev0h committed Dec 26, 2023
1 parent 9ee8a17 commit d95d1a1
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions contracts/task3.fc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
;; You may delete and rewrite as needed,
;; but the final implementation must adhere to the same structure

{-
cell get_storage() inline {
slice cs = get_data().begin_parse();

Expand All @@ -22,6 +23,7 @@ cell get_storage() inline {

return storage;
}
-}

cell wrap_storage(int version_id, cell storage) inline {
;; add additional data required for versioning in this cell
Expand Down Expand Up @@ -58,6 +60,11 @@ cell migrate_one(cell old_storage) { ;; it's just a placeholder that is required
() recv_internal(int msg_value, int balance, cell in_msg_full, slice in_msg_body) impure {
int expected_version = in_msg_body~load_uint(32);

;; ---
;; here you should check if it's the first call or not based on `expected_version` as stated in the task
;; if it is the first call, wrap the storage and finish execution by returning from the function
;; ---

if (expected_version == 0) {
set_data(wrap_storage(1, get_data().begin_parse().preload_ref()));
return();
Expand All @@ -71,12 +78,38 @@ cell migrate_one(cell old_storage) { ;; it's just a placeholder that is required
int version = ds.preload_uint(32);
cell storage = ds.preload_ref();

;; ---
;; here you should check if it's the first call or not based on `expected_version` as stated in the task
;; if it is the first call, wrap the storage and finish execution by returning from the function
;; ---
throw_if(200, expected_version < version);

int setcode = false;
if (expected_version > version) {
throw_if(200, expected_code.null?());
setcode = true;
}

while (version < expected_version) {
(slice mig, int found) = migrations.udict_get?(32, version);
throw_unless(400, found);
int next = mig~load_uint(32);
cell mc = mig.preload_maybe_ref();
ifnot (mc.null?()) {
set_c3(mc.begin_parse().bless());
storage = migrate_one(storage);
}
version = next;
}

throw_if(200, version > expected_version);

if (setcode) {
set_code(expected_code);
set_c3(expected_code.begin_parse().bless());
}

storage = process_message(storage, msg_value, balance, in_msg_full, payload.begin_parse());

set_data(wrap_storage(expected_version, storage));
set_data(begin_cell()
.store_uint(version, 32)
.store_ref(storage)
.end_cell()
);
}

0 comments on commit d95d1a1

Please sign in to comment.