Skip to content

Commit 9d30b13

Browse files
committed
fix: simplify to single account holder
Can always make it more complicated later.
1 parent 770f176 commit 9d30b13

File tree

2 files changed

+99
-140
lines changed

2 files changed

+99
-140
lines changed

contracts/aibtcdev-bank-account.clar

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
;; version: 1.0.0
33
;; summary: A contract that allows specified principals to withdraw STX from the contract with given rules.
44

5-
;; traits
6-
;;
7-
8-
;; token definitions
9-
;;
10-
115
;; constants
126
;;
137
(define-constant DEPLOYER tx-sender)
@@ -22,14 +16,20 @@
2216
(define-data-var withdrawalPeriod uint u144) ;; 144 Bitcoin blocks, ~1 day
2317
(define-data-var withdrawalAmount uint u10000000) ;; 10,000,000 microSTX, or 10 STX
2418
(define-data-var lastWithdrawalBlock uint u0)
19+
(define-data-var accountHolder principal SELF)
2520

26-
;; data maps
27-
;;
28-
(define-map Users principal bool)
2921

3022
;; public functions
3123
;;
3224

25+
(define-public (set-account-holder (new principal))
26+
(begin
27+
(try! (is-deployer))
28+
(asserts! (not (is-eq (var-get accountHolder) new)) ERR_INVALID)
29+
(ok (var-set accountHolder new))
30+
)
31+
)
32+
3333
(define-public (set-withdrawal-period (period uint))
3434
(begin
3535
(try! (is-deployer))
@@ -54,14 +54,6 @@
5454
)
5555
)
5656

57-
(define-public (set-user-list (userList (list 100 {user: principal, enabled: bool})))
58-
(begin
59-
(try! (is-deployer))
60-
(asserts! (> (len userList) u0) ERR_INVALID)
61-
(ok (map set-user-iter userList))
62-
)
63-
)
64-
6557
(define-public (deposit-stx (amount uint))
6658
(begin
6759
(print {
@@ -77,14 +69,9 @@
7769
)
7870

7971
(define-public (withdraw-stx)
80-
(let
81-
(
82-
;; verify user is known in the map (some not none)
83-
(requestor contract-caller)
84-
(userEnabled (unwrap! (map-get? Users contract-caller) ERR_UNAUTHORIZED))
85-
)
72+
(begin
8673
;; verify user is enabled in the map
87-
(asserts! userEnabled ERR_UNAUTHORIZED)
74+
(try! (is-account-holder))
8875
;; verify user is not withdrawing too soon
8976
(asserts! (>= block-height (+ (var-get lastWithdrawalBlock) (var-get withdrawalPeriod))) ERR_TOO_SOON)
9077
;; update last withdrawal block
@@ -95,10 +82,10 @@
9582
payload: {
9683
amount: (var-get withdrawalAmount),
9784
caller: contract-caller,
98-
recipient: contract-caller
85+
recipient: (var-get accountHolder)
9986
}
10087
})
101-
(as-contract (stx-transfer? (var-get withdrawalAmount) SELF requestor))
88+
(as-contract (stx-transfer? (var-get withdrawalAmount) SELF (var-get accountHolder)))
10289
)
10390
)
10491

@@ -129,10 +116,6 @@
129116
}
130117
)
131118

132-
(define-read-only (get-user (user principal))
133-
(map-get? Users user)
134-
)
135-
136119
(define-read-only (get-standard-caller)
137120
(let ((d (unwrap-panic (principal-destruct? contract-caller))))
138121
(unwrap-panic (principal-construct? (get version d) (get hash-bytes d)))
@@ -145,17 +128,6 @@
145128
(ok (asserts! (is-eq DEPLOYER (get-standard-caller)) ERR_UNAUTHORIZED))
146129
)
147130

148-
(define-private (set-user-iter (item {user: principal, enabled: bool}))
149-
(begin
150-
(print {
151-
notification: "set-user",
152-
payload: {
153-
caller: contract-caller,
154-
enabled: (get enabled item),
155-
user: (get user item),
156-
}
157-
})
158-
(map-set Users (get user item) (get enabled item))
159-
(ok (get enabled item))
160-
)
161-
)
131+
(define-private (is-account-holder)
132+
(ok (asserts! (is-eq (var-get accountHolder) (get-standard-caller)) ERR_UNAUTHORIZED))
133+
)

0 commit comments

Comments
 (0)