stacks-core
stacks-core copied to clipboard
Unable to directly extract a trait from a tuple
In Clarity 2, we should be able to store a trait in a tuple and then extract it and use it as any other trait.
(define-trait trait-foo ((foo () (response uint uint))))
(define-public (call-foo-tuple (t { address: <trait-foo>, amount: uint }))
(contract-call? (get address t) foo)
)
For the above contract, the type-checker reports missing contract name for call. As a workaround, the trait can be called indirectly by passing it first in a function call.
(define-private (call-foo (f <trait-foo>))
(contract-call? f foo)
)
(define-public (call-foo-tuple-indirect (t { address: <trait-foo>, amount: uint }))
(call-foo (get address t))
)