Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
changed map and functions to just use principal.
Browse files Browse the repository at this point in the history
  • Loading branch information
sternbergm authored and EmbeddedAndroid committed Oct 24, 2023
1 parent f532047 commit 928c9e9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ First we're going to set up the data variables we need.
```clojure
;; Define the contract's data variables
(define-map deposits { owner: principal } { amount: uint })
(define-map loans {owner : principal} { amount: uint, last-interaction-block: uint })
(define-map loans principal { amount: uint, last-interaction-block: uint })

(define-data-var total-deposits uint u0)
(define-data-var total-loans uint u0)
Expand Down Expand Up @@ -687,14 +687,14 @@ Next up, let's write the `borrow` function.
(let (
(user-deposit (default-to u0 (get amount (map-get? deposits { owner: tx-sender }))))
(allowed-borrow (/ user-deposit u2))
(current-loan-details (default-to { amount: u0, last-interaction-block: u0 } (map-get? loans { owner: tx-sender })))
(current-loan-details (default-to { amount: u0, last-interaction-block: u0 } (map-get? loans tx-sender )))
(accrued-interest (calculate-accrued-interest (get amount current-loan-details) (get last-interaction-block current-loan-details)))
(total-due (+ (get amount current-loan-details) (unwrap! accrued-interest (err u8))))
(new-loan (+ total-due amount))
)
(asserts! (<= amount allowed-borrow) (err u7))
(try! (contract-call? .asset transfer amount (as-contract tx-sender) tx-sender none))
(map-set loans { owner: tx-sender } { amount: new-loan, last-interaction-block: block-height })
(map-set loans tx-sender { amount: new-loan, last-interaction-block: block-height })
(ok true)
)
)
Expand All @@ -718,13 +718,13 @@ Next up we have the repay function.
;; Users can repay their sBTC loans
(define-public (repay (amount uint))
(let (
(current-loan-details (default-to { amount: u0, last-interaction-block: u0 } (map-get? loans { owner: tx-sender })))
(current-loan-details (default-to { amount: u0, last-interaction-block: u0 } (map-get? loans tx-sender)))
(accrued-interest (calculate-accrued-interest (get amount current-loan-details) (get last-interaction-block current-loan-details)))
(total-due (+ (get amount current-loan-details) (unwrap! accrued-interest (err u8))))
)
(asserts! (>= total-due amount) (err u4))
(try! (contract-call? .asset transfer amount tx-sender (as-contract tx-sender) none))
(map-set loans { owner: tx-sender } { amount: (- total-due amount), last-interaction-block: block-height })
(map-set loans tx-sender { amount: (- total-due amount), last-interaction-block: block-height })
(var-set total-loans (- (var-get total-loans) amount))
(ok true)
)
Expand Down

0 comments on commit 928c9e9

Please sign in to comment.