contracts.wallets.custom-code.fc Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of smartcontract Show documentation
Show all versions of smartcontract Show documentation
Build and manipulate TON smart contracts in easy way.
;; Custom smart contract, wallet with extra field
() recv_internal(slice in_msg) impure {
;; do nothing for internal messages
}
() recv_external(slice in_msg) impure {
var signature = in_msg~load_bits(512); ;; signature in msg body, see createInitExternalMessage()
var cs = in_msg;
var (msg_seqno, valid_until, extra_field) = (cs~load_uint(32), cs~load_uint(32), cs~load_uint(64)); ;; payload in message body, see createSigningMessage()
throw_if(35, valid_until <= now());
var ds = get_data().begin_parse();
var (stored_seqno, public_key, stored_x_data) = (ds~load_uint(32), ds~load_uint(256), ds~load_uint(64)); ;; data in stateInit or in storage. See createDataCell()
ds.end_parse();
throw_unless(33, msg_seqno == stored_seqno);
throw_unless(34, check_signature(slice_hash(in_msg), signature, public_key));
accept_message();
cs~touch(); ;; process data stored in ext message refs
while (cs.slice_refs()) { ;; transfer msg. Data inside the body of external msg. See
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).store_uint(stored_x_data, 64).store_uint(extra_field, 64).end_cell());
}
;; Get methods
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);
}
int get_x_data() method_id {
var cs = get_data().begin_parse();
cs~load_uint(32);
cs~load_uint(256);
return cs.preload_uint(64);
}
int get_extra_field() method_id {
var cs = get_data().begin_parse();
cs~load_uint(32);
cs~load_uint(256);
cs~load_uint(64);
return cs.preload_uint(64);
}