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
use crate::key::Key;
use crate::value::Contract;
use core::marker::PhantomData;

// URef with type information about what value is in the global state
#[derive(Debug, Clone, PartialEq, Eq, Copy, Hash)]
pub struct UPointer<T>([u8; 32], PhantomData<T>);

impl<T> UPointer<T> {
    pub fn new(id: [u8; 32]) -> UPointer<T> {
        UPointer(id, PhantomData)
    }
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ContractPointer {
    Hash([u8; 32]),
    URef(UPointer<Contract>),
}

impl<T> From<UPointer<T>> for Key {
    fn from(u_ptr: UPointer<T>) -> Self {
        Key::URef(u_ptr.0)
    }
}

impl From<ContractPointer> for Key {
    fn from(c_ptr: ContractPointer) -> Self {
        match c_ptr {
            ContractPointer::Hash(h) => Key::Hash(h),
            ContractPointer::URef(u_ptr) => u_ptr.into(),
        }
    }
}