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
use std::convert::TryFrom;
use casper_execution_engine::{shared, shared::stored_value::StoredValue};
use casper_types::{account::AccountHash, contracts::NamedKeys, URef};
use crate::{Error, Result};
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Account {
inner: shared::account::Account,
}
impl Account {
pub(crate) fn new(account: shared::account::Account) -> Self {
Account { inner: account }
}
pub fn account_hash(&self) -> AccountHash {
self.inner.account_hash()
}
pub fn named_keys(&self) -> &NamedKeys {
self.inner.named_keys()
}
pub fn main_purse(&self) -> URef {
self.inner.main_purse()
}
}
impl From<shared::account::Account> for Account {
fn from(value: shared::account::Account) -> Self {
Account::new(value)
}
}
impl TryFrom<StoredValue> for Account {
type Error = Error;
fn try_from(value: StoredValue) -> Result<Self> {
match value {
StoredValue::Account(account) => Ok(Account::new(account)),
_ => Err(Error::from(String::from("StoredValue is not an Account"))),
}
}
}