Git Product home page Git Product logo

music-licensing-icp's Introduction

Music Licensing System

Overview

This is a Rust implementation of a Music Licensing System Smart Contract for the Internet Computer Web3 platform. It is designed to manage songs, owners, and licenses in the context of a music licensing platform. The system provides functionalities such as creating, updating, and deleting songs, managing song ownership, and handling license requests.

Prerequisites

  • Rust
  • Internet Computer SDK
  • IC CDK

Installation

  1. Clone the repository:

    git clone https://github.com/loboo34/music-licensing-ICP.git
    cd music-licensing-ICP
    npm install
    dfx start --background --clean
    npm run gen-deploy

Data Structure

Type Aliases

  • SongStorage: Alias for StableBTreeMap<u64, Song> to store songs.
  • OwnerStorage: Alias for StableBTreeMap<u64, Owner> to store owners.
  • LicenseStorage: Alias for StableBTreeMap<u64, License> to store licenses.
  • LicenseeStorage: Alias for StableBTreeMap<u64, Licensee> to store licensees.

Struct Definitions

  • Song, Owner, License, Licensee: Structs representing Song, Owner, License, and Licensee entities.
    • Implement CandidType, Clone, Serialize, Deserialize, and provide default values.

Trait Implementations

  • Storable and BoundedStorable implemented for Song, Owner, License, and Licensee.
    • Storable: Conversion to and from bytes.
    • BoundedStorable: Defines maximum size and whether the size is fixed.

Thread-Local Static Variables

  • MEMORY_MANAGER: Manages virtual memory.
  • ID_COUNTER: Keeps track of global IDs.
  • SONG_STORAGE, OWNER_STORAGE, LICENSE_STORAGE, LICENSEE_STORAGE: Stable BTreeMaps for storing songs, owners, licenses, and licensees.

Payload Structs

  • SongPayload, OwnerPayload, UpdateSongPayload, LicensePayload, ApprovePayload, LicenseePayload: Payload data structures for various operations.

Candid Interface Definitions

  • Functions annotated with ic_cdk::query are read-only queries.
  • Functions annotated with ic_cdk::update are updates, which can modify the state.

Memory Management

Memory is allocated using a MemoryManager from the ic-stable-structures crate:

static MEMORY_MANAGER: RefCell<MemoryManager<DefaultMemoryImpl>> = // initialized

This manages allocating VirtualMemory for storages.

ID Generation

Unique IDs are generated using a thread-local IdCell:

static ID_COUNTER: RefCell<IdCell> = // initialized

The counter is incremented when adding new records.

Record Storage

Records are stored in thread-local StableBTreeMaps:

static SONG_STORAGE: RefCell<SongStorage> = // initialized
static OWNER_STORAGE: RefCell<OwnerStorage> = // initialized
static LICENSE_STORAGE: RefCell<LicenseStorage> = // initialized
static LICENSEE_STORAGE: RefCell<LicenseeStorage> = // initialized

Each storage maps IDs to their respective entities (songs, owners, licenses, and licensees).

Main Functions

User Functions

  • get_song(id: u64): Retrieve a song by ID.
  • get_all_songs(): Retrieve all licensable songs.
  • create_song(payload: SongPayload): Create a new song.
  • update_song(payload: UpdateSongPayload): Update an existing song.
  • delete_song(auth_key: String, id: u64): Delete a song.

Owner Functions

  • get_song_owner(id: u64): Retrieve the owner of a song.
  • create_owner(payload: OwnerPayload): Create a new owner.

License Functions

  • get_license(id: u64): Retrieve a license by ID.
  • get_owner_license_requests(id: u64): Retrieve licenses requested by an owner.
  • get_licensee_licenses(id: u64): Retrieve licenses associated with a licensee.
  • create_license_request(payload: LicensePayload): Create a license request.
  • approve_license(payload: ApprovePayload): Approve a license.

Error Handling

  • NotFound: Indicates that an entity (song, owner, license) could not be found.
  • InvalidPayload: Indicates an issue with the payload during creation or update.
  • AlreadyApproved: Indicates an attempt to approve a license that has already been approved.
  • Unauthorized: Indicates that the user does not have the necessary permissions.

Learn more

To learn more before you start working with music_licensing, see the following documentation available online:

If you want to start working on your project right away, you might want to try the following commands:

cd music-licensing-ICP/
dfx help
dfx canister --help

Running the project locally

If you want to test your project locally, you can use the following commands:

# Starts the replica, running in the background
dfx start --background

# Deploys your canisters to the replica and generates your candid interface
dfx deploy

Once the job completes, your application will be available at http://localhost:4943?canisterId={asset_canister_id}.

If you have made changes to your backend canister, you can generate a new candid interface with

npm run generate

at any time. This is recommended before starting the frontend development server, and will be run automatically any time you run dfx deploy.

If you are making frontend changes, you can start a development server with

npm start

Which will start a server at http://localhost:8080, proxying API requests to the replica at port 4943.

Note on frontend environment variables

If you are hosting frontend code somewhere without using DFX, you may need to make one of the following adjustments to ensure your project does not fetch the root key in production:

  • setDFX_NETWORK to production if you are using Webpack
  • use your own preferred method to replace process.env.DFX_NETWORK in the autogenerated declarations
    • Setting canisters -> {asset_canister_id} -> declarations -> env_override to a string in dfx.json will replace process.env.DFX_NETWORK with the string in the autogenerated declarations
  • Write your own createActor constructor

music-licensing-icp's People

Contributors

loboo34 avatar collins-ruto avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.