Struct CallMethod

Source
pub struct CallMethod {
    pub wasm_file_name: String,
    pub description: Option<String>,
    pub arguments: Vec<Argument>,
}
Expand description

Call method definition.

Fields§

§wasm_file_name: String§description: Option<String>§arguments: Vec<Argument>

Implementations§

Source§

impl CallMethod

Source

pub fn new( wasm_file_name: &str, description: &str, arguments: Vec<Argument>, ) -> Self

Creates a new call method definition.

Examples found in repository?
examples/erc20.rs (lines 137-150)
3pub fn example_erc20_schema() -> ContractSchema {
4    ContractSchema {
5        casper_contract_schema_version: 1,
6        toolchain: String::from("rustc 1.73.0 (cc66ad468 2023-10-03)"),
7        contract_name: String::from("Erc20"),
8        contract_version: String::from("0.1.0"),
9        authors: vec![String::from("John Doe <john@doe.com>")],
10        repository: Some(String::from(
11            "https://github.com/casper-ecosystem/casper-contract-schema",
12        )),
13        homepage: Some(String::from("https://john.doe.com")),
14        errors: vec![
15            UserError {
16                name: String::from("InsufficientFunds"),
17                description: Some(String::from("Insufficient funds")),
18                discriminant: 100u16,
19            },
20            UserError {
21                name: String::from("InsufficientAllowance"),
22                description: Some(String::from("Insufficient allowance")),
23                discriminant: 101u16,
24            },
25        ],
26        types: vec![
27            CustomType::Struct {
28                name: TypeName::new("Transfer"),
29                description: Some(String::from("Transfer event")),
30                members: vec![
31                    StructMember::new(
32                        "from",
33                        "Sender of tokens.",
34                        NamedCLType::Option(Box::new(NamedCLType::Key)),
35                    ),
36                    StructMember::new(
37                        "to",
38                        "Recipient of tokens.",
39                        NamedCLType::Option(Box::new(NamedCLType::Key)),
40                    ),
41                    StructMember::new("value", "Transfered amount.", NamedCLType::U256),
42                ],
43            },
44            CustomType::Struct {
45                name: TypeName::new("Approval"),
46                description: Some(String::from("Approval event")),
47                members: vec![
48                    StructMember::new("owner", "", NamedCLType::Option(Box::new(NamedCLType::Key))),
49                    StructMember::new(
50                        "spender",
51                        "",
52                        NamedCLType::Option(Box::new(NamedCLType::Key)),
53                    ),
54                    StructMember::new("value", "", NamedCLType::U256),
55                ],
56            },
57        ],
58        entry_points: vec![
59            Entrypoint {
60                name: String::from("transfer"),
61                description: Some(String::from("Transfer tokens to another account")),
62                is_mutable: true,
63                arguments: vec![
64                    Argument::new("recipient", "", NamedCLType::Key),
65                    Argument::new("amount", "", NamedCLType::U256),
66                ],
67                return_ty: NamedCLType::Unit.into(),
68                is_contract_context: true,
69                access: Access::Public,
70            },
71            Entrypoint {
72                name: String::from("transfer_from"),
73                description: Some(String::from("Transfer tokens from one account to another")),
74                is_mutable: true,
75                arguments: vec![
76                    Argument::new("owner", "", NamedCLType::Key),
77                    Argument::new("recipient", "", NamedCLType::Key),
78                    Argument::new("amount", "", NamedCLType::U256),
79                ],
80                return_ty: NamedCLType::Unit.into(),
81                is_contract_context: true,
82                access: Access::Public,
83            },
84            Entrypoint {
85                name: String::from("approve"),
86                description: Some(String::from(
87                    "Approve spender to use tokens on behalf of the owner",
88                )),
89                is_mutable: true,
90                arguments: vec![
91                    Argument::new("spender", "", NamedCLType::Key),
92                    Argument::new("amount", "", NamedCLType::U256),
93                ],
94                return_ty: NamedCLType::Unit.into(),
95                is_contract_context: true,
96                access: Access::Public,
97            },
98            Entrypoint {
99                name: String::from("allowance"),
100                description: Some(String::from(
101                    "Check the amount of tokens that an owner allowed to a spender",
102                )),
103                is_mutable: false,
104                arguments: vec![
105                    Argument::new("owner", "", NamedCLType::Key),
106                    Argument::new("spender", "", NamedCLType::Key),
107                ],
108                return_ty: NamedCLType::U256.into(),
109                is_contract_context: true,
110                access: Access::Public,
111            },
112            Entrypoint {
113                name: String::from("balance_of"),
114                description: Some(String::from(
115                    "Check the amount of tokens owned by an account",
116                )),
117                is_mutable: false,
118                arguments: vec![Argument::new("owner", "", NamedCLType::Key)],
119                return_ty: NamedCLType::U256.into(),
120                is_contract_context: true,
121                access: Access::Public,
122            },
123            Entrypoint {
124                name: String::from("total_supply"),
125                description: Some(String::from("Check the total supply of tokens")),
126                is_mutable: false,
127                arguments: vec![],
128                return_ty: NamedCLType::U256.into(),
129                is_contract_context: true,
130                access: Access::Public,
131            },
132        ],
133        events: vec![
134            Event::new("event_Transfer", "Transfer"),
135            Event::new("event_Approval", "Approval"),
136        ],
137        call: Some(CallMethod::new(
138            "erc20.wasm",
139            "Fungible token",
140            vec![
141                Argument::new("name", "Name of the token", NamedCLType::String),
142                Argument::new("symbol", "Symbol of the token", NamedCLType::String),
143                Argument::new("decimals", "Number of decimals", NamedCLType::U8),
144                Argument::new(
145                    "initial_supply",
146                    "Initial supply of tokens",
147                    NamedCLType::U256,
148                ),
149            ],
150        )),
151    }
152}

Trait Implementations§

Source§

impl Debug for CallMethod

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for CallMethod

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl JsonSchema for CallMethod

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

fn always_inline_schema() -> bool

👎Deprecated: Use inline_schema() instead
Only included for backward-compatibility - use inline_schema() instead“. Read more
Source§

impl Serialize for CallMethod

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,