1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
pub mod erc721_base;
pub mod extensions;
pub mod owned_erc721_with_metadata;

use odra::types::{Address, Bytes, U256};

/// The ERC-721 interface as defined in the standard.
pub trait Erc721 {
    fn balance_of(&self, owner: Address) -> U256;
    fn owner_of(&self, token_id: U256) -> Address;
    fn safe_transfer_from(&mut self, from: Address, to: Address, token_id: U256);
    fn safe_transfer_from_with_data(
        &mut self,
        from: Address,
        to: Address,
        token_id: U256,
        data: Bytes
    );
    fn transfer_from(&mut self, from: Address, to: Address, token_id: U256);
    fn approve(&mut self, approved: Option<Address>, token_id: U256);
    fn set_approval_for_all(&mut self, operator: Address, approved: bool);
    fn get_approved(&self, token_id: U256) -> Option<Address>;
    fn is_approved_for_all(&self, owner: Address, operator: Address) -> bool;
}

pub mod events {
    use odra::types::{Address, U256};

    #[derive(odra::Event)]
    pub struct Transfer {
        pub from: Option<Address>,
        pub to: Option<Address>,
        pub token_id: U256
    }

    #[derive(odra::Event)]
    pub struct Approval {
        pub owner: Address,
        pub approved: Option<Address>,
        pub token_id: U256
    }

    #[derive(odra::Event)]
    pub struct ApprovalForAll {
        pub owner: Address,
        pub operator: Address,
        pub approved: bool
    }
}

pub mod errors {
    use odra::execution_error;

    execution_error! {
        pub enum Error {
            InvalidTokenId => 30_000,
            NotAnOwnerOrApproved => 30_001,
            ApprovalToCurrentOwner => 30_002,
            ApproveToCaller => 30_003,
            NoSuchMethod => 30_004,
            TransferFailed => 30_005,
            StorageError => 30_501,
        }
    }
}