compound_erc20/
data.rs

1use casper_types::{ApiError, ContractHash, ContractPackageHash, Key};
2use casperlabs_contract_utils::{get_key, set_key};
3
4pub const SELF_CONTRACT_HASH: &str = "self_contract_hash";
5pub const CONTRACT_PACKAGE_HASH: &str = "contract_package_hash";
6
7pub fn set_contract_hash(contract_hash: ContractHash) {
8    set_key(SELF_CONTRACT_HASH, contract_hash);
9}
10
11pub fn get_contract_hash() -> ContractHash {
12    get_key(SELF_CONTRACT_HASH).unwrap_or_default()
13}
14
15pub fn set_package_hash(package_hash: ContractPackageHash) {
16    set_key(CONTRACT_PACKAGE_HASH, package_hash);
17}
18
19pub fn get_package_hash() -> ContractPackageHash {
20    get_key(CONTRACT_PACKAGE_HASH).unwrap_or_default()
21}
22
23pub fn zero_address() -> Key {
24    Key::from_formatted_str("hash-0000000000000000000000000000000000000000000000000000000000000000")
25        .unwrap()
26}
27
28pub fn account_zero_address() -> Key {
29    Key::from_formatted_str(
30        "account-hash-0000000000000000000000000000000000000000000000000000000000000000",
31    )
32    .unwrap()
33}
34
35#[repr(u16)]
36pub enum Error {
37    CompoundErc20ZeroAddress1 = 20,
38    CompoundErc20ZeroAddress2 = 21,
39}
40
41impl From<Error> for ApiError {
42    fn from(error: Error) -> ApiError {
43        ApiError::User(error as u16)
44    }
45}