Struct casper_contract_schema::TypeName

source ·
pub struct TypeName(pub String);
Expand description

Custom type name definition.

Tuple Fields§

§0: String

Implementations§

source§

impl TypeName

source

pub fn new(name: &str) -> Self

Creates a new type name.

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

Trait Implementations§

source§

impl Clone for TypeName

source§

fn clone(&self) -> TypeName

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for TypeName

source§

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

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

impl<'de> Deserialize<'de> for TypeName

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 From<&str> for TypeName

source§

fn from(name: &str) -> Self

Converts to this type from the input type.
source§

impl From<String> for TypeName

source§

fn from(name: String) -> Self

Converts to this type from the input type.
source§

impl JsonSchema for TypeName

source§

fn schema_name() -> String

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

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

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

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
source§

impl Ord for TypeName

source§

fn cmp(&self, other: &TypeName) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for TypeName

source§

fn eq(&self, other: &TypeName) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for TypeName

source§

fn partial_cmp(&self, other: &TypeName) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for TypeName

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
source§

impl Eq for TypeName

source§

impl StructuralPartialEq for TypeName

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> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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>,