rialo-sol-attribute-program 0.11.0

Sol attribute macro for defining a program
Documentation
// Copyright (c) Subzero Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use quote::{format_ident, quote};
use rialo_sol_lang_idl::types::Idl;

pub fn gen_errors_mod(idl: &Idl) -> proc_macro2::TokenStream {
    let errors = idl.errors.iter().map(|e| {
        let name = format_ident!("{}", e.name);
        quote! {
            #name,
        }
    });

    if errors.len() == 0 {
        return quote! {
            /// Program error type definitions.
            pub mod errors {
            }
        };
    }

    quote! {
        /// Program error type definitions.
        pub mod errors {

            #[rialo_sol_lang::error_code]
            pub enum ProgramError {
                #(#errors)*
            }
        }
    }
}