def main(): boxId = 4 seedOffset = 0 nonMint = True fileName = f'boxHolders_{boxId}_1.csv' seedStr = '0x54279ad7faff7f0ff1322f048798a80f987c394899e5a0a146e5415f4ad40d0a' byteSeed = web3.toBytes(hexstr=seedStr) seed = web3.soliditySha3(['bytes32'], [byteSeed]) seedInt = web3.toInt(seed) if seedOffset > 0: (seed, seedInt) = offsetSeed(seed, seedOffset, web3) box = NFTBoxesBox.at('0xf876bBc810E84854C9C37018103C0045544a6Af9') print(f'Box contract at {box.address}\nFetching holders of box edition {boxId}...') ids = 8 box_contract = web3.eth.contract(address=box.address, abi=box.abi) filt = box_contract.events.BoxBought.createFilter(fromBlock=0, toBlock= 'latest', argument_filters={'boxMould':boxId}) res = filt.get_all_entries() holders = [box.ownerOf(e.args.tokenId) for e in res] print(f'Box holders fetched. Size: {len(holders)}\nExecuting distribution from initial seed: {seedStr}') dissArr = [] for i in range(ids): dissArr.append([h for h in holders]) winnerArray = [] for i in range(len(holders)): tempWinnerArray = [] for j in range(ids): indexWinner = seedInt % len(dissArr[j]) winner = dissArr[j][indexWinner] (seed, seedInt) = newSeed(seed, web3) tempWinnerArray.append(winner) dissArr[j].pop(indexWinner) winnerArray.append([w for w in tempWinnerArray]) tempWinnerArray.clear() print(f'Distribution finished, writing data onto {fileName}...') strcsv = '' for row in winnerArray: for i in range(len(row)): strcsv += row[i] if i != len(row) - 1: strcsv += ',' strcsv += '\n' file = open (fileName, 'w') file.write(strcsv) file.close() print('done')
def main(): boxId = 2 seedStr = '0x4f22a72b37e5acea8fc863522419e05e71bc9947bd0559995ee58702533bbb44' byteSeed = web3.toBytes(hexstr=seedStr) seed = web3.soliditySha3(['bytes32'], [byteSeed]) seedInt = web3.toInt(seed) box = NFTBoxesBox.at('0x067ab2FbdBED63401aF802d1DD786E6D83b0ff1B') print( f'Box contract at {box.address}\nFetching holders of box edition {boxId}...' ) ids = 6 box_contract = web3.eth.contract(address=box.address, abi=box.abi) filt = box_contract.events.BoxBought.createFilter( fromBlock=0, toBlock='latest', argument_filters={'boxMould': boxId}) res = filt.get_all_entries() holders = [box.ownerOf(e.args.tokenId) for e in res] print( f'Box holders fetched. Size: {len(holders)}\nExecuting distribution from initial seed: {seedStr}' ) dissArr = [] for i in range(ids): dissArr.append([h for h in holders]) winnerArray = [] for i in range(len(holders)): tempWinnerArray = [] for j in range(ids): indexWinner = seedInt % len(dissArr[j]) winner = dissArr[j][indexWinner] (seed, seedInt) = newSeed(seed, web3) tempWinnerArray.append(winner) dissArr[j].pop(indexWinner) winnerArray.append([w for w in tempWinnerArray]) tempWinnerArray.clear() print( f'Distribution finished, writing data onto boxHolders_{boxId}.csv...') strcsv = '' for row in winnerArray: for i in range(len(row)): strcsv += row[i] if i != len(row) - 1: strcsv += ',' strcsv += '\n' file = open(f'boxHolders_{boxId}.csv', 'w') file.write(strcsv) file.close() print('done')
def main(): boxId = 1 seedStr = '0xc63e18417049d1aed1dc4bea9f25838f3423fcd552bb316546f6b92e4979065c' byteSeed = web3.toBytes(hexstr=seedStr) seed = web3.soliditySha3(['bytes32'], [byteSeed]) seedInt = web3.toInt(seed) box = NFTBoxesBox.at('0xB9134aef577b7cb43B03856E308ebDC80d51E126') print( f'Box contract at {box.address}\nFetching holders of box edition {boxId}...' ) ids = 9 box_contract = web3.eth.contract(address=box.address, abi=box.abi) filt = box_contract.events.BoxBought.createFilter( fromBlock=0, toBlock='latest', argument_filters={'boxMould': boxId}) res = filt.get_all_entries() holders = [box.ownerOf(e.args.tokenId) for e in res] print( f'Box holders fetched. Size: {len(holders)}\nExecuting distribution from initial seed: {seedStr}' ) dissArr = [] for i in range(ids): dissArr.append([h for h in holders]) winnerArray = [] for i in range(len(holders)): tempWinnerArray = [] for j in range(ids): indexWinner = seedInt % len(dissArr[j]) winner = dissArr[j][indexWinner] (seed, seedInt) = newSeed(seed, web3) tempWinnerArray.append(winner) dissArr[j].pop(indexWinner) winnerArray.append([w for w in tempWinnerArray]) tempWinnerArray.clear() print( f'Distribution finished, writing data onto boxHolders_{boxId}.csv...') wtr = csv.writer(open(f'boxHolders_{boxId}.csv', 'w'), delimiter=',', lineterminator='\n') for x in winnerArray: wtr.writerow(x) print('done')
def main(): boxId = 1 seedStr = '0x6b81fc5c9ff7a165c1f5254bc7dff5280dbc1d7d6d2f16a3cb9de105b1b67561' byteSeed = web3.toBytes(hexstr=seedStr) seed = web3.soliditySha3(['bytes32'], [byteSeed]) seedInt = web3.toInt(seed) box = NFTBoxes.at('0xE3Bc15412a26039384ED773cA5882D10F8BD48c7') print( f'Box contract at {box.address}\nFetching holders of box edition {boxId}...' ) ids = box.getIdsLength(boxId) box_contract = web3.eth.contract(address=box.address, abi=box.abi) filt = box_contract.events.BoxBought.createFilter( fromBlock=0, toBlock='latest', argument_filters={'boxMould': boxId}) res = filt.get_all_entries() holders = [box.ownerOf(e.args.tokenId) for e in res] print( f'Box holders fetched. Size: {len(holders)}\nExecuting distribution from initial seed: {seedStr}' ) dissArr = [] for i in range(ids): dissArr.append([h for h in holders]) winnerArray = [] for i in range(len(holders)): tempWinnerArray = [] for j in range(ids): indexWinner = seedInt % len(dissArr[j]) winner = dissArr[j][indexWinner] (seed, seedInt) = newSeed(seed, web3) tempWinnerArray.append(winner) dissArr[j].pop(indexWinner) winnerArray.append([w for w in tempWinnerArray]) tempWinnerArray.clear() print( f'Distribution finished, writing data onto boxHolders_{boxId}.csv...') wtr = csv.writer(open(f'boxHolders_{boxId}.csv', 'w'), delimiter=',', lineterminator='\n') for x in winnerArray: wtr.writerow(x) print('done')
def parse_string(hex_obj: HexBytes) -> str: hex_str = str(hex_obj.hex()) # chunk = web3.toInt(hexstr=hex_str[:64]) len = web3.toInt(hexstr=hex_str[64:128]) data = hex_str[128:128 + len * 2] return web3.toText(hexstr=data)
def newSeed(seed, web3): seed = web3.soliditySha3(['bytes32'], [seed]) return (seed, web3.toInt(seed))
def offsetSeed(seed, offset, web3): for i in range(offset): seed = web3.soliditySha3(['bytes32'], [seed]) return (seed, web3.toInt(seed))