Skip to content

Commit

Permalink
pizzeria improvements (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjwalters authored Jun 1, 2020
1 parent 45e027c commit c6af327
Show file tree
Hide file tree
Showing 18 changed files with 318 additions and 146 deletions.
7 changes: 7 additions & 0 deletions mobilecoind/clients/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@
To send and receive transactions, you can use `mobilecoind`'s wallet bindings.

See the jupyter notebook at [Wallet.ipynb](./Wallet.ipynb) for a walk through of an example Python wallet client.


## Running the Blockchain Explorer

The `blockchain_explorer` directory contains a simple webserver for the blockchain content that mobilecoind downloads.

Run the included `start_webserver.sh` script to launch the server at http://localhost:5000
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Copyright (c) 2018-2020 MobileCoin Inc.

import argparse
import argparse, sys
from flask import Flask, render_template
from sys import getsizeof

sys.path.append('../mob_client')
from mob_client import mob_client
Expand Down Expand Up @@ -81,9 +80,7 @@ def index():

@app.route('/from/<block_num>')
def ledger(block_num):
num_blocks, num_transactions = client.get_ledger_info()
block_num = int(block_num)
return render_ledger_range(block_num, 100)
return render_ledger_range(int(block_num), 100)

@app.route('/block/<block_num>')
def block(block_num):
Expand All @@ -95,7 +92,7 @@ def block(block_num):
num_blocks=num_blocks)

block = client.get_block(block_num)
size_of_block = getsizeof(block)
size_of_block = sys.getsizeof(block)

for signature in block.signatures:
signature.src_url = signature.src_url.split('/')[-2]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
grpcio-tools==1.24.1
qrcode==6.1
halo==0.0.29
flask==1.1.2
36 changes: 36 additions & 0 deletions mobilecoind/clients/python/blockchain_explorer/start_webserver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

# setup mob_client
cd ../mob_client
pip3 install -r requirements.txt
./compile_proto.sh

cd ../blockchain_explorer

# install mobilecoind
if [ ! -d "./mobilecoin-testnet-linux" ]
then
echo "Installing mobilecoind binary."
curl -L https://github.com/mobilecoinofficial/mobilecoin/releases/latest/download/mobilecoin-testnet-linux.tar.gz --output latest.tar.gz
tar -zxvf ./latest.tar.gz
rm ./latest.tar.gz
fi

# kill old mobilecoind processes
ps -ef | grep mobilecoind | grep -v grep | awk '{print $2}' | xargs kill

# run mobilecoind
./mobilecoin-testnet-linux/bin/mobilecoind \
--ledger-db /tmp/ledger-db \
--poll-interval 10 \
--peer mc://node1.test.mobilecoin.com/ \
--peer mc://node2.test.mobilecoin.com/ \
--tx-source-url https://s3-us-west-1.amazonaws.com/mobilecoin.chain/node1.test.mobilecoin.com/ \
--tx-source-url https://s3-us-west-1.amazonaws.com/mobilecoin.chain/node2.test.mobilecoin.com/ \
--mobilecoind-db /tmp/transaction-db \
--service-port 4444 \
--watcher-db /tmp/watcher-db &

# run the blockchain explorer flask site
pip3 install -r requirements.txt
python3 ./blockchain_explorer.py
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<head>
<title>MobileCoin Blockchain Explorer</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/lofi.css') }}">
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
</head>
<body>
<div class="container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<head>
<title>MobileCoin Blockchain Explorer</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/lofi.css') }}">
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
</head>
<body>
<div class="container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<head>
<title>MobileCoin Blockchain Explorer</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/lofi.css') }}">
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
</head>
<body>
<div class="container">
Expand Down
3 changes: 0 additions & 3 deletions mobilecoind/clients/python/mob_client/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
grpcio-tools==1.24.1
qrcode==6.1
halo==0.0.29
flask==1.1.2
25 changes: 2 additions & 23 deletions mobilecoind/clients/python/pizzamob_leaderboard/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
### PizzaMOB Leaderboard

To run:
Run the included script (with your master key passed in as an argument) to launch the server at http://localhost:5000

1. Start mobilecoind
`start_webserver.sh ENTROPY`

```sh
RUST_BACKTRACE=full RUST_LOG=trace,mc_watcher=error,mc_ledger_sync=error,mc_connection=error,hyper=error,reqwest=error,mio=error,rustls=error,want=error \
SGX_MODE=HW IAS_MODE=PROD CONSENSUS_ENCLAVE_CSS=$(pwd)/consensus-enclave.css \
cargo run --release -p mc-mobilecoind -- \
--peer mc://node1.test.mobilecoin.com:443/ \
--peer mc://node2.test.mobilecoin.com:443/ \
--tx-source-url https://s3-us-west-1.amazonaws.com/mobilecoin.chain/node1.test.mobilecoin.com/ \
--tx-source-url https://s3-us-west-1.amazonaws.com/mobilecoin.chain/node2.test.mobilecoin.com/ \
--poll-interval 10 \
--mobilecoind-db /tmp/testnet-transaction-db \
--ledger-db /tmp/testnet-ledger-db \
--service-port 4444
```

1. Start the leaderboard, default host:port on `localhost:5000`

```sh
pip3 install -r requirements.txt
./compile_proto.sh
python3 pizzamob_leaderboard.py --entropy 1234567812345678123456781234567812345678123456781234567812345678
```
15 changes: 0 additions & 15 deletions mobilecoind/clients/python/pizzamob_leaderboard/compile_proto.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from flask import Flask, render_template, request
from tinydb import TinyDB, Query
from datetime import datetime

sys.path.append('../mob_client')
from mob_client import mob_client
Expand Down Expand Up @@ -73,22 +72,25 @@ def add_user():
monitor = get_or_add_monitor(subaddress)
request_code = get_request_code(monitor, subaddress)
balance = client.get_balance(monitor, subaddress)
timestamp = datetime.now().strftime('%Y%m%d')

if new_player:
players.insert({
'passphrase': player_data,
'subaddress': subaddress,
'code': request_code
})
else:
# update the request code
players.update({'code': request_code}, player.passphrase == player_data)

leaderboard = get_leaderboard()

response = {
"code": request_code[:79] + '\n' + request_code[79:],
"mob": balance / MOB,
"time": timestamp,
"leaderboard": render_leaderboard(leaderboard)
"code": request_code,
"balance": balance / MOB,
"leaderboard": leaderboard,
"goal": WINNING_AMOUNT / MOB,
"new": new_player,
}

return json.dumps(response)
Expand All @@ -112,7 +114,7 @@ def get_or_add_monitor(subaddress):

def get_request_code(monitor, subaddress):
public_address = client.get_public_address(monitor, subaddress)
return client.get_request_code(public_address, value=WINNING_AMOUNT, memo="PizzaMOB 2.0!")
return client.get_request_code(public_address)

def get_leaderboard():
player_table = db.table('Players')
Expand All @@ -121,16 +123,11 @@ def get_leaderboard():
for p in players:
monitor = get_or_add_monitor(p['subaddress'])
balance = client.get_balance(monitor, p['subaddress'])
res.append({'balance': balance, 'code': p['code'][:17]})
res.append({'balance': balance / MOB, 'code': p['code']})
res.sort(key=lambda player: player['balance'])
res.reverse()
return res

def render_leaderboard(leaderboard):
res = ""
for leader in leaderboard:
res += f"[{leader['balance'] / MOB}] {leader['code'][:17]}...\n"
return res

if __name__ == "__main__":
args = command_args()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
grpcio-tools==1.24.1
qrcode==6.1
halo==0.0.29
flask==1.1.2
tinydb==4.1.1
36 changes: 36 additions & 0 deletions mobilecoind/clients/python/pizzamob_leaderboard/start_webserver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

# setup mob_client
cd ../mob_client
pip3 install -r requirements.txt
./compile_proto.sh

cd ../pizzamob_leaderboard

# install mobilecoind
if [ ! -d "./mobilecoin-testnet-linux" ]
then
echo "Installing mobilecoind binary."
curl -L https://github.com/mobilecoinofficial/mobilecoin/releases/latest/download/mobilecoin-testnet-linux.tar.gz --output latest.tar.gz
tar -zxvf ./latest.tar.gz
rm ./latest.tar.gz
fi

# kill old mobilecoind processes
ps -ef | grep mobilecoind | grep -v grep | awk '{print $2}' | xargs kill

# run mobilecoind
./mobilecoin-testnet-linux/bin/mobilecoind \
--ledger-db /tmp/ledger-db \
--poll-interval 10 \
--peer mc://node1.test.mobilecoin.com/ \
--peer mc://node2.test.mobilecoin.com/ \
--tx-source-url https://s3-us-west-1.amazonaws.com/mobilecoin.chain/node1.test.mobilecoin.com/ \
--tx-source-url https://s3-us-west-1.amazonaws.com/mobilecoin.chain/node2.test.mobilecoin.com/ \
--mobilecoind-db /tmp/transaction-db \
--service-port 4444 \
--watcher-db /tmp/watcher-db &

# run the pizzamob_leaderboard flask site
pip3 install -r requirements.txt
python3 ./pizzamob_leaderboard.py --entropy $1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
body {
font-family: monospace;
background-color: #222;
color: #00FF00;
font-size: 1.1vw;
}

a {
color: #00FF00;
text-decoration: none;
margin: 0px;
padding: 0px;
}

.container {
display: flex;
height: 100%;
background-color: #222;
justify-content: center;
}

.center {
width:80ch;
border: solid #eee 1px;
padding: 40px;
overflow-x: hidden;
background-color: #000;
}

.row {
height:1.8vw;
display:table;
white-space: pre;
}


input, input:focus {
border: none;
background-color: black;
color:#00FF00;
font-family:monospace;
font-size:1.0vw;
width:70ch;
outline:none;
}

.hidden {
position: absolute;
top: -5000px;
left: -5000px;
}
Binary file not shown.
Loading

0 comments on commit c6af327

Please sign in to comment.