Skip to content

benitakanu/Secondhand-Goods-History-Report

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Secondhand Goods History Report Smart Contract

A robust Clarity smart contract for the Stacks blockchain that tracks ownership and condition history of secondhand goods. This contract provides immutable, auditable records of item transfers and status updates.

Overview

This smart contract enables users to:

  • Register secondhand goods with metadata
  • Transfer ownership with historical tracking
  • Update item condition and status
  • Retrieve complete ownership and status history
  • Verify ownership at any point in time

All operations are recorded on the blockchain, creating an immutable audit trail for transparency and trust in the secondhand goods market.

Features

  • Robust Input Validation: All user inputs are validated before storage
  • Complete History Tracking: Maintains full ownership and status change history
  • Access Control: Only item owners can transfer or update their goods
  • Comprehensive Error Handling: 7 distinct error codes for different failure scenarios
  • Read-Only Queries: Safe functions to retrieve data without state changes
  • Block Height Tracking: Timestamp tracking using Stacks block height

Data Structures

Goods Map

Stores primary information about each registered good: ``` { good-id: uint, title: string-ascii (100 chars max), description: string-ascii (256 chars max), current-owner: principal, current-status: string-ascii (20 chars max), condition: uint (1-10 scale), registration-block: uint } ```

Ownership History Map

Records every ownership transfer: ``` { good-id: uint, history-index: uint, previous-owner: principal, new-owner: principal, transfer-block: uint, transfer-reason: string-ascii (64 chars max) } ```

Status History Map

Records every condition and status update: ``` { good-id: uint, status-index: uint, old-status: string-ascii (20 chars max), new-status: string-ascii (20 chars max), condition-rating: uint (1-10 scale), update-block: uint } ```

Public Functions

register-good

Registers a new secondhand good in the system.

Parameters:

  • title: Item name (1-100 ASCII characters)
  • description: Item details (1-256 ASCII characters)

Returns: (ok uint) - The assigned good-id Caller: Any principal Initial State: Status = "registered", Condition = 10/10

transfer-ownership

Transfers ownership of a good to a new owner.

Parameters:

  • good-id: ID of the good to transfer
  • new-owner: Principal receiving the good
  • reason: Transfer reason (1-64 ASCII characters)

Returns: (ok true) on success Caller: Current owner only Side Effect: Creates ownership history entry

update-condition

Updates the condition rating and status of a good.

Parameters:

  • good-id: ID of the good to update
  • new-status: New status (1-20 ASCII characters)
  • condition-rating: Condition on 1-10 scale

Returns: (ok true) on success Caller: Current owner only Validation: Condition must be between 1-10

Read-Only Functions

get-good-details

Retrieves complete information about a good.

get-ownership-record

Retrieves a specific ownership transfer record.

get-status-record

Retrieves a specific status change record.

get-total-goods

Returns total number of goods registered.

get-next-good-id

Returns the next available good-id.

verify-ownership

Checks if a principal owns a specific good.

get-condition-score

Returns the current condition rating of a good.

Error Codes

Code Name Meaning
u401 ERR-UNAUTHORIZED Access denied
u402 ERR-INVALID-GOOD Good ID not found
u403 ERR-INVALID-STATUS Invalid status or condition value
u404 ERR-ALREADY-EXISTS Good already registered
u405 ERR-NOT-OWNER Caller is not the owner
u406 ERR-INVALID-INPUT Invalid input parameter

Usage Example

;; Register a used laptop
(contract-call? .secondhand-goods register-good 
  "MacBook Pro 2020" 
  "15-inch, 16GB RAM, excellent condition")
;; Returns: (ok u1)

;; Update condition after inspection
(contract-call? .secondhand-goods update-condition 
  u1 
  "inspected" 
  u9)
;; Returns: (ok true)

;; Transfer to new owner
(contract-call? .secondhand-goods transfer-ownership 
  u1 
  'SP2C2YB838J624XPN3Q95GEQ3V77ZSC451DX4RZP7 
  "sold via marketplace")
;; Returns: (ok true)

;; Check ownership
(contract-call? .secondhand-goods verify-ownership 
  u1 
  'SP2C2YB838J624XPN3Q95GEQ3V77ZSC451DX4RZP7)
;; Returns: (ok true)

About

The Secondhand Goods History Report is a blockchain-based smart contract built on the Stacks network using Clarity. It provides an immutable, transparent system for tracking the complete lifecycle of secondhand items, including ownership transfers, condition changes, and historical records.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors