Skip to content

Commit

Permalink
burn-auction bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed Jan 24, 2024
1 parent 63a0f1a commit 5617264
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 30 deletions.
16 changes: 11 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["burn-auction"]

# exclude = ["contracts/umee"]

[workspace.package]
Expand All @@ -23,8 +23,14 @@ debug-assertions = false
rpath = false

[workspace.dependencies]
cosmwasm-std = { version = "1.5.2", features = ["staking"] }
cosmwasm-schema = "1.5.2"
sylvia = "0.9.3"
cosmwasm-schema = "1.5"
cosmwasm-std = "1.5"
# {version = "1.5", features = ["cosmwasm_1_3"]} # "cosmwasm_1_4" # <- Enable this if you only deploy to chains that have CosmWasm 1.4 or higher
cw-storage-plus = "1.2.0"
cw2 = "1.1.2"

schemars = "0.8"
serde = "1.0.195"
serde = {version = "1.0.195", default-features = false, features = ["derive"]}
thiserror = {version = "1.0.49"}

sylvia = "0.9.3"
25 changes: 17 additions & 8 deletions burn-auction/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
[package]
name = "burnauction"
name = "burn-auction"
version = "0.1.0"
authors = { workspace = true }
#edition = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }
license = { workspace = true }

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

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

[dependencies]
cosmwasm-std = "1.5"
# itertools.workspace = true
# common = { path = "../common" }
cosmwasm-schema.workspace = true
cosmwasm-std.workspace = true
cw-storage-plus.workspace = true
cw2.workspace = true

schemars.workspace=true
serde.workspace=true
thiserror.workspace=true

[dev-dependencies]
# anyhow.workspace = true
# [dev-dependencies]
# cw-multi-test = "0.18.0"
12 changes: 12 additions & 0 deletions burn-auction/src/bin/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use cosmwasm_schema::write_api;

use {{crate_name}}::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};

fn main() {
write_api! {
instantiate: InstantiateMsg,
migrate: MigrateMsg,
execute: ExecuteMsg,
query: QueryMsg,
}
}
81 changes: 81 additions & 0 deletions burn-auction/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult};
use cw2::set_contract_version;

use crate::error::ContractError;
use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};

// version info for migration info
const CONTRACT_NAME: &str = "crates.io:{{project-name}}";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

/// Handling contract instantiation
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
_env: Env,
info: MessageInfo,
_msg: InstantiateMsg,
) -> Result<Response, ContractError> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

// With `Response` type, it is possible to dispatch message to invoke external logic.
// See: https://github.com/CosmWasm/cosmwasm/blob/main/SEMANTICS.md#dispatching-messages
Ok(Response::new()
.add_attribute("method", "instantiate")
.add_attribute("owner", info.sender))
}

/// Handling contract migration
/// To make a contract migratable, you need
/// - this entry_point implemented
/// - only contract admin can migrate, so admin has to be set at contract initiation time
/// Handling contract execution
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, ContractError> {
match msg {
// Find matched incoming message variant and execute them with your custom logic.
//
// With `Response` type, it is possible to dispatch message to invoke external logic.
// See: https://github.com/CosmWasm/cosmwasm/blob/main/SEMANTICS.md#dispatching-messages
}
}

/// Handling contract execution
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
_deps: DepsMut,
_env: Env,
_info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
match msg {
// Find matched incoming message variant and execute them with your custom logic.
//
// With `Response` type, it is possible to dispatch message to invoke external logic.
// See: https://github.com/CosmWasm/cosmwasm/blob/main/SEMANTICS.md#dispatching-messages
}
}

/// Handling contract query
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(_deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
// Find matched incoming message variant and query them your custom logic
// and then construct your query response with the type usually defined
// `msg.rs` alongside with the query message itself.
//
// use `cosmwasm_std::to_binary` to serialize query response to json binary.
}
}

/// Handling submessage reply.
/// For more info on submessage and reply, see https://github.com/CosmWasm/cosmwasm/blob/main/SEMANTICS.md#submessages
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn reply(_deps: DepsMut, _env: Env, _msg: Reply) -> Result<Response, ContractError> {
// With `Response` type, it is still possible to dispatch message to invoke external logic.
// See: https://github.com/CosmWasm/cosmwasm/blob/main/SEMANTICS.md#dispatching-messages

todo!()
}
16 changes: 16 additions & 0 deletions burn-auction/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use cosmwasm_std::StdError;
use thiserror::Error;

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

#[error("Unauthorized")]
Unauthorized {},

#[error("Custom Error val: {val:?}")]
CustomError { val: String },
// Add any other custom errors you like here.
// Look at https://docs.rs/thiserror/1.0.21/thiserror/ for details.
}
22 changes: 5 additions & 17 deletions burn-auction/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
use cosmwasm_std::{
entry_point, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, StdResult,
};
pub mod contract;
mod error;
pub mod msg;
pub mod state;

#[entry_point]
pub fn instantiate(
_deps: DepsMut,
_env: Env,
_info: MessageInfo,
_msg: Empty,
) -> StdResult<Response> {
Ok(Response::new())
}

#[cfg(test)]
mod tests {
use super::*;
}
pub use crate::error::ContractError;
30 changes: 30 additions & 0 deletions burn-auction/src/msg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use cosmwasm_schema::{cw_serde, QueryResponses};

/// Message type for `instantiate` entry_point
#[cw_serde]
pub struct InstantiateMsg {}

/// Message type for `execute` entry_point
#[cw_serde]
pub enum ExecuteMsg {}

/// Message type for `migrate` entry_point
#[cw_serde]
pub enum MigrateMsg {}

/// Message type for `query` entry_point
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
// This example query variant indicates that any client can query the contract
// using `YourQuery` and it will return `YourQueryResponse`
// This `returns` information will be included in contract's schema
// which is used for client code generation.
//
// #[returns(YourQueryResponse)]
// YourQuery {},
}

// We define a custom struct for each query response
// #[cw_serde]
// pub struct YourQueryResponse {}
2 changes: 2 additions & 0 deletions burn-auction/src/state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// use `cw_storage_plus` to create ORM-like interface to storage
// see: https://crates.io/crates/cw-storage-plus

0 comments on commit 5617264

Please sign in to comment.