本文主要是介绍起源计划 | 第二期 CPI 抽奖结果公示,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
根据活动规则,抽奖过程为在投给冠军(So Dapp)战队的票数中随机抽取 60 个中奖名额,每个 1000 FC,结果如下:
抽奖程序:
import hashlib
import os
def sha3(x):
m = hashlib.sha3_256()
m.update(x.encode())
return m.hexdigest()
def pick(x):
global data
l = 0
r = len(data) - 1
while (l <= r):
mid = (l + r) >> 1
if (eval(data[mid][3]) >= luck):
r = mid - 1
else:
l = mid + 1
return r + 1
# get transfer logs
fin = open('transfer.log', 'r')
lines = fin.readlines()
# parse
# 0: epoch number
# 1: sender address
# 2: amount
# 3: accumulate amount
data = [x.strip().split(' ') for x in lines]
# filter transfer log with amount = 0
data = list(filter(lambda x : eval(x[2]) > 0, data))
# calculate initial sha3 hash
hashes = [sha3(' '.join(log)) for log in data]
now_hash = sha3(' '.join(hashes))
# roll
total_voted = eval(data[-1][-1])
award_cnt = 60
awarded = {}
for i in range(award_cnt):
now_hash = sha3(now_hash + " conflux pioneer initiative {}-th price draw".format(i))
luck = int(now_hash, 16) % total_voted
luck_user = data[pick(luck)][1]
if luck_user in awarded:
awarded[luck_user] += 1
else:
awarded[luck_user] = 1
print(awarded)
END
了解最新动态
这篇关于起源计划 | 第二期 CPI 抽奖结果公示的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!