From 1333478241248a59143ca8d24f2da6fdabeaf648 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Thu, 23 May 2024 22:34:07 +0300 Subject: [PATCH] unified syntax - register_promise unsafe warning trick --- .../tx_exec/tx_exec_async_promises.rs | 75 ++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/framework/base/src/types/interaction/tx_exec/tx_exec_async_promises.rs b/framework/base/src/types/interaction/tx_exec/tx_exec_async_promises.rs index ad8d8d4145..1e1dee40a4 100644 --- a/framework/base/src/types/interaction/tx_exec/tx_exec_async_promises.rs +++ b/framework/base/src/types/interaction/tx_exec/tx_exec_async_promises.rs @@ -1,6 +1,6 @@ use crate::{ api::{const_handles, CallTypeApi}, - contract_base::SendRawWrapper, + contract_base::{ErrorHelper, SendRawWrapper}, types::{ interaction::callback_closure::CallbackClosureWithGas, CallbackClosure, ExplicitGas, FunctionCall, ManagedBuffer, ManagedType, OriginalResultMarker, Tx, TxGas, TxGasValue, @@ -143,6 +143,20 @@ where GasValue: TxGasValue>, Callback: TxPromisesCallback, { + /// Launches a transaction as an asynchronous promise (async v2 mechanism). + /// + /// Several such transactions can be launched from a single transaction. + /// + /// Must set: + /// - to + /// - gas + /// - a function call, ideally via a proxy. + /// + /// Value-only promises are not supported. + /// + /// Optionally, can add: + /// - any payment + /// - a promise callback, which also needs explicit gas for callback. pub fn register_promise(self) { let callback_name = self.result_handler.callback_name(); let mut cb_closure_args_serialized = @@ -174,6 +188,65 @@ where } } +impl Tx, (), To, Payment, (), FunctionCall, Callback> +where + Api: CallTypeApi, + To: TxToSpecified>, + Payment: TxPayment>, + Callback: TxPromisesCallback, +{ + /// ## Incorrect call + /// + /// Must set **gas** in order to call `register_promise`. + /// + /// ## Safety + /// + /// This version of the method must never be called. It is only here to provide a more readable error. + pub unsafe fn register_promise(self) { + ErrorHelper::::signal_error_with_message("register_promise requires explicit gas"); + } +} + +impl Tx, (), To, Payment, (), (), Callback> +where + Api: CallTypeApi, + To: TxToSpecified>, + Payment: TxPayment>, + Callback: TxPromisesCallback, +{ + /// ## Incorrect call + /// + /// Must set **gas** and **function call** in order to call `register_promise`. + /// + /// ## Safety + /// + /// This version of the method must never be called. It is only here to provide a more readable error. + pub unsafe fn register_promise(self) { + ErrorHelper::::signal_error_with_message("register_promise requires explicit gas and function call"); + } +} + +impl + Tx, (), To, Payment, ExplicitGas, (), Callback> +where + Api: CallTypeApi, + To: TxToSpecified>, + Payment: TxPayment>, + GasValue: TxGasValue>, + Callback: TxPromisesCallback, +{ + /// ## Incorrect call + /// + /// Must set **function call** in order to call `register_promise`. + /// + /// ## Safety + /// + /// This version of the method must never be called. It is only here to provide a more readable error. + pub unsafe fn register_promise(self) { + ErrorHelper::::signal_error_with_message("register_promise requires function call"); + } +} + impl Tx, (), To, Payment, Gas, FunctionCall, Callback> where