/** * @param $coinSymbol * @return \BitWasp\Bitcoin\Network\Network * @throws \Exception */ public static function getNetwork($coinSymbol) { CoinSymbolValidator::validate($coinSymbol, 'coinSymbol'); $network = null; switch ($coinSymbol) { case 'btc': $network = NetworkFactory::bitcoin(); break; case 'btc-testnet': $network = NetworkFactory::bitcoinTestnet(); break; case 'ltc': $network = NetworkFactory::litecoin(); break; case 'doge': $network = NetworkFactory::create('1e', '16', '9e')->setHDPubByte('02fd3929')->setHDPrivByte('02fd3955')->setNetMagicBytes('c0c0c0c0'); break; case 'uro': // NetMagicBytes: https://github.com/urocoin/uro/blob/319de97bbd56a10a3b2dca5b36be0c7a9c6603ae/src/main.cpp#L3233 throw new \Exception("Unsupported coin symbol: {$coinSymbol}"); break; case 'bcy': // TODO: check ef, 043587cf, 04358394, d9b4bef9 values // not used for the time being $network = NetworkFactory::create('1b', '1f', 'ef', true)->setHDPubByte('043587cf')->setHDPrivByte('04358394')->setNetMagicBytes('d9b4bef9'); break; default: throw new \Exception("Unsupported coin symbol: {$coinSymbol} by php-client"); } return $network; }
use BitWasp\Bitcoin\Network\NetworkFactory; use BitWasp\Bitcoin\Bitcoin; use BitWasp\Bitcoin\Script\OutputScriptFactory; use BitWasp\Bitcoin\Script\ScriptFactory; use BitWasp\Buffertools\Buffer; use willgriffin\MariaInterface\MariaInterface; $configFile = count($argv) > 1 ? $argv[1] : false; $x = count($argv) > 2 ? intval($argv[2]) : 1; $math = new Math(); $difficulty = new Difficulty($math); if (file_exists($configFile)) { $config = (object) parse_ini_file($configFile); //$currency = Main::getCurrency($currencyName); $db = new MariaInterface(["host" => $config->dbhost, "user" => $config->dbuser, "pass" => $config->dbpass, "port" => $config->dbport, "name" => $config->dbname]); $bitcoind = RpcFactory::bitcoind($config->rpchost, $config->rpcport, $config->rpcuser, $config->rpcpass); $network = NetworkFactory::create($config->magic_byte, $config->magic_p2sh_byte, $config->private_key_byte)->setHDPubByte($config->hd_pub_byte)->setHDPrivByte($config->hd_priv_byte)->setNetMagicBytes($config->net_magic_bytes); Bitcoin::setNetwork($network); $nextBlockHash = $bitcoind->getblockhash($x); do { echo "Block {$x}\n"; $blockhash = $nextBlockHash; $block = $bitcoind->getblock($blockhash); $blockHeader = $block->getHeader(); $blockBits = $blockHeader->getBits(); $blockTime = $blockHeader->getTimestamp(); $nextBlockHash = $blockHeader->getNextBlock(); $bvals = ['isiidsisdss', $blockHeader->getTimestamp(), $blockHeader->getBlockHash(), $block->getBuffer()->getSize(), $x, $blockHeader->getVersion(), $blockHeader->getMerkleRoot(), $blockHeader->getNonce(), $math->getCompact($blockBits), $difficulty->getDifficulty($blockBits), $blockHeader->getPrevBlock(), $nextBlockHash]; $block_id = $db->value('select block_id from blocks where hash = ?', ['s', $blockhash]); if (!$block_id) { $bsql = "insert into blocks " . "(time, " . "hash, " . "size, " . "height, " . "version, " . "merkleroot, " . "nonce, " . "bits, " . "difficulty, " . "previousblockhash, " . "nextblockhash, " . "last_updated " . ") values (from_unixtime(?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now())"; $block_id = $db->insert($bsql, $bvals);