Skip to content

Commit

Permalink
chore: update minimal version message and selector
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasmpw committed Aug 21, 2023
1 parent 6021592 commit 3f61170
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/test_generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function test-template() {
GIT_BRANCH=$(git -C "$REPO_ROOT" branch --show-current)

echo "Generating project from local repository (branch $GIT_BRANCH) ..."
cargo generate --path "$REPO_ROOT" --name "$PROJECT_NAME" -d minimal=false "$TEMPLATE"
cargo generate --path "$REPO_ROOT" --name "$PROJECT_NAME" -d version=full "$TEMPLATE"

(
cd "$PROJECT_NAME"
Expand Down
17 changes: 10 additions & 7 deletions increment/cargo-generate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
# The files will be copied 1:1 to the target project. To avoid shipping them completely add them to `.genignore`.
exclude = [".circleci/config.yml"]

[placeholders.minimal]
type = "bool"
prompt = """The full template includes some example logic in case you're new to CosmWasm smart contracts.
The minimal template assumes you already know how to write your own logic, and doesn't get in your way.
[placeholders.version]
type = "string"
choices = ["full", "minimal"]
prompt = """This template has 2 versions:
Would you like to generate the minimal template?"""
default = false
- The full template includes example logic in case you're new to CosmWasm smart contracts.
- The minimal template assumes you already know how to write your own logic, includes the bare minimum and doesn't get in your way.
[conditional.'minimal']
Which version do you want to generate?"""
default = "full"

[conditional.'version == "minimal"']
ignore = [
"Developing.md",
"Importing.md",
Expand Down
36 changes: 18 additions & 18 deletions increment/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{% raw %}{{% endraw %}{% unless minimal %}to_binary, {% endunless %}Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};
{% if minimal %}// {% endif %}use cw2::set_contract_version;
use cosmwasm_std::{% raw %}{{% endraw %}{% unless version == "minimal" %}to_binary, {% endunless %}Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};
{% if version == "minimal" %}// {% endif %}use cw2::set_contract_version;

use crate::error::ContractError;
use crate::msg::{ExecuteMsg, {% unless minimal %}GetCountResponse, {% endunless %}InstantiateMsg, QueryMsg};
{% unless minimal %}use crate::state::{State, STATE};
{% unless version == "minimal" %}use crate::state::{State, STATE};
{% endunless %}
{% if minimal %}/*
{% if version == "minimal" %}/*
{% endif %}// version info for migration info
const CONTRACT_NAME: &str = "crates.io:{{project-name}}";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
{% if minimal %}*/
{% if version == "minimal" %}*/
{% endif %}
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
{% if minimal %}_{% endif %}deps: DepsMut,
{% if version == "minimal" %}_{% endif %}deps: DepsMut,
_env: Env,
{% if minimal %}_{% endif %}info: MessageInfo,
{% if minimal %}_{% endif %}msg: InstantiateMsg,
{% if version == "minimal" %}_{% endif %}info: MessageInfo,
{% if version == "minimal" %}_{% endif %}msg: InstantiateMsg,
) -> Result<Response, ContractError> {
{% if minimal %}unimplemented!(){% else %}let state = State {
{% if version == "minimal" %}unimplemented!(){% else %}let state = State {
count: msg.count,
owner: info.sender.clone(),
};
Expand All @@ -35,16 +35,16 @@ pub fn instantiate(

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
{% if minimal %}_{% endif %}deps: DepsMut,
{% if version == "minimal" %}_{% endif %}deps: DepsMut,
_env: Env,
{% if minimal %}_{% endif %}info: MessageInfo,
{% if minimal %}_{% endif %}msg: ExecuteMsg,
{% if version == "minimal" %}_{% endif %}info: MessageInfo,
{% if version == "minimal" %}_{% endif %}msg: ExecuteMsg,
) -> Result<Response, ContractError> {
{% if minimal %}unimplemented!(){% else %}match msg {
{% if version == "minimal" %}unimplemented!(){% else %}match msg {
ExecuteMsg::Increment {} => execute::increment(deps),
ExecuteMsg::Reset { count } => execute::reset(deps, info, count),
}{% endif %}
}{% unless minimal %}
}{% unless version == "minimal" %}

pub mod execute {
use super::*;
Expand All @@ -71,11 +71,11 @@ pub mod execute {
}{% endunless %}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query({% if minimal %}_{% endif %}deps: Deps, _env: Env, {% if minimal %}_{% endif %}msg: QueryMsg) -> StdResult<Binary> {
{% if minimal %}unimplemented!(){% else %}match msg {
pub fn query({% if version == "minimal" %}_{% endif %}deps: Deps, _env: Env, {% if version == "minimal" %}_{% endif %}msg: QueryMsg) -> StdResult<Binary> {
{% if version == "minimal" %}unimplemented!(){% else %}match msg {
QueryMsg::GetCount {} => to_binary(&query::count(deps)?),
}{% endif %}
}{% unless minimal %}
}{% unless version == "minimal" %}

pub mod query {
use super::*;
Expand All @@ -87,7 +87,7 @@ pub mod query {
}{% endunless %}

#[cfg(test)]
mod tests {% raw %}{{% endraw %}{% unless minimal %}
mod tests {% raw %}{{% endraw %}{% unless version == "minimal" %}
use super::*;
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::{coins, from_binary};
Expand Down
6 changes: 3 additions & 3 deletions increment/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

{% if minimal %}use cosmwasm_std::{to_binary, Addr, CosmosMsg, StdResult, WasmMsg};{% else %}use cosmwasm_std::{
{% if version == "minimal" %}use cosmwasm_std::{to_binary, Addr, CosmosMsg, StdResult, WasmMsg};{% else %}use cosmwasm_std::{
to_binary, Addr, CosmosMsg, CustomQuery, Querier, QuerierWrapper, StdResult, WasmMsg, WasmQuery,
};{% endif %}

{% if minimal %}use crate::msg::ExecuteMsg;{% else %}use crate::msg::{ExecuteMsg, GetCountResponse, QueryMsg};{% endif %}
{% if version == "minimal" %}use crate::msg::ExecuteMsg;{% else %}use crate::msg::{ExecuteMsg, GetCountResponse, QueryMsg};{% endif %}

/// CwTemplateContract is a wrapper around Addr that provides a lot of helpers
/// for working with this.
Expand All @@ -25,7 +25,7 @@ impl CwTemplateContract {
funds: vec![],
}
.into())
}{% unless minimal %}
}{% unless version == "minimal" %}

/// Get Count
pub fn count<Q, T, CQ>(&self, querier: &Q) -> StdResult<GetCountResponse>
Expand Down
2 changes: 1 addition & 1 deletion increment/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod contract;
mod error;
pub mod helpers;
{% unless minimal %}pub mod integration_tests;
{% unless version == "minimal" %}pub mod integration_tests;
{% endunless %}pub mod msg;
pub mod state;

Expand Down
8 changes: 4 additions & 4 deletions increment/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
use cosmwasm_schema::{cw_serde, QueryResponses};

#[cw_serde]
pub struct InstantiateMsg {% raw %}{{% endraw %}{% unless minimal %}
pub struct InstantiateMsg {% raw %}{{% endraw %}{% unless version == "minimal" %}
pub count: i32,
{% endunless %}}

#[cw_serde]
pub enum ExecuteMsg {% raw %}{{% endraw %}{% unless minimal %}
pub enum ExecuteMsg {% raw %}{{% endraw %}{% unless version == "minimal" %}
Increment {},
Reset { count: i32 },
{% endunless %}}

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {% raw %}{{% endraw %}{% unless minimal %}
pub enum QueryMsg {% raw %}{{% endraw %}{% unless version == "minimal" %}
// GetCount returns the current count as a json-encoded number
#[returns(GetCountResponse)]
GetCount {},
{% endunless %}}
{% unless minimal %}
{% unless version == "minimal" %}
// We define a custom struct for each query response
#[cw_serde]
pub struct GetCountResponse {
Expand Down
2 changes: 1 addition & 1 deletion increment/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% unless minimal %}use schemars::JsonSchema;
{% unless version == "minimal" %}use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use cosmwasm_std::Addr;
Expand Down

0 comments on commit 3f61170

Please sign in to comment.