6 releases
| 0.1.9 | Nov 4, 2025 |
|---|---|
| 0.1.8 | Oct 31, 2025 |
#646 in Procedural macros
10KB
99 lines
VIA Labs Stellar Macros
Proc macro for providing default implementations of traits for Stellar contracts in the VIA cross-chain messaging system.
Overview
The vialabs-stellar-macros crate provides the #[default_impl] attribute macro that automatically generates default implementations for trait methods. This allows contract developers to focus on implementing only the custom logic they need, while the macro provides standard implementations for the rest.
Supported Traits
MessageClientV4Interface
The macro currently supports the full MessageClientV4Interface trait and provides all of the needed default implementations.
Note: The message_process method is not provided by default and must be implemented by the contract.
Usage
Add the macro crate to your contract's Cargo.toml:
[dependencies]
vialabs-stellar-macros = "0.1.9"
vialabs-stellar-common = "0.1.9"
soroban-sdk = "23.0.2"
Inside your contract file:
use vialabs_stellar_macros::default_impl;
use vialabs_stellar_common::message_client_v4::MessageClientV4Interface;
#[contract]
pub struct MyContract;
#[default_impl]
#[contractimpl]
impl MessageClientV4Interface for MyContract {
fn message_process(env: &Env, message: ProcessFromGatewayRequest) {
// Your custom implementation here
// All other methods will be automatically provided by the macro
}
}
Overriding Methods
Important: Only message_process can be overridden. All other methods will always use the default implementation provided by the macro, even if you try to provide a custom implementation.
#[default_impl]
#[contractimpl]
impl MessageClientV4Interface for MyContract {
fn message_process(env: &Env, message: ProcessFromGatewayRequest) {
// Only this method can be customized
// Custom implementation here
}
// This will panic
fn message_send(env: &Env, destination_chain: u64, chain_data: Bytes, confirmations: u32) -> u128 {
0u128
}
}
Dependencies
~120–495KB
~12K SLoC