Source Code

;; ink-pen -- Islamic calligraphy pen and tool marketplace
(define-data-var tool-count uint u0)
(define-map tools uint { seller: principal, name: (string-ascii 30), type: (string-ascii 20), price: uint, sold: bool })
(define-public (list-tool (name (string-ascii 30)) (type (string-ascii 20)) (price uint))
  (let ((id (+ (var-get tool-count) u1)))
    (var-set tool-count id)
    (map-set tools id { seller: tx-sender, name: name, type: type, price: price, sold: false }) (ok id)))
(define-public (buy-tool (id uint))
  (let ((t (unwrap! (map-get? tools id) (err u404))))
    (map-set tools id (merge t { sold: true })) (ok true)))
(define-read-only (get-tool (id uint)) (map-get? tools id))
(define-read-only (get-count) (var-get tool-count))

Functions (4)

FunctionAccessArgs
list-toolpublicname: (string-ascii 30
buy-toolpublicid: uint
get-toolread-onlyid: uint
get-countread-only