diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e99e36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc \ No newline at end of file diff --git a/README.md b/README.md index 846c933..d64f396 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ A python script for creating the parameters required for a unique genesis block. ### Dependencies sudo pip install scrypt construct==2.5.2 -To create geneses based on X11 algorithm you will also need to install the [xcoin-hash](https://github.com/lhartikk/xcoin-hash) module. -For X13 you will need the [x13_hash](https://github.com/sherlockcoin/X13-PythonHash) module and for X15 the [x15_hash](https://github.com/minings/x15_hash) module. - +To create geneses based on X11 algorithm you will also need to install the [xcoin-hash](https://github.com/lhartikk/xcoin-hash) module. +For X13 you will need the [x13_hash](https://github.com/sherlockcoin/X13-PythonHash) module and for X15 the [x15_hash](https://github.com/minings/x15_hash) module. For quark you will additionally need the [quark_hash](https://github.com/Neisklar/quarkcoin-hash-python) module. + ### Examples Create the original genesis hash found in Bitcoin @@ -30,11 +30,11 @@ Create the regtest genesis hash found in Bitcoin Create the original genesis hash found in Litecoin python genesis.py -a scrypt -z "NY Times 05/Oct/2011 Steve Jobs, Apple’s Visionary, Dies at 56" -p "040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9" -t 1317972665 -n 2084524493 - + Create a unique genesis hash with custom pszTimestamp python genesis.py -a scrypt -z "Time flies like an arrow. Fruit flies like a banana." - + Create the original genesis hash found in DarkCoin. (requires [xcoin-hash](https://github.com/lhartikk/xcoin-hash)) python genesis.py -a X11 -z "Wired 09/Jan/2014 The Grand Experiment Goes Live: Overstock.com Is Now Accepting Bitcoins" -t 1317972665 -p "040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9" -n 28917698 -t 1390095618 -v 5000000000 @@ -42,12 +42,12 @@ Create the original genesis hash found in DarkCoin. (requires [xcoin-hash](https Create the original genesis hash found in HiroCoin (requires [xcoin-hash](https://github.com/lhartikk/xcoin-hash)). python genesis.py -a X11 -z "JapanToday 13/Mar/2014 Ways eyed to make planes easier to find in ocean" -p "040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9" -n 1234746574 -t 1394723131 -v 40000000000 - + ### Options Usage: genesis.py [options] - + Options: -h, --help show this help message and exit -t TIME, --time=TIME the (unix) time when the genesisblock is created @@ -64,4 +64,3 @@ Create the original genesis hash found in HiroCoin (requires [xcoin-hash](https: the value in coins for the output, full value (exp. in bitcoin 5000000000 - To get other coins value: Block Value * 100000000) -b BITS, --bits=BITS the target in compact representation, associated to a difficulty of 1 - diff --git a/genesis.py b/genesis.py index 1eacc15..1b191ee 100644 --- a/genesis.py +++ b/genesis.py @@ -3,34 +3,39 @@ from construct import * +supported_algorithms = ["SHA256", "scrypt", "X11", "X13", "X15", "quark"] def main(): + print 'Searching for genesis hash...' options = get_args() + merkle_hash, nonce, genesis_hash = get_genesis(options) + print_block_info(options, merkle_hash) + announce_found_genesis(genesis_hash, nonce) +def get_genesis(options): algorithm = get_algorithm(options) input_script = create_input_script(options.timestamp) output_script = create_output_script(options.pubkey) - # hash merkle root is the double sha256 hash of the transaction(s) + # hash merkle root is the double sha256 hash of the transaction(s) tx = create_transaction(input_script, output_script,options) hash_merkle_root = hashlib.sha256(hashlib.sha256(tx).digest()).digest() - print_block_info(options, hash_merkle_root) block_header = create_block_header(hash_merkle_root, options.time, options.bits, options.nonce) genesis_hash, nonce = generate_hash(block_header, algorithm, options.nonce, options.bits) - announce_found_genesis(genesis_hash, nonce) + return hash_merkle_root[::-1].encode('hex_codec'), str(nonce), genesis_hash.encode('hex_codec') def get_args(): parser = optparse.OptionParser() - parser.add_option("-t", "--time", dest="time", default=int(time.time()), + parser.add_option("-t", "--time", dest="time", default=int(time.time()), type="int", help="the (unix) time when the genesisblock is created") parser.add_option("-z", "--timestamp", dest="timestamp", default="The Times 03/Jan/2009 Chancellor on brink of second bailout for banks", type="string", help="the pszTimestamp found in the coinbase of the genesisblock") parser.add_option("-n", "--nonce", dest="nonce", default=0, type="int", help="the first value of the nonce that will be incremented when searching the genesis hash") parser.add_option("-a", "--algorithm", dest="algorithm", default="SHA256", - help="the PoW algorithm: [SHA256|scrypt|X11|X13|X15]") + help="the PoW algorithm: [SHA256|scrypt|X11|X13|X15|quark]") parser.add_option("-p", "--pubkey", dest="pubkey", default="04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f", type="string", help="the pubkey found in the output script") parser.add_option("-v", "--value", dest="value", default=5000000000, @@ -40,14 +45,13 @@ def get_args(): (options, args) = parser.parse_args() if not options.bits: - if options.algorithm == "scrypt" or options.algorithm == "X11" or options.algorithm == "X13" or options.algorithm == "X15": - options.bits = 0x1e0ffff0 - else: + if options.algorithm == 'SHA256': options.bits = 0x1d00ffff + else: + options.bits = 0x1e0ffff0 return options def get_algorithm(options): - supported_algorithms = ["SHA256", "scrypt", "X11", "X13", "X15"] if options.algorithm in supported_algorithms: return options.algorithm else: @@ -59,7 +63,7 @@ def create_input_script(psz_timestamp): if len(psz_timestamp) > 76: psz_prefix = '4c' script_prefix = '04ffff001d0104' + psz_prefix + chr(len(psz_timestamp)).encode('hex') - print (script_prefix + psz_timestamp.encode('hex')) + # print (script_prefix + psz_timestamp.encode('hex')) return (script_prefix + psz_timestamp.encode('hex')).decode('hex') @@ -97,7 +101,7 @@ def create_transaction(input_script, output_script,options): #tx.out_value = struct.pack('