Skip to content

Commit

Permalink
Add set_wasm_version! to create custom Wasm section
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Nov 14, 2023
1 parent 88762e8 commit 5fbfdfb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
9 changes: 8 additions & 1 deletion contracts/cyberpunk/Cargo.lock

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

3 changes: 2 additions & 1 deletion contracts/cyberpunk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cyberpunk"
version = "0.0.0"
version = "0.12.345"
authors = ["Tomasz Kurcz <[email protected]>"]
edition = "2021"
publish = false
Expand Down Expand Up @@ -33,6 +33,7 @@ cosmwasm-schema = { path = "../../packages/schema" }
cosmwasm-std = { path = "../../packages/std", default-features = false, features = ["abort", "cosmwasm_1_3"] }
rust-argon2 = "0.8"
thiserror = "1.0.26"
const-str = "0.5.6"

[dev-dependencies]
cosmwasm-vm = { path = "../../packages/vm", default-features = false }
Expand Down
6 changes: 6 additions & 0 deletions contracts/cyberpunk/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ use cosmwasm_std::{

use crate::errors::ContractError;
use crate::msg::{ExecuteMsg, QueryMsg};
use crate::set_wasm_version;

const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME");
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

set_wasm_version!(CONTRACT_NAME, CONTRACT_VERSION);

#[entry_point]
pub fn instantiate(
Expand Down
2 changes: 2 additions & 0 deletions contracts/cyberpunk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod contract;
pub mod errors;
pub mod msg;

mod set_version;
15 changes: 15 additions & 0 deletions contracts/cyberpunk/src/set_version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#[macro_export]
macro_rules! set_wasm_version {
($s1: expr, $s2: expr) => {
/// Private module with no stability guarantees
mod __cw5 {
use super::*;

const FULL: &str = const_str::concat!("/", $s1, "/", $s2);

#[link_section = "cw5"]
#[allow(unused)]
static AS_BYTES: [u8; FULL.len()] = const_str::to_byte_array!(FULL);
}
};
}

0 comments on commit 5fbfdfb

Please sign in to comment.