from random import seed, uniform
current_block_hash = previous_game_block['nextblockhash']
jackpot_total = 0
players = []
while True:
current_block = getblock(current_block_hash)
for transaction in current_block:
if transaction['amount'] <= 0:
continue
jackpot_total += amount
players.append({
'from_address': transaction['from_address']
'amount': transaction['amount'],
})
if jackpot_total < 0.01:
current_block_hash = current_block['nextblockhash']
continue
seed(current_block['nextblockhash'])
winning_marker = uniform(0.0, float(jackpot_total))
current_marker = 0
winner_address = None
for player in players:
current_marker += player['amount']
if winning_marker <= current_marker:
winner_address = player['from_address']
break
send_to_winner = float(jackpot_total) * 0.99
send_to_bank = float(jackpot_total) - send_to_winner
sendmany("", {
winner_address: send_to_winner,
bank_address: send_to_bank,
})
jackpot_total = 0
current_block_hash = current_block['nextblockhash']