Skip to content

Commit

Permalink
Make body as ref
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerg1996 committed Apr 10, 2024
1 parent c28c408 commit 656e42b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 75 deletions.
56 changes: 10 additions & 46 deletions llvm/projects/ton-compiler/cpp-sdk/tvm/contract_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,11 @@ cell contract_call_prepare(address addr, Evers amount,
out_info.value = amount;

using est_t = estimate_element<message<decltype(hdr_plus_args)>>;
if constexpr (est_t::max_bits > cell::max_bits || est_t::max_refs > cell::max_refs) {
auto chain_tup = make_chain_tuple(hdr_plus_args);
message_relaxed<decltype(chain_tup)> out_msg;
out_msg.info = out_info;
out_msg.body = ref<decltype(chain_tup)>{chain_tup};
return build(out_msg).endc();
} else {
message_relaxed<decltype(hdr_plus_args)> out_msg;
out_msg.info = out_info;
out_msg.body = hdr_plus_args;
return build(out_msg).endc();
}
}

template<auto Func, class... Args>
Expand Down Expand Up @@ -192,18 +185,10 @@ cell external_call_prepare(address addr, uint256 pubkey, Args... args) {
};

using est_t = estimate_element<message<decltype(hdr_plus_args)>>;
if constexpr (est_t::max_bits > cell::max_bits || est_t::max_refs > cell::max_refs) {
auto chain_tup = make_chain_tuple(hdr_plus_args);
message_relaxed<decltype(chain_tup)> out_msg;
out_msg.info = msg_info;
out_msg.body = ref<decltype(chain_tup)>{chain_tup};
return build(out_msg).endc();
} else {
message_relaxed<decltype(hdr_plus_args)> out_msg;
out_msg.info = msg_info;
out_msg.body = hdr_plus_args;
return build(out_msg).endc();
}
}

// Prepare message cell for external call (should later be signed by debot engine)
Expand All @@ -226,18 +211,11 @@ cell external_call_prepare_nosign(address addr, uint256 pubkey, Args... args) {
};

using est_t = estimate_element<message<decltype(hdr_plus_args)>>;
if constexpr (est_t::max_bits > cell::max_bits || est_t::max_refs > cell::max_refs) {
auto chain_tup = make_chain_tuple(hdr_plus_args);
message_relaxed<decltype(chain_tup)> out_msg;
out_msg.info = msg_info;
out_msg.body = ref<decltype(chain_tup)>{chain_tup};
return build(out_msg).endc();
} else {
message_relaxed<decltype(hdr_plus_args)> out_msg;
out_msg.info = msg_info;
out_msg.body = hdr_plus_args;
return build(out_msg).endc();
}
}

// Prepare message cell for getter call (no signature/pubkey)
Expand All @@ -261,18 +239,11 @@ cell getter_call_prepare(address addr, Args... args) {
};

using est_t = estimate_element<message<decltype(hdr_plus_args)>>;
if constexpr (est_t::max_bits > cell::max_bits || est_t::max_refs > cell::max_refs) {
auto chain_tup = make_chain_tuple(hdr_plus_args);
message_relaxed<decltype(chain_tup)> out_msg;
out_msg.info = msg_info;
out_msg.body = ref<decltype(chain_tup)>{chain_tup};
return build(out_msg).endc();
} else {
message_relaxed<decltype(hdr_plus_args)> out_msg;
out_msg.info = msg_info;
out_msg.body = hdr_plus_args;
return build(out_msg).endc();
}
auto chain_tup = make_chain_tuple(hdr_plus_args);
message_relaxed<decltype(chain_tup)> out_msg;
out_msg.info = msg_info;
out_msg.body = ref<decltype(chain_tup)>{chain_tup};
return build(out_msg).endc();
}

// expire_val is used to place answer_id for debot external-in calls
Expand All @@ -298,18 +269,11 @@ cell external_call_prepare_with_pubkey(address addr, uint32 expire_val,
};

using est_t = estimate_element<message<decltype(hdr_plus_args)>>;
if constexpr (est_t::max_bits > cell::max_bits || est_t::max_refs > cell::max_refs) {
auto chain_tup = make_chain_tuple(hdr_plus_args);
message_relaxed<decltype(chain_tup)> out_msg;
out_msg.info = msg_info;
out_msg.body = ref<decltype(chain_tup)>{chain_tup};
return build(out_msg).endc();
} else {
message_relaxed<decltype(hdr_plus_args)> out_msg;
out_msg.info = msg_info;
out_msg.body = hdr_plus_args;
return build(out_msg).endc();
}
auto chain_tup = make_chain_tuple(hdr_plus_args);
message_relaxed<decltype(chain_tup)> out_msg;
out_msg.info = msg_info;
out_msg.body = ref<decltype(chain_tup)>{chain_tup};
return build(out_msg).endc();
}

template<auto Func, class... Args>
Expand Down
32 changes: 17 additions & 15 deletions llvm/projects/ton-compiler/cpp-sdk/tvm/emit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,38 @@

namespace tvm {

template<class Interface, class Func, class... Args>
using good_emit_args_t = decltype( (((Interface*)nullptr)->*(Func::value))(Args{}...) );
template<class Interface, auto Func, class... Args>
constexpr bool good_emit_args_v = std::experimental::is_detected_v<good_emit_args_t, Interface, proxy_method<Func>, Args...>;

template<class T>
struct extract_class : std::false_type {};
template<class R, class C, class... A>
struct extract_class<R (C::*)(A...)> {
template <class Interface, class Func, class... Args>
using good_emit_args_t =
decltype((((Interface *)nullptr)->*(Func::value))(Args{}...));
template <class Interface, auto Func, class... Args>
constexpr bool good_emit_args_v =
std::experimental::is_detected_v<good_emit_args_t, Interface,
proxy_method<Func>, Args...>;

template <class T> struct extract_class : std::false_type {};
template <class R, class C, class... A> struct extract_class<R (C::*)(A...)> {
using type = C;
};

template<auto EventPtr, class... Args>
void emit(Args... args) {
template <auto EventPtr, class... Args> void emit(Args... args) {
using Interface = typename extract_class<decltype(EventPtr)>::type;
static_assert(good_emit_args_v<Interface, EventPtr, Args...>, "Wrong emit arguments");
static_assert(good_emit_args_v<Interface, EventPtr, Args...>,
"Wrong emit arguments");

using namespace schema;

abiv1::external_outbound_msg_header hdr{ uint32(id_v<EventPtr>) };
abiv1::external_outbound_msg_header hdr{uint32(id_v<EventPtr>)};
auto hdr_plus_args = std::make_tuple(hdr, args...);
ext_out_msg_info_relaxed out_info;
out_info.src = addr_none{};
out_info.dest = addr_none{}; // TODO: which address to use as dest for events?
out_info.created_lt = 0;
out_info.created_at = 0;

message_relaxed<decltype(hdr_plus_args)> out_msg;
auto chain_tup = make_chain_tuple(hdr_plus_args);
message_relaxed<decltype(chain_tup)> out_msg;
out_msg.info = out_info;
out_msg.body = hdr_plus_args;
out_msg.body = ref<decltype(chain_tup)>{chain_tup};
tvm_sendmsg(build(out_msg).endc(), 0);
}

Expand Down
14 changes: 0 additions & 14 deletions llvm/projects/ton-compiler/cpp-sdk/tvm/smart_switcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,11 @@ __always_inline void send_external_answer(Contract& c, unsigned func_id, ReturnV
out_info.created_at = 0;

using est_t = estimate_element<message<decltype(hdr_plus_rv)>>;
if constexpr (est_t::max_bits > cell::max_bits || est_t::max_refs > cell::max_refs) {
auto chain_tup = make_chain_tuple(hdr_plus_rv);
message_relaxed<decltype(chain_tup)> out_msg;
out_msg.info = out_info;
out_msg.body = ref<decltype(chain_tup)>{chain_tup};
tvm_sendmsg(build(out_msg).endc(), 0);
} else {
message_relaxed<decltype(hdr_plus_rv)> out_msg;
out_msg.info = out_info;
out_msg.body = hdr_plus_rv;
tvm_sendmsg(build(out_msg).endc(), 0);
}
}

template<class Contract>
Expand Down Expand Up @@ -188,18 +181,11 @@ __always_inline void send_internal_answer(Contract& c, unsigned func_id, ReturnV
out_info.value = int_return_value(c);

using est_t = estimate_element<message<decltype(hdr_plus_rv)>>;
if constexpr (est_t::max_bits > cell::max_bits || est_t::max_refs > cell::max_refs) {
auto chain_tup = make_chain_tuple(hdr_plus_rv);
message_relaxed<decltype(chain_tup)> out_msg;
out_msg.info = out_info;
out_msg.body = ref<decltype(chain_tup)>{chain_tup};
tvm_sendmsg(build(out_msg).endc(), int_return_flag(c));
} else {
message_relaxed<decltype(hdr_plus_rv)> out_msg;
out_msg.info = out_info;
out_msg.body = hdr_plus_rv;
tvm_sendmsg(build(out_msg).endc(), int_return_flag(c));
}
}

template<bool Internal, bool ImplicitFuncId, class Contract, class ReturnValue>
Expand Down

0 comments on commit 656e42b

Please sign in to comment.