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

feat: return any value type from execute_contract_allow_private #4520

Merged
merged 4 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions clarity/src/vm/callables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ impl DefinedFunction {
pub fn apply(&self, args: &[Value], env: &mut Environment) -> Result<Value> {
match self.define_type {
DefineType::Private => self.execute_apply(args, env),
DefineType::Public => env.execute_function_as_transaction(self, args, None),
DefineType::ReadOnly => env.execute_function_as_transaction(self, args, None),
DefineType::Public => env.execute_function_as_transaction(self, args, None, false),
DefineType::ReadOnly => env.execute_function_as_transaction(self, args, None, false),
}
}

Expand Down
15 changes: 11 additions & 4 deletions clarity/src/vm/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,8 +1139,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> {
return Err(CheckErrors::CircularReference(vec![func_identifier.to_string()]).into())
}
self.call_stack.insert(&func_identifier, true);

let res = self.execute_function_as_transaction(&func, &args, Some(&contract.contract_context));
let res = self.execute_function_as_transaction(&func, &args, Some(&contract.contract_context), allow_private);
self.call_stack.remove(&func_identifier, true)?;

match res {
Expand Down Expand Up @@ -1168,6 +1167,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> {
function: &DefinedFunction,
args: &[Value],
next_contract_context: Option<&ContractContext>,
allow_private: bool,
) -> Result<Value> {
let make_read_only = function.is_read_only();

Expand Down Expand Up @@ -1196,7 +1196,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> {
self.global_context.roll_back()?;
result
} else {
self.global_context.handle_tx_result(result)
self.global_context.handle_tx_result(result, allow_private)
}
}

Expand Down Expand Up @@ -1726,7 +1726,11 @@ impl<'a, 'hooks> GlobalContext<'a, 'hooks> {
self.database.roll_back()
}

pub fn handle_tx_result(&mut self, result: Result<Value>) -> Result<Value> {
pub fn handle_tx_result(
&mut self,
result: Result<Value>,
allow_private: bool,
) -> Result<Value> {
if let Ok(result) = result {
if let Value::Response(data) = result {
if data.committed {
Expand All @@ -1735,6 +1739,9 @@ impl<'a, 'hooks> GlobalContext<'a, 'hooks> {
self.roll_back()?;
}
Ok(Value::Response(data))
} else if allow_private {
self.commit()?;
Ok(result)
} else {
Err(
CheckErrors::PublicFunctionMustReturnResponse(TypeSignature::type_of(&result)?)
Expand Down