2qtzw-4iaaa-aaaai-qjdtq-cai.icp0.io Open in urlscan Pro
216.52.51.137  Public Scan

URL: https://2qtzw-4iaaa-aaaai-qjdtq-cai.icp0.io/docs/motoko/nft/history/index.html
Submission: On November 03 via api from US — Scanned from CA

Form analysis 0 forms found in the DOM

Text Content

Skip to main content

Anvil ProtocolIntroMotokoJsReactCli
GitHub

 * Intro
 * Web mint
 * SDK
 * Motoko
   * Aaa
   * Account
   * Cluster
   * History
   * Ledger
   * Nft
     * 🔶 Interface
     * AccountIdentifier
     * APrincipal
     * Config
     * Content
     * History
     * Memo
     * Metadata
     * Pricing
     * SubAccount
     * TokenIdentifier
     * TokenIndex
     * User
   * Pwr
   * Router

 * 🏠
 * Motoko
 * Nft
 * History


HISTORY

Github: packages/nftanvil_canisters/mo/type/nft_interface.mo

import Nft "mo:anvil/type/nft_interface"


module {
...


    public type TransactionId = Blob;
    public type EventIndex = Nat32;

    public module TransactionId = { 
        public func encode(history_slot: CanisterSlot, idx: EventIndex) : TransactionId { 
                let raw = Array.flatten<Nat8>([
                    Blob_.nat64ToBytes(history_slot),
                    Binary.BigEndian.fromNat32(idx),
                ]);
                
                Blob.fromArray(raw)
        };

        public func decode(tx: TransactionId) : {history_slot: CanisterSlot; idx: EventIndex} { 
                let (slotArr, idxArr) = Array_.split<Nat8>(Blob.toArray(tx), 8);
                {
                    history_slot = Blob_.bytesToNat64(slotArr);
                    idx = Blob_.bytesToNat32(idxArr);
                }
        };
    };
  

    public type Timestamp = Time.Time;

    public module EventIndex = {
        public func equal (a:EventIndex, b:EventIndex): Bool {
            a == b
        };
        public func hash (a:EventIndex) : Hash.Hash {
            return a;
        };
    };

    public type Event = {
        info : EventInfo;
        hash : Blob; // accumulated by hash previous hash and current event hash
    };

    public type Transaction = Event;

    public module EventInfo = {
        public func hash( e: EventInfo) : [Nat8] {
             switch(e) {
                case (#nft(x)) NftEvent.hash(x);
                case (#pwr(x)) PwrEvent.hash(x);
                case (#anv(x)) AnvEvent.hash(x);
                case (#treasury(x)) [];
            };
        }
    };

    public type EventInfo = {
        #nft : NftEvent;
        #pwr : PwrEvent;
        #anv : AnvEvent;
    };

    public type AnvEvent = {
        #transfer : EventFungibleTransaction;
        // vote
    };

    public type PwrEvent = {
        #transfer : EventFungibleTransaction;
        #withdraw : PwrWithdraw;
        #mint : EventFungibleMint;
    };

    public type NftEvent = {
  
        #transfer : {
            created: Timestamp;
            from: AccountIdentifier;
            to: AccountIdentifier;
            token: TokenIdentifier;
            memo: Memo;
        };

        #burn : {
            created: Timestamp;
            user: AccountIdentifier;
            token: TokenIdentifier;
            memo: Memo;
        };

        #use : {
            created: Timestamp;
            user: AccountIdentifier;
            token: TokenIdentifier;
            use: ItemUse;
            memo: Memo;
        };

        #price : {
            created: Timestamp;
            user: AccountIdentifier;
            token: TokenIdentifier;
            price: Price;
        };

        #purchase : NFTPurchase;

        #mint : {
            created: Timestamp;
            token: TokenIdentifier;
            user: AccountIdentifier;
            pwr: Balance;
        };

        #approve : {
            created: Timestamp;
            token: TokenIdentifier;
            user: AccountIdentifier;
            spender: Principal;
        };

        #socket : {
            created: Timestamp;
            user: AccountIdentifier;
            socket : TokenIdentifier;
            plug   : TokenIdentifier;
            memo: Memo;
        };

        #unsocket : {
            created: Timestamp;
            user: AccountIdentifier;
            socket : TokenIdentifier;
            plug   : TokenIdentifier;
            memo: Memo;
        };
    };


    public module AnvEvent = {
        public func hash(e : AnvEvent) : [Nat8] {
             switch (e) {
                case (#transfer({created;from;to;amount;memo})) {
                    Array.flatten<Nat8>([
                        [1:Nat8],
                        Blob_.intToBytes(created),
                        Blob.toArray(from),
                        Blob.toArray(to),
                        Blob_.nat64ToBytes(amount),
                        Blob.toArray(memo)
                    ])
                };
             }
        }
    };

    public module PwrEvent = {
        public func hash(e : PwrEvent) : [Nat8] {
             switch (e) {
                case (#transfer({from;to;amount;memo;created})) {
                    Array.flatten<Nat8>([
                        [2:Nat8],
                        Blob_.intToBytes(created),
                        Blob.toArray(from),
                        Blob.toArray(to),
                        Blob_.nat64ToBytes(amount),
                        Blob.toArray(memo)
                    ])
                };
                case (#withdraw({from;to;amount;created})) {
                    Array.flatten<Nat8>([
                        [2:Nat8],
                        Blob_.intToBytes(created),
                        Blob.toArray(from),
                        Blob.toArray(to),
                        Blob_.nat64ToBytes(amount)
                    ])
                };
                case (#mint({created;user;amount})) {
                    Array.flatten<Nat8>([
                        [3:Nat8],
                        Blob_.intToBytes(created),
                        Blob.toArray(user),
                        Blob_.nat64ToBytes(amount),
                    ])
                };
             }
        }
    };

    public module NftEvent = {
        public func hash(e : NftEvent) : [Nat8] {
            switch (e) {
                case (#transfer({created;from;to;token;memo})) {
                    Array.flatten<Nat8>([
                        [3:Nat8],
                        Blob_.intToBytes(created),
                        Blob.toArray(from),
                        Blob.toArray(to),
                        Blob_.nat64ToBytes(token),
                        Blob.toArray(memo)
                    ])
                };
                case (#burn({created;user;token;memo})) {
                    Array.flatten<Nat8>([
                        [4:Nat8],
                        Blob_.intToBytes(created),
                        Blob.toArray(user),
                        Blob_.nat64ToBytes(token),
                        Blob.toArray(memo)
                    ])
                };
                case (#use({created;user;token;use;memo})) { 
                    Array.flatten<Nat8>([
                        [5:Nat8],
                        Blob_.intToBytes(created),
                        Blob.toArray(user),
                        Blob_.nat64ToBytes(token),
                        ItemUse.hash(use),
                        Blob.toArray(memo)
                    ])
                };
                case (#price({created;user;token;price})) {
                    Array.flatten<Nat8>([
                        [5:Nat8],
                        Blob_.intToBytes(created),
                        Blob.toArray(user),
                        Blob_.nat64ToBytes(token),
                        Price.hash(price)
                    ])
                };
                case (#mint({created;token;pwr;user})) {  
                    Array.flatten<Nat8>([
                        [6:Nat8],
                        Blob_.intToBytes(created),
                        Blob_.nat64ToBytes(token),
                        Blob_.nat64ToBytes(pwr),
                        Blob.toArray(user),
                    ])
                };
                case (#socket({created;socket; plug; memo; user})) {
                    Array.flatten<Nat8>([
                        [7:Nat8],
                        Blob_.intToBytes(created),
                        Blob_.nat64ToBytes(socket),
                        Blob_.nat64ToBytes(plug),
                        Blob.toArray(memo),
                        Blob.toArray(user)
                    ])
                };
                case (#unsocket({created;socket; plug; memo; user})) {
                    Array.flatten<Nat8>([
                        [8:Nat8],
                        Blob_.intToBytes(created),
                        Blob_.nat64ToBytes(socket),
                        Blob_.nat64ToBytes(plug),
                        Blob.toArray(memo),
                        Blob.toArray(user)
                    ])
                };
                case (#purchase(a)) {
                    // 9
                    NFTPurchase.hash(a)
                };
                case (#approve({created;spender;user;token})) {
                    Array.flatten<Nat8>([
                        [10:Nat8],
                        Blob_.intToBytes(created),
                        Blob.toArray(user),
                        Blob.toArray(Principal.toBlob(spender)),
                        Blob_.nat64ToBytes(token)
                    ])
                };
            
            };
                
        };

    };


    public module NFTPurchase {
            public func hash (e : NFTPurchase) : [Nat8] {
                Array.flatten<Nat8>([
                            [9:Nat8],
                            Blob_.intToBytes(e.created),
                            Blob_.nat64ToBytes(e.amount),
                            Blob_.nat64ToBytes(e.token),
                            Blob.toArray(e.buyer),
                            Blob.toArray(e.seller),
                            Blob.toArray(e.author.address),
                            Blob_.nat16ToBytes(e.author.share),
                            switch(e.marketplace) { 
                                case (?a) Array.flatten<Nat8>([ 
                                    Blob.toArray(a.address),
                                    Blob_.nat16ToBytes(a.share)
                                ]);
                                case (null) []
                            },
                            switch(e.affiliate) { 
                                case (?a) Array.flatten<Nat8>([ 
                                    Blob.toArray(a.address),
                                    Blob_.nat64ToBytes(a.amount)
                                ]);
                                case (null) []
                            }
                        ])
            };
        };

    
    public type PwrWithdraw =  {
                    created: Timestamp;
                    from: AccountIdentifier;
                    to: AccountIdentifier;
                    amount: Balance;
                };


    public type EventFungibleMint =  {
                    created: Timestamp;
                    user: AccountIdentifier;
                    amount: Balance;
                };

    public type EventFungibleTransaction =  {
                    created: Timestamp;
                    from: AccountIdentifier;
                    to: AccountIdentifier;
                    amount: Balance;
                    memo: Memo;
                };

    public type Block = {
        events: [Event]
    };


    
...
}


Previous
Content
Next
Memo
Docs
 * Mint
 * Intro

Community
 * Discord
 * Twitter

More
 * Dashboard
 * History
 * GitHub

Copyright © 2022 VVV DAO