Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First System ADO - Current Block creating endpoints anywhere in the VFS #561

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Boolean Storage ADO [(#513)](https://github.com/andromedaprotocol/andromeda-core/pull/513)
- Added Counter ADO [(#514)](https://github.com/andromedaprotocol/andromeda-core/pull/514)
- Added Date Time ADO [(#519)](https://github.com/andromedaprotocol/andromeda-core/pull/519)
- Added System ADO - current block [(#526)](https://github.com/andromedaprotocol/andromeda-core/pull/526)
- Added Authorized CW721 Addresses to Marketplace [(#542)](https://github.com/andromedaprotocol/andromeda-core/pull/542)
- Added IBC Registry ADO [(#566)](https://github.com/andromedaprotocol/andromeda-core/pull/566)

Expand Down
28 changes: 28 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"contracts/finance/*",
# "contracts/automation/*",
"contracts/modules/*",
"contracts/systems/*",
"contracts/os/*",

#Internal
Expand Down Expand Up @@ -37,6 +38,7 @@ andromeda-data-storage = { path = "./packages/andromeda-data-storage", version =
andromeda-modules = { path = "./packages/andromeda-modules", version = "2.0.0" }
andromeda-app = { path = "./packages/andromeda-app", version = "1.0.0" }
andromeda-ecosystem = { path = "./packages/andromeda-ecosystem", version = "1.0.0" }
andromeda-systems = { path = "./packages/andromeda-systems", version = "1.0.0" }
andromeda-testing = { path = "./packages/andromeda-testing", version = "1.0.0" }
andromeda-testing-e2e = { path = "./packages/andromeda-testing-e2e", version = "1.0.0" }

Expand Down
24 changes: 24 additions & 0 deletions DEADJOE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

*** These modified files were found in JOE when it aborted on Wed Sep 25 08:34:44 2024
*** JOE was aborted by UNIX signal 1

*** File '/home/paperspace/WorkSpace/rust/perf/system-current-block/.git/MERGE_MSG'
Merge branch 'development' of https://github.com/andromedaprotocol/andromeda-core into mdjakovic/system-current-block
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.

*** File '(Unnamed)'
/home/paperspace/WorkSpace/MiniCPM-V/.git/COMMIT_EDITMSG
* Startup Log *
* Shell 2 *
/home/paperspace/WorkSpace/rust/perf/system-ados/.git/MERGE_MSG
/home/paperspace/WorkSpace/rust/perf/system-current-block/.git/MERGE_MSG

*** File '* Startup Log *'
Processing '/etc/joe/editorrc'...
Processing '/etc/joe/ftyperc'...
Finished processing /etc/joe/ftyperc
Finished processing /etc/joe/editorrc
10 changes: 10 additions & 0 deletions contracts/os/andromeda-vfs/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ pub fn execute(
name,
parent_address,
} => execute::add_child(execute_env, name, parent_address),
ExecuteMsg::AddSystemAdoPath { name, root } => {
execute::add_system_ado_path(execute_env, name, root)
}
ExecuteMsg::RegisterLibrary {
lib_name,
lib_address,
Expand Down Expand Up @@ -107,7 +110,14 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result<Binary, ContractErr
max,
limit,
} => encode_binary(&query::subdir(deps, path, min, max, limit)?),
QueryMsg::SubSystem {
root,
min,
max,
limit,
} => encode_binary(&query::subsystem(deps, root, min, max, limit)?),
QueryMsg::Paths { addr } => encode_binary(&query::paths(deps, addr)?),
QueryMsg::SystemPaths { addr } => encode_binary(&query::system_paths(deps, addr)?),
QueryMsg::GetUsername { address } => encode_binary(&query::get_username(deps, address)?),
QueryMsg::GetLibrary { address } => encode_binary(&query::get_library_name(deps, address)?),
QueryMsg::ResolveSymlink { path } => encode_binary(&query::get_symlink(deps, path)?),
Expand Down
43 changes: 41 additions & 2 deletions contracts/os/andromeda-vfs/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use cosmwasm_std::{
};

use crate::state::{
add_path_symlink, add_pathname, paths, resolve_pathname, ADDRESS_LIBRARY, ADDRESS_USERNAME,
LIBRARIES, USERS,
add_path_symlink, add_pathname, add_system_ado_path_name, paths, resolve_pathname,
system_ado_paths, ADDRESS_LIBRARY, ADDRESS_USERNAME, LIBRARIES, USERS,
};

pub struct ExecuteEnv<'a> {
Expand Down Expand Up @@ -139,6 +139,45 @@ pub fn add_child(
Ok(Response::default())
}

pub fn add_system_ado_path(
env: ExecuteEnv,
name: String,
root: String,
) -> Result<Response, ContractError> {
let ExecuteEnv { deps, info, .. } = env;
let name = name.to_lowercase();
let root = root.to_lowercase();

let sender_code_id_res = deps.querier.query_wasm_contract_info(info.sender.clone());
// Sender must be a system ADO contract
ensure!(sender_code_id_res.is_ok(), ContractError::Unauthorized {});

mdjakovic0920 marked this conversation as resolved.
Show resolved Hide resolved
validate_component_name(name.clone())?;
validate_component_name(root.clone())?;

let existing = system_ado_paths()
.load(deps.storage, &(root.clone(), name.clone()))
.ok();
// Ensure that this path is not already added or if already added it should point to same address as above. This prevent external users to override existing paths.
// Only add path method can override existing paths as its safe because only owner of the path can execute it
match existing {
None => {
add_system_ado_path_name(deps.storage, root.clone(), name.clone(), info.sender)?;
}
Some(path) => {
ensure!(path.address == info.sender, ContractError::Unauthorized {});
return Err(ContractError::CustomError {
msg: "System ADO already exists".to_string(),
});
}
mdjakovic0920 marked this conversation as resolved.
Show resolved Hide resolved
};
Ok(Response::default().add_attributes(vec![
attr("action", "add_system_ado_path"),
attr("name", name.clone()),
attr("root", root.clone()),
]))
}

const MAX_USERNAME_LENGTH: u64 = 30;

pub fn register_user(
Expand Down
20 changes: 17 additions & 3 deletions contracts/os/andromeda-vfs/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use andromeda_std::os::vfs::{validate_path_name, SubDirBound};
use andromeda_std::os::vfs::{validate_path_name, SubDirBound, SubSystemBound};
use andromeda_std::{amp::AndrAddr, error::ContractError};
use cosmwasm_std::{Addr, Deps};

use crate::state::{
get_paths, get_subdir, resolve_pathname, resolve_symlink, PathInfo, ADDRESS_LIBRARY,
ADDRESS_USERNAME,
get_paths, get_subdir, get_subsystem, get_system_paths, resolve_pathname, resolve_symlink,
PathInfo, SystemAdoPathInfo, ADDRESS_LIBRARY, ADDRESS_USERNAME,
};

pub fn resolve_path(deps: Deps, path: AndrAddr) -> Result<Addr, ContractError> {
Expand All @@ -22,10 +22,24 @@ pub fn subdir(
get_subdir(deps.storage, deps.api, path, min, max, limit)
}

pub fn subsystem(
deps: Deps,
root: String,
min: Option<SubSystemBound>,
max: Option<SubSystemBound>,
limit: Option<u32>,
) -> Result<Vec<SystemAdoPathInfo>, ContractError> {
get_subsystem(deps.storage, root, min, max, limit)
}

pub fn paths(deps: Deps, addr: Addr) -> Result<Vec<String>, ContractError> {
get_paths(deps.storage, addr)
}

pub fn system_paths(deps: Deps, addr: Addr) -> Result<Vec<String>, ContractError> {
get_system_paths(deps.storage, addr)
}

pub fn get_symlink(deps: Deps, addr: AndrAddr) -> Result<AndrAddr, ContractError> {
resolve_symlink(deps.storage, deps.api, addr)
}
Expand Down
Loading
Loading