From 928c9e9c5bdb5be0ed6c93effe7cd6cf164a8bb6 Mon Sep 17 00:00:00 2001 From: sternbergm Date: Sat, 21 Oct 2023 14:01:54 -0400 Subject: [PATCH] changed map and functions to just use principal. --- src/tutorial.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tutorial.md b/src/tutorial.md index db3070a..7a723f1 100644 --- a/src/tutorial.md +++ b/src/tutorial.md @@ -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) @@ -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) ) ) @@ -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) )