Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mobile): Holders review fixes #781

Draft
wants to merge 15 commits into
base: develop
Choose a base branch
from

Conversation

voloshinskii
Copy link
Contributor

No description provided.

@JanKortes212
Copy link

ok

Copy link

@hossen71 hossen71 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4111fd9e3313ec17d99ca9b5b1656445b5b49d8f

@hossen71
Copy link

UQA5NWl5eH6KvxwnMBCj7vDbb-Xebok-pWGfFuHhq1zMxmv5

@KKR321
Copy link

KKR321 commented Dec 20, 2024

;; Simple wallet smart contract with plugins

(slice, int) dict_get?(cell dict, int key_len, slice index) asm(index dict key_len) "DICTGET" "NULLSWAPIFNOT";
(cell, int) dict_add_builder?(cell dict, int key_len, slice index, builder value) asm(value index dict key_len) "DICTADDB";
(cell, int) dict_delete?(cell dict, int key_len, slice index) asm(index dict key_len) "DICTDEL";

() recv_internal(cell in_msg_cell, slice in_msg) impure {
var cs = in_msg_cell.begin_parse();
var flags = csload_uint(4); ;; int_msg_info$0 ihr_disabled:Bool bounce:Bool bounced:Bool
if (flags & 1) {
;; ignore all bounced messages
return ();
}
if((in_msg.slice_bits() < 32) || (in_msg
load_uint(32) != 0x706c7567)) { ;; "plug" prefix
;; ignore all messages withour request subscription op
return ();
}
slice s_addr = csload_msg_addr();
(int wc, int addr_hash) = parse_std_addr(s_addr);
var ds = get_data().begin_parse();
var (unused, plugins) = (ds
load_bits(32 + 32 + 256), dsload_dict());
var (v, success?) = plugins.dict_get?( 8 + 256, begin_cell().store_int(wc, 8).store_uint(addr_hash, 256).end_cell().begin_parse());
throw_unless(40, success?);
accept_message();
(int toncoins, cell extra) = (in_msg
load_grams(), in_msg~load_dict());
;; TODO check that we have enough money and send notification if not
var msg = begin_cell()
.store_uint(0x18, 6)
.store_slice(s_addr)
.store_grams(toncoins)
.store_dict(extra)
.store_uint(0, 4 + 4 + 64 + 32 + 1 + 1)
.store_uint(0x706c7567,32);
send_raw_message(msg.end_cell(), 1);
}

() recv_external(slice in_msg) impure {
var signature = in_msgload_bits(512);
var cs = in_msg;
var (subwallet_id, valid_until, msg_seqno) = (cs
load_uint(32), csload_uint(32), csload_uint(32));
throw_if(35, valid_until <= now());
var ds = get_data().begin_parse();
var (stored_seqno, stored_subwallet, public_key, plugins) = (dsload_uint(32), dsload_uint(32), dsload_uint(256), dsload_dict());
ds.end_parse();
throw_unless(33, msg_seqno == stored_seqno);
throw_unless(34, subwallet_id == stored_subwallet);
throw_unless(35, check_signature(slice_hash(in_msg), signature, public_key));
accept_message();
cstouch();
int op = cs
load_uint(8);
if (op == 0) { ;; simple send
while (cs.slice_refs()) {
var mode = csload_uint(8);
send_raw_message(cs
load_ref(), mode);
}
}
if (op == 1) { ;; deploy and install plugin
int plugin_workchain = csload_int(8);
int plugin_balance = cs
load_grams();
(cell state_init, cell body) = (csload_ref(), csload_ref());
int plugin_address = cell_hash(state_init);
slice wc_n_address = begin_cell().store_int(plugin_workchain,8).store_uint(plugin_address,256).end_cell().begin_parse();
var msg = begin_cell()
.store_uint(0x18, 6)
.store_uint(4,3).store_slice(wc_n_address)
.store_grams(plugin_balance)
.store_uint(4 + 2 + 1, 1 + 4 + 4 + 64 + 32 + 1 + 1 + 1)
.store_ref(state_init)
.store_ref(body);
send_raw_message(msg.end_cell(), 1);
(plugins, int success?) = plugins.dict_add_builder?(8 + 256, wc_n_address, begin_cell());
throw_unless(39, success?);
}

if (op == 2) { ;; install plugin
slice wc_n_address = cs~load_bits(8 + 256);
(plugins, int success?) = plugins.dict_add_builder?(8 + 256, wc_n_address, begin_cell());
throw_unless(39, success?);
;; TODO notify plugin
}

if (op == 2) { ;; remove plugin
slice wc_n_address = cs~load_bits(8 + 256);
(plugins, int success?) = plugins.dict_delete?(8 + 256, wc_n_address);
throw_unless(39, success?);
;;TODO request self-destruct
}

set_data(begin_cell()
.store_uint(stored_seqno + 1, 32)
.store_uint(stored_subwallet, 32)
.store_uint(public_key, 256)
.store_dict(plugins)
.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(64);
return cs.preload_uint(256);
}

int is_plugin_installed(int wc, int addr_hash) method_id {
var ds = get_data().begin_parse();
var (unused, plugins) = (dsload_bits(32 + 32 + 256), dsload_dict());
var (v, success?) = plugins.dict_get?( 8 + 256, begin_cell().store_int(wc, 8).store_uint(addr_hash, 256).end_cell().begin_parse());
return success?;
}

tuple get_plugin_list() method_id {
var list = null();
var ds = get_data().begin_parse();
var (unused, plugins) = (dsload_bits(32 + 32 + 256), dsload_dict());
do {
var (load_dict, wc_n_address, value, f) = plugins.dict_delete_get_min( 8 + 256 );
ftouch();
if (f) {
(int wc, int addr) = (wc_n_address
load_int(8), wc_n_addressload_uint(256));
list = cons(pair(wc, addr), list);
}
} until (
f);
return list;
}

Copy link

@mostafa3100 mostafa3100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

اعمال همه تغییرات

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants