Skip to content

Commit

Permalink
Sylvia: Move attributes to macro dir (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
jawoznia authored Aug 6, 2024
2 parents 53fddff + be9e9da commit 52ecd6e
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 61 deletions.
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 @@ -151,11 +151,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.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ 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

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

Expand Down Expand Up @@ -64,7 +64,7 @@ impl CounterContract {
respectively.
</Callout>

`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;
Expand Down Expand Up @@ -98,5 +98,5 @@ pub trait SomeInterface {

<Callout>
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.
</Callout>
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<Callout>
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.
</Callout>

## Usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<Callout>
[`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.
</Callout>

## Usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@ 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.

<Callout>
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.
</Callout>

## Macros

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

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

0 comments on commit 52ecd6e

Please sign in to comment.