/ auction / run.sh
run.sh
  1  #!/bin/bash
  2  # First check that Leo is installed.
  3  if ! command -v leo &> /dev/null
  4  then
  5      echo "leo is not installed."
  6      exit
  7  fi
  8  
  9  # The private key and address of the first bidder.
 10  # Swap these into .env, when running transactions as the first bidder.
 11  # NETWORK=testnet
 12  # PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH
 13  
 14  # The private key and address of the second bidder.
 15  # Swap these into .env, when running transactions as the second bidder.
 16  # NETWORK=testnet
 17  # PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh
 18  
 19  
 20  # The private key and address of the auctioneer.
 21  # Swap these into .env, when running transactions as the auctioneer.
 22  # NETWORK=testnet
 23  # PRIVATE_KEY=APrivateKey1zkp2GUmKbVsuc1NSj28pa1WTQuZaK5f1DQJAT6vPcHyWokG
 24  
 25  
 26  echo "
 27  ###############################################################################
 28  ########                                                               ########
 29  ########            STEP 0: Initialize a new 2-party auction           ########
 30  ########                                                               ########
 31  ########                -------------------------------                ########
 32  ########                |  OPEN   |    A    |    B    |                ########
 33  ########                -------------------------------                ########
 34  ########                |   Bid   |         |         |                ########
 35  ########                -------------------------------                ########
 36  ########                                                               ########
 37  ###############################################################################
 38  "
 39  # Swap in the private key and address of the first bidder to .env.
 40  echo "NETWORK=testnet
 41  PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH
 42  ENDPOINT=http://localhost:3030
 43  " > .env
 44  
 45  # Have the first bidder place a bid of 10.
 46  echo "
 47  ###############################################################################
 48  ########                                                               ########
 49  ########          STEP 1: The first bidder places a bid of 10          ########
 50  ########                                                               ########
 51  ########                -------------------------------                ########
 52  ########                |  OPEN   |    A    |    B    |                ########
 53  ########                -------------------------------                ########
 54  ########                |   Bid   |   10    |         |                ########
 55  ########                -------------------------------                ########
 56  ########                                                               ########
 57  ###############################################################################
 58  "
 59  leo run place_bid aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px 10u64 || exit
 60  
 61  # Swap in the private key and address of the second bidder to .env.
 62  echo "NETWORK=testnet
 63  PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh
 64  ENDPOINT=http://localhost:3030
 65  " > .env
 66  
 67  # Have the second bidder place a bid of 90.
 68  echo "
 69  ###############################################################################
 70  ########                                                               ########
 71  ########         STEP 2: The second bidder places a bid of 90          ########
 72  ########                                                               ########
 73  ########                -------------------------------                ########
 74  ########                |  OPEN   |    A    |    B    |                ########
 75  ########                -------------------------------                ########
 76  ########                |   Bid   |   10    |   90    |                ########
 77  ########                -------------------------------                ########
 78  ########                                                               ########
 79  ###############################################################################
 80  "
 81  leo run place_bid aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t 90u64 || exit
 82  
 83  # Swap in the private key and address of the auctioneer to .env.
 84  echo "NETWORK=testnet
 85  PRIVATE_KEY=APrivateKey1zkp2GUmKbVsuc1NSj28pa1WTQuZaK5f1DQJAT6vPcHyWokG
 86  ENDPOINT=http://localhost:3030
 87  " > .env
 88  
 89  # Have the auctioneer select the winning bid.
 90  echo "
 91  ###############################################################################
 92  ########                                                               ########
 93  ########       STEP 3: The auctioneer selects the winning bidder       ########
 94  ########                                                               ########
 95  ########                -------------------------------                ########
 96  ########                |  OPEN   |    A    |  → B ←  |                ########
 97  ########                -------------------------------                ########
 98  ########                |   Bid   |   10    |  → 90 ← |                ########
 99  ########                -------------------------------                ########
100  ########                                                               ########
101  ###############################################################################
102  "
103  leo run resolve "{
104          owner: aleo1ashyu96tjwe63u0gtnnv8z5lhapdu4l5pjsl2kha7fv7hvz2eqxs5dz0rg.private,
105          bidder: aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px.private,
106          amount: 10u64.private,
107          is_winner: false.private,
108          _nonce: 4668394794828730542675887906815309351994017139223602571716627453741502624516group.public
109      }" "{
110          owner: aleo1ashyu96tjwe63u0gtnnv8z5lhapdu4l5pjsl2kha7fv7hvz2eqxs5dz0rg.private,
111          bidder: aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t.private,
112          amount: 90u64.private,
113          is_winner: false.private,
114          _nonce: 5952811863753971450641238938606857357746712138665944763541786901326522216736group.public
115      }" || exit
116  
117  # Have the auctioneer finish the auction.
118  echo "
119  ###############################################################################
120  ########                                                               ########
121  ########         STEP 4: The auctioneer completes the auction.         ########
122  ########                                                               ########
123  ########                -------------------------------                ########
124  ########                |  CLOSE  |    A    |  → B ←  |                ########
125  ########                -------------------------------                ########
126  ########                |   Bid   |   10    |  → 90 ← |                ########
127  ########                -------------------------------                ########
128  ########                                                               ########
129  ###############################################################################
130  "
131  leo run finish "{
132          owner: aleo1ashyu96tjwe63u0gtnnv8z5lhapdu4l5pjsl2kha7fv7hvz2eqxs5dz0rg.private,
133          bidder: aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t.private,
134          amount: 90u64.private,
135          is_winner: false.private,
136          _nonce: 5952811863753971450641238938606857357746712138665944763541786901326522216736group.public
137      }" || exit
138  
139  
140  # Restore the .env file to its original state.
141  echo "NETWORK=testnet
142  PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH
143  ENDPOINT=http://localhost:3030
144  " > .env
145  
146  
147  
148  
149  
150