fn handle_query(
        &self,
        origin: Option<&chain::AccountId>,
        req: Request,
        _context: &mut contracts::QueryContext,
    ) -> Result<Response, Error> {
        info!("Query received: {:?}", &req);

        let sender = origin.ok_or(Error::OriginUnavailable)?;
        let alice = contracts::account_id_from_hex(ALICE)
            .expect("should not failed with valid address; qed.");
        match req {
            Request::QueryOwner => Ok(Response::Owner(self.owner.clone())),
            Request::QueryBotToken => {
                if sender != &alice && sender != &self.owner {
                    return Err(Error::NotAuthorized);
                }

                Ok(Response::BotToken(self.bot_token.clone()))
            }
            Request::QueryChatId => {
                if sender != &alice && sender != &self.owner {
                    return Err(Error::NotAuthorized);
                }

                Ok(Response::ChatId(self.chat_id.clone()))
            }
            Request::QueryPrice => Ok(Response::Price(self.price.clone())),
        }
    }
// Handle a direct Query and respond to it. It shouldn't modify the contract state.
Handle a direct Query and respond to it. It shouldn't modify the contract state.
Handle a direct Query and respond to it . It shouldn ' t modify the contract state .
fn handle_query(
        &self,
        origin: Option<&chain::AccountId>,
        req: Request,
        _context: &mut contracts::QueryContext,
    ) -> Result<Response, Error> {
        info!("Query received: {:?}", &req);
        let sender = origin.ok_or(Error::OriginUnavailable)?;
        let alice = contracts::account_id_from_hex(ALICE)
            .expect("should not failed with valid address; qed.");
        match req {
            Request::QueryOwner => Ok(Response::Owner(self.owner.clone())),
            Request::QueryBotToken => {
                if sender != &alice && sender != &self.owner {
                    return Err(Error::NotAuthorized);
                }
                Ok(Response::BotToken(self.bot_token.clone()))
            }
            Request::QueryChatId => {
                if sender != &alice && sender != &self.owner {
                    return Err(Error::NotAuthorized);
                }
                Ok(Response::ChatId(self.chat_id.clone()))
            }
            Request::QueryPrice => Ok(Response::Price(self.price.clone())),
        }
    }
fn handle_query ( & self , origin : Option < & chain :: AccountId > , req : Request , _context : & mut contracts :: QueryContext , ) -> Result < Response , Error > { info ! ( " " req ) ; let sender = origin . ok_or ( Error :: OriginUnavailable ) ? ; let alice = contracts :: account_id_from_hex ( ALICE ) . expect ( " " ) ; match req { Request :: QueryOwner => Ok ( Response :: Owner ( self . owner . clone ( ) ) ) , Request :: QueryBotToken => { if sender != & alice && sender != & self . owner { return Err ( Error :: NotAuthorized ) ; } Ok ( Response :: BotToken ( self . bot_token . clone ( ) ) ) } Request :: QueryChatId => { if sender != & alice && sender != & self . owner { return Err ( Error :: NotAuthorized ) ; } Ok ( Response :: ChatId ( self . chat_id . clone ( ) ) ) } Request :: QueryPrice => Ok ( Response :: Price ( self . price . clone ( ) ) ) , } }
Handle a direct Query and respond to it.
Handle a direct Query and respond to it .
&self
origin
Option<&chain::AccountId>
req
Request
_context
&mut contracts::QueryContext
&self
origin
Option<&chain::AccountId>
req
Request
_context
&mut contracts::QueryContext