Move语言社区

【Move进阶】NFT协议V3

address 0x2 {
module NFTExample3 {
    use 0x1::Signer;
    use 0x1::Vector;

    struct NFT<T: store> has key, store { name: T }

    struct UniqIdList<T: store> has key, store {
        data: vector<T>
    }

    public fun initialize<T: store>(account: &signer) {
        move_to(account, UniqIdList {data: Vector::empty<T>()});
    }

    public fun new<T: store + copy>(account: &signer, name: T): NFT<T> acquires UniqIdList {
        let account_address = Signer::address_of(account);
        let exist = Vector::contains<T>(&borrow_global<UniqIdList<T>>(account_address).data, &name);
        assert(!exist, 1);
        let id_list = borrow_global_mut<UniqIdList<T>>(account_address);
        Vector::push_back<T>(&mut id_list.data, copy name);
        NFT { name }
    }
}
}