Skip to content

Commit ebc3e55

Browse files
authored
feat(access-manager): init (#5175)
2 parents 1ceb0da + fb24c70 commit ebc3e55

File tree

29 files changed

+4840
-37
lines changed

29 files changed

+4840
-37
lines changed

Cargo.lock

Lines changed: 26 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ members = [
250250
"cosmwasm/osmosis-tokenfactory-token-minter",
251251
"cosmwasm/cw20-token-minter",
252252
"cosmwasm/cw-account",
253+
"cosmwasm/access-manager",
253254
"cosmwasm/cw-escrow-vault",
254255
"cosmwasm/cw-unionversal-token",
255256
"cosmwasm/ucs03-zkgm-token-minter-api",
@@ -389,6 +390,7 @@ ibc-union-msg = { path = "cosmwasm/ibc-union/core/msg", default-feature
389390

390391
frissitheto = { path = "lib/frissitheto", default-features = false }
391392

393+
access-manager = { path = "cosmwasm/access-manager", default-features = false }
392394
cw-account = { path = "cosmwasm/cw-account", default-features = false }
393395
cw-escrow-vault = { path = "cosmwasm/cw-escrow-vault", default-features = false }
394396
cw-unionversal-token = { path = "cosmwasm/cw-unionversal-token", default-features = false }

cosmwasm/access-manager/Cargo.toml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[package]
2+
name = "access-manager"
3+
version = "0.0.0"
4+
5+
authors = { workspace = true }
6+
edition = { workspace = true }
7+
license-file = { workspace = true }
8+
publish = { workspace = true }
9+
repository = { workspace = true }
10+
11+
[lints]
12+
workspace = true
13+
14+
[lib]
15+
crate-type = ["cdylib", "rlib"]
16+
17+
[dependencies]
18+
bincode = { workspace = true, features = ["derive"] }
19+
cosmwasm-std = { workspace = true, features = ["cosmwasm_1_3", "staking"] }
20+
depolama = { workspace = true, features = ["iterator"] }
21+
embed-commit = { workspace = true }
22+
frissitheto = { workspace = true }
23+
serde = { workspace = true, features = ["derive"] }
24+
serde-json-wasm = "1.0.0"
25+
serde-utils = { workspace = true }
26+
serde_json = { workspace = true, features = ["raw_value"] }
27+
sha2 = { workspace = true }
28+
strum = { version = "0.27.2", features = ["derive"] }
29+
thiserror = { workspace = true }
30+
unionlabs-encoding = { workspace = true, features = ["bincode"] }
31+
unionlabs-primitives = { workspace = true, features = ["bincode", "serde", "generic-array-compat"] }
32+
33+
[features]
34+
default = []
35+
library = []
36+
37+
[dev-dependencies]
38+
hex-literal = { workspace = true }
39+
itertools = { workspace = true }
40+
41+
# TODO: Do something like this so the solidity codeblocks are highlighted correctly: https://users.rust-lang.org/t/how-did-slint-create-custom-syntax-highlight-link-and-preview-for-their-code-examples/85294/2
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
use cosmwasm_std::{Addr, Coin, Deps, DepsMut, Env, Event, MessageInfo, QuerierWrapper, Storage};
2+
use serde_json::value::RawValue;
3+
4+
#[must_use]
5+
pub(crate) struct ExecCtx<'info, 'deps> {
6+
events: Vec<Event>,
7+
deps: DepsMut<'deps>,
8+
env: &'info Env,
9+
info: &'info MessageInfo,
10+
data: &'info RawValue,
11+
}
12+
13+
#[derive(Clone, Copy)]
14+
pub(crate) struct QueryCtx<'info, 'deps> {
15+
deps: Deps<'deps>,
16+
env: &'info Env,
17+
}
18+
19+
impl<'info, 'deps> QueryCtx<'info, 'deps> {
20+
pub fn new(deps: Deps<'deps>, env: &'info Env) -> Self {
21+
Self { deps, env }
22+
}
23+
}
24+
25+
impl<'info, 'deps> ExecCtx<'info, 'deps> {
26+
pub fn new(
27+
deps: DepsMut<'deps>,
28+
env: &'info Env,
29+
info: &'info MessageInfo,
30+
data: &'info RawValue,
31+
) -> Self {
32+
Self {
33+
events: vec![],
34+
deps,
35+
info,
36+
env,
37+
data,
38+
}
39+
}
40+
41+
pub fn events(self) -> Vec<Event> {
42+
self.events
43+
}
44+
}
45+
46+
pub(crate) trait IQueryCtx<'info> {
47+
fn querier(&self) -> QuerierWrapper;
48+
fn address_this(&self) -> &'info Addr;
49+
fn timestamp(&self) -> u64;
50+
}
51+
52+
pub(crate) trait IExecCtx<'info> {
53+
fn emit(&mut self, event: impl Into<Event>);
54+
fn msg_sender(&self) -> &'info Addr;
55+
fn msg_data(&self) -> &'info str;
56+
fn value(&self) -> &[Coin];
57+
fn query_ctx<'a>(&'a self) -> QueryCtx<'info, 'a>;
58+
}
59+
60+
impl<'info> IQueryCtx<'info> for ExecCtx<'info, '_> {
61+
fn querier(&self) -> QuerierWrapper {
62+
self.deps.querier
63+
}
64+
65+
fn address_this(&self) -> &'info Addr {
66+
&self.env.contract.address
67+
}
68+
69+
fn timestamp(&self) -> u64 {
70+
self.env.block.time.seconds()
71+
}
72+
}
73+
74+
impl<'info> IExecCtx<'info> for ExecCtx<'info, '_> {
75+
fn emit(&mut self, event: impl Into<Event>) {
76+
self.events.push(event.into());
77+
}
78+
79+
fn msg_sender(&self) -> &'info Addr {
80+
&self.info.sender
81+
}
82+
83+
fn msg_data(&self) -> &'info str {
84+
self.data.get()
85+
}
86+
87+
fn value(&self) -> &[Coin] {
88+
&self.info.funds
89+
}
90+
91+
fn query_ctx<'a>(&'a self) -> QueryCtx<'info, 'a> {
92+
QueryCtx::new(self.deps.as_ref(), self.env)
93+
}
94+
}
95+
96+
impl<'info> IQueryCtx<'info> for QueryCtx<'info, '_> {
97+
fn querier(&self) -> QuerierWrapper {
98+
self.deps.querier
99+
}
100+
101+
fn address_this(&self) -> &'info Addr {
102+
&self.env.contract.address
103+
}
104+
105+
fn timestamp(&self) -> u64 {
106+
self.env.block.time.seconds()
107+
}
108+
}
109+
110+
pub(crate) trait HasStorage<'storage> {
111+
type Storage: 'storage;
112+
113+
fn storage(self) -> Self::Storage;
114+
}
115+
116+
impl<'deps: 'call, 'call> HasStorage<'call> for &'call mut ExecCtx<'_, 'deps> {
117+
type Storage = &'call mut dyn Storage;
118+
119+
fn storage(self) -> Self::Storage {
120+
self.deps.storage
121+
}
122+
}
123+
124+
impl<'deps> HasStorage<'deps> for QueryCtx<'_, 'deps> {
125+
type Storage = &'deps dyn Storage;
126+
127+
fn storage(self) -> Self::Storage {
128+
self.deps.storage
129+
}
130+
}

0 commit comments

Comments
 (0)