1

The force_vote function in voting contract places a call to a different contract easily, but when I want to get some data from the other contract as well, it fails. Similarly in the function where the funds get distributed it is throwing "ContractTrapped" error. If I try hardcoding the values, it works fine, but not in this case. Am I doing something wrong here?

        pub fn force_vote(&mut self, _vote_id: u32) -> Result<()> {
            if self.env().caller() != self.admin {
                return Err(Error::UnAuthorisedCall);
            }
            if self.vote_id_to_info.get(_vote_id).unwrap().admin_hit_time
                > self.env().block_timestamp()
            {
                return Err(Error::RightsNotActivatedYet);
            }
            let mut x = self.vote_id_to_info.get(_vote_id).unwrap();

            if !x.is_active {
                return Err(Error::ResultAlreadyPublished);
            }
            if x.decided_deadline > 0 {
                let result_call = ink::env::call::build_call::<Environment>()
                    .call(self.escrow_address)
                    .gas_limit(0)
                    .transferred_value(0)
                    .exec_input(
                        ink::env::call::ExecutionInput::new(ink::env::call::Selector::new(
                            ink::selector_bytes!("arbiters_extend_deadline"),
                        ))
                        .push_arg(&x.audit_id)
                        .push_arg(&x.decided_deadline + self.env().block_timestamp())
                        .push_arg(&x.decided_haircut)
                        .push_arg(self.arbiters_share),
                    )
                    .returns::<Result<()>>()
                    .try_invoke();
                if matches!(result_call.unwrap().unwrap(), Result::Ok(())) {
                    //middleout changes
                    // let payment_info = ink::env::call::build_call::<Environment>()
                    //     .call(self.escrow_address)
                    //     .gas_limit(0)
                    //     .transferred_value(0)
                    //     .exec_input(
                    //         ink::env::call::ExecutionInput::new(ink::env::call::Selector::new(
                    //             ink::selector_bytes!("get_paymentinfo"),
                    //         ))
                    //         .push_arg(x.audit_id),
                    //     )
                    //     .returns::<Option<PaymentInfo>>()
                    //     .invoke()
                    //     .unwrap();
                    // let push_value =
                    //     payment_info.value * 5 / 100 + self.get_treasury_info(_vote_id).unwrap();
                    // // let push_value = self.internal_value_calculator(_vote_id, 5, x.audit_id);
                    // self.vote_id_to_treasury.insert(_vote_id, &push_value);
                    let bal: Balance = 1000;
                    self.vote_id_to_treasury.insert(_vote_id, &bal);

                    x.is_active = false;
                    x.decided_deadline = (x.decided_deadline) / (x.available_votes as Timestamp);
                    x.decided_haircut = (x.decided_haircut) / (x.available_votes as Balance);
                    self.vote_id_to_info.insert(_vote_id, &x);
                    self.env().emit_event(FinalVotePushed {
                        id: _vote_id,
                        pusher: self.env().caller(),
                    });
                    return Ok(());
                } else {
                    return Err(Error::AssessmentFailed);
                }
            } else if x.decided_deadline == 0 {
                let result_call = ink::env::call::build_call::<Environment>()
                    .call(self.escrow_address)
                    .gas_limit(0)
                    .transferred_value(0)
                    .exec_input(
                        ink::env::call::ExecutionInput::new(ink::env::call::Selector::new(
                            ink::selector_bytes!("assess_audit"),
                        ))
                        .push_arg(&x.audit_id)
                        .push_arg(true),
                    )
                    .returns::<Result<()>>()
                    .try_invoke();
                if matches!(result_call.unwrap().unwrap(), Result::Ok(())) {
                    // let payment_info = ink::env::call::build_call::<Environment>()
                    //     .call(self.escrow_address)
                    //     .gas_limit(0)
                    //     .transferred_value(0)
                    //     .exec_input(
                    //         ink::env::call::ExecutionInput::new(ink::env::call::Selector::new(
                    //             ink::selector_bytes!("get_paymentinfo"),
                    //         ))
                    //         .push_arg(x.audit_id),
                    //     )
                    //     .returns::<Option<PaymentInfo>>()
                    //     .invoke()
                    //     .unwrap();
                    // let push_value =
                    //     payment_info.value * 5 / 100 + self.get_treasury_info(_vote_id).unwrap();
                    // let push_value = self.internal_value_calculator(_vote_id, 5, x.audit_id);
                    // self.vote_id_to_treasury.insert(_vote_id, &push_value);
                    let bal: Balance = 1000;
                    self.vote_id_to_treasury.insert(_vote_id, &bal);
                    x.is_active = false;
                    self.vote_id_to_info.insert(_vote_id, &x);
                    return Ok(());
                } else {
                    return Err(Error::AssessmentFailed);
                }
            }
            return Err(Error::UnAuthorisedCall);
        }

0

Your Answer

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