---
source: crates/sdk-derive/derive-core/src/client.rs
expression: formatted.to_string()
---
#[derive(Debug)]
pub struct TestContractClient<SDK> {
    pub sdk: SDK,
}
pub type FirstMethodCallArgs = (u32,);
#[derive(Debug, Clone, PartialEq)]
pub struct FirstMethodCall(pub FirstMethodCallArgs);
pub type FirstMethodReturnArgs = (u32,);
#[derive(Debug, Clone, PartialEq)]
pub struct FirstMethodReturn(pub FirstMethodReturnArgs);
const _: () = {
    impl FirstMethodCall {
        pub const SELECTOR: [u8; 4] = [90u8, 193u8, 6u8, 45u8];
        pub const SIGNATURE: &'static str = "firstMethod(uint32)";
        /// Creates a new call instance from arguments
        pub fn new(args: FirstMethodCallArgs) -> 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::<
                FirstMethodCallArgs,
            >::decode_function_args(buf)?;
            Ok(Self(args))
        }
    }
    impl ::core::ops::Deref for FirstMethodCall {
        type Target = FirstMethodCallArgs;
        fn deref(&self) -> &Self::Target {
            &self.0
        }
    }
    impl FirstMethodReturn {
        /// Creates a new return instance from values
        pub fn new(args: FirstMethodReturnArgs) -> 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::<
                FirstMethodReturnArgs,
            >::decode_function_args(buf)?;
            Ok(Self(args))
        }
    }
    impl ::core::ops::Deref for FirstMethodReturn {
        type Target = FirstMethodReturnArgs;
        fn deref(&self) -> &Self::Target {
            &self.0
        }
    }
};
pub type SecondMethodCallArgs = (String, bool);
#[derive(Debug, Clone, PartialEq)]
pub struct SecondMethodCall(pub SecondMethodCallArgs);
pub type SecondMethodReturnArgs = (String, bool);
#[derive(Debug, Clone, PartialEq)]
pub struct SecondMethodReturn(pub SecondMethodReturnArgs);
const _: () = {
    impl SecondMethodCall {
        pub const SELECTOR: [u8; 4] = [92u8, 23u8, 35u8, 57u8];
        pub const SIGNATURE: &'static str = "secondMethod(string,bool)";
        /// Creates a new call instance from arguments
        pub fn new(args: SecondMethodCallArgs) -> 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::<
                SecondMethodCallArgs,
            >::decode_function_args(buf)?;
            Ok(Self(args))
        }
    }
    impl ::core::ops::Deref for SecondMethodCall {
        type Target = SecondMethodCallArgs;
        fn deref(&self) -> &Self::Target {
            &self.0
        }
    }
    impl SecondMethodReturn {
        /// Creates a new return instance from values
        pub fn new(args: SecondMethodReturnArgs) -> 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::<
                SecondMethodReturnArgs,
            >::decode_function_args(buf)?;
            Ok(Self(args))
        }
    }
    impl ::core::ops::Deref for SecondMethodReturn {
        type Target = SecondMethodReturnArgs;
        fn deref(&self) -> &Self::Target {
            &self.0
        }
    }
};
impl<SDK: fluentbase_sdk::SharedAPI> TestContractClient<SDK> {
    pub fn new(sdk: SDK) -> Self {
        Self { sdk }
    }
    pub fn first_method(
        &mut self,
        contract_address: fluentbase_sdk::Address,
        value: fluentbase_sdk::U256,
        gas_limit: u64,
        value: u32,
    ) -> u32 {
        use fluentbase_sdk::ContextReader;
        let input = fluentbase_sdk::Bytes::from(FirstMethodCall::new((value,)).encode());
        {
            let context = self.sdk.context();
            if context.tx_value() < value {
                ::core::panic!("Insufficient funds for transaction");
            }
            if context.tx_gas_limit() < gas_limit {
                ::core::panic!("Insufficient gas limit for transaction");
            }
        }
        let result = self.sdk.call(contract_address, value, &input, Some(gas_limit));
        if !fluentbase_sdk::SyscallResult::is_ok(result.status) {
            ::core::panic!("Contract call failed");
        }
        FirstMethodReturn::decode(&result.data).expect("failed to decode result").0.0
    }
    pub fn second_method(
        &mut self,
        contract_address: fluentbase_sdk::Address,
        value: fluentbase_sdk::U256,
        gas_limit: u64,
        a: String,
        b: bool,
    ) -> (String, bool) {
        use fluentbase_sdk::ContextReader;
        let input = fluentbase_sdk::Bytes::from(SecondMethodCall::new((a, b)).encode());
        {
            let context = self.sdk.context();
            if context.tx_value() < value {
                ::core::panic!("Insufficient funds for transaction");
            }
            if context.tx_gas_limit() < gas_limit {
                ::core::panic!("Insufficient gas limit for transaction");
            }
        }
        let result = self.sdk.call(contract_address, value, &input, Some(gas_limit));
        if !fluentbase_sdk::SyscallResult::is_ok(result.status) {
            ::core::panic!("Contract call failed");
        }
        SecondMethodReturn::decode(&result.data).expect("failed to decode result").0
    }
}
