1
0
mirror of https://github.com/danog/ton.git synced 2024-11-26 20:14:55 +01:00
ton/crypto/smartcont/wallet-code.fc

32 lines
932 B
Plaintext
Raw Normal View History

2019-09-07 12:03:22 +02:00
;; Simple wallet smart contract
() recv_internal(slice in_msg) impure {
;; do nothing for internal messages
}
() recv_external(slice in_msg) impure {
var signature = in_msg~load_bits(512);
var cs = in_msg;
var (msg_seqno, valid_until) = (cs~load_uint(32), cs~load_uint(32));
2019-09-07 12:03:22 +02:00
throw_if(35, valid_until < now());
var ds = get_data().begin_parse();
var (stored_seqno, public_key) = (ds~load_uint(32), ds~load_uint(256));
ds.end_parse();
2019-09-07 12:03:22 +02:00
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()) {
var mode = cs~load_uint(8);
send_raw_message(cs~load_ref(), mode);
}
cs.end_parse();
set_data(begin_cell().store_uint(stored_seqno + 1, 32).store_uint(public_key, 256).end_cell());
}
;; Get methods
int seqno() method_id {
return get_data().begin_parse().preload_uint(32);
}