use crate::{
access_path::AccessPath,
account_config::constants::{
xus_tag, ACCOUNT_MODULE_NAME, CORE_CODE_ADDRESS,
},
};
use move_core_types::{
language_storage::{StructTag, TypeTag},
move_resource::MoveResource,
};
#[cfg(any(test, feature = "fuzzing"))]
use proptest_derive::Arbitrary;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(any(test, feature = "fuzzing"), derive(Arbitrary))]
pub struct BalanceResource {
coin: u64,
}
impl BalanceResource {
pub fn new(coin: u64) -> Self { Self { coin } }
pub fn coin(&self) -> u64 { self.coin }
pub fn struct_tag_for_currency(currency_typetag: TypeTag) -> StructTag {
StructTag {
address: CORE_CODE_ADDRESS,
name: BalanceResource::struct_identifier(),
module: BalanceResource::module_identifier(),
type_params: vec![currency_typetag],
}
}
pub fn access_path_for(currency_typetag: TypeTag) -> Vec<u8> {
AccessPath::resource_access_vec(
BalanceResource::struct_tag_for_currency(currency_typetag),
)
}
}
impl MoveResource for BalanceResource {
const MODULE_NAME: &'static str = ACCOUNT_MODULE_NAME;
const STRUCT_NAME: &'static str = "Balance";
fn type_params() -> Vec<TypeTag> { vec![xus_tag()] }
}