summaryrefslogtreecommitdiff
path: root/graphs/cpp/my_nfts/auction.hh
blob: 9a1d1626e8052533e4344bb7295d806f9230ccc5 (plain)
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
#pragma once

#include "nft.hh"
#include "person.hh"

// Smart contract to auction a NFT.
// It is a RAII class.
class Auction
{
public:
    // Start the auction with the given (non-null) NFT.
    Auction(Person& organizer, NFT nft, uint initial_bid);
    // Close the auction.
    ~Auction();

    // https://en.cppreference.com/w/cpp/language/rule_of_three#Rule_of_five
    Auction(const Auction&&) = delete;
    Auction(const Auction&) = delete;
    Auction& operator=(const Auction&&) = delete;
    Auction& operator=(const Auction&) = delete;

    // Allow a person to bid at the auction.
    bool bid(Person& person, uint money);

    // Getters for the nft name and highest bid.
    const std::string& get_nft_name() const;
    uint get_highest_bid() const;

private:
    Person& organizer_;
    NFT nft_;
    Person* highest_bidder_;
    uint highest_bid_;
};