Skip to content

Commit

Permalink
Add migration info and auto-inject proper version for all contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Aug 26, 2020
1 parent 7f0a128 commit 9f93435
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion contracts/cw1-subkeys/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::ops::{AddAssign, Sub};

// version info for migration info
const CONTRACT_NAME: &str = "crates.io:cw1-subkeys";
const CONTRACT_VERSION: &str = "v0.1.0";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

pub fn init<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw1-whitelist/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::state::{admin_list, admin_list_read, AdminList};

// version info for migration info
const CONTRACT_NAME: &str = "crates.io:cw1-whitelist";
const CONTRACT_VERSION: &str = "v0.1.0";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

pub fn init<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw20-base/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::state::{balances, balances_read, token_info, token_info_read, MinterD

// version info for migration info
const CONTRACT_NAME: &str = "crates.io:cw20-base";
const CONTRACT_VERSION: &str = "v0.1.0";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

pub fn init<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw20-escrow/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use cosmwasm_storage::prefixed;

// version info for migration info
const CONTRACT_NAME: &str = "crates.io:cw20-escrow";
const CONTRACT_VERSION: &str = "v0.1.0";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

pub fn init<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
Expand Down
3 changes: 2 additions & 1 deletion contracts/cw20-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ backtraces = ["cosmwasm-std/backtraces"]
library = []

[dependencies]
cw2 = { path = "../../packages/cw2", version = "0.1.1" }
cw20 = { path = "../../packages/cw20", version = "0.1.1" }
cosmwasm-std = { version = "0.10.1", features = ["staking"] }
cosmwasm-storage = { version = "0.10.1" }
cw20 = { path = "../../packages/cw20", version = "0.1.1" }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
snafu = { version = "0.6.3" }
Expand Down
4 changes: 2 additions & 2 deletions contracts/cw20-staking/schema/init_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"properties": {
"decimals": {
"description": "decimal places of the derivative token (for UI) TODO: does this make sense? Do we need to normalize on this? We don't even know the decimals of the native token",
"description": "decimal places of the derivative token (for UI)",
"type": "integer",
"format": "uint8",
"minimum": 0.0
Expand All @@ -34,7 +34,7 @@
]
},
"name": {
"description": "name of the derivative token (FIXME: auto-generate?)",
"description": "name of the derivative token",
"type": "string"
},
"symbol": {
Expand Down
11 changes: 11 additions & 0 deletions contracts/cw20-staking/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use cosmwasm_std::{
coin, log, to_binary, Api, BankMsg, Binary, Decimal, Env, Extern, HandleResponse, HumanAddr,
InitResponse, Querier, StakingMsg, StdError, StdResult, Storage, Uint128, WasmMsg,
};
use cw2::{set_contract_version, ContractVersion};

use crate::msg::{
BalanceResponse, ClaimsResponse, HandleMsg, InitMsg, InvestmentResponse, QueryMsg,
Expand All @@ -14,11 +15,21 @@ use crate::state::{

const FALLBACK_RATIO: Decimal = Decimal::one();

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

pub fn init<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
env: Env,
msg: InitMsg,
) -> StdResult<InitResponse> {
let version = ContractVersion {
contract: CONTRACT_NAME.to_string(),
version: CONTRACT_VERSION.to_string(),
};
set_contract_version(&mut deps.storage, &version)?;

// ensure the validator is registered
let vals = deps.querier.query_validators()?;
if !vals.iter().any(|v| v.address == msg.validator) {
Expand Down
4 changes: 1 addition & 3 deletions contracts/cw20-staking/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ use cosmwasm_std::{Coin, Decimal, HumanAddr, Uint128};

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct InitMsg {
/// name of the derivative token (FIXME: auto-generate?)
/// name of the derivative token
pub name: String,
/// symbol / ticker of the derivative token
pub symbol: String,
/// decimal places of the derivative token (for UI)
/// TODO: does this make sense? Do we need to normalize on this?
/// We don't even know the decimals of the native token
pub decimals: u8,

/// This is the validator that all tokens will be bonded to
Expand Down

0 comments on commit 9f93435

Please sign in to comment.