Bonjour à toutes et à tous ,
Voici un code en Python pour effectuer le minage de crypto BTC, retrouvé sur le site ci-joint. J'ai légèrement modifié le code car il présentait un problème de division par zéro :
https://128mots.com/2021/02/23/bitco...rithme-python/
Ca marche super pour block 671712 de l'exemple :
Mais pour autres block ca ne marche par exemple pour le Bloc 790732:Code:import hashlibimport time import struct import binascii import datetime from binascii import unhexlify, hexlify from dateutil import parser from datetime import datetime from datetime import timedelta nontrouve = True dtprec = datetime.now() inonc = 1768459821 - 400 # Starting 400 before the good nonce resultat = [] while nontrouve: inonc += 1 if inonc % 50 == 0: time_difference = datetime.now() - dtprec if time_difference.total_seconds() != 0: print( str(round(timedelta(seconds=1) / time_difference)) + " H/s" ) dtprec = datetime.now() header_hex = ( binascii.hexlify(struct.Struct("<L").pack(int("0x3fff0000", 16))).decode() + binascii.hexlify( binascii.unhexlify("000000000000000000062a949bc297739a12e639ba9e2107638b469afe11d0f8")[ ::-1 ] ).decode() + binascii.hexlify( binascii.unhexlify("692e5f889b4d5c35925402ae46a6b00bf249d768715d1475f15e4a2325b8930e")[ ::-1 ] ).decode() + binascii.hexlify( struct.Struct("<L").pack( int(hex(int(parser.parse("2021-02-22 15:39:00 GMT +1").timestamp()) - 3600), 16) ) ).decode() + binascii.hexlify(struct.Struct("<L").pack(int("0x170cf4e3", 16))).decode() + binascii.hexlify(struct.Struct("<L").pack(int(hex(inonc), 16))).decode() ) header_bin = unhexlify(header_hex) dt1 = datetime.now().strftime("%H:%M:%S.%f") hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest() hexlify(hash).decode("utf-8") hexlify(hash[::-1]).decode("utf-8") hash = hexlify(hash[::-1]).decode("utf-8") resultat.append([round(int(hash, 16) / 10 ** 65)]) MAX_TARGET = int("00000000FFFF0000000000000000000000000000000000000000000000000000", 16) Difficulty = 21724134900047 target = int(MAX_TARGET / Difficulty) target32 = "{:0>64x}".format(target) if int(hash, 16) < int(target32, 16): print("###########BLOC MINED###################") print("HEADER=" + header_hex) print("HASH=" + hash) print("NONCE=" + str(inonc)) print("NONCE (hex)=" + hex(inonc)) print("###########BLOC MINED###################") break
https://blockstream.info/block/00000...a6d1b981a065d3Code:import hashlibimport time import struct import binascii import datetime from binascii import unhexlify, hexlify from dateutil import parser from datetime import datetime from datetime import timedelta nontrouve = True dtprec = datetime.now() inonc = 4006631778 - 400 # Starting 400 before the good nonce resultat = [] while nontrouve: inonc += 1 if inonc % 50 == 0: time_difference = datetime.now() - dtprec if time_difference.total_seconds() != 0: print( str(round(timedelta(seconds=1) / time_difference)) + " H/s" ) dtprec = datetime.now() header_hex = ( binascii.hexlify(struct.Struct("<L").pack(int("0x30e0c000", 16))).decode() + binascii.hexlify( binascii.unhexlify("00000000000000000003e7e3d5d006a6e8145e564f07e873f3dd857132066868")[ ::-1 ] ).decode() + binascii.hexlify( binascii.unhexlify("6429ba685a97048c9a50196de127e668c1d32379a38f41cab2609882359cae23")[ ::-1 ] ).decode() + binascii.hexlify( struct.Struct("<L").pack( int(hex(int(parser.parse("2023-05-21 12:02:17 GMT +1").timestamp()) - 3600), 16) ) ).decode() + binascii.hexlify(struct.Struct("<L").pack(int("0x1705ae3a", 16))).decode() + binascii.hexlify(struct.Struct("<L").pack(int(hex(inonc), 16))).decode() ) header_bin = unhexlify(header_hex) dt1 = datetime.now().strftime("%H:%M:%S.%f") hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest() hexlify(hash).decode("utf-8") hexlify(hash[::-1]).decode("utf-8") hash = hexlify(hash[::-1]).decode("utf-8") resultat.append([round(int(hash, 16) / 10 ** 65)]) MAX_TARGET = int("00000000FFFF0000000000000000000000000000000000000000000000000000", 16) Difficulty = 49549703178592 target = int(MAX_TARGET / Difficulty) target32 = "{:0>64x}".format(target) if int(hash, 16) < int(target32, 16): print("###########BLOC MINED###################") print("HEADER=" + header_hex) print("HASH=" + hash) print("NONCE=" + str(inonc)) print("NONCE (hex)=" + hex(inonc)) print("###########BLOC MINED###################") break
Pourriez-vous m'aider à faire fonctionner ce code pour les blocs récents ? Je n'aime pas jouer au loto, mais jouer à ça m'intéresse, surtout que je ne vais pas acheter un ticket.
-----