Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sylvia: Move attributes to macro dir #125

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion src/pages/sylvia/_meta.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"basics": "Basics",
"macros": "Macros",
"attributes": "Attributes",
"types": "Types"
}
8 changes: 4 additions & 4 deletions src/pages/sylvia/basics/contract-structure.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/pages/sylvia/macros/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"interface": "Interface",
"contract": "Contract",
"entry-points": "Entry points",
"attributes": "Attributes",
"generated-types": "Generated types"
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
20 changes: 10 additions & 10 deletions src/pages/sylvia/macros/contract.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -78,15 +78,15 @@ 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.

## 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

Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/pages/sylvia/macros/entry-points.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/pages/sylvia/macros/generated-types/communication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pages/sylvia/macros/generated-types/message-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pages/sylvia/macros/generated-types/multitest.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/pages/sylvia/macros/interface.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ will be able to assign their error type to it and have wider range of errors tha
</Callout>

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
Expand Down