Skip to content

Commit

Permalink
readme and additional checks
Browse files Browse the repository at this point in the history
  • Loading branch information
KitHat committed Oct 28, 2024
1 parent bec2377 commit baf6cce
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
39 changes: 37 additions & 2 deletions procedural/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
We have made a wrapper over the `construct_runtime!` to support the abstractions. The macro itself have changed, supporting both abstractions and regular pallets:

```rust
#[construct_openzeppelin_runtime]
#[openzeppelin_construct_runtime]
mod runtime {
#[abstraction]
struct System; // Available names are System, Consensus, XCM, Assets, Governance. EVM is in development.
Expand All @@ -23,4 +23,39 @@ Pallet index assignment is hidden from this API. If you want to use it, please c
* `Consensus` -- `pallet_authorship`, `pallet_aura`, `cumulus_pallet_aura_ext`, `pallet_collator_selection`
* `Governance` -- `pallet_sudo`, `pallet_treasury`, `pallet_conviction_voting`, `pallet_whitelist`, `pallet_custom_origins`, `pallet_referenda`
* `XCM` -- `pallet_message_queue`, `cumulus_pallet_xcmp_queue`, `pallet_xcm`, `cumulus_pallet_xcm`
* `EVM` -- `pallet_ethereum`, `pallet_evm`, `pallet_base_fee`, `pallet_evm_chain_id`
* `EVM` -- `pallet_ethereum`, `pallet_evm`, `pallet_base_fee`, `pallet_evm_chain_id`

### `impl_runtime_apis!`

We have also made a wrapper for `impl_runtime_apis!` macro. There is now a new macro where you only provide the types and structs:

```rust
#[openzeppelin_runtime_apis]
mod apis {
// these types should be present and required for all abstractions
// runtime generated by construct_runtime
type Runtime = Runtime;
// block type
type Block = Block;

#[abstraction]
mod assets {
type TransactionPayment = TransactionPayment;
type RuntimeCall = RuntimeCall;
type Balance = Balance;
}

// Any impl block can also go there
}
```

Supported abstractions:

| Abstraction name | Implemented APIs | Required configs |
|---|---|---|
| `EVM` | * `fp_rpc::EthereumRuntimeRPCApi`<br>* `fp_rpc::ConvertTransactionRuntimeApi` | * `RuntimeCall` -- runtime call generated by `construct_runtime` macro<br>* `Executive` -- `frame_executive::Executive` specification used by parachain system<br>* `Ethereum` -- `pallet_ethereum` pallet struct generated by `construct_runtime` macro |
| `assets` | * `pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi`<br>* `pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi` | * `TransactionPayment` -- `pallet_transaction_payment` struct pallet generated by `construct_runtime` macro<br> * `RuntimeCall` -- runtime call generated by `construct_runtime` macro<br> * `Balance` -- type used for balance specification (e.g. in `pallet_balances` config) |
| `consensus` | * `sp_consensus_aura::AuraApi`<br> * `sp_session::SessionKeys`<br> * `cumulus_primitives_aura::AuraUnincludedSegmentApi` (if `async-backing` feature is enabled) | * `SessionKeys` -- struct generated by `impl_opaque_keys` macro <br> * `Aura` -- `pallet_aura` struct pallet generated by `construct_runtime` macro (only if `async-backing` feature is not enabled)<br> * `SlotDuration` -- constant that is use for slot duration definition (only if `async-backing` feature is enabled)<br> * `ConsensusHook` -- type that is used in `cumulus_pallet_parachain_system::Config::ConsensusHook` (only if `async-backing` feature is enabled) |
| `system` | * `sp_api::Core`<br> * `sp_api::Metadata`<br> * `sp_block_builder::BlockBuilder`<br> * `sp_transaction_pool::runtime_api::TaggedTransactionQueue` <br> * `sp_offchain::OffchainWorkerApi` <br> * `frame_system_rpc_runtime_api::AccountNonceApi` <br> * `cumulus_primitives_core::CollectCollationInfo` <br> * `frame_try_runtime::TryRuntime` (under a `try-runtime` feature) <br> * `sp_genesis_builder::GenesisBuilder`<br> * `frame_system_benchmarking::Config` (under a `runtime-benchmarks` feature) | * `Executive` -- `frame_executive::Executive` specification used by parachain system<br> * `System` -- `frame_system` pallet struct generated by `construct_runtime` macro<br> * `ParachainSystem` -- `cumulus_pallet_parachain_system` pallet struct generated by `construct_runtime` macro<br> * `RuntimeVersion` -- runtime version, generated by `sp_version::runtime_version`<br> * `AccountId` -- account id type that was specified in `frame_system::Config`<br> * `Nonce` -- npnce type that was specified in `frame_system::Config`<br> * `RuntimeGenesisBuilder` -- type generated by `construct_runtime` macro. |

Also, this macro implements `frame_benchmarking::Benchmark` for all of the specified pallets.
2 changes: 1 addition & 1 deletion procedural/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod models;
mod runtime_apis;

#[proc_macro_attribute]
pub fn construct_openzeppelin_runtime(_: TokenStream, tokens: TokenStream) -> TokenStream {
pub fn openzeppelin_construct_runtime(_: TokenStream, tokens: TokenStream) -> TokenStream {
construct_runtime::construct_openzeppelin_runtime(tokens)
}

Expand Down
14 changes: 12 additions & 2 deletions procedural/src/runtime_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,18 @@ pub fn impl_openzeppelin_runtime_apis(input: TokenStream) -> TokenStream {
}
}
Item::Mod(m) => {
// TODO: check abstraction attribute
abstractions.push(m)
let is_abstraction = m.attrs.iter().any(|f| {
let Ok(path) = f.meta.require_path_only() else {
return false;
};
let Ok(ident) = path.require_ident() else {
return false;
};
ident == "abstraction"
});
if is_abstraction {
abstractions.push(m)
}
}
Item::Impl(im) => {
inner.extend(im.to_token_stream());
Expand Down

0 comments on commit baf6cce

Please sign in to comment.