Move语言社区

【Move进阶】NFT协议V1

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

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

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

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

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