本文整理汇总了PHP中BitWasp\Buffertools\Buffer::getInt方法的典型用法代码示例。如果您正苦于以下问题:PHP Buffer::getInt方法的具体用法?PHP Buffer::getInt怎么用?PHP Buffer::getInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitWasp\Buffertools\Buffer
的用法示例。
在下文中一共展示了Buffer::getInt方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: twoValueCases
/**
* @param $opCode
* @param ScriptStack $mainStack
* @throws \BitWasp\Bitcoin\Exceptions\ScriptStackException
* @throws \Exception
*/
private function twoValueCases($opCode, ScriptStack $mainStack)
{
if ($mainStack->size() < 2) {
throw new \Exception('Invalid stack operation (greater than)');
}
$num1 = $mainStack->top(-2)->getInt();
// cscriptnum
$num2 = $mainStack->top(-1)->getInt();
$opCodes = $this->opCodes;
$opName = $opCodes->getOp($opCode);
$math = $this->math;
$castToBool = $this->castToBool;
if ($opName == 'OP_ADD') {
$num = $math->add($num1, $num2);
} elseif ($opName == 'OP_SUB') {
// cscriptnum
$num = $math->sub($num1, $num2);
} elseif ($opName == 'OP_BOOLAND') {
// cscriptnum
$num = $math->cmp($num1, $this->_bn0->getInt()) !== 0 && $math->cmp($num2, $this->_bn0->getInt()) !== 0;
} elseif ($opName == 'OP_BOOLOR') {
$num = $math->cmp($num1, $this->_bn0->getInt()) !== 0 || $math->cmp($num2, $this->_bn0->getInt()) !== 0;
} elseif ($opName == 'OP_NUMEQUAL') {
// cscriptnum
$num = $math->cmp($num1, $num2) == 0;
} elseif ($opName == 'OP_NUMEQUALVERIFY') {
// cscriptnum
$num = $math->cmp($num1, $num2) == 0;
} elseif ($opName == 'OP_NUMNOTEQUAL') {
$num = $math->cmp($num1, $num2) !== 0;
} elseif ($opName == 'OP_LESSTHAN') {
// cscriptnum
$num = $math->cmp($num1, $num2) < 0;
} elseif ($opName == 'OP_GREATERTHAN') {
$num = $math->cmp($num1, $num2) > 0;
} elseif ($opName == 'OP_LESSTHANOREQUAL') {
// cscriptnum
$num = $math->cmp($num1, $num2) <= 0;
} elseif ($opName == 'OP_GREATERTHANOREQUAL') {
$num = $math->cmp($num1, $num2) >= 0;
} elseif ($opName == 'OP_MIN') {
$num = $math->cmp($num1, $num2) <= 0 ? $num1 : $num2;
} else {
// is OP_MAX
$num = $math->cmp($num1, $num2) >= 0 ? $num1 : $num2;
}
$mainStack->pop();
$mainStack->pop();
$buffer = Buffer::hex($math->decHex($num));
$mainStack->push($buffer);
if ($opCodes->isOp($opCode, 'OP_NUMEQUALVERIFY')) {
if ($castToBool($mainStack->top(-1))) {
$mainStack->pop();
} else {
throw new \Exception('NUM EQUAL VERIFY error');
}
}
}
示例3: check
/**
* @param Buffer $hash
* @param int|string $nBits
* @return bool
*/
public function check(Buffer $hash, $nBits)
{
$negative = false;
$overflow = false;
$target = $this->math->writeCompact($nBits, $negative, $overflow);
if ($negative || $overflow || $this->math->cmp($target, 0) === 0 || $this->math->cmp($target, $this->getMaxTarget()) > 0) {
throw new \RuntimeException('nBits below minimum work');
}
if ($this->math->cmp($hash->getInt(), $target) > 0) {
throw new \RuntimeException("Hash doesn't match nBits");
}
return true;
}
示例4: 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?
$seed = $oldseed = $seed->getHex();
// Perform sha256 hash 5 times per iteration
for ($i = 0; $i < 5 * 20000; $i++) {
// Hash should return binary data
$seed = hash('sha256', $seed . $oldseed, true);
}
// Convert binary data to hex.
$str = new Buffer($seed);
return self::fromSecretExponent($str->getInt(), $ecAdapter ?: Bitcoin::getEcAdapter());
}
示例5: encode
/**
* Encode a given hex string in base58
*
* @param Buffer $binary
* @return string
* @throws \Exception
*/
public static function encode(Buffer $binary)
{
$size = $binary->getSize();
if ($size == 0) {
return '';
}
$math = Bitcoin::getMath();
$orig = $binary->getBinary();
$decimal = $binary->getInt();
$return = "";
while ($math->cmp($decimal, 0) > 0) {
list($decimal, $rem) = $math->divQr($decimal, 58);
$return = $return . self::$base58chars[$rem];
}
$return = strrev($return);
//leading zeros
for ($i = 0; $i < $size && $orig[$i] == ""; $i++) {
$return = "1" . $return;
}
return $return;
}
示例6: __construct
/**
* @param EcAdapterInterface $ecAdapter
* @param PrivateKeyInterface $privateKey
* @param Buffer $messageHash
* @param string $algo
*/
public function __construct(EcAdapterInterface $ecAdapter, PrivateKeyInterface $privateKey, Buffer $messageHash, $algo = 'sha256')
{
$mdPk = new MdPrivateKey($ecAdapter->getMath(), $ecAdapter->getGenerator(), $privateKey->getSecretMultiplier());
$this->ecAdapter = $ecAdapter;
$this->hmac = new HmacRandomNumberGenerator($ecAdapter->getMath(), $mdPk, $messageHash->getInt(), $algo);
}
示例7: hasBlockchain
public function hasBlockchain()
{
$math = Bitcoin::getMath();
return $math->cmp($math->bitwiseAnd($this->services->getInt(), self::NODE_NETWORK), self::NODE_NETWORK) == 0;
}
示例8: validatePrivateKey
/**
* @param Buffer $privateKey
* @return bool
*/
public function validatePrivateKey(Buffer $privateKey)
{
$math = $this->math;
$scalar = $privateKey->getInt();
return $math->cmp($scalar, 0) > 0 && $math->cmp($scalar, $this->getGenerator()->getOrder()) < 0;
}
示例9: castToBool
/**
* Cast the value to a boolean
*
* @param $value
* @return bool
*/
public function castToBool(Buffer $value)
{
if ($value->getSize() === 0) {
return true;
}
// Since we're using buffers, lets try ensuring the contents are not 0.
return $this->math->cmp($value->getInt(), 0) > 0;
}
示例10: validatePrivateKey
/**
* @param Buffer $privateKey
* @return bool
*/
public function validatePrivateKey(Buffer $privateKey)
{
return $this->checkInt($privateKey->getInt(), $this->getGenerator()->getOrder());
}
示例11: castToBool
/**
* Cast the value to a boolean
*
* @param $value
* @return bool
*/
public function castToBool(Buffer $value)
{
// Since we're using buffers, lets try ensuring the contents are not 0.
return $this->ecAdapter->getMath()->cmp($value->getInt(), 0) > 0;
// cscriptNum or edge case.
}