In this article, we’ll analyze an example of how a Leo auction works.
Let’s clarify the nuances of this auction right away, because the Leo language works in the private Aleo blockchain, where as much data as possible is protected by encryption:
- Bidders will not learn any information about the size of other bids.
That is, this auction does not involve the disclosure of information about the bids made, so all bidders bid “blind”. This is only possible thanks to Zero Knowledge proofs, but we can still remove this feature if we wish, so that all bidders see each other’s bids. In public blockchains, however, it would not be possible to hide bets.
Let’s move on to the code:
- owner: The address of the account that owns the record associated with this bid. This is separate from the address of the account that placed the bid.
- gates: The value associated with the record (always zero).
- bidder: The address of the account that placed the bid.
- amount: The amount of the bid.
- is_winner: Whether the bid is the winning bid.
Now let’s describe the “make bid” function. It changes the record Bid, and the bet is not yet a winning bet:
Next, let’s decide who the winner of the auction is:
Here it’s simple, we choose the highest bid and return the winning record Bid.
Next, we finish the auction:
We change the value of is_winner
, thus later we can find the owner of the winning bid and give him the prize.
Don’t forget about “inputs” file:
In [finish] we enter the value is_winner = false
, because only after the execution of the program will it change to true
.
Original version: https://medium.com/@kaylej/312d0cc2f543