Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Minor app macro changes #376

Merged
merged 7 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/abstract-app/examples/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct CounterReceiveMsg;
#[cosmwasm_schema::cw_serde]
pub struct CounterSudoMsg;

abstract_app::app_messages!(CounterApp, CounterExecMsg, CounterQueryMsg);
abstract_app::app_msg_types!(CounterApp, CounterExecMsg, CounterQueryMsg);

use abstract_app::{AppContract, AppError};

Expand Down Expand Up @@ -81,7 +81,7 @@ abstract_app::export_endpoints!(COUNTER_APP, CounterApp);
// ANCHOR_END: export

// ANCHOR: interface
abstract_app::create_interface!(COUNTER_APP, CounterApp);
abstract_app::cw_orch_interface!(COUNTER_APP, CounterApp, CounterAppInterface);
// ANCHOR_END: interface

mod handlers {
Expand Down
18 changes: 16 additions & 2 deletions packages/abstract-app/src/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,22 @@ mod reply;
mod sudo;

#[macro_export]
/// Exports all entrypoints
/// Disable export with "library" feature
/// Exports all entry-points, should be enabled by default.
/// - instantiate
/// - execute
/// - query
/// - migrate
/// - reply
/// - sudo
///
/// ## Usage
/// Requires two arguments:
/// 1. The App constant.
/// 2. The App type.
///
/// ```ignore
/// abstract_app::export_endpoints!(MY_APP, MyApp);
/// ```
macro_rules! export_endpoints {
($app_const:expr, $app_type:ty) => {
/// Instantiate entrypoint
Expand Down
56 changes: 50 additions & 6 deletions packages/abstract-app/src/interface.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
#[macro_export]
/// Creates the interface for working with the app wth cw-orch
macro_rules! create_interface {
($app_const:expr, $app_type:ident) => {
/// Creates the interface for working with the app with [cw-orch](https://github.com/AbstractSDK/cw-orchestrator).
/// This generates all the necessary code used to interact with the app in an cw-orch environment
///
/// ## Usage
/// The macro takes three arguments:
/// 1. The app's constant, declared in `contract.rs`.
/// 2. The app's type, declared in `contract.rs`.
/// 3. The name of the interface struct to be generated.
/// ```rust,ignore
/// cw_orch_interface!(APP, App, AppInterface);
/// ```
///
/// This will generate :
/// ```rust,ignore
/// pub mod interface{
/// #[cw_orch::interface(App::InstantiateMsg, App::ExecuteMsg, App::QueryMsg, App::MigrateMsg)]
/// pub struct AppInterface;
///
/// impl <Chain: cw_orch::prelude::CwEnv> cw_orch::prelude::Uploadable for AppInterface<Chain> {
/// // Looks for the wasm file in the app's artifacts directory
/// // The name of the wasm file should contain the app crate name (snake_cased)
/// fn wasm(&self) -> cw_orch::prelude::WasmPath {
/// let wasm_name = env!("CARGO_CRATE_NAME").replace('-', "_");
/// cw_orch::prelude::ArtifactsDir::auto(Some(env!("CARGO_MANIFEST_DIR").to_string()))
/// .find_wasm_path(&wasm_name).unwrap()
/// }
///
/// fn wrapper(
/// &self,
/// ) -> Box<dyn cw_orch::prelude::MockContract<cosmwasm_std::Empty, cosmwasm_std::Empty>> {
/// Box::new(
/// cw_orch::prelude::ContractWrapper::new_with_empty(
/// APP::execute, // This notation, doesn't actually work like so, but we use that to illustrate
/// APP::instantiate,
/// APP::query,
/// )
/// .with_reply(APP::reply)
/// .with_migrate(APP::migrate)
/// .with_sudo(APP::sudo),
/// )
/// }
/// }
/// impl<Chain: ::cw_orch::prelude::CwEnv> ::abstract_interface::AppDeployer<Chain> for AppInterface<Chain> {}
/// }
/// ```
macro_rules! cw_orch_interface {
($app_const:expr, $app_type:ty, $interface_name: ident) => {
mod _wrapper_fns{
use super::*;
pub fn instantiate(
Expand Down Expand Up @@ -69,10 +113,10 @@ macro_rules! create_interface {
pub mod interface{
use super::_wrapper_fns;
#[::cw_orch::interface(_wrapper_fns::InstantiateMsg, _wrapper_fns::ExecuteMsg, _wrapper_fns::QueryMsg, _wrapper_fns::MigrateMsg)]
pub struct $app_type;
pub struct $interface_name;


impl <Chain: ::cw_orch::prelude::CwEnv> ::cw_orch::prelude::Uploadable for $app_type<Chain> {
impl <Chain: ::cw_orch::prelude::CwEnv> ::cw_orch::prelude::Uploadable for $interface_name<Chain> {
fn wasm(&self) -> ::cw_orch::prelude::WasmPath {
let wasm_name = env!("CARGO_CRATE_NAME").replace('-', "_");
::cw_orch::prelude::ArtifactsDir::auto(Some(env!("CARGO_MANIFEST_DIR").to_string()))
Expand All @@ -95,7 +139,7 @@ macro_rules! create_interface {
}
}

impl<Chain: ::cw_orch::prelude::CwEnv> ::abstract_interface::AppDeployer<Chain> for $app_type<Chain> {}
impl<Chain: ::cw_orch::prelude::CwEnv> ::abstract_interface::AppDeployer<Chain> for $interface_name<Chain> {}
}


Expand Down
33 changes: 29 additions & 4 deletions packages/abstract-app/src/msgs.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
#[macro_export]
/// Groups code that is needed on every app.
/// This registers the types for safety when using Messages
/// This is also used to indicate that The Query And Execute messages or used as app messages
macro_rules! app_messages {
/// Generates boilerplate code and entrypoint message types.
///
/// ### Usage
///
/// Requires three arguments:
/// 1. The App type.
/// 2. The App's custom execute message type.
/// 3. The App's custom query message type.
///
/// ```rust,ignore
/// abstract_app::app_msg_types!(MyApp, MyAppExecuteMsg, MyAppQueryMsg);
/// ```
///
/// Generates:
/// ```ignore
/// // These are the entry point messages expected by the smart-contract. Our custom messages get wrapped by the abstract base message.
/// pub type InstantiateMsg =
/// <MyApp as abstract_sdk::base::InstantiateEndpoint>::InstantiateMsg;
/// pub type ExecuteMsg = <MyApp as abstract_sdk::base::ExecuteEndpoint>::ExecuteMsg;
/// pub type QueryMsg = <MyApp as abstract_sdk::base::QueryEndpoint>::QueryMsg;
/// pub type MigrateMsg = <MyApp as abstract_sdk::base::MigrateEndpoint>::MigrateMsg;

/// // Implements the trait-bounds for the abstract app messages, which allows them to be used in the App type.
/// // Also implements `Into<ExecuteMsg> for MyAppExecuteMsg` and `Into<QueryMsg> for MyAppQueryMsg`.
/// // This enables the use of the `impl_into` macro of cw-orchestrator.
/// impl abstract_core::app::AppExecuteMsg for MyAppExecuteMsg {}
/// impl abstract_core::app::AppQueryMsg for MyAppQueryMsg {}
/// ```
macro_rules! app_msg_types {
($app_type:ty, $app_execute_msg: ty, $app_query_msg: ty) => {
/// Abstract App instantiate msg
pub type InstantiateMsg =
Expand Down
44 changes: 0 additions & 44 deletions packages/abstract-interface/tests/daemon.rs

This file was deleted.