lit_node_core/models/
action_price_component.rs

1use serde::{Deserialize, Serialize};
2
3#[doc = "The different components that can be priced in the dynamic payment system."]
4#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
5pub enum LitActionPriceComponent {
6    #[default]
7    BaseAmount,
8    RunTimeLength,
9    MemoryUsage,
10    CodeLength,
11    ResponseLength,
12    Signatures,
13    Broadcasts,
14    ContractCalls,
15    CallDepth,
16    Decrypts,
17    Fetches,
18}
19
20impl From<LitActionPriceComponent> for u8 {
21    fn from(value: LitActionPriceComponent) -> Self {
22        match value {
23            LitActionPriceComponent::BaseAmount => 0,
24            LitActionPriceComponent::RunTimeLength => 1,
25            LitActionPriceComponent::MemoryUsage => 2,
26            LitActionPriceComponent::CodeLength => 3,
27            LitActionPriceComponent::ResponseLength => 4,
28            LitActionPriceComponent::Signatures => 5,
29            LitActionPriceComponent::Broadcasts => 6,
30            LitActionPriceComponent::ContractCalls => 7,
31            LitActionPriceComponent::CallDepth => 8,
32            LitActionPriceComponent::Decrypts => 9,
33            LitActionPriceComponent::Fetches => 10,
34        }
35    }
36}
37
38#[doc = "Converts a u8 to a LitActionPriceComponent, or returns an error if the value is invalid."]
39impl TryFrom<u8> for LitActionPriceComponent {
40    type Error = String;
41    fn try_from(value: u8) -> Result<Self, Self::Error> {
42        match value {
43            0 => Ok(LitActionPriceComponent::BaseAmount),
44            1 => Ok(LitActionPriceComponent::RunTimeLength),
45            2 => Ok(LitActionPriceComponent::MemoryUsage),
46            3 => Ok(LitActionPriceComponent::CodeLength),
47            4 => Ok(LitActionPriceComponent::ResponseLength),
48            5 => Ok(LitActionPriceComponent::Signatures),
49            6 => Ok(LitActionPriceComponent::Broadcasts),
50            7 => Ok(LitActionPriceComponent::ContractCalls),
51            8 => Ok(LitActionPriceComponent::CallDepth),
52            9 => Ok(LitActionPriceComponent::Decrypts),
53            10 => Ok(LitActionPriceComponent::Fetches),
54            _ => Err(format!("Invalid lit action price component: {value}")),
55        }
56    }
57}