From c27a8a865598f9d319436e1e25f2b1a88c836bd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wo=C5=BAniak?= Date: Mon, 5 Aug 2024 11:58:35 +0200 Subject: [PATCH 1/2] Sylvia: Move attributes to macro dir --- src/pages/sylvia/_meta.json | 1 - .../sylvia/basics/contract-structure.mdx | 8 ++++---- src/pages/sylvia/macros/_meta.json | 1 + src/pages/sylvia/{ => macros}/attributes.mdx | 0 .../sylvia/{ => macros}/attributes/_meta.json | 0 .../sylvia/{ => macros}/attributes/attr.mdx | 8 ++++---- .../sylvia/{ => macros}/attributes/custom.mdx | 0 .../sylvia/{ => macros}/attributes/error.mdx | 0 .../{ => macros}/attributes/message.mdx | 0 .../sylvia/{ => macros}/attributes/msg.mdx | 0 .../{ => macros}/attributes/msg_attr.mdx | 2 +- .../attributes/override-entry-point.mdx | 0 src/pages/sylvia/macros/contract.mdx | 20 +++++++++---------- src/pages/sylvia/macros/entry-points.mdx | 14 ++++++------- .../macros/generated-types/communication.mdx | 4 ++-- .../macros/generated-types/message-types.mdx | 2 +- .../macros/generated-types/multitest.mdx | 2 +- src/pages/sylvia/macros/interface.mdx | 4 ++-- 18 files changed, 33 insertions(+), 33 deletions(-) rename src/pages/sylvia/{ => macros}/attributes.mdx (100%) rename src/pages/sylvia/{ => macros}/attributes/_meta.json (100%) rename src/pages/sylvia/{ => macros}/attributes/attr.mdx (77%) rename src/pages/sylvia/{ => macros}/attributes/custom.mdx (100%) rename src/pages/sylvia/{ => macros}/attributes/error.mdx (100%) rename src/pages/sylvia/{ => macros}/attributes/message.mdx (100%) rename src/pages/sylvia/{ => macros}/attributes/msg.mdx (100%) rename src/pages/sylvia/{ => macros}/attributes/msg_attr.mdx (97%) rename src/pages/sylvia/{ => macros}/attributes/override-entry-point.mdx (100%) diff --git a/src/pages/sylvia/_meta.json b/src/pages/sylvia/_meta.json index f6b50315..badcb8f5 100644 --- a/src/pages/sylvia/_meta.json +++ b/src/pages/sylvia/_meta.json @@ -1,6 +1,5 @@ { "basics": "Basics", "macros": "Macros", - "attributes": "Attributes", "types": "Types" } diff --git a/src/pages/sylvia/basics/contract-structure.mdx b/src/pages/sylvia/basics/contract-structure.mdx index 9cafea9b..c01ce8b6 100644 --- a/src/pages/sylvia/basics/contract-structure.mdx +++ b/src/pages/sylvia/basics/contract-structure.mdx @@ -65,11 +65,11 @@ In the first two lines, we see the usage of two macros: point collision. - [`contract`](../macros/contract) - Parses every method inside the `impl` block marked with the - [`[sv::msg(...)]`](../attributes/msg) attribute and create proper messages and utilities like - helpers for [`MultiTest`](../../cw-multi-test). + [`[sv::msg(...)]`](../macros/attributes/msg) attribute and create proper messages and utilities + like helpers for [`MultiTest`](../../cw-multi-test). -This simple example also has the [`sv::msg(...)`](../attributes/msg) attributes. Sylvia macros -distinguish the if message should be generated from the marked method and of what type. +This simple example also has the [`sv::msg(...)`](../macros/attributes/msg) attributes. Sylvia +macros distinguish the if message should be generated from the marked method and of what type. CosmWasm contract requires the `instantiate` message, and it is mandatory to specify it for the [`contract`](../macros/contract) macro. We have to provide it with the proper context type: diff --git a/src/pages/sylvia/macros/_meta.json b/src/pages/sylvia/macros/_meta.json index d94ca1b3..f463292a 100644 --- a/src/pages/sylvia/macros/_meta.json +++ b/src/pages/sylvia/macros/_meta.json @@ -2,5 +2,6 @@ "interface": "Interface", "contract": "Contract", "entry-points": "Entry points", + "attributes": "Attributes", "generated-types": "Generated types" } diff --git a/src/pages/sylvia/attributes.mdx b/src/pages/sylvia/macros/attributes.mdx similarity index 100% rename from src/pages/sylvia/attributes.mdx rename to src/pages/sylvia/macros/attributes.mdx diff --git a/src/pages/sylvia/attributes/_meta.json b/src/pages/sylvia/macros/attributes/_meta.json similarity index 100% rename from src/pages/sylvia/attributes/_meta.json rename to src/pages/sylvia/macros/attributes/_meta.json diff --git a/src/pages/sylvia/attributes/attr.mdx b/src/pages/sylvia/macros/attributes/attr.mdx similarity index 77% rename from src/pages/sylvia/attributes/attr.mdx rename to src/pages/sylvia/macros/attributes/attr.mdx index b3ebbb2b..4b74e0c9 100644 --- a/src/pages/sylvia/attributes/attr.mdx +++ b/src/pages/sylvia/macros/attributes/attr.mdx @@ -17,8 +17,8 @@ List of macros supporting the `sv::attr` attribute: ## Usage -Use the `sv::attr` above any of the methods marked with -[`#[sv::msg(exec|sudo|query)]`](../attributes/msg) attribute. +Use the `sv::attr` above any of the methods marked with [`#[sv::msg(exec|sudo|query)]`](msg) +attribute. ```rust {19} use sylvia::contract; @@ -46,8 +46,8 @@ impl Contract { } ``` -The [`contract`](../macros/contract) and [`interface`](../macros/interface) macros will decorate the -message variant with the attribute provided in `sv::attr`. +The [`contract`](../contract) and [`interface`](../interface) macros will decorate the message +variant with the attribute provided in `sv::attr`. ```rust {2} pub enum ExecMsg { diff --git a/src/pages/sylvia/attributes/custom.mdx b/src/pages/sylvia/macros/attributes/custom.mdx similarity index 100% rename from src/pages/sylvia/attributes/custom.mdx rename to src/pages/sylvia/macros/attributes/custom.mdx diff --git a/src/pages/sylvia/attributes/error.mdx b/src/pages/sylvia/macros/attributes/error.mdx similarity index 100% rename from src/pages/sylvia/attributes/error.mdx rename to src/pages/sylvia/macros/attributes/error.mdx diff --git a/src/pages/sylvia/attributes/message.mdx b/src/pages/sylvia/macros/attributes/message.mdx similarity index 100% rename from src/pages/sylvia/attributes/message.mdx rename to src/pages/sylvia/macros/attributes/message.mdx diff --git a/src/pages/sylvia/attributes/msg.mdx b/src/pages/sylvia/macros/attributes/msg.mdx similarity index 100% rename from src/pages/sylvia/attributes/msg.mdx rename to src/pages/sylvia/macros/attributes/msg.mdx diff --git a/src/pages/sylvia/attributes/msg_attr.mdx b/src/pages/sylvia/macros/attributes/msg_attr.mdx similarity index 97% rename from src/pages/sylvia/attributes/msg_attr.mdx rename to src/pages/sylvia/macros/attributes/msg_attr.mdx index ae41aa25..cf2b8b2a 100644 --- a/src/pages/sylvia/attributes/msg_attr.mdx +++ b/src/pages/sylvia/macros/attributes/msg_attr.mdx @@ -17,7 +17,7 @@ List of macros supporting the `sv::msg_attr` attribute: ## Usage -Use the `sv::msg_attr` above any of the methods marked with [`#[sv::msg(..)]`](../attributes/msg) +Use the `sv::msg_attr` above any of the methods marked with [`#[sv::msg(..)]`](attributes/msg) attribute. ```rust {19} diff --git a/src/pages/sylvia/attributes/override-entry-point.mdx b/src/pages/sylvia/macros/attributes/override-entry-point.mdx similarity index 100% rename from src/pages/sylvia/attributes/override-entry-point.mdx rename to src/pages/sylvia/macros/attributes/override-entry-point.mdx diff --git a/src/pages/sylvia/macros/contract.mdx b/src/pages/sylvia/macros/contract.mdx index 32f7bc2a..443b5b04 100644 --- a/src/pages/sylvia/macros/contract.mdx +++ b/src/pages/sylvia/macros/contract.mdx @@ -19,11 +19,11 @@ contract messages List of attributes supported by [`contract`](https://docs.rs/sylvia/latest/sylvia/attr.contract.html) macro: -- [`custom`](../attributes/custom) -- [`error`](../attributes/error) -- [`message`](../attributes/message) -- [`msg`](../attributes/msg) -- [`override_entry_point`](../attributes/override-entry-point) +- [`custom`](attributes/custom) +- [`error`](attributes/error) +- [`message`](attributes/message) +- [`msg`](attributes/msg) +- [`override_entry_point`](attributes/override-entry-point) ## Usage @@ -78,7 +78,7 @@ impl CounterContract { ``` We define our messages signatures by marking the appropriate methods with the -[`sv::msg`](../attributes/msg) attribute. +[`sv::msg`](attributes/msg) attribute. The `impl` block must contain the attributeless `new` method for the generated `dispatch` to work properly. @@ -86,7 +86,7 @@ properly. ## Custom types You can construct your contract to work with some specific custom types with the -[`sv::custom`](../attributes/custom). +[`sv::custom`](attributes/custom). ## Generic types @@ -176,9 +176,9 @@ pub struct InstantiateMsg { ### Prefer generic custom types -The [`sv::custom`](../attributes/custom) attribute is not mandatory, as by default contract macro -will use [`Empty`](https://docs.rs/cosmwasm-std/latest/cosmwasm_std/struct.Empty.html) type in place -of custom types. It has a downside that the contract always expects the +The [`sv::custom`](attributes/custom) attribute is not mandatory, as by default contract macro will +use [`Empty`](https://docs.rs/cosmwasm-std/latest/cosmwasm_std/struct.Empty.html) type in place of +custom types. It has a downside that the contract always expects the [`Empty`](https://docs.rs/cosmwasm-std/latest/cosmwasm_std/struct.Empty.html) custom messages, and it makes testing it in the [MultiTest](../../cw-multi-test) environment with different custom messages tricky. We recommend that if your contract is meant to be chain agnostic, define it with a diff --git a/src/pages/sylvia/macros/entry-points.mdx b/src/pages/sylvia/macros/entry-points.mdx index b30b1c7d..0c984625 100644 --- a/src/pages/sylvia/macros/entry-points.mdx +++ b/src/pages/sylvia/macros/entry-points.mdx @@ -18,10 +18,10 @@ Use the `entry_points` macro to generate entry points of your contract. List of attributes supported by `entry_points` macro: -- [`custom`](../attributes/custom) -- [`error`](../attributes/error) -- [`msg`](../attributes/msg) -- [`override_entry_point`](../attributes/override-entry-point) +- [`custom`](attributes/custom) +- [`error`](attributes/error) +- [`msg`](attributes/msg) +- [`override_entry_point`](attributes/override-entry-point) ## Usage @@ -59,13 +59,13 @@ impl CounterContract { } ``` -The `entry_points` macro scans for [`sv::msg`](../attributes/msg) attributes. By default it -generates: instantiate, exec, and query entry points. +The `entry_points` macro scans for [`sv::msg`](attributes/msg) attributes. By default it generates: +instantiate, exec, and query entry points. ## Custom types You can construct your entry points to work with some specific custom types with the -[`sv::custom`](../attributes/custom). +[`sv::custom`](attributes/custom). ## Generic types diff --git a/src/pages/sylvia/macros/generated-types/communication.mdx b/src/pages/sylvia/macros/generated-types/communication.mdx index d73ea7cb..bdb96a80 100644 --- a/src/pages/sylvia/macros/generated-types/communication.mdx +++ b/src/pages/sylvia/macros/generated-types/communication.mdx @@ -43,7 +43,7 @@ impl CounterContract { ## Query helpers Sylvia macros generate a `Querier` trait that mirrors all of the methods marked with the -[`sv::msg(query)`](../../attributes/msg.mdx) attribute. This trait is then implemented on the +[`sv::msg(query)`](../attributes/msg.mdx) attribute. This trait is then implemented on the [`BoundQuerier`](../../types/communication#boundquerier) type. Implementation of each method constructs the appropriate message and sends it to the contract. @@ -64,7 +64,7 @@ impl<'a, C: sylvia::cw_std::CustomQuery> Querier ## Executor helpers Sylvia macros generate an `Executor` trait that mirrors all of the methods marked with the -[`sv::msg(exec)`](../../attributes/msg.mdx) attribute. This trait is then implemented on the +[`sv::msg(exec)`](../attributes/msg.mdx) attribute. This trait is then implemented on the [`ExecutorBuilder`](../../types/communication#executorbuilder) type. Implementation of each method constructs the appropriate message and returns the [`ExecutorBuilder`](../../types/communication#executorbuilder) generic over diff --git a/src/pages/sylvia/macros/generated-types/message-types.mdx b/src/pages/sylvia/macros/generated-types/message-types.mdx index a2e6bbb0..2f23adb8 100644 --- a/src/pages/sylvia/macros/generated-types/message-types.mdx +++ b/src/pages/sylvia/macros/generated-types/message-types.mdx @@ -6,7 +6,7 @@ import { Callout, Tabs } from "nextra/components"; # Generated message types -Sylvia macros generate CosmWasm messages from methods marked with [`sv::msg`](../../attributes/msg) +Sylvia macros generate CosmWasm messages from methods marked with [`sv::msg`](../attributes/msg) attributes. Messages are generated either as struct, for instantiate and migrate, or enum in case of the rest of diff --git a/src/pages/sylvia/macros/generated-types/multitest.mdx b/src/pages/sylvia/macros/generated-types/multitest.mdx index 30240ad1..a67b867a 100644 --- a/src/pages/sylvia/macros/generated-types/multitest.mdx +++ b/src/pages/sylvia/macros/generated-types/multitest.mdx @@ -364,7 +364,7 @@ the reference to the [`App`](../../types/multitest#app). } ``` - The proxy trait declares methods marked with the [`sv::msg`](../../attributes/msg) attribute, and found in the contract impl block + The proxy trait declares methods marked with the [`sv::msg`](../attributes/msg) attribute, and found in the contract impl block The trait is then implemented on the [`Proxy`](../../types/multitest#proxy) generic over the contract type. Implementation of the methods instantiates appropriate messages and sends them to the [`App`](../../types/multitest#app) so that we don't have to do it manually. diff --git a/src/pages/sylvia/macros/interface.mdx b/src/pages/sylvia/macros/interface.mdx index 682f4b3a..4cd041f9 100644 --- a/src/pages/sylvia/macros/interface.mdx +++ b/src/pages/sylvia/macros/interface.mdx @@ -47,12 +47,12 @@ will be able to assign their error type to it and have wider range of errors tha Then we can define our messages signatures. We do that by marking the methods with the -[`sv::msg`](../attributes/msg) attribute. +[`sv::msg`](attributes/msg) attribute. ## Custom types You can construct your interface to work with some specific custom types with the -[`sv::custom`](../attributes/custom) attribute. Use of `sv::custom` restricts the interface to work +[`sv::custom`](attributes/custom) attribute. Use of `sv::custom` restricts the interface to work with the predefined custom types. If you want to allow the users to use the interface with their own specified custom types, you can From be9e9da9d887dfaf4a70e4ad86114746d8fa3acf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wo=C5=BAniak?= Date: Tue, 6 Aug 2024 13:14:29 +0200 Subject: [PATCH 2/2] Sylvia: Fix links --- src/pages/sylvia/macros/attributes/attr.mdx | 4 ++-- src/pages/sylvia/macros/attributes/custom.mdx | 10 +++++----- src/pages/sylvia/macros/attributes/error.mdx | 6 +++--- src/pages/sylvia/macros/attributes/message.mdx | 4 ++-- src/pages/sylvia/macros/attributes/msg.mdx | 10 +++++----- src/pages/sylvia/macros/attributes/msg_attr.mdx | 11 +++++------ .../sylvia/macros/attributes/override-entry-point.mdx | 11 +++++------ 7 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/pages/sylvia/macros/attributes/attr.mdx b/src/pages/sylvia/macros/attributes/attr.mdx index 4b74e0c9..47bcf00e 100644 --- a/src/pages/sylvia/macros/attributes/attr.mdx +++ b/src/pages/sylvia/macros/attributes/attr.mdx @@ -12,8 +12,8 @@ Use `sv::attr` to forward an external attribute to the generated message variant List of macros supporting the `sv::attr` attribute: -- [`contract`](../macros/contract) -- [`interface`](../macros/interface) +- [`contract`](../contract) +- [`interface`](../interface) ## Usage diff --git a/src/pages/sylvia/macros/attributes/custom.mdx b/src/pages/sylvia/macros/attributes/custom.mdx index e0f57a71..0a583297 100644 --- a/src/pages/sylvia/macros/attributes/custom.mdx +++ b/src/pages/sylvia/macros/attributes/custom.mdx @@ -12,9 +12,9 @@ Use `sv::custom` if you want to use a custom message and/or query in your contra List of macros supporting the `sv::custom` attribute: -- [`contract`](../macros/contract) -- [`interface`](../macros/interface) -- [`entry_points`](../macros/entry-points) +- [`contract`](../contract) +- [`interface`](../interface) +- [`entry_points`](../entry-points) ## Usage @@ -64,7 +64,7 @@ impl CounterContract { respectively. -`sv::custom` works the same in the case of the `interface` macro. +`sv::custom` works the same in the case of the [`interface`](../interface) macro. ```rust use cosmwasm_schema::cw_serde; @@ -98,5 +98,5 @@ pub trait SomeInterface { It's also possible to define custom types for the interface using associated types. We cover it in - the [`interface`](../macros/interface) macro section. + the [`interface`](../interface) macro section. diff --git a/src/pages/sylvia/macros/attributes/error.mdx b/src/pages/sylvia/macros/attributes/error.mdx index 311a5533..ace1e7c5 100644 --- a/src/pages/sylvia/macros/attributes/error.mdx +++ b/src/pages/sylvia/macros/attributes/error.mdx @@ -17,11 +17,11 @@ You can quickly provide this logic using, for example, [`thiserror`](https://doc List of macros supporting the `sv::error` attribute: -- [`contract`](../macros/contract) -- [`entry_points`](../macros/entry-points) +- [`contract`](../contract) +- [`entry_points`](../entry-points) - The `interface` macro supports custom error types via the `Error` associated type. + The [`interface`](../interface) macro supports custom error types via the `Error` associated type. ## Usage diff --git a/src/pages/sylvia/macros/attributes/message.mdx b/src/pages/sylvia/macros/attributes/message.mdx index 69ad87af..e2782e8d 100644 --- a/src/pages/sylvia/macros/attributes/message.mdx +++ b/src/pages/sylvia/macros/attributes/message.mdx @@ -16,8 +16,8 @@ Use `sv::messages` to expand your contract functionality with the Sylvia interfa List of macros supporting the `sv::messages` attribute: -- [`contract`](../macros/contract) -- [`entry_points`](../macros/entry-points) +- [`contract`](../contract) +- [`entry_points`](../entry-points) ## Usage diff --git a/src/pages/sylvia/macros/attributes/msg.mdx b/src/pages/sylvia/macros/attributes/msg.mdx index c70d4705..5d786404 100644 --- a/src/pages/sylvia/macros/attributes/msg.mdx +++ b/src/pages/sylvia/macros/attributes/msg.mdx @@ -12,13 +12,13 @@ Use the `sv::msg` attribute to mark methods as specific message types. List of macros supporting the `sv::msg` attribute: -- [`contract`](..//macros/contract) -- [`interface`](../macros/interface) -- [`entry_points`](../macros/entry-points) +- [`contract`](../contract) +- [`interface`](../interface) +- [`entry_points`](../entry-points) - [`interface`](../macros/interface) macro supports the `sv::msg` attribute only with `exec`, - `query` or `sudo` value. + [`interface`](../interface) macro supports the `sv::msg` attribute only with `exec`, `query` or + `sudo` value. ## Usage diff --git a/src/pages/sylvia/macros/attributes/msg_attr.mdx b/src/pages/sylvia/macros/attributes/msg_attr.mdx index cf2b8b2a..e577dcd5 100644 --- a/src/pages/sylvia/macros/attributes/msg_attr.mdx +++ b/src/pages/sylvia/macros/attributes/msg_attr.mdx @@ -12,13 +12,12 @@ Use `sv::msg_attr` to forward an external attribute to the generated message. List of macros supporting the `sv::msg_attr` attribute: -- [`contract`](../macros/contract) -- [`interface`](../macros/interface) +- [`contract`](../contract) +- [`interface`](../interface) ## Usage -Use the `sv::msg_attr` above any of the methods marked with [`#[sv::msg(..)]`](attributes/msg) -attribute. +Use the `sv::msg_attr` above any of the methods marked with [`#[sv::msg(..)]`](msg) attribute. ```rust {19} use sylvia::contract; @@ -43,8 +42,8 @@ impl MyContract { } ``` -The [`contract`](../macros/contract) and [`interface`](../macros/interface) macros will decorate the -message with the attributes/macros provided in `sv::msg_attr`. +The [`contract`](../contract) and [`interface`](../interface) macros will decorate the message with +the attributes/macros provided in `sv::msg_attr`. ```rust {8, 10-11} #[derive( diff --git a/src/pages/sylvia/macros/attributes/override-entry-point.mdx b/src/pages/sylvia/macros/attributes/override-entry-point.mdx index 383fb385..ebf00d80 100644 --- a/src/pages/sylvia/macros/attributes/override-entry-point.mdx +++ b/src/pages/sylvia/macros/attributes/override-entry-point.mdx @@ -7,13 +7,12 @@ import { Callout } from "nextra/components"; # `sv::override_entry_point` attribute Use `sv::override_entry_point` if you want to define an entry point of your contract yourself. This -way, the [`sv::entry_points`](../macros/entry-points) macro won't generate it for you. The entry -point will also be used as a dispatch method in the `MultiTest` helpers generated by the `contract` -macro. +way, the [`sv::entry_points`](../entry-points) macro won't generate it for you. The entry point will +also be used as a dispatch method in the `MultiTest` helpers generated by the `contract` macro. Use this attribute if you provide some custom logic in the entry points. Otherwise, the - [`MultiTest`](../../cw-multi-test) helpers won't cover that logic, and thus you will miss the + [`MultiTest`](../../../cw-multi-test) helpers won't cover that logic, and thus you will miss the coverage. @@ -21,8 +20,8 @@ macro. List of macros supporting the `sv::override_entry_point` attribute: -- [`contract`](../macros/contract) -- [`entry_points`](../macros/entry-points) +- [`contract`](../contract) +- [`entry_points`](../entry-points) ## Usage