1
    #![cfg_attr(not(feature = "std"), no_std, no_main)]

#[ink::contract]
mod arm {
    use ink::prelude::vec::Vec;

    #[derive(scale::Decode, scale::Encode)]
    #[cfg_attr(
        feature = "std",
        derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout)
    )]
    pub struct Arbiter {
        voter_address: AccountId,
        has_voted: bool,
    }

    #[derive(scale::Decode, scale::Encode)]
    #[cfg_attr(
        feature = "std",
        derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout)
    )]
    pub struct X {
        pub audit_id: u32,
        pub arbiters: Vec<Arbiter>,
        pub is_active: bool,
        pub available_votes: u8,
        pub decided_deadline: Timestamp,
        pub decided_haircut: Balance,
        pub admin_hit_time: Timestamp,
    }
    // use ink::primitives::AccountId;

    /// Defines the storage of your contract.
    /// Add new fields to the below struct in order
    /// to add new static storage fields to your contract.
    #[ink(storage)]
    pub struct Arm {
        /// Stores a single `bool` value on the storage.
        value: AccountId,
    }

    impl Arm {
        /// Constructor that initializes the `bool` value to the given `init_value`.
        #[ink(constructor)]
        pub fn new(init_value: AccountId) -> Self {
            Self { value: init_value }
        }

        /// Constructor that initializes the `bool` value to `false`.
        /// A message that can be called on instantiated contracts.
        /// This one flips the value of the stored `bool` from `true`
        /// to `false` and vice versa.

        /// Simply returns the current value of our `bool`.
        #[ink(message)]
        pub fn get_owner(&self) -> AccountId {
            let actual_provider = ink::env::call::build_call::<Environment>()
                .call(self.value)
                .gas_limit(0)
                .transferred_value(0)
                .exec_input(ink::env::call::ExecutionInput::new(
                    ink::env::call::Selector::new(ink::selector_bytes!("know_your_admin")),
                ))
                .returns::<AccountId>()
                .invoke();
            return actual_provider;
        }
        #[ink(message)]
        pub fn get_struct_details(&self) -> u8 {
            let vote_info: X = ink::env::call::build_call::<Environment>()
                .call(self.value)
                .gas_limit(0)
                .transferred_value(0)
                .exec_input(
                    ink::env::call::ExecutionInput::new(ink::env::call::Selector::new(
                        ink::selector_bytes!("get_poll_info"),
                    ))
                    .push_arg(0),
        

            )
                    .returns::<X>()
                    .invoke();
                return vote_info.available_votes;
            }
        }
    }

This is just a trial contract to check the viability of performing this task in this manner, i.e, defining the struct in caller's contract as well and then trying to use it. It is not working. What am I doing wrong? Is there another way I could do this?

1 Answer 1

0

From looking at a piece of code of mine:

            let result = build_call::<DefaultEnvironment>()
                .call(self.governance_token)
                .gas_limit(0)
                .transferred_value(0)
                .call_flags(CallFlags::default())
                .exec_input(
                    ExecutionInput::new(Selector::new(ink::selector_bytes!("balance_of")))
                        .push_arg(caller),
                )
                .returns::<Balance>()
                .try_invoke();
            match result {
                EnvResult::Ok(MessageResult::Ok(result)) => result,
                _ => unimplemented!(),
            }

You might need to check what type vote_info is (maybe you still need to unwrap it).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.