loam-sdk
Subcontracts
A subcontract is a type that implements the IntoKey trait, which is used for lazily loading and storing the type.
Creating Subcontracts
Here's an example of how to create a subcontract:
;
This generates the following implementation:
External API
You can also create and implement external APIs for contract subcontracts:
Core Subcontract
The Core trait provides the minimum logic needed for a contract to be redeployable. A contract should be able to be redeployed to another contract that can also be redeployed. Redeployment requires admin status, as it would be undesirable for an account to redeploy the contract without permission.
Using Core
To use the core subcontract, create a Contract struct and implement Core for it. This makes Contract redeployable by the Admin of the contract and will continue to be redeployable if the new contract also implements Core. After Core other Subcontracts can be added as needed.
use ;
use ;
;
soroban_contract!;
This code generates the following implementation:
;
By specifying the associated Impl type for Core, you enable the default Admin methods to be used (admin_set, admin_get, redeploy). However, you can also provide a different implementation if needed by replacing Admin with a different struct/enum that also implements IsCore.
Notice that the generated code calls Contract::redeploy and other methods. This ensures that the Contract type is redeployable, while also allowing for extensions, as Contract can overwrite the default methods.