Skip to content

Commit dd4b7cb

Browse files
authored
Update simple_nft.move
1 parent 64abe5f commit dd4b7cb

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

simplenft/sources/simple_nft.move

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
module SimpleNFT::nft {
2-
use 0x1::signer;
3-
use 0x1::vector;
4-
use 0x1::string;
2+
use std::signer;
3+
use std::vector;
4+
use std::string;
55

6-
/// Примитивный NFT (без рыночной логики)
7-
struct NFT has store { id: u64, name: string::String, owner: address }
8-
9-
struct Registry has store { next_id: u64, items: vector<NFT> }
6+
/// Minimal NFT (educational)
7+
struct NFT has store {
8+
id: u64,
9+
name: string::String,
10+
owner: address,
11+
}
12+
13+
struct Registry has store {
14+
next_id: u64,
15+
items: vector<NFT>,
16+
}
1017

1118
public fun new_registry(_admin: &signer): Registry {
1219
Registry { next_id: 0, items: vector::empty<NFT>() }
@@ -20,7 +27,6 @@ use 0x1::string;
2027
}
2128

2229
public fun transfer(_caller: &signer, r: &mut Registry, id: u64, to: address) {
23-
let len = vector::length(&r.items);
2430
let i = find_index(&r.items, id);
2531
let mut nft = vector::borrow_mut(&mut r.items, i);
2632
nft.owner = to;
@@ -33,13 +39,12 @@ use 0x1::string;
3339
}
3440

3541
fun find_index(items: &vector<NFT>, id: u64): u64 {
36-
let i = 0;
42+
let mut i = 0;
3743
while (i < vector::length(items)) {
3844
let nft_ref = vector::borrow(items, i);
3945
if (nft_ref.id == id) return i;
4046
i = i + 1;
4147
};
42-
// если не нашли — для учебного проекта просто вернём 0
4348
0
4449
}
4550
}

0 commit comments

Comments
 (0)