Canister guard in Rust on the Internet Computer

David Dal Busco
3 min readDec 15, 2022
Photo by Illumination Marketing on Unsplash

I recently discovered ​it was possible to specify a guard function to be executed before update and query functions of canister smart contracts written in Rust on the Internet Computer.

​​You might tell me that the following post is just a rip off of the Crate documentation but, as I only figured out this was possible while having a look at the transaction notifier repo of OpenChat, I thought it was worth a post 😄.

Want to start building decentralized apps without learning a new programming language? Check out Juno, the open-source Blockchain-as-a-Service platform that makes it faster and easier than ever before to build dapps with frontend code only! ⚡️🚀🤯

Original approach

​I began my journey with Rust when I migrated my existing Motoko code — i.e. when I upgraded the existing smart contracts of Papyrs.

As these canisters were dedicated to user data, I had to migrate functions that required access control too.

​For this purpose, I implemented comparison of principals — i.e. I match the callers of functions against users that are saved in the state. If they are equals, methods can be executed, if not, I throw errors and reject the call.

--

--