Last active
January 14, 2016 20:23
-
-
Save walkeralencar/58cb3342d9cb9bdb18b0 to your computer and use it in GitHub Desktop.
Decred - Vanity Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Decred vanity generator | |
* Inspired by RiCK: https://gist.github.com/Retord/4cffeae3516e2c99fa0d | |
* | |
* @author Walker de Alencar <@walkeralencar> | |
*/ | |
$config = [ | |
'type' => 'noseed', // can use: 'seed' or 'noseed' or 'regtest' or 'simnet' or 'testnet' | |
'prefix' => 'DsVanity', // overwrite Vanity by your name, use less than 5 chars. should take lesser time | |
'output' => 'vanity.dcr' | |
'storage' => 'storage.txt' | |
]; | |
/** | |
* @param $output | |
* @param string $type can use: 'seed'|'noseed'|'regtest'|'simnet'|'testnet' | |
* @return array | |
* @throws Exception | |
*/ | |
function generate($output, $type = 'noseed') | |
{ | |
if (!in_array($type,['seed','noseed','regtest','simnet','testnet'])){ | |
throw new Exception('Invalid Type!'); | |
} | |
if (exec( 'dcraddrgen' . ($type === 'seed'? '': ' -'. $type) . ' ' . $output)) { | |
return array_map(function ($address) { | |
return explode(': ', $address)[1]; | |
}, file($output,FILE_IGNORE_NEW_LINES)); | |
} else { | |
throw new Exception('dcraddrgen Not Working!'); | |
} | |
} | |
$got = false; | |
$cnt = 0; | |
$time_start = microtime(true); | |
while ($got == false) { | |
$address = generate($config['output'], $config['type']); | |
$got = (strtolower(substr($address[0],0,15)) == strtolower($config['prefix'])); | |
if (!$got){ | |
file_put_contents($config['storage'],"('" . implode("', '",$address) . "')," . PHP_EOL, FILE_APPEND); | |
unlink($config['output']); | |
} | |
echo $cnt++ . ': ' . $address[0] . PHP_EOL; | |
} | |
echo (microtime(true) - $time_start) . 's and ' . $cnt . 'generated addresses;'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment