1
 2
 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
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

use crate::{
    access_path::AccessPath,
    account_config::{
        constants::{xus_tag, CORE_CODE_ADDRESS, DIEM_MODULE_NAME},
        resources::PreburnResource,
    },
};
use move_core_types::{
    language_storage::{StructTag, TypeTag},
    move_resource::MoveResource,
};
#[cfg(any(test, feature = "fuzzing"))]
use proptest_derive::Arbitrary;
use serde::{Deserialize, Serialize};

/// The preburn along with metadata held in a preburn queue.
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(any(test, feature = "fuzzing"), derive(Arbitrary))]
pub struct PreburnWithMetadataResource {
    preburn: PreburnResource,
    metadata: Vec<u8>,
}

impl PreburnWithMetadataResource {
    pub fn new(preburn: PreburnResource, metadata: Vec<u8>) -> Self {
        Self { preburn, metadata }
    }

    pub fn preburn(&self) -> &PreburnResource {
        &self.preburn
    }

    pub fn metadata(&self) -> &[u8] {
        &self.metadata
    }

    // TODO/XXX: remove this once the MoveResource trait allows type arguments to `struct_tag`.
    pub fn struct_tag_for_currency(currency_typetag: TypeTag) -> StructTag {
        StructTag {
            address: CORE_CODE_ADDRESS,
            name: PreburnWithMetadataResource::struct_identifier(),
            module: PreburnWithMetadataResource::module_identifier(),
            type_params: vec![currency_typetag],
        }
    }

    // TODO: remove this once the MoveResource trait allows type arguments to `resource_path`.
    pub fn access_path_for(currency_typetag: TypeTag) -> Vec<u8> {
        AccessPath::resource_access_vec(PreburnWithMetadataResource::struct_tag_for_currency(
            currency_typetag,
        ))
    }
}

impl MoveResource for PreburnWithMetadataResource {
    const MODULE_NAME: &'static str = DIEM_MODULE_NAME;
    const STRUCT_NAME: &'static str = "PreburnWithMetadata";

    fn type_params() -> Vec<TypeTag> {
        vec![xus_tag()]
    }
}