Skip to content

Instantly share code, notes, and snippets.

@whalelephant
Created September 27, 2023 14:09
Show Gist options
  • Save whalelephant/aab2f7ff0e6ee70f98123f76c3e769ec to your computer and use it in GitHub Desktop.
Save whalelephant/aab2f7ff0e6ee70f98123f76c3e769ec to your computer and use it in GitHub Desktop.
contract_authz_example.rs
// 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