radix_engine/system/system_modules/costing/
costing_entry.rs

1use super::FeeTable;
2use crate::internal_prelude::*;
3use crate::kernel::kernel_callback_api::{
4    CheckReferenceEvent, CloseSubstateEvent, CreateNodeEvent, DrainSubstatesEvent, DropNodeEvent,
5    MoveModuleEvent, OpenSubstateEvent, ReadSubstateEvent, RemoveSubstateEvent, ScanKeysEvent,
6    ScanSortedSubstatesEvent, SetSubstateEvent, WriteSubstateEvent,
7};
8use crate::system::actor::Actor;
9use crate::system::system_modules::transaction_runtime::Event;
10use crate::track::interface::StoreCommit;
11
12#[derive(Debug, IntoStaticStr)]
13pub enum ExecutionCostingEntry<'a> {
14    /* verify signature */
15    VerifyTxSignatures {
16        num_signatures: usize,
17    },
18    ValidateTxPayload {
19        size: usize,
20    },
21    CheckReference {
22        event: &'a CheckReferenceEvent<'a>,
23    },
24    CheckIntentValidity,
25    CheckTimestamp,
26
27    /* run code */
28    RunNativeCode {
29        package_address: &'a PackageAddress,
30        export_name: &'a str,
31        input_size: usize,
32    },
33    RunWasmCode {
34        package_address: &'a PackageAddress,
35        export_name: &'a str,
36        wasm_execution_units: u32,
37    },
38    PrepareWasmCode {
39        size: usize,
40    },
41
42    /* invoke */
43    BeforeInvoke {
44        actor: &'a Actor,
45        input_size: usize,
46    },
47    AfterInvoke {
48        output_size: usize,
49    },
50
51    /* node */
52    AllocateNodeId,
53    CreateNode {
54        event: &'a CreateNodeEvent<'a>,
55    },
56    DropNode {
57        event: &'a DropNodeEvent<'a>,
58    },
59    PinNode {
60        node_id: &'a NodeId,
61    },
62    MoveModule {
63        event: &'a MoveModuleEvent<'a>,
64    },
65
66    /* Substate */
67    OpenSubstate {
68        event: &'a OpenSubstateEvent<'a>,
69    },
70    ReadSubstate {
71        event: &'a ReadSubstateEvent<'a>,
72    },
73    WriteSubstate {
74        event: &'a WriteSubstateEvent<'a>,
75    },
76    CloseSubstate {
77        event: &'a CloseSubstateEvent,
78    },
79    MarkSubstateAsTransient {
80        node_id: &'a NodeId,
81        partition_number: &'a PartitionNumber,
82        substate_key: &'a SubstateKey,
83    },
84
85    /* unstable node apis */
86    SetSubstate {
87        event: &'a SetSubstateEvent<'a>,
88    },
89    RemoveSubstate {
90        event: &'a RemoveSubstateEvent<'a>,
91    },
92    ScanKeys {
93        event: &'a ScanKeysEvent<'a>,
94    },
95    ScanSortedSubstates {
96        event: &'a ScanSortedSubstatesEvent<'a>,
97    },
98    DrainSubstates {
99        event: &'a DrainSubstatesEvent<'a>,
100    },
101
102    /* stack api */
103    GetStackId,
104    GetOwnedNodes,
105    SwitchStack,
106    SendToStack {
107        data_len: usize,
108    },
109    SetCallFrameData {
110        data_len: usize,
111    },
112
113    /* system */
114    LockFee,
115    QueryFeeReserve,
116    QueryCostingModule,
117    QueryActor,
118    QueryTransactionHash,
119    GenerateRuid,
120    EmitEvent {
121        size: usize,
122    },
123    EmitLog {
124        size: usize,
125    },
126    EncodeBech32Address,
127    Panic {
128        size: usize,
129    },
130
131    /* crypto utils */
132    Bls12381V1Verify {
133        size: usize,
134    },
135    Bls12381V1AggregateVerify {
136        sizes: &'a [usize],
137    },
138    Bls12381V1FastAggregateVerify {
139        size: usize,
140        keys_cnt: usize,
141    },
142    Bls12381G2SignatureAggregate {
143        signatures_cnt: usize,
144    },
145    Keccak256Hash {
146        size: usize,
147    },
148    Blake2b256Hash {
149        size: usize,
150    },
151    Ed25519Verify {
152        size: usize,
153    },
154    Secp256k1EcdsaVerify,
155    Secp256k1EcdsaVerifyAndKeyRecover,
156}
157
158#[derive(Debug, IntoStaticStr)]
159pub enum FinalizationCostingEntry<'a> {
160    CommitStateUpdates { store_commit: &'a StoreCommit },
161    CommitEvents { events: &'a Vec<Event> },
162    CommitLogs { logs: &'a Vec<(Level, String)> },
163    CommitIntentStatus { num_of_intent_statuses: usize },
164}
165
166impl<'a> ExecutionCostingEntry<'a> {
167    pub fn to_execution_cost_units(&self, ft: &FeeTable) -> u32 {
168        match self {
169            ExecutionCostingEntry::VerifyTxSignatures {
170                num_signatures: num_of_signatures,
171            } => ft.verify_tx_signatures_cost(*num_of_signatures),
172            ExecutionCostingEntry::ValidateTxPayload { size } => ft.validate_tx_payload_cost(*size),
173            ExecutionCostingEntry::CheckReference { event } => ft.check_reference(event),
174            ExecutionCostingEntry::CheckIntentValidity => ft.check_intent_validity(),
175            ExecutionCostingEntry::CheckTimestamp => ft.check_timestamp(),
176            ExecutionCostingEntry::RunNativeCode {
177                package_address,
178                export_name,
179                input_size,
180            } => ft.run_native_code_cost(package_address, export_name, input_size),
181            ExecutionCostingEntry::RunWasmCode {
182                package_address,
183                export_name,
184                wasm_execution_units,
185            } => ft.run_wasm_code_cost(package_address, export_name, *wasm_execution_units),
186            ExecutionCostingEntry::PrepareWasmCode { size } => ft.instantiate_wasm_code_cost(*size),
187            ExecutionCostingEntry::BeforeInvoke { actor, input_size } => {
188                ft.before_invoke_cost(actor, *input_size)
189            }
190            ExecutionCostingEntry::AfterInvoke { output_size } => {
191                ft.after_invoke_cost(*output_size)
192            }
193            ExecutionCostingEntry::AllocateNodeId => ft.allocate_node_id_cost(),
194            ExecutionCostingEntry::CreateNode { event } => ft.create_node_cost(event),
195            ExecutionCostingEntry::DropNode { event } => ft.drop_node_cost(event),
196            ExecutionCostingEntry::PinNode { node_id } => ft.pin_node_cost(node_id),
197            ExecutionCostingEntry::MoveModule { event } => ft.move_module_cost(event),
198            ExecutionCostingEntry::OpenSubstate { event } => ft.open_substate_cost(event),
199            ExecutionCostingEntry::ReadSubstate { event } => ft.read_substate_cost(event),
200            ExecutionCostingEntry::WriteSubstate { event } => ft.write_substate_cost(event),
201            ExecutionCostingEntry::CloseSubstate { event } => ft.close_substate_cost(event),
202            ExecutionCostingEntry::SetSubstate { event } => ft.set_substate_cost(event),
203            ExecutionCostingEntry::RemoveSubstate { event } => ft.remove_substate_cost(event),
204            ExecutionCostingEntry::MarkSubstateAsTransient {
205                node_id,
206                partition_number,
207                substate_key,
208            } => ft.mark_substate_as_transient_cost(node_id, partition_number, substate_key),
209            ExecutionCostingEntry::ScanKeys { event } => ft.scan_keys_cost(event),
210            ExecutionCostingEntry::DrainSubstates { event } => ft.drain_substates_cost(event),
211            ExecutionCostingEntry::ScanSortedSubstates { event } => {
212                ft.scan_sorted_substates_cost(event)
213            }
214            ExecutionCostingEntry::GetStackId => ft.get_stack_id(),
215            ExecutionCostingEntry::GetOwnedNodes => ft.get_owned_nodes(),
216            ExecutionCostingEntry::SwitchStack => ft.switch_stack(),
217            ExecutionCostingEntry::SendToStack { data_len } => ft.send_to_stack(*data_len),
218            ExecutionCostingEntry::SetCallFrameData { data_len } => {
219                ft.set_call_frame_data(*data_len)
220            }
221            ExecutionCostingEntry::LockFee => ft.lock_fee_cost(),
222            ExecutionCostingEntry::QueryFeeReserve => ft.query_fee_reserve_cost(),
223            ExecutionCostingEntry::QueryCostingModule => ft.query_costing_module(),
224            ExecutionCostingEntry::QueryActor => ft.query_actor_cost(),
225            ExecutionCostingEntry::QueryTransactionHash => ft.query_transaction_hash_cost(),
226            ExecutionCostingEntry::GenerateRuid => ft.generate_ruid_cost(),
227            ExecutionCostingEntry::EmitEvent { size } => ft.emit_event_cost(*size),
228            ExecutionCostingEntry::EmitLog { size } => ft.emit_log_cost(*size),
229            ExecutionCostingEntry::EncodeBech32Address => ft.encode_bech32_address_cost(),
230            ExecutionCostingEntry::Panic { size } => ft.panic_cost(*size),
231            ExecutionCostingEntry::Bls12381V1Verify { size } => ft.bls12381_v1_verify_cost(*size),
232            ExecutionCostingEntry::Bls12381V1AggregateVerify { sizes } => {
233                ft.bls12381_v1_aggregate_verify_cost(sizes)
234            }
235            ExecutionCostingEntry::Bls12381V1FastAggregateVerify { size, keys_cnt } => {
236                ft.bls12381_v1_fast_aggregate_verify_cost(*size, *keys_cnt)
237            }
238            ExecutionCostingEntry::Bls12381G2SignatureAggregate { signatures_cnt } => {
239                ft.bls12381_g2_signature_aggregate_cost(*signatures_cnt)
240            }
241            ExecutionCostingEntry::Keccak256Hash { size } => ft.keccak256_hash_cost(*size),
242            ExecutionCostingEntry::Blake2b256Hash { size } => ft.blake2b256_hash_cost(*size),
243            ExecutionCostingEntry::Ed25519Verify { size } => ft.ed25519_verify_cost(*size),
244            ExecutionCostingEntry::Secp256k1EcdsaVerify => ft.secp256k1_ecdsa_verify_cost(),
245            ExecutionCostingEntry::Secp256k1EcdsaVerifyAndKeyRecover => {
246                ft.secp256k1_ecdsa_verify_and_key_recover_cost()
247            }
248        }
249    }
250}
251
252impl<'a> FinalizationCostingEntry<'a> {
253    pub fn to_finalization_cost_units(&self, ft: &FeeTable) -> u32 {
254        match self {
255            FinalizationCostingEntry::CommitStateUpdates { store_commit } => {
256                ft.commit_state_updates_cost(store_commit)
257            }
258            FinalizationCostingEntry::CommitEvents { events } => ft.commit_events_cost(events),
259            FinalizationCostingEntry::CommitLogs { logs } => ft.commit_logs_cost(logs),
260
261            FinalizationCostingEntry::CommitIntentStatus {
262                num_of_intent_statuses,
263            } => ft.commit_intent_status(*num_of_intent_statuses),
264        }
265    }
266}
267
268impl<'a> ExecutionCostingEntry<'a> {
269    pub fn to_trace_key(&self) -> String {
270        match self {
271            ExecutionCostingEntry::RunNativeCode { export_name, .. } => {
272                format!("RunNativeCode::{}", export_name)
273            }
274            ExecutionCostingEntry::RunWasmCode { export_name, .. } => {
275                format!("RunWasmCode::{}", export_name)
276            }
277            ExecutionCostingEntry::OpenSubstate { event, .. } => {
278                let node_id = match event {
279                    OpenSubstateEvent::Start { node_id, .. } => **node_id,
280                    OpenSubstateEvent::IOAccess(access) => access.node_id(),
281                    OpenSubstateEvent::End { node_id, .. } => **node_id,
282                };
283
284                format!(
285                    "OpenSubstate::{}",
286                    node_id.entity_type().map(|x| x.into()).unwrap_or("?")
287                )
288            }
289            x => Into::<&'static str>::into(x).to_string(),
290        }
291    }
292}
293
294impl<'a> FinalizationCostingEntry<'a> {
295    pub fn to_trace_key(&self) -> String {
296        match self {
297            FinalizationCostingEntry::CommitStateUpdates { store_commit } => {
298                format!(
299                    "CommitStateUpdates::{}",
300                    store_commit
301                        .node_id()
302                        .entity_type()
303                        .map(|x| x.into())
304                        .unwrap_or("?")
305                )
306            }
307            x => Into::<&'static str>::into(x).to_string(),
308        }
309    }
310}
311
312/// A module containing various models that do not use references and use owned objects instead.
313/// Keep in mind that using references is more efficient and that this is used in applications that
314/// are not performance critical.
315#[allow(clippy::large_enum_variant)]
316pub mod owned {
317    use super::*;
318    use crate::kernel::substate_io::*;
319    use crate::track::*;
320
321    /// An owned model equivalent of [`ExecutionCostingEntry`].
322    #[derive(Debug, Clone, ScryptoSbor, PartialEq, Eq)]
323    pub enum ExecutionCostingEntryOwned {
324        /* verify signature */
325        VerifyTxSignatures {
326            num_signatures: usize,
327        },
328        ValidateTxPayload {
329            size: usize,
330        },
331        CheckReference {
332            event: CheckReferenceEventOwned,
333        },
334        CheckIntentValidity,
335        CheckTimestamp,
336
337        /* run code */
338        RunNativeCode {
339            package_address: PackageAddress,
340            export_name: String,
341            input_size: usize,
342        },
343        RunWasmCode {
344            package_address: PackageAddress,
345            export_name: String,
346            wasm_execution_units: u32,
347        },
348        PrepareWasmCode {
349            size: usize,
350        },
351
352        /* invoke */
353        BeforeInvoke {
354            actor: Actor,
355            input_size: usize,
356        },
357        AfterInvoke {
358            output_size: usize,
359        },
360
361        /* node */
362        AllocateNodeId,
363        CreateNode {
364            event: CreateNodeEventOwned,
365        },
366        DropNode {
367            event: DropNodeEventOwned,
368        },
369        PinNode {
370            node_id: NodeId,
371        },
372        MoveModule {
373            event: MoveModuleEventOwned,
374        },
375
376        /* Substate */
377        OpenSubstate {
378            event: OpenSubstateEventOwned,
379        },
380        ReadSubstate {
381            event: ReadSubstateEventOwned,
382        },
383        WriteSubstate {
384            event: WriteSubstateEventOwned,
385        },
386        CloseSubstate {
387            event: CloseSubstateEventOwned,
388        },
389        MarkSubstateAsTransient {
390            node_id: NodeId,
391            partition_number: PartitionNumber,
392            substate_key: SubstateKey,
393        },
394
395        /* unstable node apis */
396        SetSubstate {
397            event: SetSubstateEventOwned,
398        },
399        RemoveSubstate {
400            event: RemoveSubstateEventOwned,
401        },
402        ScanKeys {
403            event: ScanKeysEventOwned,
404        },
405        ScanSortedSubstates {
406            event: ScanSortedSubstatesEventOwned,
407        },
408        DrainSubstates {
409            event: DrainSubstatesEventOwned,
410        },
411
412        GetStackId,
413        GetOwnedNodes,
414        SwitchStack,
415        SendToStack {
416            data_len: usize,
417        },
418        SetCallFrameData {
419            data_len: usize,
420        },
421
422        /* system */
423        LockFee,
424        QueryFeeReserve,
425        QueryCostingModule,
426        QueryActor,
427        QueryTransactionHash,
428        GenerateRuid,
429        EmitEvent {
430            size: usize,
431        },
432        EmitLog {
433            size: usize,
434        },
435        EncodeBech32Address,
436        Panic {
437            size: usize,
438        },
439
440        /* crypto utils */
441        Bls12381V1Verify {
442            size: usize,
443        },
444        Bls12381V1AggregateVerify {
445            sizes: Vec<usize>,
446        },
447        Bls12381V1FastAggregateVerify {
448            size: usize,
449            keys_cnt: usize,
450        },
451        Bls12381G2SignatureAggregate {
452            signatures_cnt: usize,
453        },
454        Keccak256Hash {
455            size: usize,
456        },
457        Blake2b256Hash {
458            size: usize,
459        },
460        Ed25519Verify {
461            size: usize,
462        },
463        Secp256k1EcdsaVerify,
464        Secp256k1EcdsaVerifyAndKeyRecover,
465    }
466
467    /// An owned model equivalent of [`CreateNodeEvent`].
468    #[derive(Debug, Clone, ScryptoSbor, PartialEq, Eq)]
469    pub enum CreateNodeEventOwned {
470        Start(
471            NodeId,
472            BTreeMap<PartitionNumber, BTreeMap<SubstateKey, (ScryptoValue,)>>,
473        ),
474        IOAccess(IOAccess),
475        End(NodeId),
476    }
477
478    /// An owned model equivalent of [`DropNodeEvent`].
479    #[derive(Debug, Clone, ScryptoSbor, PartialEq, Eq)]
480    pub enum DropNodeEventOwned {
481        Start(NodeId),
482        IOAccess(IOAccess),
483        End(
484            NodeId,
485            BTreeMap<PartitionNumber, BTreeMap<SubstateKey, (ScryptoValue,)>>,
486        ),
487    }
488
489    /// An owned model equivalent of [`RefCheckEvent`].
490    #[derive(Debug, Clone, ScryptoSbor, PartialEq, Eq)]
491    pub enum CheckReferenceEventOwned {
492        IOAccess(IOAccess),
493    }
494
495    /// An owned model equivalent of [`MoveModuleEvent`].
496    #[derive(Debug, Clone, ScryptoSbor, PartialEq, Eq)]
497    pub enum MoveModuleEventOwned {
498        IOAccess(IOAccess),
499    }
500
501    /// An owned model equivalent of [`OpenSubstateEvent`].
502    #[derive(Debug, Clone, ScryptoSbor, PartialEq, Eq)]
503    pub enum OpenSubstateEventOwned {
504        Start {
505            node_id: NodeId,
506            partition_num: PartitionNumber,
507            substate_key: SubstateKey,
508            flags: LockFlags,
509        },
510        IOAccess(IOAccess),
511        End {
512            handle: SubstateHandle,
513            node_id: NodeId,
514            size: usize,
515        },
516    }
517
518    /// An owned model equivalent of [`ReadSubstateEvent`].
519    #[derive(Debug, Clone, ScryptoSbor, PartialEq, Eq)]
520    pub enum ReadSubstateEventOwned {
521        OnRead {
522            handle: SubstateHandle,
523            value: (ScryptoValue,),
524            device: SubstateDevice,
525        },
526        IOAccess(IOAccess),
527    }
528
529    /// An owned model equivalent of [`WriteSubstateEvent`].
530    #[derive(Debug, Clone, ScryptoSbor, PartialEq, Eq)]
531    pub enum WriteSubstateEventOwned {
532        Start {
533            handle: SubstateHandle,
534            value: (ScryptoValue,),
535        },
536        IOAccess(IOAccess),
537    }
538
539    /// An owned model equivalent of [`CloseSubstateEvent`].
540    #[derive(Debug, Clone, ScryptoSbor, PartialEq, Eq)]
541    pub enum CloseSubstateEventOwned {
542        Start(SubstateHandle),
543    }
544
545    /// An owned model equivalent of [`SetSubstateEvent`].
546    #[derive(Debug, Clone, ScryptoSbor, PartialEq, Eq)]
547    pub enum SetSubstateEventOwned {
548        Start(NodeId, PartitionNumber, SubstateKey, (ScryptoValue,)),
549        IOAccess(IOAccess),
550    }
551
552    /// An owned model equivalent of [`RemoveSubstateEvent`].
553    #[derive(Debug, Clone, ScryptoSbor, PartialEq, Eq)]
554    pub enum RemoveSubstateEventOwned {
555        Start(NodeId, PartitionNumber, SubstateKey),
556        IOAccess(IOAccess),
557    }
558
559    /// An owned model equivalent of [`ScanKeysEvent`].
560    #[derive(Debug, Clone, ScryptoSbor, PartialEq, Eq)]
561    pub enum ScanKeysEventOwned {
562        Start,
563        IOAccess(IOAccess),
564    }
565
566    /// An owned model equivalent of [`DrainSubstatesEvent`].
567    #[derive(Debug, Clone, ScryptoSbor, PartialEq, Eq)]
568    pub enum DrainSubstatesEventOwned {
569        Start(u32),
570        IOAccess(IOAccess),
571    }
572
573    /// An owned model equivalent of [`ScanSortedSubstatesEvent`].
574    #[derive(Debug, Clone, ScryptoSbor, PartialEq, Eq)]
575    pub enum ScanSortedSubstatesEventOwned {
576        Start,
577        IOAccess(IOAccess),
578    }
579
580    impl<'a> From<ExecutionCostingEntry<'a>> for ExecutionCostingEntryOwned {
581        fn from(value: ExecutionCostingEntry<'a>) -> Self {
582            match value {
583                ExecutionCostingEntry::VerifyTxSignatures { num_signatures } => {
584                    Self::VerifyTxSignatures { num_signatures }
585                }
586                ExecutionCostingEntry::ValidateTxPayload { size } => {
587                    Self::ValidateTxPayload { size }
588                }
589                ExecutionCostingEntry::CheckReference { event } => Self::CheckReference {
590                    event: event.into(),
591                },
592                ExecutionCostingEntry::CheckIntentValidity => Self::CheckIntentValidity,
593                ExecutionCostingEntry::CheckTimestamp => Self::CheckTimestamp,
594                ExecutionCostingEntry::RunNativeCode {
595                    package_address,
596                    export_name,
597                    input_size,
598                } => Self::RunNativeCode {
599                    package_address: *package_address,
600                    export_name: export_name.to_owned(),
601                    input_size,
602                },
603                ExecutionCostingEntry::RunWasmCode {
604                    package_address,
605                    export_name,
606                    wasm_execution_units,
607                } => Self::RunWasmCode {
608                    package_address: *package_address,
609                    export_name: export_name.to_owned(),
610                    wasm_execution_units,
611                },
612                ExecutionCostingEntry::PrepareWasmCode { size } => Self::PrepareWasmCode { size },
613                ExecutionCostingEntry::BeforeInvoke { actor, input_size } => Self::BeforeInvoke {
614                    actor: actor.clone(),
615                    input_size,
616                },
617                ExecutionCostingEntry::AfterInvoke { output_size } => {
618                    Self::AfterInvoke { output_size }
619                }
620                ExecutionCostingEntry::AllocateNodeId => Self::AllocateNodeId,
621                ExecutionCostingEntry::CreateNode { event } => Self::CreateNode {
622                    event: event.into(),
623                },
624                ExecutionCostingEntry::DropNode { event } => Self::DropNode {
625                    event: event.into(),
626                },
627                ExecutionCostingEntry::PinNode { node_id } => Self::PinNode { node_id: *node_id },
628                ExecutionCostingEntry::MoveModule { event } => Self::MoveModule {
629                    event: event.into(),
630                },
631                ExecutionCostingEntry::OpenSubstate { event } => Self::OpenSubstate {
632                    event: event.into(),
633                },
634                ExecutionCostingEntry::ReadSubstate { event } => Self::ReadSubstate {
635                    event: event.into(),
636                },
637                ExecutionCostingEntry::WriteSubstate { event } => Self::WriteSubstate {
638                    event: event.into(),
639                },
640                ExecutionCostingEntry::CloseSubstate { event } => Self::CloseSubstate {
641                    event: event.into(),
642                },
643                ExecutionCostingEntry::MarkSubstateAsTransient {
644                    node_id,
645                    partition_number,
646                    substate_key,
647                } => Self::MarkSubstateAsTransient {
648                    node_id: *node_id,
649                    partition_number: *partition_number,
650                    substate_key: substate_key.clone(),
651                },
652                ExecutionCostingEntry::SetSubstate { event } => Self::SetSubstate {
653                    event: event.into(),
654                },
655                ExecutionCostingEntry::RemoveSubstate { event } => Self::RemoveSubstate {
656                    event: event.into(),
657                },
658                ExecutionCostingEntry::ScanKeys { event } => Self::ScanKeys {
659                    event: event.into(),
660                },
661                ExecutionCostingEntry::ScanSortedSubstates { event } => Self::ScanSortedSubstates {
662                    event: event.into(),
663                },
664                ExecutionCostingEntry::DrainSubstates { event } => Self::DrainSubstates {
665                    event: event.into(),
666                },
667                ExecutionCostingEntry::GetStackId => Self::GetStackId,
668                ExecutionCostingEntry::GetOwnedNodes => Self::GetOwnedNodes,
669                ExecutionCostingEntry::SwitchStack => Self::SwitchStack,
670                ExecutionCostingEntry::SendToStack { data_len } => Self::SendToStack { data_len },
671                ExecutionCostingEntry::SetCallFrameData { data_len } => {
672                    Self::SetCallFrameData { data_len }
673                }
674                ExecutionCostingEntry::LockFee => Self::LockFee,
675                ExecutionCostingEntry::QueryFeeReserve => Self::QueryFeeReserve,
676                ExecutionCostingEntry::QueryCostingModule => Self::QueryCostingModule,
677                ExecutionCostingEntry::QueryActor => Self::QueryActor,
678                ExecutionCostingEntry::QueryTransactionHash => Self::QueryTransactionHash,
679                ExecutionCostingEntry::GenerateRuid => Self::GenerateRuid,
680                ExecutionCostingEntry::EmitEvent { size } => Self::EmitEvent { size },
681                ExecutionCostingEntry::EmitLog { size } => Self::EmitLog { size },
682                ExecutionCostingEntry::EncodeBech32Address => Self::EncodeBech32Address,
683                ExecutionCostingEntry::Panic { size } => Self::Panic { size },
684                ExecutionCostingEntry::Bls12381V1Verify { size } => Self::Bls12381V1Verify { size },
685                ExecutionCostingEntry::Bls12381V1AggregateVerify { sizes } => {
686                    Self::Bls12381V1AggregateVerify {
687                        sizes: sizes.to_vec(),
688                    }
689                }
690                ExecutionCostingEntry::Bls12381V1FastAggregateVerify { size, keys_cnt } => {
691                    Self::Bls12381V1FastAggregateVerify { size, keys_cnt }
692                }
693                ExecutionCostingEntry::Bls12381G2SignatureAggregate { signatures_cnt } => {
694                    Self::Bls12381G2SignatureAggregate { signatures_cnt }
695                }
696                ExecutionCostingEntry::Keccak256Hash { size } => Self::Keccak256Hash { size },
697                ExecutionCostingEntry::Blake2b256Hash { size } => Self::Blake2b256Hash { size },
698                ExecutionCostingEntry::Ed25519Verify { size } => Self::Ed25519Verify { size },
699                ExecutionCostingEntry::Secp256k1EcdsaVerify => Self::Secp256k1EcdsaVerify,
700                ExecutionCostingEntry::Secp256k1EcdsaVerifyAndKeyRecover => {
701                    Self::Secp256k1EcdsaVerifyAndKeyRecover
702                }
703            }
704        }
705    }
706
707    impl<'a> From<&'a CreateNodeEvent<'a>> for CreateNodeEventOwned {
708        fn from(value: &'a CreateNodeEvent<'a>) -> Self {
709            match value {
710                CreateNodeEvent::Start(item1, item2) => Self::Start(
711                    **item1,
712                    item2
713                        .iter()
714                        .map(|(key, value)| {
715                            (
716                                *key,
717                                value
718                                    .iter()
719                                    .map(|(key, value)| {
720                                        (key.clone(), (value.as_scrypto_value().to_owned(),))
721                                    })
722                                    .collect(),
723                            )
724                        })
725                        .collect(),
726                ),
727                CreateNodeEvent::IOAccess(item) => Self::IOAccess((*item).clone()),
728                CreateNodeEvent::End(item) => Self::End(**item),
729            }
730        }
731    }
732
733    impl<'a> From<&'a DropNodeEvent<'a>> for DropNodeEventOwned {
734        fn from(value: &'a DropNodeEvent<'a>) -> Self {
735            match value {
736                DropNodeEvent::Start(item) => Self::Start(**item),
737                DropNodeEvent::IOAccess(item) => Self::IOAccess((*item).clone()),
738                DropNodeEvent::End(item1, item2) => Self::End(
739                    **item1,
740                    item2
741                        .iter()
742                        .map(|(key, value)| {
743                            (
744                                *key,
745                                value
746                                    .iter()
747                                    .map(|(key, value)| {
748                                        (key.clone(), (value.as_scrypto_value().to_owned(),))
749                                    })
750                                    .collect(),
751                            )
752                        })
753                        .collect(),
754                ),
755            }
756        }
757    }
758
759    impl<'a> From<&'a CheckReferenceEvent<'a>> for CheckReferenceEventOwned {
760        fn from(value: &'a CheckReferenceEvent<'a>) -> Self {
761            match value {
762                CheckReferenceEvent::IOAccess(item) => Self::IOAccess((*item).clone()),
763            }
764        }
765    }
766
767    impl<'a> From<&'a MoveModuleEvent<'a>> for MoveModuleEventOwned {
768        fn from(value: &'a MoveModuleEvent<'a>) -> Self {
769            match value {
770                MoveModuleEvent::IOAccess(item) => Self::IOAccess((*item).clone()),
771            }
772        }
773    }
774
775    impl<'a> From<&'a OpenSubstateEvent<'a>> for OpenSubstateEventOwned {
776        fn from(value: &'a OpenSubstateEvent<'a>) -> Self {
777            match value {
778                OpenSubstateEvent::Start {
779                    node_id,
780                    partition_num,
781                    substate_key,
782                    flags,
783                } => Self::Start {
784                    node_id: **node_id,
785                    partition_num: **partition_num,
786                    substate_key: (*substate_key).clone(),
787                    flags: **flags,
788                },
789                OpenSubstateEvent::IOAccess(item) => Self::IOAccess((*item).clone()),
790                OpenSubstateEvent::End {
791                    handle,
792                    node_id,
793                    size,
794                } => Self::End {
795                    handle: *handle,
796                    node_id: **node_id,
797                    size: *size,
798                },
799            }
800        }
801    }
802
803    impl<'a> From<&'a ReadSubstateEvent<'a>> for ReadSubstateEventOwned {
804        fn from(value: &'a ReadSubstateEvent<'a>) -> Self {
805            match value {
806                ReadSubstateEvent::OnRead {
807                    handle,
808                    value,
809                    device,
810                } => Self::OnRead {
811                    handle: *handle,
812                    value: (value.as_scrypto_value().to_owned(),),
813                    device: *device,
814                },
815                ReadSubstateEvent::IOAccess(item) => Self::IOAccess((*item).clone()),
816            }
817        }
818    }
819
820    impl<'a> From<&'a WriteSubstateEvent<'a>> for WriteSubstateEventOwned {
821        fn from(value: &'a WriteSubstateEvent<'a>) -> Self {
822            match value {
823                WriteSubstateEvent::Start { handle, value } => Self::Start {
824                    handle: *handle,
825                    value: (value.as_scrypto_value().to_owned(),),
826                },
827                WriteSubstateEvent::IOAccess(item) => Self::IOAccess((*item).clone()),
828            }
829        }
830    }
831
832    impl From<&CloseSubstateEvent> for CloseSubstateEventOwned {
833        fn from(value: &CloseSubstateEvent) -> Self {
834            match value {
835                CloseSubstateEvent::Start(item) => Self::Start(*item),
836            }
837        }
838    }
839
840    impl<'a> From<&'a SetSubstateEvent<'a>> for SetSubstateEventOwned {
841        fn from(value: &'a SetSubstateEvent<'a>) -> Self {
842            match value {
843                SetSubstateEvent::Start(item1, item2, item3, item4) => Self::Start(
844                    **item1,
845                    **item2,
846                    (*item3).clone(),
847                    (item4.as_scrypto_value().to_owned(),),
848                ),
849                SetSubstateEvent::IOAccess(item) => Self::IOAccess((*item).clone()),
850            }
851        }
852    }
853
854    impl<'a> From<&'a RemoveSubstateEvent<'a>> for RemoveSubstateEventOwned {
855        fn from(value: &'a RemoveSubstateEvent<'a>) -> Self {
856            match value {
857                RemoveSubstateEvent::Start(item1, item2, item3) => {
858                    Self::Start(**item1, **item2, (*item3).clone())
859                }
860                RemoveSubstateEvent::IOAccess(item) => Self::IOAccess((*item).clone()),
861            }
862        }
863    }
864
865    impl<'a> From<&'a ScanKeysEvent<'a>> for ScanKeysEventOwned {
866        fn from(value: &'a ScanKeysEvent<'a>) -> Self {
867            match value {
868                ScanKeysEvent::Start => Self::Start,
869                ScanKeysEvent::IOAccess(item) => Self::IOAccess((*item).clone()),
870            }
871        }
872    }
873
874    impl<'a> From<&'a DrainSubstatesEvent<'a>> for DrainSubstatesEventOwned {
875        fn from(value: &'a DrainSubstatesEvent<'a>) -> Self {
876            match value {
877                DrainSubstatesEvent::Start(item) => Self::Start(*item),
878                DrainSubstatesEvent::IOAccess(item) => Self::IOAccess((*item).clone()),
879            }
880        }
881    }
882
883    impl<'a> From<&'a ScanSortedSubstatesEvent<'a>> for ScanSortedSubstatesEventOwned {
884        fn from(value: &'a ScanSortedSubstatesEvent<'a>) -> Self {
885            match value {
886                ScanSortedSubstatesEvent::Start => Self::Start,
887                ScanSortedSubstatesEvent::IOAccess(item) => Self::IOAccess((*item).clone()),
888            }
889        }
890    }
891}