本文整理汇总了PHP中BitWasp\Buffertools\Buffer::getHex方法的典型用法代码示例。如果您正苦于以下问题:PHP Buffer::getHex方法的具体用法?PHP Buffer::getHex怎么用?PHP Buffer::getHex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitWasp\Buffertools\Buffer
的用法示例。
在下文中一共展示了Buffer::getHex方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSerialize
public function testSerialize()
{
$hex = '41414141';
$dec = EccFactory::getAdapter()->hexDec($hex);
$bin = pack("H*", $hex);
$this->buffer = Buffer::hex($hex);
// Check Binary
$retBinary = $this->buffer->getBinary();
$this->assertSame($bin, $retBinary);
// Check Hex
$this->assertSame($hex, $this->buffer->getHex());
// Check Decimal
$this->assertSame($dec, $this->buffer->getInt());
}
示例2: generateMasterKey
/**
* Generate a master private key given a
* @param Buffer $seed
* @param EcAdapterInterface $ecAdapter
* @return ElectrumKey
*/
public static function generateMasterKey(Buffer $seed, EcAdapterInterface $ecAdapter = null)
{
// Really weird, did electrum actually hash hex string seeds?
$binary = $oldseed = $seed->getHex();
// Perform sha256 hash 5 times per iteration
for ($i = 0; $i < 5 * 20000; $i++) {
// Hash should return binary data
$binary = hash('sha256', $binary . $oldseed, true);
}
$ecAdapter = $ecAdapter ?: Bitcoin::getEcAdapter();
// Convert binary data to hex.
$str = new Buffer($binary, 32, $ecAdapter->getMath());
return self::fromSecretExponent($str->getInt(), $ecAdapter);
}
示例3: entropyToWords
/**
* @param Buffer $entropy
* @return array
*/
public function entropyToWords(Buffer $entropy)
{
$math = $this->ecAdapter->getMath();
$ENT = $entropy->getSize() * 8;
$CS = $ENT / 32;
$entBits = $math->baseConvert($entropy->getHex(), 16, 2);
$csBits = $this->calculateChecksum($entropy, $CS);
$bits = str_pad($entBits . $csBits, $ENT + $CS, '0', STR_PAD_LEFT);
$result = [];
foreach (str_split($bits, 11) as $bit) {
$idx = $math->baseConvert($bit, 2, 10);
$result[] = $this->wordList->getWord($idx);
}
return $result;
}
示例4: fetchBlock
/**
* @param Buffer $hash
* @return Block
*/
public function fetchBlock(Buffer $hash)
{
if ($this->debug) {
echo 'db: called fetchBlock (' . $hash->getHex() . '\\n';
}
$stmt = $this->dbh->prepare('
SELECT h.hash, h.version, h.prevBlock, h.merkleRoot, h.nBits, h.nNonce, h.nTimestamp
FROM blockIndex b
JOIN headerIndex h ON b.hash = h.hash
WHERE b.hash = :hash
');
$stmt->bindValue(':hash', $hash->getHex());
if ($stmt->execute()) {
$r = $stmt->fetch();
$stmt->closeCursor();
if ($r) {
return new Block(Bitcoin::getMath(), new BlockHeader($r['version'], $r['prevBlock'], $r['merkleRoot'], $r['nTimestamp'], Buffer::int($r['nBits'], 4), $r['nNonce']), $this->fetchBlockTransactions($hash));
}
}
throw new \RuntimeException('Failed to fetch block');
}
示例5: Buffer
<?php
require "../vendor/autoload.php";
use BitWasp\Buffertools\Buffer;
use BitWasp\Buffertools\BufferHex;
use BitWasp\Buffertools\BufferInt;
// Binary data and ASCII can be passed directly to a Buffer
$binary = new Buffer('hello world');
echo $binary->getBinary() . PHP_EOL;
echo $binary->getHex() . PHP_EOL;
// BufferHex and BufferInt convert data to binary
$hex = new BufferHex('68656c6c6f20776f726c64');
echo $binary->getBinary() . PHP_EOL;
echo $hex->getHex() . PHP_EOL;
// All Buffers expose getBinary(), getInt(), getHex()
$int = new BufferInt(65);
echo $int->getBinary() . PHP_EOL;
echo $int->getInt() . PHP_EOL;
echo $int->getHex() . PHP_EOL;
示例6: __construct
/**
* @param Buffer $hash
*/
public function __construct(Buffer $hash)
{
$this->hash = $hash->getHex();
}
示例7: markReceived
/**
* @param Buffer $hash
* @return $this
*/
public function markReceived(Buffer $hash)
{
unset($this->inFlight[$hash->getHex()]);
return $this;
}
示例8: readBits
/**
* @param Buffer $buffer
* @return string
*/
public function readBits(Buffer $buffer)
{
return str_pad($this->getMath()->baseConvert($buffer->getHex(), 16, 2), $this->length * 8, '0', STR_PAD_LEFT);
}