Skip to content

Instantly share code, notes, and snippets.

@thelucre
Created June 1, 2016 15:04
Show Gist options
  • Save thelucre/67e7f02b6846cc1368246ccc676ce9f6 to your computer and use it in GitHub Desktop.
Save thelucre/67e7f02b6846cc1368246ccc676ce9f6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from two1.wallet import Wallet
from two1.bitrequests import BitTransferRequests
# set up bitrequest client for BitTransfer requests
wallet = Wallet()
requests = BitTransferRequests(wallet)
# server address
server_url = 'http://localhost:5000/'
def play():
# get the question from the server
response = requests.get(url=server_url+'question')
question = response.text
ans = input("Question: {}?\n".format(question))
sel_url = server_url + 'play?question={0}&selection={1}&payout_address={2}'
answer = requests.get(url=sel_url.format(question, ans, wallet.get_payout_address()))
print(answer.text)
if __name__ == '__main__':
play()
#!/usr/bin/env python3
import random
from flask import Flask
from flask import request
from two1.wallet import Wallet
from two1.bitserv.flask import Payment
app = Flask(__name__)
wallet = Wallet()
payment = Payment(app, wallet)
question_bank = {
'Who is the inventor of Bitcoin': 'Satoshi Nakamoto',
'How many satoshis are in a bitcoin': '100000000',
'What is the current coinbase reward (in BTC) for mining a block': '25'
}
question_list = list(question_bank.keys())
# endpoint to get a question from the server
@app.route('/question')
def get_question():
return question_list[random.randrange(0, len(question_list))]
# machine-payable endpoint that pays user if answer is correct
@app.route('/play')
@payment.required(10)
def answer_question():
# extract answer from client request
answer = request.args.get('selection')
# extract payout address from client address
client_payout_addr = request.args.get('payout_address')
# extract question from client request
client_question = request.args.get('question')
# check if answer is correct
if answer.lower() == question_bank[client_question].lower():
wallet.send_to(client_payout_addr, 20)
return "Correct!"
else:
return "Incorrect response."
if __name__ == '__main__':
app.run(host='0.0.0.0')
[21 Activity Log]
2016-06-01 07:52:52 UTC-07:00 : +5 satoshis to your 21.co balance
Description: You sold 'http://10.244.199.125:6002/?uri=21.co' to 21dotco
2016-05-31 23:55:40 UTC-07:00 : +3000 satoshis to your 21.co balance
Description: You sold 'http://10.244.199.125:8080/ping/?uri=21.co' to 21dotco
2016-05-31 23:49:16 UTC-07:00 : +10 satoshis to your 21.co balance
Description: You sold 'http://localhost:5000/play?question=How%20many%20satoshis%20are%20in%20a%20bitcoin&selection=100000000&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' to theLucre
2016-05-31 23:49:16 UTC-07:00 : -10 satoshis from your 21.co balance
Description: You bought 'http://localhost:5000/play?question=How%20many%20satoshis%20are%20in%20a%20bitcoin&selection=100000000&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' from thelucre
2016-05-31 22:43:09 UTC-07:00 : +3000 satoshis to your 21.co balance
Description: You sold 'http://10.244.199.125:8080/ping/?uri=21.co' to 21dotco
2016-05-31 22:32:50 UTC-07:00 : +5 satoshis to your 21.co balance
Description: You sold 'http://10.244.199.125:6002/?uri=21.co' to 21dotco
2016-05-31 22:27:37 UTC-07:00 : +1000 satoshis to your 21.co balance
Description: You sold 'http://localhost:5000/play?question=How%20many%20satoshis%20are%20in%20a%20bitcoin&selection=100000000&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' to theLucre
2016-05-31 22:27:37 UTC-07:00 : -1000 satoshis from your 21.co balance
Description: You bought 'http://localhost:5000/play?question=How%20many%20satoshis%20are%20in%20a%20bitcoin&selection=100000000&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' from thelucre
2016-05-31 22:27:27 UTC-07:00 : +1000 satoshis to your 21.co balance
Description: You sold 'http://localhost:5000/play?question=What%20is%20the%20current%20coinbase%20reward%20(in%20BTC)%20for%20mining%20a%20block&selection=255&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' to theLucre
2016-05-31 22:27:27 UTC-07:00 : -1000 satoshis from your 21.co balance
Description: You bought 'http://localhost:5000/play?question=What%20is%20the%20current%20coinbase%20reward%20(in%20BTC)%20for%20mining%20a%20block&selection=255&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' from thelucre
2016-05-31 22:19:25 UTC-07:00 : +1000 satoshis to your 21.co balance
Description: You sold 'http://localhost:5000/play?question=How%20many%20satoshis%20are%20in%20a%20bitcoin&selection=100000000&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' to theLucre
2016-05-31 22:19:25 UTC-07:00 : -1000 satoshis from your 21.co balance
Description: You bought 'http://localhost:5000/play?question=How%20many%20satoshis%20are%20in%20a%20bitcoin&selection=100000000&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' from thelucre
2016-05-31 22:17:09 UTC-07:00 : +1000 satoshis to your 21.co balance
Description: You sold 'http://localhost:5000/roll?question=What%20is%20the%20current%20coinbase%20reward%20%28in%20BTC%29%20for%20mining%20a%20block&selection=25&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' to theLucre
2016-05-31 22:17:09 UTC-07:00 : -1000 satoshis from your 21.co balance
Description: You bought 'http://localhost:5000/roll?question=What%20is%20the%20current%20coinbase%20reward%20%28in%20BTC%29%20for%20mining%20a%20block&selection=25&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' from thelucre
2016-05-31 22:16:37 UTC-07:00 : +1000 satoshis to your 21.co balance
Description: You sold 'http://localhost:5000/roll?question=What%20is%20the%20current%20coinbase%20reward%20%28in%20BTC%29%20for%20mining%20a%20block&selection=25&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' to theLucre
2016-05-31 22:16:37 UTC-07:00 : -1000 satoshis from your 21.co balance
Description: You bought 'http://localhost:5000/roll?question=What%20is%20the%20current%20coinbase%20reward%20%28in%20BTC%29%20for%20mining%20a%20block&selection=25&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' from thelucre
2016-05-31 21:50:45 UTC-07:00 : +1000 satoshis to your 21.co balance
Description: You sold 'http://localhost:5000/roll?question=What%20is%20the%20current%20coinbase%20reward%20%28in%20BTC%29%20for%20mining%20a%20block&selection=25&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' to theLucre
2016-05-31 21:50:45 UTC-07:00 : -1000 satoshis from your 21.co balance
Description: You bought 'http://localhost:5000/roll?question=What%20is%20the%20current%20coinbase%20reward%20%28in%20BTC%29%20for%20mining%20a%20block&selection=25&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' from thelucre
2016-05-31 21:42:01 UTC-07:00 : +1000 satoshis to your 21.co balance
Description: You sold 'http://localhost:5000/roll?question=How%20many%20satoshis%20are%20in%20a%20bitcoin&selection=100000000&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' to theLucre
2016-05-31 21:42:01 UTC-07:00 : -1000 satoshis from your 21.co balance
Description: You bought 'http://localhost:5000/roll?question=How%20many%20satoshis%20are%20in%20a%20bitcoin&selection=100000000&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' from thelucre
2016-05-31 21:41:41 UTC-07:00 : +5 satoshis to your 21.co balance
Description: You sold 'http://10.244.199.125:6002/?uri=21.co' to 21dotco
2016-05-31 21:37:49 UTC-07:00 : +1000 satoshis to your 21.co balance
Description: You sold 'http://localhost:5000/roll?question=What%20is%20the%20current%20coinbase%20reward%20(in%20BTC)%20for%20mining%20a%20block&selection=25&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' to theLucre
2016-05-31 21:37:49 UTC-07:00 : -1000 satoshis from your 21.co balance
Description: You bought 'http://localhost:5000/roll?question=What%20is%20the%20current%20coinbase%20reward%20(in%20BTC)%20for%20mining%20a%20block&selection=25&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' from thelucre
2016-05-31 21:37:22 UTC-07:00 : +1000 satoshis to your 21.co balance
Description: You sold 'http://localhost:5000/roll?question=How%20many%20satoshis%20are%20in%20a%20bitcoin&selection=100000000&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' to theLucre
2016-05-31 21:37:22 UTC-07:00 : -1000 satoshis from your 21.co balance
Description: You bought 'http://localhost:5000/roll?question=How%20many%20satoshis%20are%20in%20a%20bitcoin&selection=100000000&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' from thelucre
2016-05-31 21:36:22 UTC-07:00 : +1000 satoshis to your 21.co balance
Description: You sold 'http://localhost:5000/roll?question=What%20is%20the%20current%20coinbase%20reward%20(in%20BTC)%20for%20mining%20a%20block&selection=25&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' to theLucre
2016-05-31 21:36:22 UTC-07:00 : -1000 satoshis from your 21.co balance
Description: You bought 'http://localhost:5000/roll?question=What%20is%20the%20current%20coinbase%20reward%20(in%20BTC)%20for%20mining%20a%20block&selection=25&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' from thelucre
2016-05-31 21:33:33 UTC-07:00 : +1000 satoshis to your 21.co balance
Description: You sold 'http://localhost:5000/roll?question=How%20many%20satoshis%20are%20in%20a%20bitcoin&selection=100000000&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' to theLucre
2016-05-31 21:33:33 UTC-07:00 : -1000 satoshis from your 21.co balance
Description: You bought 'http://localhost:5000/roll?question=How%20many%20satoshis%20are%20in%20a%20bitcoin&selection=100000000&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' from thelucre
2016-05-31 21:32:40 UTC-07:00 : +1000 satoshis to your 21.co balance
Description: You sold 'http://localhost:5000/roll?question=What%20is%20the%20current%20coinbase%20reward%20(in%20BTC)%20for%20mining%20a%20block&selection=25&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' to theLucre
2016-05-31 21:32:40 UTC-07:00 : -1000 satoshis from your 21.co balance
Description: You bought 'http://localhost:5000/roll?question=What%20is%20the%20current%20coinbase%20reward%20(in%20BTC)%20for%20mining%20a%20block&selection=25&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' from thelucre
2016-05-31 21:30:25 UTC-07:00 : +1000 satoshis to your 21.co balance
Description: You sold 'http://localhost:5000/roll?question=Who%20is%20the%20inventor%20of%20Bitcoin&selection=Satoshi%20Nakamoto&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' to theLucre
2016-05-31 21:30:25 UTC-07:00 : -1000 satoshis from your 21.co balance
Description: You bought 'http://localhost:5000/roll?question=Who%20is%20the%20inventor%20of%20Bitcoin&selection=Satoshi%20Nakamoto&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' from thelucre
2016-05-31 21:26:03 UTC-07:00 : +1000 satoshis to your 21.co balance
Description: You sold 'http://localhost:5000/play?question=Who%20is%20the%20inventor%20of%20Bitcoin&selection=Satoshi%20Nakamoto&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' to theLucre
2016-05-31 21:26:03 UTC-07:00 : -1000 satoshis from your 21.co balance
Description: You bought 'http://localhost:5000/play?question=Who%20is%20the%20inventor%20of%20Bitcoin&selection=Satoshi%20Nakamoto&payout_address=1NoGUxxjVcBBk39k1gKXsC5J7zh9Nn55Wx' from thelucre
2016-05-31 20:59:44 UTC-07:00 : +5 satoshis to your 21.co balance
Description: You sold 'http://10.244.199.125:6002/?uri=21.co' to 21dotco
2016-05-31 20:28:43 UTC-07:00 : +3000 satoshis to your 21.co balance
Description: You sold 'http://10.244.199.125:8080/ping/?uri=21.co' to 21dotco
2016-05-31 20:08:11 UTC-07:00 : +3000 satoshis to your 21.co balance
Description: You sold 'http://10.244.199.125:8080/ping/?uri=21.co' to 21dotco
2016-05-31 19:36:38 UTC-07:00 : +5 satoshis to your 21.co balance
Description: You sold 'http://10.244.199.125:6002/?uri=21.co' to 21dotco
2016-05-31 15:42:28 UTC-07:00 : -200000 satoshis from your 21.co balance, +200000 satoshis to your Blockchain balance
Description: You performed 21 flush to move your earnings to the Blockchain.
Address paid to : 1NGUqKcktaU6AuZQVb7FpeKpzkv3hUomyq
Blockchain Transaction(s) : cecfc4d566aa22b3f646198234a1dd835fa24f3802952983ae43de05add21f26
2016-05-31 14:49:31 UTC-07:00 : +40000 satoshis to your 21.co balance
Description: You just received a little bit of bitcoin.
2016-05-31 14:48:48 UTC-07:00 : +40000 satoshis to your 21.co balance
Description: You just received a little bit of bitcoin.
2016-05-31 14:48:36 UTC-07:00 : +40000 satoshis to your 21.co balance
Description: You just received a little bit of bitcoin.
2016-05-31 14:47:39 UTC-07:00 : +40000 satoshis to your 21.co balance
Description: You just received a little bit of bitcoin.
2016-05-31 14:47:30 UTC-07:00 : +40000 satoshis to your 21.co balance
Description: You connected your Linkedin profile to your 21 account.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment