-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(contracts/basic-analyzer): initial version
- Loading branch information
Showing
8 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |