Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
Skydev0h committed Dec 23, 2023
1 parent 1fc3b66 commit f6ba0af
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 5 deletions.
1 change: 1 addition & 0 deletions contracts/task1.fc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ int getter(int id) method_id(111) {
if (id == 77871) { ;; get_seqno
return get_data().begin_parse().skip_bits(256 + 32 + 3 + 8 + 256).preload_uint(32);
}
;; get_execution_time
return get_data().begin_parse().skip_bits(256).preload_uint(32);
}

Expand Down
16 changes: 12 additions & 4 deletions contracts/task2.fc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ int equal_slices?(slice a, slice b) asm "SDEQ";

() recv_internal(int my_balance, int msg_value, cell in_msg_full, slice in_msg_body) impure {

if (in_msg_body~is_add_user_call()) {
int op = in_msg_body~load_uint(32);

;; if (in_msg_body~is_add_user_call()) {
if (op == 0x368ddef3) {

slice data = get_data().begin_parse();
slice admin_address = data~load_msg_addr();
Expand All @@ -41,7 +44,8 @@ int equal_slices?(slice a, slice b) asm "SDEQ";

}

if (in_msg_body~is_split_call()) {
;; if (in_msg_body~is_split_call()) {
if (op == 0x068530b3) {

slice data = get_data().begin_parse();
data~load_msg_addr();
Expand Down Expand Up @@ -86,7 +90,8 @@ int equal_slices?(slice a, slice b) asm "SDEQ";

}

if (in_msg_body~is_remove_user_call()) {
;; if (in_msg_body~is_remove_user_call()) {
if (op == 0x278205c8) {

slice data = get_data().begin_parse();
slice admin_address = data~load_msg_addr();
Expand All @@ -111,7 +116,10 @@ int equal_slices?(slice a, slice b) asm "SDEQ";

}

in_msg_body~is_transfer_notification_call_or_ret();
;; in_msg_body~is_transfer_notification_call_or_ret();
if (op != 0x7362d09c) {
return ();
}

slice data = get_data().begin_parse();
data~load_msg_addr();
Expand Down
80 changes: 79 additions & 1 deletion contracts/task3.fc
Original file line number Diff line number Diff line change
@@ -1,5 +1,83 @@
#include "imports/stdlib.fc";

() recv_internal(int my_balance, int msg_value, cell in_msg_full, slice in_msg_body) impure {
;; All the code in recv_internal, get_storage, wrap_storage, and version
;; serves as an example of the intended structure.

;; The provided code is an "empty wrapper." It:
;; + Parses "wrapped" incoming messages (discards versioning information)
;; + "Wraps" the call to the version-specific process_message
;; + Implements "get_storage" for version-specific get-methods
;; However, it does not yet implement any upgrade logic, which is your task.

;; The empty wrapper is provided to demonstrate
;; how version-specific code is intended to be "wrapped" and interacted with.
;; 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();

;; Logic to extract the storage on which the version-specific process_message and get-methods operate
cell storage = cs~load_ref();

return storage;
}

cell wrap_storage(int version_id, cell storage) inline {
;; add additional data required for versioning in this cell
return begin_cell()
.store_uint(version_id, 32)
.store_ref(storage)
.end_cell();
}

;; Return the current version of the smart contract
int version() method_id {
return get_data().begin_parse().preload_uint(32);
}

;; <<<<< Custom version-specific code begins
;; This section (everything between << and >> characters) will be fully substituted for each version.
;; This is an IMPORTANT part, and these exact lines with <<<<< and >>>>> must be present in your code for the testing system to work correctly.
;; All the code provided here serves as an example of the version-code, which your update code must be compatible with.
;; Refer to the "3-example" directory for more version examples.

;; from counter-v0.fc
cell process_message(cell storage, int msg_value, int balance, cell in_msg_full, slice in_msg_body) impure {
slice cs = storage.begin_parse();
int current_amount = cs.preload_uint(32);
return begin_cell().store_uint(current_amount + 1, 32).end_cell();
}

cell migrate_one(cell old_storage) { ;; it's just a placeholder that is required for correct compilation
return old_storage;
}

;; Custom version-specific code ends >>>>>

() 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);
cell expected_code = in_msg_body~load_maybe_ref();
cell migrations = in_msg_body~load_dict();
cell payload = in_msg_body~load_ref();

slice ds = get_data().begin_parse();
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
;; ---

if (expected_version == 0) {
set_data(wrap_storage(1, get_data().begin_parse().preload_ref()));
return();
}



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

set_data(wrap_storage(expected_version, storage));
}

0 comments on commit f6ba0af

Please sign in to comment.