Skip to content
CCPEDIAby Unity Nodes
App Development

Finance Library Interface Casting

4 posts321 views3 likesLast activity Dec 2022

  1. VictorShneerOP 1

    Hi Finance team!

    I have a template that implements Fungible interface.
    In order to Merge or Split I need to work with ContractId Fungible type.
    Imagine that my input is ContractId Holding.I type.
    Is it right that in order to cast from ContractId Holding.I to ContractId Fungible I have to go through three steps. Like this:

    holdingCid = fromInterfaceContractId @Holding holdingIcid -- holdingIcid : Holding.I
    fungibleIcid = toInterfaceContractId @Fungible.I holdingCid
    fungibleCid = fromInterfaceContractId @Fungible fungibleIcid
    

    I tested it in the Update context and it works. Is it the only way, or I missing something?
    I’m asking mostly for the sake of understanding. This is not a production code.

    Thanks!

  2. Matteo_Limberto 2

    Hi @VictorShneer,

    You can use the following casting functions.

    • template cid → interface cid : toInterfaceContractId
    • interface cid → template cid : fromInterfaceContractId
    • interface cid → interface cid : coerceInterfaceContractId (or coerceContractId for an SDK version earlier than 2.5.0

    In your case, you can use the third option to convert a ContractId Holding.I to a ContractId Fungible.I

  3. VictorShneer
    Matteo_Limberto:

    coerceContractId

    Cool thanks! Is it documented?


  4. Matteo_Limberto

    coerceInterfaceContractId will be documented in the documentation for the 2.5.0 release.

    coerceContractId, on the other hand, is not documented.