Skip to content

Commit

Permalink
feat(contracts/basic-analyzer): initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
Pitasi committed May 13, 2024
1 parent 2367e15 commit d97d627
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 0 deletions.
17 changes: 17 additions & 0 deletions contracts/Cargo.lock

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

6 changes: 6 additions & 0 deletions contracts/contracts/basic-analyzer/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[alias]
wasm = "build --release --lib --target wasm32-unknown-unknown"
wasm-debug = "build --lib --target wasm32-unknown-unknown"
unit-test = "test --lib"
integration-test = "test --test integration"
schema = "run --bin schema"
31 changes: 31 additions & 0 deletions contracts/contracts/basic-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "basic-analyzer"
version.workspace = true
edition = "2021"
description = ""
license = "Apache-2.0"
repository = "https://github.com/warden-protocol/wardenprotocol"
homepage = "https://wardenprotocol.org/"

[lib]
crate-type = ["cdylib", "rlib"]

[features]
# use library feature to disable all instantiate/execute/query exports
library = []
test-utils = []

[dependencies]
cosmwasm-schema = { workspace = true }
cw2 = { workspace = true }
bindings = { workspace = true }
cosmwasm-std = { workspace = true, features = ["staking"] }
schemars = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }
serde-json-wasm = "1.0.1"

[dev-dependencies]
anyhow = "1"
assert_matches = "1"
derivative = "2"
10 changes: 10 additions & 0 deletions contracts/contracts/basic-analyzer/src/bin/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use cosmwasm_schema::write_api;

use basic_analyzer::msg::{ExecuteMsg, QueryMsg};

fn main() {
write_api! {
execute: ExecuteMsg,
query: QueryMsg
}
}
50 changes: 50 additions & 0 deletions contracts/contracts/basic-analyzer/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use crate::error::ContractError;
use crate::msg::{AnalyzeResult, ExecuteMsg, QueryMsg};
use bindings::WardenProtocolQuery;
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, StdError, StdResult};
use cw2::set_contract_version;

// version info for migration info
const CONTRACT_NAME: &str = "crates.io:wardenprotocol-basic-analyzer";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut<WardenProtocolQuery>,
_env: Env,
_info: MessageInfo,
_msg: Empty,
) -> StdResult<Response> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Ok(Response::default())
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
_deps: DepsMut<WardenProtocolQuery>,
_env: Env,
_info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
match msg {
ExecuteMsg::Analyze { input } => analyze(input),
}
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(_deps: Deps<WardenProtocolQuery>, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {}
}

pub fn analyze(input: Binary) -> Result<Response, ContractError> {
let result = AnalyzeResult {
length: input.len() as u64,
};

let ser_result = serde_json_wasm::to_vec(&result)
.map_err(|e| -> ContractError { StdError::generic_err(e.to_string()).into() })?;
let res = Response::new().set_data(ser_result);
Ok(res)
}
11 changes: 11 additions & 0 deletions contracts/contracts/basic-analyzer/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use cosmwasm_std::StdError;
use thiserror::Error;

#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
#[error("{0}")]
Std(#[from] StdError),

#[error("Unauthorized")]
Unauthorized {},
}
5 changes: 5 additions & 0 deletions contracts/contracts/basic-analyzer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub mod contract;
pub mod error;
pub mod msg;

pub use crate::error::ContractError;
16 changes: 16 additions & 0 deletions contracts/contracts/basic-analyzer/src/msg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::Binary;

#[cw_serde]
pub enum ExecuteMsg {
Analyze { input: Binary },
}

#[cw_serde]
pub struct AnalyzeResult {
pub length: u64,
}

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {}

0 comments on commit d97d627

Please sign in to comment.