Skip to content

Commit 384bb2f

Browse files
committed
fix: update messaging contract
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.
1 parent 2dfd27f commit 384bb2f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

contracts/dao/extensions/aibtcdev-messaging.clar

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
(ok true)
1919
)
2020

21-
(define-public (send (msg (string-ascii 1048576)) (opcode (optional (buff 16))))
21+
(define-public (send (msg (string-ascii 1048576)) (isFromDao bool))
2222
(begin
23+
(and isFromDao (try! (is-dao-or-extension)))
2324
(asserts! (> (len msg) u0) INPUT_ERROR)
2425
;; print the message as the first event
2526
(print msg)
@@ -29,9 +30,19 @@
2930
payload: {
3031
caller: contract-caller,
3132
height: block-height,
33+
isFromDao: isFromDao,
3234
sender: tx-sender,
3335
}
3436
})
3537
(ok true)
3638
)
3739
)
40+
41+
;; private functions
42+
;;
43+
44+
(define-private (is-dao-or-extension)
45+
(ok (asserts! (or (is-eq tx-sender .aibtcdev-dao)
46+
(contract-call? .aibtcdev-dao is-extension contract-caller)) ERR_UNAUTHORIZED
47+
))
48+
)

contracts/dao/traits/aibtcdev-dao-traits-v1.clar

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@
4747

4848
(define-trait messaging
4949
(
50-
;; send a message on-chain
50+
;; send a message on-chain (opt from DAO)
5151
;; @param msg the message to send (up to 1MB)
52+
;; @param isFromDao whether the message is from the DAO
5253
;; @returns (response bool uint)
53-
(send ((string-ascii 1048576)) (response bool uint))
54+
(send ((string-ascii 1048576) bool) (response bool uint))
5455
)
5556
)
5657

0 commit comments

Comments
 (0)