Ton

Форк
0
60 строк · 2.1 Кб
1
int now() asm "NOW";
2

3
int cell_hash(cell c)
4
asm "HASHCU";
5

6
int slice_hash(slice s)
7
asm "HASHSU";
8

9
int check_signature(int hash, slice signature, int public_key)
10
asm "CHKSIGNU";
11

12
;; () throw_if(int excno, int cond) impure
13
;; asm "THROWARGIF";
14

15
cell get_data() asm "c4 PUSH";
16
() set_data(cell c) impure asm "c4 POP";
17
() accept_message() impure asm "ACCEPT";
18

19
slice begin_parse(cell c) asm "CTOS";
20
() end_parse(slice s) impure asm "ENDS";
21
(slice, cell) load_ref(slice s) asm( -> 1 0) "LDREF";
22
;; (slice, int) load_int(slice s, int len) asm(s len -> 1 0) "LDIX";
23
;; (slice, int) load_uint(slice s, int len) asm( -> 1 0) "LDUX";
24
;; int preload_int(slice s, int len) asm "PLDIX";
25
;; int preload_uint(slice s, int len) asm "PLDUX";
26
(slice, slice) load_bits(slice s, int len) asm(s len -> 1 0) "LDSLICEX";
27
slice preload_bits(slice s, int len) asm "PLDSLICEX";
28
cell set_idict_ref(cell dict, int key_len, int index, cell value) asm(value index dict key_len) "DICTISETREF";
29
builder begin_cell() asm "NEWC";
30
builder store_ref(builder b, cell c) asm(c b) "STREF";
31
;; builder store_uint(builder b, int x, int len) asm(x b len) "STUX";
32
;; builder store_int(builder b, int x, int len) asm(x b len) "STIX";
33
cell end_cell(builder b) asm "ENDC";
34

35
;; Simple configuration smart contract
36

37
() recv_internal(cell in_msg) impure {
38
  ;; do nothing for internal messages
39
}
40

41
() recv_external(cell in_msg) impure {
42
  var (cs0, signature) = load_bits(begin_parse(in_msg), 512);
43
  var (cs, msg_seqno) = load_uint(cs0, 32);
44
  (cs, var valid_until) = load_uint(cs, 32);
45
  throw_if(35, valid_until < now());
46
  var (cs2, cfg_dict) = load_ref(begin_parse(get_data()));
47
  (cs2, var stored_seqno) = load_uint(cs2, 32);
48
  (cs2, var public_key) = load_uint(cs2, 256);
49
  end_parse(cs2);
50
  throw_unless(33, msg_seqno == stored_seqno);
51
  throw_unless(34, check_signature(slice_hash(cs0), signature, public_key));
52
  accept_message();
53
  (cs, var param_index) = load_uint(cs, 32);
54
  (cs, var param_value) = load_ref(cs);
55
  end_parse(cs);
56
  var cb = store_ref(begin_cell(), set_idict_ref(cfg_dict, 32, param_index, param_value));
57
  cb = store_uint(cb, stored_seqno + 1, 32);
58
  cb = store_uint(cb, public_key, 256);
59
  set_data(end_cell(cb));
60
}
61

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.