Created
September 27, 2023 14:09
-
-
Save whalelephant/aab2f7ff0e6ee70f98123f76c3e769ec to your computer and use it in GitHub Desktop.
contract_authz_example.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use protobuf | |
use cosmos_sdk_proto::{ | |
cosmos::feegrant::v1beta1::{BasicAllowance, MsgGrantAllowance}, | |
traits::{MessageExt, TypeUrl}, | |
}; | |
// example code Exec | |
#[msg(exec)] | |
fn authz_exec(&self, ctx: ExecCtx, grantee: String) -> Result<Response, Self::Error> { | |
deps.api.addr_validate(&grantee)?; | |
let feegrant_msg = MsgGrantAllowance { | |
granter: env.contract.address.to_string(), | |
grantee, | |
allowance: Some( | |
BasicAllowance { | |
// There is no spending limit for this grantee | |
spend_limit: vec![], | |
expiration: None, | |
} | |
.to_any()?, | |
), | |
} | |
.to_any()?; | |
let msg = CosmosMsg::Stargate { | |
type_url: feegrant_msg.type_url, | |
value: feegrant_msg.value.into(), | |
}; | |
Response::new().add_message(msg); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment