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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
use alloc::{collections::BTreeSet, vec::Vec};
use crate::{
account::AccountHash,
bytesrepr::{FromBytes, ToBytes},
system::{
auction::{Bid, EraInfo, Error, SeigniorageRecipientsSnapshot, UnbondingPurse},
mint,
},
CLTyped, EraId, Key, KeyTag, URef, BLAKE2B_DIGEST_LENGTH, U512,
};
pub trait RuntimeProvider {
fn get_caller(&self) -> AccountHash;
fn is_allowed_session_caller(&self, account_hash: &AccountHash) -> bool;
fn named_keys_get(&self, name: &str) -> Option<Key>;
fn get_keys(&mut self, key_tag: &KeyTag) -> Result<BTreeSet<Key>, Error>;
fn blake2b<T: AsRef<[u8]>>(&self, data: T) -> [u8; BLAKE2B_DIGEST_LENGTH];
}
pub trait StorageProvider {
fn read<T: FromBytes + CLTyped>(&mut self, uref: URef) -> Result<Option<T>, Error>;
fn write<T: ToBytes + CLTyped>(&mut self, uref: URef, value: T) -> Result<(), Error>;
fn read_bid(&mut self, account_hash: &AccountHash) -> Result<Option<Bid>, Error>;
fn write_bid(&mut self, account_hash: AccountHash, bid: Bid) -> Result<(), Error>;
fn read_withdraw(&mut self, account_hash: &AccountHash) -> Result<Vec<UnbondingPurse>, Error>;
fn write_withdraw(
&mut self,
account_hash: AccountHash,
unbonding_purses: Vec<UnbondingPurse>,
) -> Result<(), Error>;
fn record_era_info(&mut self, _era_id: EraId, era_summary: EraInfo) -> Result<(), Error>;
fn write_seigniorage_recipients_snapshot(
&mut self,
uref: URef,
snapshot: SeigniorageRecipientsSnapshot,
) -> Result<(), Error>;
}
pub trait MintProvider {
fn unbond(&mut self, unbonding_purse: &UnbondingPurse) -> Result<(), Error>;
fn mint_transfer_direct(
&mut self,
to: Option<AccountHash>,
source: URef,
target: URef,
amount: U512,
id: Option<u64>,
) -> Result<Result<(), mint::Error>, Error>;
fn mint_into_existing_purse(&mut self, amount: U512, existing_purse: URef)
-> Result<(), Error>;
fn create_purse(&mut self) -> Result<URef, Error>;
fn get_balance(&mut self, purse: URef) -> Result<Option<U512>, Error>;
fn read_base_round_reward(&mut self) -> Result<U512, Error>;
fn mint(&mut self, amount: U512) -> Result<URef, Error>;
fn reduce_total_supply(&mut self, amount: U512) -> Result<(), Error>;
}
pub trait AccountProvider {
fn get_main_purse(&self) -> Result<URef, Error>;
}