Skip to content

Commit

Permalink
fix: update messaging contract
Browse files Browse the repository at this point in the history
Adds an option to auth from DAO or not, so can be used from proposals to send authenticated messages or can be used by anyone who calls it.
  • Loading branch information
whoabuddy committed Dec 24, 2024
1 parent 2dfd27f commit 384bb2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 12 additions & 1 deletion contracts/dao/extensions/aibtcdev-messaging.clar
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
(ok true)
)

(define-public (send (msg (string-ascii 1048576)) (opcode (optional (buff 16))))
(define-public (send (msg (string-ascii 1048576)) (isFromDao bool))
(begin
(and isFromDao (try! (is-dao-or-extension)))
(asserts! (> (len msg) u0) INPUT_ERROR)
;; print the message as the first event
(print msg)
Expand All @@ -29,9 +30,19 @@
payload: {
caller: contract-caller,
height: block-height,
isFromDao: isFromDao,
sender: tx-sender,
}
})
(ok true)
)
)

;; private functions
;;

(define-private (is-dao-or-extension)
(ok (asserts! (or (is-eq tx-sender .aibtcdev-dao)
(contract-call? .aibtcdev-dao is-extension contract-caller)) ERR_UNAUTHORIZED
))
)
5 changes: 3 additions & 2 deletions contracts/dao/traits/aibtcdev-dao-traits-v1.clar
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@

(define-trait messaging
(
;; send a message on-chain
;; send a message on-chain (opt from DAO)
;; @param msg the message to send (up to 1MB)
;; @param isFromDao whether the message is from the DAO
;; @returns (response bool uint)
(send ((string-ascii 1048576)) (response bool uint))
(send ((string-ascii 1048576) bool) (response bool uint))
)
)

Expand Down

0 comments on commit 384bb2f

Please sign in to comment.