-
Notifications
You must be signed in to change notification settings - Fork 265
/
run.sh
executable file
Β·202 lines (173 loc) Β· 9.69 KB
/
run.sh
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/bash
# First check that Leo is installed.
if ! command -v leo &> /dev/null
then
echo "leo is not installed."
exit
fi
echo "
We will be playing the role of three parties.
The private key and address of the first bidder.
private_key: APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH
address: aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px
The private key and address of the second bidder.
private_key: APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh
address: aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t
The private key and address of the auctioneer.
private_key: APrivateKey1zkp2GUmKbVsuc1NSj28pa1WTQuZaK5f1DQJAT6vPcHyWokG
address: aleo1ashyu96tjwe63u0gtnnv8z5lhapdu4l5pjsl2kha7fv7hvz2eqxs5dz0rg
"
echo "
Let's start an auction!
###############################################################################
######## ########
######## Step 0: Initialize a new 2-party auction ########
######## ########
######## ------------------------------- ########
######## | OPEN | A | B | ########
######## ------------------------------- ########
######## | Bid | | | ########
######## ------------------------------- ########
######## ########
###############################################################################
"
echo "
Let's take the role of the first bidder - we'll swap in the private key and address of the first bidder to .env.
We're going to run the transition function "place_bid", slotting in the first bidder's public address and the amount that is being bid. The inputs are the user's public address and the amount being bid.
echo '
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH
' > .env
leo run place_bid aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px 10u64
"
# Swap in the private key of the first bidder to .env.
echo "
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH
" > .env
# Have the first bidder place a bid of 10.
leo run place_bid aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px 10u64
echo "
###############################################################################
######## ########
######## Step 1: The first bidder places a bid of 10 ########
######## ########
######## ------------------------------- ########
######## | OPEN | A | B | ########
######## ------------------------------- ########
######## | Bid | 10 | | ########
######## ------------------------------- ########
######## ########
###############################################################################
"
echo "
Now we're going to place another bid as the second bidder, so let's switch our keys to the second bidder and run the same transition function, this time with the second bidder's keys, public address, and different amount.
echo '
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh
' > .env
leo run place_bid aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t 90u64
"
# Swap in the private key of the second bidder to .env.
echo "
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh
" > .env
# Have the second bidder place a bid of 90.
leo run place_bid aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t 90u64
echo "
###############################################################################
######## ########
######## Step 2: The second bidder places a bid of 90 ########
######## ########
######## ------------------------------- ########
######## | OPEN | A | B | ########
######## ------------------------------- ########
######## | Bid | 10 | 90 | ########
######## ------------------------------- ########
######## ########
###############################################################################
"
echo "
Now, let's take the role of the auctioneer, so we can determine which bid wins. Let's swap our keys to the auctioneer and run the resolve command on the output of the two bids from before. The resolve command takes the two output records from the bids as inputs and compares them to determine which bid wins.
echo '
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkp2GUmKbVsuc1NSj28pa1WTQuZaK5f1DQJAT6vPcHyWokG
' > .env
leo run resolve '{
owner: aleo1ashyu96tjwe63u0gtnnv8z5lhapdu4l5pjsl2kha7fv7hvz2eqxs5dz0rg.private,
bidder: aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px.private,
amount: 10u64.private,
is_winner: false.private,
_nonce: 4668394794828730542675887906815309351994017139223602571716627453741502624516group.public
}' '{
owner: aleo1ashyu96tjwe63u0gtnnv8z5lhapdu4l5pjsl2kha7fv7hvz2eqxs5dz0rg.private,
bidder: aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t.private,
amount: 90u64.private,
is_winner: false.private,
_nonce: 5952811863753971450641238938606857357746712138665944763541786901326522216736group.public
}'
"
# Swaps in the private key of the auctioneer to .env.
echo "
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkp2GUmKbVsuc1NSj28pa1WTQuZaK5f1DQJAT6vPcHyWokG
" > .env
# Have the auctioneer select the winning bid.
leo run resolve "{
owner: aleo1ashyu96tjwe63u0gtnnv8z5lhapdu4l5pjsl2kha7fv7hvz2eqxs5dz0rg.private,
bidder: aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px.private,
amount: 10u64.private,
is_winner: false.private,
_nonce: 4668394794828730542675887906815309351994017139223602571716627453741502624516group.public
}" "{
owner: aleo1ashyu96tjwe63u0gtnnv8z5lhapdu4l5pjsl2kha7fv7hvz2eqxs5dz0rg.private,
bidder: aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t.private,
amount: 90u64.private,
is_winner: false.private,
_nonce: 5952811863753971450641238938606857357746712138665944763541786901326522216736group.public
}"
echo "
###############################################################################
######## ########
######## Step 3: The auctioneer determines the winning bidder ########
######## ########
######## ------------------------------- ########
######## | OPEN | A | β B β | ########
######## ------------------------------- ########
######## | Bid | 10 | β 90 β | ########
######## ------------------------------- ########
######## ########
###############################################################################
"
echo "
Keeping the key environment the same since we're still the auctioneer, let's finalize the auction and label the winning output as the winner. The finish transition takes the winning output bid as the input and marks it as such.
leo run finish '{
owner: aleo1ashyu96tjwe63u0gtnnv8z5lhapdu4l5pjsl2kha7fv7hvz2eqxs5dz0rg.private,
bidder: aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t.private,
amount: 90u64.private,
is_winner: false.private,
_nonce: 5952811863753971450641238938606857357746712138665944763541786901326522216736group.public
}'
"
# Have the auctioneer finish the auction.
leo run finish "{
owner: aleo1ashyu96tjwe63u0gtnnv8z5lhapdu4l5pjsl2kha7fv7hvz2eqxs5dz0rg.private,
bidder: aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t.private,
amount: 90u64.private,
is_winner: false.private,
_nonce: 5952811863753971450641238938606857357746712138665944763541786901326522216736group.public
}"
echo "
###############################################################################
######## ########
######## The auctioneer completes the auction. ########
######## ########
######## ------------------------------- ########
######## | CLOSE | A | β B β | ########
######## ------------------------------- ########
######## | Bid | 10 | β 90 β | ########
######## ------------------------------- ########
######## ########
###############################################################################
"