paritytech / ink

@@ -71,12 +71,14 @@
Loading
71 71
    /// Version 1 of the contract metadata.
72 72
    V1(MetadataVersionDeprecated),
73 73
    /// Version 2 of the contract metadata.
74 -
    V2(InkProject),
74 +
    V2(MetadataVersionDeprecated),
75 +
    /// Version 3 of the contract metadata.
76 +
    V3(InkProject),
75 77
}
76 78
77 79
impl From<InkProject> for MetadataVersioned {
78 80
    fn from(ink_project: InkProject) -> Self {
79 -
        MetadataVersioned::V2(ink_project)
81 +
        MetadataVersioned::V3(ink_project)
80 82
    }
81 83
}
82 84

@@ -227,6 +227,8 @@
Loading
227 227
    pub label: F::String,
228 228
    /// The selector hash of the message.
229 229
    pub selector: Selector,
230 +
    /// If the constructor accepts any `value` from the caller.
231 +
    pub payable: bool,
230 232
    /// The parameters of the deployment handler.
231 233
    pub args: Vec<MessageParamSpec<F>>,
232 234
    /// The deployment handler documentation.
@@ -240,6 +242,7 @@
Loading
240 242
        ConstructorSpec {
241 243
            label: self.label.into_portable(registry),
242 244
            selector: self.selector,
245 +
            payable: self.payable,
243 246
            args: self
244 247
                .args
245 248
                .into_iter()
@@ -266,6 +269,11 @@
Loading
266 269
        &self.selector
267 270
    }
268 271
272 +
    /// Returns if the constructor is payable by the caller.
273 +
    pub fn payable(&self) -> &bool {
274 +
        &self.payable
275 +
    }
276 +
269 277
    /// Returns the parameters of the deployment handler.
270 278
    pub fn args(&self) -> &[MessageParamSpec<F>] {
271 279
        &self.args
@@ -285,20 +293,21 @@
Loading
285 293
/// compile-time instead of at run-time. This is useful to better
286 294
/// debug code-gen macros.
287 295
#[must_use]
288 -
pub struct ConstructorSpecBuilder<Selector> {
296 +
pub struct ConstructorSpecBuilder<Selector, IsPayable> {
289 297
    spec: ConstructorSpec,
290 -
    marker: PhantomData<fn() -> Selector>,
298 +
    marker: PhantomData<fn() -> (Selector, IsPayable)>,
291 299
}
292 300
293 301
impl ConstructorSpec {
294 302
    /// Creates a new constructor spec builder.
295 303
    pub fn from_label(
296 304
        label: &'static str,
297 -
    ) -> ConstructorSpecBuilder<Missing<state::Selector>> {
305 +
    ) -> ConstructorSpecBuilder<Missing<state::Selector>, Missing<state::IsPayable>> {
298 306
        ConstructorSpecBuilder {
299 307
            spec: Self {
300 308
                label,
301 309
                selector: Selector::default(),
310 +
                payable: Default::default(),
302 311
                args: Vec::new(),
303 312
                docs: Vec::new(),
304 313
            },
@@ -307,9 +316,12 @@
Loading
307 316
    }
308 317
}
309 318
310 -
impl ConstructorSpecBuilder<Missing<state::Selector>> {
319 +
impl<P> ConstructorSpecBuilder<Missing<state::Selector>, P> {
311 320
    /// Sets the function selector of the message.
312 -
    pub fn selector(self, selector: [u8; 4]) -> ConstructorSpecBuilder<state::Selector> {
321 +
    pub fn selector(
322 +
        self,
323 +
        selector: [u8; 4],
324 +
    ) -> ConstructorSpecBuilder<state::Selector, P> {
313 325
        ConstructorSpecBuilder {
314 326
            spec: ConstructorSpec {
315 327
                selector: selector.into(),
@@ -320,7 +332,23 @@
Loading
320 332
    }
321 333
}
322 334
323 -
impl<S> ConstructorSpecBuilder<S> {
335 +
impl<S> ConstructorSpecBuilder<S, Missing<state::IsPayable>> {
336 +
    /// Sets if the constructor is payable, thus accepting value for the caller.
337 +
    pub fn payable(
338 +
        self,
339 +
        is_payable: bool,
340 +
    ) -> ConstructorSpecBuilder<S, state::IsPayable> {
341 +
        ConstructorSpecBuilder {
342 +
            spec: ConstructorSpec {
343 +
                payable: is_payable,
344 +
                ..self.spec
345 +
            },
346 +
            marker: PhantomData,
347 +
        }
348 +
    }
349 +
}
350 +
351 +
impl<S, P> ConstructorSpecBuilder<S, P> {
324 352
    /// Sets the input arguments of the message specification.
325 353
    pub fn args<A>(self, args: A) -> Self
326 354
    where
@@ -344,7 +372,7 @@
Loading
344 372
    }
345 373
}
346 374
347 -
impl ConstructorSpecBuilder<state::Selector> {
375 +
impl ConstructorSpecBuilder<state::Selector, state::IsPayable> {
348 376
    /// Finishes construction of the constructor.
349 377
    pub fn done(self) -> ConstructorSpec {
350 378
        self.spec
@@ -368,7 +396,7 @@
Loading
368 396
    selector: Selector,
369 397
    /// If the message is allowed to mutate the contract state.
370 398
    mutates: bool,
371 -
    /// If the message is payable by the caller.
399 +
    /// If the message accepts any `value` from the caller.
372 400
    payable: bool,
373 401
    /// The parameters of the message.
374 402
    args: Vec<MessageParamSpec<F>>,
@@ -508,7 +536,7 @@
Loading
508 536
}
509 537
510 538
impl<S, M, R> MessageSpecBuilder<S, M, Missing<state::IsPayable>, R> {
511 -
    /// Sets if the message is mutable, thus taking `&mut self` or not thus taking `&self`.
539 +
    /// Sets if the message is payable, thus accepting value for the caller.
512 540
    pub fn payable(
513 541
        self,
514 542
        is_payable: bool,

@@ -122,6 +122,7 @@
Loading
122 122
            .iter()
123 123
            .filter_map(|attr| attr.extract_docs());
124 124
        let selector_bytes = constructor.composed_selector().hex_lits();
125 +
        let is_payable = constructor.is_payable();
125 126
        let constructor = constructor.callable();
126 127
        let ident = constructor.ident();
127 128
        let args = constructor.inputs().map(Self::generate_dispatch_argument);
@@ -133,6 +134,7 @@
Loading
133 134
                .args([
134 135
                    #( #args ),*
135 136
                ])
137 +
                .payable(#is_payable)
136 138
                .docs([
137 139
                    #( #docs ),*
138 140
                ])
Files Coverage
crates 78.84%
Project Totals (252 files) 78.84%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading