Lev
2 years ago
4 changed files with 136 additions and 10 deletions
@ -0,0 +1,86 @@
|
||||
;; This wrapper contract is used to be the interface to a domain managed by Agorata |
||||
|
||||
;; It makes it so that both the owner and the domain manager can call the functions of the contract -- with some permission management |
||||
|
||||
#pragma version >=0.2.0; |
||||
#include "imports/stdlib.fc"; |
||||
#include "imports/constants.fc"; |
||||
#include "imports/utils.fc"; |
||||
#include "imports/op-codes.fc"; |
||||
|
||||
;; Storage schema: |
||||
|
||||
;; Address contract: the domain owned by the wrapper |
||||
;; Address owner: the original domain owner |
||||
;; Address agorata: the address of the Agorata |
||||
|
||||
(slice, slice, slice) load_data() inline_ref { |
||||
slice ds = get_data().begin_parse(); |
||||
slice target = ds~load_msg_addr(); |
||||
slice owner = ds~load_msg_addr(); |
||||
slice agorata = ds~load_msg_addr(); |
||||
return (target, owner, agorata); |
||||
} |
||||
|
||||
() store_data(slice target, slice owner, slice agorata) impure inline_ref { |
||||
set_data( |
||||
begin_cell() |
||||
.store_slice(target) |
||||
.store_slice(owner) |
||||
.store_slice(agorata) |
||||
.end_cell()); |
||||
} |
||||
|
||||
() recv_internal(int my_balance, int msg_value, cell in_msg_full, slice in_msg_body) impure { |
||||
if (in_msg_body.slice_empty?()) { ;; bounce back empty messages |
||||
throw(0xffff); |
||||
} |
||||
;; handle internal messages |
||||
int op = in_msg_body~load_uint(32); |
||||
slice cs = in_msg_full.begin_parse(); |
||||
int flags = cs~load_uint(4); |
||||
|
||||
if (flags & 1) { ;; ignore all bounced messages |
||||
return (); |
||||
} |
||||
slice sender_address = cs~load_msg_addr(); |
||||
(slice target, slice owner, slice agorata) = load_data(); |
||||
if (equal_slices(sender_address, owner)) { |
||||
if ((op == op::transfer()) | (op == op::transfer_editorship())) { |
||||
;; todo: the owner can transfer the ownership, but only to Agorata (just like Agorata can transfer the ownership to the owner) |
||||
return (); |
||||
} |
||||
if (op == op::fill_up_wrapper()) { |
||||
;; do nothing |
||||
return (); |
||||
} |
||||
if (op == op::change_wrapper_code()) { |
||||
;; todo |
||||
} |
||||
;; otherwise, send the message to the target |
||||
} |
||||
} |
||||
|
||||
() send_msg(slice to_address, int amount, int op, int query_id, builder payload, int send_mode) impure inline { |
||||
var msg = begin_cell() |
||||
.store_uint(0x10, 6) ;; nobounce - int_msg_info$0 ihr_disabled:Bool bounce:Bool bounced:Bool src:MsgAddress -> 010000 |
||||
.store_slice(to_address) |
||||
.store_coins(amount) |
||||
.store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1) |
||||
.store_uint(op, 32) |
||||
.store_uint(query_id, 64); |
||||
|
||||
if (~ builder_null?(payload)) { |
||||
msg = msg.store_builder(payload); |
||||
} |
||||
|
||||
send_raw_message(msg.end_cell(), send_mode); |
||||
} |
||||
|
||||
() recv_external(slice in_msg_body) impure { |
||||
;; handle external messages |
||||
} |
||||
|
||||
_ get_owner() method_id { |
||||
|
||||
} |
Loading…
Reference in new issue