Skip to content

use-function built-in to import functions from other contracts #97

@MarvinJanssen

Description

@MarvinJanssen

I suggest the introduction of a new top-level built-in like use-trait.

The use-function built-in is used to import and alias a function of another contract.

contract-a:

(define-data-var some-var uint u0)

(define-public (some-func (some-param uint))
  (ok (var-set some-var some-param))
)

contract-b:

(use-function SP123...contract-a some-func my-some-func)

(define-public (use-some-func)
  (my-some-func u42)
)

The calling context remains the contract the function is defined in. Using my-some-func would be equivalent to substituting it with contract-call?. (It is a call, not a delegate call.)

use-function, like use-trait, can only be used top-level.

The upsides:

  • All contracts for which use-function is used are cached so the external function will be cheaper to call iteratively compared to a series of contract-call?. It is an alternative solution for the issue described in Support caching model #94. Bound by all the same runtime dimensions.
  • Much easier to create library contracts that add functionality.
  • Better composability, don't need to repeat contract-call? nor create a local wrapper function.

Edit: related to #11.

Metadata

Metadata

Assignees

No one assigned

    Labels

    new-builtinThe issue describes a new Clarity builtin (function or variable)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions