vialabs-stellar-macros

Crates.iovialabs-stellar-macros
lib.rsvialabs-stellar-macros
version0.1.9
created_at2025-10-31 17:31:39.777422+00
updated_at2025-11-04 15:48:07.118594+00
descriptionProc macro for providing default implementations of traits for Stellar contracts in the VIA cross-chain messaging system
homepage
repositoryhttps://github.com/vialabs-io/via-drivers
max_upload_size
id1910391
size10,783
Amanda Gonsalves (amandagonsalves)

documentation

README

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
    }
}
Commit count: 0

cargo fmt