Contract post-conditions
Source: SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.xbtc-sbtc-swap-v2
Description
The as-contract? function resolves the expression caller to the principal of the current contract. Most importantly it allows a contract to protect its own assets during the execution of the expression with a set of specified allowances.
Use Cases
A contract invoking a body expression that potentially may have unwanted and unexpected asset transfers.
Protecting a contract invoking another external contract's function.
Key Concepts
Contract caller context - Switches the current context's
tx-senderandcontract-callervalues to the contract's principal and executes the body expressions within that context, then checks the asset outflows from the contract against the granted allowances, in declaration order.Clarity post-conditions - Accepts a set of allowances, defined using
with-stx,with-ft,with-nft, andwith-stacking, which selectively grant outflow allowances from the contract's assets.
Last updated
Was this helpful?