Skip to content

Commit 3875cc1

Browse files
authored
Update simple_nft.move
1 parent 08fde6e commit 3875cc1

1 file changed

Lines changed: 10 additions & 38 deletions

File tree

simplenft/sources/simple_nft.move

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,22 @@
11
module SimpleNFT::nft {
2-
use std::signer;
3-
use std::vector;
4-
use std::string;
5-
6-
/// Minimal NFT (educational)
2+
/// Minimal NFT without strings/vectors/signers
73
struct NFT has store {
84
id: u64,
9-
name: string::String,
105
owner: address,
116
}
127

13-
struct Registry has store {
14-
next_id: u64,
15-
items: vector<NFT>,
16-
}
17-
18-
public fun new_registry(_admin: &signer): Registry {
19-
Registry { next_id: 0, items: vector::empty<NFT>() }
20-
}
21-
22-
public fun mint(admin: &signer, r: &mut Registry, to: address, name: string::String) {
23-
let id = r.next_id;
24-
r.next_id = id + 1;
25-
let nft = NFT { id, name, owner: to };
26-
vector::push_back(&mut r.items, nft);
27-
}
28-
29-
public fun transfer(_caller: &signer, r: &mut Registry, id: u64, to: address) {
30-
let i = find_index(&r.items, id);
31-
let mut nft = vector::borrow_mut(&mut r.items, i);
32-
nft.owner = to;
8+
/// Mint an NFT to owner with id
9+
public fun mint(id: u64, owner: address): NFT {
10+
NFT { id, owner }
3311
}
3412

35-
public fun get_owner(r: &Registry, id: u64): address {
36-
let i = find_index(&r.items, id);
37-
let nft = vector::borrow(&r.items, i);
38-
nft.owner
13+
/// Transfer ownership
14+
public fun transfer(n: &mut NFT, to: address) {
15+
n.owner = to;
3916
}
4017

41-
fun find_index(items: &vector<NFT>, id: u64): u64 {
42-
let mut i = 0;
43-
while (i < vector::length(items)) {
44-
let nft_ref = vector::borrow(items, i);
45-
if (nft_ref.id == id) return i;
46-
i = i + 1;
47-
};
48-
0
18+
/// Read owner
19+
public fun owner_of(n: &NFT): address {
20+
n.owner
4921
}
5022
}

0 commit comments

Comments
 (0)