pub fn receive_cw20(
    deps: DepsMut,
    env: Env,
    info: MessageInfo,
    cw20_msg: Cw20ReceiveMsg,
) -> Result<Response, ContractError> {
    // only asset contract can execute this message
    let config: Config = config_read(deps.storage).load()?;
    if config.whale_token != deps.api.addr_canonicalize(info.sender.as_str())? {
        return Err(ContractError::Unauthorized {});
    }

    match from_binary(&cw20_msg.msg) {
        Ok(Cw20HookMsg::StakeVotingTokens {}) => {
            let api = deps.api;
            stake_voting_tokens(deps, api.addr_validate(&cw20_msg.sender)?, cw20_msg.amount)
        }
        Ok(Cw20HookMsg::CreatePoll {
            title,
            description,
            link,
            execute_msgs,
        }) => create_poll(
            deps,
            env,
            cw20_msg.sender,
            cw20_msg.amount,
            title,
            description,
            link,
            execute_msgs,
        ),
        _ => Err(ContractError::DataShouldBeGiven {}),
    }
}
/// handler function invoked when the governance contract receives
/// a transaction. This is akin to a payable function in Solidity
handler function invoked when the governance contract receives
a transaction. This is akin to a payable function in Solidity
handler function invoked when the governance contract receives a transaction . This is akin to a payable function in Solidity
pub fn receive_cw20(
    deps: DepsMut,
    env: Env,
    info: MessageInfo,
    cw20_msg: Cw20ReceiveMsg,
) -> Result<Response, ContractError> {
    // only asset contract can execute this message
    let config: Config = config_read(deps.storage).load()?;
    if config.whale_token != deps.api.addr_canonicalize(info.sender.as_str())? {
        return Err(ContractError::Unauthorized {});
    }
    match from_binary(&cw20_msg.msg) {
        Ok(Cw20HookMsg::StakeVotingTokens {}) => {
            let api = deps.api;
            stake_voting_tokens(deps, api.addr_validate(&cw20_msg.sender)?, cw20_msg.amount)
        }
        Ok(Cw20HookMsg::CreatePoll {
            title,
            description,
            link,
            execute_msgs,
        }) => create_poll(
            deps,
            env,
            cw20_msg.sender,
            cw20_msg.amount,
            title,
            description,
            link,
            execute_msgs,
        ),
        _ => Err(ContractError::DataShouldBeGiven {}),
    }
}
pub fn receive_cw20 ( deps : DepsMut , env : Env , info : MessageInfo , cw20_msg : Cw20ReceiveMsg , ) -> Result < Response , ContractError > { // only asset contract can execute this message let config : Config = config_read ( deps . storage ) . load ( ) ? ; if config . whale_token != deps . api . addr_canonicalize ( info . sender . as_str ( ) ) ? { return Err ( ContractError :: Unauthorized { } ) ; } match from_binary ( & cw20_msg . msg ) { Ok ( Cw20HookMsg :: StakeVotingTokens { } ) => { let api = deps . api ; stake_voting_tokens ( deps , api . addr_validate ( & cw20_msg . sender ) ? , cw20_msg . amount ) } Ok ( Cw20HookMsg :: CreatePoll { title , description , link , execute_msgs , } ) => create_poll ( deps , env , cw20_msg . sender , cw20_msg . amount , title , description , link , execute_msgs , ) , _ => Err ( ContractError :: DataShouldBeGiven { } ) , } }
handler function invoked when the governance contract receives
a transaction.
handler function invoked when the governance contract receives a transaction .
deps
DepsMut
env
Env
info
MessageInfo
cw20_msg
Cw20ReceiveMsg
deps
DepsMut
env
Env
info
MessageInfo
cw20_msg
Cw20ReceiveMsg