Skip to content

Commit

Permalink
Sylvia: Move generated types to macros directory
Browse files Browse the repository at this point in the history
  • Loading branch information
jawoznia committed Jul 11, 2024
1 parent 1ff4ebb commit 267d32c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 38 deletions.
3 changes: 2 additions & 1 deletion src/pages/sylvia/_meta.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"basics": "Basics",
"macros": "Macros",
"attributes": "Attributes"
"attributes": "Attributes",
"types": "Types"
}
3 changes: 2 additions & 1 deletion src/pages/sylvia/macros/_meta.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"interface": "Interface",
"contract": "Contract",
"entry-points": "Entry-points"
"entry-points": "Entry points",
"generated-types": "Generated types"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ tags: ["sylvia", "macro"]
This part of the documentation describes types generated by Sylvia macros.

All of the generated code, except for the one generated by the
[`entry_points`](../macros/entry-points) macro is generated inside of the `sv`
module.
[`entry_points`](entry-points) macro is generated inside of the `sv` module.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import { Callout, Tabs } from "nextra/components";
Sylvia exposes types to ease communication between contracts. Currently there
are two types:

- [`BoundQuerier`](../types/communication#boundquerier) - for sending query
- [`BoundQuerier`](../../types/communication#boundquerier) - for sending query
messages,
- [`ExecutorBuilder`](../types/communication#executorbuilder) - for building
- [`ExecutorBuilder`](../../types/communication#executorbuilder) - for building
execute messages.

The [`contract`](../macros/contract) and [`interface`](../macros/interface)
expand these types by generating and implementing traits with methods
representing execute and query methods
The [`contract`](../contract) and [`interface`](../interface) expand these types
by generating and implementing traits with methods representing execute and
query methods

Examples in the following paragraphs are generated from the below contract:

Expand Down Expand Up @@ -47,10 +47,10 @@ 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 [`BoundQuerier`](../types/communication#boundquerier) type.
Implementation of each method constructs the appropriate message and sends it to
the contract.
with 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.

```rust
pub trait Querier {
Expand All @@ -69,11 +69,11 @@ 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
[`ExecutorBuilder`](../types/communication#executorbuilder) type. Implementation
of each method constructs the appropriate message and returns the
[`ExecutorBuilder`](../types/communication#executorbuilder) generic over
marked with 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
[`ReadyExecutorBuilderState`](https://docs.rs/sylvia/latest/sylvia/types/struct.ReadyExecutorBuilderState.html).

```rust
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Callout, Tabs } from "nextra/components";
# Generated message types

Sylvia macros generate CosmWasm messages from methods marked with
[`sv::msg`](../attributes/msg) attributes.
[`sv::msg`](../../attributes/msg) attributes.

Messages are generated either as struct, for instantiate and migrate, or enum in
case of the rest of the types.
Expand Down Expand Up @@ -67,7 +67,7 @@ impl CounterContract {
```

generates the following messages for every respective
[entrypoint](../../core/entrypoints):
[entrypoint](../../../core/entrypoints):

<Tabs items={['InstantiateMsg', 'ExecMsg', 'QueryMsg', 'SudoMsg', 'MigrateMsg']} defaultIndex={0}>
<Tabs.Tab>
Expand Down Expand Up @@ -269,10 +269,10 @@ generates the following messages for every respective
and their variants.
</Callout>

The [`contract`](../macros/contract) macro also generates wrapper messages for
exec, query and sudo. Their goal is to wrap respective messages, like `ExecMsg`,
from both the contract and interfaces implemented on it, which are used as the
main messages of the contract.
The [`contract`](../contract) macro also generates wrapper messages for exec,
query and sudo. Their goal is to wrap respective messages, like `ExecMsg`, from
both the contract and interfaces implemented on it, which are used as the main
messages of the contract.

<Callout>
Use `ContractExecMsg`/`ContractQueryMsg`/`ContractSudoMsg` in hand made entry
Expand Down Expand Up @@ -408,8 +408,8 @@ validation that none of the messages overlap between a contract and interfaces.

## Interface messages

The generation done by [`interface`](../macros/interface) macro is much simpler,
as Sylvia generates just three types of messages.
The generation done by [`interface`](../interface) macro is much simpler, as
Sylvia generates just three types of messages.

We will use the below example interface to generate the messages:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import { Callout, Tabs } from "nextra/components";
enabled. We recommend enabling it in the dev-dependencies.
</Callout>

The [`contract`](../macros/contract) and [`interface`](../macros/interface)
macros generate QoL utilities to test your contract with the
[MultiTest](../../cw-multi-test).
The [`contract`](../contract) and [`interface`](../interface) macros generate
QoL utilities to test your contract with the
[MultiTest](../../../cw-multi-test).

<Callout>The MultiTest helpers are generated in the `sv::mt` module.</Callout>

## Code generation

Most of the code is generated only by the [`contract`](../macros/contract)
macro. To see the code generated by the [`interface`](../macros/interface) macro
skip to the [proxy trait](#proxy-trait) section.
Most of the code is generated only by the [`contract`](../contract) macro. To
see the code generated by the [`interface`](../interface) macro skip to the
[proxy trait](#proxy-trait) section.

### CodeId

Expand Down Expand Up @@ -523,8 +523,8 @@ The
[`store_code`](https://docs.rs/cw-multi-test/latest/cw_multi_test/struct.App.html#method.store_code)
expects a type to implement the
[`Contract`](https://docs.rs/cw-multi-test/latest/cw_multi_test/trait.Contract.html)
trait. The [`contract`](../macros/contract) macro covers that by implementing
this trait on our contract type.
trait. The [`contract`](../contract) macro covers that by implementing this
trait on our contract type.

```rust
impl sylvia::cw_multi_test::Contract<sylvia::cw_std::Empty, sylvia::cw_std::Empty>
Expand Down
9 changes: 5 additions & 4 deletions src/pages/sylvia/types/communication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ is a wrapper over the
We provide the querying functionality via traits. The
[`contract`](../macros/contract) and [`interface`](../macros/interface) macros
generate these traits for us. You can learn about that in
[`this section`](../generated-types/communication#query-helpers). If you don't
use Sylvia yet, you can create and implement those traits manually. Feel free to
get inspiration from above example.
[`this section`](../macros/generated-types/communication#query-helpers). If you
don't use Sylvia yet, you can create and implement those traits manually. Feel
free to get inspiration from above example.

With the traits implemented, a contract with a query method `some_query` can be
queried as follows:
Expand Down Expand Up @@ -134,7 +134,8 @@ For the `ExecutorBuilder` generic over `EmptyExecutorBuilderState`, we also
provide the message constructing functionality. The
[`contract`](../macros/contract) and [`interface`](../macros/interface) macros
generate a trait with methods for every execute message. You can learn about
that in [`this section`](../generated-types/communication#execute-helpers). If
that in
[`this section`](../macros/generated-types/communication#execute-helpers). If
you don't use Sylvia yet, you can create and implement those traits manually.
Feel free to get inspiration from above example.

Expand Down

0 comments on commit 267d32c

Please sign in to comment.