Skip to content

Commit

Permalink
auction workshop new expressive script
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Chen committed Oct 10, 2023
1 parent d9b411c commit 80ac6ac
Showing 1 changed file with 77 additions and 33 deletions.
110 changes: 77 additions & 33 deletions auction/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,31 @@ then
exit
fi

echo "
We will be playing the role of these three parties:
# The private key and address of the first bidder.
# Swap these into program.json, when running transactions as the first bidder.
# Swap these into .env, when running transactions as the first bidder.
# "private_key": "APrivateKey1zkpG9Af9z5Ha4ejVyMCqVFXRKknSm8L1ELEwcc4htk9YhVK"
# "address": aleo1yzlta2q5h8t0fqe0v6dyh9mtv4aggd53fgzr068jvplqhvqsnvzq7pj2ke
# The private key and address of the second bidder.
# Swap these into program.json, when running transactions as the second bidder.
# Swap these into .env, when running transactions as the second bidder.
# "private_key": "APrivateKey1zkpAFshdsj2EqQzXh5zHceDapFWVCwR6wMCJFfkLYRKupug"
# "address": aleo1esqchvevwn7n5p84e735w4dtwt2hdtu4dpguwgwy94tsxm2p7qpqmlrta4
# The private key and address of the auctioneer.
# Swap these into program.json, when running transactions as the auctioneer.
# Swap these into .env, when running transactions as the auctioneer.
# "private_key": "APrivateKey1zkp5wvamYgK3WCAdpBQxZqQX8XnuN2u11Y6QprZTriVwZVc",
# "address": "aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh"

"

echo "
Let's start an auction!
###############################################################################
######## ########
######## STEP 0: Initialize a new 2-party auction ########
######## Initialize a new 2-party auction ########
######## ########
######## ------------------------------- ########
######## | OPEN | A | B | ########
Expand All @@ -35,17 +40,26 @@ echo "
######## ########
###############################################################################
"
# Swap in the private key and address of the first bidder to .env.

echo "
Let's take the role of bidder 1 - 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 bidder 1's public address and the amount that is being bid.
leo run place_bid aleo1yzlta2q5h8t0fqe0v6dyh9mtv4aggd53fgzr068jvplqhvqsnvzq7pj2ke 10u64 || exit
"

echo "
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkpG9Af9z5Ha4ejVyMCqVFXRKknSm8L1ELEwcc4htk9YhVK
" > .env

# Have the first bidder place a bid of 10.
leo run place_bid aleo1yzlta2q5h8t0fqe0v6dyh9mtv4aggd53fgzr068jvplqhvqsnvzq7pj2ke 10u64 || exit

echo "
###############################################################################
######## ########
######## STEP 1: The first bidder places a bid of 10 ########
######## The first bidder places a bid of 10 ########
######## ########
######## ------------------------------- ########
######## | OPEN | A | B | ########
Expand All @@ -55,19 +69,24 @@ echo "
######## ########
###############################################################################
"
leo run place_bid aleo1yzlta2q5h8t0fqe0v6dyh9mtv4aggd53fgzr068jvplqhvqsnvzq7pj2ke 10u64 || exit

# Swap in the private key and address of the second bidder to .env.
echo "
Now we're going to place another bid as bidder 2, so let's switch our keys to bidder 2 and run the same transition function, this time with bidder 2's keys, public address, and different amount.
leo run place_bid aleo1esqchvevwn7n5p84e735w4dtwt2hdtu4dpguwgwy94tsxm2p7qpqmlrta4 90u64 || exit
"

echo "
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkpAFshdsj2EqQzXh5zHceDapFWVCwR6wMCJFfkLYRKupug
" > .env

# Have the second bidder place a bid of 90.
leo run place_bid aleo1esqchvevwn7n5p84e735w4dtwt2hdtu4dpguwgwy94tsxm2p7qpqmlrta4 90u64 || exit

echo "
###############################################################################
######## ########
######## STEP 2: The second bidder places a bid of 90 ########
######## The second bidder places a bid of 90 ########
######## ########
######## ------------------------------- ########
######## | OPEN | A | B | ########
Expand All @@ -77,28 +96,30 @@ echo "
######## ########
###############################################################################
"
leo run place_bid aleo1esqchvevwn7n5p84e735w4dtwt2hdtu4dpguwgwy94tsxm2p7qpqmlrta4 90u64 || exit

# Swap in the private key and address of the auctioneer to .env.
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.
leo run resolve '{
owner: aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh.private,
bidder: aleo1yzlta2q5h8t0fqe0v6dyh9mtv4aggd53fgzr068jvplqhvqsnvzq7pj2ke.private,
amount: 10u64.private,
is_winner: false.private,
_nonce: 4668394794828730542675887906815309351994017139223602571716627453741502624516group.public
}" "{
owner: aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh.private,
bidder: aleo1esqchvevwn7n5p84e735w4dtwt2hdtu4dpguwgwy94tsxm2p7qpqmlrta4.private,
amount: 90u64.private,
is_winner: false.private,
_nonce: 5952811863753971450641238938606857357746712138665944763541786901326522216736group.public
}' || exit
"

echo "
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkp5wvamYgK3WCAdpBQxZqQX8XnuN2u11Y6QprZTriVwZVc
" > .env

# Have the auctioneer select the winning bid.
echo "
###############################################################################
######## ########
######## STEP 3: The auctioneer selects the winning bidder ########
######## ########
######## ------------------------------- ########
######## | OPEN | A | β†’ B ← | ########
######## ------------------------------- ########
######## | Bid | 10 | β†’ 90 ← | ########
######## ------------------------------- ########
######## ########
###############################################################################
"
leo run resolve "{
owner: aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh.private,
bidder: aleo1yzlta2q5h8t0fqe0v6dyh9mtv4aggd53fgzr068jvplqhvqsnvzq7pj2ke.private,
Expand All @@ -113,20 +134,32 @@ leo run resolve "{
_nonce: 5952811863753971450641238938606857357746712138665944763541786901326522216736group.public
}" || exit

# Have the auctioneer finish the auction.
echo "
###############################################################################
######## ########
######## STEP 3: The auctioneer completes the auction. ########
######## The auctioneer determines the winning bidder ########
######## ########
######## ------------------------------- ########
######## | CLOSE | A | β†’ B ← | ########
######## | 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.
leo run finish '{
owner: aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh.private,
bidder: aleo1esqchvevwn7n5p84e735w4dtwt2hdtu4dpguwgwy94tsxm2p7qpqmlrta4.private,
amount: 90u64.private,
is_winner: false.private,
_nonce: 5952811863753971450641238938606857357746712138665944763541786901326522216736group.public
}' || exit
"

leo run finish "{
owner: aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh.private,
bidder: aleo1esqchvevwn7n5p84e735w4dtwt2hdtu4dpguwgwy94tsxm2p7qpqmlrta4.private,
Expand All @@ -135,8 +168,19 @@ leo run finish "{
_nonce: 5952811863753971450641238938606857357746712138665944763541786901326522216736group.public
}" || exit



echo "
###############################################################################
######## ########
######## The auctioneer completes the auction. ########
######## ########
######## ------------------------------- ########
######## | CLOSE | A | β†’ B ← | ########
######## ------------------------------- ########
######## | Bid | 10 | β†’ 90 ← | ########
######## ------------------------------- ########
######## ########
###############################################################################
"



0 comments on commit 80ac6ac

Please sign in to comment.