2024-12-08 21:57:35 +03:00

107 lines
2.4 KiB
Plaintext

#pragma version ^0.4.1;
#include "../imports/stdlib.fc";
#include "../utils/Constants.fc";
#include "./Math.fc";
;; Constants remain same
;; Error codes remain same
;; Helper function for sender
slice get_sender() inline {
var cs = get_current_slice();
cs~skip_bits(4);
return cs~load_msg_addr();
}
;; Helper function for slice comparison
int equal_slices(slice s1, slice s2) inline {
return slice_hash(s1) == slice_hash(s2);
}
;; Storage variables
global slice owner;
global slice guardian;
global int last_action;
global int nonce;
global int paused;
global cell rate_limits;
global cell operations;
global cell blacklist;
global int entered;
() load_data() impure {
slice ds = get_data().begin_parse();
owner = ds~load_msg_addr();
guardian = ds~load_msg_addr();
last_action = ds~load_uint(64);
nonce = ds~load_uint(32);
paused = ds~load_uint(1);
rate_limits = ds~load_dict();
operations = ds~load_dict();
blacklist = ds~load_dict();
entered = ds~load_uint(1);
}
() save_data() impure {
set_data(begin_cell()
.store_slice(owner)
.store_slice(guardian)
.store_uint(last_action, 64)
.store_uint(nonce, 32)
.store_uint(paused, 1)
.store_dict(rate_limits)
.store_dict(operations)
.store_dict(blacklist)
.store_uint(entered, 1)
.end_cell());
}
() check_owner() impure inline {
slice sender = get_sender();
throw_unless(error::unauthorized, equal_slices(sender, owner));
}
() check_not_paused() impure inline {
throw_if(error::paused, paused != 0);
}
() prevent_reentrancy() impure inline {
throw_if(error::reentrancy, entered != 0);
entered = 1;
}
() check_rate_limit(int operation) impure {
}
;; Validation functions
() validate_amount(int amount) impure inline {
throw_if(error_invalid_nonce, amount <= 0);
throw_if(error_invalid_nonce, amount > MAX_UINT128);
}
() validate_signature(slice msg, slice signature, int public_key) impure inline {
;; Convert message to cell for hashing
cell msg_cell = begin_cell().store_slice(msg).end_cell();
throw_unless(error_invalid_sig, check_signature(
cell_hash(msg_cell),
signature,
public_key
));
}
;; Get methods
int get_paused() method_id {
load_data();
return paused;
}
slice get_owner() method_id {
load_data();
return owner;
}
slice get_guardian() method_id {
load_data();
return guardian;
}