---
source: crates/sdk-derive/derive-core/src/router.rs
expression: formatted
---
impl<SDK: SharedAPI> RouterAPI for App<SDK> {
    fn greeting(&self, message: String, owner: Address, amount: U256) -> String {
        message
    }
    fn custom_greeting(&self, message: String) -> String {
        message
    }
}
pub type GreetingCallArgs = (String, Address, U256);
#[derive(Debug, Clone, PartialEq)]
pub struct GreetingCall(pub GreetingCallArgs);
pub type GreetingReturnArgs = (String,);
#[derive(Debug, Clone, PartialEq)]
pub struct GreetingReturn(pub GreetingReturnArgs);
const _: () = {
    impl GreetingCall {
        pub const SELECTOR: [u8; 4] = [68u8, 97u8, 93u8, 234u8];
        pub const SIGNATURE: &'static str = "greeting(string,address,uint256)";
        /// Creates a new call instance from arguments
        pub fn new(args: GreetingCallArgs) -> Self {
            Self(args)
        }
        /// Encodes with selector
        pub fn encode(&self) -> fluentbase_sdk::codec::bytes::Bytes {
            let mut args_buf = fluentbase_sdk::codec::bytes::BytesMut::new();
            fluentbase_sdk::codec::encoder::SolidityABI::encode_function_args(
                    &self.0,
                    &mut args_buf,
                )
                .expect("Failed to encode values");
            let mut buf = fluentbase_sdk::codec::bytes::BytesMut::new();
            buf.extend_from_slice(&Self::SELECTOR);
            buf.extend_from_slice(&args_buf);
            buf.freeze()
        }
        /// Decodes call arguments from bytes
        pub fn decode(
            buf: &impl fluentbase_sdk::codec::bytes::Buf,
        ) -> Result<Self, fluentbase_sdk::codec::CodecError> {
            let args = fluentbase_sdk::codec::encoder::SolidityABI::<
                GreetingCallArgs,
            >::decode_function_args(buf)?;
            Ok(Self(args))
        }
    }
    impl ::core::ops::Deref for GreetingCall {
        type Target = GreetingCallArgs;
        fn deref(&self) -> &Self::Target {
            &self.0
        }
    }
    impl GreetingReturn {
        /// Creates a new return instance from values
        pub fn new(args: GreetingReturnArgs) -> Self {
            Self(args)
        }
        /// Encodes the return values to bytes
        pub fn encode(&self) -> fluentbase_sdk::codec::bytes::Bytes {
            let mut buf = fluentbase_sdk::codec::bytes::BytesMut::new();
            fluentbase_sdk::codec::encoder::SolidityABI::encode_function_args(
                    &self.0,
                    &mut buf,
                )
                .expect("Failed to encode values");
            buf.freeze()
        }
        /// Decodes return values from bytes
        pub fn decode(
            buf: &impl fluentbase_sdk::codec::bytes::Buf,
        ) -> Result<Self, fluentbase_sdk::codec::CodecError> {
            let args = fluentbase_sdk::codec::encoder::SolidityABI::<
                GreetingReturnArgs,
            >::decode_function_args(buf)?;
            Ok(Self(args))
        }
    }
    impl ::core::ops::Deref for GreetingReturn {
        type Target = GreetingReturnArgs;
        fn deref(&self) -> &Self::Target {
            &self.0
        }
    }
};
pub type CustomGreetingCallArgs = (String,);
#[derive(Debug, Clone, PartialEq)]
pub struct CustomGreetingCall(pub CustomGreetingCallArgs);
pub type CustomGreetingReturnArgs = (String,);
#[derive(Debug, Clone, PartialEq)]
pub struct CustomGreetingReturn(pub CustomGreetingReturnArgs);
const _: () = {
    impl CustomGreetingCall {
        pub const SELECTOR: [u8; 4] = [54u8, 184u8, 58u8, 154u8];
        pub const SIGNATURE: &'static str = "customGreeting(string)";
        /// Creates a new call instance from arguments
        pub fn new(args: CustomGreetingCallArgs) -> Self {
            Self(args)
        }
        /// Encodes with selector
        pub fn encode(&self) -> fluentbase_sdk::codec::bytes::Bytes {
            let mut args_buf = fluentbase_sdk::codec::bytes::BytesMut::new();
            fluentbase_sdk::codec::encoder::SolidityABI::encode_function_args(
                    &self.0,
                    &mut args_buf,
                )
                .expect("Failed to encode values");
            let mut buf = fluentbase_sdk::codec::bytes::BytesMut::new();
            buf.extend_from_slice(&Self::SELECTOR);
            buf.extend_from_slice(&args_buf);
            buf.freeze()
        }
        /// Decodes call arguments from bytes
        pub fn decode(
            buf: &impl fluentbase_sdk::codec::bytes::Buf,
        ) -> Result<Self, fluentbase_sdk::codec::CodecError> {
            let args = fluentbase_sdk::codec::encoder::SolidityABI::<
                CustomGreetingCallArgs,
            >::decode_function_args(buf)?;
            Ok(Self(args))
        }
    }
    impl ::core::ops::Deref for CustomGreetingCall {
        type Target = CustomGreetingCallArgs;
        fn deref(&self) -> &Self::Target {
            &self.0
        }
    }
    impl CustomGreetingReturn {
        /// Creates a new return instance from values
        pub fn new(args: CustomGreetingReturnArgs) -> Self {
            Self(args)
        }
        /// Encodes the return values to bytes
        pub fn encode(&self) -> fluentbase_sdk::codec::bytes::Bytes {
            let mut buf = fluentbase_sdk::codec::bytes::BytesMut::new();
            fluentbase_sdk::codec::encoder::SolidityABI::encode_function_args(
                    &self.0,
                    &mut buf,
                )
                .expect("Failed to encode values");
            buf.freeze()
        }
        /// Decodes return values from bytes
        pub fn decode(
            buf: &impl fluentbase_sdk::codec::bytes::Buf,
        ) -> Result<Self, fluentbase_sdk::codec::CodecError> {
            let args = fluentbase_sdk::codec::encoder::SolidityABI::<
                CustomGreetingReturnArgs,
            >::decode_function_args(buf)?;
            Ok(Self(args))
        }
    }
    impl ::core::ops::Deref for CustomGreetingReturn {
        type Target = CustomGreetingReturnArgs;
        fn deref(&self) -> &Self::Target {
            &self.0
        }
    }
};
impl<SDK: SharedAPI> App<SDK> {
    pub fn main(&mut self) {
        let input_length = self.sdk.input_size();
        if input_length < 4 {
            panic!("insufficient input length for method selector");
        }
        let mut call_data = alloc::vec![0u8; input_length as usize];
        self.sdk.read(&mut call_data, 0);
        let (selector, params) = call_data.split_at(4);
        match [selector[0], selector[1], selector[2], selector[3]] {
            [68u8, 97u8, 93u8, 234u8] => {
                let (param0, param1, param2) = match GreetingCall::decode(&params) {
                    Ok(decoded) => (decoded.0.0, decoded.0.1, decoded.0.2),
                    Err(err) => {
                        panic!("Failed to decode parameters: {:?}", err);
                    }
                };
                let output = self.greeting(param0, param1, param2);
                let encoded_output = GreetingReturn::new((output,)).encode();
                self.sdk.write(&encoded_output);
            }
            [54u8, 184u8, 58u8, 154u8] => {
                let param0 = match CustomGreetingCall::decode(&params) {
                    Ok(decoded) => decoded.0.0,
                    Err(err) => {
                        panic!("Failed to decode parameters: {:?}", err);
                    }
                };
                let output = self.custom_greeting(param0);
                let encoded_output = CustomGreetingReturn::new((output,)).encode();
                self.sdk.write(&encoded_output);
            }
            _ => panic!("unsupported method selector"),
        }
    }
}
