Skip to content

Instantly share code, notes, and snippets.

@isopen
Created March 9, 2023 05:57
Show Gist options
  • Save isopen/1ecf6922ba0a979cc017c4c07c4eccd2 to your computer and use it in GitHub Desktop.
Save isopen/1ecf6922ba0a979cc017c4c07c4eccd2 to your computer and use it in GitHub Desktop.
() recv_external(slice in_msg) impure {
var signature = in_msg~load_bits(512);
var cs = in_msg;
var (msg_seqno, valid_until, stored_seqno, public_key) = (cs~load_uint(32), cs~load_uint(32), get_data().begin_parse().load_uint(32), get_data().begin_parse().load_uint(256));
throw_if(35, valid_until <= now());
throw_unless(33, msg_seqno == stored_seqno);
throw_unless(34, check_signature(slice_hash(in_msg), signature, public_key));
accept_message();
cs~touch();
while (cs.slice_refs()) {
send_raw_message(cs~load_ref(), cs~load_uint(8));
}
cs.end_parse();
set_data(begin_cell().store_uint(stored_seqno + 1, 32).store_uint(public_key, 256).end_cell());
}
int seqno() method_id {
return get_data().begin_parse().preload_uint(32);
}
int get_public_key() method_id {
var cs = get_data().begin_parse();
cs~load_uint(32);
return cs.preload_uint(256);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment