Skip to content

IP‑On‑Chain Pallet — Configuration Guide

Covers the Config trait items, runtime‑integration snippets, and genesis examples for the ip‑onchain pallet.


Config Trait

#[pallet::config]
pub trait Config<I: 'static = ()>: frame_system::Config {
    /* --- Core Identifier Types --- */
    type EntityId:       Parameter + Member + MaxEncodedLen + Copy + Incrementable + CheckedAdd + CheckedSub + PartialOrd;
    type AuthorId:       Parameter + Member + MaxEncodedLen + Copy + Incrementable + CheckedAdd + CheckedSub + PartialOrd;
    type AuthorityId:    Parameter + Member + MaxEncodedLen + Copy + Incrementable + CheckedAdd + CheckedSub + PartialOrd;

    /* --- Runtime Whitelist for entity creation --- */
    type WhiteListChecker: Contains<Self::AccountId>;

    /* --- Size / Count Limits --- */
    #[pallet::constant] type MaxShortStringLength: Get<u32>;   // e.g. titles, names
    #[pallet::constant] type MaxLongStringLength:  Get<u32>;   // e.g. descriptions, URIs
    #[pallet::constant] type MaxEntityAuthors:     Get<u32>;   // authors-per-entity
    #[pallet::constant] type MaxRoyaltyParts:      Get<u32>;   // splits per entity
    #[pallet::constant] type MaxRelatedEntities:   Get<u32>;   // e.g. stems & remixes references
    #[pallet::constant] type MaxArrayLen:          Get<u32>;   // generic upper‑bound for Vec fields

    /* --- Events --- */
    type RuntimeEvent: From<Event<Self, I>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}

Extended Constants

Constant Purpose Suggested Default
MaxShortStringLength Upper‑bound for short text (e.g. titles) 64
MaxLongStringLength Upper‑bound for long text (e.g. IPFS URIs) 256–512
MaxEntityAuthors Max co‑authors per entity 10
MaxRoyaltyParts Max royalty splits per entity 10–20
MaxRelatedEntities Max linked entities (stems/remixes) 32
MaxArrayLen Safety cap for any unbounded Vec 128

(Adjust numbers to suit chain limits and weight benchmarks.)

Updated Key Types Table

Associated Type Purpose
EntityId Track/sample primary key
AuthorId Artist or rights‑holder identifier
AuthorityId Verification/certification body
WhiteListChecker Origin filter for privileged calls
RuntimeEvent Aggregated pallet events

All identifier types must implement Incrementable, CheckedAdd, and CheckedSub so the pallet can paginate IDs safely.

Key Items

Associated Type Purpose Typical Choice
EntityId Primary key for tracks/samples u128, H256, or BoundedVec<u8, 32>
AuthorId Maps to on‑chain account or off‑chain artist ID AccountId or u64
AuthorityId Verifying organization AccountId or u32
MaxEntitiesPerAuthor Spam‑prevention limit 1000–10000

Runtime Integration

Add the pallet to your runtime’s construct_runtime! macro:

impl ip_onchain::Config for Runtime {
    type RuntimeEvent = RuntimeEvent;

    type EntityId  = u128;
    type AuthorId  = AccountId;
    type AuthorityId = AccountId;

    type MaxEntitiesPerAuthor = ConstU32<1_000>;
    type WeightInfo = ip_onchain::weights::SubstrateWeight<Runtime>;
}

construct_runtime!(
    ...
    IpOnchain: ip_onchain,
    ...
);

Genesis Configuration (Optional)

Pre‑seed the chain with authors & entities:

use ip_onchain::{AuthorGenesis, EntityGenesis};

GenesisConfig {
    ip_onchain: Some(ip_onchain::GenesisConfig {
        authors: vec![
            AuthorGenesis { id: 1, owner: alice_account() },
        ],
        entities: vec![
            EntityGenesis {
                id: 42,
                author: 1,
                uri: *b"ipfs://Qm…",
                hash: H256::random(),
            },
        ],
    }),
    ..Default::default()
}

Omit the ip_onchain field if no bootstrap data is desired.


Storage Summary

Storage Item Key Value Purpose
Entity<T> EntityId EntityDetails Metadata for each track/sample
Author<T> AuthorId AuthorDetails Registered artist info
Authority<T> AuthorityId AuthorityDetails Verification entity
AuthorEntityCount AuthorId u32 Number of entities an author owns

Further Reading