Skip to content

Commit

Permalink
chore(jstz_proto): avoid clone
Browse files Browse the repository at this point in the history
  • Loading branch information
ryutamago committed Jan 28, 2025
1 parent e6e2d56 commit 44589ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 32 deletions.
5 changes: 1 addition & 4 deletions crates/jstz_proto/src/api/smart_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ impl SmartFunction {
)
})?;
// 2. Set the referrer of the request to the current smart function address
headers::test_and_set_referrer(
&request_deref,
&Address::SmartFunction(self_address.clone()),
)?;
headers::test_and_set_referrer(&request_deref, self_address)?;

// 3. Load, init and run!
Script::load_init_run(
Expand Down
26 changes: 5 additions & 21 deletions crates/jstz_proto/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use jstz_core::{host::HostRuntime, kv::Transaction};
use tezos_crypto_rs::hash::ContractKt1Hash;

use crate::{
context::account::Address,
operation::{self, ExternalOperation, Operation, SignedOperation},
receipt::{self, Receipt},
Result,
Expand Down Expand Up @@ -32,12 +31,7 @@ fn execute_operation_inner(
content: operation::Content::DeployFunction(deployment),
..
} => {
let result = smart_function::deploy::execute(
hrt,
tx,
&Address::User(source.clone()),
deployment,
)?;
let result = smart_function::deploy::execute(hrt, tx, &source, deployment)?;

Ok(receipt::ReceiptContent::DeployFunction(result))
}
Expand All @@ -48,20 +42,10 @@ fn execute_operation_inner(
..
} => {
let result = match run.uri.host() {
Some(JSTZ_HOST) => smart_function::jstz_run::execute(
hrt,
tx,
ticketer,
&Address::User(source.clone()),
run,
)?,
_ => smart_function::run::execute(
hrt,
tx,
&Address::User(source.clone()),
run,
operation_hash,
)?,
Some(JSTZ_HOST) => {
smart_function::jstz_run::execute(hrt, tx, ticketer, &source, run)?
}
_ => smart_function::run::execute(hrt, tx, &source, run, operation_hash)?,
};
Ok(receipt::ReceiptContent::RunFunction(result))
}
Expand Down
19 changes: 12 additions & 7 deletions crates/jstz_proto/src/executor/smart_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use tezos_smart_rollup::prelude::debug_msg;

use crate::{
api::{self, TraceData},
context::account::{Account, Address, Addressable, Amount, ParsedCode},
context::account::{Account, Addressable, Amount, ParsedCode},
js_logger::JsonLogger,
operation::{OperationHash, RunFunction},
receipt,
Expand All @@ -41,7 +41,10 @@ pub mod headers {
use super::*;
pub const REFERRER: &str = "Referer";

pub fn test_and_set_referrer(request: &Request, referer: &Address) -> JsResult<()> {
pub fn test_and_set_referrer(
request: &Request,
referrer: &impl Addressable,
) -> JsResult<()> {
if request.headers().deref().contains_key(REFERRER) {
return Err(JsError::from_native(
JsNativeError::error().with_message("Referer already set"),
Expand All @@ -51,7 +54,7 @@ pub mod headers {
request
.headers()
.deref_mut()
.set(REFERRER, &referer.to_base58())
.set(REFERRER, &referrer.to_base58())
}
}

Expand Down Expand Up @@ -449,7 +452,7 @@ pub mod run {
pub fn execute(
hrt: &mut impl HostRuntime,
tx: &mut Transaction,
source: &Address,
source: &impl Addressable,
run: operation::RunFunction,
operation_hash: OperationHash,
) -> Result<receipt::RunFunctionReceipt> {
Expand Down Expand Up @@ -626,7 +629,7 @@ pub mod jstz_run {
use tezos_smart_rollup_mock::MockHost;

use crate::{
context::ticket_table::TicketTable,
context::{account::Address, ticket_table::TicketTable},
executor::{
fa_withdraw::{FaWithdraw, RoutingInfo, TicketInfo},
smart_function::jstz_run::{execute_without_ticketer, Account},
Expand All @@ -635,7 +638,7 @@ pub mod jstz_run {
Error,
};

use super::{execute, Address};
use super::execute;

fn withdraw_request() -> RunFunction {
RunFunction {
Expand Down Expand Up @@ -908,7 +911,7 @@ pub mod deploy {
pub fn execute(
hrt: &impl HostRuntime,
tx: &mut Transaction,
source: &Address,
source: &impl Addressable,
deployment: operation::DeployFunction,
) -> Result<receipt::DeployFunctionReceipt> {
let operation::DeployFunction {
Expand All @@ -923,6 +926,8 @@ pub mod deploy {

#[cfg(test)]
mod test {
use crate::context::account::Address;

use super::*;
use jstz_core::kv::Transaction;
use jstz_mock::host::JstzMockHost;
Expand Down

0 comments on commit 44589ac

Please sign in to comment.